1a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 2a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 3a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// found in the LICENSE file. 4a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 5a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include <string> 6a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 7a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/path_service.h" 8a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "base/strings/utf_string_conversions.h" 9a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/download/download_prefs.h" 10a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/prefs/pref_service_syncable.h" 11a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/ui/browser.h" 12a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/ui/browser_commands.h" 13a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 14a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/common/chrome_paths.h" 15a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/common/pref_names.h" 16a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h" 171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#include "chrome/test/base/testing_browser_process.h" 18a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/test/base/testing_profile.h" 19a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 20a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "content/public/browser/web_contents.h" 21a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "content/public/test/browser_test_utils.h" 22a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)#include "content/public/test/download_test_observer.h" 23a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 24a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)using content::BrowserContext; 25a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)using content::DownloadManager; 26a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 27a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)class PrefsFunctionalTest : public InProcessBrowserTest { 28a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) protected: 29a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Create a DownloadTestObserverTerminal that will wait for the 30a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // specified number of downloads to finish. 31a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) scoped_ptr<content::DownloadTestObserver> CreateWaiter(Browser* browser, 32a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) int num_downloads) { 33a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) DownloadManager* download_manager = 34a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) BrowserContext::GetDownloadManager(browser->profile()); 35a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 36a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) content::DownloadTestObserver* downloads_observer = 37a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) new content::DownloadTestObserverTerminal( 38a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) download_manager, 39a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) num_downloads, 40a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); 41a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) return make_scoped_ptr(downloads_observer); 42a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) } 43a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)}; 44a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 45a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestDownloadDirPref) { 46a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 47cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) base::ScopedTempDir new_download_dir; 48cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) ASSERT_TRUE(new_download_dir.CreateUniqueTempDir()); 49a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 50a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::FilePath downloaded_pkg = 51cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) new_download_dir.path().AppendASCII("a_zip_file.zip"); 52a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 53a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Set pref to download in new_download_dir. 54a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser()->profile()->GetPrefs()->SetFilePath( 55cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) prefs::kDownloadDefaultDirectory, new_download_dir.path()); 56a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 57a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Create a downloads observer. 58a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) scoped_ptr<content::DownloadTestObserver> downloads_observer( 59a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) CreateWaiter(browser(), 1)); 60a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ui_test_utils::NavigateToURL( 61a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser(), 62a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) test_server()->GetURL("files/downloads/a_zip_file.zip")); 63a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) // Waits for the download to complete. 64a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) downloads_observer->WaitForFinished(); 65a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(base::PathExists(downloaded_pkg)); 66a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 67a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 68a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Verify image content settings show or hide images. 69a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImageContentSettings) { 70a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 71a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 72a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ui_test_utils::NavigateToURL( 73a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser(), 74a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) test_server()->GetURL("files/settings/image_page.html")); 75a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 76a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) bool result = false; 77a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) std::string script = 78a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) "for (i=0; i < document.images.length; i++) {" 79a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) " if ((document.images[i].naturalWidth != 0) &&" 80a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) " (document.images[i].naturalHeight != 0)) {" 81a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) " window.domAutomationController.send(true);" 82a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) " }" 83a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) "}" 84a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) "window.domAutomationController.send(false);"; 85a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 86a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(), 87a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) script, 88a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) &result)); 89a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(result); 90a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 91a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) base::DictionaryValue value; 92a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) value.SetInteger("images", 2); 93a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser()->profile()->GetPrefs()->Set(prefs::kDefaultContentSettings, 94a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) value); 95a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 96a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ui_test_utils::NavigateToURL( 97a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser(), 98a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) test_server()->GetURL("files/settings/image_page.html")); 99a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 100a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) result = false; 101a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 102a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents(), 103a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) script, 104a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) &result)); 105a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_FALSE(result); 106a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 107a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 108a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Verify that enabling/disabling Javascript in prefs works. 109a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestJavascriptEnableDisable) { 110a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 111a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 112a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 113a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) prefs::kWebKitJavascriptEnabled)); 114a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ui_test_utils::NavigateToURL( 115a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser(), 116a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) test_server()->GetURL("files/javaScriptTitle.html")); 1175d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(base::ASCIIToUTF16("Title from script javascript enabled"), 118a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 119a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser()->profile()->GetPrefs()->SetBoolean(prefs::kWebKitJavascriptEnabled, 120a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) false); 121a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) ui_test_utils::NavigateToURL( 122a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser(), 123a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) test_server()->GetURL("files/javaScriptTitle.html")); 1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) EXPECT_EQ(base::ASCIIToUTF16("This is html title"), 125a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); 126a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 127a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 128a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Verify DNS prefetching pref. 129a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestNetworkPredictionEnabledPref) { 130a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 131a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) prefs::kNetworkPredictionEnabled)); 132a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) browser()->profile()->GetPrefs()->SetBoolean(prefs::kNetworkPredictionEnabled, 133a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) false); 134a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( 135a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) prefs::kNetworkPredictionEnabled)); 136a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 137a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 138a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)// Verify restore for bookmark bar visibility. 139a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, 140a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) TestSessionRestoreShowBookmarkBar) { 141a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( 1421320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bookmarks::prefs::kShowBookmarkBar)); 1431320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci browser()->profile()->GetPrefs()->SetBoolean( 1441320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bookmarks::prefs::kShowBookmarkBar, true); 145a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 1461320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bookmarks::prefs::kShowBookmarkBar)); 147a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) 148a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 1491320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci bookmarks::prefs::kShowBookmarkBar)); 150a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles) EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); 151a36e5920737c6adbddd3e43b760e5de8431db6e0Torne (Richard Coles)} 1521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1531e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verify images are not blocked in incognito mode. 1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImagesNotBlockedInIncognito) { 1551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ASSERT_TRUE(test_server()->Start()); 1561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) GURL url = test_server()->GetURL("files/settings/image_page.html"); 1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) Browser* incognito_browser = CreateIncognitoBrowser(); 1581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ui_test_utils::NavigateToURLWithDisposition( 1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) incognito_browser, 1601e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) url, 1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) CURRENT_TAB, 1621e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); 1631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1641e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) bool result = false; 1651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) std::string script = 1661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "for (i=0; i < document.images.length; i++) {" 1671e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) " if ((document.images[i].naturalWidth != 0) &&" 1681e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) " (document.images[i].naturalHeight != 0)) {" 1691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) " window.domAutomationController.send(true);" 1701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) " }" 1711e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "}" 1721e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) "window.domAutomationController.send(false);"; 1731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(content::ExecuteScriptAndExtractBool( 1741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) incognito_browser->tab_strip_model()->GetActiveWebContents(), 1751e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) script, 1761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) &result)); 1771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(result); 1781e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1791e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1801e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verify setting homepage preference to newtabpage across restarts. Part1 1811e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestHomepageNewTabpagePrefs) { 1821e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) browser()->profile()->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage, 1831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) true); 1841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verify setting homepage preference to newtabpage across restarts. Part2 1871e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHomepageNewTabpagePrefs) { 1881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( 1891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) prefs::kHomePageIsNewTabPage)); 1901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 1911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verify setting homepage preference to specific url. Part1 1931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestHomepagePrefs) { 1941e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) GURL home_page_url("http://www.google.com"); 1951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 1961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PrefService* prefs = browser()->profile()->GetPrefs(); 1971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false); 1981e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) const PrefService::Preference* pref = 1991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) prefs->FindPreference(prefs::kHomePage); 2001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) if (pref && !pref->IsManaged()) { 2011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) prefs->SetString(prefs::kHomePage, home_page_url.spec()); 2021e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) } 2031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verify setting homepage preference to specific url. Part2 2061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHomepagePrefs) { 2071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) GURL home_page_url("http://www.google.com"); 2081e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PrefService* prefs = browser()->profile()->GetPrefs(); 2101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage)); 2111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_EQ(home_page_url.spec(), prefs->GetString(prefs::kHomePage)); 2121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verify the security preference under privacy across restarts. Part1 2151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestPrivacySecurityPrefs) { 2161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PrefService* prefs = browser()->profile()->GetPrefs(); 2171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); 2191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) prefs->SetBoolean(prefs::kNetworkPredictionEnabled, false); 2201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled)); 2221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) prefs->SetBoolean(prefs::kSafeBrowsingEnabled, false); 2231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)); 2251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) prefs->SetBoolean(prefs::kAlternateErrorPagesEnabled, false); 2261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_TRUE(prefs->GetBoolean(prefs::kSearchSuggestEnabled)); 2281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) prefs->SetBoolean(prefs::kSearchSuggestEnabled, false); 2291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verify the security preference under privacy across restarts. Part2 2321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestPrivacySecurityPrefs) { 2331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) PrefService* prefs = browser()->profile()->GetPrefs(); 2341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled)); 2361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled)); 2371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)); 2381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) EXPECT_FALSE(prefs->GetBoolean(prefs::kSearchSuggestEnabled)); 2391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2401e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 2411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Verify that we have some Local State prefs. 2421e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHaveLocalStatePrefs) { 2430f1bc08d4cfcc34181b0b5cbf065c40f687bf740Torne (Richard Coles) EXPECT_TRUE(g_browser_process->local_state()->GetPreferenceValues().get()); 2441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)} 2451e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 246