Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(69)

Side by Side Diff: chrome/browser/net/proxy_browsertest.cc

Issue 15665006: Allow specifying proxy scripts using file:// URLs. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add test. Created 7 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | chrome/test/data/bad_server.pac » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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"
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
116 replacements.SetSchemeStr(scheme); 116 replacements.SetSchemeStr(scheme);
117 ui_test_utils::NavigateToURL( 117 ui_test_utils::NavigateToURL(
118 browser(), 118 browser(),
119 ws_server.GetURL("connect_check.html").ReplaceComponents(replacements)); 119 ws_server.GetURL("connect_check.html").ReplaceComponents(replacements));
120 120
121 const string16 result = watcher.WaitAndGetTitle(); 121 const string16 result = watcher.WaitAndGetTitle();
122 EXPECT_TRUE(EqualsASCII(result, "PASS")); 122 EXPECT_TRUE(EqualsASCII(result, "PASS"));
123 EXPECT_TRUE(observer.auth_handled()); 123 EXPECT_TRUE(observer.auth_handled());
124 } 124 }
125 125
126 // PAC script that sends all requests to an invalid proxy server.
127 const base::FilePath::CharType kPACScript[] = FILE_PATH_LITERAL(
James Hawkins 2013/05/29 17:24:33 Optional nit: Move helpers and related constants t
pauljensen 2013/05/29 18:45:15 Done.
128 "bad_server.pac");
129
130 // Verify kPACScript is installed as the PAC script.
131 void VerifyProxyScript(Browser* browser) {
132 content::WebContents* tab =
133 browser->tab_strip_model()->GetActiveWebContents();
134 const char *expected_title = "http://google.com/ is not available";
eroman 2013/05/29 17:45:52 nit: asterisk on the left. nit: [optional] make it
pauljensen 2013/05/29 18:45:15 I deleted this code per mmenke's comment.
135 content::TitleWatcher watcher(tab, ASCIIToUTF16(expected_title));
136 ui_test_utils::NavigateToURL(browser, GURL("http://google.com"));
mmenke 2013/05/29 18:06:25 Not a big fan of depending on UI strings, since I
pauljensen 2013/05/29 18:45:15 Done.
137
138 const string16 title = watcher.WaitAndGetTitle();
139 EXPECT_TRUE(EqualsASCII(title, expected_title));
140 // Verify we get the ERR_PROXY_CONNECTION_FAILED screen.
141 bool result = false;
142 EXPECT_TRUE(content::ExecuteScriptAndExtractBool(
143 browser->tab_strip_model()->GetActiveWebContents(),
144 "var textContent = document.body.textContent;"
145 "var hasError = textContent.indexOf("
146 " 'Unable to connect to the proxy server') >= 0;"
mmenke 2013/05/29 18:06:25 Rather than depend on UI strings, how about search
pauljensen 2013/05/29 18:45:15 I tried that first, but ERR_PROXY_CONNECTION_FAILE
mmenke 2013/05/29 18:47:51 Hmm... textContent includes the entire raw page,
mmenke 2013/05/29 18:50:28 Just tested it manually with ERR_UNSAFE_PORT, and
pauljensen 2013/05/29 18:54:52 Huh, you're right. I've changed it to look for ER
147 "domAutomationController.send(hasError);",
148 &result));
149 EXPECT_TRUE(result);
150 }
151
152 // Fetch PAC script via an http:// URL.
153 class HttpProxyScriptBrowserTest : public InProcessBrowserTest {
154 public:
155 HttpProxyScriptBrowserTest()
156 : http_server_(net::SpawnedTestServer::TYPE_HTTP,
157 net::SpawnedTestServer::kLocalhost,
158 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) {
159 }
160 virtual ~HttpProxyScriptBrowserTest() {}
161
162 virtual void SetUp() OVERRIDE {
163 ASSERT_TRUE(http_server_.Start());
164 InProcessBrowserTest::SetUp();
165 }
166
167 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
168 base::FilePath pac_script_path(FILE_PATH_LITERAL("files"));
169 command_line->AppendSwitchASCII(switches::kProxyPacUrl, http_server_.GetURL(
170 pac_script_path.Append(kPACScript).MaybeAsASCII()).spec());
171 }
172
173 private:
174 net::SpawnedTestServer http_server_;
175
176 DISALLOW_COPY_AND_ASSIGN(HttpProxyScriptBrowserTest);
177 };
178
179 IN_PROC_BROWSER_TEST_F(HttpProxyScriptBrowserTest, Verify) {
180 VerifyProxyScript(browser());
181 }
182
183 // Fetch PAC script via a file:// URL.
184 class FileProxyScriptBrowserTest : public InProcessBrowserTest {
185 public:
186 FileProxyScriptBrowserTest() {}
187 virtual ~FileProxyScriptBrowserTest() {}
188
189 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
190 command_line->AppendSwitchASCII(switches::kProxyPacUrl,
191 ui_test_utils::GetTestUrl(
192 base::FilePath(base::FilePath::kCurrentDirectory),
193 base::FilePath(kPACScript)).spec());
194 }
195
196 private:
197 DISALLOW_COPY_AND_ASSIGN(FileProxyScriptBrowserTest);
198 };
199
200 IN_PROC_BROWSER_TEST_F(FileProxyScriptBrowserTest, Verify) {
201 VerifyProxyScript(browser());
202 }
203
204 // Fetch PAC script via an ftp:// URL.
205 class FtpProxyScriptBrowserTest : public InProcessBrowserTest {
206 public:
207 FtpProxyScriptBrowserTest()
208 : ftp_server_(net::SpawnedTestServer::TYPE_FTP,
209 net::SpawnedTestServer::kLocalhost,
210 base::FilePath(FILE_PATH_LITERAL("chrome/test/data"))) {
211 }
212 virtual ~FtpProxyScriptBrowserTest() {}
213
214 virtual void SetUp() OVERRIDE {
215 ASSERT_TRUE(ftp_server_.Start());
216 InProcessBrowserTest::SetUp();
217 }
218
219 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
220 base::FilePath pac_script_path(kPACScript);
221 command_line->AppendSwitchASCII(
222 switches::kProxyPacUrl,
223 ftp_server_.GetURL(pac_script_path.MaybeAsASCII()).spec());
224 }
225
226 private:
227 net::SpawnedTestServer ftp_server_;
228
229 DISALLOW_COPY_AND_ASSIGN(FtpProxyScriptBrowserTest);
230 };
231
232 IN_PROC_BROWSER_TEST_F(FtpProxyScriptBrowserTest, Verify) {
233 VerifyProxyScript(browser());
234 }
235
236 // Fetch PAC script via a data: URL.
237 class DataProxyScriptBrowserTest : public InProcessBrowserTest {
238 public:
239 DataProxyScriptBrowserTest() {}
240 virtual ~DataProxyScriptBrowserTest() {}
241
242 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
243 std::string contents;
244 // Read in kPACScript contents.
245 ASSERT_TRUE(file_util::ReadFileToString(ui_test_utils::GetTestFilePath(
246 base::FilePath(base::FilePath::kCurrentDirectory),
247 base::FilePath(kPACScript)),
248 &contents));
249 command_line->AppendSwitchASCII(switches::kProxyPacUrl,
250 std::string("data:,") + contents);
251 }
252
253 private:
254 DISALLOW_COPY_AND_ASSIGN(DataProxyScriptBrowserTest);
255 };
256
257 IN_PROC_BROWSER_TEST_F(DataProxyScriptBrowserTest, Verify) {
258 VerifyProxyScript(browser());
259 }
260
126 } // namespace 261 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/io_thread.cc ('k') | chrome/test/data/bad_server.pac » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698