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

Side by Side Diff: net/proxy/proxy_service_unittest.cc

Issue 525104: Adds a NetworkChangeNotifier dependency to ProxyService; when we observer a n... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Add a test_shell file Created 10 years, 11 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 | « net/proxy/proxy_service.cc ('k') | webkit/tools/test_shell/test_shell_request_context.cc » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 "net/proxy/proxy_service.h" 5 #include "net/proxy/proxy_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
11 #include "base/string_util.h" 11 #include "base/string_util.h"
12 #include "googleurl/src/gurl.h" 12 #include "googleurl/src/gurl.h"
13 #include "net/base/load_log.h" 13 #include "net/base/load_log.h"
14 #include "net/base/load_log_unittest.h" 14 #include "net/base/load_log_unittest.h"
15 #include "net/base/mock_network_change_notifier.h"
15 #include "net/base/net_errors.h" 16 #include "net/base/net_errors.h"
16 #include "net/base/test_completion_callback.h" 17 #include "net/base/test_completion_callback.h"
17 #include "net/proxy/mock_proxy_resolver.h" 18 #include "net/proxy/mock_proxy_resolver.h"
18 #include "net/proxy/proxy_config_service.h" 19 #include "net/proxy/proxy_config_service.h"
19 #include "net/proxy/proxy_resolver.h" 20 #include "net/proxy/proxy_resolver.h"
20 #include "net/proxy/proxy_script_fetcher.h" 21 #include "net/proxy/proxy_script_fetcher.h"
21 #include "testing/gtest/include/gtest/gtest.h" 22 #include "testing/gtest/include/gtest/gtest.h"
22 23
23 // TODO(eroman): Write a test which exercises 24 // TODO(eroman): Write a test which exercises
24 // ProxyService::SuspendAllPendingRequests(). 25 // ProxyService::SuspendAllPendingRequests().
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
84 85
85 private: 86 private:
86 GURL pending_request_url_; 87 GURL pending_request_url_;
87 CompletionCallback* pending_request_callback_; 88 CompletionCallback* pending_request_callback_;
88 std::string* pending_request_bytes_; 89 std::string* pending_request_bytes_;
89 }; 90 };
90 91
91 TEST(ProxyServiceTest, Direct) { 92 TEST(ProxyServiceTest, Direct) {
92 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 93 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
93 scoped_refptr<ProxyService> service( 94 scoped_refptr<ProxyService> service(
94 new ProxyService(new MockProxyConfigService, resolver)); 95 new ProxyService(new MockProxyConfigService, resolver, NULL));
95 96
96 GURL url("http://www.google.com/"); 97 GURL url("http://www.google.com/");
97 98
98 ProxyInfo info; 99 ProxyInfo info;
99 TestCompletionCallback callback; 100 TestCompletionCallback callback;
100 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); 101 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
101 int rv = service->ResolveProxy(url, &info, &callback, NULL, log); 102 int rv = service->ResolveProxy(url, &info, &callback, NULL, log);
102 EXPECT_EQ(OK, rv); 103 EXPECT_EQ(OK, rv);
103 EXPECT_TRUE(resolver->pending_requests().empty()); 104 EXPECT_TRUE(resolver->pending_requests().empty());
104 EXPECT_TRUE(NULL == service->init_proxy_resolver_log()); 105 EXPECT_TRUE(NULL == service->init_proxy_resolver_log());
105 106
106 EXPECT_TRUE(info.is_direct()); 107 EXPECT_TRUE(info.is_direct());
107 108
108 // Check the LoadLog was filled correctly. 109 // Check the LoadLog was filled correctly.
109 EXPECT_EQ(5u, log->entries().size()); 110 EXPECT_EQ(5u, log->entries().size());
110 ExpectLogContains(log, 0, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_BEGIN); 111 ExpectLogContains(log, 0, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_BEGIN);
111 ExpectLogContains(log, 4, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_END); 112 ExpectLogContains(log, 4, LoadLog::TYPE_PROXY_SERVICE, LoadLog::PHASE_END);
112 } 113 }
113 114
114 TEST(ProxyServiceTest, PAC) { 115 TEST(ProxyServiceTest, PAC) {
115 MockProxyConfigService* config_service = 116 MockProxyConfigService* config_service =
116 new MockProxyConfigService("http://foopy/proxy.pac"); 117 new MockProxyConfigService("http://foopy/proxy.pac");
117 118
118 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 119 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
119 120
120 scoped_refptr<ProxyService> service( 121 scoped_refptr<ProxyService> service(
121 new ProxyService(config_service, resolver)); 122 new ProxyService(config_service, resolver, NULL));
122 123
123 GURL url("http://www.google.com/"); 124 GURL url("http://www.google.com/");
124 125
125 ProxyInfo info; 126 ProxyInfo info;
126 TestCompletionCallback callback; 127 TestCompletionCallback callback;
127 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded)); 128 scoped_refptr<LoadLog> log(new LoadLog(LoadLog::kUnbounded));
128 int rv = service->ResolveProxy(url, &info, &callback, NULL, log); 129 int rv = service->ResolveProxy(url, &info, &callback, NULL, log);
129 EXPECT_EQ(ERR_IO_PENDING, rv); 130 EXPECT_EQ(ERR_IO_PENDING, rv);
130 131
131 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 132 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
(...skipping 24 matching lines...) Expand all
156 157
157 // Test that the proxy resolver does not see the URL's username/password 158 // Test that the proxy resolver does not see the URL's username/password
158 // or its reference section. 159 // or its reference section.
159 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) { 160 TEST(ProxyServiceTest, PAC_NoIdentityOrHash) {
160 MockProxyConfigService* config_service = 161 MockProxyConfigService* config_service =
161 new MockProxyConfigService("http://foopy/proxy.pac"); 162 new MockProxyConfigService("http://foopy/proxy.pac");
162 163
163 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 164 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
164 165
165 scoped_refptr<ProxyService> service( 166 scoped_refptr<ProxyService> service(
166 new ProxyService(config_service, resolver)); 167 new ProxyService(config_service, resolver, NULL));
167 168
168 GURL url("http://username:password@www.google.com/?ref#hash#hash"); 169 GURL url("http://username:password@www.google.com/?ref#hash#hash");
169 170
170 ProxyInfo info; 171 ProxyInfo info;
171 TestCompletionCallback callback; 172 TestCompletionCallback callback;
172 int rv = service->ResolveProxy(url, &info, &callback, NULL, NULL); 173 int rv = service->ResolveProxy(url, &info, &callback, NULL, NULL);
173 EXPECT_EQ(ERR_IO_PENDING, rv); 174 EXPECT_EQ(ERR_IO_PENDING, rv);
174 175
175 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 176 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
176 resolver->pending_set_pac_script_request()->pac_url()); 177 resolver->pending_set_pac_script_request()->pac_url());
177 resolver->pending_set_pac_script_request()->CompleteNow(OK); 178 resolver->pending_set_pac_script_request()->CompleteNow(OK);
178 179
179 ASSERT_EQ(1u, resolver->pending_requests().size()); 180 ASSERT_EQ(1u, resolver->pending_requests().size());
180 // The URL should have been simplified, stripping the username/password/hash. 181 // The URL should have been simplified, stripping the username/password/hash.
181 EXPECT_EQ(GURL("http://www.google.com/?ref"), 182 EXPECT_EQ(GURL("http://www.google.com/?ref"),
182 resolver->pending_requests()[0]->url()); 183 resolver->pending_requests()[0]->url());
183 184
184 // We end here without ever completing the request -- destruction of 185 // We end here without ever completing the request -- destruction of
185 // ProxyService will cancel the outstanding request. 186 // ProxyService will cancel the outstanding request.
186 } 187 }
187 188
188 TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) { 189 TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) {
189 MockProxyConfigService* config_service = 190 MockProxyConfigService* config_service =
190 new MockProxyConfigService("http://foopy/proxy.pac"); 191 new MockProxyConfigService("http://foopy/proxy.pac");
191 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 192 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
192 193
193 scoped_refptr<ProxyService> service( 194 scoped_refptr<ProxyService> service(
194 new ProxyService(config_service, resolver)); 195 new ProxyService(config_service, resolver, NULL));
195 196
196 GURL url("http://www.google.com/"); 197 GURL url("http://www.google.com/");
197 198
198 ProxyInfo info; 199 ProxyInfo info;
199 TestCompletionCallback callback1; 200 TestCompletionCallback callback1;
200 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 201 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
201 EXPECT_EQ(ERR_IO_PENDING, rv); 202 EXPECT_EQ(ERR_IO_PENDING, rv);
202 203
203 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 204 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
204 resolver->pending_set_pac_script_request()->pac_url()); 205 resolver->pending_set_pac_script_request()->pac_url());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 // then foobar:20, and then give up and error. 242 // then foobar:20, and then give up and error.
242 // 243 //
243 // The important check of this test is to make sure that DIRECT is not somehow 244 // The important check of this test is to make sure that DIRECT is not somehow
244 // cached as being a bad proxy. 245 // cached as being a bad proxy.
245 TEST(ProxyServiceTest, PAC_FailoverAfterDirect) { 246 TEST(ProxyServiceTest, PAC_FailoverAfterDirect) {
246 MockProxyConfigService* config_service = 247 MockProxyConfigService* config_service =
247 new MockProxyConfigService("http://foopy/proxy.pac"); 248 new MockProxyConfigService("http://foopy/proxy.pac");
248 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 249 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
249 250
250 scoped_refptr<ProxyService> service( 251 scoped_refptr<ProxyService> service(
251 new ProxyService(config_service, resolver)); 252 new ProxyService(config_service, resolver, NULL));
252 253
253 GURL url("http://www.google.com/"); 254 GURL url("http://www.google.com/");
254 255
255 ProxyInfo info; 256 ProxyInfo info;
256 TestCompletionCallback callback1; 257 TestCompletionCallback callback1;
257 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 258 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
258 EXPECT_EQ(ERR_IO_PENDING, rv); 259 EXPECT_EQ(ERR_IO_PENDING, rv);
259 260
260 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 261 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
261 resolver->pending_set_pac_script_request()->pac_url()); 262 resolver->pending_set_pac_script_request()->pac_url());
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
303 // Test what happens when the ProxyResolver fails. The download and setting 304 // Test what happens when the ProxyResolver fails. The download and setting
304 // of the PAC script have already succeeded, so this corresponds with a 305 // of the PAC script have already succeeded, so this corresponds with a
305 // javascript runtime error while calling FindProxyForURL(). 306 // javascript runtime error while calling FindProxyForURL().
306 307
307 MockProxyConfigService* config_service = 308 MockProxyConfigService* config_service =
308 new MockProxyConfigService("http://foopy/proxy.pac"); 309 new MockProxyConfigService("http://foopy/proxy.pac");
309 310
310 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 311 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
311 312
312 scoped_refptr<ProxyService> service( 313 scoped_refptr<ProxyService> service(
313 new ProxyService(config_service, resolver)); 314 new ProxyService(config_service, resolver, NULL));
314 315
315 // Start first resolve request. 316 // Start first resolve request.
316 GURL url("http://www.google.com/"); 317 GURL url("http://www.google.com/");
317 ProxyInfo info; 318 ProxyInfo info;
318 TestCompletionCallback callback1; 319 TestCompletionCallback callback1;
319 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 320 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
320 EXPECT_EQ(ERR_IO_PENDING, rv); 321 EXPECT_EQ(ERR_IO_PENDING, rv);
321 322
322 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 323 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
323 resolver->pending_set_pac_script_request()->pac_url()); 324 resolver->pending_set_pac_script_request()->pac_url());
(...skipping 29 matching lines...) Expand all
353 TEST(ProxyServiceTest, ProxyFallback) { 354 TEST(ProxyServiceTest, ProxyFallback) {
354 // Test what happens when we specify multiple proxy servers and some of them 355 // Test what happens when we specify multiple proxy servers and some of them
355 // are bad. 356 // are bad.
356 357
357 MockProxyConfigService* config_service = 358 MockProxyConfigService* config_service =
358 new MockProxyConfigService("http://foopy/proxy.pac"); 359 new MockProxyConfigService("http://foopy/proxy.pac");
359 360
360 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 361 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
361 362
362 scoped_refptr<ProxyService> service( 363 scoped_refptr<ProxyService> service(
363 new ProxyService(config_service, resolver)); 364 new ProxyService(config_service, resolver, NULL));
364 365
365 GURL url("http://www.google.com/"); 366 GURL url("http://www.google.com/");
366 367
367 // Get the proxy information. 368 // Get the proxy information.
368 ProxyInfo info; 369 ProxyInfo info;
369 TestCompletionCallback callback1; 370 TestCompletionCallback callback1;
370 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 371 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
371 EXPECT_EQ(ERR_IO_PENDING, rv); 372 EXPECT_EQ(ERR_IO_PENDING, rv);
372 373
373 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 374 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
431 432
432 // This test is similar to ProxyFallback, but this time we have an explicit 433 // This test is similar to ProxyFallback, but this time we have an explicit
433 // fallback choice to DIRECT. 434 // fallback choice to DIRECT.
434 TEST(ProxyServiceTest, ProxyFallbackToDirect) { 435 TEST(ProxyServiceTest, ProxyFallbackToDirect) {
435 MockProxyConfigService* config_service = 436 MockProxyConfigService* config_service =
436 new MockProxyConfigService("http://foopy/proxy.pac"); 437 new MockProxyConfigService("http://foopy/proxy.pac");
437 438
438 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 439 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
439 440
440 scoped_refptr<ProxyService> service( 441 scoped_refptr<ProxyService> service(
441 new ProxyService(config_service, resolver)); 442 new ProxyService(config_service, resolver, NULL));
442 443
443 GURL url("http://www.google.com/"); 444 GURL url("http://www.google.com/");
444 445
445 // Get the proxy information. 446 // Get the proxy information.
446 ProxyInfo info; 447 ProxyInfo info;
447 TestCompletionCallback callback1; 448 TestCompletionCallback callback1;
448 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 449 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
449 EXPECT_EQ(ERR_IO_PENDING, rv); 450 EXPECT_EQ(ERR_IO_PENDING, rv);
450 451
451 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 452 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 492
492 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { 493 TEST(ProxyServiceTest, ProxyFallback_NewSettings) {
493 // Test proxy failover when new settings are available. 494 // Test proxy failover when new settings are available.
494 495
495 MockProxyConfigService* config_service = 496 MockProxyConfigService* config_service =
496 new MockProxyConfigService("http://foopy/proxy.pac"); 497 new MockProxyConfigService("http://foopy/proxy.pac");
497 498
498 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 499 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
499 500
500 scoped_refptr<ProxyService> service( 501 scoped_refptr<ProxyService> service(
501 new ProxyService(config_service, resolver)); 502 new ProxyService(config_service, resolver, NULL));
502 503
503 GURL url("http://www.google.com/"); 504 GURL url("http://www.google.com/");
504 505
505 // Get the proxy information. 506 // Get the proxy information.
506 ProxyInfo info; 507 ProxyInfo info;
507 TestCompletionCallback callback1; 508 TestCompletionCallback callback1;
508 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 509 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
509 EXPECT_EQ(ERR_IO_PENDING, rv); 510 EXPECT_EQ(ERR_IO_PENDING, rv);
510 511
511 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 512 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
580 581
581 TEST(ProxyServiceTest, ProxyFallback_BadConfig) { 582 TEST(ProxyServiceTest, ProxyFallback_BadConfig) {
582 // Test proxy failover when the configuration is bad. 583 // Test proxy failover when the configuration is bad.
583 584
584 MockProxyConfigService* config_service = 585 MockProxyConfigService* config_service =
585 new MockProxyConfigService("http://foopy/proxy.pac"); 586 new MockProxyConfigService("http://foopy/proxy.pac");
586 587
587 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 588 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
588 589
589 scoped_refptr<ProxyService> service( 590 scoped_refptr<ProxyService> service(
590 new ProxyService(config_service, resolver)); 591 new ProxyService(config_service, resolver, NULL));
591 592
592 GURL url("http://www.google.com/"); 593 GURL url("http://www.google.com/");
593 594
594 // Get the proxy information. 595 // Get the proxy information.
595 ProxyInfo info; 596 ProxyInfo info;
596 TestCompletionCallback callback1; 597 TestCompletionCallback callback1;
597 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 598 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
598 EXPECT_EQ(ERR_IO_PENDING, rv); 599 EXPECT_EQ(ERR_IO_PENDING, rv);
599 600
600 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 601 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
664 // Test what happens when a proxy bypass list is specified. 665 // Test what happens when a proxy bypass list is specified.
665 666
666 ProxyInfo info; 667 ProxyInfo info;
667 ProxyConfig config; 668 ProxyConfig config;
668 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); 669 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090");
669 config.auto_detect = false; 670 config.auto_detect = false;
670 config.proxy_bypass_local_names = true; 671 config.proxy_bypass_local_names = true;
671 672
672 { 673 {
673 scoped_refptr<ProxyService> service(new ProxyService( 674 scoped_refptr<ProxyService> service(new ProxyService(
674 new MockProxyConfigService(config), new MockAsyncProxyResolver())); 675 new MockProxyConfigService(config),
676 new MockAsyncProxyResolver(),
677 NULL));
675 GURL url("http://www.google.com/"); 678 GURL url("http://www.google.com/");
676 // Get the proxy information. 679 // Get the proxy information.
677 TestCompletionCallback callback; 680 TestCompletionCallback callback;
678 int rv = service->ResolveProxy(url, &info, &callback, NULL, NULL); 681 int rv = service->ResolveProxy(url, &info, &callback, NULL, NULL);
679 EXPECT_EQ(OK, rv); 682 EXPECT_EQ(OK, rv);
680 EXPECT_FALSE(info.is_direct()); 683 EXPECT_FALSE(info.is_direct());
681 } 684 }
682 685
683 { 686 {
684 scoped_refptr<ProxyService> service(new ProxyService( 687 scoped_refptr<ProxyService> service(new ProxyService(
685 new MockProxyConfigService(config), new MockAsyncProxyResolver())); 688 new MockProxyConfigService(config),
689 new MockAsyncProxyResolver(),
690 NULL));
686 GURL test_url("http://local"); 691 GURL test_url("http://local");
687 TestCompletionCallback callback; 692 TestCompletionCallback callback;
688 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 693 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
689 EXPECT_EQ(OK, rv); 694 EXPECT_EQ(OK, rv);
690 EXPECT_TRUE(info.is_direct()); 695 EXPECT_TRUE(info.is_direct());
691 } 696 }
692 697
693 config.proxy_bypass.clear(); 698 config.proxy_bypass.clear();
694 config.proxy_bypass.push_back("*.org"); 699 config.proxy_bypass.push_back("*.org");
695 config.proxy_bypass_local_names = true; 700 config.proxy_bypass_local_names = true;
696 { 701 {
697 scoped_refptr<ProxyService> service(new ProxyService( 702 scoped_refptr<ProxyService> service(new ProxyService(
698 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 703 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
699 GURL test_url("http://www.webkit.org"); 704 GURL test_url("http://www.webkit.org");
700 TestCompletionCallback callback; 705 TestCompletionCallback callback;
701 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 706 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
702 EXPECT_EQ(OK, rv); 707 EXPECT_EQ(OK, rv);
703 EXPECT_TRUE(info.is_direct()); 708 EXPECT_TRUE(info.is_direct());
704 } 709 }
705 710
706 config.proxy_bypass.clear(); 711 config.proxy_bypass.clear();
707 config.proxy_bypass.push_back("*.org"); 712 config.proxy_bypass.push_back("*.org");
708 config.proxy_bypass.push_back("7*"); 713 config.proxy_bypass.push_back("7*");
709 config.proxy_bypass_local_names = true; 714 config.proxy_bypass_local_names = true;
710 { 715 {
711 scoped_refptr<ProxyService> service(new ProxyService( 716 scoped_refptr<ProxyService> service(new ProxyService(
712 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 717 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
713 GURL test_url("http://74.125.19.147"); 718 GURL test_url("http://74.125.19.147");
714 TestCompletionCallback callback; 719 TestCompletionCallback callback;
715 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 720 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
716 EXPECT_EQ(OK, rv); 721 EXPECT_EQ(OK, rv);
717 EXPECT_TRUE(info.is_direct()); 722 EXPECT_TRUE(info.is_direct());
718 } 723 }
719 724
720 config.proxy_bypass.clear(); 725 config.proxy_bypass.clear();
721 config.proxy_bypass.push_back("*.org"); 726 config.proxy_bypass.push_back("*.org");
722 config.proxy_bypass_local_names = true; 727 config.proxy_bypass_local_names = true;
723 { 728 {
724 scoped_refptr<ProxyService> service(new ProxyService( 729 scoped_refptr<ProxyService> service(new ProxyService(
725 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 730 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
726 GURL test_url("http://www.msn.com"); 731 GURL test_url("http://www.msn.com");
727 TestCompletionCallback callback; 732 TestCompletionCallback callback;
728 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 733 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
729 EXPECT_EQ(OK, rv); 734 EXPECT_EQ(OK, rv);
730 EXPECT_FALSE(info.is_direct()); 735 EXPECT_FALSE(info.is_direct());
731 } 736 }
732 737
733 config.proxy_bypass.clear(); 738 config.proxy_bypass.clear();
734 config.proxy_bypass.push_back("*.MSN.COM"); 739 config.proxy_bypass.push_back("*.MSN.COM");
735 config.proxy_bypass_local_names = true; 740 config.proxy_bypass_local_names = true;
736 { 741 {
737 scoped_refptr<ProxyService> service(new ProxyService( 742 scoped_refptr<ProxyService> service(new ProxyService(
738 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 743 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
739 GURL test_url("http://www.msnbc.msn.com"); 744 GURL test_url("http://www.msnbc.msn.com");
740 TestCompletionCallback callback; 745 TestCompletionCallback callback;
741 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 746 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
742 EXPECT_EQ(OK, rv); 747 EXPECT_EQ(OK, rv);
743 EXPECT_TRUE(info.is_direct()); 748 EXPECT_TRUE(info.is_direct());
744 } 749 }
745 750
746 config.proxy_bypass.clear(); 751 config.proxy_bypass.clear();
747 config.proxy_bypass.push_back("*.msn.com"); 752 config.proxy_bypass.push_back("*.msn.com");
748 config.proxy_bypass_local_names = true; 753 config.proxy_bypass_local_names = true;
749 { 754 {
750 scoped_refptr<ProxyService> service(new ProxyService( 755 scoped_refptr<ProxyService> service(new ProxyService(
751 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 756 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
752 GURL test_url("HTTP://WWW.MSNBC.MSN.COM"); 757 GURL test_url("HTTP://WWW.MSNBC.MSN.COM");
753 TestCompletionCallback callback; 758 TestCompletionCallback callback;
754 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 759 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
755 EXPECT_EQ(OK, rv); 760 EXPECT_EQ(OK, rv);
756 EXPECT_TRUE(info.is_direct()); 761 EXPECT_TRUE(info.is_direct());
757 } 762 }
758 } 763 }
759 764
760 TEST(ProxyServiceTest, ProxyBypassListWithPorts) { 765 TEST(ProxyServiceTest, ProxyBypassListWithPorts) {
761 // Test port specification in bypass list entries. 766 // Test port specification in bypass list entries.
762 ProxyInfo info; 767 ProxyInfo info;
763 ProxyConfig config; 768 ProxyConfig config;
764 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); 769 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090");
765 config.auto_detect = false; 770 config.auto_detect = false;
766 config.proxy_bypass_local_names = false; 771 config.proxy_bypass_local_names = false;
767 772
768 config.proxy_bypass.clear(); 773 config.proxy_bypass.clear();
769 config.proxy_bypass.push_back("*.example.com:99"); 774 config.proxy_bypass.push_back("*.example.com:99");
770 { 775 {
771 scoped_refptr<ProxyService> service(new ProxyService( 776 scoped_refptr<ProxyService> service(new ProxyService(
772 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 777 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
773 { 778 {
774 GURL test_url("http://www.example.com:99"); 779 GURL test_url("http://www.example.com:99");
775 TestCompletionCallback callback; 780 TestCompletionCallback callback;
776 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 781 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
777 EXPECT_EQ(OK, rv); 782 EXPECT_EQ(OK, rv);
778 EXPECT_TRUE(info.is_direct()); 783 EXPECT_TRUE(info.is_direct());
779 } 784 }
780 { 785 {
781 GURL test_url("http://www.example.com:100"); 786 GURL test_url("http://www.example.com:100");
782 TestCompletionCallback callback; 787 TestCompletionCallback callback;
783 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 788 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
784 EXPECT_EQ(OK, rv); 789 EXPECT_EQ(OK, rv);
785 EXPECT_FALSE(info.is_direct()); 790 EXPECT_FALSE(info.is_direct());
786 } 791 }
787 { 792 {
788 GURL test_url("http://www.example.com"); 793 GURL test_url("http://www.example.com");
789 TestCompletionCallback callback; 794 TestCompletionCallback callback;
790 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 795 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
791 EXPECT_EQ(OK, rv); 796 EXPECT_EQ(OK, rv);
792 EXPECT_FALSE(info.is_direct()); 797 EXPECT_FALSE(info.is_direct());
793 } 798 }
794 } 799 }
795 800
796 config.proxy_bypass.clear(); 801 config.proxy_bypass.clear();
797 config.proxy_bypass.push_back("*.example.com:80"); 802 config.proxy_bypass.push_back("*.example.com:80");
798 { 803 {
799 scoped_refptr<ProxyService> service(new ProxyService( 804 scoped_refptr<ProxyService> service(new ProxyService(
800 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 805 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
801 GURL test_url("http://www.example.com"); 806 GURL test_url("http://www.example.com");
802 TestCompletionCallback callback; 807 TestCompletionCallback callback;
803 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 808 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
804 EXPECT_EQ(OK, rv); 809 EXPECT_EQ(OK, rv);
805 EXPECT_TRUE(info.is_direct()); 810 EXPECT_TRUE(info.is_direct());
806 } 811 }
807 812
808 config.proxy_bypass.clear(); 813 config.proxy_bypass.clear();
809 config.proxy_bypass.push_back("*.example.com"); 814 config.proxy_bypass.push_back("*.example.com");
810 { 815 {
811 scoped_refptr<ProxyService> service(new ProxyService( 816 scoped_refptr<ProxyService> service(new ProxyService(
812 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 817 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
813 GURL test_url("http://www.example.com:99"); 818 GURL test_url("http://www.example.com:99");
814 TestCompletionCallback callback; 819 TestCompletionCallback callback;
815 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 820 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
816 EXPECT_EQ(OK, rv); 821 EXPECT_EQ(OK, rv);
817 EXPECT_TRUE(info.is_direct()); 822 EXPECT_TRUE(info.is_direct());
818 } 823 }
819 824
820 // IPv6 with port. 825 // IPv6 with port.
821 config.proxy_bypass.clear(); 826 config.proxy_bypass.clear();
822 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]:99"); 827 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]:99");
823 { 828 {
824 scoped_refptr<ProxyService> service(new ProxyService( 829 scoped_refptr<ProxyService> service(new ProxyService(
825 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 830 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
826 { 831 {
827 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); 832 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/");
828 TestCompletionCallback callback; 833 TestCompletionCallback callback;
829 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 834 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
830 EXPECT_EQ(OK, rv); 835 EXPECT_EQ(OK, rv);
831 EXPECT_TRUE(info.is_direct()); 836 EXPECT_TRUE(info.is_direct());
832 } 837 }
833 { 838 {
834 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); 839 GURL test_url("http://[3ffe:2a00:100:7031::1]/");
835 TestCompletionCallback callback; 840 TestCompletionCallback callback;
836 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 841 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
837 EXPECT_EQ(OK, rv); 842 EXPECT_EQ(OK, rv);
838 EXPECT_FALSE(info.is_direct()); 843 EXPECT_FALSE(info.is_direct());
839 } 844 }
840 } 845 }
841 846
842 // IPv6 without port. The bypass entry ought to work without the 847 // IPv6 without port. The bypass entry ought to work without the
843 // brackets, but the bypass matching logic in ProxyService is 848 // brackets, but the bypass matching logic in ProxyService is
844 // currently limited. 849 // currently limited.
845 config.proxy_bypass.clear(); 850 config.proxy_bypass.clear();
846 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]"); 851 config.proxy_bypass.push_back("[3ffe:2a00:100:7031::1]");
847 { 852 {
848 scoped_refptr<ProxyService> service(new ProxyService( 853 scoped_refptr<ProxyService> service(new ProxyService(
849 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 854 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
850 { 855 {
851 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/"); 856 GURL test_url("http://[3ffe:2a00:100:7031::1]:99/");
852 TestCompletionCallback callback; 857 TestCompletionCallback callback;
853 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 858 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
854 EXPECT_EQ(OK, rv); 859 EXPECT_EQ(OK, rv);
855 EXPECT_TRUE(info.is_direct()); 860 EXPECT_TRUE(info.is_direct());
856 } 861 }
857 { 862 {
858 GURL test_url("http://[3ffe:2a00:100:7031::1]/"); 863 GURL test_url("http://[3ffe:2a00:100:7031::1]/");
859 TestCompletionCallback callback; 864 TestCompletionCallback callback;
860 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 865 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
861 EXPECT_EQ(OK, rv); 866 EXPECT_EQ(OK, rv);
862 EXPECT_TRUE(info.is_direct()); 867 EXPECT_TRUE(info.is_direct());
863 } 868 }
864 } 869 }
865 } 870 }
866 871
867 TEST(ProxyServiceTest, PerProtocolProxyTests) { 872 TEST(ProxyServiceTest, PerProtocolProxyTests) {
868 ProxyConfig config; 873 ProxyConfig config;
869 config.proxy_rules.ParseFromString("http=foopy1:8080;https=foopy2:8080"); 874 config.proxy_rules.ParseFromString("http=foopy1:8080;https=foopy2:8080");
870 config.auto_detect = false; 875 config.auto_detect = false;
871 { 876 {
872 scoped_refptr<ProxyService> service(new ProxyService( 877 scoped_refptr<ProxyService> service(new ProxyService(
873 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 878 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
874 GURL test_url("http://www.msn.com"); 879 GURL test_url("http://www.msn.com");
875 ProxyInfo info; 880 ProxyInfo info;
876 TestCompletionCallback callback; 881 TestCompletionCallback callback;
877 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 882 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
878 EXPECT_EQ(OK, rv); 883 EXPECT_EQ(OK, rv);
879 EXPECT_FALSE(info.is_direct()); 884 EXPECT_FALSE(info.is_direct());
880 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 885 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
881 } 886 }
882 { 887 {
883 scoped_refptr<ProxyService> service(new ProxyService( 888 scoped_refptr<ProxyService> service(new ProxyService(
884 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 889 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
885 GURL test_url("ftp://ftp.google.com"); 890 GURL test_url("ftp://ftp.google.com");
886 ProxyInfo info; 891 ProxyInfo info;
887 TestCompletionCallback callback; 892 TestCompletionCallback callback;
888 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 893 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
889 EXPECT_EQ(OK, rv); 894 EXPECT_EQ(OK, rv);
890 EXPECT_TRUE(info.is_direct()); 895 EXPECT_TRUE(info.is_direct());
891 EXPECT_EQ("direct://", info.proxy_server().ToURI()); 896 EXPECT_EQ("direct://", info.proxy_server().ToURI());
892 } 897 }
893 { 898 {
894 scoped_refptr<ProxyService> service(new ProxyService( 899 scoped_refptr<ProxyService> service(new ProxyService(
895 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 900 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
896 GURL test_url("https://webbranch.techcu.com"); 901 GURL test_url("https://webbranch.techcu.com");
897 ProxyInfo info; 902 ProxyInfo info;
898 TestCompletionCallback callback; 903 TestCompletionCallback callback;
899 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 904 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
900 EXPECT_EQ(OK, rv); 905 EXPECT_EQ(OK, rv);
901 EXPECT_FALSE(info.is_direct()); 906 EXPECT_FALSE(info.is_direct());
902 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); 907 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI());
903 } 908 }
904 { 909 {
905 config.proxy_rules.ParseFromString("foopy1:8080"); 910 config.proxy_rules.ParseFromString("foopy1:8080");
906 scoped_refptr<ProxyService> service(new ProxyService( 911 scoped_refptr<ProxyService> service(new ProxyService(
907 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 912 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
908 GURL test_url("http://www.microsoft.com"); 913 GURL test_url("http://www.microsoft.com");
909 ProxyInfo info; 914 ProxyInfo info;
910 TestCompletionCallback callback; 915 TestCompletionCallback callback;
911 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 916 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
912 EXPECT_EQ(OK, rv); 917 EXPECT_EQ(OK, rv);
913 EXPECT_FALSE(info.is_direct()); 918 EXPECT_FALSE(info.is_direct());
914 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 919 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
915 } 920 }
916 } 921 }
917 922
918 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries 923 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries
919 // fall back to the SOCKS proxy. 924 // fall back to the SOCKS proxy.
920 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { 925 TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) {
921 ProxyConfig config; 926 ProxyConfig config;
922 config.proxy_rules.ParseFromString("http=foopy1:8080;socks=foopy2:1080"); 927 config.proxy_rules.ParseFromString("http=foopy1:8080;socks=foopy2:1080");
923 config.auto_detect = false; 928 config.auto_detect = false;
924 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 929 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
925 config.proxy_rules.type); 930 config.proxy_rules.type);
926 931
927 { 932 {
928 scoped_refptr<ProxyService> service(new ProxyService( 933 scoped_refptr<ProxyService> service(new ProxyService(
929 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 934 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
930 GURL test_url("http://www.msn.com"); 935 GURL test_url("http://www.msn.com");
931 ProxyInfo info; 936 ProxyInfo info;
932 TestCompletionCallback callback; 937 TestCompletionCallback callback;
933 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 938 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
934 EXPECT_EQ(OK, rv); 939 EXPECT_EQ(OK, rv);
935 EXPECT_FALSE(info.is_direct()); 940 EXPECT_FALSE(info.is_direct());
936 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 941 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
937 } 942 }
938 { 943 {
939 scoped_refptr<ProxyService> service(new ProxyService( 944 scoped_refptr<ProxyService> service(new ProxyService(
940 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 945 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
941 GURL test_url("ftp://ftp.google.com"); 946 GURL test_url("ftp://ftp.google.com");
942 ProxyInfo info; 947 ProxyInfo info;
943 TestCompletionCallback callback; 948 TestCompletionCallback callback;
944 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 949 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
945 EXPECT_EQ(OK, rv); 950 EXPECT_EQ(OK, rv);
946 EXPECT_FALSE(info.is_direct()); 951 EXPECT_FALSE(info.is_direct());
947 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); 952 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI());
948 } 953 }
949 { 954 {
950 scoped_refptr<ProxyService> service(new ProxyService( 955 scoped_refptr<ProxyService> service(new ProxyService(
951 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 956 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
952 GURL test_url("https://webbranch.techcu.com"); 957 GURL test_url("https://webbranch.techcu.com");
953 ProxyInfo info; 958 ProxyInfo info;
954 TestCompletionCallback callback; 959 TestCompletionCallback callback;
955 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 960 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
956 EXPECT_EQ(OK, rv); 961 EXPECT_EQ(OK, rv);
957 EXPECT_FALSE(info.is_direct()); 962 EXPECT_FALSE(info.is_direct());
958 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); 963 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI());
959 } 964 }
960 { 965 {
961 scoped_refptr<ProxyService> service(new ProxyService( 966 scoped_refptr<ProxyService> service(new ProxyService(
962 new MockProxyConfigService(config), new MockAsyncProxyResolver)); 967 new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
963 GURL test_url("unknown://www.microsoft.com"); 968 GURL test_url("unknown://www.microsoft.com");
964 ProxyInfo info; 969 ProxyInfo info;
965 TestCompletionCallback callback; 970 TestCompletionCallback callback;
966 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL); 971 int rv = service->ResolveProxy(test_url, &info, &callback, NULL, NULL);
967 EXPECT_EQ(OK, rv); 972 EXPECT_EQ(OK, rv);
968 EXPECT_FALSE(info.is_direct()); 973 EXPECT_FALSE(info.is_direct());
969 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); 974 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI());
970 } 975 }
971 } 976 }
972 977
973 // Test cancellation of an in-progress request. 978 // Test cancellation of an in-progress request.
974 TEST(ProxyServiceTest, CancelInProgressRequest) { 979 TEST(ProxyServiceTest, CancelInProgressRequest) {
975 MockProxyConfigService* config_service = 980 MockProxyConfigService* config_service =
976 new MockProxyConfigService("http://foopy/proxy.pac"); 981 new MockProxyConfigService("http://foopy/proxy.pac");
977 982
978 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 983 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
979 984
980 scoped_refptr<ProxyService> service( 985 scoped_refptr<ProxyService> service(
981 new ProxyService(config_service, resolver)); 986 new ProxyService(config_service, resolver, NULL));
982 987
983 // Start 3 requests. 988 // Start 3 requests.
984 989
985 ProxyInfo info1; 990 ProxyInfo info1;
986 TestCompletionCallback callback1; 991 TestCompletionCallback callback1;
987 int rv = service->ResolveProxy( 992 int rv = service->ResolveProxy(
988 GURL("http://request1"), &info1, &callback1, NULL, NULL); 993 GURL("http://request1"), &info1, &callback1, NULL, NULL);
989 EXPECT_EQ(ERR_IO_PENDING, rv); 994 EXPECT_EQ(ERR_IO_PENDING, rv);
990 995
991 // Nothing has been sent to the proxy resolver yet, since the proxy 996 // Nothing has been sent to the proxy resolver yet, since the proxy
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
1046 1051
1047 // Test the initial PAC download for resolver that expects bytes. 1052 // Test the initial PAC download for resolver that expects bytes.
1048 TEST(ProxyServiceTest, InitialPACScriptDownload) { 1053 TEST(ProxyServiceTest, InitialPACScriptDownload) {
1049 MockProxyConfigService* config_service = 1054 MockProxyConfigService* config_service =
1050 new MockProxyConfigService("http://foopy/proxy.pac"); 1055 new MockProxyConfigService("http://foopy/proxy.pac");
1051 1056
1052 MockAsyncProxyResolverExpectsBytes* resolver = 1057 MockAsyncProxyResolverExpectsBytes* resolver =
1053 new MockAsyncProxyResolverExpectsBytes; 1058 new MockAsyncProxyResolverExpectsBytes;
1054 1059
1055 scoped_refptr<ProxyService> service( 1060 scoped_refptr<ProxyService> service(
1056 new ProxyService(config_service, resolver)); 1061 new ProxyService(config_service, resolver, NULL));
1057 1062
1058 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1063 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1059 service->SetProxyScriptFetcher(fetcher); 1064 service->SetProxyScriptFetcher(fetcher);
1060 1065
1061 // Start 3 requests. 1066 // Start 3 requests.
1062 1067
1063 ProxyInfo info1; 1068 ProxyInfo info1;
1064 TestCompletionCallback callback1; 1069 TestCompletionCallback callback1;
1065 int rv = service->ResolveProxy( 1070 int rv = service->ResolveProxy(
1066 GURL("http://request1"), &info1, &callback1, NULL, NULL); 1071 GURL("http://request1"), &info1, &callback1, NULL, NULL);
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
1125 1130
1126 // Test changing the ProxyScriptFetcher while PAC download is in progress. 1131 // Test changing the ProxyScriptFetcher while PAC download is in progress.
1127 TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { 1132 TEST(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) {
1128 MockProxyConfigService* config_service = 1133 MockProxyConfigService* config_service =
1129 new MockProxyConfigService("http://foopy/proxy.pac"); 1134 new MockProxyConfigService("http://foopy/proxy.pac");
1130 1135
1131 MockAsyncProxyResolverExpectsBytes* resolver = 1136 MockAsyncProxyResolverExpectsBytes* resolver =
1132 new MockAsyncProxyResolverExpectsBytes; 1137 new MockAsyncProxyResolverExpectsBytes;
1133 1138
1134 scoped_refptr<ProxyService> service( 1139 scoped_refptr<ProxyService> service(
1135 new ProxyService(config_service, resolver)); 1140 new ProxyService(config_service, resolver, NULL));
1136 1141
1137 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1142 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1138 service->SetProxyScriptFetcher(fetcher); 1143 service->SetProxyScriptFetcher(fetcher);
1139 1144
1140 // Start 2 requests. 1145 // Start 2 requests.
1141 1146
1142 ProxyInfo info1; 1147 ProxyInfo info1;
1143 TestCompletionCallback callback1; 1148 TestCompletionCallback callback1;
1144 int rv = service->ResolveProxy( 1149 int rv = service->ResolveProxy(
1145 GURL("http://request1"), &info1, &callback1, NULL, NULL); 1150 GURL("http://request1"), &info1, &callback1, NULL, NULL);
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1182 1187
1183 // Test cancellation of a request, while the PAC script is being fetched. 1188 // Test cancellation of a request, while the PAC script is being fetched.
1184 TEST(ProxyServiceTest, CancelWhilePACFetching) { 1189 TEST(ProxyServiceTest, CancelWhilePACFetching) {
1185 MockProxyConfigService* config_service = 1190 MockProxyConfigService* config_service =
1186 new MockProxyConfigService("http://foopy/proxy.pac"); 1191 new MockProxyConfigService("http://foopy/proxy.pac");
1187 1192
1188 MockAsyncProxyResolverExpectsBytes* resolver = 1193 MockAsyncProxyResolverExpectsBytes* resolver =
1189 new MockAsyncProxyResolverExpectsBytes; 1194 new MockAsyncProxyResolverExpectsBytes;
1190 1195
1191 scoped_refptr<ProxyService> service( 1196 scoped_refptr<ProxyService> service(
1192 new ProxyService(config_service, resolver)); 1197 new ProxyService(config_service, resolver, NULL));
1193 1198
1194 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1199 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1195 service->SetProxyScriptFetcher(fetcher); 1200 service->SetProxyScriptFetcher(fetcher);
1196 1201
1197 // Start 3 requests. 1202 // Start 3 requests.
1198 ProxyInfo info1; 1203 ProxyInfo info1;
1199 TestCompletionCallback callback1; 1204 TestCompletionCallback callback1;
1200 ProxyService::PacRequest* request1; 1205 ProxyService::PacRequest* request1;
1201 scoped_refptr<LoadLog> log1(new LoadLog(LoadLog::kUnbounded)); 1206 scoped_refptr<LoadLog> log1(new LoadLog(LoadLog::kUnbounded));
1202 int rv = service->ResolveProxy( 1207 int rv = service->ResolveProxy(
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
1267 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { 1272 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) {
1268 ProxyConfig config; 1273 ProxyConfig config;
1269 config.auto_detect = true; 1274 config.auto_detect = true;
1270 config.pac_url = GURL("http://foopy/proxy.pac"); 1275 config.pac_url = GURL("http://foopy/proxy.pac");
1271 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used. 1276 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used.
1272 1277
1273 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1278 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1274 MockAsyncProxyResolverExpectsBytes* resolver = 1279 MockAsyncProxyResolverExpectsBytes* resolver =
1275 new MockAsyncProxyResolverExpectsBytes; 1280 new MockAsyncProxyResolverExpectsBytes;
1276 scoped_refptr<ProxyService> service( 1281 scoped_refptr<ProxyService> service(
1277 new ProxyService(config_service, resolver)); 1282 new ProxyService(config_service, resolver, NULL));
1278 1283
1279 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1284 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1280 service->SetProxyScriptFetcher(fetcher); 1285 service->SetProxyScriptFetcher(fetcher);
1281 1286
1282 // Start 2 requests. 1287 // Start 2 requests.
1283 1288
1284 ProxyInfo info1; 1289 ProxyInfo info1;
1285 TestCompletionCallback callback1; 1290 TestCompletionCallback callback1;
1286 int rv = service->ResolveProxy( 1291 int rv = service->ResolveProxy(
1287 GURL("http://request1"), &info1, &callback1, NULL, NULL); 1292 GURL("http://request1"), &info1, &callback1, NULL, NULL);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
1338 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { 1343 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) {
1339 ProxyConfig config; 1344 ProxyConfig config;
1340 config.auto_detect = true; 1345 config.auto_detect = true;
1341 config.pac_url = GURL("http://foopy/proxy.pac"); 1346 config.pac_url = GURL("http://foopy/proxy.pac");
1342 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used. 1347 config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used.
1343 1348
1344 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1349 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1345 MockAsyncProxyResolverExpectsBytes* resolver = 1350 MockAsyncProxyResolverExpectsBytes* resolver =
1346 new MockAsyncProxyResolverExpectsBytes; 1351 new MockAsyncProxyResolverExpectsBytes;
1347 scoped_refptr<ProxyService> service( 1352 scoped_refptr<ProxyService> service(
1348 new ProxyService(config_service, resolver)); 1353 new ProxyService(config_service, resolver, NULL));
1349 1354
1350 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1355 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1351 service->SetProxyScriptFetcher(fetcher); 1356 service->SetProxyScriptFetcher(fetcher);
1352 1357
1353 // Start 2 requests. 1358 // Start 2 requests.
1354 1359
1355 ProxyInfo info1; 1360 ProxyInfo info1;
1356 TestCompletionCallback callback1; 1361 TestCompletionCallback callback1;
1357 int rv = service->ResolveProxy( 1362 int rv = service->ResolveProxy(
1358 GURL("http://request1"), &info1, &callback1, NULL, NULL); 1363 GURL("http://request1"), &info1, &callback1, NULL, NULL);
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
1414 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { 1419 TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) {
1415 ProxyConfig config; 1420 ProxyConfig config;
1416 config.auto_detect = true; 1421 config.auto_detect = true;
1417 config.pac_url = GURL("http://foopy/proxy.pac"); 1422 config.pac_url = GURL("http://foopy/proxy.pac");
1418 config.proxy_rules.ParseFromString("http=foopy:80"); 1423 config.proxy_rules.ParseFromString("http=foopy:80");
1419 1424
1420 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1425 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1421 MockAsyncProxyResolverExpectsBytes* resolver = 1426 MockAsyncProxyResolverExpectsBytes* resolver =
1422 new MockAsyncProxyResolverExpectsBytes; 1427 new MockAsyncProxyResolverExpectsBytes;
1423 scoped_refptr<ProxyService> service( 1428 scoped_refptr<ProxyService> service(
1424 new ProxyService(config_service, resolver)); 1429 new ProxyService(config_service, resolver, NULL));
1425 1430
1426 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1431 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1427 service->SetProxyScriptFetcher(fetcher); 1432 service->SetProxyScriptFetcher(fetcher);
1428 1433
1429 // Start 2 requests. 1434 // Start 2 requests.
1430 1435
1431 ProxyInfo info1; 1436 ProxyInfo info1;
1432 TestCompletionCallback callback1; 1437 TestCompletionCallback callback1;
1433 int rv = service->ResolveProxy( 1438 int rv = service->ResolveProxy(
1434 GURL("http://request1"), &info1, &callback1, NULL, NULL); 1439 GURL("http://request1"), &info1, &callback1, NULL, NULL);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 ProxyConfig config; 1477 ProxyConfig config;
1473 config.auto_detect = true; 1478 config.auto_detect = true;
1474 config.pac_url = GURL("http://foopy/proxy.pac"); 1479 config.pac_url = GURL("http://foopy/proxy.pac");
1475 config.proxy_rules.ParseFromString("http=foopy:80"); // Not used. 1480 config.proxy_rules.ParseFromString("http=foopy:80"); // Not used.
1476 config.proxy_bypass.push_back("www.google.com"); 1481 config.proxy_bypass.push_back("www.google.com");
1477 1482
1478 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1483 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1479 MockAsyncProxyResolverExpectsBytes* resolver = 1484 MockAsyncProxyResolverExpectsBytes* resolver =
1480 new MockAsyncProxyResolverExpectsBytes; 1485 new MockAsyncProxyResolverExpectsBytes;
1481 scoped_refptr<ProxyService> service( 1486 scoped_refptr<ProxyService> service(
1482 new ProxyService(config_service, resolver)); 1487 new ProxyService(config_service, resolver, NULL));
1483 1488
1484 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1489 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1485 service->SetProxyScriptFetcher(fetcher); 1490 service->SetProxyScriptFetcher(fetcher);
1486 1491
1487 // Start 1 requests. 1492 // Start 1 requests.
1488 1493
1489 ProxyInfo info1; 1494 ProxyInfo info1;
1490 TestCompletionCallback callback1; 1495 TestCompletionCallback callback1;
1491 int rv = service->ResolveProxy( 1496 int rv = service->ResolveProxy(
1492 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); 1497 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
1540 // have any memory errors (used to be that the ProxyScriptFetcher was 1545 // have any memory errors (used to be that the ProxyScriptFetcher was
1541 // being deleted prior to the InitProxyResolver). 1546 // being deleted prior to the InitProxyResolver).
1542 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { 1547 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) {
1543 ProxyConfig config; 1548 ProxyConfig config;
1544 config.pac_url = GURL("http://foopy/proxy.pac"); 1549 config.pac_url = GURL("http://foopy/proxy.pac");
1545 1550
1546 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1551 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1547 MockAsyncProxyResolverExpectsBytes* resolver = 1552 MockAsyncProxyResolverExpectsBytes* resolver =
1548 new MockAsyncProxyResolverExpectsBytes; 1553 new MockAsyncProxyResolverExpectsBytes;
1549 scoped_refptr<ProxyService> service( 1554 scoped_refptr<ProxyService> service(
1550 new ProxyService(config_service, resolver)); 1555 new ProxyService(config_service, resolver, NULL));
1551 1556
1552 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1557 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1553 service->SetProxyScriptFetcher(fetcher); 1558 service->SetProxyScriptFetcher(fetcher);
1554 1559
1555 // Start 1 request. 1560 // Start 1 request.
1556 1561
1557 ProxyInfo info1; 1562 ProxyInfo info1;
1558 TestCompletionCallback callback1; 1563 TestCompletionCallback callback1;
1559 int rv = service->ResolveProxy( 1564 int rv = service->ResolveProxy(
1560 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); 1565 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL);
(...skipping 15 matching lines...) Expand all
1576 // request to the proxy resolver. When run under valgrind, should not 1581 // request to the proxy resolver. When run under valgrind, should not
1577 // have any memory errors (used to be that the ProxyResolver was 1582 // have any memory errors (used to be that the ProxyResolver was
1578 // being deleted prior to the InitProxyResolver). 1583 // being deleted prior to the InitProxyResolver).
1579 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { 1584 TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) {
1580 MockProxyConfigService* config_service = 1585 MockProxyConfigService* config_service =
1581 new MockProxyConfigService("http://foopy/proxy.pac"); 1586 new MockProxyConfigService("http://foopy/proxy.pac");
1582 1587
1583 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 1588 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
1584 1589
1585 scoped_refptr<ProxyService> service( 1590 scoped_refptr<ProxyService> service(
1586 new ProxyService(config_service, resolver)); 1591 new ProxyService(config_service, resolver, NULL));
1587 1592
1588 GURL url("http://www.google.com/"); 1593 GURL url("http://www.google.com/");
1589 1594
1590 ProxyInfo info; 1595 ProxyInfo info;
1591 TestCompletionCallback callback; 1596 TestCompletionCallback callback;
1592 int rv = service->ResolveProxy(url, &info, &callback, NULL, NULL); 1597 int rv = service->ResolveProxy(url, &info, &callback, NULL, NULL);
1593 EXPECT_EQ(ERR_IO_PENDING, rv); 1598 EXPECT_EQ(ERR_IO_PENDING, rv);
1594 1599
1595 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1600 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1596 resolver->pending_set_pac_script_request()->pac_url()); 1601 resolver->pending_set_pac_script_request()->pac_url());
1597 1602
1598 // Delete the ProxyService. 1603 // Delete the ProxyService.
1599 service = NULL; 1604 service = NULL;
1600 } 1605 }
1601 1606
1602 TEST(ProxyServiceTest, ResetProxyConfigService) { 1607 TEST(ProxyServiceTest, ResetProxyConfigService) {
1603 ProxyConfig config1; 1608 ProxyConfig config1;
1604 config1.proxy_rules.ParseFromString("foopy1:8080"); 1609 config1.proxy_rules.ParseFromString("foopy1:8080");
1605 config1.auto_detect = false; 1610 config1.auto_detect = false;
1606 scoped_refptr<ProxyService> service(new ProxyService( 1611 scoped_refptr<ProxyService> service(new ProxyService(
1607 new MockProxyConfigService(config1), new MockAsyncProxyResolverExpectsByte s)); 1612 new MockProxyConfigService(config1),
1613 new MockAsyncProxyResolverExpectsBytes,
1614 NULL));
1608 1615
1609 ProxyInfo info; 1616 ProxyInfo info;
1610 TestCompletionCallback callback1; 1617 TestCompletionCallback callback1;
1611 int rv = service->ResolveProxy( 1618 int rv = service->ResolveProxy(
1612 GURL("http://request1"), &info, &callback1, NULL, NULL); 1619 GURL("http://request1"), &info, &callback1, NULL, NULL);
1613 EXPECT_EQ(OK, rv); 1620 EXPECT_EQ(OK, rv);
1614 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1621 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1615 1622
1616 ProxyConfig config2; 1623 ProxyConfig config2;
1617 config2.proxy_rules.ParseFromString("foopy2:8080"); 1624 config2.proxy_rules.ParseFromString("foopy2:8080");
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
1670 // Regression test for http://crbug.com/18526 -- the configuration was being 1677 // Regression test for http://crbug.com/18526 -- the configuration was being
1671 // mutated to cancel out the automatic settings, which meant UpdateConfig() 1678 // mutated to cancel out the automatic settings, which meant UpdateConfig()
1672 // thought it had received a new configuration. 1679 // thought it had received a new configuration.
1673 TEST(ProxyServiceTest, UpdateConfigAfterFailedAutodetect) { 1680 TEST(ProxyServiceTest, UpdateConfigAfterFailedAutodetect) {
1674 ProxyConfig config; 1681 ProxyConfig config;
1675 config.auto_detect = true; 1682 config.auto_detect = true;
1676 1683
1677 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1684 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1678 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 1685 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
1679 scoped_refptr<ProxyService> service( 1686 scoped_refptr<ProxyService> service(
1680 new ProxyService(config_service, resolver)); 1687 new ProxyService(config_service, resolver, NULL));
1681 1688
1682 // Start 1 requests. 1689 // Start 1 requests.
1683 1690
1684 ProxyInfo info1; 1691 ProxyInfo info1;
1685 TestCompletionCallback callback1; 1692 TestCompletionCallback callback1;
1686 int rv = service->ResolveProxy( 1693 int rv = service->ResolveProxy(
1687 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); 1694 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL);
1688 EXPECT_EQ(ERR_IO_PENDING, rv); 1695 EXPECT_EQ(ERR_IO_PENDING, rv);
1689 1696
1690 // Check that nothing has been sent to the proxy resolver yet. 1697 // Check that nothing has been sent to the proxy resolver yet.
(...skipping 25 matching lines...) Expand all
1716 1723
1717 // Test that when going from a configuration that required PAC to one 1724 // Test that when going from a configuration that required PAC to one
1718 // that does NOT, we unset the variable |should_use_proxy_resolver_|. 1725 // that does NOT, we unset the variable |should_use_proxy_resolver_|.
1719 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) { 1726 TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) {
1720 ProxyConfig config; 1727 ProxyConfig config;
1721 config.auto_detect = true; 1728 config.auto_detect = true;
1722 1729
1723 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1730 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1724 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 1731 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
1725 scoped_refptr<ProxyService> service( 1732 scoped_refptr<ProxyService> service(
1726 new ProxyService(config_service, resolver)); 1733 new ProxyService(config_service, resolver, NULL));
1727 1734
1728 // Start 1 request. 1735 // Start 1 request.
1729 1736
1730 ProxyInfo info1; 1737 ProxyInfo info1;
1731 TestCompletionCallback callback1; 1738 TestCompletionCallback callback1;
1732 int rv = service->ResolveProxy( 1739 int rv = service->ResolveProxy(
1733 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL); 1740 GURL("http://www.google.com"), &info1, &callback1, NULL, NULL);
1734 EXPECT_EQ(ERR_IO_PENDING, rv); 1741 EXPECT_EQ(ERR_IO_PENDING, rv);
1735 1742
1736 // Check that nothing has been sent to the proxy resolver yet. 1743 // Check that nothing has been sent to the proxy resolver yet.
(...skipping 24 matching lines...) Expand all
1761 // Start another request -- the effective configuration has changed. 1768 // Start another request -- the effective configuration has changed.
1762 ProxyInfo info2; 1769 ProxyInfo info2;
1763 TestCompletionCallback callback2; 1770 TestCompletionCallback callback2;
1764 rv = service->ResolveProxy( 1771 rv = service->ResolveProxy(
1765 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); 1772 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL);
1766 EXPECT_EQ(OK, rv); 1773 EXPECT_EQ(OK, rv);
1767 1774
1768 EXPECT_TRUE(info2.is_direct()); 1775 EXPECT_TRUE(info2.is_direct());
1769 } 1776 }
1770 1777
1778 TEST(ProxyServiceTest, NetworkChangeTriggersPacRefetch) {
1779 MockProxyConfigService* config_service =
1780 new MockProxyConfigService("http://foopy/proxy.pac");
1781
1782 MockAsyncProxyResolverExpectsBytes* resolver =
1783 new MockAsyncProxyResolverExpectsBytes;
1784
1785 scoped_refptr<MockNetworkChangeNotifier> network_change_notifier(
1786 new MockNetworkChangeNotifier());
1787
1788 scoped_refptr<ProxyService> service(
1789 new ProxyService(config_service, resolver, network_change_notifier));
1790
1791 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1792 service->SetProxyScriptFetcher(fetcher);
1793
1794 // Start 1 request.
1795
1796 ProxyInfo info1;
1797 TestCompletionCallback callback1;
1798 int rv = service->ResolveProxy(
1799 GURL("http://request1"), &info1, &callback1, NULL, NULL);
1800 EXPECT_EQ(ERR_IO_PENDING, rv);
1801
1802 // The first request should have triggered initial download of PAC script.
1803 EXPECT_TRUE(fetcher->has_pending_request());
1804 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
1805
1806 // Nothing has been sent to the resolver yet.
1807 EXPECT_TRUE(resolver->pending_requests().empty());
1808
1809 // At this point the ProxyService should be waiting for the
1810 // ProxyScriptFetcher to invoke its completion callback, notifying it of
1811 // PAC script download completion.
1812 fetcher->NotifyFetchCompletion(OK, "pac-v1");
1813
1814 // Now that the PAC script is downloaded, the request will have been sent to
1815 // the proxy resolver.
1816 EXPECT_EQ("pac-v1", resolver->pending_set_pac_script_request()->pac_bytes());
1817 resolver->pending_set_pac_script_request()->CompleteNow(OK);
1818
1819 ASSERT_EQ(1u, resolver->pending_requests().size());
1820 EXPECT_EQ(GURL("http://request1"), resolver->pending_requests()[0]->url());
1821
1822 // Complete the pending request.
1823 resolver->pending_requests()[0]->results()->UseNamedProxy("request1:80");
1824 resolver->pending_requests()[0]->CompleteNow(OK);
1825
1826 // Wait for completion callback, and verify that the request ran as expected.
1827 EXPECT_EQ(OK, callback1.WaitForResult());
1828 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
1829
1830 // Now simluate a change in the network. The ProxyConfigService is still
1831 // going to return the same PAC URL as before, but this URL needs to be
1832 // refetched on the new network.
1833
1834 network_change_notifier->NotifyIPAddressChange();
1835
1836 // Start a second request.
1837 ProxyInfo info2;
1838 TestCompletionCallback callback2;
1839 rv = service->ResolveProxy(
1840 GURL("http://request2"), &info2, &callback2, NULL, NULL);
1841 EXPECT_EQ(ERR_IO_PENDING, rv);
1842
1843 // This second request should have triggered the re-download of the PAC
1844 // script (since we marked the network as having changed).
1845 EXPECT_TRUE(fetcher->has_pending_request());
1846 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
1847
1848 // Nothing has been sent to the resolver yet.
1849 EXPECT_TRUE(resolver->pending_requests().empty());
1850
1851 // Simulate the PAC script fetch as having completed (this time with
1852 // different data).
1853 fetcher->NotifyFetchCompletion(OK, "pac-v2");
1854
1855 // Now that the PAC script is downloaded, the second request will have been
1856 // sent to the proxy resolver.
1857 EXPECT_EQ("pac-v2", resolver->pending_set_pac_script_request()->pac_bytes());
1858 resolver->pending_set_pac_script_request()->CompleteNow(OK);
1859
1860 ASSERT_EQ(1u, resolver->pending_requests().size());
1861 EXPECT_EQ(GURL("http://request2"), resolver->pending_requests()[0]->url());
1862
1863 // Complete the pending second request.
1864 resolver->pending_requests()[0]->results()->UseNamedProxy("request2:80");
1865 resolver->pending_requests()[0]->CompleteNow(OK);
1866
1867 // Wait for completion callback, and verify that the request ran as expected.
1868 EXPECT_EQ(OK, callback2.WaitForResult());
1869 EXPECT_EQ("request2:80", info2.proxy_server().ToURI());
1870 }
1871
1771 } // namespace net 1872 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | webkit/tools/test_shell/test_shell_request_context.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698