Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / prefs / pref_functional_browsertest.cc
blob9ef8ccdd0a28a6dbda834bb099914c29b57247a5
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 "components/content_settings/core/browser/website_settings_info.h"
20 #include "components/content_settings/core/browser/website_settings_registry.h"
21 #include "components/content_settings/core/common/content_settings_types.h"
22 #include "content/public/browser/web_contents.h"
23 #include "content/public/test/browser_test_utils.h"
24 #include "content/public/test/download_test_observer.h"
26 using content::BrowserContext;
27 using content::DownloadManager;
29 class PrefsFunctionalTest : public InProcessBrowserTest {
30 protected:
31 // Create a DownloadTestObserverTerminal that will wait for the
32 // specified number of downloads to finish.
33 scoped_ptr<content::DownloadTestObserver> CreateWaiter(Browser* browser,
34 int num_downloads) {
35 DownloadManager* download_manager =
36 BrowserContext::GetDownloadManager(browser->profile());
38 content::DownloadTestObserver* downloads_observer =
39 new content::DownloadTestObserverTerminal(
40 download_manager,
41 num_downloads,
42 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL);
43 return make_scoped_ptr(downloads_observer);
47 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestDownloadDirPref) {
48 ASSERT_TRUE(test_server()->Start());
49 base::ScopedTempDir new_download_dir;
50 ASSERT_TRUE(new_download_dir.CreateUniqueTempDir());
52 base::FilePath downloaded_pkg =
53 new_download_dir.path().AppendASCII("a_zip_file.zip");
55 // Set pref to download in new_download_dir.
56 browser()->profile()->GetPrefs()->SetFilePath(
57 prefs::kDownloadDefaultDirectory, new_download_dir.path());
59 // Create a downloads observer.
60 scoped_ptr<content::DownloadTestObserver> downloads_observer(
61 CreateWaiter(browser(), 1));
62 ui_test_utils::NavigateToURL(
63 browser(),
64 test_server()->GetURL("files/downloads/a_zip_file.zip"));
65 // Waits for the download to complete.
66 downloads_observer->WaitForFinished();
67 EXPECT_TRUE(base::PathExists(downloaded_pkg));
70 // Verify image content settings show or hide images.
71 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImageContentSettings) {
72 ASSERT_TRUE(test_server()->Start());
74 ui_test_utils::NavigateToURL(
75 browser(),
76 test_server()->GetURL("files/settings/image_page.html"));
78 bool result = false;
79 std::string script =
80 "for (i=0; i < document.images.length; i++) {"
81 " if ((document.images[i].naturalWidth != 0) &&"
82 " (document.images[i].naturalHeight != 0)) {"
83 " window.domAutomationController.send(true);"
84 " }"
85 "}"
86 "window.domAutomationController.send(false);";
87 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
88 browser()->tab_strip_model()->GetActiveWebContents(),
89 script,
90 &result));
91 EXPECT_TRUE(result);
93 browser()->profile()->GetPrefs()->SetInteger(
94 content_settings::WebsiteSettingsRegistry::GetInstance()
95 ->Get(CONTENT_SETTINGS_TYPE_IMAGES)
96 ->default_value_pref_name(),
97 CONTENT_SETTING_BLOCK);
99 ui_test_utils::NavigateToURL(
100 browser(),
101 test_server()->GetURL("files/settings/image_page.html"));
103 result = false;
104 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
105 browser()->tab_strip_model()->GetActiveWebContents(),
106 script,
107 &result));
108 EXPECT_FALSE(result);
111 // Verify that enabling/disabling Javascript in prefs works.
112 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestJavascriptEnableDisable) {
113 ASSERT_TRUE(test_server()->Start());
115 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
116 prefs::kWebKitJavascriptEnabled));
117 ui_test_utils::NavigateToURL(
118 browser(),
119 test_server()->GetURL("files/javaScriptTitle.html"));
120 EXPECT_EQ(base::ASCIIToUTF16("Title from script javascript enabled"),
121 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
122 browser()->profile()->GetPrefs()->SetBoolean(prefs::kWebKitJavascriptEnabled,
123 false);
124 ui_test_utils::NavigateToURL(
125 browser(),
126 test_server()->GetURL("files/javaScriptTitle.html"));
127 EXPECT_EQ(base::ASCIIToUTF16("This is html title"),
128 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle());
131 // Verify restore for bookmark bar visibility.
132 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest,
133 TestSessionRestoreShowBookmarkBar) {
134 EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean(
135 bookmarks::prefs::kShowBookmarkBar));
136 browser()->profile()->GetPrefs()->SetBoolean(
137 bookmarks::prefs::kShowBookmarkBar, true);
138 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
139 bookmarks::prefs::kShowBookmarkBar));
141 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
142 bookmarks::prefs::kShowBookmarkBar));
143 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state());
146 // Verify images are not blocked in incognito mode.
147 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImagesNotBlockedInIncognito) {
148 ASSERT_TRUE(test_server()->Start());
149 GURL url = test_server()->GetURL("files/settings/image_page.html");
150 Browser* incognito_browser = CreateIncognitoBrowser();
151 ui_test_utils::NavigateToURL(incognito_browser, url);
153 bool result = false;
154 std::string script =
155 "for (i=0; i < document.images.length; i++) {"
156 " if ((document.images[i].naturalWidth != 0) &&"
157 " (document.images[i].naturalHeight != 0)) {"
158 " window.domAutomationController.send(true);"
159 " }"
161 "window.domAutomationController.send(false);";
162 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
163 incognito_browser->tab_strip_model()->GetActiveWebContents(),
164 script,
165 &result));
166 EXPECT_TRUE(result);
169 // Verify setting homepage preference to newtabpage across restarts. Part1
170 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestHomepageNewTabpagePrefs) {
171 browser()->profile()->GetPrefs()->SetBoolean(prefs::kHomePageIsNewTabPage,
172 true);
175 // Verify setting homepage preference to newtabpage across restarts. Part2
176 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHomepageNewTabpagePrefs) {
177 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean(
178 prefs::kHomePageIsNewTabPage));
181 // Verify setting homepage preference to specific url. Part1
182 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestHomepagePrefs) {
183 GURL home_page_url("http://www.google.com");
185 PrefService* prefs = browser()->profile()->GetPrefs();
186 prefs->SetBoolean(prefs::kHomePageIsNewTabPage, false);
187 const PrefService::Preference* pref =
188 prefs->FindPreference(prefs::kHomePage);
189 if (pref && !pref->IsManaged()) {
190 prefs->SetString(prefs::kHomePage, home_page_url.spec());
194 // Verify setting homepage preference to specific url. Part2
195 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHomepagePrefs) {
196 GURL home_page_url("http://www.google.com");
198 PrefService* prefs = browser()->profile()->GetPrefs();
199 EXPECT_FALSE(prefs->GetBoolean(prefs::kHomePageIsNewTabPage));
200 EXPECT_EQ(home_page_url.spec(), prefs->GetString(prefs::kHomePage));
203 // Verify the security preference under privacy across restarts. Part1
204 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, PRE_TestPrivacySecurityPrefs) {
205 PrefService* prefs = browser()->profile()->GetPrefs();
207 EXPECT_TRUE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
208 prefs->SetBoolean(prefs::kNetworkPredictionEnabled, false);
210 EXPECT_TRUE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled));
211 prefs->SetBoolean(prefs::kSafeBrowsingEnabled, false);
213 EXPECT_TRUE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled));
214 prefs->SetBoolean(prefs::kAlternateErrorPagesEnabled, false);
216 EXPECT_TRUE(prefs->GetBoolean(prefs::kSearchSuggestEnabled));
217 prefs->SetBoolean(prefs::kSearchSuggestEnabled, false);
220 // Verify the security preference under privacy across restarts. Part2
221 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestPrivacySecurityPrefs) {
222 PrefService* prefs = browser()->profile()->GetPrefs();
224 EXPECT_FALSE(prefs->GetBoolean(prefs::kNetworkPredictionEnabled));
225 EXPECT_FALSE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled));
226 EXPECT_FALSE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled));
227 EXPECT_FALSE(prefs->GetBoolean(prefs::kSearchSuggestEnabled));
230 // Verify that we have some Local State prefs.
231 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHaveLocalStatePrefs) {
232 EXPECT_TRUE(g_browser_process->local_state()->GetPreferenceValues().get());