Give names to all utility processes.
[chromium-blink-merge.git] / chrome / browser / prefs / pref_functional_browsertest.cc
blob0a9331a20ff2d0a9ee2ec70214bd620cb75e45b0
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include <string>
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/download/download_prefs.h"
9 #include "chrome/browser/prefs/pref_service_syncable.h"
10 #include "chrome/browser/ui/browser.h"
11 #include "chrome/browser/ui/browser_commands.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_paths.h"
14 #include "chrome/common/pref_names.h"
15 #include "chrome/test/base/in_process_browser_test.h"
16 #include "chrome/test/base/testing_browser_process.h"
17 #include "chrome/test/base/testing_profile.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/browser_test_utils.h"
21 #include "content/public/test/download_test_observer.h"
23 using content::BrowserContext;
24 using content::DownloadManager;
26 class PrefsFunctionalTest : public InProcessBrowserTest {
27 protected:
28 // Create a DownloadTestObserverTerminal that will wait for the
29 // specified number of downloads to finish.
30 scoped_ptr<content::DownloadTestObserver> CreateWaiter(Browser* browser,
31 int num_downloads) {
32 DownloadManager* download_manager =
33 BrowserContext::GetDownloadManager(browser->profile());
35 content::DownloadTestObserver* downloads_observer =
36 new content::DownloadTestObserverTerminal(
37 download_manager,
38 num_downloads,
39 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
40 return make_scoped_ptr(downloads_observer);
44 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestDownloadDirPref) {
45 ASSERT_TRUE(test_server()->Start());
46 base::ScopedTempDir new_download_dir;
47 ASSERT_TRUE(new_download_dir.CreateUniqueTempDir());
49 base::FilePath downloaded_pkg =
50 new_download_dir.path().AppendASCII("a_zip_file.zip");
52 // Set pref to download in new_download_dir.
53 browser()->profile()->GetPrefs()->SetFilePath(
54 prefs::kDownloadDefaultDirectory, new_download_dir.path());
56 // Create a downloads observer.
57 scoped_ptr<content::DownloadTestObserver> downloads_observer(
58 CreateWaiter(browser(), 1));
59 ui_test_utils::NavigateToURL(
60 browser(),
61 test_server()->GetURL("files/downloads/a_zip_file.zip"));
62 // Waits for the download to complete.
63 downloads_observer->WaitForFinished();
64 EXPECT_TRUE(base::PathExists(downloaded_pkg));
67 // Verify image content settings show or hide images.
68 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImageContentSettings) {
69 ASSERT_TRUE(test_server()->Start());
71 ui_test_utils::NavigateToURL(
72 browser(),
73 test_server()->GetURL("files/settings/image_page.html"));
75 bool result = false;
76 std::string script =
77 "for (i=0; i < document.images.length; i++) {"
78 " if ((document.images[i].naturalWidth != 0) &&"
79 " (document.images[i].naturalHeight != 0)) {"
80 " window.domAutomationController.send(true);"
81 " }"
82 "}"
83 "window.domAutomationController.send(false);";
84 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
85 browser()->tab_strip_model()->GetActiveWebContents(),
86 script,
87 &result));
88 EXPECT_TRUE(result);
90 base::DictionaryValue value;
91 value.SetInteger("images", 2);
92 browser()->profile()->GetPrefs()->Set(prefs::kDefaultContentSettings,
93 value);
95 ui_test_utils::NavigateToURL(
96 browser(),
97 test_server()->GetURL("files/settings/image_page.html"));
99 result = false;
100 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
101 browser()->tab_strip_model()->GetActiveWebContents(),
102 script,
103 &result));
104 EXPECT_FALSE(result);
107 // Verify that enabling/disabling Javascript in prefs works.
108 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestJavascriptEnableDisable) {
109 ASSERT_TRUE(test_server()->Start());
111 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
112 prefs::kWebKitJavascriptEnabled));
113 ui_test_utils::NavigateToURL(
114 browser(),
115 test_server()->GetURL("files/javaScriptTitle.html"));
116 EXPECT_EQ(base::ASCIIToUTF16("Title from script javascript enabled"),
117 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
118 browser()->profile()->GetPrefs()->SetBoolean(prefs::kWebKitJavascriptEnabled,
119 false);
120 ui_test_utils::NavigateToURL(
121 browser(),
122 test_server()->GetURL("files/javaScriptTitle.html"));
123 EXPECT_EQ(base::ASCIIToUTF16("This is html title"),
124 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
127 // Verify restore for bookmark bar visibility.
128 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest,
129 TestSessionRestoreShowBookmarkBar) {
130 EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
131 bookmarks::prefs::kShowBookmarkBar));
132 browser()->profile()->GetPrefs()->SetBoolean(
133 bookmarks::prefs::kShowBookmarkBar, true);
134 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
135 bookmarks::prefs::kShowBookmarkBar));
137 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
138 bookmarks::prefs::kShowBookmarkBar));
139 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
142 // Verify images are not blocked in incognito mode.
143 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImagesNotBlockedInIncognito) {
144 ASSERT_TRUE(test_server()->Start());
145 GURL url = test_server()->GetURL("files/settings/image_page.html");
146 Browser* incognito_browser = CreateIncognitoBrowser();
147 ui_test_utils::NavigateToURL(incognito_browser, url);
149 bool result = false;
150 std::string script =
151 "for (i=0; i < document.images.length; i++) {"
152 " if ((document.images[i].naturalWidth != 0) &&"
153 " (document.images[i].naturalHeight != 0)) {"
154 " window.domAutomationController.send(true);"
155 " }"
157 "window.domAutomationController.send(false);";
158 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
159 incognito_browser->tab_strip_model()->GetActiveWebContents(),
160 script,
161 &result));
162 EXPECT_TRUE(result);
165 // Verify setting homepage preference to newtabpage across restarts. Part1
166 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestHomepageNewTabpagePrefs) {
167 browser()->profile()->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage,
168 true);
171 // Verify setting homepage preference to newtabpage across restarts. Part2
172 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHomepageNewTabpagePrefs) {
173 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
174 prefs::kHomePageIsNewTabPage));
177 // Verify setting homepage preference to specific url. Part1
178 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestHomepagePrefs) {
179 GURL home_page_url("http://www.google.com");
181 PrefService* prefs = browser()->profile()->GetPrefs();
182 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false);
183 const PrefService::Preference* pref =
184 prefs->FindPreference(prefs::kHomePage);
185 if (pref && !pref->IsManaged()) {
186 prefs->SetString(prefs::kHomePage, home_page_url.spec());
190 // Verify setting homepage preference to specific url. Part2
191 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHomepagePrefs) {
192 GURL home_page_url("http://www.google.com");
194 PrefService* prefs = browser()->profile()->GetPrefs();
195 EXPECT_FALSE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage));
196 EXPECT_EQ(home_page_url.spec(), prefs->GetString(prefs::kHomePage));
199 // Verify the security preference under privacy across restarts. Part1
200 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestPrivacySecurityPrefs) {
201 PrefService* prefs = browser()->profile()->GetPrefs();
203 EXPECT_TRUE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
204 prefs->SetBoolean(prefs::kNetworkPredictionEnabled, false);
206 EXPECT_TRUE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled));
207 prefs->SetBoolean(prefs::kSafeBrowsingEnabled, false);
209 EXPECT_TRUE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled));
210 prefs->SetBoolean(prefs::kAlternateErrorPagesEnabled, false);
212 EXPECT_TRUE(prefs->GetBoolean(prefs::kSearchSuggestEnabled));
213 prefs->SetBoolean(prefs::kSearchSuggestEnabled, false);
216 // Verify the security preference under privacy across restarts. Part2
217 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestPrivacySecurityPrefs) {
218 PrefService* prefs = browser()->profile()->GetPrefs();
220 EXPECT_FALSE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
221 EXPECT_FALSE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled));
222 EXPECT_FALSE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled));
223 EXPECT_FALSE(prefs->GetBoolean(prefs::kSearchSuggestEnabled));
226 // Verify that we have some Local State prefs.
227 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHaveLocalStatePrefs) {
228 EXPECT_TRUE(g_browser_process->local_state()->GetPreferenceValues().get());