Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright (c) 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. | |
| 4 | |
| 5 #include <string> | |
| 6 | |
| 7 #include "base/path_service.h" | |
| 8 #include "base/strings/utf_string_conversions.h" | |
| 9 #include "chrome/browser/download/download_prefs.h" | |
| 10 #include "chrome/browser/prefs/pref_service_syncable.h" | |
| 11 #include "chrome/browser/ui/browser.h" | |
| 12 #include "chrome/browser/ui/browser_commands.h" | |
| 13 #include "chrome/browser/ui/tabs/tab_strip_model.h" | |
| 14 #include "chrome/common/chrome_paths.h" | |
| 15 #include "chrome/common/pref_names.h" | |
| 16 #include "chrome/test/base/in_process_browser_test.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" | |
| 22 | |
| 23 using content::BrowserContext; | |
| 24 using content::DownloadManager; | |
| 25 | |
| 26 class PrefsFunctionalTest : public InProcessBrowserTest { | |
| 27 public: | |
| 28 virtual void SetUpCommandLine(CommandLine* command_line) { | |
| 29 PathService::Get(chrome::DIR_TEST_DATA, &test_data_dir_); | |
| 30 } | |
|
Bernhard Bauer
2013/08/01 11:38:42
Nit: Newline before public/protected/private secti
pshenoy
2013/08/01 17:26:44
Done.
| |
| 31 protected: | |
| 32 // Create a DownloadTestObserverTerminal that will wait for the | |
| 33 // specified number of downloads to finish. | |
| 34 content::DownloadTestObserver* CreateWaiter( | |
|
Bernhard Bauer
2013/08/01 11:38:42
Who owns this object? The caller? If so, you can r
pshenoy
2013/08/01 17:26:44
I am using scoped_ptr in line# 69 where it is actu
Bernhard Bauer
2013/08/01 22:20:07
You can also return a scoped_ptr here. The effect
pshenoy
2013/08/01 23:44:33
Done.
| |
| 35 Browser* browser, int num_downloads) { | |
|
Bernhard Bauer
2013/08/01 11:38:42
Does this not fit on the previous line?
pshenoy
2013/08/01 17:26:44
Done.
| |
| 36 DownloadManager* download_manager = | |
| 37 BrowserContext::GetDownloadManager(browser->profile()); | |
|
Bernhard Bauer
2013/08/01 11:38:42
Indent two more spaces.
pshenoy
2013/08/01 17:26:44
Done.
| |
| 38 return new content::DownloadTestObserverTerminal( | |
| 39 download_manager, num_downloads, | |
| 40 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_FAIL); | |
| 41 } | |
| 42 base::FilePath test_data_dir_; | |
|
Bernhard Bauer
2013/08/01 11:38:42
Nit: A newline before this would be nice.
Hm, is
pshenoy
2013/08/01 17:26:44
Done.
| |
| 43 }; | |
| 44 | |
| 45 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestDownloadDirPref) { | |
| 46 ASSERT_TRUE(test_server()->Start()); | |
| 47 | |
| 48 DownloadManager* download_manager = | |
| 49 BrowserContext::GetDownloadManager(browser()->profile()); | |
| 50 base::FilePath download_dir = | |
| 51 (DownloadPrefs::FromDownloadManager(download_manager))->DownloadPath(); | |
| 52 base::FilePath new_download_dir = download_dir.AppendASCII("my_downloads"); | |
| 53 base::FilePath downloaded_pkg = | |
| 54 new_download_dir.AppendASCII("a_zip_file.zip"); | |
| 55 | |
| 56 // If the directory exists, delete it. | |
| 57 if (base::PathExists(new_download_dir)) { | |
| 58 base::DeleteFile(new_download_dir, true); | |
| 59 } | |
| 60 | |
| 61 // Create the new downloads directory. | |
| 62 file_util::CreateDirectory(new_download_dir); | |
| 63 // Set pref to download in new_download_dir. | |
| 64 browser()->profile()->GetPrefs()->SetFilePath( | |
| 65 prefs::kDownloadDefaultDirectory, | |
| 66 new_download_dir); | |
| 67 | |
| 68 // Create a downloads observer. | |
| 69 scoped_ptr<content::DownloadTestObserver> downloads_observer( | |
| 70 CreateWaiter(browser(), 1)); | |
| 71 ui_test_utils::NavigateToURL( | |
| 72 browser(), | |
| 73 test_server()->GetURL("files/downloads/a_zip_file.zip")); | |
| 74 // Waits for the download to complete. | |
| 75 downloads_observer->WaitForFinished(); | |
| 76 EXPECT_TRUE(base::PathExists(downloaded_pkg)); | |
| 77 } | |
| 78 | |
| 79 // Verify image content settings show or hide images. | |
| 80 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestImageContentSettings) { | |
| 81 ASSERT_TRUE(test_server()->Start()); | |
| 82 | |
| 83 ui_test_utils::NavigateToURL( | |
| 84 browser(), | |
| 85 test_server()->GetURL("files/settings/image_page.html")); | |
| 86 | |
| 87 bool result = false; | |
| 88 std::string script = | |
| 89 "for (i=0; i < document.images.length; i++) {" | |
| 90 " if ((document.images[i].naturalWidth != 0) &&" | |
| 91 " (document.images[i].naturalHeight != 0)) {" | |
| 92 " window.domAutomationController.send(true);" | |
| 93 " }" | |
| 94 "}" | |
| 95 "window.domAutomationController.send(false);"; | |
| 96 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 97 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 98 script, | |
| 99 &result)); | |
| 100 EXPECT_TRUE(result); | |
| 101 | |
| 102 base::DictionaryValue value; | |
| 103 value.SetInteger("images", 2); | |
| 104 browser()->profile()->GetPrefs()->Set(prefs::kDefaultContentSettings, | |
| 105 value); | |
| 106 | |
| 107 ui_test_utils::NavigateToURL( | |
| 108 browser(), | |
| 109 test_server()->GetURL("files/settings/image_page.html")); | |
| 110 | |
| 111 result = false; | |
| 112 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( | |
| 113 browser()->tab_strip_model()->GetActiveWebContents(), | |
| 114 script, | |
| 115 &result)); | |
| 116 EXPECT_FALSE(result); | |
| 117 } | |
| 118 | |
| 119 // Verify enabling disbling javascript perfs work. | |
|
Bernhard Bauer
2013/08/01 11:38:42
"Verify that enabling/disabling Javascript in pref
pshenoy
2013/08/01 17:26:44
Done.
| |
| 120 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestJavascriptEnableDisable) { | |
| 121 ASSERT_TRUE(test_server()->Start()); | |
| 122 | |
| 123 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | |
| 124 prefs::kWebKitJavascriptEnabled)); | |
| 125 ui_test_utils::NavigateToURL( | |
| 126 browser(), | |
| 127 test_server()->GetURL("files/javaScriptTitle.html")); | |
| 128 EXPECT_EQ(ASCIIToUTF16("Title from script javascript enabled"), | |
| 129 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | |
| 130 browser()->profile()->GetPrefs()->SetBoolean(prefs::kWebKitJavascriptEnabled, | |
| 131 false); | |
| 132 ui_test_utils::NavigateToURL( | |
| 133 browser(), | |
| 134 test_server()->GetURL("files/javaScriptTitle.html")); | |
| 135 EXPECT_EQ(ASCIIToUTF16("This is html title"), | |
| 136 browser()->tab_strip_model()->GetActiveWebContents()->GetTitle()); | |
| 137 } | |
| 138 | |
| 139 // Verify DNS prefetching pref. | |
| 140 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestNetworkPredictionEnabledPref) { | |
| 141 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | |
| 142 prefs::kNetworkPredictionEnabled)); | |
| 143 browser()->profile()->GetPrefs()->SetBoolean(prefs::kNetworkPredictionEnabled, | |
| 144 false); | |
| 145 chrome::Exit(); | |
|
Bernhard Bauer
2013/08/01 11:38:42
Hm, I'm confused -- this is an in-process test, ri
pshenoy
2013/08/01 17:26:44
I'm confused too :-) I wanted to close all browser
Bernhard Bauer
2013/08/01 22:20:07
Well, yes. The test sets a preference and then rea
pshenoy
2013/08/01 23:44:33
I have removed 'chrome::Exit() and chrome::NewWind
Bernhard Bauer
2013/08/02 08:46:12
Use a PRE_ prefix: http://www.chromium.org/develop
pshenoy
2013/08/02 16:36:17
Thank you so much for the information.
| |
| 146 chrome::NewWindow(browser()); | |
| 147 | |
| 148 EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( | |
| 149 prefs::kNetworkPredictionEnabled)); | |
| 150 } | |
| 151 | |
| 152 // Verify toolbar buttons prefs. | |
| 153 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, TestToolbarButtonsPref) { | |
|
Bernhard Bauer
2013/08/01 11:38:42
This doesn't really test much else than the previo
pshenoy
2013/08/01 17:26:44
Done.
| |
| 154 EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( | |
| 155 prefs::kShowHomeButton)); | |
| 156 browser()->profile()->GetPrefs()->SetBoolean(prefs::kShowHomeButton, true); | |
| 157 | |
| 158 chrome::Exit(); | |
| 159 chrome::NewWindow(browser()); | |
| 160 | |
| 161 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | |
| 162 prefs::kShowHomeButton)); | |
| 163 } | |
| 164 | |
| 165 // Verify restore for bookmark bar visibility. | |
| 166 IN_PROC_BROWSER_TEST_F(PrefsFunctionalTest, | |
| 167 TestSessionRestoreShowBookmarkBar) { | |
| 168 EXPECT_FALSE(browser()->profile()->GetPrefs()->GetBoolean( | |
| 169 prefs::kShowBookmarkBar)); | |
| 170 browser()->profile()->GetPrefs()->SetBoolean(prefs::kShowBookmarkBar, true); | |
| 171 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | |
| 172 prefs::kShowBookmarkBar)); | |
| 173 | |
| 174 chrome::Exit(); | |
| 175 chrome::NewWindow(browser()); | |
| 176 | |
| 177 EXPECT_TRUE(browser()->profile()->GetPrefs()->GetBoolean( | |
| 178 prefs::kShowBookmarkBar)); | |
| 179 EXPECT_EQ(BookmarkBar::SHOW, browser()->bookmark_bar_state()); | |
| 180 } | |
| OLD | NEW |