blob: 29813acc6c56c1e6c358b7b8dc52094759d5050a [file] [log] [blame]
[email protected]db8ff912012-06-12 23:32:511// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]5b45aec02009-03-31 01:03:232// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
Lily Houghton582d4622018-01-22 22:43:405#include "net/proxy_resolution/proxy_config.h"
Eric Roman4c0456a2019-09-18 17:04:346#include "base/json/json_writer.h"
Avi Drissman4365a4782018-12-28 19:26:247#include "base/stl_util.h"
Eric Roman4c0456a2019-09-18 17:04:348#include "base/values.h"
Lily Houghton582d4622018-01-22 22:43:409#include "net/proxy_resolution/proxy_config_service_common_unittest.h"
10#include "net/proxy_resolution/proxy_info.h"
[email protected]5b45aec02009-03-31 01:03:2311#include "testing/gtest/include/gtest/gtest.h"
12
[email protected]3dfd29f2009-09-06 00:48:3713namespace net {
[email protected]5b45aec02009-03-31 01:03:2314namespace {
[email protected]3dfd29f2009-09-06 00:48:3715
16void ExpectProxyServerEquals(const char* expectation,
[email protected]2189e092013-03-16 18:02:0217 const ProxyList& proxy_servers) {
Raul Tambre94493c652019-03-11 17:18:3518 if (expectation == nullptr) {
[email protected]2189e092013-03-16 18:02:0219 EXPECT_TRUE(proxy_servers.IsEmpty());
[email protected]5b45aec02009-03-31 01:03:2320 } else {
[email protected]2189e092013-03-16 18:02:0221 EXPECT_EQ(expectation, proxy_servers.ToPacString());
[email protected]5b45aec02009-03-31 01:03:2322 }
23}
[email protected]5b45aec02009-03-31 01:03:2324
25TEST(ProxyConfigTest, Equals) {
26 // Test |ProxyConfig::auto_detect|.
27
[email protected]3dfd29f2009-09-06 00:48:3728 ProxyConfig config1;
[email protected]ed4ed0f2010-02-24 00:20:4829 config1.set_auto_detect(true);
[email protected]5b45aec02009-03-31 01:03:2330
[email protected]3dfd29f2009-09-06 00:48:3731 ProxyConfig config2;
[email protected]ed4ed0f2010-02-24 00:20:4832 config2.set_auto_detect(false);
[email protected]5b45aec02009-03-31 01:03:2333
34 EXPECT_FALSE(config1.Equals(config2));
35 EXPECT_FALSE(config2.Equals(config1));
36
[email protected]ed4ed0f2010-02-24 00:20:4837 config2.set_auto_detect(true);
[email protected]5b45aec02009-03-31 01:03:2338
39 EXPECT_TRUE(config1.Equals(config2));
40 EXPECT_TRUE(config2.Equals(config1));
41
42 // Test |ProxyConfig::pac_url|.
43
[email protected]ed4ed0f2010-02-24 00:20:4844 config2.set_pac_url(GURL("http://wpad/wpad.dat"));
[email protected]5b45aec02009-03-31 01:03:2345
46 EXPECT_FALSE(config1.Equals(config2));
47 EXPECT_FALSE(config2.Equals(config1));
48
[email protected]ed4ed0f2010-02-24 00:20:4849 config1.set_pac_url(GURL("http://wpad/wpad.dat"));
[email protected]5b45aec02009-03-31 01:03:2350
51 EXPECT_TRUE(config1.Equals(config2));
52 EXPECT_TRUE(config2.Equals(config1));
53
54 // Test |ProxyConfig::proxy_rules|.
55
Lily Houghtone6b617e2018-01-19 20:13:0756 config2.proxy_rules().type = ProxyConfig::ProxyRules::Type::PROXY_LIST;
[email protected]2189e092013-03-16 18:02:0257 config2.proxy_rules().single_proxies.SetSingleProxyServer(
58 ProxyServer::FromURI("myproxy:80", ProxyServer::SCHEME_HTTP));
[email protected]5b45aec02009-03-31 01:03:2359
60 EXPECT_FALSE(config1.Equals(config2));
61 EXPECT_FALSE(config2.Equals(config1));
62
Lily Houghtone6b617e2018-01-19 20:13:0763 config1.proxy_rules().type = ProxyConfig::ProxyRules::Type::PROXY_LIST;
[email protected]2189e092013-03-16 18:02:0264 config1.proxy_rules().single_proxies.SetSingleProxyServer(
65 ProxyServer::FromURI("myproxy:100", ProxyServer::SCHEME_HTTP));
[email protected]5b45aec02009-03-31 01:03:2366
67 EXPECT_FALSE(config1.Equals(config2));
68 EXPECT_FALSE(config2.Equals(config1));
69
[email protected]2189e092013-03-16 18:02:0270 config1.proxy_rules().single_proxies.SetSingleProxyServer(
71 ProxyServer::FromURI("myproxy", ProxyServer::SCHEME_HTTP));
[email protected]5b45aec02009-03-31 01:03:2372
73 EXPECT_TRUE(config1.Equals(config2));
74 EXPECT_TRUE(config2.Equals(config1));
75
[email protected]7541206c2010-02-19 20:24:0676 // Test |ProxyConfig::bypass_rules|.
[email protected]5b45aec02009-03-31 01:03:2377
[email protected]ed4ed0f2010-02-24 00:20:4878 config2.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
[email protected]5b45aec02009-03-31 01:03:2379
80 EXPECT_FALSE(config1.Equals(config2));
81 EXPECT_FALSE(config2.Equals(config1));
82
[email protected]ed4ed0f2010-02-24 00:20:4883 config1.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
[email protected]5b45aec02009-03-31 01:03:2384
85 EXPECT_TRUE(config1.Equals(config2));
86 EXPECT_TRUE(config2.Equals(config1));
[email protected]a48bf4a2010-06-14 18:24:5387
88 // Test |ProxyConfig::proxy_rules.reverse_bypass|.
89
90 config2.proxy_rules().reverse_bypass = true;
91
92 EXPECT_FALSE(config1.Equals(config2));
93 EXPECT_FALSE(config2.Equals(config1));
94
95 config1.proxy_rules().reverse_bypass = true;
96
97 EXPECT_TRUE(config1.Equals(config2));
98 EXPECT_TRUE(config2.Equals(config1));
[email protected]5b45aec02009-03-31 01:03:2399}
100
Eric Roman4c0456a2019-09-18 17:04:34101struct ProxyConfigToValueTestCase {
102 ProxyConfig config;
103 const char* expected_value_json;
104};
105
106class ProxyConfigToValueTest
107 : public ::testing::TestWithParam<ProxyConfigToValueTestCase> {};
108
109TEST_P(ProxyConfigToValueTest, ToValueJSON) {
110 const ProxyConfigToValueTestCase& test_case = GetParam();
111
112 base::Value value = test_case.config.ToValue();
113
114 std::string json_string;
115 ASSERT_TRUE(base::JSONWriter::Write(value, &json_string));
116
117 EXPECT_EQ(std::string(test_case.expected_value_json), json_string);
118}
119
120ProxyConfigToValueTestCase GetTestCaseDirect() {
121 return {ProxyConfig::CreateDirect(), "{}"};
122}
123
124ProxyConfigToValueTestCase GetTestCaseAutoDetect() {
125 return {ProxyConfig::CreateAutoDetect(), "{\"auto_detect\":true}"};
126}
127
128ProxyConfigToValueTestCase GetTestCasePacUrl() {
129 ProxyConfig config;
130 config.set_pac_url(GURL("http://www.example.com/test.pac"));
131
132 return {std::move(config),
133 "{\"pac_url\":\"http://www.example.com/test.pac\"}"};
134}
135
136ProxyConfigToValueTestCase GetTestCasePacUrlMandatory() {
137 ProxyConfig config;
138 config.set_pac_url(GURL("http://www.example.com/test.pac"));
139 config.set_pac_mandatory(true);
140
141 return {std::move(config),
142 "{\"pac_mandatory\":true,\"pac_url\":\"http://www.example.com/"
143 "test.pac\"}"};
144}
145
146ProxyConfigToValueTestCase GetTestCasePacUrlAndAutoDetect() {
147 ProxyConfig config = ProxyConfig::CreateAutoDetect();
148 config.set_pac_url(GURL("http://www.example.com/test.pac"));
149
150 return {
151 std::move(config),
152 "{\"auto_detect\":true,\"pac_url\":\"http://www.example.com/test.pac\"}"};
153}
154
155ProxyConfigToValueTestCase GetTestCaseSingleProxy() {
156 ProxyConfig config;
157 config.proxy_rules().ParseFromString("https://proxy1:8080");
158
159 return {std::move(config), "{\"single_proxy\":[\"https://proxy1:8080\"]}"};
160}
161
162ProxyConfigToValueTestCase GetTestCaseSingleProxyWithBypass() {
163 ProxyConfig config;
164 config.proxy_rules().ParseFromString("https://proxy1:8080");
165 config.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
166 config.proxy_rules().bypass_rules.AddRuleFromString("192.168.0.1/16");
167
168 return {std::move(config),
169 "{\"bypass_list\":[\"*.google.com\",\"192.168.0.1/"
170 "16\"],\"single_proxy\":[\"https://proxy1:8080\"]}"};
171}
172
173ProxyConfigToValueTestCase GetTestCaseSingleProxyWithReversedBypass() {
174 ProxyConfig config;
175 config.proxy_rules().ParseFromString("https://proxy1:8080");
176 config.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
177 config.proxy_rules().reverse_bypass = true;
178
179 return {std::move(config),
180 "{\"bypass_list\":[\"*.google.com\"],\"reverse_bypass\":true,"
181 "\"single_proxy\":[\"https://proxy1:8080\"]}"};
182}
183
184ProxyConfigToValueTestCase GetTestCaseProxyPerScheme() {
185 ProxyConfig config;
186 config.proxy_rules().ParseFromString(
187 "http=https://proxy1:8080;https=socks5://proxy2");
188 config.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
189 config.set_pac_url(GURL("http://wpad/wpad.dat"));
190 config.set_auto_detect(true);
191
192 return {
193 std::move(config),
194 "{\"auto_detect\":true,\"bypass_list\":[\"*.google.com\"],\"pac_url\":"
195 "\"http://wpad/wpad.dat\",\"proxy_per_scheme\":{\"http\":[\"https://"
196 "proxy1:8080\"],\"https\":[\"socks5://proxy2:1080\"]}}"};
197}
198
199ProxyConfigToValueTestCase GetTestCaseSingleProxyList() {
200 ProxyConfig config;
201 config.proxy_rules().ParseFromString(
202 "https://proxy1:8080,http://proxy2,direct://");
203
204 return {std::move(config),
205 "{\"single_proxy\":[\"https://proxy1:8080\",\"proxy2:80\",\"direct://"
206 "\"]}"};
207}
208
209INSTANTIATE_TEST_SUITE_P(
210 ,
211 ProxyConfigToValueTest,
212 testing::Values(GetTestCaseDirect(),
213 GetTestCaseAutoDetect(),
214 GetTestCasePacUrl(),
215 GetTestCasePacUrlMandatory(),
216 GetTestCasePacUrlAndAutoDetect(),
217 GetTestCaseSingleProxy(),
218 GetTestCaseSingleProxyWithBypass(),
219 GetTestCaseSingleProxyWithReversedBypass(),
220 GetTestCaseProxyPerScheme(),
221 GetTestCaseSingleProxyList()));
222
[email protected]5b45aec02009-03-31 01:03:23223TEST(ProxyConfigTest, ParseProxyRules) {
224 const struct {
225 const char* proxy_rules;
226
[email protected]3dfd29f2009-09-06 00:48:37227 ProxyConfig::ProxyRules::Type type;
[email protected]2189e092013-03-16 18:02:02228 // These will be PAC-stle strings, eg 'PROXY foo.com'
[email protected]5b45aec02009-03-31 01:03:23229 const char* single_proxy;
230 const char* proxy_for_http;
231 const char* proxy_for_https;
232 const char* proxy_for_ftp;
[email protected]2b6ed3dc2010-08-25 06:03:48233 const char* fallback_proxy;
[email protected]5b45aec02009-03-31 01:03:23234 } tests[] = {
Raul Tambre94493c652019-03-11 17:18:35235 // One HTTP proxy for all schemes.
236 {
237 "myproxy:80",
[email protected]5b45aec02009-03-31 01:03:23238
Raul Tambre94493c652019-03-11 17:18:35239 ProxyConfig::ProxyRules::Type::PROXY_LIST,
240 "PROXY myproxy:80",
241 nullptr,
242 nullptr,
243 nullptr,
244 nullptr,
[email protected]87a102b2009-07-14 05:23:30245 },
246
Raul Tambre94493c652019-03-11 17:18:35247 // Multiple HTTP proxies for all schemes.
248 {
249 "myproxy:80,https://myotherproxy",
[email protected]87a102b2009-07-14 05:23:30250
Raul Tambre94493c652019-03-11 17:18:35251 ProxyConfig::ProxyRules::Type::PROXY_LIST,
252 "PROXY myproxy:80;HTTPS myotherproxy:443",
253 nullptr,
254 nullptr,
255 nullptr,
256 nullptr,
[email protected]87a102b2009-07-14 05:23:30257 },
258
Raul Tambre94493c652019-03-11 17:18:35259 // Only specify a proxy server for "http://" urls.
260 {
261 "http=myproxy:80",
[email protected]5b45aec02009-03-31 01:03:23262
Raul Tambre94493c652019-03-11 17:18:35263 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
264 nullptr,
265 "PROXY myproxy:80",
266 nullptr,
267 nullptr,
268 nullptr,
269 },
[email protected]2189e092013-03-16 18:02:02270
Raul Tambre94493c652019-03-11 17:18:35271 // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://"
272 // urls.
273 {
274 "ftp=ftp-proxy ; https=socks4://foopy",
[email protected]2189e092013-03-16 18:02:02275
Raul Tambre94493c652019-03-11 17:18:35276 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
277 nullptr,
278 nullptr,
279 "SOCKS foopy:1080",
280 "PROXY ftp-proxy:80",
281 nullptr,
282 },
[email protected]2189e092013-03-16 18:02:02283
Raul Tambre94493c652019-03-11 17:18:35284 // Give a scheme-specific proxy as well as a non-scheme specific.
285 // The first entry "foopy" takes precedance marking this list as
286 // Type::PROXY_LIST.
287 {
288 "foopy ; ftp=ftp-proxy",
[email protected]2189e092013-03-16 18:02:02289
Raul Tambre94493c652019-03-11 17:18:35290 ProxyConfig::ProxyRules::Type::PROXY_LIST,
291 "PROXY foopy:80",
292 nullptr,
293 nullptr,
294 nullptr,
295 nullptr,
296 },
297
298 // Give a scheme-specific proxy as well as a non-scheme specific.
299 // The first entry "ftp=ftp-proxy" takes precedance marking this list as
300 // Type::PROXY_LIST_PER_SCHEME.
301 {
302 "ftp=ftp-proxy ; foopy",
303
304 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
305 nullptr,
306 nullptr,
307 nullptr,
308 "PROXY ftp-proxy:80",
309 nullptr,
310 },
311
312 // Include a list of entries for a single scheme.
313 {
314 "ftp=ftp1,ftp2,ftp3",
315
316 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
317 nullptr,
318 nullptr,
319 nullptr,
320 "PROXY ftp1:80;PROXY ftp2:80;PROXY ftp3:80",
321 nullptr,
322 },
323
324 // Include multiple entries for the same scheme -- they accumulate.
325 {
326 "http=http1,http2; http=http3",
327
328 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
329 nullptr,
330 "PROXY http1:80;PROXY http2:80;PROXY http3:80",
331 nullptr,
332 nullptr,
333 nullptr,
334 },
335
336 // Include lists of entries for multiple schemes.
337 {
338 "ftp=ftp1,ftp2,ftp3 ; http=http1,http2; ",
339
340 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
341 nullptr,
342 "PROXY http1:80;PROXY http2:80",
343 nullptr,
344 "PROXY ftp1:80;PROXY ftp2:80;PROXY ftp3:80",
345 nullptr,
346 },
347
348 // Include non-default proxy schemes.
349 {
350 "http=https://secure_proxy; ftp=socks4://socks_proxy; "
351 "https=socks://foo",
352
353 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
354 nullptr,
355 "HTTPS secure_proxy:443",
356 "SOCKS5 foo:1080",
357 "SOCKS socks_proxy:1080",
358 nullptr,
359 },
360
361 // Only SOCKS proxy present, others being blank.
362 {
363 "socks=foopy",
364
365 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
366 nullptr,
367 nullptr,
368 nullptr,
369 nullptr,
370 "SOCKS foopy:1080",
371 },
372
373 // SOCKS proxy present along with other proxies too
374 {
375 "http=httpproxy ; https=httpsproxy ; ftp=ftpproxy ; socks=foopy ",
376
377 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
378 nullptr,
379 "PROXY httpproxy:80",
380 "PROXY httpsproxy:80",
381 "PROXY ftpproxy:80",
382 "SOCKS foopy:1080",
383 },
384
385 // SOCKS proxy (with modifier) present along with some proxies
386 // (FTP being blank)
387 {
388 "http=httpproxy ; https=httpsproxy ; socks=socks5://foopy ",
389
390 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
391 nullptr,
392 "PROXY httpproxy:80",
393 "PROXY httpsproxy:80",
394 nullptr,
395 "SOCKS5 foopy:1080",
396 },
397
398 // Include unsupported schemes -- they are discarded.
399 {
400 "crazy=foopy ; foo=bar ; https=myhttpsproxy",
401
402 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
403 nullptr,
404 nullptr,
405 "PROXY myhttpsproxy:80",
406 nullptr,
407 nullptr,
408 },
409
410 // direct:// as first option for a scheme.
411 {
412 "http=direct://,myhttpproxy; https=direct://",
413
414 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
415 nullptr,
416 "DIRECT;PROXY myhttpproxy:80",
417 "DIRECT",
418 nullptr,
419 nullptr,
420 },
421
422 // direct:// as a second option for a scheme.
423 {
424 "http=myhttpproxy,direct://",
425
426 ProxyConfig::ProxyRules::Type::PROXY_LIST_PER_SCHEME,
427 nullptr,
428 "PROXY myhttpproxy:80;DIRECT",
429 nullptr,
430 nullptr,
431 nullptr,
432 },
[email protected]2189e092013-03-16 18:02:02433
[email protected]5b45aec02009-03-31 01:03:23434 };
435
[email protected]3dfd29f2009-09-06 00:48:37436 ProxyConfig config;
[email protected]5b45aec02009-03-31 01:03:23437
Avi Drissman4365a4782018-12-28 19:26:24438 for (size_t i = 0; i < base::size(tests); ++i) {
[email protected]ed4ed0f2010-02-24 00:20:48439 config.proxy_rules().ParseFromString(tests[i].proxy_rules);
[email protected]5b45aec02009-03-31 01:03:23440
[email protected]ed4ed0f2010-02-24 00:20:48441 EXPECT_EQ(tests[i].type, config.proxy_rules().type);
[email protected]5b45aec02009-03-31 01:03:23442 ExpectProxyServerEquals(tests[i].single_proxy,
[email protected]2189e092013-03-16 18:02:02443 config.proxy_rules().single_proxies);
[email protected]5b45aec02009-03-31 01:03:23444 ExpectProxyServerEquals(tests[i].proxy_for_http,
[email protected]2189e092013-03-16 18:02:02445 config.proxy_rules().proxies_for_http);
[email protected]5b45aec02009-03-31 01:03:23446 ExpectProxyServerEquals(tests[i].proxy_for_https,
[email protected]2189e092013-03-16 18:02:02447 config.proxy_rules().proxies_for_https);
[email protected]5b45aec02009-03-31 01:03:23448 ExpectProxyServerEquals(tests[i].proxy_for_ftp,
[email protected]2189e092013-03-16 18:02:02449 config.proxy_rules().proxies_for_ftp);
[email protected]2b6ed3dc2010-08-25 06:03:48450 ExpectProxyServerEquals(tests[i].fallback_proxy,
[email protected]2189e092013-03-16 18:02:02451 config.proxy_rules().fallback_proxies);
[email protected]5b45aec02009-03-31 01:03:23452 }
453}
[email protected]ab501a6a2009-05-12 15:07:50454
[email protected]db8ff912012-06-12 23:32:51455TEST(ProxyConfigTest, ProxyRulesSetBypassFlag) {
456 // Test whether the did_bypass_proxy() flag is set in proxy info correctly.
457 ProxyConfig::ProxyRules rules;
458 ProxyInfo result;
459
460 rules.ParseFromString("http=httpproxy:80");
461 rules.bypass_rules.AddRuleFromString(".com");
462
463 rules.Apply(GURL("http://example.com"), &result);
464 EXPECT_TRUE(result.is_direct_only());
465 EXPECT_TRUE(result.did_bypass_proxy());
466
467 rules.Apply(GURL("http://example.org"), &result);
468 EXPECT_FALSE(result.is_direct());
469 EXPECT_FALSE(result.did_bypass_proxy());
470
471 // Try with reversed bypass rules.
472 rules.reverse_bypass = true;
473
474 rules.Apply(GURL("http://example.org"), &result);
475 EXPECT_TRUE(result.is_direct_only());
476 EXPECT_TRUE(result.did_bypass_proxy());
477
478 rules.Apply(GURL("http://example.com"), &result);
479 EXPECT_FALSE(result.is_direct());
480 EXPECT_FALSE(result.did_bypass_proxy());
481}
482
riceabec95602014-10-30 05:05:07483static const char kWsUrl[] = "ws://example.com/echo";
484static const char kWssUrl[] = "wss://example.com/echo";
485
486class ProxyConfigWebSocketTest : public ::testing::Test {
487 protected:
488 void ParseFromString(const std::string& rules) {
489 rules_.ParseFromString(rules);
490 }
491 void Apply(const GURL& gurl) { rules_.Apply(gurl, &info_); }
492 std::string ToPacString() const { return info_.ToPacString(); }
493
494 static GURL WsUrl() { return GURL(kWsUrl); }
495 static GURL WssUrl() { return GURL(kWssUrl); }
496
497 ProxyConfig::ProxyRules rules_;
498 ProxyInfo info_;
499};
500
501// If a single proxy is set for all protocols, WebSocket uses it.
502TEST_F(ProxyConfigWebSocketTest, UsesProxy) {
503 ParseFromString("proxy:3128");
504 Apply(WsUrl());
505 EXPECT_EQ("PROXY proxy:3128", ToPacString());
506}
507
508// See RFC6455 Section 4.1. item 3, "_Proxy Usage_".
509TEST_F(ProxyConfigWebSocketTest, PrefersSocks) {
510 ParseFromString(
511 "http=proxy:3128 ; https=sslproxy:3128 ; socks=socksproxy:1080");
512 Apply(WsUrl());
513 EXPECT_EQ("SOCKS socksproxy:1080", ToPacString());
514}
515
516TEST_F(ProxyConfigWebSocketTest, PrefersHttpsToHttp) {
517 ParseFromString("http=proxy:3128 ; https=sslproxy:3128");
518 Apply(WssUrl());
519 EXPECT_EQ("PROXY sslproxy:3128", ToPacString());
520}
521
522TEST_F(ProxyConfigWebSocketTest, PrefersHttpsEvenForWs) {
523 ParseFromString("http=proxy:3128 ; https=sslproxy:3128");
524 Apply(WsUrl());
525 EXPECT_EQ("PROXY sslproxy:3128", ToPacString());
526}
527
528TEST_F(ProxyConfigWebSocketTest, PrefersHttpToDirect) {
529 ParseFromString("http=proxy:3128");
530 Apply(WssUrl());
531 EXPECT_EQ("PROXY proxy:3128", ToPacString());
532}
533
534TEST_F(ProxyConfigWebSocketTest, IgnoresFtpProxy) {
535 ParseFromString("ftp=ftpproxy:3128");
536 Apply(WssUrl());
537 EXPECT_EQ("DIRECT", ToPacString());
538}
539
540TEST_F(ProxyConfigWebSocketTest, ObeysBypassRules) {
541 ParseFromString("http=proxy:3128 ; https=sslproxy:3128");
542 rules_.bypass_rules.AddRuleFromString(".chromium.org");
543 Apply(GURL("wss://codereview.chromium.org/feed"));
544 EXPECT_EQ("DIRECT", ToPacString());
545}
546
547TEST_F(ProxyConfigWebSocketTest, ObeysLocalBypass) {
548 ParseFromString("http=proxy:3128 ; https=sslproxy:3128");
549 rules_.bypass_rules.AddRuleFromString("<local>");
550 Apply(GURL("ws://localhost/feed"));
551 EXPECT_EQ("DIRECT", ToPacString());
552}
553
[email protected]3dfd29f2009-09-06 00:48:37554} // namespace
555} // namespace net