OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/path_service.h" | 6 #include "base/path_service.h" |
7 #include "base/string_util.h" | 7 #include "base/string_util.h" |
8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/login/login_prompt.h" | 11 #include "chrome/browser/ui/login/login_prompt.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_notification_types.h" | 13 #include "chrome/common/chrome_notification_types.h" |
14 #include "chrome/common/chrome_paths.h" | 14 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
16 #include "chrome/common/pref_names.h" | 16 #include "chrome/common/pref_names.h" |
17 #include "chrome/test/base/in_process_browser_test.h" | 17 #include "chrome/test/base/in_process_browser_test.h" |
18 #include "chrome/test/base/ui_test_utils.h" | 18 #include "chrome/test/base/ui_test_utils.h" |
19 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_source.h" | 20 #include "content/public/browser/notification_source.h" |
21 #include "content/public/browser/web_contents.h" | 21 #include "content/public/browser/web_contents.h" |
22 #include "content/public/browser/web_contents_observer.h" | 22 #include "content/public/browser/web_contents_observer.h" |
23 #include "content/public/test/browser_test_utils.h" | 23 #include "content/public/test/browser_test_utils.h" |
24 #include "net/base/test_data_directory.h" | 24 #include "net/base/test_data_directory.h" |
25 #include "net/test/spawned_test_server/spawned_test_server.h" | 25 #include "net/test/spawned_test_server/spawned_test_server.h" |
26 | 26 |
27 namespace { | 27 namespace { |
28 | 28 |
| 29 // PAC script that sends all requests to an invalid proxy server. |
| 30 const base::FilePath::CharType kPACScript[] = FILE_PATH_LITERAL( |
| 31 "bad_server.pac"); |
| 32 |
| 33 // Verify kPACScript is installed as the PAC script. |
| 34 void VerifyProxyScript(Browser* browser) { |
| 35 ui_test_utils::NavigateToURL(browser, GURL("http://google.com")); |
| 36 |
| 37 // Verify we get the ERR_PROXY_CONNECTION_FAILED screen. |
| 38 bool result = false; |
| 39 EXPECT_TRUE(content::ExecuteScriptAndExtractBool( |
| 40 browser->tab_strip_model()->GetActiveWebContents(), |
| 41 "var textContent = document.body.textContent;" |
| 42 "var hasError = textContent.indexOf('ERR_PROXY_CONNECTION_FAILED') >= 0;" |
| 43 "domAutomationController.send(hasError);", |
| 44 &result)); |
| 45 EXPECT_TRUE(result); |
| 46 } |
| 47 |
29 // This class observes chrome::NOTIFICATION_AUTH_NEEDED and supplies | 48 // This class observes chrome::NOTIFICATION_AUTH_NEEDED and supplies |
30 // the credential which is required by the test proxy server. | 49 // the credential which is required by the test proxy server. |
31 // "foo:bar" is the required username and password for our test proxy server. | 50 // "foo:bar" is the required username and password for our test proxy server. |
32 class LoginPromptObserver : public content::NotificationObserver { | 51 class LoginPromptObserver : public content::NotificationObserver { |
33 public: | 52 public: |
34 LoginPromptObserver() : auth_handled_(false) {} | 53 LoginPromptObserver() : auth_handled_(false) {} |
35 | 54 |
36 virtual void Observe(int type, | 55 virtual void Observe(int type, |
37 const content::NotificationSource& source, | 56 const content::NotificationSource& source, |
38 const content::NotificationDetails& details) OVERRIDE { | 57 const content::NotificationDetails& details) OVERRIDE { |
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 replacements.SetSchemeStr(scheme); | 135 replacements.SetSchemeStr(scheme); |
117 ui_test_utils::NavigateToURL( | 136 ui_test_utils::NavigateToURL( |
118 browser(), | 137 browser(), |
119 ws_server.GetURL("connect_check.html").ReplaceComponents(replacements)); | 138 ws_server.GetURL("connect_check.html").ReplaceComponents(replacements)); |
120 | 139 |
121 const string16 result = watcher.WaitAndGetTitle(); | 140 const string16 result = watcher.WaitAndGetTitle(); |
122 EXPECT_TRUE(EqualsASCII(result, "PASS")); | 141 EXPECT_TRUE(EqualsASCII(result, "PASS")); |
123 EXPECT_TRUE(observer.auth_handled()); | 142 EXPECT_TRUE(observer.auth_handled()); |
124 } | 143 } |
125 | 144 |
| 145 // Fetch PAC script via an http:// URL. |
| 146 class HttpProxyScriptBrowserTest : public InProcessBrowserTest { |
| 147 public: |
| 148 HttpProxyScriptBrowserTest() |
| 149 : http_server_(net::SpawnedTestServer::TYPE_HTTP, |
| 150 net::SpawnedTestServer::kLocalhost, |
| 151 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { |
| 152 } |
| 153 virtual ~HttpProxyScriptBrowserTest() {} |
| 154 |
| 155 virtual void SetUp() OVERRIDE { |
| 156 ASSERT_TRUE(http_server_.Start()); |
| 157 InProcessBrowserTest::SetUp(); |
| 158 } |
| 159 |
| 160 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 161 base::FilePath pac_script_path(FILE_PATH_LITERAL("files")); |
| 162 command_line->AppendSwitchASCII(switches::kProxyPacUrl, http_server_.GetURL( |
| 163 pac_script_path.Append(kPACScript).MaybeAsASCII()).spec()); |
| 164 } |
| 165 |
| 166 private: |
| 167 net::SpawnedTestServer http_server_; |
| 168 |
| 169 DISALLOW_COPY_AND_ASSIGN(HttpProxyScriptBrowserTest); |
| 170 }; |
| 171 |
| 172 IN_PROC_BROWSER_TEST_F(HttpProxyScriptBrowserTest, Verify) { |
| 173 VerifyProxyScript(browser()); |
| 174 } |
| 175 |
| 176 // Fetch PAC script via a file:// URL. |
| 177 class FileProxyScriptBrowserTest : public InProcessBrowserTest { |
| 178 public: |
| 179 FileProxyScriptBrowserTest() {} |
| 180 virtual ~FileProxyScriptBrowserTest() {} |
| 181 |
| 182 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 183 command_line->AppendSwitchASCII(switches::kProxyPacUrl, |
| 184 ui_test_utils::GetTestUrl( |
| 185 base::FilePath(base::FilePath::kCurrentDirectory), |
| 186 base::FilePath(kPACScript)).spec()); |
| 187 } |
| 188 |
| 189 private: |
| 190 DISALLOW_COPY_AND_ASSIGN(FileProxyScriptBrowserTest); |
| 191 }; |
| 192 |
| 193 IN_PROC_BROWSER_TEST_F(FileProxyScriptBrowserTest, Verify) { |
| 194 VerifyProxyScript(browser()); |
| 195 } |
| 196 |
| 197 // Fetch PAC script via an ftp:// URL. |
| 198 class FtpProxyScriptBrowserTest : public InProcessBrowserTest { |
| 199 public: |
| 200 FtpProxyScriptBrowserTest() |
| 201 : ftp_server_(net::SpawnedTestServer::TYPE_FTP, |
| 202 net::SpawnedTestServer::kLocalhost, |
| 203 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) { |
| 204 } |
| 205 virtual ~FtpProxyScriptBrowserTest() {} |
| 206 |
| 207 virtual void SetUp() OVERRIDE { |
| 208 ASSERT_TRUE(ftp_server_.Start()); |
| 209 InProcessBrowserTest::SetUp(); |
| 210 } |
| 211 |
| 212 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 213 base::FilePath pac_script_path(kPACScript); |
| 214 command_line->AppendSwitchASCII( |
| 215 switches::kProxyPacUrl, |
| 216 ftp_server_.GetURL(pac_script_path.MaybeAsASCII()).spec()); |
| 217 } |
| 218 |
| 219 private: |
| 220 net::SpawnedTestServer ftp_server_; |
| 221 |
| 222 DISALLOW_COPY_AND_ASSIGN(FtpProxyScriptBrowserTest); |
| 223 }; |
| 224 |
| 225 IN_PROC_BROWSER_TEST_F(FtpProxyScriptBrowserTest, Verify) { |
| 226 VerifyProxyScript(browser()); |
| 227 } |
| 228 |
| 229 // Fetch PAC script via a data: URL. |
| 230 class DataProxyScriptBrowserTest : public InProcessBrowserTest { |
| 231 public: |
| 232 DataProxyScriptBrowserTest() {} |
| 233 virtual ~DataProxyScriptBrowserTest() {} |
| 234 |
| 235 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
| 236 std::string contents; |
| 237 // Read in kPACScript contents. |
| 238 ASSERT_TRUE(file_util::ReadFileToString(ui_test_utils::GetTestFilePath( |
| 239 base::FilePath(base::FilePath::kCurrentDirectory), |
| 240 base::FilePath(kPACScript)), |
| 241 &contents)); |
| 242 command_line->AppendSwitchASCII(switches::kProxyPacUrl, |
| 243 std::string("data:,") + contents); |
| 244 } |
| 245 |
| 246 private: |
| 247 DISALLOW_COPY_AND_ASSIGN(DataProxyScriptBrowserTest); |
| 248 }; |
| 249 |
| 250 IN_PROC_BROWSER_TEST_F(DataProxyScriptBrowserTest, Verify) { |
| 251 VerifyProxyScript(browser()); |
| 252 } |
| 253 |
126 } // namespace | 254 } // namespace |
OLD | NEW |