| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <string> | 5 #include <string> |
| 6 | 6 |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "chrome/browser/download/download_prefs.h" | 8 #include "chrome/browser/download/download_prefs.h" |
| 9 #include "chrome/browser/net/prediction_options.h" | 9 #include "chrome/browser/net/prediction_options.h" |
| 10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
| 11 #include "chrome/browser/ui/browser_commands.h" | 11 #include "chrome/browser/ui/browser_commands.h" |
| 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 12 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 13 #include "chrome/common/chrome_paths.h" | 13 #include "chrome/common/chrome_paths.h" |
| 14 #include "chrome/common/pref_names.h" | 14 #include "chrome/common/pref_names.h" |
| 15 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 16 #include "chrome/test/base/testing_browser_process.h" | 16 #include "chrome/test/base/testing_browser_process.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
| 19 #include "components/bookmarks/common/bookmark_pref_names.h" | 19 #include "components/bookmarks/common/bookmark_pref_names.h" |
| 20 #include "components/content_settings/core/browser/website_settings_info.h" | 20 #include "components/content_settings/core/browser/website_settings_info.h" |
| 21 #include "components/content_settings/core/browser/website_settings_registry.h" | 21 #include "components/content_settings/core/browser/website_settings_registry.h" |
| 22 #include "components/content_settings/core/common/content_settings_types.h" | 22 #include "components/content_settings/core/common/content_settings_types.h" |
| 23 #include "components/content_settings/core/common/pref_names.h" | 23 #include "components/content_settings/core/common/pref_names.h" |
| 24 #include "components/syncable_prefs/pref_service_syncable.h" | 24 #include "components/syncable_prefs/pref_service_syncable.h" |
| 25 #include "content/public/browser/web_contents.h" | 25 #include "content/public/browser/web_contents.h" |
| 26 #include "content/public/test/browser_test_utils.h" | 26 #include "content/public/test/browser_test_utils.h" |
| 27 #include "content/public/test/download_test_observer.h" | 27 #include "content/public/test/download_test_observer.h" |
| 28 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 28 | 29 |
| 29 using content::BrowserContext; | 30 using content::BrowserContext; |
| 30 using content::DownloadManager; | 31 using content::DownloadManager; |
| 31 | 32 |
| 32 class PrefsFunctionalTest : public InProcessBrowserTest { | 33 class PrefsFunctionalTest : public InProcessBrowserTest { |
| 33 protected: | 34 protected: |
| 34 // Create a DownloadTestObserverTerminal that will wait for the | 35 // Create a DownloadTestObserverTerminal that will wait for the |
| 35 // specified number of downloads to finish. | 36 // specified number of downloads to finish. |
| 36 scoped_ptr<content::DownloadTestObserver> CreateWaiter(Browser* browser, | 37 scoped_ptr<content::DownloadTestObserver> CreateWaiter(Browser* browser, |
| 37 int num_downloads) { | 38 int num_downloads) { |
| 38 DownloadManager* download_manager = | 39 DownloadManager* download_manager = |
| 39 BrowserContext::GetDownloadManager(browser->profile()); | 40 BrowserContext::GetDownloadManager(browser->profile()); |
| 40 | 41 |
| 41 content::DownloadTestObserver* downloads_observer = | 42 content::DownloadTestObserver* downloads_observer = |
| 42 new content::DownloadTestObserverTerminal( | 43 new content::DownloadTestObserverTerminal( |
| 43 download_manager, | 44 download_manager, |
| 44 num_downloads, | 45 num_downloads, |
| 45 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | 46 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); |
| 46 return make_scoped_ptr(downloads_observer); | 47 return make_scoped_ptr(downloads_observer); |
| 47 } | 48 } |
| 48 }; | 49 }; |
| 49 | 50 |
| 50 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestDownloadDirPref) { | 51 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestDownloadDirPref) { |
| 51 ASSERT_TRUE(test_server()->Start()); | 52 ASSERT_TRUE(embedded_test_server()->Start()); |
| 52 base::ScopedTempDir new_download_dir; | 53 base::ScopedTempDir new_download_dir; |
| 53 ASSERT_TRUE(new_download_dir.CreateUniqueTempDir()); | 54 ASSERT_TRUE(new_download_dir.CreateUniqueTempDir()); |
| 54 | 55 |
| 55 base::FilePath downloaded_pkg = | 56 base::FilePath downloaded_pkg = |
| 56 new_download_dir.path().AppendASCII("a_zip_file.zip"); | 57 new_download_dir.path().AppendASCII("a_zip_file.zip"); |
| 57 | 58 |
| 58 // Set pref to download in new_download_dir. | 59 // Set pref to download in new_download_dir. |
| 59 browser()->profile()->GetPrefs()->SetFilePath( | 60 browser()->profile()->GetPrefs()->SetFilePath( |
| 60 prefs::kDownloadDefaultDirectory, new_download_dir.path()); | 61 prefs::kDownloadDefaultDirectory, new_download_dir.path()); |
| 61 | 62 |
| 62 // Create a downloads observer. | 63 // Create a downloads observer. |
| 63 scoped_ptr<content::DownloadTestObserver> downloads_observer( | 64 scoped_ptr<content::DownloadTestObserver> downloads_observer( |
| 64 CreateWaiter(browser(), 1)); | 65 CreateWaiter(browser(), 1)); |
| 65 ui_test_utils::NavigateToURL( | 66 ui_test_utils::NavigateToURL( |
| 66 browser(), | 67 browser(), embedded_test_server()->GetURL("/downloads/a_zip_file.zip")); |
| 67 test_server()->GetURL("files/downloads/a_zip_file.zip")); | |
| 68 // Waits for the download to complete. | 68 // Waits for the download to complete. |
| 69 downloads_observer->WaitForFinished(); | 69 downloads_observer->WaitForFinished(); |
| 70 EXPECT_TRUE(base::PathExists(downloaded_pkg)); | 70 EXPECT_TRUE(base::PathExists(downloaded_pkg)); |
| 71 } | 71 } |
| 72 | 72 |
| 73 // Verify image content settings show or hide images. | 73 // Verify image content settings show or hide images. |
| 74 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImageContentSettings) { | 74 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImageContentSettings) { |
| 75 ASSERT_TRUE(test_server()->Start()); | 75 ASSERT_TRUE(embedded_test_server()->Start()); |
| 76 | 76 |
| 77 ui_test_utils::NavigateToURL( | 77 ui_test_utils::NavigateToURL( |
| 78 browser(), | 78 browser(), embedded_test_server()->GetURL("/settings/image_page.html")); |
| 79 test_server()->GetURL("files/settings/image_page.html")); | |
| 80 | 79 |
| 81 bool result = false; | 80 bool result = false; |
| 82 std::string script = | 81 std::string script = |
| 83 "for (i=0; i < document.images.length; i++) {" | 82 "for (i=0; i < document.images.length; i++) {" |
| 84 " if ((document.images[i].naturalWidth != 0) &&" | 83 " if ((document.images[i].naturalWidth != 0) &&" |
| 85 " (document.images[i].naturalHeight != 0)) {" | 84 " (document.images[i].naturalHeight != 0)) {" |
| 86 " window.domAutomationController.send(true);" | 85 " window.domAutomationController.send(true);" |
| 87 " }" | 86 " }" |
| 88 "}" | 87 "}" |
| 89 "window.domAutomationController.send(false);"; | 88 "window.domAutomationController.send(false);"; |
| 90 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 89 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 91 browser()->tab_strip_model()->GetActiveWebContents(), | 90 browser()->tab_strip_model()->GetActiveWebContents(), |
| 92 script, | 91 script, |
| 93 &result)); | 92 &result)); |
| 94 EXPECT_TRUE(result); | 93 EXPECT_TRUE(result); |
| 95 | 94 |
| 96 browser()->profile()->GetPrefs()->SetInteger( | 95 browser()->profile()->GetPrefs()->SetInteger( |
| 97 content_settings::WebsiteSettingsRegistry::GetInstance() | 96 content_settings::WebsiteSettingsRegistry::GetInstance() |
| 98 ->Get(CONTENT_SETTINGS_TYPE_IMAGES) | 97 ->Get(CONTENT_SETTINGS_TYPE_IMAGES) |
| 99 ->default_value_pref_name(), | 98 ->default_value_pref_name(), |
| 100 CONTENT_SETTING_BLOCK); | 99 CONTENT_SETTING_BLOCK); |
| 101 | 100 |
| 102 ui_test_utils::NavigateToURL( | 101 ui_test_utils::NavigateToURL( |
| 103 browser(), | 102 browser(), embedded_test_server()->GetURL("/settings/image_page.html")); |
| 104 test_server()->GetURL("files/settings/image_page.html")); | |
| 105 | 103 |
| 106 result = false; | 104 result = false; |
| 107 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | 105 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 108 browser()->tab_strip_model()->GetActiveWebContents(), | 106 browser()->tab_strip_model()->GetActiveWebContents(), |
| 109 script, | 107 script, |
| 110 &result)); | 108 &result)); |
| 111 EXPECT_FALSE(result); | 109 EXPECT_FALSE(result); |
| 112 } | 110 } |
| 113 | 111 |
| 114 // Verify that enabling/disabling Javascript in prefs works. | 112 // Verify that enabling/disabling Javascript in prefs works. |
| 115 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestJavascriptEnableDisable) { | 113 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestJavascriptEnableDisable) { |
| 116 ASSERT_TRUE(test_server()->Start()); | 114 ASSERT_TRUE(embedded_test_server()->Start()); |
| 117 | 115 |
| 118 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | 116 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( |
| 119 prefs::kWebKitJavascriptEnabled)); | 117 prefs::kWebKitJavascriptEnabled)); |
| 120 ui_test_utils::NavigateToURL( | 118 ui_test_utils::NavigateToURL( |
| 121 browser(), | 119 browser(), embedded_test_server()->GetURL("/javaScriptTitle.html")); |
| 122 test_server()->GetURL("files/javaScriptTitle.html")); | |
| 123 EXPECT_EQ(base::ASCIIToUTF16("Title from script javascript enabled"), | 120 EXPECT_EQ(base::ASCIIToUTF16("Title from script javascript enabled"), |
| 124 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 121 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 125 browser()->profile()->GetPrefs()->SetBoolean(prefs::kWebKitJavascriptEnabled, | 122 browser()->profile()->GetPrefs()->SetBoolean(prefs::kWebKitJavascriptEnabled, |
| 126 false); | 123 false); |
| 127 ui_test_utils::NavigateToURL( | 124 ui_test_utils::NavigateToURL( |
| 128 browser(), | 125 browser(), embedded_test_server()->GetURL("/javaScriptTitle.html")); |
| 129 test_server()->GetURL("files/javaScriptTitle.html")); | |
| 130 EXPECT_EQ(base::ASCIIToUTF16("This is html title"), | 126 EXPECT_EQ(base::ASCIIToUTF16("This is html title"), |
| 131 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | 127 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); |
| 132 } | 128 } |
| 133 | 129 |
| 134 // Verify restore for bookmark bar visibility. | 130 // Verify restore for bookmark bar visibility. |
| 135 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, | 131 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, |
| 136 TestSessionRestoreShowBookmarkBar) { | 132 TestSessionRestoreShowBookmarkBar) { |
| 137 EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( | 133 EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( |
| 138 bookmarks::prefs::kShowBookmarkBar)); | 134 bookmarks::prefs::kShowBookmarkBar)); |
| 139 browser()->profile()->GetPrefs()->SetBoolean( | 135 browser()->profile()->GetPrefs()->SetBoolean( |
| 140 bookmarks::prefs::kShowBookmarkBar, true); | 136 bookmarks::prefs::kShowBookmarkBar, true); |
| 141 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | 137 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( |
| 142 bookmarks::prefs::kShowBookmarkBar)); | 138 bookmarks::prefs::kShowBookmarkBar)); |
| 143 | 139 |
| 144 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | 140 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( |
| 145 bookmarks::prefs::kShowBookmarkBar)); | 141 bookmarks::prefs::kShowBookmarkBar)); |
| 146 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | 142 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); |
| 147 } | 143 } |
| 148 | 144 |
| 149 // Verify images are not blocked in incognito mode. | 145 // Verify images are not blocked in incognito mode. |
| 150 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImagesNotBlockedInIncognito) { | 146 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImagesNotBlockedInIncognito) { |
| 151 ASSERT_TRUE(test_server()->Start()); | 147 ASSERT_TRUE(embedded_test_server()->Start()); |
| 152 GURL url = test_server()->GetURL("files/settings/image_page.html"); | 148 GURL url = embedded_test_server()->GetURL("/settings/image_page.html"); |
| 153 Browser* incognito_browser = CreateIncognitoBrowser(); | 149 Browser* incognito_browser = CreateIncognitoBrowser(); |
| 154 ui_test_utils::NavigateToURL(incognito_browser, url); | 150 ui_test_utils::NavigateToURL(incognito_browser, url); |
| 155 | 151 |
| 156 bool result = false; | 152 bool result = false; |
| 157 std::string script = | 153 std::string script = |
| 158 "for (i=0; i < document.images.length; i++) {" | 154 "for (i=0; i < document.images.length; i++) {" |
| 159 " if ((document.images[i].naturalWidth != 0) &&" | 155 " if ((document.images[i].naturalWidth != 0) &&" |
| 160 " (document.images[i].naturalHeight != 0)) {" | 156 " (document.images[i].naturalHeight != 0)) {" |
| 161 " window.domAutomationController.send(true);" | 157 " window.domAutomationController.send(true);" |
| 162 " }" | 158 " }" |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 234 prefs->GetInteger(prefs::kNetworkPredictionOptions)); | 230 prefs->GetInteger(prefs::kNetworkPredictionOptions)); |
| 235 EXPECT_FALSE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled)); | 231 EXPECT_FALSE(prefs->GetBoolean(prefs::kSafeBrowsingEnabled)); |
| 236 EXPECT_FALSE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)); | 232 EXPECT_FALSE(prefs->GetBoolean(prefs::kAlternateErrorPagesEnabled)); |
| 237 EXPECT_FALSE(prefs->GetBoolean(prefs::kSearchSuggestEnabled)); | 233 EXPECT_FALSE(prefs->GetBoolean(prefs::kSearchSuggestEnabled)); |
| 238 } | 234 } |
| 239 | 235 |
| 240 // Verify that we have some Local State prefs. | 236 // Verify that we have some Local State prefs. |
| 241 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHaveLocalStatePrefs) { | 237 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestHaveLocalStatePrefs) { |
| 242 EXPECT_TRUE(g_browser_process->local_state()->GetPreferenceValues().get()); | 238 EXPECT_TRUE(g_browser_process->local_state()->GetPreferenceValues().get()); |
| 243 } | 239 } |
| 244 | |
| OLD | NEW |