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

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

Issue 1102463002: Add a MockAsyncProxyResolverFactory and update some tests to use it. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@proxy-factory-refactor
Patch Set: Created 5 years, 8 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
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 "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"
(...skipping 222 matching lines...) Expand 10 before | Expand all | Expand 10 after
233 233
234 private: 234 private:
235 bool on_proxy_fallback_called_; 235 bool on_proxy_fallback_called_;
236 ProxyServer proxy_server_; 236 ProxyServer proxy_server_;
237 int proxy_fallback_net_error_; 237 int proxy_fallback_net_error_;
238 }; 238 };
239 239
240 } // namespace 240 } // namespace
241 241
242 TEST_F(ProxyServiceTest, Direct) { 242 TEST_F(ProxyServiceTest, Direct) {
243 MockAsyncProxyResolver resolver; 243 MockAsyncProxyResolverFactory factory(false);
244 ProxyService service( 244 ProxyService service(
245 new MockProxyConfigService(ProxyConfig::CreateDirect()), 245 new MockProxyConfigService(ProxyConfig::CreateDirect()),
246 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 246 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
eroman 2015/04/22 16:30:38 Would it be clearer to just get rid of ForwardingP
Sam McNally 2015/04/23 03:04:44 Done.
247 247
248 GURL url("http://www.google.com/"); 248 GURL url("http://www.google.com/");
249 249
250 ProxyInfo info; 250 ProxyInfo info;
251 TestCompletionCallback callback; 251 TestCompletionCallback callback;
252 BoundTestNetLog log; 252 BoundTestNetLog log;
253 int rv = service.ResolveProxy( 253 int rv = service.ResolveProxy(
254 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, 254 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL,
255 log.bound()); 255 log.bound());
256 EXPECT_EQ(OK, rv); 256 EXPECT_EQ(OK, rv);
257 EXPECT_TRUE(resolver.pending_requests().empty()); 257 EXPECT_TRUE(factory.pending_requests().empty());
258 258
259 EXPECT_TRUE(info.is_direct()); 259 EXPECT_TRUE(info.is_direct());
260 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); 260 EXPECT_TRUE(info.proxy_resolve_start_time().is_null());
261 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); 261 EXPECT_TRUE(info.proxy_resolve_end_time().is_null());
262 262
263 // Check the NetLog was filled correctly. 263 // Check the NetLog was filled correctly.
264 TestNetLog::CapturedEntryList entries; 264 TestNetLog::CapturedEntryList entries;
265 log.GetEntries(&entries); 265 log.GetEntries(&entries);
266 266
267 EXPECT_EQ(3u, entries.size()); 267 EXPECT_EQ(3u, entries.size());
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
376 bypass_url, net::LOAD_NORMAL, &info, callback.callback(), NULL, 376 bypass_url, net::LOAD_NORMAL, &info, callback.callback(), NULL,
377 &delegate, log.bound()); 377 &delegate, log.bound());
378 EXPECT_TRUE(info.is_direct()); 378 EXPECT_TRUE(info.is_direct());
379 } 379 }
380 380
381 TEST_F(ProxyServiceTest, PAC) { 381 TEST_F(ProxyServiceTest, PAC) {
382 MockProxyConfigService* config_service = 382 MockProxyConfigService* config_service =
383 new MockProxyConfigService("http://foopy/proxy.pac"); 383 new MockProxyConfigService("http://foopy/proxy.pac");
384 384
385 MockAsyncProxyResolver resolver; 385 MockAsyncProxyResolver resolver;
386 MockAsyncProxyResolverFactory factory(false);
386 387
387 ProxyService service( 388 ProxyService service(
388 config_service, 389 config_service,
389 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 390 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
390 391
391 GURL url("http://www.google.com/"); 392 GURL url("http://www.google.com/");
392 393
393 ProxyInfo info; 394 ProxyInfo info;
394 TestCompletionCallback callback; 395 TestCompletionCallback callback;
395 ProxyService::PacRequest* request; 396 ProxyService::PacRequest* request;
396 BoundTestNetLog log; 397 BoundTestNetLog log;
397 398
398 int rv = service.ResolveProxy( 399 int rv = service.ResolveProxy(
399 url, net::LOAD_NORMAL, &info, callback.callback(), &request, NULL, 400 url, net::LOAD_NORMAL, &info, callback.callback(), &request, NULL,
400 log.bound()); 401 log.bound());
401 EXPECT_EQ(ERR_IO_PENDING, rv); 402 EXPECT_EQ(ERR_IO_PENDING, rv);
402 403
403 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); 404 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request));
404 405
406 ASSERT_EQ(1u, factory.pending_requests().size());
405 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 407 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
406 resolver.pending_set_pac_script_request()->script_data()->url()); 408 factory.pending_requests()[0]->script_data()->url());
407 resolver.pending_set_pac_script_request()->CompleteNow(OK); 409 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
408 410
409 ASSERT_EQ(1u, resolver.pending_requests().size()); 411 ASSERT_EQ(1u, resolver.pending_requests().size());
410 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 412 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
411 413
412 // Set the result in proxy resolver. 414 // Set the result in proxy resolver.
413 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); 415 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy");
414 resolver.pending_requests()[0]->CompleteNow(OK); 416 resolver.pending_requests()[0]->CompleteNow(OK);
415 417
416 EXPECT_EQ(OK, callback.WaitForResult()); 418 EXPECT_EQ(OK, callback.WaitForResult());
417 EXPECT_FALSE(info.is_direct()); 419 EXPECT_FALSE(info.is_direct());
(...skipping 19 matching lines...) Expand all
437 entries, 4, NetLog::TYPE_PROXY_SERVICE)); 439 entries, 4, NetLog::TYPE_PROXY_SERVICE));
438 } 440 }
439 441
440 // Test that the proxy resolver does not see the URL's username/password 442 // Test that the proxy resolver does not see the URL's username/password
441 // or its reference section. 443 // or its reference section.
442 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { 444 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) {
443 MockProxyConfigService* config_service = 445 MockProxyConfigService* config_service =
444 new MockProxyConfigService("http://foopy/proxy.pac"); 446 new MockProxyConfigService("http://foopy/proxy.pac");
445 447
446 MockAsyncProxyResolver resolver; 448 MockAsyncProxyResolver resolver;
449 MockAsyncProxyResolverFactory factory(false);
447 450
448 ProxyService service( 451 ProxyService service(
449 config_service, 452 config_service,
450 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 453 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
451 454
452 GURL url("http://username:password@www.google.com/?ref#hash#hash"); 455 GURL url("http://username:password@www.google.com/?ref#hash#hash");
453 456
454 ProxyInfo info; 457 ProxyInfo info;
455 TestCompletionCallback callback; 458 TestCompletionCallback callback;
456 int rv = service.ResolveProxy( 459 int rv = service.ResolveProxy(
457 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, 460 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL,
458 BoundNetLog()); 461 BoundNetLog());
459 EXPECT_EQ(ERR_IO_PENDING, rv); 462 EXPECT_EQ(ERR_IO_PENDING, rv);
460 463
461 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 464 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
462 resolver.pending_set_pac_script_request()->script_data()->url()); 465 factory.pending_requests()[0]->script_data()->url());
463 resolver.pending_set_pac_script_request()->CompleteNow(OK); 466 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
464 467
465 ASSERT_EQ(1u, resolver.pending_requests().size()); 468 ASSERT_EQ(1u, resolver.pending_requests().size());
466 // The URL should have been simplified, stripping the username/password/hash. 469 // The URL should have been simplified, stripping the username/password/hash.
467 EXPECT_EQ(GURL("http://www.google.com/?ref"), 470 EXPECT_EQ(GURL("http://www.google.com/?ref"),
468 resolver.pending_requests()[0]->url()); 471 resolver.pending_requests()[0]->url());
469 472
470 // We end here without ever completing the request -- destruction of 473 // We end here without ever completing the request -- destruction of
471 // ProxyService will cancel the outstanding request. 474 // ProxyService will cancel the outstanding request.
472 } 475 }
473 476
474 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { 477 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) {
475 MockProxyConfigService* config_service = 478 MockProxyConfigService* config_service =
476 new MockProxyConfigService("http://foopy/proxy.pac"); 479 new MockProxyConfigService("http://foopy/proxy.pac");
477 MockAsyncProxyResolver resolver; 480 MockAsyncProxyResolver resolver;
481 MockAsyncProxyResolverFactory factory(false);
478 482
479 ProxyService service( 483 ProxyService service(
480 config_service, 484 config_service,
481 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 485 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
482 486
483 GURL url("http://www.google.com/"); 487 GURL url("http://www.google.com/");
484 488
485 ProxyInfo info; 489 ProxyInfo info;
486 TestCompletionCallback callback1; 490 TestCompletionCallback callback1;
487 int rv = service.ResolveProxy( 491 int rv = service.ResolveProxy(
488 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 492 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
489 BoundNetLog()); 493 BoundNetLog());
490 EXPECT_EQ(ERR_IO_PENDING, rv); 494 EXPECT_EQ(ERR_IO_PENDING, rv);
491 495
492 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 496 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
493 resolver.pending_set_pac_script_request()->script_data()->url()); 497 factory.pending_requests()[0]->script_data()->url());
494 resolver.pending_set_pac_script_request()->CompleteNow(OK); 498 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
495 499
496 ASSERT_EQ(1u, resolver.pending_requests().size()); 500 ASSERT_EQ(1u, resolver.pending_requests().size());
497 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 501 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
498 502
499 // Set the result in proxy resolver. 503 // Set the result in proxy resolver.
500 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); 504 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080");
501 resolver.pending_requests()[0]->CompleteNow(OK); 505 resolver.pending_requests()[0]->CompleteNow(OK);
502 506
503 EXPECT_EQ(OK, callback1.WaitForResult()); 507 EXPECT_EQ(OK, callback1.WaitForResult());
504 EXPECT_FALSE(info.is_direct()); 508 EXPECT_FALSE(info.is_direct());
(...skipping 17 matching lines...) Expand all
522 EXPECT_EQ(ERR_FAILED, rv); 526 EXPECT_EQ(ERR_FAILED, rv);
523 EXPECT_TRUE(info.is_empty()); 527 EXPECT_TRUE(info.is_empty());
524 } 528 }
525 529
526 // Test that if the execution of the PAC script fails (i.e. javascript runtime 530 // Test that if the execution of the PAC script fails (i.e. javascript runtime
527 // error), and the PAC settings are non-mandatory, that we fall-back to direct. 531 // error), and the PAC settings are non-mandatory, that we fall-back to direct.
528 TEST_F(ProxyServiceTest, PAC_RuntimeError) { 532 TEST_F(ProxyServiceTest, PAC_RuntimeError) {
529 MockProxyConfigService* config_service = 533 MockProxyConfigService* config_service =
530 new MockProxyConfigService("http://foopy/proxy.pac"); 534 new MockProxyConfigService("http://foopy/proxy.pac");
531 MockAsyncProxyResolver resolver; 535 MockAsyncProxyResolver resolver;
536 MockAsyncProxyResolverFactory factory(false);
532 537
533 ProxyService service( 538 ProxyService service(
534 config_service, 539 config_service,
535 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 540 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
536 541
537 GURL url("http://this-causes-js-error/"); 542 GURL url("http://this-causes-js-error/");
538 543
539 ProxyInfo info; 544 ProxyInfo info;
540 TestCompletionCallback callback1; 545 TestCompletionCallback callback1;
541 int rv = service.ResolveProxy( 546 int rv = service.ResolveProxy(
542 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 547 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
543 BoundNetLog()); 548 BoundNetLog());
544 EXPECT_EQ(ERR_IO_PENDING, rv); 549 EXPECT_EQ(ERR_IO_PENDING, rv);
545 550
546 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 551 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
547 resolver.pending_set_pac_script_request()->script_data()->url()); 552 factory.pending_requests()[0]->script_data()->url());
548 resolver.pending_set_pac_script_request()->CompleteNow(OK); 553 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
549 554
550 ASSERT_EQ(1u, resolver.pending_requests().size()); 555 ASSERT_EQ(1u, resolver.pending_requests().size());
551 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 556 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
552 557
553 // Simulate a failure in the PAC executor. 558 // Simulate a failure in the PAC executor.
554 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); 559 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED);
555 560
556 EXPECT_EQ(OK, callback1.WaitForResult()); 561 EXPECT_EQ(OK, callback1.WaitForResult());
557 562
558 // Since the PAC script was non-mandatory, we should have fallen-back to 563 // Since the PAC script was non-mandatory, we should have fallen-back to
(...skipping 21 matching lines...) Expand all
580 // 585 //
581 // For which we expect it to try DIRECT, then foobar:10, then DIRECT again, 586 // For which we expect it to try DIRECT, then foobar:10, then DIRECT again,
582 // then foobar:20, and then give up and error. 587 // then foobar:20, and then give up and error.
583 // 588 //
584 // The important check of this test is to make sure that DIRECT is not somehow 589 // The important check of this test is to make sure that DIRECT is not somehow
585 // cached as being a bad proxy. 590 // cached as being a bad proxy.
586 TEST_F(ProxyServiceTest, PAC_FailoverAfterDirect) { 591 TEST_F(ProxyServiceTest, PAC_FailoverAfterDirect) {
587 MockProxyConfigService* config_service = 592 MockProxyConfigService* config_service =
588 new MockProxyConfigService("http://foopy/proxy.pac"); 593 new MockProxyConfigService("http://foopy/proxy.pac");
589 MockAsyncProxyResolver resolver; 594 MockAsyncProxyResolver resolver;
595 MockAsyncProxyResolverFactory factory(false);
590 596
591 ProxyService service( 597 ProxyService service(
592 config_service, 598 config_service,
593 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 599 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
594 600
595 GURL url("http://www.google.com/"); 601 GURL url("http://www.google.com/");
596 602
597 ProxyInfo info; 603 ProxyInfo info;
598 TestCompletionCallback callback1; 604 TestCompletionCallback callback1;
599 int rv = service.ResolveProxy( 605 int rv = service.ResolveProxy(
600 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 606 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
601 BoundNetLog()); 607 BoundNetLog());
602 EXPECT_EQ(ERR_IO_PENDING, rv); 608 EXPECT_EQ(ERR_IO_PENDING, rv);
603 609
604 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 610 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
605 resolver.pending_set_pac_script_request()->script_data()->url()); 611 factory.pending_requests()[0]->script_data()->url());
606 resolver.pending_set_pac_script_request()->CompleteNow(OK); 612 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
607 613
608 ASSERT_EQ(1u, resolver.pending_requests().size()); 614 ASSERT_EQ(1u, resolver.pending_requests().size());
609 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 615 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
610 616
611 // Set the result in proxy resolver. 617 // Set the result in proxy resolver.
612 resolver.pending_requests()[0]->results()->UsePacString( 618 resolver.pending_requests()[0]->results()->UsePacString(
613 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); 619 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20");
614 resolver.pending_requests()[0]->CompleteNow(OK); 620 resolver.pending_requests()[0]->CompleteNow(OK);
615 621
616 EXPECT_EQ(OK, callback1.WaitForResult()); 622 EXPECT_EQ(OK, callback1.WaitForResult());
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
661 667
662 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { 668 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) {
663 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied 669 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied
664 // to ProxyInfo after the proxy is resolved via a PAC script. 670 // to ProxyInfo after the proxy is resolved via a PAC script.
665 ProxyConfig config = 671 ProxyConfig config =
666 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); 672 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"));
667 config.set_source(PROXY_CONFIG_SOURCE_TEST); 673 config.set_source(PROXY_CONFIG_SOURCE_TEST);
668 674
669 MockProxyConfigService* config_service = new MockProxyConfigService(config); 675 MockProxyConfigService* config_service = new MockProxyConfigService(config);
670 MockAsyncProxyResolver resolver; 676 MockAsyncProxyResolver resolver;
677 MockAsyncProxyResolverFactory factory(false);
671 ProxyService service( 678 ProxyService service(
672 config_service, 679 config_service,
673 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 680 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
674 681
675 // Resolve something. 682 // Resolve something.
676 GURL url("http://www.google.com/"); 683 GURL url("http://www.google.com/");
677 ProxyInfo info; 684 ProxyInfo info;
678 TestCompletionCallback callback; 685 TestCompletionCallback callback;
679 int rv = service.ResolveProxy( 686 int rv = service.ResolveProxy(
680 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, 687 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL,
681 BoundNetLog()); 688 BoundNetLog());
682 ASSERT_EQ(ERR_IO_PENDING, rv); 689 ASSERT_EQ(ERR_IO_PENDING, rv);
683 resolver.pending_set_pac_script_request()->CompleteNow(OK); 690 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
684 ASSERT_EQ(1u, resolver.pending_requests().size()); 691 ASSERT_EQ(1u, resolver.pending_requests().size());
685 692
686 // Set the result in proxy resolver. 693 // Set the result in proxy resolver.
687 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); 694 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy");
688 resolver.pending_requests()[0]->CompleteNow(OK); 695 resolver.pending_requests()[0]->CompleteNow(OK);
689 696
690 EXPECT_EQ(OK, callback.WaitForResult()); 697 EXPECT_EQ(OK, callback.WaitForResult());
691 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); 698 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
692 EXPECT_TRUE(info.did_use_pac_script()); 699 EXPECT_TRUE(info.did_use_pac_script());
693 700
694 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 701 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
695 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 702 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
696 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 703 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
697 } 704 }
698 705
699 TEST_F(ProxyServiceTest, ProxyResolverFails) { 706 TEST_F(ProxyServiceTest, ProxyResolverFails) {
700 // Test what happens when the ProxyResolver fails. The download and setting 707 // Test what happens when the ProxyResolver fails. The download and setting
701 // of the PAC script have already succeeded, so this corresponds with a 708 // of the PAC script have already succeeded, so this corresponds with a
702 // javascript runtime error while calling FindProxyForURL(). 709 // javascript runtime error while calling FindProxyForURL().
703 710
704 MockProxyConfigService* config_service = 711 MockProxyConfigService* config_service =
705 new MockProxyConfigService("http://foopy/proxy.pac"); 712 new MockProxyConfigService("http://foopy/proxy.pac");
706 713
707 MockAsyncProxyResolver resolver; 714 MockAsyncProxyResolver resolver;
715 MockAsyncProxyResolverFactory factory(false);
708 716
709 ProxyService service( 717 ProxyService service(
710 config_service, 718 config_service,
711 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 719 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
712 720
713 // Start first resolve request. 721 // Start first resolve request.
714 GURL url("http://www.google.com/"); 722 GURL url("http://www.google.com/");
715 ProxyInfo info; 723 ProxyInfo info;
716 TestCompletionCallback callback1; 724 TestCompletionCallback callback1;
717 int rv = service.ResolveProxy( 725 int rv = service.ResolveProxy(
718 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 726 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
719 BoundNetLog()); 727 BoundNetLog());
720 EXPECT_EQ(ERR_IO_PENDING, rv); 728 EXPECT_EQ(ERR_IO_PENDING, rv);
721 729
722 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 730 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
723 resolver.pending_set_pac_script_request()->script_data()->url()); 731 factory.pending_requests()[0]->script_data()->url());
724 resolver.pending_set_pac_script_request()->CompleteNow(OK); 732 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
725 733
726 ASSERT_EQ(1u, resolver.pending_requests().size()); 734 ASSERT_EQ(1u, resolver.pending_requests().size());
727 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 735 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
728 736
729 // Fail the first resolve request in MockAsyncProxyResolver. 737 // Fail the first resolve request in MockAsyncProxyResolver.
730 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); 738 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED);
731 739
732 // Although the proxy resolver failed the request, ProxyService implicitly 740 // Although the proxy resolver failed the request, ProxyService implicitly
733 // falls-back to DIRECT. 741 // falls-back to DIRECT.
734 EXPECT_EQ(OK, callback1.WaitForResult()); 742 EXPECT_EQ(OK, callback1.WaitForResult());
(...skipping 28 matching lines...) Expand all
763 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { 771 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) {
764 // Test what happens when the ProxyScriptResolver fails to download a 772 // Test what happens when the ProxyScriptResolver fails to download a
765 // mandatory PAC script. 773 // mandatory PAC script.
766 774
767 ProxyConfig config( 775 ProxyConfig config(
768 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); 776 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")));
769 config.set_pac_mandatory(true); 777 config.set_pac_mandatory(true);
770 778
771 MockProxyConfigService* config_service = new MockProxyConfigService(config); 779 MockProxyConfigService* config_service = new MockProxyConfigService(config);
772 780
773 MockAsyncProxyResolver resolver; 781 MockAsyncProxyResolverFactory factory(false);
774 782
775 ProxyService service( 783 ProxyService service(
776 config_service, 784 config_service,
777 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 785 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
778 786
779 // Start first resolve request. 787 // Start first resolve request.
780 GURL url("http://www.google.com/"); 788 GURL url("http://www.google.com/");
781 ProxyInfo info; 789 ProxyInfo info;
782 TestCompletionCallback callback1; 790 TestCompletionCallback callback1;
783 int rv = service.ResolveProxy( 791 int rv = service.ResolveProxy(
784 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 792 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
785 BoundNetLog()); 793 BoundNetLog());
786 EXPECT_EQ(ERR_IO_PENDING, rv); 794 EXPECT_EQ(ERR_IO_PENDING, rv);
787 795
788 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 796 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
789 resolver.pending_set_pac_script_request()->script_data()->url()); 797 factory.pending_requests()[0]->script_data()->url());
790 resolver.pending_set_pac_script_request()->CompleteNow(ERR_FAILED); 798 factory.pending_requests()[0]->CompleteNow(ERR_FAILED, nullptr);
791 799
792 ASSERT_EQ(0u, resolver.pending_requests().size()); 800 ASSERT_EQ(0u, factory.pending_requests().size());
793 // As the proxy resolver failed the request and is configured for a mandatory 801 // As the proxy resolver factory failed the request and is configured for a
794 // PAC script, ProxyService must not implicitly fall-back to DIRECT. 802 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT.
795 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, 803 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED,
796 callback1.WaitForResult()); 804 callback1.WaitForResult());
797 EXPECT_FALSE(info.is_direct()); 805 EXPECT_FALSE(info.is_direct());
798 806
799 // As the proxy resolver failed the request and is configured for a mandatory 807 // As the proxy resolver factory failed the request and is configured for a
800 // PAC script, ProxyService must not implicitly fall-back to DIRECT. 808 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT.
801 TestCompletionCallback callback2; 809 TestCompletionCallback callback2;
802 rv = service.ResolveProxy( 810 rv = service.ResolveProxy(
803 url, net::LOAD_NORMAL, &info, callback2.callback(), NULL, NULL, 811 url, net::LOAD_NORMAL, &info, callback2.callback(), NULL, NULL,
804 BoundNetLog()); 812 BoundNetLog());
805 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); 813 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv);
806 EXPECT_FALSE(info.is_direct()); 814 EXPECT_FALSE(info.is_direct());
807 } 815 }
808 816
809 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { 817 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) {
810 // Test what happens when the ProxyResolver fails that is configured to use a 818 // Test what happens when the ProxyResolver fails that is configured to use a
811 // mandatory PAC script. The download of the PAC script has already 819 // mandatory PAC script. The download of the PAC script has already
812 // succeeded but the PAC script contains no valid javascript. 820 // succeeded but the PAC script contains no valid javascript.
813 821
814 ProxyConfig config( 822 ProxyConfig config(
815 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); 823 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")));
816 config.set_pac_mandatory(true); 824 config.set_pac_mandatory(true);
817 825
818 MockProxyConfigService* config_service = new MockProxyConfigService(config); 826 MockProxyConfigService* config_service = new MockProxyConfigService(config);
819 827
820 MockAsyncProxyResolverExpectsBytes resolver; 828 MockAsyncProxyResolverFactory factory(true);
821 829
822 ProxyService service( 830 ProxyService service(
823 config_service, 831 config_service,
824 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 832 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
825 833
826 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 834 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
827 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); 835 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher();
828 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); 836 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher);
829 837
830 // Start resolve request. 838 // Start resolve request.
831 GURL url("http://www.google.com/"); 839 GURL url("http://www.google.com/");
832 ProxyInfo info; 840 ProxyInfo info;
833 TestCompletionCallback callback; 841 TestCompletionCallback callback;
834 int rv = service.ResolveProxy( 842 int rv = service.ResolveProxy(
835 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, 843 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL,
836 BoundNetLog()); 844 BoundNetLog());
837 EXPECT_EQ(ERR_IO_PENDING, rv); 845 EXPECT_EQ(ERR_IO_PENDING, rv);
838 846
839 // Check that nothing has been sent to the proxy resolver yet. 847 // Check that nothing has been sent to the proxy resolver factory yet.
840 ASSERT_EQ(0u, resolver.pending_requests().size()); 848 ASSERT_EQ(0u, factory.pending_requests().size());
841 849
842 // Downloading the PAC script succeeds. 850 // Downloading the PAC script succeeds.
843 EXPECT_TRUE(fetcher->has_pending_request()); 851 EXPECT_TRUE(fetcher->has_pending_request());
844 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 852 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
845 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); 853 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents");
846 854
847 EXPECT_FALSE(fetcher->has_pending_request()); 855 EXPECT_FALSE(fetcher->has_pending_request());
848 ASSERT_EQ(0u, resolver.pending_requests().size()); 856 ASSERT_EQ(0u, factory.pending_requests().size());
849 857
850 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was 858 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was
851 // mandatory for this configuration, the ProxyService must not implicitly 859 // mandatory for this configuration, the ProxyService must not implicitly
852 // fall-back to DIRECT. 860 // fall-back to DIRECT.
853 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, 861 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED,
854 callback.WaitForResult()); 862 callback.WaitForResult());
855 EXPECT_FALSE(info.is_direct()); 863 EXPECT_FALSE(info.is_direct());
856 } 864 }
857 865
858 TEST_F(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { 866 TEST_F(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) {
859 // Test what happens when the ProxyResolver fails that is configured to use a 867 // Test what happens when the ProxyResolver fails that is configured to use a
860 // mandatory PAC script. The download and setting of the PAC script have 868 // mandatory PAC script. The download and setting of the PAC script have
861 // already succeeded, so this corresponds with a javascript runtime error 869 // already succeeded, so this corresponds with a javascript runtime error
862 // while calling FindProxyForURL(). 870 // while calling FindProxyForURL().
863 871
864 ProxyConfig config( 872 ProxyConfig config(
865 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); 873 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")));
866 config.set_pac_mandatory(true); 874 config.set_pac_mandatory(true);
867 875
868 MockProxyConfigService* config_service = new MockProxyConfigService(config); 876 MockProxyConfigService* config_service = new MockProxyConfigService(config);
869 877
870 MockAsyncProxyResolver resolver; 878 MockAsyncProxyResolver resolver;
879 MockAsyncProxyResolverFactory factory(false);
871 880
872 ProxyService service( 881 ProxyService service(
873 config_service, 882 config_service,
874 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 883 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
875 884
876 // Start first resolve request. 885 // Start first resolve request.
877 GURL url("http://www.google.com/"); 886 GURL url("http://www.google.com/");
878 ProxyInfo info; 887 ProxyInfo info;
879 TestCompletionCallback callback1; 888 TestCompletionCallback callback1;
880 int rv = service.ResolveProxy( 889 int rv = service.ResolveProxy(
881 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 890 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
882 BoundNetLog()); 891 BoundNetLog());
883 EXPECT_EQ(ERR_IO_PENDING, rv); 892 EXPECT_EQ(ERR_IO_PENDING, rv);
884 893
885 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 894 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
886 resolver.pending_set_pac_script_request()->script_data()->url()); 895 factory.pending_requests()[0]->script_data()->url());
887 resolver.pending_set_pac_script_request()->CompleteNow(OK); 896 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
888 897
889 ASSERT_EQ(1u, resolver.pending_requests().size()); 898 ASSERT_EQ(1u, resolver.pending_requests().size());
890 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 899 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
891 900
892 // Fail the first resolve request in MockAsyncProxyResolver. 901 // Fail the first resolve request in MockAsyncProxyResolver.
893 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); 902 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED);
894 903
895 // As the proxy resolver failed the request and is configured for a mandatory 904 // As the proxy resolver failed the request and is configured for a mandatory
896 // PAC script, ProxyService must not implicitly fall-back to DIRECT. 905 // PAC script, ProxyService must not implicitly fall-back to DIRECT.
897 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, 906 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED,
(...skipping 22 matching lines...) Expand all
920 } 929 }
921 930
922 TEST_F(ProxyServiceTest, ProxyFallback) { 931 TEST_F(ProxyServiceTest, ProxyFallback) {
923 // Test what happens when we specify multiple proxy servers and some of them 932 // Test what happens when we specify multiple proxy servers and some of them
924 // are bad. 933 // are bad.
925 934
926 MockProxyConfigService* config_service = 935 MockProxyConfigService* config_service =
927 new MockProxyConfigService("http://foopy/proxy.pac"); 936 new MockProxyConfigService("http://foopy/proxy.pac");
928 937
929 MockAsyncProxyResolver resolver; 938 MockAsyncProxyResolver resolver;
939 MockAsyncProxyResolverFactory factory(false);
930 940
931 ProxyService service( 941 ProxyService service(
932 config_service, 942 config_service,
933 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 943 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
934 944
935 GURL url("http://www.google.com/"); 945 GURL url("http://www.google.com/");
936 946
937 // Get the proxy information. 947 // Get the proxy information.
938 ProxyInfo info; 948 ProxyInfo info;
939 TestCompletionCallback callback1; 949 TestCompletionCallback callback1;
940 int rv = service.ResolveProxy( 950 int rv = service.ResolveProxy(
941 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 951 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
942 BoundNetLog()); 952 BoundNetLog());
943 EXPECT_EQ(ERR_IO_PENDING, rv); 953 EXPECT_EQ(ERR_IO_PENDING, rv);
944 954
945 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 955 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
946 resolver.pending_set_pac_script_request()->script_data()->url()); 956 factory.pending_requests()[0]->script_data()->url());
947 resolver.pending_set_pac_script_request()->CompleteNow(OK); 957 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
948 958
949 ASSERT_EQ(1u, resolver.pending_requests().size()); 959 ASSERT_EQ(1u, resolver.pending_requests().size());
950 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 960 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
951 961
952 // Set the result in proxy resolver. 962 // Set the result in proxy resolver.
953 resolver.pending_requests()[0]->results()->UseNamedProxy( 963 resolver.pending_requests()[0]->results()->UseNamedProxy(
954 "foopy1:8080;foopy2:9090"); 964 "foopy1:8080;foopy2:9090");
955 resolver.pending_requests()[0]->CompleteNow(OK); 965 resolver.pending_requests()[0]->CompleteNow(OK);
956 966
957 // The first item is valid. 967 // The first item is valid.
(...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after
1075 // TODO(nsylvain): Test that the proxy can be retried after the delay. 1085 // TODO(nsylvain): Test that the proxy can be retried after the delay.
1076 } 1086 }
1077 1087
1078 // This test is similar to ProxyFallback, but this time we have an explicit 1088 // This test is similar to ProxyFallback, but this time we have an explicit
1079 // fallback choice to DIRECT. 1089 // fallback choice to DIRECT.
1080 TEST_F(ProxyServiceTest, ProxyFallbackToDirect) { 1090 TEST_F(ProxyServiceTest, ProxyFallbackToDirect) {
1081 MockProxyConfigService* config_service = 1091 MockProxyConfigService* config_service =
1082 new MockProxyConfigService("http://foopy/proxy.pac"); 1092 new MockProxyConfigService("http://foopy/proxy.pac");
1083 1093
1084 MockAsyncProxyResolver resolver; 1094 MockAsyncProxyResolver resolver;
1095 MockAsyncProxyResolverFactory factory(false);
1085 1096
1086 ProxyService service( 1097 ProxyService service(
1087 config_service, 1098 config_service,
1088 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 1099 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
1089 1100
1090 GURL url("http://www.google.com/"); 1101 GURL url("http://www.google.com/");
1091 1102
1092 // Get the proxy information. 1103 // Get the proxy information.
1093 ProxyInfo info; 1104 ProxyInfo info;
1094 TestCompletionCallback callback1; 1105 TestCompletionCallback callback1;
1095 int rv = service.ResolveProxy( 1106 int rv = service.ResolveProxy(
1096 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 1107 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
1097 BoundNetLog()); 1108 BoundNetLog());
1098 EXPECT_EQ(ERR_IO_PENDING, rv); 1109 EXPECT_EQ(ERR_IO_PENDING, rv);
1099 1110
1100 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1111 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1101 resolver.pending_set_pac_script_request()->script_data()->url()); 1112 factory.pending_requests()[0]->script_data()->url());
1102 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1113 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1103 1114
1104 ASSERT_EQ(1u, resolver.pending_requests().size()); 1115 ASSERT_EQ(1u, resolver.pending_requests().size());
1105 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 1116 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
1106 1117
1107 // Set the result in proxy resolver. 1118 // Set the result in proxy resolver.
1108 resolver.pending_requests()[0]->results()->UsePacString( 1119 resolver.pending_requests()[0]->results()->UsePacString(
1109 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); 1120 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT");
1110 resolver.pending_requests()[0]->CompleteNow(OK); 1121 resolver.pending_requests()[0]->CompleteNow(OK);
1111 1122
1112 // Get the first result. 1123 // Get the first result.
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
1151 EXPECT_EQ(ERR_FAILED, rv); 1162 EXPECT_EQ(ERR_FAILED, rv);
1152 } 1163 }
1153 1164
1154 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { 1165 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) {
1155 // Test proxy failover when new settings are available. 1166 // Test proxy failover when new settings are available.
1156 1167
1157 MockProxyConfigService* config_service = 1168 MockProxyConfigService* config_service =
1158 new MockProxyConfigService("http://foopy/proxy.pac"); 1169 new MockProxyConfigService("http://foopy/proxy.pac");
1159 1170
1160 MockAsyncProxyResolver resolver; 1171 MockAsyncProxyResolver resolver;
1172 MockAsyncProxyResolverFactory factory(false);
1161 1173
1162 ProxyService service( 1174 ProxyService service(
1163 config_service, 1175 config_service,
1164 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 1176 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
1165 1177
1166 GURL url("http://www.google.com/"); 1178 GURL url("http://www.google.com/");
1167 1179
1168 // Get the proxy information. 1180 // Get the proxy information.
1169 ProxyInfo info; 1181 ProxyInfo info;
1170 TestCompletionCallback callback1; 1182 TestCompletionCallback callback1;
1171 int rv = service.ResolveProxy( 1183 int rv = service.ResolveProxy(
1172 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 1184 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
1173 BoundNetLog()); 1185 BoundNetLog());
1174 EXPECT_EQ(ERR_IO_PENDING, rv); 1186 EXPECT_EQ(ERR_IO_PENDING, rv);
1175 1187
1176 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1188 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1177 resolver.pending_set_pac_script_request()->script_data()->url()); 1189 factory.pending_requests()[0]->script_data()->url());
1178 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1190 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1179 1191
1180 ASSERT_EQ(1u, resolver.pending_requests().size()); 1192 ASSERT_EQ(1u, resolver.pending_requests().size());
1181 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 1193 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
1182 1194
1183 // Set the result in proxy resolver. 1195 // Set the result in proxy resolver.
1184 resolver.pending_requests()[0]->results()->UseNamedProxy( 1196 resolver.pending_requests()[0]->results()->UseNamedProxy(
1185 "foopy1:8080;foopy2:9090"); 1197 "foopy1:8080;foopy2:9090");
1186 resolver.pending_requests()[0]->CompleteNow(OK); 1198 resolver.pending_requests()[0]->CompleteNow(OK);
1187 1199
1188 // The first item is valid. 1200 // The first item is valid.
1189 EXPECT_EQ(OK, callback1.WaitForResult()); 1201 EXPECT_EQ(OK, callback1.WaitForResult());
1190 EXPECT_FALSE(info.is_direct()); 1202 EXPECT_FALSE(info.is_direct());
1191 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1203 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1192 1204
1193 // Fake an error on the proxy, and also a new configuration on the proxy. 1205 // Fake an error on the proxy, and also a new configuration on the proxy.
1194 config_service->SetConfig( 1206 config_service->SetConfig(
1195 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); 1207 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac")));
1196 1208
1197 TestCompletionCallback callback2; 1209 TestCompletionCallback callback2;
1198 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, 1210 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1199 net::ERR_PROXY_CONNECTION_FAILED, 1211 net::ERR_PROXY_CONNECTION_FAILED,
1200 &info, callback2.callback(), NULL, 1212 &info, callback2.callback(), NULL,
1201 NULL, BoundNetLog()); 1213 NULL, BoundNetLog());
1202 EXPECT_EQ(ERR_IO_PENDING, rv); 1214 EXPECT_EQ(ERR_IO_PENDING, rv);
1203 1215
1204 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), 1216 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"),
1205 resolver.pending_set_pac_script_request()->script_data()->url()); 1217 factory.pending_requests()[0]->script_data()->url());
1206 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1218 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1207 1219
1208 ASSERT_EQ(1u, resolver.pending_requests().size()); 1220 ASSERT_EQ(1u, resolver.pending_requests().size());
1209 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 1221 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
1210 1222
1211 resolver.pending_requests()[0]->results()->UseNamedProxy( 1223 resolver.pending_requests()[0]->results()->UseNamedProxy(
1212 "foopy1:8080;foopy2:9090"); 1224 "foopy1:8080;foopy2:9090");
1213 resolver.pending_requests()[0]->CompleteNow(OK); 1225 resolver.pending_requests()[0]->CompleteNow(OK);
1214 1226
1215 // The first proxy is still there since the configuration changed. 1227 // The first proxy is still there since the configuration changed.
1216 EXPECT_EQ(OK, callback2.WaitForResult()); 1228 EXPECT_EQ(OK, callback2.WaitForResult());
(...skipping 15 matching lines...) Expand all
1232 1244
1233 // We fake another error. It should go back to the first proxy. 1245 // We fake another error. It should go back to the first proxy.
1234 TestCompletionCallback callback4; 1246 TestCompletionCallback callback4;
1235 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL, 1247 rv = service.ReconsiderProxyAfterError(url, net::LOAD_NORMAL,
1236 net::ERR_PROXY_CONNECTION_FAILED, 1248 net::ERR_PROXY_CONNECTION_FAILED,
1237 &info, callback4.callback(), NULL, 1249 &info, callback4.callback(), NULL,
1238 NULL, BoundNetLog()); 1250 NULL, BoundNetLog());
1239 EXPECT_EQ(ERR_IO_PENDING, rv); 1251 EXPECT_EQ(ERR_IO_PENDING, rv);
1240 1252
1241 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), 1253 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"),
1242 resolver.pending_set_pac_script_request()->script_data()->url()); 1254 factory.pending_requests()[0]->script_data()->url());
1243 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1255 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1244 1256
1245 ASSERT_EQ(1u, resolver.pending_requests().size()); 1257 ASSERT_EQ(1u, resolver.pending_requests().size());
1246 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 1258 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
1247 1259
1248 resolver.pending_requests()[0]->results()->UseNamedProxy( 1260 resolver.pending_requests()[0]->results()->UseNamedProxy(
1249 "foopy1:8080;foopy2:9090"); 1261 "foopy1:8080;foopy2:9090");
1250 resolver.pending_requests()[0]->CompleteNow(OK); 1262 resolver.pending_requests()[0]->CompleteNow(OK);
1251 1263
1252 EXPECT_EQ(OK, callback4.WaitForResult()); 1264 EXPECT_EQ(OK, callback4.WaitForResult());
1253 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); 1265 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
1254 1266
1255 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); 1267 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
1256 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); 1268 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
1257 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); 1269 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
1258 } 1270 }
1259 1271
1260 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { 1272 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) {
1261 // Test proxy failover when the configuration is bad. 1273 // Test proxy failover when the configuration is bad.
1262 1274
1263 MockProxyConfigService* config_service = 1275 MockProxyConfigService* config_service =
1264 new MockProxyConfigService("http://foopy/proxy.pac"); 1276 new MockProxyConfigService("http://foopy/proxy.pac");
1265 1277
1266 MockAsyncProxyResolver resolver; 1278 MockAsyncProxyResolver resolver;
1279 MockAsyncProxyResolverFactory factory(false);
1267 1280
1268 ProxyService service( 1281 ProxyService service(
1269 config_service, 1282 config_service,
1270 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 1283 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
1271 1284
1272 GURL url("http://www.google.com/"); 1285 GURL url("http://www.google.com/");
1273 1286
1274 // Get the proxy information. 1287 // Get the proxy information.
1275 ProxyInfo info; 1288 ProxyInfo info;
1276 TestCompletionCallback callback1; 1289 TestCompletionCallback callback1;
1277 int rv = service.ResolveProxy( 1290 int rv = service.ResolveProxy(
1278 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 1291 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
1279 BoundNetLog()); 1292 BoundNetLog());
1280 EXPECT_EQ(ERR_IO_PENDING, rv); 1293 EXPECT_EQ(ERR_IO_PENDING, rv);
1281 1294
1282 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1295 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1283 resolver.pending_set_pac_script_request()->script_data()->url()); 1296 factory.pending_requests()[0]->script_data()->url());
1284 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1297 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1285 ASSERT_EQ(1u, resolver.pending_requests().size()); 1298 ASSERT_EQ(1u, resolver.pending_requests().size());
1286 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 1299 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
1287 1300
1288 resolver.pending_requests()[0]->results()->UseNamedProxy( 1301 resolver.pending_requests()[0]->results()->UseNamedProxy(
1289 "foopy1:8080;foopy2:9090"); 1302 "foopy1:8080;foopy2:9090");
1290 resolver.pending_requests()[0]->CompleteNow(OK); 1303 resolver.pending_requests()[0]->CompleteNow(OK);
1291 1304
1292 // The first item is valid. 1305 // The first item is valid.
1293 EXPECT_EQ(OK, callback1.WaitForResult()); 1306 EXPECT_EQ(OK, callback1.WaitForResult());
1294 EXPECT_FALSE(info.is_direct()); 1307 EXPECT_FALSE(info.is_direct());
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
1358 TEST_F(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { 1371 TEST_F(ProxyServiceTest, ProxyFallback_BadConfigMandatory) {
1359 // Test proxy failover when the configuration is bad. 1372 // Test proxy failover when the configuration is bad.
1360 1373
1361 ProxyConfig config( 1374 ProxyConfig config(
1362 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); 1375 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")));
1363 1376
1364 config.set_pac_mandatory(true); 1377 config.set_pac_mandatory(true);
1365 MockProxyConfigService* config_service = new MockProxyConfigService(config); 1378 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1366 1379
1367 MockAsyncProxyResolver resolver; 1380 MockAsyncProxyResolver resolver;
1381 MockAsyncProxyResolverFactory factory(false);
1368 1382
1369 ProxyService service( 1383 ProxyService service(
1370 config_service, 1384 config_service,
1371 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 1385 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
1372 1386
1373 GURL url("http://www.google.com/"); 1387 GURL url("http://www.google.com/");
1374 1388
1375 // Get the proxy information. 1389 // Get the proxy information.
1376 ProxyInfo info; 1390 ProxyInfo info;
1377 TestCompletionCallback callback1; 1391 TestCompletionCallback callback1;
1378 int rv = service.ResolveProxy( 1392 int rv = service.ResolveProxy(
1379 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL, 1393 url, net::LOAD_NORMAL, &info, callback1.callback(), NULL, NULL,
1380 BoundNetLog()); 1394 BoundNetLog());
1381 EXPECT_EQ(ERR_IO_PENDING, rv); 1395 EXPECT_EQ(ERR_IO_PENDING, rv);
1382 1396
1383 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1397 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1384 resolver.pending_set_pac_script_request()->script_data()->url()); 1398 factory.pending_requests()[0]->script_data()->url());
1385 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1399 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1386 ASSERT_EQ(1u, resolver.pending_requests().size()); 1400 ASSERT_EQ(1u, resolver.pending_requests().size());
1387 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); 1401 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
1388 1402
1389 resolver.pending_requests()[0]->results()->UseNamedProxy( 1403 resolver.pending_requests()[0]->results()->UseNamedProxy(
1390 "foopy1:8080;foopy2:9090"); 1404 "foopy1:8080;foopy2:9090");
1391 resolver.pending_requests()[0]->CompleteNow(OK); 1405 resolver.pending_requests()[0]->CompleteNow(OK);
1392 1406
1393 // The first item is valid. 1407 // The first item is valid.
1394 EXPECT_EQ(OK, callback1.WaitForResult()); 1408 EXPECT_EQ(OK, callback1.WaitForResult());
1395 EXPECT_FALSE(info.is_direct()); 1409 EXPECT_FALSE(info.is_direct());
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
1648 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); 1662 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI());
1649 } 1663 }
1650 } 1664 }
1651 1665
1652 // Test cancellation of an in-progress request. 1666 // Test cancellation of an in-progress request.
1653 TEST_F(ProxyServiceTest, CancelInProgressRequest) { 1667 TEST_F(ProxyServiceTest, CancelInProgressRequest) {
1654 MockProxyConfigService* config_service = 1668 MockProxyConfigService* config_service =
1655 new MockProxyConfigService("http://foopy/proxy.pac"); 1669 new MockProxyConfigService("http://foopy/proxy.pac");
1656 1670
1657 MockAsyncProxyResolver resolver; 1671 MockAsyncProxyResolver resolver;
1672 MockAsyncProxyResolverFactory factory(false);
1658 1673
1659 ProxyService service( 1674 ProxyService service(
1660 config_service, 1675 config_service,
1661 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 1676 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
1662 1677
1663 // Start 3 requests. 1678 // Start 3 requests.
1664 1679
1665 ProxyInfo info1; 1680 ProxyInfo info1;
1666 TestCompletionCallback callback1; 1681 TestCompletionCallback callback1;
1667 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, 1682 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL,
1668 &info1, callback1.callback(), NULL, NULL, 1683 &info1, callback1.callback(), NULL, NULL,
1669 BoundNetLog()); 1684 BoundNetLog());
1670 EXPECT_EQ(ERR_IO_PENDING, rv); 1685 EXPECT_EQ(ERR_IO_PENDING, rv);
1671 1686
1672 // Nothing has been sent to the proxy resolver yet, since the proxy
1673 // resolver has not been configured yet.
1674 ASSERT_EQ(0u, resolver.pending_requests().size());
1675
1676 // Successfully initialize the PAC script. 1687 // Successfully initialize the PAC script.
1677 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 1688 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
1678 resolver.pending_set_pac_script_request()->script_data()->url()); 1689 factory.pending_requests()[0]->script_data()->url());
1679 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1690 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1680 1691
1681 ASSERT_EQ(1u, resolver.pending_requests().size()); 1692 ASSERT_EQ(1u, resolver.pending_requests().size());
1682 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 1693 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
1683 1694
1684 ProxyInfo info2; 1695 ProxyInfo info2;
1685 TestCompletionCallback callback2; 1696 TestCompletionCallback callback2;
1686 ProxyService::PacRequest* request2; 1697 ProxyService::PacRequest* request2;
1687 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, 1698 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2,
1688 callback2.callback(), &request2, NULL, 1699 callback2.callback(), &request2, NULL,
1689 BoundNetLog()); 1700 BoundNetLog());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
1725 EXPECT_EQ(OK, callback3.WaitForResult()); 1736 EXPECT_EQ(OK, callback3.WaitForResult());
1726 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); 1737 EXPECT_EQ("request3:80", info3.proxy_server().ToURI());
1727 } 1738 }
1728 1739
1729 // Test the initial PAC download for resolver that expects bytes. 1740 // Test the initial PAC download for resolver that expects bytes.
1730 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { 1741 TEST_F(ProxyServiceTest, InitialPACScriptDownload) {
1731 MockProxyConfigService* config_service = 1742 MockProxyConfigService* config_service =
1732 new MockProxyConfigService("http://foopy/proxy.pac"); 1743 new MockProxyConfigService("http://foopy/proxy.pac");
1733 1744
1734 MockAsyncProxyResolverExpectsBytes resolver; 1745 MockAsyncProxyResolverExpectsBytes resolver;
1746 MockAsyncProxyResolverFactory factory(true);
1735 1747
1736 ProxyService service( 1748 ProxyService service(
1737 config_service, 1749 config_service,
1738 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 1750 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
1739 1751
1740 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1752 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1741 service.SetProxyScriptFetchers(fetcher, 1753 service.SetProxyScriptFetchers(fetcher,
1742 new DoNothingDhcpProxyScriptFetcher()); 1754 new DoNothingDhcpProxyScriptFetcher());
1743 1755
1744 // Start 3 requests. 1756 // Start 3 requests.
1745 1757
1746 ProxyInfo info1; 1758 ProxyInfo info1;
1747 TestCompletionCallback callback1; 1759 TestCompletionCallback callback1;
1748 ProxyService::PacRequest* request1; 1760 ProxyService::PacRequest* request1;
(...skipping 15 matching lines...) Expand all
1764 EXPECT_EQ(ERR_IO_PENDING, rv); 1776 EXPECT_EQ(ERR_IO_PENDING, rv);
1765 1777
1766 ProxyInfo info3; 1778 ProxyInfo info3;
1767 TestCompletionCallback callback3; 1779 TestCompletionCallback callback3;
1768 ProxyService::PacRequest* request3; 1780 ProxyService::PacRequest* request3;
1769 rv = service.ResolveProxy(GURL("http://request3"), net::LOAD_NORMAL, &info3, 1781 rv = service.ResolveProxy(GURL("http://request3"), net::LOAD_NORMAL, &info3,
1770 callback3.callback(), &request3, NULL, 1782 callback3.callback(), &request3, NULL,
1771 BoundNetLog()); 1783 BoundNetLog());
1772 EXPECT_EQ(ERR_IO_PENDING, rv); 1784 EXPECT_EQ(ERR_IO_PENDING, rv);
1773 1785
1774 // Nothing has been sent to the resolver yet. 1786 // Nothing has been sent to the factory yet.
1775 EXPECT_TRUE(resolver.pending_requests().empty()); 1787 EXPECT_TRUE(factory.pending_requests().empty());
1776 1788
1777 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, 1789 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT,
1778 service.GetLoadState(request1)); 1790 service.GetLoadState(request1));
1779 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, 1791 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT,
1780 service.GetLoadState(request2)); 1792 service.GetLoadState(request2));
1781 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, 1793 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT,
1782 service.GetLoadState(request3)); 1794 service.GetLoadState(request3));
1783 1795
1784 // At this point the ProxyService should be waiting for the 1796 // At this point the ProxyService should be waiting for the
1785 // ProxyScriptFetcher to invoke its completion callback, notifying it of 1797 // ProxyScriptFetcher to invoke its completion callback, notifying it of
1786 // PAC script download completion. 1798 // PAC script download completion.
1787 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 1799 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
1788 1800
1789 // Now that the PAC script is downloaded, it will have been sent to the proxy 1801 // Now that the PAC script is downloaded, it will have been sent to the proxy
1790 // resolver. 1802 // resolver.
1791 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 1803 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
1792 resolver.pending_set_pac_script_request()->script_data()->utf16()); 1804 factory.pending_requests()[0]->script_data()->utf16());
1793 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1805 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1794 1806
1795 ASSERT_EQ(3u, resolver.pending_requests().size()); 1807 ASSERT_EQ(3u, resolver.pending_requests().size());
1796 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 1808 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
1797 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); 1809 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url());
1798 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[2]->url()); 1810 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[2]->url());
1799 1811
1800 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); 1812 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1));
1801 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); 1813 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2));
1802 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); 1814 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3));
1803 1815
(...skipping 28 matching lines...) Expand all
1832 EXPECT_FALSE(info3.proxy_resolve_end_time().is_null()); 1844 EXPECT_FALSE(info3.proxy_resolve_end_time().is_null());
1833 EXPECT_LE(info3.proxy_resolve_start_time(), info3.proxy_resolve_end_time()); 1845 EXPECT_LE(info3.proxy_resolve_start_time(), info3.proxy_resolve_end_time());
1834 } 1846 }
1835 1847
1836 // Test changing the ProxyScriptFetcher while PAC download is in progress. 1848 // Test changing the ProxyScriptFetcher while PAC download is in progress.
1837 TEST_F(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { 1849 TEST_F(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) {
1838 MockProxyConfigService* config_service = 1850 MockProxyConfigService* config_service =
1839 new MockProxyConfigService("http://foopy/proxy.pac"); 1851 new MockProxyConfigService("http://foopy/proxy.pac");
1840 1852
1841 MockAsyncProxyResolverExpectsBytes resolver; 1853 MockAsyncProxyResolverExpectsBytes resolver;
1854 MockAsyncProxyResolverFactory factory(true);
1842 1855
1843 ProxyService service( 1856 ProxyService service(
1844 config_service, 1857 config_service,
1845 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 1858 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
1846 1859
1847 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1860 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1848 service.SetProxyScriptFetchers(fetcher, 1861 service.SetProxyScriptFetchers(fetcher,
1849 new DoNothingDhcpProxyScriptFetcher()); 1862 new DoNothingDhcpProxyScriptFetcher());
1850 1863
1851 // Start 2 requests. 1864 // Start 2 requests.
1852 1865
1853 ProxyInfo info1; 1866 ProxyInfo info1;
1854 TestCompletionCallback callback1; 1867 TestCompletionCallback callback1;
1855 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, 1868 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL,
(...skipping 15 matching lines...) Expand all
1871 // ProxyScriptFetcher to invoke its completion callback, notifying it of 1884 // ProxyScriptFetcher to invoke its completion callback, notifying it of
1872 // PAC script download completion. 1885 // PAC script download completion.
1873 1886
1874 // We now change out the ProxyService's script fetcher. We should restart 1887 // We now change out the ProxyService's script fetcher. We should restart
1875 // the initialization with the new fetcher. 1888 // the initialization with the new fetcher.
1876 1889
1877 fetcher = new MockProxyScriptFetcher; 1890 fetcher = new MockProxyScriptFetcher;
1878 service.SetProxyScriptFetchers(fetcher, 1891 service.SetProxyScriptFetchers(fetcher,
1879 new DoNothingDhcpProxyScriptFetcher()); 1892 new DoNothingDhcpProxyScriptFetcher());
1880 1893
1881 // Nothing has been sent to the resolver yet. 1894 // Nothing has been sent to the factory yet.
1882 EXPECT_TRUE(resolver.pending_requests().empty()); 1895 EXPECT_TRUE(factory.pending_requests().empty());
1883 1896
1884 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 1897 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
1885 1898
1886 // Now that the PAC script is downloaded, it will have been sent to the proxy 1899 // Now that the PAC script is downloaded, it will have been sent to the proxy
1887 // resolver. 1900 // resolver.
1888 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 1901 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
1889 resolver.pending_set_pac_script_request()->script_data()->utf16()); 1902 factory.pending_requests()[0]->script_data()->utf16());
1890 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1903 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1891 1904
1892 ASSERT_EQ(2u, resolver.pending_requests().size()); 1905 ASSERT_EQ(2u, resolver.pending_requests().size());
1893 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 1906 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
1894 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); 1907 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url());
1895 } 1908 }
1896 1909
1897 // Test cancellation of a request, while the PAC script is being fetched. 1910 // Test cancellation of a request, while the PAC script is being fetched.
1898 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { 1911 TEST_F(ProxyServiceTest, CancelWhilePACFetching) {
1899 MockProxyConfigService* config_service = 1912 MockProxyConfigService* config_service =
1900 new MockProxyConfigService("http://foopy/proxy.pac"); 1913 new MockProxyConfigService("http://foopy/proxy.pac");
1901 1914
1902 MockAsyncProxyResolverExpectsBytes resolver; 1915 MockAsyncProxyResolverExpectsBytes resolver;
1916 MockAsyncProxyResolverFactory factory(true);
1903 1917
1904 ProxyService service( 1918 ProxyService service(
1905 config_service, 1919 config_service,
1906 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 1920 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
1907 1921
1908 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 1922 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
1909 service.SetProxyScriptFetchers(fetcher, 1923 service.SetProxyScriptFetchers(fetcher,
1910 new DoNothingDhcpProxyScriptFetcher()); 1924 new DoNothingDhcpProxyScriptFetcher());
1911 1925
1912 // Start 3 requests. 1926 // Start 3 requests.
1913 ProxyInfo info1; 1927 ProxyInfo info1;
1914 TestCompletionCallback callback1; 1928 TestCompletionCallback callback1;
1915 ProxyService::PacRequest* request1; 1929 ProxyService::PacRequest* request1;
1916 BoundTestNetLog log1; 1930 BoundTestNetLog log1;
(...skipping 13 matching lines...) Expand all
1930 callback2.callback(), &request2, NULL, 1944 callback2.callback(), &request2, NULL,
1931 BoundNetLog()); 1945 BoundNetLog());
1932 EXPECT_EQ(ERR_IO_PENDING, rv); 1946 EXPECT_EQ(ERR_IO_PENDING, rv);
1933 1947
1934 ProxyInfo info3; 1948 ProxyInfo info3;
1935 TestCompletionCallback callback3; 1949 TestCompletionCallback callback3;
1936 rv = service.ResolveProxy(GURL("http://request3"), net::LOAD_NORMAL, &info3, 1950 rv = service.ResolveProxy(GURL("http://request3"), net::LOAD_NORMAL, &info3,
1937 callback3.callback(), NULL, NULL, BoundNetLog()); 1951 callback3.callback(), NULL, NULL, BoundNetLog());
1938 EXPECT_EQ(ERR_IO_PENDING, rv); 1952 EXPECT_EQ(ERR_IO_PENDING, rv);
1939 1953
1940 // Nothing has been sent to the resolver yet. 1954 // Nothing has been sent to the factory yet.
1941 EXPECT_TRUE(resolver.pending_requests().empty()); 1955 EXPECT_TRUE(factory.pending_requests().empty());
1942 1956
1943 // Cancel the first 2 requests. 1957 // Cancel the first 2 requests.
1944 service.CancelPacRequest(request1); 1958 service.CancelPacRequest(request1);
1945 service.CancelPacRequest(request2); 1959 service.CancelPacRequest(request2);
1946 1960
1947 // At this point the ProxyService should be waiting for the 1961 // At this point the ProxyService should be waiting for the
1948 // ProxyScriptFetcher to invoke its completion callback, notifying it of 1962 // ProxyScriptFetcher to invoke its completion callback, notifying it of
1949 // PAC script download completion. 1963 // PAC script download completion.
1950 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 1964 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
1951 1965
1952 // Now that the PAC script is downloaded, it will have been sent to the 1966 // Now that the PAC script is downloaded, it will have been sent to the
1953 // proxy resolver. 1967 // proxy resolver.
1954 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 1968 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
1955 resolver.pending_set_pac_script_request()->script_data()->utf16()); 1969 factory.pending_requests()[0]->script_data()->utf16());
1956 resolver.pending_set_pac_script_request()->CompleteNow(OK); 1970 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
1957 1971
1958 ASSERT_EQ(1u, resolver.pending_requests().size()); 1972 ASSERT_EQ(1u, resolver.pending_requests().size());
1959 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url()); 1973 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url());
1960 1974
1961 // Complete all the requests. 1975 // Complete all the requests.
1962 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80"); 1976 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80");
1963 resolver.pending_requests()[0]->CompleteNow(OK); 1977 resolver.pending_requests()[0]->CompleteNow(OK);
1964 1978
1965 EXPECT_EQ(OK, callback3.WaitForResult()); 1979 EXPECT_EQ(OK, callback3.WaitForResult());
1966 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); 1980 EXPECT_EQ("request3:80", info3.proxy_server().ToURI());
(...skipping 22 matching lines...) Expand all
1989 2003
1990 // Test that if auto-detect fails, we fall-back to the custom pac. 2004 // Test that if auto-detect fails, we fall-back to the custom pac.
1991 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { 2005 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) {
1992 ProxyConfig config; 2006 ProxyConfig config;
1993 config.set_auto_detect(true); 2007 config.set_auto_detect(true);
1994 config.set_pac_url(GURL("http://foopy/proxy.pac")); 2008 config.set_pac_url(GURL("http://foopy/proxy.pac"));
1995 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. 2009 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used.
1996 2010
1997 MockProxyConfigService* config_service = new MockProxyConfigService(config); 2011 MockProxyConfigService* config_service = new MockProxyConfigService(config);
1998 MockAsyncProxyResolverExpectsBytes resolver; 2012 MockAsyncProxyResolverExpectsBytes resolver;
2013 MockAsyncProxyResolverFactory factory(true);
1999 ProxyService service( 2014 ProxyService service(
2000 config_service, 2015 config_service,
2001 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2016 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2002 2017
2003 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2018 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2004 service.SetProxyScriptFetchers(fetcher, 2019 service.SetProxyScriptFetchers(fetcher,
2005 new DoNothingDhcpProxyScriptFetcher()); 2020 new DoNothingDhcpProxyScriptFetcher());
2006 2021
2007 // Start 2 requests. 2022 // Start 2 requests.
2008 2023
2009 ProxyInfo info1; 2024 ProxyInfo info1;
2010 TestCompletionCallback callback1; 2025 TestCompletionCallback callback1;
2011 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, 2026 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL,
2012 &info1, callback1.callback(), NULL, NULL, 2027 &info1, callback1.callback(), NULL, NULL,
2013 BoundNetLog()); 2028 BoundNetLog());
2014 EXPECT_EQ(ERR_IO_PENDING, rv); 2029 EXPECT_EQ(ERR_IO_PENDING, rv);
2015 2030
2016 ProxyInfo info2; 2031 ProxyInfo info2;
2017 TestCompletionCallback callback2; 2032 TestCompletionCallback callback2;
2018 ProxyService::PacRequest* request2; 2033 ProxyService::PacRequest* request2;
2019 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, 2034 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2,
2020 callback2.callback(), &request2, NULL, 2035 callback2.callback(), &request2, NULL,
2021 BoundNetLog()); 2036 BoundNetLog());
2022 EXPECT_EQ(ERR_IO_PENDING, rv); 2037 EXPECT_EQ(ERR_IO_PENDING, rv);
2023 2038
2024 // Check that nothing has been sent to the proxy resolver yet. 2039 // Check that nothing has been sent to the proxy resolver factory yet.
2025 ASSERT_EQ(0u, resolver.pending_requests().size()); 2040 ASSERT_EQ(0u, factory.pending_requests().size());
2026 2041
2027 // It should be trying to auto-detect first -- FAIL the autodetect during 2042 // It should be trying to auto-detect first -- FAIL the autodetect during
2028 // the script download. 2043 // the script download.
2029 EXPECT_TRUE(fetcher->has_pending_request()); 2044 EXPECT_TRUE(fetcher->has_pending_request());
2030 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); 2045 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
2031 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 2046 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
2032 2047
2033 // Next it should be trying the custom PAC url. 2048 // Next it should be trying the custom PAC url.
2034 EXPECT_TRUE(fetcher->has_pending_request()); 2049 EXPECT_TRUE(fetcher->has_pending_request());
2035 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2050 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2036 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2051 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2037 2052
2038 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2053 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2039 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2054 factory.pending_requests()[0]->script_data()->utf16());
2040 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2055 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2041 2056
2042 // Now finally, the pending requests should have been sent to the resolver 2057 // Now finally, the pending requests should have been sent to the resolver
2043 // (which was initialized with custom PAC script). 2058 // (which was initialized with custom PAC script).
2044 2059
2045 ASSERT_EQ(2u, resolver.pending_requests().size()); 2060 ASSERT_EQ(2u, resolver.pending_requests().size());
2046 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 2061 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
2047 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); 2062 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url());
2048 2063
2049 // Complete the pending requests. 2064 // Complete the pending requests.
2050 resolver.pending_requests()[1]->results()->UseNamedProxy("request2:80"); 2065 resolver.pending_requests()[1]->results()->UseNamedProxy("request2:80");
(...skipping 18 matching lines...) Expand all
2069 // This is the same test as FallbackFromAutodetectToCustomPac, except 2084 // This is the same test as FallbackFromAutodetectToCustomPac, except
2070 // the auto-detect script fails parsing rather than downloading. 2085 // the auto-detect script fails parsing rather than downloading.
2071 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { 2086 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) {
2072 ProxyConfig config; 2087 ProxyConfig config;
2073 config.set_auto_detect(true); 2088 config.set_auto_detect(true);
2074 config.set_pac_url(GURL("http://foopy/proxy.pac")); 2089 config.set_pac_url(GURL("http://foopy/proxy.pac"));
2075 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. 2090 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used.
2076 2091
2077 MockProxyConfigService* config_service = new MockProxyConfigService(config); 2092 MockProxyConfigService* config_service = new MockProxyConfigService(config);
2078 MockAsyncProxyResolverExpectsBytes resolver; 2093 MockAsyncProxyResolverExpectsBytes resolver;
2094 MockAsyncProxyResolverFactory factory(true);
2079 ProxyService service( 2095 ProxyService service(
2080 config_service, 2096 config_service,
2081 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2097 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2082 2098
2083 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2099 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2084 service.SetProxyScriptFetchers(fetcher, 2100 service.SetProxyScriptFetchers(fetcher,
2085 new DoNothingDhcpProxyScriptFetcher()); 2101 new DoNothingDhcpProxyScriptFetcher());
2086 2102
2087 // Start 2 requests. 2103 // Start 2 requests.
2088 2104
2089 ProxyInfo info1; 2105 ProxyInfo info1;
2090 TestCompletionCallback callback1; 2106 TestCompletionCallback callback1;
2091 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, 2107 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL,
2092 &info1, callback1.callback(), NULL, NULL, 2108 &info1, callback1.callback(), NULL, NULL,
2093 BoundNetLog()); 2109 BoundNetLog());
2094 EXPECT_EQ(ERR_IO_PENDING, rv); 2110 EXPECT_EQ(ERR_IO_PENDING, rv);
2095 2111
2096 ProxyInfo info2; 2112 ProxyInfo info2;
2097 TestCompletionCallback callback2; 2113 TestCompletionCallback callback2;
2098 ProxyService::PacRequest* request2; 2114 ProxyService::PacRequest* request2;
2099 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, 2115 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2,
2100 callback2.callback(), &request2, NULL, 2116 callback2.callback(), &request2, NULL,
2101 BoundNetLog()); 2117 BoundNetLog());
2102 EXPECT_EQ(ERR_IO_PENDING, rv); 2118 EXPECT_EQ(ERR_IO_PENDING, rv);
2103 2119
2104 // Check that nothing has been sent to the proxy resolver yet. 2120 // Check that nothing has been sent to the proxy resolver factory yet.
2105 ASSERT_EQ(0u, resolver.pending_requests().size()); 2121 ASSERT_EQ(0u, factory.pending_requests().size());
2106 2122
2107 // It should be trying to auto-detect first -- succeed the download. 2123 // It should be trying to auto-detect first -- succeed the download.
2108 EXPECT_TRUE(fetcher->has_pending_request()); 2124 EXPECT_TRUE(fetcher->has_pending_request());
2109 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); 2125 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
2110 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); 2126 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents");
2111 2127
2112 // The script contents passed failed basic verification step (since didn't 2128 // The script contents passed failed basic verification step (since didn't
2113 // contain token FindProxyForURL), so it was never passed to the resolver. 2129 // contain token FindProxyForURL), so it was never passed to the resolver.
2114 2130
2115 // Next it should be trying the custom PAC url. 2131 // Next it should be trying the custom PAC url.
2116 EXPECT_TRUE(fetcher->has_pending_request()); 2132 EXPECT_TRUE(fetcher->has_pending_request());
2117 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2133 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2118 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2134 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2119 2135
2120 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2136 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2121 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2137 factory.pending_requests()[0]->script_data()->utf16());
2122 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2138 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2123 2139
2124 // Now finally, the pending requests should have been sent to the resolver 2140 // Now finally, the pending requests should have been sent to the resolver
2125 // (which was initialized with custom PAC script). 2141 // (which was initialized with custom PAC script).
2126 2142
2127 ASSERT_EQ(2u, resolver.pending_requests().size()); 2143 ASSERT_EQ(2u, resolver.pending_requests().size());
2128 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 2144 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
2129 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); 2145 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url());
2130 2146
2131 // Complete the pending requests. 2147 // Complete the pending requests.
2132 resolver.pending_requests()[1]->results()->UseNamedProxy("request2:80"); 2148 resolver.pending_requests()[1]->results()->UseNamedProxy("request2:80");
(...skipping 11 matching lines...) Expand all
2144 2160
2145 // Test that if all of auto-detect, a custom PAC script, and manual settings 2161 // Test that if all of auto-detect, a custom PAC script, and manual settings
2146 // are given, then we will try them in that order. 2162 // are given, then we will try them in that order.
2147 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { 2163 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) {
2148 ProxyConfig config; 2164 ProxyConfig config;
2149 config.set_auto_detect(true); 2165 config.set_auto_detect(true);
2150 config.set_pac_url(GURL("http://foopy/proxy.pac")); 2166 config.set_pac_url(GURL("http://foopy/proxy.pac"));
2151 config.proxy_rules().ParseFromString("http=foopy:80"); 2167 config.proxy_rules().ParseFromString("http=foopy:80");
2152 2168
2153 MockProxyConfigService* config_service = new MockProxyConfigService(config); 2169 MockProxyConfigService* config_service = new MockProxyConfigService(config);
2154 MockAsyncProxyResolverExpectsBytes resolver; 2170 MockAsyncProxyResolverFactory factory(true);
2155 ProxyService service( 2171 ProxyService service(
2156 config_service, 2172 config_service,
2157 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2173 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2158 2174
2159 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2175 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2160 service.SetProxyScriptFetchers(fetcher, 2176 service.SetProxyScriptFetchers(fetcher,
2161 new DoNothingDhcpProxyScriptFetcher()); 2177 new DoNothingDhcpProxyScriptFetcher());
2162 2178
2163 // Start 2 requests. 2179 // Start 2 requests.
2164 2180
2165 ProxyInfo info1; 2181 ProxyInfo info1;
2166 TestCompletionCallback callback1; 2182 TestCompletionCallback callback1;
2167 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, 2183 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL,
2168 &info1, callback1.callback(), NULL, NULL, 2184 &info1, callback1.callback(), NULL, NULL,
2169 BoundNetLog()); 2185 BoundNetLog());
2170 EXPECT_EQ(ERR_IO_PENDING, rv); 2186 EXPECT_EQ(ERR_IO_PENDING, rv);
2171 2187
2172 ProxyInfo info2; 2188 ProxyInfo info2;
2173 TestCompletionCallback callback2; 2189 TestCompletionCallback callback2;
2174 ProxyService::PacRequest* request2; 2190 ProxyService::PacRequest* request2;
2175 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, 2191 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2,
2176 callback2.callback(), &request2, NULL, 2192 callback2.callback(), &request2, NULL,
2177 BoundNetLog()); 2193 BoundNetLog());
2178 EXPECT_EQ(ERR_IO_PENDING, rv); 2194 EXPECT_EQ(ERR_IO_PENDING, rv);
2179 2195
2180 // Check that nothing has been sent to the proxy resolver yet. 2196 // Check that nothing has been sent to the proxy resolver factory yet.
2181 ASSERT_EQ(0u, resolver.pending_requests().size()); 2197 ASSERT_EQ(0u, factory.pending_requests().size());
2182 2198
2183 // It should be trying to auto-detect first -- fail the download. 2199 // It should be trying to auto-detect first -- fail the download.
2184 EXPECT_TRUE(fetcher->has_pending_request()); 2200 EXPECT_TRUE(fetcher->has_pending_request());
2185 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); 2201 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
2186 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 2202 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
2187 2203
2188 // Next it should be trying the custom PAC url -- fail the download. 2204 // Next it should be trying the custom PAC url -- fail the download.
2189 EXPECT_TRUE(fetcher->has_pending_request()); 2205 EXPECT_TRUE(fetcher->has_pending_request());
2190 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2206 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2191 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 2207 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
2192 2208
2193 // Since we never managed to initialize a resolver, nothing should have been 2209 // Since we never managed to initialize a resolver, nothing should have been
2194 // sent to it. 2210 // sent to it.
2195 ASSERT_EQ(0u, resolver.pending_requests().size()); 2211 ASSERT_EQ(0u, factory.pending_requests().size());
2196 2212
2197 // Verify that requests ran as expected -- they should have fallen back to 2213 // Verify that requests ran as expected -- they should have fallen back to
2198 // the manual proxy configuration for HTTP urls. 2214 // the manual proxy configuration for HTTP urls.
2199 EXPECT_EQ(OK, callback1.WaitForResult()); 2215 EXPECT_EQ(OK, callback1.WaitForResult());
2200 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); 2216 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI());
2201 2217
2202 EXPECT_EQ(OK, callback2.WaitForResult()); 2218 EXPECT_EQ(OK, callback2.WaitForResult());
2203 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); 2219 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI());
2204 } 2220 }
2205 2221
2206 // Test that the bypass rules are NOT applied when using autodetect. 2222 // Test that the bypass rules are NOT applied when using autodetect.
2207 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { 2223 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) {
2208 ProxyConfig config; 2224 ProxyConfig config;
2209 config.set_auto_detect(true); 2225 config.set_auto_detect(true);
2210 config.set_pac_url(GURL("http://foopy/proxy.pac")); 2226 config.set_pac_url(GURL("http://foopy/proxy.pac"));
2211 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. 2227 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used.
2212 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); 2228 config.proxy_rules().bypass_rules.ParseFromString("www.google.com");
2213 2229
2214 MockProxyConfigService* config_service = new MockProxyConfigService(config); 2230 MockProxyConfigService* config_service = new MockProxyConfigService(config);
2215 MockAsyncProxyResolverExpectsBytes resolver; 2231 MockAsyncProxyResolverExpectsBytes resolver;
2232 MockAsyncProxyResolverFactory factory(true);
2216 ProxyService service( 2233 ProxyService service(
2217 config_service, 2234 config_service,
2218 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2235 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2219 2236
2220 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2237 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2221 service.SetProxyScriptFetchers(fetcher, 2238 service.SetProxyScriptFetchers(fetcher,
2222 new DoNothingDhcpProxyScriptFetcher()); 2239 new DoNothingDhcpProxyScriptFetcher());
2223 2240
2224 // Start 1 requests. 2241 // Start 1 requests.
2225 2242
2226 ProxyInfo info1; 2243 ProxyInfo info1;
2227 TestCompletionCallback callback1; 2244 TestCompletionCallback callback1;
2228 int rv = service.ResolveProxy( 2245 int rv = service.ResolveProxy(
2229 GURL("http://www.google.com"), net::LOAD_NORMAL, &info1, 2246 GURL("http://www.google.com"), net::LOAD_NORMAL, &info1,
2230 callback1.callback(), NULL, NULL, BoundNetLog()); 2247 callback1.callback(), NULL, NULL, BoundNetLog());
2231 EXPECT_EQ(ERR_IO_PENDING, rv); 2248 EXPECT_EQ(ERR_IO_PENDING, rv);
2232 2249
2233 // Check that nothing has been sent to the proxy resolver yet. 2250 // Check that nothing has been sent to the proxy resolver factory yet.
2234 ASSERT_EQ(0u, resolver.pending_requests().size()); 2251 ASSERT_EQ(0u, factory.pending_requests().size());
2235 2252
2236 // It should be trying to auto-detect first -- succeed the download. 2253 // It should be trying to auto-detect first -- succeed the download.
2237 EXPECT_TRUE(fetcher->has_pending_request()); 2254 EXPECT_TRUE(fetcher->has_pending_request());
2238 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); 2255 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url());
2239 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2256 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2240 2257
2241 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2258 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2242 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2259 factory.pending_requests()[0]->script_data()->utf16());
2243 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2260 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2244 2261
2245 ASSERT_EQ(1u, resolver.pending_requests().size()); 2262 ASSERT_EQ(1u, resolver.pending_requests().size());
2246 EXPECT_EQ(GURL("http://www.google.com"), 2263 EXPECT_EQ(GURL("http://www.google.com"),
2247 resolver.pending_requests()[0]->url()); 2264 resolver.pending_requests()[0]->url());
2248 2265
2249 // Complete the pending request. 2266 // Complete the pending request.
2250 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); 2267 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80");
2251 resolver.pending_requests()[0]->CompleteNow(OK); 2268 resolver.pending_requests()[0]->CompleteNow(OK);
2252 2269
2253 // Verify that request ran as expected. 2270 // Verify that request ran as expected.
(...skipping 22 matching lines...) Expand all
2276 2293
2277 // Delete the ProxyService while InitProxyResolver has an outstanding 2294 // Delete the ProxyService while InitProxyResolver has an outstanding
2278 // request to the script fetcher. When run under valgrind, should not 2295 // request to the script fetcher. When run under valgrind, should not
2279 // have any memory errors (used to be that the ProxyScriptFetcher was 2296 // have any memory errors (used to be that the ProxyScriptFetcher was
2280 // being deleted prior to the InitProxyResolver). 2297 // being deleted prior to the InitProxyResolver).
2281 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { 2298 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) {
2282 ProxyConfig config = 2299 ProxyConfig config =
2283 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); 2300 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"));
2284 2301
2285 MockProxyConfigService* config_service = new MockProxyConfigService(config); 2302 MockProxyConfigService* config_service = new MockProxyConfigService(config);
2286 MockAsyncProxyResolverExpectsBytes resolver; 2303 MockAsyncProxyResolverFactory factory(true);
2287 ProxyService service( 2304 ProxyService service(
2288 config_service, 2305 config_service,
2289 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2306 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2290 2307
2291 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2308 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2292 service.SetProxyScriptFetchers(fetcher, 2309 service.SetProxyScriptFetchers(fetcher,
2293 new DoNothingDhcpProxyScriptFetcher()); 2310 new DoNothingDhcpProxyScriptFetcher());
2294 2311
2295 // Start 1 request. 2312 // Start 1 request.
2296 2313
2297 ProxyInfo info1; 2314 ProxyInfo info1;
2298 TestCompletionCallback callback1; 2315 TestCompletionCallback callback1;
2299 int rv = service.ResolveProxy(GURL("http://www.google.com"), net::LOAD_NORMAL, 2316 int rv = service.ResolveProxy(GURL("http://www.google.com"), net::LOAD_NORMAL,
2300 &info1, callback1.callback(), NULL, NULL, 2317 &info1, callback1.callback(), NULL, NULL,
2301 BoundNetLog()); 2318 BoundNetLog());
2302 EXPECT_EQ(ERR_IO_PENDING, rv); 2319 EXPECT_EQ(ERR_IO_PENDING, rv);
2303 2320
2304 // Check that nothing has been sent to the proxy resolver yet. 2321 // Check that nothing has been sent to the proxy resolver factory yet.
2305 ASSERT_EQ(0u, resolver.pending_requests().size()); 2322 ASSERT_EQ(0u, factory.pending_requests().size());
2306 2323
2307 // InitProxyResolver should have issued a request to the ProxyScriptFetcher 2324 // InitProxyResolver should have issued a request to the ProxyScriptFetcher
2308 // and be waiting on that to complete. 2325 // and be waiting on that to complete.
2309 EXPECT_TRUE(fetcher->has_pending_request()); 2326 EXPECT_TRUE(fetcher->has_pending_request());
2310 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2327 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2311 } 2328 }
2312 2329
2313 // Delete the ProxyService while InitProxyResolver has an outstanding 2330 // Delete the ProxyService while InitProxyResolver has an outstanding
2314 // request to the proxy resolver. When run under valgrind, should not 2331 // request to the proxy resolver. When run under valgrind, should not
2315 // have any memory errors (used to be that the ProxyResolver was 2332 // have any memory errors (used to be that the ProxyResolver was
2316 // being deleted prior to the InitProxyResolver). 2333 // being deleted prior to the InitProxyResolver).
2317 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { 2334 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) {
2318 MockProxyConfigService* config_service = 2335 MockProxyConfigService* config_service =
2319 new MockProxyConfigService("http://foopy/proxy.pac"); 2336 new MockProxyConfigService("http://foopy/proxy.pac");
2320 2337
2321 MockAsyncProxyResolver resolver; 2338 MockAsyncProxyResolverFactory factory(false);
2322 2339
2323 ProxyService service( 2340 ProxyService service(
2324 config_service, 2341 config_service,
2325 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2342 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2326 2343
2327 GURL url("http://www.google.com/"); 2344 GURL url("http://www.google.com/");
2328 2345
2329 ProxyInfo info; 2346 ProxyInfo info;
2330 TestCompletionCallback callback; 2347 TestCompletionCallback callback;
2331 int rv = service.ResolveProxy( 2348 int rv = service.ResolveProxy(
2332 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL, 2349 url, net::LOAD_NORMAL, &info, callback.callback(), NULL, NULL,
2333 BoundNetLog()); 2350 BoundNetLog());
2334 EXPECT_EQ(ERR_IO_PENDING, rv); 2351 EXPECT_EQ(ERR_IO_PENDING, rv);
2335 2352
2336 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 2353 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
2337 resolver.pending_set_pac_script_request()->script_data()->url()); 2354 factory.pending_requests()[0]->script_data()->url());
2338 } 2355 }
2339 2356
2340 TEST_F(ProxyServiceTest, ResetProxyConfigService) { 2357 TEST_F(ProxyServiceTest, ResetProxyConfigService) {
2341 ProxyConfig config1; 2358 ProxyConfig config1;
2342 config1.proxy_rules().ParseFromString("foopy1:8080"); 2359 config1.proxy_rules().ParseFromString("foopy1:8080");
2343 config1.set_auto_detect(false); 2360 config1.set_auto_detect(false);
2344 ProxyService service(new MockProxyConfigService(config1), nullptr, NULL); 2361 ProxyService service(new MockProxyConfigService(config1), nullptr, NULL);
2345 2362
2346 ProxyInfo info; 2363 ProxyInfo info;
2347 TestCompletionCallback callback1; 2364 TestCompletionCallback callback1;
(...skipping 14 matching lines...) Expand all
2362 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); 2379 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI());
2363 } 2380 }
2364 2381
2365 // Test that when going from a configuration that required PAC to one 2382 // Test that when going from a configuration that required PAC to one
2366 // that does NOT, we unset the variable |should_use_proxy_resolver_|. 2383 // that does NOT, we unset the variable |should_use_proxy_resolver_|.
2367 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { 2384 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) {
2368 ProxyConfig config = ProxyConfig::CreateAutoDetect(); 2385 ProxyConfig config = ProxyConfig::CreateAutoDetect();
2369 2386
2370 MockProxyConfigService* config_service = new MockProxyConfigService(config); 2387 MockProxyConfigService* config_service = new MockProxyConfigService(config);
2371 MockAsyncProxyResolver resolver; 2388 MockAsyncProxyResolver resolver;
2389 MockAsyncProxyResolverFactory factory(false);
2372 ProxyService service( 2390 ProxyService service(
2373 config_service, 2391 config_service,
2374 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2392 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2375 2393
2376 // Start 1 request. 2394 // Start 1 request.
2377 2395
2378 ProxyInfo info1; 2396 ProxyInfo info1;
2379 TestCompletionCallback callback1; 2397 TestCompletionCallback callback1;
2380 int rv = service.ResolveProxy(GURL("http://www.google.com"), net::LOAD_NORMAL, 2398 int rv = service.ResolveProxy(GURL("http://www.google.com"), net::LOAD_NORMAL,
2381 &info1, callback1.callback(), NULL, NULL, 2399 &info1, callback1.callback(), NULL, NULL,
2382 BoundNetLog()); 2400 BoundNetLog());
2383 EXPECT_EQ(ERR_IO_PENDING, rv); 2401 EXPECT_EQ(ERR_IO_PENDING, rv);
2384 2402
2385 // Check that nothing has been sent to the proxy resolver yet.
2386 ASSERT_EQ(0u, resolver.pending_requests().size());
2387
2388 // Successfully set the autodetect script. 2403 // Successfully set the autodetect script.
2389 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, 2404 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT,
2390 resolver.pending_set_pac_script_request()->script_data()->type()); 2405 factory.pending_requests()[0]->script_data()->type());
2391 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2406 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2392 2407
2393 // Complete the pending request. 2408 // Complete the pending request.
2394 ASSERT_EQ(1u, resolver.pending_requests().size()); 2409 ASSERT_EQ(1u, resolver.pending_requests().size());
2395 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); 2410 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80");
2396 resolver.pending_requests()[0]->CompleteNow(OK); 2411 resolver.pending_requests()[0]->CompleteNow(OK);
2397 2412
2398 // Verify that request ran as expected. 2413 // Verify that request ran as expected.
2399 EXPECT_EQ(OK, callback1.WaitForResult()); 2414 EXPECT_EQ(OK, callback1.WaitForResult());
2400 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); 2415 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
2401 2416
(...skipping 13 matching lines...) Expand all
2415 EXPECT_EQ(OK, rv); 2430 EXPECT_EQ(OK, rv);
2416 2431
2417 EXPECT_TRUE(info2.is_direct()); 2432 EXPECT_TRUE(info2.is_direct());
2418 } 2433 }
2419 2434
2420 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { 2435 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) {
2421 MockProxyConfigService* config_service = 2436 MockProxyConfigService* config_service =
2422 new MockProxyConfigService("http://foopy/proxy.pac"); 2437 new MockProxyConfigService("http://foopy/proxy.pac");
2423 2438
2424 MockAsyncProxyResolverExpectsBytes resolver; 2439 MockAsyncProxyResolverExpectsBytes resolver;
2440 MockAsyncProxyResolverFactory factory(true);
2425 2441
2426 TestNetLog log; 2442 TestNetLog log;
2427 2443
2428 ProxyService service( 2444 ProxyService service(
2429 config_service, 2445 config_service,
2430 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), &log); 2446 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), &log);
2431 2447
2432 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2448 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2433 service.SetProxyScriptFetchers(fetcher, 2449 service.SetProxyScriptFetchers(fetcher,
2434 new DoNothingDhcpProxyScriptFetcher()); 2450 new DoNothingDhcpProxyScriptFetcher());
2435 2451
2436 // Disable the "wait after IP address changes" hack, so this unit-test can 2452 // Disable the "wait after IP address changes" hack, so this unit-test can
2437 // complete quickly. 2453 // complete quickly.
2438 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); 2454 service.set_stall_proxy_auto_config_delay(base::TimeDelta());
2439 2455
2440 // Start 1 request. 2456 // Start 1 request.
2441 2457
2442 ProxyInfo info1; 2458 ProxyInfo info1;
2443 TestCompletionCallback callback1; 2459 TestCompletionCallback callback1;
2444 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL, 2460 int rv = service.ResolveProxy(GURL("http://request1"), net::LOAD_NORMAL,
2445 &info1, callback1.callback(), NULL, NULL, 2461 &info1, callback1.callback(), NULL, NULL,
2446 BoundNetLog()); 2462 BoundNetLog());
2447 EXPECT_EQ(ERR_IO_PENDING, rv); 2463 EXPECT_EQ(ERR_IO_PENDING, rv);
2448 2464
2449 // The first request should have triggered initial download of PAC script. 2465 // The first request should have triggered initial download of PAC script.
2450 EXPECT_TRUE(fetcher->has_pending_request()); 2466 EXPECT_TRUE(fetcher->has_pending_request());
2451 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2467 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2452 2468
2453 // Nothing has been sent to the resolver yet. 2469 // Nothing has been sent to the factory yet.
2454 EXPECT_TRUE(resolver.pending_requests().empty()); 2470 EXPECT_TRUE(factory.pending_requests().empty());
2455 2471
2456 // At this point the ProxyService should be waiting for the 2472 // At this point the ProxyService should be waiting for the
2457 // ProxyScriptFetcher to invoke its completion callback, notifying it of 2473 // ProxyScriptFetcher to invoke its completion callback, notifying it of
2458 // PAC script download completion. 2474 // PAC script download completion.
2459 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2475 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2460 2476
2461 // Now that the PAC script is downloaded, the request will have been sent to 2477 // Now that the PAC script is downloaded, the request will have been sent to
2462 // the proxy resolver. 2478 // the proxy resolver.
2463 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2479 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2464 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2480 factory.pending_requests()[0]->script_data()->utf16());
2465 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2481 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2466 2482
2467 ASSERT_EQ(1u, resolver.pending_requests().size()); 2483 ASSERT_EQ(1u, resolver.pending_requests().size());
2468 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 2484 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
2469 2485
2470 // Complete the pending request. 2486 // Complete the pending request.
2471 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); 2487 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80");
2472 resolver.pending_requests()[0]->CompleteNow(OK); 2488 resolver.pending_requests()[0]->CompleteNow(OK);
2473 2489
2474 // Wait for completion callback, and verify that the request ran as expected. 2490 // Wait for completion callback, and verify that the request ran as expected.
2475 EXPECT_EQ(OK, callback1.WaitForResult()); 2491 EXPECT_EQ(OK, callback1.WaitForResult());
(...skipping 10 matching lines...) Expand all
2486 TestCompletionCallback callback2; 2502 TestCompletionCallback callback2;
2487 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2, 2503 rv = service.ResolveProxy(GURL("http://request2"), net::LOAD_NORMAL, &info2,
2488 callback2.callback(), NULL, NULL, BoundNetLog()); 2504 callback2.callback(), NULL, NULL, BoundNetLog());
2489 EXPECT_EQ(ERR_IO_PENDING, rv); 2505 EXPECT_EQ(ERR_IO_PENDING, rv);
2490 2506
2491 // This second request should have triggered the re-download of the PAC 2507 // This second request should have triggered the re-download of the PAC
2492 // script (since we marked the network as having changed). 2508 // script (since we marked the network as having changed).
2493 EXPECT_TRUE(fetcher->has_pending_request()); 2509 EXPECT_TRUE(fetcher->has_pending_request());
2494 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2510 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2495 2511
2496 // Nothing has been sent to the resolver yet. 2512 // Nothing has been sent to the factory yet.
2497 EXPECT_TRUE(resolver.pending_requests().empty()); 2513 EXPECT_TRUE(factory.pending_requests().empty());
2498 2514
2499 // Simulate the PAC script fetch as having completed (this time with 2515 // Simulate the PAC script fetch as having completed (this time with
2500 // different data). 2516 // different data).
2501 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); 2517 fetcher->NotifyFetchCompletion(OK, kValidPacScript2);
2502 2518
2503 // Now that the PAC script is downloaded, the second request will have been 2519 // Now that the PAC script is downloaded, the second request will have been
2504 // sent to the proxy resolver. 2520 // sent to the proxy resolver.
2505 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), 2521 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2),
2506 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2522 factory.pending_requests()[0]->script_data()->utf16());
2507 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2523 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2508 2524
2509 ASSERT_EQ(1u, resolver.pending_requests().size()); 2525 ASSERT_EQ(1u, resolver.pending_requests().size());
2510 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); 2526 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url());
2511 2527
2512 // Complete the pending second request. 2528 // Complete the pending second request.
2513 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); 2529 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80");
2514 resolver.pending_requests()[0]->CompleteNow(OK); 2530 resolver.pending_requests()[0]->CompleteNow(OK);
2515 2531
2516 // Wait for completion callback, and verify that the request ran as expected. 2532 // Wait for completion callback, and verify that the request ran as expected.
2517 EXPECT_EQ(OK, callback2.WaitForResult()); 2533 EXPECT_EQ(OK, callback2.WaitForResult());
(...skipping 19 matching lines...) Expand all
2537 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { 2553 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) {
2538 // Change the retry policy to wait a mere 1 ms before retrying, so the test 2554 // Change the retry policy to wait a mere 1 ms before retrying, so the test
2539 // runs quickly. 2555 // runs quickly.
2540 ImmediatePollPolicy poll_policy; 2556 ImmediatePollPolicy poll_policy;
2541 ProxyService::set_pac_script_poll_policy(&poll_policy); 2557 ProxyService::set_pac_script_poll_policy(&poll_policy);
2542 2558
2543 MockProxyConfigService* config_service = 2559 MockProxyConfigService* config_service =
2544 new MockProxyConfigService("http://foopy/proxy.pac"); 2560 new MockProxyConfigService("http://foopy/proxy.pac");
2545 2561
2546 MockAsyncProxyResolverExpectsBytes resolver; 2562 MockAsyncProxyResolverExpectsBytes resolver;
2563 MockAsyncProxyResolverFactory factory(true);
2547 2564
2548 ProxyService service( 2565 ProxyService service(
2549 config_service, 2566 config_service,
2550 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2567 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2551 2568
2552 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2569 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2553 service.SetProxyScriptFetchers(fetcher, 2570 service.SetProxyScriptFetchers(fetcher,
2554 new DoNothingDhcpProxyScriptFetcher()); 2571 new DoNothingDhcpProxyScriptFetcher());
2555 2572
2556 // Start 1 request. 2573 // Start 1 request.
2557 2574
2558 ProxyInfo info1; 2575 ProxyInfo info1;
2559 TestCompletionCallback callback1; 2576 TestCompletionCallback callback1;
2560 int rv = service.ResolveProxy( 2577 int rv = service.ResolveProxy(
2561 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), 2578 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(),
2562 NULL, NULL, BoundNetLog()); 2579 NULL, NULL, BoundNetLog());
2563 EXPECT_EQ(ERR_IO_PENDING, rv); 2580 EXPECT_EQ(ERR_IO_PENDING, rv);
2564 2581
2565 // The first request should have triggered initial download of PAC script. 2582 // The first request should have triggered initial download of PAC script.
2566 EXPECT_TRUE(fetcher->has_pending_request()); 2583 EXPECT_TRUE(fetcher->has_pending_request());
2567 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2584 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2568 2585
2569 // Nothing has been sent to the resolver yet. 2586 // Nothing has been sent to the factory yet.
2570 EXPECT_TRUE(resolver.pending_requests().empty()); 2587 EXPECT_TRUE(factory.pending_requests().empty());
2571 2588
2572 // At this point the ProxyService should be waiting for the 2589 // At this point the ProxyService should be waiting for the
2573 // ProxyScriptFetcher to invoke its completion callback, notifying it of 2590 // ProxyScriptFetcher to invoke its completion callback, notifying it of
2574 // PAC script download completion. 2591 // PAC script download completion.
2575 // 2592 //
2576 // We simulate a failed download attempt, the proxy service should now 2593 // We simulate a failed download attempt, the proxy service should now
2577 // fall-back to DIRECT connections. 2594 // fall-back to DIRECT connections.
2578 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 2595 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
2579 2596
2580 ASSERT_TRUE(resolver.pending_requests().empty()); 2597 ASSERT_TRUE(factory.pending_requests().empty());
2581 2598
2582 // Wait for completion callback, and verify it used DIRECT. 2599 // Wait for completion callback, and verify it used DIRECT.
2583 EXPECT_EQ(OK, callback1.WaitForResult()); 2600 EXPECT_EQ(OK, callback1.WaitForResult());
2584 EXPECT_TRUE(info1.is_direct()); 2601 EXPECT_TRUE(info1.is_direct());
2585 2602
2586 // At this point we have initialized the proxy service using a PAC script, 2603 // At this point we have initialized the proxy service using a PAC script,
2587 // however it failed and fell-back to DIRECT. 2604 // however it failed and fell-back to DIRECT.
2588 // 2605 //
2589 // A background task to periodically re-check the PAC script for validity will 2606 // A background task to periodically re-check the PAC script for validity will
2590 // have been started. We will now wait for the next download attempt to start. 2607 // have been started. We will now wait for the next download attempt to start.
2591 // 2608 //
2592 // Note that we shouldn't have to wait long here, since our test enables a 2609 // Note that we shouldn't have to wait long here, since our test enables a
2593 // special unit-test mode. 2610 // special unit-test mode.
2594 fetcher->WaitUntilFetch(); 2611 fetcher->WaitUntilFetch();
2595 2612
2596 ASSERT_TRUE(resolver.pending_requests().empty()); 2613 ASSERT_TRUE(factory.pending_requests().empty());
2597 2614
2598 // Make sure that our background checker is trying to download the expected 2615 // Make sure that our background checker is trying to download the expected
2599 // PAC script (same one as before). This time we will simulate a successful 2616 // PAC script (same one as before). This time we will simulate a successful
2600 // download of the script. 2617 // download of the script.
2601 EXPECT_TRUE(fetcher->has_pending_request()); 2618 EXPECT_TRUE(fetcher->has_pending_request());
2602 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2619 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2603 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2620 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2604 2621
2605 base::MessageLoop::current()->RunUntilIdle(); 2622 base::MessageLoop::current()->RunUntilIdle();
2606 2623
2607 // Now that the PAC script is downloaded, it should be used to initialize the 2624 // Now that the PAC script is downloaded, it should be used to initialize the
2608 // ProxyResolver. Simulate a successful parse. 2625 // ProxyResolver. Simulate a successful parse.
2609 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2626 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2610 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2627 factory.pending_requests()[0]->script_data()->utf16());
2611 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2628 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2612 2629
2613 // At this point the ProxyService should have re-configured itself to use the 2630 // At this point the ProxyService should have re-configured itself to use the
2614 // PAC script (thereby recovering from the initial fetch failure). We will 2631 // PAC script (thereby recovering from the initial fetch failure). We will
2615 // verify that the next Resolve request uses the resolver rather than 2632 // verify that the next Resolve request uses the resolver rather than
2616 // DIRECT. 2633 // DIRECT.
2617 2634
2618 // Start a second request. 2635 // Start a second request.
2619 ProxyInfo info2; 2636 ProxyInfo info2;
2620 TestCompletionCallback callback2; 2637 TestCompletionCallback callback2;
2621 rv = service.ResolveProxy( 2638 rv = service.ResolveProxy(
(...skipping 21 matching lines...) Expand all
2643 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) { 2660 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) {
2644 // Change the retry policy to wait a mere 1 ms before retrying, so the test 2661 // Change the retry policy to wait a mere 1 ms before retrying, so the test
2645 // runs quickly. 2662 // runs quickly.
2646 ImmediatePollPolicy poll_policy; 2663 ImmediatePollPolicy poll_policy;
2647 ProxyService::set_pac_script_poll_policy(&poll_policy); 2664 ProxyService::set_pac_script_poll_policy(&poll_policy);
2648 2665
2649 MockProxyConfigService* config_service = 2666 MockProxyConfigService* config_service =
2650 new MockProxyConfigService("http://foopy/proxy.pac"); 2667 new MockProxyConfigService("http://foopy/proxy.pac");
2651 2668
2652 MockAsyncProxyResolverExpectsBytes resolver; 2669 MockAsyncProxyResolverExpectsBytes resolver;
2670 MockAsyncProxyResolverFactory factory(true);
2653 2671
2654 ProxyService service( 2672 ProxyService service(
2655 config_service, 2673 config_service,
2656 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2674 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2657 2675
2658 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2676 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2659 service.SetProxyScriptFetchers(fetcher, 2677 service.SetProxyScriptFetchers(fetcher,
2660 new DoNothingDhcpProxyScriptFetcher()); 2678 new DoNothingDhcpProxyScriptFetcher());
2661 2679
2662 // Start 1 request. 2680 // Start 1 request.
2663 2681
2664 ProxyInfo info1; 2682 ProxyInfo info1;
2665 TestCompletionCallback callback1; 2683 TestCompletionCallback callback1;
2666 int rv = service.ResolveProxy( 2684 int rv = service.ResolveProxy(
2667 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), 2685 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(),
2668 NULL, NULL, BoundNetLog()); 2686 NULL, NULL, BoundNetLog());
2669 EXPECT_EQ(ERR_IO_PENDING, rv); 2687 EXPECT_EQ(ERR_IO_PENDING, rv);
2670 2688
2671 // The first request should have triggered initial download of PAC script. 2689 // The first request should have triggered initial download of PAC script.
2672 EXPECT_TRUE(fetcher->has_pending_request()); 2690 EXPECT_TRUE(fetcher->has_pending_request());
2673 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2691 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2674 2692
2675 // Nothing has been sent to the resolver yet. 2693 // Nothing has been sent to the factory yet.
2676 EXPECT_TRUE(resolver.pending_requests().empty()); 2694 EXPECT_TRUE(factory.pending_requests().empty());
2677 2695
2678 // At this point the ProxyService should be waiting for the 2696 // At this point the ProxyService should be waiting for the
2679 // ProxyScriptFetcher to invoke its completion callback, notifying it of 2697 // ProxyScriptFetcher to invoke its completion callback, notifying it of
2680 // PAC script download completion. 2698 // PAC script download completion.
2681 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2699 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2682 2700
2683 // Now that the PAC script is downloaded, the request will have been sent to 2701 // Now that the PAC script is downloaded, the request will have been sent to
2684 // the proxy resolver. 2702 // the proxy resolver.
2685 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2703 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2686 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2704 factory.pending_requests()[0]->script_data()->utf16());
2687 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2705 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2688 2706
2689 ASSERT_EQ(1u, resolver.pending_requests().size()); 2707 ASSERT_EQ(1u, resolver.pending_requests().size());
2690 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 2708 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
2691 2709
2692 // Complete the pending request. 2710 // Complete the pending request.
2693 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); 2711 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80");
2694 resolver.pending_requests()[0]->CompleteNow(OK); 2712 resolver.pending_requests()[0]->CompleteNow(OK);
2695 2713
2696 // Wait for completion callback, and verify that the request ran as expected. 2714 // Wait for completion callback, and verify that the request ran as expected.
2697 EXPECT_EQ(OK, callback1.WaitForResult()); 2715 EXPECT_EQ(OK, callback1.WaitForResult());
2698 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); 2716 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
2699 2717
2700 // At this point we have initialized the proxy service using a PAC script. 2718 // At this point we have initialized the proxy service using a PAC script.
2701 // 2719 //
2702 // A background task to periodically re-check the PAC script for validity will 2720 // A background task to periodically re-check the PAC script for validity will
2703 // have been started. We will now wait for the next download attempt to start. 2721 // have been started. We will now wait for the next download attempt to start.
2704 // 2722 //
2705 // Note that we shouldn't have to wait long here, since our test enables a 2723 // Note that we shouldn't have to wait long here, since our test enables a
2706 // special unit-test mode. 2724 // special unit-test mode.
2707 fetcher->WaitUntilFetch(); 2725 fetcher->WaitUntilFetch();
2708 2726
2727 ASSERT_TRUE(factory.pending_requests().empty());
2709 ASSERT_TRUE(resolver.pending_requests().empty()); 2728 ASSERT_TRUE(resolver.pending_requests().empty());
2710 2729
2711 // Make sure that our background checker is trying to download the expected 2730 // Make sure that our background checker is trying to download the expected
2712 // PAC script (same one as before). This time we will simulate a successful 2731 // PAC script (same one as before). This time we will simulate a successful
2713 // download of a DIFFERENT script. 2732 // download of a DIFFERENT script.
2714 EXPECT_TRUE(fetcher->has_pending_request()); 2733 EXPECT_TRUE(fetcher->has_pending_request());
2715 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2734 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2716 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); 2735 fetcher->NotifyFetchCompletion(OK, kValidPacScript2);
2717 2736
2718 base::MessageLoop::current()->RunUntilIdle(); 2737 base::MessageLoop::current()->RunUntilIdle();
2719 2738
2720 // Now that the PAC script is downloaded, it should be used to initialize the 2739 // Now that the PAC script is downloaded, it should be used to initialize the
2721 // ProxyResolver. Simulate a successful parse. 2740 // ProxyResolver. Simulate a successful parse.
2722 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), 2741 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2),
2723 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2742 factory.pending_requests()[0]->script_data()->utf16());
2724 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2743 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2725 2744
2726 // At this point the ProxyService should have re-configured itself to use the 2745 // At this point the ProxyService should have re-configured itself to use the
2727 // new PAC script. 2746 // new PAC script.
2728 2747
2729 // Start a second request. 2748 // Start a second request.
2730 ProxyInfo info2; 2749 ProxyInfo info2;
2731 TestCompletionCallback callback2; 2750 TestCompletionCallback callback2;
2732 rv = service.ResolveProxy( 2751 rv = service.ResolveProxy(
2733 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(), 2752 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(),
2734 NULL, NULL, BoundNetLog()); 2753 NULL, NULL, BoundNetLog());
(...skipping 19 matching lines...) Expand all
2754 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) { 2773 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) {
2755 // Change the retry policy to wait a mere 1 ms before retrying, so the test 2774 // Change the retry policy to wait a mere 1 ms before retrying, so the test
2756 // runs quickly. 2775 // runs quickly.
2757 ImmediatePollPolicy poll_policy; 2776 ImmediatePollPolicy poll_policy;
2758 ProxyService::set_pac_script_poll_policy(&poll_policy); 2777 ProxyService::set_pac_script_poll_policy(&poll_policy);
2759 2778
2760 MockProxyConfigService* config_service = 2779 MockProxyConfigService* config_service =
2761 new MockProxyConfigService("http://foopy/proxy.pac"); 2780 new MockProxyConfigService("http://foopy/proxy.pac");
2762 2781
2763 MockAsyncProxyResolverExpectsBytes resolver; 2782 MockAsyncProxyResolverExpectsBytes resolver;
2783 MockAsyncProxyResolverFactory factory(true);
2764 2784
2765 ProxyService service( 2785 ProxyService service(
2766 config_service, 2786 config_service,
2767 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2787 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2768 2788
2769 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2789 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2770 service.SetProxyScriptFetchers(fetcher, 2790 service.SetProxyScriptFetchers(fetcher,
2771 new DoNothingDhcpProxyScriptFetcher()); 2791 new DoNothingDhcpProxyScriptFetcher());
2772 2792
2773 // Start 1 request. 2793 // Start 1 request.
2774 2794
2775 ProxyInfo info1; 2795 ProxyInfo info1;
2776 TestCompletionCallback callback1; 2796 TestCompletionCallback callback1;
2777 int rv = service.ResolveProxy( 2797 int rv = service.ResolveProxy(
2778 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), 2798 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(),
2779 NULL, NULL, BoundNetLog()); 2799 NULL, NULL, BoundNetLog());
2780 EXPECT_EQ(ERR_IO_PENDING, rv); 2800 EXPECT_EQ(ERR_IO_PENDING, rv);
2781 2801
2782 // The first request should have triggered initial download of PAC script. 2802 // The first request should have triggered initial download of PAC script.
2783 EXPECT_TRUE(fetcher->has_pending_request()); 2803 EXPECT_TRUE(fetcher->has_pending_request());
2784 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2804 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2785 2805
2786 // Nothing has been sent to the resolver yet. 2806 // Nothing has been sent to the factory yet.
2787 EXPECT_TRUE(resolver.pending_requests().empty()); 2807 EXPECT_TRUE(factory.pending_requests().empty());
2788 2808
2789 // At this point the ProxyService should be waiting for the 2809 // At this point the ProxyService should be waiting for the
2790 // ProxyScriptFetcher to invoke its completion callback, notifying it of 2810 // ProxyScriptFetcher to invoke its completion callback, notifying it of
2791 // PAC script download completion. 2811 // PAC script download completion.
2792 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2812 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2793 2813
2794 // Now that the PAC script is downloaded, the request will have been sent to 2814 // Now that the PAC script is downloaded, the request will have been sent to
2795 // the proxy resolver. 2815 // the proxy resolver.
2796 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2816 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2797 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2817 factory.pending_requests()[0]->script_data()->utf16());
2798 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2818 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2799 2819
2800 ASSERT_EQ(1u, resolver.pending_requests().size()); 2820 ASSERT_EQ(1u, resolver.pending_requests().size());
2801 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 2821 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
2802 2822
2803 // Complete the pending request. 2823 // Complete the pending request.
2804 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); 2824 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80");
2805 resolver.pending_requests()[0]->CompleteNow(OK); 2825 resolver.pending_requests()[0]->CompleteNow(OK);
2806 2826
2807 // Wait for completion callback, and verify that the request ran as expected. 2827 // Wait for completion callback, and verify that the request ran as expected.
2808 EXPECT_EQ(OK, callback1.WaitForResult()); 2828 EXPECT_EQ(OK, callback1.WaitForResult());
2809 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); 2829 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
2810 2830
2811 // At this point we have initialized the proxy service using a PAC script. 2831 // At this point we have initialized the proxy service using a PAC script.
2812 // 2832 //
2813 // A background task to periodically re-check the PAC script for validity will 2833 // A background task to periodically re-check the PAC script for validity will
2814 // have been started. We will now wait for the next download attempt to start. 2834 // have been started. We will now wait for the next download attempt to start.
2815 // 2835 //
2816 // Note that we shouldn't have to wait long here, since our test enables a 2836 // Note that we shouldn't have to wait long here, since our test enables a
2817 // special unit-test mode. 2837 // special unit-test mode.
2818 fetcher->WaitUntilFetch(); 2838 fetcher->WaitUntilFetch();
2819 2839
2840 ASSERT_TRUE(factory.pending_requests().empty());
2820 ASSERT_TRUE(resolver.pending_requests().empty()); 2841 ASSERT_TRUE(resolver.pending_requests().empty());
2821 2842
2822 // Make sure that our background checker is trying to download the expected 2843 // Make sure that our background checker is trying to download the expected
2823 // PAC script (same one as before). We will simulate the same response as 2844 // PAC script (same one as before). We will simulate the same response as
2824 // last time (i.e. the script is unchanged). 2845 // last time (i.e. the script is unchanged).
2825 EXPECT_TRUE(fetcher->has_pending_request()); 2846 EXPECT_TRUE(fetcher->has_pending_request());
2826 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2847 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2827 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2848 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2828 2849
2829 base::MessageLoop::current()->RunUntilIdle(); 2850 base::MessageLoop::current()->RunUntilIdle();
2830 2851
2831 ASSERT_FALSE(resolver.has_pending_set_pac_script_request()); 2852 ASSERT_TRUE(factory.pending_requests().empty());
2853 ASSERT_TRUE(resolver.pending_requests().empty());
2832 2854
2833 // At this point the ProxyService is still running the same PAC script as 2855 // At this point the ProxyService is still running the same PAC script as
2834 // before. 2856 // before.
2835 2857
2836 // Start a second request. 2858 // Start a second request.
2837 ProxyInfo info2; 2859 ProxyInfo info2;
2838 TestCompletionCallback callback2; 2860 TestCompletionCallback callback2;
2839 rv = service.ResolveProxy( 2861 rv = service.ResolveProxy(
2840 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(), 2862 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(),
2841 NULL, NULL, BoundNetLog()); 2863 NULL, NULL, BoundNetLog());
(...skipping 19 matching lines...) Expand all
2861 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) { 2883 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) {
2862 // Change the retry policy to wait a mere 1 ms before retrying, so the test 2884 // Change the retry policy to wait a mere 1 ms before retrying, so the test
2863 // runs quickly. 2885 // runs quickly.
2864 ImmediatePollPolicy poll_policy; 2886 ImmediatePollPolicy poll_policy;
2865 ProxyService::set_pac_script_poll_policy(&poll_policy); 2887 ProxyService::set_pac_script_poll_policy(&poll_policy);
2866 2888
2867 MockProxyConfigService* config_service = 2889 MockProxyConfigService* config_service =
2868 new MockProxyConfigService("http://foopy/proxy.pac"); 2890 new MockProxyConfigService("http://foopy/proxy.pac");
2869 2891
2870 MockAsyncProxyResolverExpectsBytes resolver; 2892 MockAsyncProxyResolverExpectsBytes resolver;
2893 MockAsyncProxyResolverFactory factory(true);
2871 2894
2872 ProxyService service( 2895 ProxyService service(
2873 config_service, 2896 config_service,
2874 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 2897 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
2875 2898
2876 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 2899 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
2877 service.SetProxyScriptFetchers(fetcher, 2900 service.SetProxyScriptFetchers(fetcher,
2878 new DoNothingDhcpProxyScriptFetcher()); 2901 new DoNothingDhcpProxyScriptFetcher());
2879 2902
2880 // Start 1 request. 2903 // Start 1 request.
2881 2904
2882 ProxyInfo info1; 2905 ProxyInfo info1;
2883 TestCompletionCallback callback1; 2906 TestCompletionCallback callback1;
2884 int rv = service.ResolveProxy( 2907 int rv = service.ResolveProxy(
2885 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), 2908 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(),
2886 NULL, NULL, BoundNetLog()); 2909 NULL, NULL, BoundNetLog());
2887 EXPECT_EQ(ERR_IO_PENDING, rv); 2910 EXPECT_EQ(ERR_IO_PENDING, rv);
2888 2911
2889 // The first request should have triggered initial download of PAC script. 2912 // The first request should have triggered initial download of PAC script.
2890 EXPECT_TRUE(fetcher->has_pending_request()); 2913 EXPECT_TRUE(fetcher->has_pending_request());
2891 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2914 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2892 2915
2893 // Nothing has been sent to the resolver yet. 2916 // Nothing has been sent to the factory yet.
2894 EXPECT_TRUE(resolver.pending_requests().empty()); 2917 EXPECT_TRUE(factory.pending_requests().empty());
2895 2918
2896 // At this point the ProxyService should be waiting for the 2919 // At this point the ProxyService should be waiting for the
2897 // ProxyScriptFetcher to invoke its completion callback, notifying it of 2920 // ProxyScriptFetcher to invoke its completion callback, notifying it of
2898 // PAC script download completion. 2921 // PAC script download completion.
2899 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 2922 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
2900 2923
2901 // Now that the PAC script is downloaded, the request will have been sent to 2924 // Now that the PAC script is downloaded, the request will have been sent to
2902 // the proxy resolver. 2925 // the proxy resolver.
2903 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 2926 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
2904 resolver.pending_set_pac_script_request()->script_data()->utf16()); 2927 factory.pending_requests()[0]->script_data()->utf16());
2905 resolver.pending_set_pac_script_request()->CompleteNow(OK); 2928 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
2906 2929
2907 ASSERT_EQ(1u, resolver.pending_requests().size()); 2930 ASSERT_EQ(1u, resolver.pending_requests().size());
2908 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 2931 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
2909 2932
2910 // Complete the pending request. 2933 // Complete the pending request.
2911 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); 2934 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80");
2912 resolver.pending_requests()[0]->CompleteNow(OK); 2935 resolver.pending_requests()[0]->CompleteNow(OK);
2913 2936
2914 // Wait for completion callback, and verify that the request ran as expected. 2937 // Wait for completion callback, and verify that the request ran as expected.
2915 EXPECT_EQ(OK, callback1.WaitForResult()); 2938 EXPECT_EQ(OK, callback1.WaitForResult());
2916 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); 2939 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
2917 2940
2918 // At this point we have initialized the proxy service using a PAC script. 2941 // At this point we have initialized the proxy service using a PAC script.
2919 // 2942 //
2920 // A background task to periodically re-check the PAC script for validity will 2943 // A background task to periodically re-check the PAC script for validity will
2921 // have been started. We will now wait for the next download attempt to start. 2944 // have been started. We will now wait for the next download attempt to start.
2922 // 2945 //
2923 // Note that we shouldn't have to wait long here, since our test enables a 2946 // Note that we shouldn't have to wait long here, since our test enables a
2924 // special unit-test mode. 2947 // special unit-test mode.
2925 fetcher->WaitUntilFetch(); 2948 fetcher->WaitUntilFetch();
2926 2949
2950 ASSERT_TRUE(factory.pending_requests().empty());
2927 ASSERT_TRUE(resolver.pending_requests().empty()); 2951 ASSERT_TRUE(resolver.pending_requests().empty());
2928 2952
2929 // Make sure that our background checker is trying to download the expected 2953 // Make sure that our background checker is trying to download the expected
2930 // PAC script (same one as before). This time we will simulate a failure 2954 // PAC script (same one as before). This time we will simulate a failure
2931 // to download the script. 2955 // to download the script.
2932 EXPECT_TRUE(fetcher->has_pending_request()); 2956 EXPECT_TRUE(fetcher->has_pending_request());
2933 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 2957 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
2934 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); 2958 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string());
2935 2959
2936 base::MessageLoop::current()->RunUntilIdle(); 2960 base::MessageLoop::current()->RunUntilIdle();
(...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after
3014 // This tests the polling of the PAC script. Specifically, it tests that 3038 // This tests the polling of the PAC script. Specifically, it tests that
3015 // polling occurs in response to user activity. 3039 // polling occurs in response to user activity.
3016 TEST_F(ProxyServiceTest, PACScriptRefetchAfterActivity) { 3040 TEST_F(ProxyServiceTest, PACScriptRefetchAfterActivity) {
3017 ImmediateAfterActivityPollPolicy poll_policy; 3041 ImmediateAfterActivityPollPolicy poll_policy;
3018 ProxyService::set_pac_script_poll_policy(&poll_policy); 3042 ProxyService::set_pac_script_poll_policy(&poll_policy);
3019 3043
3020 MockProxyConfigService* config_service = 3044 MockProxyConfigService* config_service =
3021 new MockProxyConfigService("http://foopy/proxy.pac"); 3045 new MockProxyConfigService("http://foopy/proxy.pac");
3022 3046
3023 MockAsyncProxyResolverExpectsBytes resolver; 3047 MockAsyncProxyResolverExpectsBytes resolver;
3048 MockAsyncProxyResolverFactory factory(true);
3024 3049
3025 ProxyService service( 3050 ProxyService service(
3026 config_service, 3051 config_service,
3027 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 3052 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
3028 3053
3029 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; 3054 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher;
3030 service.SetProxyScriptFetchers(fetcher, 3055 service.SetProxyScriptFetchers(fetcher,
3031 new DoNothingDhcpProxyScriptFetcher()); 3056 new DoNothingDhcpProxyScriptFetcher());
3032 3057
3033 // Start 1 request. 3058 // Start 1 request.
3034 3059
3035 ProxyInfo info1; 3060 ProxyInfo info1;
3036 TestCompletionCallback callback1; 3061 TestCompletionCallback callback1;
3037 int rv = service.ResolveProxy( 3062 int rv = service.ResolveProxy(
3038 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(), 3063 GURL("http://request1"), net::LOAD_NORMAL, &info1, callback1.callback(),
3039 NULL, NULL, BoundNetLog()); 3064 NULL, NULL, BoundNetLog());
3040 EXPECT_EQ(ERR_IO_PENDING, rv); 3065 EXPECT_EQ(ERR_IO_PENDING, rv);
3041 3066
3042 // The first request should have triggered initial download of PAC script. 3067 // The first request should have triggered initial download of PAC script.
3043 EXPECT_TRUE(fetcher->has_pending_request()); 3068 EXPECT_TRUE(fetcher->has_pending_request());
3044 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); 3069 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url());
3045 3070
3046 // Nothing has been sent to the resolver yet. 3071 // Nothing has been sent to the factory yet.
3047 EXPECT_TRUE(resolver.pending_requests().empty()); 3072 EXPECT_TRUE(factory.pending_requests().empty());
3048 3073
3049 // At this point the ProxyService should be waiting for the 3074 // At this point the ProxyService should be waiting for the
3050 // ProxyScriptFetcher to invoke its completion callback, notifying it of 3075 // ProxyScriptFetcher to invoke its completion callback, notifying it of
3051 // PAC script download completion. 3076 // PAC script download completion.
3052 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); 3077 fetcher->NotifyFetchCompletion(OK, kValidPacScript1);
3053 3078
3054 // Now that the PAC script is downloaded, the request will have been sent to 3079 // Now that the PAC script is downloaded, the request will have been sent to
3055 // the proxy resolver. 3080 // the proxy resolver.
3056 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), 3081 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1),
3057 resolver.pending_set_pac_script_request()->script_data()->utf16()); 3082 factory.pending_requests()[0]->script_data()->utf16());
3058 resolver.pending_set_pac_script_request()->CompleteNow(OK); 3083 factory.pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
3059 3084
3060 ASSERT_EQ(1u, resolver.pending_requests().size()); 3085 ASSERT_EQ(1u, resolver.pending_requests().size());
3061 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); 3086 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url());
3062 3087
3063 // Complete the pending request. 3088 // Complete the pending request.
3064 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); 3089 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80");
3065 resolver.pending_requests()[0]->CompleteNow(OK); 3090 resolver.pending_requests()[0]->CompleteNow(OK);
3066 3091
3067 // Wait for completion callback, and verify that the request ran as expected. 3092 // Wait for completion callback, and verify that the request ran as expected.
3068 EXPECT_EQ(OK, callback1.WaitForResult()); 3093 EXPECT_EQ(OK, callback1.WaitForResult());
3069 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); 3094 EXPECT_EQ("request1:80", info1.proxy_server().ToURI());
3070 3095
3071 // At this point we have initialized the proxy service using a PAC script. 3096 // At this point we have initialized the proxy service using a PAC script.
3072 // Our PAC poller is set to update ONLY in response to network activity, 3097 // Our PAC poller is set to update ONLY in response to network activity,
3073 // (i.e. another call to ResolveProxy()). 3098 // (i.e. another call to ResolveProxy()).
3074 3099
3075 ASSERT_FALSE(fetcher->has_pending_request()); 3100 ASSERT_FALSE(fetcher->has_pending_request());
3101 ASSERT_TRUE(factory.pending_requests().empty());
3076 ASSERT_TRUE(resolver.pending_requests().empty()); 3102 ASSERT_TRUE(resolver.pending_requests().empty());
3077 3103
3078 // Start a second request. 3104 // Start a second request.
3079 ProxyInfo info2; 3105 ProxyInfo info2;
3080 TestCompletionCallback callback2; 3106 TestCompletionCallback callback2;
3081 rv = service.ResolveProxy( 3107 rv = service.ResolveProxy(
3082 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(), 3108 GURL("http://request2"), net::LOAD_NORMAL, &info2, callback2.callback(),
3083 NULL, NULL, BoundNetLog()); 3109 NULL, NULL, BoundNetLog());
3084 EXPECT_EQ(ERR_IO_PENDING, rv); 3110 EXPECT_EQ(ERR_IO_PENDING, rv);
3085 3111
(...skipping 28 matching lines...) Expand all
3114 NULL, NULL, BoundNetLog()); 3140 NULL, NULL, BoundNetLog());
3115 EXPECT_EQ(OK, rv); 3141 EXPECT_EQ(OK, rv);
3116 EXPECT_TRUE(info3.is_direct()); 3142 EXPECT_TRUE(info3.is_direct());
3117 } 3143 }
3118 3144
3119 // Test that the synchronous resolution fails when a PAC script is active. 3145 // Test that the synchronous resolution fails when a PAC script is active.
3120 TEST_F(ProxyServiceTest, SynchronousWithPAC) { 3146 TEST_F(ProxyServiceTest, SynchronousWithPAC) {
3121 MockProxyConfigService* config_service = 3147 MockProxyConfigService* config_service =
3122 new MockProxyConfigService("http://foopy/proxy.pac"); 3148 new MockProxyConfigService("http://foopy/proxy.pac");
3123 3149
3124 MockAsyncProxyResolver resolver; 3150 MockAsyncProxyResolverFactory factory(false);
3125 3151
3126 ProxyService service( 3152 ProxyService service(
3127 config_service, 3153 config_service,
3128 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 3154 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
3129 3155
3130 GURL url("http://www.google.com/"); 3156 GURL url("http://www.google.com/");
3131 3157
3132 ProxyInfo info; 3158 ProxyInfo info;
3133 info.UseDirect(); 3159 info.UseDirect();
3134 BoundTestNetLog log; 3160 BoundTestNetLog log;
3135 3161
3136 bool synchronous_success = service.TryResolveProxySynchronously( 3162 bool synchronous_success = service.TryResolveProxySynchronously(
3137 url, net::LOAD_NORMAL, &info, NULL, log.bound()); 3163 url, net::LOAD_NORMAL, &info, NULL, log.bound());
3138 EXPECT_FALSE(synchronous_success); 3164 EXPECT_FALSE(synchronous_success);
3139 3165
3140 // No request should have been queued.
3141 EXPECT_EQ(0u, resolver.pending_requests().size());
3142
3143 // |info| should not have been modified. 3166 // |info| should not have been modified.
3144 EXPECT_TRUE(info.is_direct()); 3167 EXPECT_TRUE(info.is_direct());
3145 } 3168 }
3146 3169
3147 // Test that synchronous results are returned correctly if a fixed proxy 3170 // Test that synchronous results are returned correctly if a fixed proxy
3148 // configuration is active. 3171 // configuration is active.
3149 TEST_F(ProxyServiceTest, SynchronousWithFixedConfiguration) { 3172 TEST_F(ProxyServiceTest, SynchronousWithFixedConfiguration) {
3150 ProxyConfig config; 3173 ProxyConfig config;
3151 config.proxy_rules().ParseFromString("foopy1:8080"); 3174 config.proxy_rules().ParseFromString("foopy1:8080");
3152 config.set_auto_detect(false); 3175 config.set_auto_detect(false);
3153 3176
3154 MockAsyncProxyResolver resolver; 3177 MockAsyncProxyResolverFactory factory(false);
3155 3178
3156 ProxyService service( 3179 ProxyService service(
3157 new MockProxyConfigService(config), 3180 new MockProxyConfigService(config),
3158 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); 3181 make_scoped_ptr(new ForwardingProxyResolverFactory(&factory)), NULL);
3159 3182
3160 GURL url("http://www.google.com/"); 3183 GURL url("http://www.google.com/");
3161 3184
3162 ProxyInfo info; 3185 ProxyInfo info;
3163 BoundTestNetLog log; 3186 BoundTestNetLog log;
3164 3187
3165 bool synchronous_success = service.TryResolveProxySynchronously( 3188 bool synchronous_success = service.TryResolveProxySynchronously(
3166 url, net::LOAD_NORMAL, &info, NULL, log.bound()); 3189 url, net::LOAD_NORMAL, &info, NULL, log.bound());
3167 EXPECT_TRUE(synchronous_success); 3190 EXPECT_TRUE(synchronous_success);
3168 EXPECT_FALSE(info.is_direct()); 3191 EXPECT_FALSE(info.is_direct());
3169 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); 3192 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host());
3170 3193
3171 // No request should have been queued. 3194 // No request should have been queued.
3172 EXPECT_EQ(0u, resolver.pending_requests().size()); 3195 EXPECT_EQ(0u, factory.pending_requests().size());
3173 } 3196 }
3174 3197
3175 } // namespace net 3198 } // namespace net
OLDNEW
« net/proxy/mock_proxy_resolver.cc ('K') | « net/proxy/multi_threaded_proxy_resolver_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698