OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/proxy/proxy_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 11 matching lines...) Expand all Loading... |
22 #include "net/log/net_log.h" | 22 #include "net/log/net_log.h" |
23 #include "net/log/test_net_log.h" | 23 #include "net/log/test_net_log.h" |
24 #include "net/log/test_net_log_entry.h" | 24 #include "net/log/test_net_log_entry.h" |
25 #include "net/log/test_net_log_util.h" | 25 #include "net/log/test_net_log_util.h" |
26 #include "net/proxy/dhcp_proxy_script_fetcher.h" | 26 #include "net/proxy/dhcp_proxy_script_fetcher.h" |
27 #include "net/proxy/mock_proxy_resolver.h" | 27 #include "net/proxy/mock_proxy_resolver.h" |
28 #include "net/proxy/mock_proxy_script_fetcher.h" | 28 #include "net/proxy/mock_proxy_script_fetcher.h" |
29 #include "net/proxy/proxy_config_service.h" | 29 #include "net/proxy/proxy_config_service.h" |
30 #include "net/proxy/proxy_resolver.h" | 30 #include "net/proxy/proxy_resolver.h" |
31 #include "net/proxy/proxy_script_fetcher.h" | 31 #include "net/proxy/proxy_script_fetcher.h" |
| 32 #include "net/test/gtest_util.h" |
| 33 #include "testing/gmock/include/gmock/gmock.h" |
32 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
33 #include "url/gurl.h" | 35 #include "url/gurl.h" |
34 | 36 |
| 37 using net::test::IsError; |
| 38 using net::test::IsOk; |
| 39 |
35 using base::ASCIIToUTF16; | 40 using base::ASCIIToUTF16; |
36 | 41 |
37 // TODO(eroman): Write a test which exercises | 42 // TODO(eroman): Write a test which exercises |
38 // ProxyService::SuspendAllPendingRequests(). | 43 // ProxyService::SuspendAllPendingRequests(). |
39 namespace net { | 44 namespace net { |
40 namespace { | 45 namespace { |
41 | 46 |
42 // This polling policy will decide to poll every 1 ms. | 47 // This polling policy will decide to poll every 1 ms. |
43 class ImmediatePollPolicy : public ProxyService::PacPollPolicy { | 48 class ImmediatePollPolicy : public ProxyService::PacPollPolicy { |
44 public: | 49 public: |
(...skipping 308 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 base::WrapUnique(factory), nullptr); | 358 base::WrapUnique(factory), nullptr); |
354 | 359 |
355 GURL url("http://www.google.com/"); | 360 GURL url("http://www.google.com/"); |
356 | 361 |
357 ProxyInfo info; | 362 ProxyInfo info; |
358 TestCompletionCallback callback; | 363 TestCompletionCallback callback; |
359 BoundTestNetLog log; | 364 BoundTestNetLog log; |
360 int rv = | 365 int rv = |
361 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 366 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
362 callback.callback(), nullptr, nullptr, log.bound()); | 367 callback.callback(), nullptr, nullptr, log.bound()); |
363 EXPECT_EQ(OK, rv); | 368 EXPECT_THAT(rv, IsOk()); |
364 EXPECT_TRUE(factory->pending_requests().empty()); | 369 EXPECT_TRUE(factory->pending_requests().empty()); |
365 | 370 |
366 EXPECT_TRUE(info.is_direct()); | 371 EXPECT_TRUE(info.is_direct()); |
367 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 372 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
368 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 373 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
369 | 374 |
370 // Check the NetLog was filled correctly. | 375 // Check the NetLog was filled correctly. |
371 TestNetLogEntry::List entries; | 376 TestNetLogEntry::List entries; |
372 log.GetEntries(&entries); | 377 log.GetEntries(&entries); |
373 | 378 |
(...skipping 20 matching lines...) Expand all Loading... |
394 GURL bypass_url("http://internet.org"); | 399 GURL bypass_url("http://internet.org"); |
395 | 400 |
396 ProxyInfo info; | 401 ProxyInfo info; |
397 TestCompletionCallback callback; | 402 TestCompletionCallback callback; |
398 BoundTestNetLog log; | 403 BoundTestNetLog log; |
399 | 404 |
400 // First, warm up the ProxyService. | 405 // First, warm up the ProxyService. |
401 int rv = | 406 int rv = |
402 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 407 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
403 callback.callback(), nullptr, nullptr, log.bound()); | 408 callback.callback(), nullptr, nullptr, log.bound()); |
404 EXPECT_EQ(OK, rv); | 409 EXPECT_THAT(rv, IsOk()); |
405 | 410 |
406 // Verify that network delegate is invoked. | 411 // Verify that network delegate is invoked. |
407 TestResolveProxyDelegate delegate; | 412 TestResolveProxyDelegate delegate; |
408 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), | 413 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), |
409 nullptr, &delegate, log.bound()); | 414 nullptr, &delegate, log.bound()); |
410 EXPECT_TRUE(delegate.on_resolve_proxy_called()); | 415 EXPECT_TRUE(delegate.on_resolve_proxy_called()); |
411 EXPECT_EQ(&service, delegate.proxy_service()); | 416 EXPECT_EQ(&service, delegate.proxy_service()); |
412 EXPECT_EQ(delegate.method(), "GET"); | 417 EXPECT_EQ(delegate.method(), "GET"); |
413 | 418 |
414 // Verify that the ProxyDelegate's behavior is stateless across | 419 // Verify that the ProxyDelegate's behavior is stateless across |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
452 GURL bypass_url("http://internet.org"); | 457 GURL bypass_url("http://internet.org"); |
453 | 458 |
454 ProxyInfo info; | 459 ProxyInfo info; |
455 TestCompletionCallback callback; | 460 TestCompletionCallback callback; |
456 BoundTestNetLog log; | 461 BoundTestNetLog log; |
457 | 462 |
458 // First, warm up the ProxyService. | 463 // First, warm up the ProxyService. |
459 int rv = | 464 int rv = |
460 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 465 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
461 callback.callback(), nullptr, nullptr, log.bound()); | 466 callback.callback(), nullptr, nullptr, log.bound()); |
462 EXPECT_EQ(OK, rv); | 467 EXPECT_THAT(rv, IsOk()); |
463 | 468 |
464 TestResolveProxyDelegate delegate; | 469 TestResolveProxyDelegate delegate; |
465 delegate.set_remove_proxy(true); | 470 delegate.set_remove_proxy(true); |
466 | 471 |
467 // Callback should interpose: | 472 // Callback should interpose: |
468 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), | 473 rv = service.ResolveProxy(url, "GET", LOAD_NORMAL, &info, callback.callback(), |
469 nullptr, &delegate, log.bound()); | 474 nullptr, &delegate, log.bound()); |
470 EXPECT_TRUE(info.is_direct()); | 475 EXPECT_TRUE(info.is_direct()); |
471 delegate.set_remove_proxy(false); | 476 delegate.set_remove_proxy(false); |
472 | 477 |
(...skipping 24 matching lines...) Expand all Loading... |
497 GURL url("http://www.google.com/"); | 502 GURL url("http://www.google.com/"); |
498 | 503 |
499 ProxyInfo info; | 504 ProxyInfo info; |
500 TestCompletionCallback callback; | 505 TestCompletionCallback callback; |
501 ProxyService::PacRequest* request; | 506 ProxyService::PacRequest* request; |
502 BoundTestNetLog log; | 507 BoundTestNetLog log; |
503 | 508 |
504 int rv = | 509 int rv = |
505 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 510 service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
506 callback.callback(), &request, nullptr, log.bound()); | 511 callback.callback(), &request, nullptr, log.bound()); |
507 EXPECT_EQ(ERR_IO_PENDING, rv); | 512 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
508 | 513 |
509 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 514 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
510 | 515 |
511 ASSERT_EQ(1u, factory->pending_requests().size()); | 516 ASSERT_EQ(1u, factory->pending_requests().size()); |
512 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 517 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
513 factory->pending_requests()[0]->script_data()->url()); | 518 factory->pending_requests()[0]->script_data()->url()); |
514 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 519 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
515 | 520 |
516 ASSERT_EQ(1u, resolver.pending_requests().size()); | 521 ASSERT_EQ(1u, resolver.pending_requests().size()); |
517 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 522 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
518 | 523 |
519 // Set the result in proxy resolver. | 524 // Set the result in proxy resolver. |
520 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 525 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); |
521 resolver.pending_requests()[0]->CompleteNow(OK); | 526 resolver.pending_requests()[0]->CompleteNow(OK); |
522 | 527 |
523 EXPECT_EQ(OK, callback.WaitForResult()); | 528 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
524 EXPECT_FALSE(info.is_direct()); | 529 EXPECT_FALSE(info.is_direct()); |
525 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); | 530 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); |
526 EXPECT_TRUE(info.did_use_pac_script()); | 531 EXPECT_TRUE(info.did_use_pac_script()); |
527 | 532 |
528 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 533 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
529 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 534 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
530 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 535 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
531 | 536 |
532 // Check the NetLog was filled correctly. | 537 // Check the NetLog was filled correctly. |
533 TestNetLogEntry::List entries; | 538 TestNetLogEntry::List entries; |
(...skipping 23 matching lines...) Expand all Loading... |
557 ProxyService service(base::WrapUnique(config_service), | 562 ProxyService service(base::WrapUnique(config_service), |
558 base::WrapUnique(factory), nullptr); | 563 base::WrapUnique(factory), nullptr); |
559 | 564 |
560 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 565 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
561 | 566 |
562 ProxyInfo info; | 567 ProxyInfo info; |
563 TestCompletionCallback callback; | 568 TestCompletionCallback callback; |
564 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 569 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
565 callback.callback(), nullptr, nullptr, | 570 callback.callback(), nullptr, nullptr, |
566 BoundNetLog()); | 571 BoundNetLog()); |
567 EXPECT_EQ(ERR_IO_PENDING, rv); | 572 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
568 | 573 |
569 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 574 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
570 factory->pending_requests()[0]->script_data()->url()); | 575 factory->pending_requests()[0]->script_data()->url()); |
571 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 576 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
572 | 577 |
573 ASSERT_EQ(1u, resolver.pending_requests().size()); | 578 ASSERT_EQ(1u, resolver.pending_requests().size()); |
574 // The URL should have been simplified, stripping the username/password/hash. | 579 // The URL should have been simplified, stripping the username/password/hash. |
575 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 580 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
576 resolver.pending_requests()[0]->url()); | 581 resolver.pending_requests()[0]->url()); |
577 | 582 |
(...skipping 11 matching lines...) Expand all Loading... |
589 ProxyService service(base::WrapUnique(config_service), | 594 ProxyService service(base::WrapUnique(config_service), |
590 base::WrapUnique(factory), nullptr); | 595 base::WrapUnique(factory), nullptr); |
591 | 596 |
592 GURL url("http://www.google.com/"); | 597 GURL url("http://www.google.com/"); |
593 | 598 |
594 ProxyInfo info; | 599 ProxyInfo info; |
595 TestCompletionCallback callback1; | 600 TestCompletionCallback callback1; |
596 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 601 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
597 callback1.callback(), nullptr, nullptr, | 602 callback1.callback(), nullptr, nullptr, |
598 BoundNetLog()); | 603 BoundNetLog()); |
599 EXPECT_EQ(ERR_IO_PENDING, rv); | 604 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
600 | 605 |
601 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 606 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
602 factory->pending_requests()[0]->script_data()->url()); | 607 factory->pending_requests()[0]->script_data()->url()); |
603 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 608 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
604 | 609 |
605 ASSERT_EQ(1u, resolver.pending_requests().size()); | 610 ASSERT_EQ(1u, resolver.pending_requests().size()); |
606 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 611 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
607 | 612 |
608 // Set the result in proxy resolver. | 613 // Set the result in proxy resolver. |
609 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 614 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
610 resolver.pending_requests()[0]->CompleteNow(OK); | 615 resolver.pending_requests()[0]->CompleteNow(OK); |
611 | 616 |
612 EXPECT_EQ(OK, callback1.WaitForResult()); | 617 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
613 EXPECT_FALSE(info.is_direct()); | 618 EXPECT_FALSE(info.is_direct()); |
614 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 619 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
615 EXPECT_TRUE(info.did_use_pac_script()); | 620 EXPECT_TRUE(info.did_use_pac_script()); |
616 | 621 |
617 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 622 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
618 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 623 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
619 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 624 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
620 | 625 |
621 // Now, imagine that connecting to foopy:8080 fails: there is nothing | 626 // Now, imagine that connecting to foopy:8080 fails: there is nothing |
622 // left to fallback to, since our proxy list was NOT terminated by | 627 // left to fallback to, since our proxy list was NOT terminated by |
623 // DIRECT. | 628 // DIRECT. |
624 TestResolveProxyDelegate proxy_delegate; | 629 TestResolveProxyDelegate proxy_delegate; |
625 TestCompletionCallback callback2; | 630 TestCompletionCallback callback2; |
626 ProxyServer expected_proxy_server = info.proxy_server(); | 631 ProxyServer expected_proxy_server = info.proxy_server(); |
627 rv = service.ReconsiderProxyAfterError( | 632 rv = service.ReconsiderProxyAfterError( |
628 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 633 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
629 callback2.callback(), nullptr, &proxy_delegate, BoundNetLog()); | 634 callback2.callback(), nullptr, &proxy_delegate, BoundNetLog()); |
630 // ReconsiderProxyAfterError returns error indicating nothing left. | 635 // ReconsiderProxyAfterError returns error indicating nothing left. |
631 EXPECT_EQ(ERR_FAILED, rv); | 636 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
632 EXPECT_TRUE(info.is_empty()); | 637 EXPECT_TRUE(info.is_empty()); |
633 } | 638 } |
634 | 639 |
635 // Test that if the execution of the PAC script fails (i.e. javascript runtime | 640 // Test that if the execution of the PAC script fails (i.e. javascript runtime |
636 // error), and the PAC settings are non-mandatory, that we fall-back to direct. | 641 // error), and the PAC settings are non-mandatory, that we fall-back to direct. |
637 TEST_F(ProxyServiceTest, PAC_RuntimeError) { | 642 TEST_F(ProxyServiceTest, PAC_RuntimeError) { |
638 MockProxyConfigService* config_service = | 643 MockProxyConfigService* config_service = |
639 new MockProxyConfigService("http://foopy/proxy.pac"); | 644 new MockProxyConfigService("http://foopy/proxy.pac"); |
640 MockAsyncProxyResolver resolver; | 645 MockAsyncProxyResolver resolver; |
641 MockAsyncProxyResolverFactory* factory = | 646 MockAsyncProxyResolverFactory* factory = |
642 new MockAsyncProxyResolverFactory(false); | 647 new MockAsyncProxyResolverFactory(false); |
643 | 648 |
644 ProxyService service(base::WrapUnique(config_service), | 649 ProxyService service(base::WrapUnique(config_service), |
645 base::WrapUnique(factory), nullptr); | 650 base::WrapUnique(factory), nullptr); |
646 | 651 |
647 GURL url("http://this-causes-js-error/"); | 652 GURL url("http://this-causes-js-error/"); |
648 | 653 |
649 ProxyInfo info; | 654 ProxyInfo info; |
650 TestCompletionCallback callback1; | 655 TestCompletionCallback callback1; |
651 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 656 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
652 callback1.callback(), nullptr, nullptr, | 657 callback1.callback(), nullptr, nullptr, |
653 BoundNetLog()); | 658 BoundNetLog()); |
654 EXPECT_EQ(ERR_IO_PENDING, rv); | 659 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
655 | 660 |
656 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 661 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
657 factory->pending_requests()[0]->script_data()->url()); | 662 factory->pending_requests()[0]->script_data()->url()); |
658 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 663 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
659 | 664 |
660 ASSERT_EQ(1u, resolver.pending_requests().size()); | 665 ASSERT_EQ(1u, resolver.pending_requests().size()); |
661 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 666 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
662 | 667 |
663 // Simulate a failure in the PAC executor. | 668 // Simulate a failure in the PAC executor. |
664 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); | 669 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); |
665 | 670 |
666 EXPECT_EQ(OK, callback1.WaitForResult()); | 671 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
667 | 672 |
668 // Since the PAC script was non-mandatory, we should have fallen-back to | 673 // Since the PAC script was non-mandatory, we should have fallen-back to |
669 // DIRECT. | 674 // DIRECT. |
670 EXPECT_TRUE(info.is_direct()); | 675 EXPECT_TRUE(info.is_direct()); |
671 EXPECT_TRUE(info.did_use_pac_script()); | 676 EXPECT_TRUE(info.did_use_pac_script()); |
672 EXPECT_EQ(1, info.config_id()); | 677 EXPECT_EQ(1, info.config_id()); |
673 | 678 |
674 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 679 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
675 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 680 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
676 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 681 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
(...skipping 26 matching lines...) Expand all Loading... |
703 ProxyService service(base::WrapUnique(config_service), | 708 ProxyService service(base::WrapUnique(config_service), |
704 base::WrapUnique(factory), nullptr); | 709 base::WrapUnique(factory), nullptr); |
705 | 710 |
706 GURL url("http://www.google.com/"); | 711 GURL url("http://www.google.com/"); |
707 | 712 |
708 ProxyInfo info; | 713 ProxyInfo info; |
709 TestCompletionCallback callback1; | 714 TestCompletionCallback callback1; |
710 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 715 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
711 callback1.callback(), nullptr, nullptr, | 716 callback1.callback(), nullptr, nullptr, |
712 BoundNetLog()); | 717 BoundNetLog()); |
713 EXPECT_EQ(ERR_IO_PENDING, rv); | 718 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
714 | 719 |
715 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 720 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
716 factory->pending_requests()[0]->script_data()->url()); | 721 factory->pending_requests()[0]->script_data()->url()); |
717 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 722 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
718 | 723 |
719 ASSERT_EQ(1u, resolver.pending_requests().size()); | 724 ASSERT_EQ(1u, resolver.pending_requests().size()); |
720 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 725 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
721 | 726 |
722 // Set the result in proxy resolver. | 727 // Set the result in proxy resolver. |
723 resolver.pending_requests()[0]->results()->UsePacString( | 728 resolver.pending_requests()[0]->results()->UsePacString( |
724 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 729 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
725 resolver.pending_requests()[0]->CompleteNow(OK); | 730 resolver.pending_requests()[0]->CompleteNow(OK); |
726 | 731 |
727 EXPECT_EQ(OK, callback1.WaitForResult()); | 732 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
728 EXPECT_TRUE(info.is_direct()); | 733 EXPECT_TRUE(info.is_direct()); |
729 | 734 |
730 // Fallback 1. | 735 // Fallback 1. |
731 TestCompletionCallback callback2; | 736 TestCompletionCallback callback2; |
732 rv = service.ReconsiderProxyAfterError( | 737 rv = service.ReconsiderProxyAfterError( |
733 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 738 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
734 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 739 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
735 EXPECT_EQ(OK, rv); | 740 EXPECT_THAT(rv, IsOk()); |
736 EXPECT_FALSE(info.is_direct()); | 741 EXPECT_FALSE(info.is_direct()); |
737 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); | 742 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); |
738 | 743 |
739 // Fallback 2. | 744 // Fallback 2. |
740 TestResolveProxyDelegate proxy_delegate; | 745 TestResolveProxyDelegate proxy_delegate; |
741 ProxyServer expected_proxy_server3 = info.proxy_server(); | 746 ProxyServer expected_proxy_server3 = info.proxy_server(); |
742 TestCompletionCallback callback3; | 747 TestCompletionCallback callback3; |
743 rv = service.ReconsiderProxyAfterError( | 748 rv = service.ReconsiderProxyAfterError( |
744 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 749 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
745 callback3.callback(), nullptr, &proxy_delegate, BoundNetLog()); | 750 callback3.callback(), nullptr, &proxy_delegate, BoundNetLog()); |
746 EXPECT_EQ(OK, rv); | 751 EXPECT_THAT(rv, IsOk()); |
747 EXPECT_TRUE(info.is_direct()); | 752 EXPECT_TRUE(info.is_direct()); |
748 | 753 |
749 // Fallback 3. | 754 // Fallback 3. |
750 ProxyServer expected_proxy_server4 = info.proxy_server(); | 755 ProxyServer expected_proxy_server4 = info.proxy_server(); |
751 TestCompletionCallback callback4; | 756 TestCompletionCallback callback4; |
752 rv = service.ReconsiderProxyAfterError( | 757 rv = service.ReconsiderProxyAfterError( |
753 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 758 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
754 callback4.callback(), nullptr, &proxy_delegate, BoundNetLog()); | 759 callback4.callback(), nullptr, &proxy_delegate, BoundNetLog()); |
755 EXPECT_EQ(OK, rv); | 760 EXPECT_THAT(rv, IsOk()); |
756 EXPECT_FALSE(info.is_direct()); | 761 EXPECT_FALSE(info.is_direct()); |
757 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); | 762 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); |
758 | 763 |
759 // Fallback 4 -- Nothing to fall back to! | 764 // Fallback 4 -- Nothing to fall back to! |
760 ProxyServer expected_proxy_server5 = info.proxy_server(); | 765 ProxyServer expected_proxy_server5 = info.proxy_server(); |
761 TestCompletionCallback callback5; | 766 TestCompletionCallback callback5; |
762 rv = service.ReconsiderProxyAfterError( | 767 rv = service.ReconsiderProxyAfterError( |
763 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 768 url, "GET", LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
764 callback5.callback(), nullptr, &proxy_delegate, BoundNetLog()); | 769 callback5.callback(), nullptr, &proxy_delegate, BoundNetLog()); |
765 EXPECT_EQ(ERR_FAILED, rv); | 770 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
766 EXPECT_TRUE(info.is_empty()); | 771 EXPECT_TRUE(info.is_empty()); |
767 } | 772 } |
768 | 773 |
769 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { | 774 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { |
770 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied | 775 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied |
771 // to ProxyInfo after the proxy is resolved via a PAC script. | 776 // to ProxyInfo after the proxy is resolved via a PAC script. |
772 ProxyConfig config = | 777 ProxyConfig config = |
773 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 778 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
774 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 779 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
775 | 780 |
776 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 781 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
777 MockAsyncProxyResolver resolver; | 782 MockAsyncProxyResolver resolver; |
778 MockAsyncProxyResolverFactory* factory = | 783 MockAsyncProxyResolverFactory* factory = |
779 new MockAsyncProxyResolverFactory(false); | 784 new MockAsyncProxyResolverFactory(false); |
780 ProxyService service(base::WrapUnique(config_service), | 785 ProxyService service(base::WrapUnique(config_service), |
781 base::WrapUnique(factory), nullptr); | 786 base::WrapUnique(factory), nullptr); |
782 | 787 |
783 // Resolve something. | 788 // Resolve something. |
784 GURL url("http://www.google.com/"); | 789 GURL url("http://www.google.com/"); |
785 ProxyInfo info; | 790 ProxyInfo info; |
786 TestCompletionCallback callback; | 791 TestCompletionCallback callback; |
787 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 792 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
788 callback.callback(), nullptr, nullptr, | 793 callback.callback(), nullptr, nullptr, |
789 BoundNetLog()); | 794 BoundNetLog()); |
790 ASSERT_EQ(ERR_IO_PENDING, rv); | 795 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
791 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 796 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
792 ASSERT_EQ(1u, resolver.pending_requests().size()); | 797 ASSERT_EQ(1u, resolver.pending_requests().size()); |
793 | 798 |
794 // Set the result in proxy resolver. | 799 // Set the result in proxy resolver. |
795 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 800 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); |
796 resolver.pending_requests()[0]->CompleteNow(OK); | 801 resolver.pending_requests()[0]->CompleteNow(OK); |
797 | 802 |
798 EXPECT_EQ(OK, callback.WaitForResult()); | 803 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
799 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 804 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
800 EXPECT_TRUE(info.did_use_pac_script()); | 805 EXPECT_TRUE(info.did_use_pac_script()); |
801 | 806 |
802 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 807 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
803 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 808 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
804 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 809 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
805 } | 810 } |
806 | 811 |
807 TEST_F(ProxyServiceTest, ProxyResolverFails) { | 812 TEST_F(ProxyServiceTest, ProxyResolverFails) { |
808 // Test what happens when the ProxyResolver fails. The download and setting | 813 // Test what happens when the ProxyResolver fails. The download and setting |
(...skipping 10 matching lines...) Expand all Loading... |
819 ProxyService service(base::WrapUnique(config_service), | 824 ProxyService service(base::WrapUnique(config_service), |
820 base::WrapUnique(factory), nullptr); | 825 base::WrapUnique(factory), nullptr); |
821 | 826 |
822 // Start first resolve request. | 827 // Start first resolve request. |
823 GURL url("http://www.google.com/"); | 828 GURL url("http://www.google.com/"); |
824 ProxyInfo info; | 829 ProxyInfo info; |
825 TestCompletionCallback callback1; | 830 TestCompletionCallback callback1; |
826 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 831 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
827 callback1.callback(), nullptr, nullptr, | 832 callback1.callback(), nullptr, nullptr, |
828 BoundNetLog()); | 833 BoundNetLog()); |
829 EXPECT_EQ(ERR_IO_PENDING, rv); | 834 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
830 | 835 |
831 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 836 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
832 factory->pending_requests()[0]->script_data()->url()); | 837 factory->pending_requests()[0]->script_data()->url()); |
833 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 838 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
834 | 839 |
835 ASSERT_EQ(1u, resolver.pending_requests().size()); | 840 ASSERT_EQ(1u, resolver.pending_requests().size()); |
836 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 841 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
837 | 842 |
838 // Fail the first resolve request in MockAsyncProxyResolver. | 843 // Fail the first resolve request in MockAsyncProxyResolver. |
839 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 844 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
840 | 845 |
841 // Although the proxy resolver failed the request, ProxyService implicitly | 846 // Although the proxy resolver failed the request, ProxyService implicitly |
842 // falls-back to DIRECT. | 847 // falls-back to DIRECT. |
843 EXPECT_EQ(OK, callback1.WaitForResult()); | 848 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
844 EXPECT_TRUE(info.is_direct()); | 849 EXPECT_TRUE(info.is_direct()); |
845 | 850 |
846 // Failed PAC executions still have proxy resolution times. | 851 // Failed PAC executions still have proxy resolution times. |
847 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 852 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
848 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 853 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
849 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 854 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
850 | 855 |
851 // The second resolve request will try to run through the proxy resolver, | 856 // The second resolve request will try to run through the proxy resolver, |
852 // regardless of whether the first request failed in it. | 857 // regardless of whether the first request failed in it. |
853 TestCompletionCallback callback2; | 858 TestCompletionCallback callback2; |
854 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 859 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
855 callback2.callback(), nullptr, nullptr, | 860 callback2.callback(), nullptr, nullptr, |
856 BoundNetLog()); | 861 BoundNetLog()); |
857 EXPECT_EQ(ERR_IO_PENDING, rv); | 862 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
858 | 863 |
859 ASSERT_EQ(1u, resolver.pending_requests().size()); | 864 ASSERT_EQ(1u, resolver.pending_requests().size()); |
860 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 865 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
861 | 866 |
862 // This time we will have the resolver succeed (perhaps the PAC script has | 867 // This time we will have the resolver succeed (perhaps the PAC script has |
863 // a dependency on the current time). | 868 // a dependency on the current time). |
864 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 869 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
865 resolver.pending_requests()[0]->CompleteNow(OK); | 870 resolver.pending_requests()[0]->CompleteNow(OK); |
866 | 871 |
867 EXPECT_EQ(OK, callback2.WaitForResult()); | 872 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
868 EXPECT_FALSE(info.is_direct()); | 873 EXPECT_FALSE(info.is_direct()); |
869 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 874 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
870 } | 875 } |
871 | 876 |
872 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { | 877 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { |
873 // Test what happens when the ProxyResolver fails with a fatal error while | 878 // Test what happens when the ProxyResolver fails with a fatal error while |
874 // a GetProxyForURL() call is in progress. | 879 // a GetProxyForURL() call is in progress. |
875 | 880 |
876 MockProxyConfigService* config_service = | 881 MockProxyConfigService* config_service = |
877 new MockProxyConfigService("http://foopy/proxy.pac"); | 882 new MockProxyConfigService("http://foopy/proxy.pac"); |
878 | 883 |
879 MockAsyncProxyResolver resolver; | 884 MockAsyncProxyResolver resolver; |
880 MockAsyncProxyResolverFactory* factory = | 885 MockAsyncProxyResolverFactory* factory = |
881 new MockAsyncProxyResolverFactory(false); | 886 new MockAsyncProxyResolverFactory(false); |
882 | 887 |
883 ProxyService service(base::WrapUnique(config_service), | 888 ProxyService service(base::WrapUnique(config_service), |
884 base::WrapUnique(factory), nullptr); | 889 base::WrapUnique(factory), nullptr); |
885 | 890 |
886 // Start first resolve request. | 891 // Start first resolve request. |
887 GURL url("http://www.google.com/"); | 892 GURL url("http://www.google.com/"); |
888 ProxyInfo info; | 893 ProxyInfo info; |
889 TestCompletionCallback callback1; | 894 TestCompletionCallback callback1; |
890 int rv = service.ResolveProxy(url, std::string(), net::LOAD_NORMAL, &info, | 895 int rv = service.ResolveProxy(url, std::string(), net::LOAD_NORMAL, &info, |
891 callback1.callback(), nullptr, nullptr, | 896 callback1.callback(), nullptr, nullptr, |
892 BoundNetLog()); | 897 BoundNetLog()); |
893 EXPECT_EQ(ERR_IO_PENDING, rv); | 898 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
894 | 899 |
895 ASSERT_EQ(1u, factory->pending_requests().size()); | 900 ASSERT_EQ(1u, factory->pending_requests().size()); |
896 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 901 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
897 factory->pending_requests()[0]->script_data()->url()); | 902 factory->pending_requests()[0]->script_data()->url()); |
898 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 903 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
899 | 904 |
900 ASSERT_EQ(1u, resolver.pending_requests().size()); | 905 ASSERT_EQ(1u, resolver.pending_requests().size()); |
901 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 906 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
902 | 907 |
903 // Fail the first resolve request in MockAsyncProxyResolver. | 908 // Fail the first resolve request in MockAsyncProxyResolver. |
904 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 909 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
905 | 910 |
906 // Although the proxy resolver failed the request, ProxyService implicitly | 911 // Although the proxy resolver failed the request, ProxyService implicitly |
907 // falls-back to DIRECT. | 912 // falls-back to DIRECT. |
908 EXPECT_EQ(OK, callback1.WaitForResult()); | 913 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
909 EXPECT_TRUE(info.is_direct()); | 914 EXPECT_TRUE(info.is_direct()); |
910 | 915 |
911 // Failed PAC executions still have proxy resolution times. | 916 // Failed PAC executions still have proxy resolution times. |
912 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 917 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
913 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 918 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
914 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 919 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
915 | 920 |
916 // With no other requests, the ProxyService waits for a new request before | 921 // With no other requests, the ProxyService waits for a new request before |
917 // initializing a new ProxyResolver. | 922 // initializing a new ProxyResolver. |
918 EXPECT_TRUE(factory->pending_requests().empty()); | 923 EXPECT_TRUE(factory->pending_requests().empty()); |
919 | 924 |
920 TestCompletionCallback callback2; | 925 TestCompletionCallback callback2; |
921 rv = service.ResolveProxy(url, std::string(), net::LOAD_NORMAL, &info, | 926 rv = service.ResolveProxy(url, std::string(), net::LOAD_NORMAL, &info, |
922 callback2.callback(), nullptr, nullptr, | 927 callback2.callback(), nullptr, nullptr, |
923 BoundNetLog()); | 928 BoundNetLog()); |
924 EXPECT_EQ(ERR_IO_PENDING, rv); | 929 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
925 | 930 |
926 ASSERT_EQ(1u, factory->pending_requests().size()); | 931 ASSERT_EQ(1u, factory->pending_requests().size()); |
927 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 932 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
928 factory->pending_requests()[0]->script_data()->url()); | 933 factory->pending_requests()[0]->script_data()->url()); |
929 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 934 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
930 | 935 |
931 ASSERT_EQ(1u, resolver.pending_requests().size()); | 936 ASSERT_EQ(1u, resolver.pending_requests().size()); |
932 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 937 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
933 | 938 |
934 // This time we will have the resolver succeed. | 939 // This time we will have the resolver succeed. |
935 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 940 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
936 resolver.pending_requests()[0]->CompleteNow(OK); | 941 resolver.pending_requests()[0]->CompleteNow(OK); |
937 | 942 |
938 EXPECT_EQ(OK, callback2.WaitForResult()); | 943 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
939 EXPECT_FALSE(info.is_direct()); | 944 EXPECT_FALSE(info.is_direct()); |
940 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 945 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
941 } | 946 } |
942 | 947 |
943 TEST_F(ProxyServiceTest, | 948 TEST_F(ProxyServiceTest, |
944 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { | 949 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { |
945 // Test what happens when the ProxyResolver fails with a fatal error while | 950 // Test what happens when the ProxyResolver fails with a fatal error while |
946 // a GetProxyForURL() call is in progress. | 951 // a GetProxyForURL() call is in progress. |
947 | 952 |
948 MockProxyConfigService* config_service = | 953 MockProxyConfigService* config_service = |
949 new MockProxyConfigService("http://foopy/proxy.pac"); | 954 new MockProxyConfigService("http://foopy/proxy.pac"); |
950 | 955 |
951 MockAsyncProxyResolver resolver; | 956 MockAsyncProxyResolver resolver; |
952 MockAsyncProxyResolverFactory* factory = | 957 MockAsyncProxyResolverFactory* factory = |
953 new MockAsyncProxyResolverFactory(false); | 958 new MockAsyncProxyResolverFactory(false); |
954 | 959 |
955 ProxyService service(base::WrapUnique(config_service), | 960 ProxyService service(base::WrapUnique(config_service), |
956 base::WrapUnique(factory), nullptr); | 961 base::WrapUnique(factory), nullptr); |
957 | 962 |
958 // Start two resolve requests. | 963 // Start two resolve requests. |
959 GURL url1("http://www.google.com/"); | 964 GURL url1("http://www.google.com/"); |
960 GURL url2("https://www.google.com/"); | 965 GURL url2("https://www.google.com/"); |
961 ProxyInfo info; | 966 ProxyInfo info; |
962 TestCompletionCallback callback1; | 967 TestCompletionCallback callback1; |
963 int rv = service.ResolveProxy(url1, std::string(), net::LOAD_NORMAL, &info, | 968 int rv = service.ResolveProxy(url1, std::string(), net::LOAD_NORMAL, &info, |
964 callback1.callback(), nullptr, nullptr, | 969 callback1.callback(), nullptr, nullptr, |
965 BoundNetLog()); | 970 BoundNetLog()); |
966 EXPECT_EQ(ERR_IO_PENDING, rv); | 971 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
967 TestCompletionCallback callback2; | 972 TestCompletionCallback callback2; |
968 rv = service.ResolveProxy(url2, std::string(), net::LOAD_NORMAL, &info, | 973 rv = service.ResolveProxy(url2, std::string(), net::LOAD_NORMAL, &info, |
969 callback2.callback(), nullptr, nullptr, | 974 callback2.callback(), nullptr, nullptr, |
970 BoundNetLog()); | 975 BoundNetLog()); |
971 EXPECT_EQ(ERR_IO_PENDING, rv); | 976 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
972 | 977 |
973 ASSERT_EQ(1u, factory->pending_requests().size()); | 978 ASSERT_EQ(1u, factory->pending_requests().size()); |
974 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 979 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
975 factory->pending_requests()[0]->script_data()->url()); | 980 factory->pending_requests()[0]->script_data()->url()); |
976 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 981 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
977 | 982 |
978 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 983 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); |
979 | 984 |
980 // Fail the first resolve request in MockAsyncProxyResolver. | 985 // Fail the first resolve request in MockAsyncProxyResolver. |
981 requests[url1]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 986 requests[url1]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
982 | 987 |
983 // Although the proxy resolver failed the request, ProxyService implicitly | 988 // Although the proxy resolver failed the request, ProxyService implicitly |
984 // falls-back to DIRECT. | 989 // falls-back to DIRECT. |
985 EXPECT_EQ(OK, callback1.WaitForResult()); | 990 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
986 EXPECT_TRUE(info.is_direct()); | 991 EXPECT_TRUE(info.is_direct()); |
987 | 992 |
988 // Failed PAC executions still have proxy resolution times. | 993 // Failed PAC executions still have proxy resolution times. |
989 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 994 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
990 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 995 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
991 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 996 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
992 | 997 |
993 // The second request is cancelled when the proxy resolver terminates. | 998 // The second request is cancelled when the proxy resolver terminates. |
994 requests = GetCancelledRequestsForURLs(resolver, url2); | 999 requests = GetCancelledRequestsForURLs(resolver, url2); |
995 | 1000 |
996 // Since a second request was in progress, the ProxyService starts | 1001 // Since a second request was in progress, the ProxyService starts |
997 // initializating a new ProxyResolver. | 1002 // initializating a new ProxyResolver. |
998 ASSERT_EQ(1u, factory->pending_requests().size()); | 1003 ASSERT_EQ(1u, factory->pending_requests().size()); |
999 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1004 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1000 factory->pending_requests()[0]->script_data()->url()); | 1005 factory->pending_requests()[0]->script_data()->url()); |
1001 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1006 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1002 | 1007 |
1003 requests = GetPendingRequestsForURLs(resolver, url2); | 1008 requests = GetPendingRequestsForURLs(resolver, url2); |
1004 | 1009 |
1005 // This request succeeds. | 1010 // This request succeeds. |
1006 requests[url2]->results()->UseNamedProxy("foopy_valid:8080"); | 1011 requests[url2]->results()->UseNamedProxy("foopy_valid:8080"); |
1007 requests[url2]->CompleteNow(OK); | 1012 requests[url2]->CompleteNow(OK); |
1008 | 1013 |
1009 EXPECT_EQ(OK, callback2.WaitForResult()); | 1014 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
1010 EXPECT_FALSE(info.is_direct()); | 1015 EXPECT_FALSE(info.is_direct()); |
1011 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 1016 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
1012 } | 1017 } |
1013 | 1018 |
1014 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { | 1019 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { |
1015 // Test what happens when the ProxyScriptResolver fails to download a | 1020 // Test what happens when the ProxyScriptResolver fails to download a |
1016 // mandatory PAC script. | 1021 // mandatory PAC script. |
1017 | 1022 |
1018 ProxyConfig config( | 1023 ProxyConfig config( |
1019 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 1024 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
1020 config.set_pac_mandatory(true); | 1025 config.set_pac_mandatory(true); |
1021 | 1026 |
1022 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1027 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
1023 | 1028 |
1024 MockAsyncProxyResolverFactory* factory = | 1029 MockAsyncProxyResolverFactory* factory = |
1025 new MockAsyncProxyResolverFactory(false); | 1030 new MockAsyncProxyResolverFactory(false); |
1026 | 1031 |
1027 ProxyService service(base::WrapUnique(config_service), | 1032 ProxyService service(base::WrapUnique(config_service), |
1028 base::WrapUnique(factory), nullptr); | 1033 base::WrapUnique(factory), nullptr); |
1029 | 1034 |
1030 // Start first resolve request. | 1035 // Start first resolve request. |
1031 GURL url("http://www.google.com/"); | 1036 GURL url("http://www.google.com/"); |
1032 ProxyInfo info; | 1037 ProxyInfo info; |
1033 TestCompletionCallback callback1; | 1038 TestCompletionCallback callback1; |
1034 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1039 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1035 callback1.callback(), nullptr, nullptr, | 1040 callback1.callback(), nullptr, nullptr, |
1036 BoundNetLog()); | 1041 BoundNetLog()); |
1037 EXPECT_EQ(ERR_IO_PENDING, rv); | 1042 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1038 | 1043 |
1039 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1044 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1040 factory->pending_requests()[0]->script_data()->url()); | 1045 factory->pending_requests()[0]->script_data()->url()); |
1041 factory->pending_requests()[0]->CompleteNow(ERR_FAILED, nullptr); | 1046 factory->pending_requests()[0]->CompleteNow(ERR_FAILED, nullptr); |
1042 | 1047 |
1043 ASSERT_EQ(0u, factory->pending_requests().size()); | 1048 ASSERT_EQ(0u, factory->pending_requests().size()); |
1044 // As the proxy resolver factory failed the request and is configured for a | 1049 // As the proxy resolver factory failed the request and is configured for a |
1045 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1050 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1046 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1051 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1047 callback1.WaitForResult()); | 1052 callback1.WaitForResult()); |
1048 EXPECT_FALSE(info.is_direct()); | 1053 EXPECT_FALSE(info.is_direct()); |
1049 | 1054 |
1050 // As the proxy resolver factory failed the request and is configured for a | 1055 // As the proxy resolver factory failed the request and is configured for a |
1051 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1056 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1052 TestCompletionCallback callback2; | 1057 TestCompletionCallback callback2; |
1053 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1058 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1054 callback2.callback(), nullptr, nullptr, | 1059 callback2.callback(), nullptr, nullptr, |
1055 BoundNetLog()); | 1060 BoundNetLog()); |
1056 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); | 1061 EXPECT_THAT(rv, IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
1057 EXPECT_FALSE(info.is_direct()); | 1062 EXPECT_FALSE(info.is_direct()); |
1058 } | 1063 } |
1059 | 1064 |
1060 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 1065 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
1061 // Test what happens when the ProxyResolver fails that is configured to use a | 1066 // Test what happens when the ProxyResolver fails that is configured to use a |
1062 // mandatory PAC script. The download of the PAC script has already | 1067 // mandatory PAC script. The download of the PAC script has already |
1063 // succeeded but the PAC script contains no valid javascript. | 1068 // succeeded but the PAC script contains no valid javascript. |
1064 | 1069 |
1065 ProxyConfig config( | 1070 ProxyConfig config( |
1066 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 1071 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
(...skipping 11 matching lines...) Expand all Loading... |
1078 service.SetProxyScriptFetchers( | 1083 service.SetProxyScriptFetchers( |
1079 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 1084 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
1080 | 1085 |
1081 // Start resolve request. | 1086 // Start resolve request. |
1082 GURL url("http://www.google.com/"); | 1087 GURL url("http://www.google.com/"); |
1083 ProxyInfo info; | 1088 ProxyInfo info; |
1084 TestCompletionCallback callback; | 1089 TestCompletionCallback callback; |
1085 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1090 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1086 callback.callback(), nullptr, nullptr, | 1091 callback.callback(), nullptr, nullptr, |
1087 BoundNetLog()); | 1092 BoundNetLog()); |
1088 EXPECT_EQ(ERR_IO_PENDING, rv); | 1093 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1089 | 1094 |
1090 // Check that nothing has been sent to the proxy resolver factory yet. | 1095 // Check that nothing has been sent to the proxy resolver factory yet. |
1091 ASSERT_EQ(0u, factory->pending_requests().size()); | 1096 ASSERT_EQ(0u, factory->pending_requests().size()); |
1092 | 1097 |
1093 // Downloading the PAC script succeeds. | 1098 // Downloading the PAC script succeeds. |
1094 EXPECT_TRUE(fetcher->has_pending_request()); | 1099 EXPECT_TRUE(fetcher->has_pending_request()); |
1095 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1100 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1096 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1101 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
1097 | 1102 |
1098 EXPECT_FALSE(fetcher->has_pending_request()); | 1103 EXPECT_FALSE(fetcher->has_pending_request()); |
(...skipping 26 matching lines...) Expand all Loading... |
1125 ProxyService service(base::WrapUnique(config_service), | 1130 ProxyService service(base::WrapUnique(config_service), |
1126 base::WrapUnique(factory), nullptr); | 1131 base::WrapUnique(factory), nullptr); |
1127 | 1132 |
1128 // Start first resolve request. | 1133 // Start first resolve request. |
1129 GURL url("http://www.google.com/"); | 1134 GURL url("http://www.google.com/"); |
1130 ProxyInfo info; | 1135 ProxyInfo info; |
1131 TestCompletionCallback callback1; | 1136 TestCompletionCallback callback1; |
1132 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1137 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1133 callback1.callback(), nullptr, nullptr, | 1138 callback1.callback(), nullptr, nullptr, |
1134 BoundNetLog()); | 1139 BoundNetLog()); |
1135 EXPECT_EQ(ERR_IO_PENDING, rv); | 1140 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1136 | 1141 |
1137 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1142 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1138 factory->pending_requests()[0]->script_data()->url()); | 1143 factory->pending_requests()[0]->script_data()->url()); |
1139 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1144 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1140 | 1145 |
1141 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1146 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1142 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1147 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1143 | 1148 |
1144 // Fail the first resolve request in MockAsyncProxyResolver. | 1149 // Fail the first resolve request in MockAsyncProxyResolver. |
1145 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1150 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1146 | 1151 |
1147 // As the proxy resolver failed the request and is configured for a mandatory | 1152 // As the proxy resolver failed the request and is configured for a mandatory |
1148 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1153 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1149 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1154 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1150 callback1.WaitForResult()); | 1155 callback1.WaitForResult()); |
1151 EXPECT_FALSE(info.is_direct()); | 1156 EXPECT_FALSE(info.is_direct()); |
1152 | 1157 |
1153 // The second resolve request will try to run through the proxy resolver, | 1158 // The second resolve request will try to run through the proxy resolver, |
1154 // regardless of whether the first request failed in it. | 1159 // regardless of whether the first request failed in it. |
1155 TestCompletionCallback callback2; | 1160 TestCompletionCallback callback2; |
1156 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1161 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1157 callback2.callback(), nullptr, nullptr, | 1162 callback2.callback(), nullptr, nullptr, |
1158 BoundNetLog()); | 1163 BoundNetLog()); |
1159 EXPECT_EQ(ERR_IO_PENDING, rv); | 1164 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1160 | 1165 |
1161 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1166 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1162 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1167 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1163 | 1168 |
1164 // This time we will have the resolver succeed (perhaps the PAC script has | 1169 // This time we will have the resolver succeed (perhaps the PAC script has |
1165 // a dependency on the current time). | 1170 // a dependency on the current time). |
1166 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 1171 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
1167 resolver.pending_requests()[0]->CompleteNow(OK); | 1172 resolver.pending_requests()[0]->CompleteNow(OK); |
1168 | 1173 |
1169 EXPECT_EQ(OK, callback2.WaitForResult()); | 1174 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
1170 EXPECT_FALSE(info.is_direct()); | 1175 EXPECT_FALSE(info.is_direct()); |
1171 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 1176 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
1172 } | 1177 } |
1173 | 1178 |
1174 TEST_F(ProxyServiceTest, ProxyFallback) { | 1179 TEST_F(ProxyServiceTest, ProxyFallback) { |
1175 // Test what happens when we specify multiple proxy servers and some of them | 1180 // Test what happens when we specify multiple proxy servers and some of them |
1176 // are bad. | 1181 // are bad. |
1177 | 1182 |
1178 MockProxyConfigService* config_service = | 1183 MockProxyConfigService* config_service = |
1179 new MockProxyConfigService("http://foopy/proxy.pac"); | 1184 new MockProxyConfigService("http://foopy/proxy.pac"); |
1180 | 1185 |
1181 MockAsyncProxyResolver resolver; | 1186 MockAsyncProxyResolver resolver; |
1182 MockAsyncProxyResolverFactory* factory = | 1187 MockAsyncProxyResolverFactory* factory = |
1183 new MockAsyncProxyResolverFactory(false); | 1188 new MockAsyncProxyResolverFactory(false); |
1184 | 1189 |
1185 ProxyService service(base::WrapUnique(config_service), | 1190 ProxyService service(base::WrapUnique(config_service), |
1186 base::WrapUnique(factory), nullptr); | 1191 base::WrapUnique(factory), nullptr); |
1187 | 1192 |
1188 GURL url("http://www.google.com/"); | 1193 GURL url("http://www.google.com/"); |
1189 | 1194 |
1190 // Get the proxy information. | 1195 // Get the proxy information. |
1191 ProxyInfo info; | 1196 ProxyInfo info; |
1192 TestCompletionCallback callback1; | 1197 TestCompletionCallback callback1; |
1193 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1198 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1194 callback1.callback(), nullptr, nullptr, | 1199 callback1.callback(), nullptr, nullptr, |
1195 BoundNetLog()); | 1200 BoundNetLog()); |
1196 EXPECT_EQ(ERR_IO_PENDING, rv); | 1201 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1197 | 1202 |
1198 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1203 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1199 factory->pending_requests()[0]->script_data()->url()); | 1204 factory->pending_requests()[0]->script_data()->url()); |
1200 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1205 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1201 | 1206 |
1202 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1207 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1203 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1208 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1204 | 1209 |
1205 // Set the result in proxy resolver. | 1210 // Set the result in proxy resolver. |
1206 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1211 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1207 "foopy1:8080;foopy2:9090"); | 1212 "foopy1:8080;foopy2:9090"); |
1208 resolver.pending_requests()[0]->CompleteNow(OK); | 1213 resolver.pending_requests()[0]->CompleteNow(OK); |
1209 | 1214 |
1210 // The first item is valid. | 1215 // The first item is valid. |
1211 EXPECT_EQ(OK, callback1.WaitForResult()); | 1216 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1212 EXPECT_FALSE(info.is_direct()); | 1217 EXPECT_FALSE(info.is_direct()); |
1213 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1218 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1214 | 1219 |
1215 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1220 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1216 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1221 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1217 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1222 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1218 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1223 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); |
1219 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); | 1224 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); |
1220 | 1225 |
1221 // Fake an error on the proxy. | 1226 // Fake an error on the proxy. |
1222 TestCompletionCallback callback2; | 1227 TestCompletionCallback callback2; |
1223 rv = service.ReconsiderProxyAfterError( | 1228 rv = service.ReconsiderProxyAfterError( |
1224 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1229 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1225 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1230 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
1226 EXPECT_EQ(OK, rv); | 1231 EXPECT_THAT(rv, IsOk()); |
1227 | 1232 |
1228 // Proxy times should not have been modified by fallback. | 1233 // Proxy times should not have been modified by fallback. |
1229 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1234 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
1230 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1235 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
1231 | 1236 |
1232 // The second proxy should be specified. | 1237 // The second proxy should be specified. |
1233 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1238 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1234 // Report back that the second proxy worked. This will globally mark the | 1239 // Report back that the second proxy worked. This will globally mark the |
1235 // first proxy as bad. | 1240 // first proxy as bad. |
1236 TestProxyFallbackProxyDelegate test_delegate; | 1241 TestProxyFallbackProxyDelegate test_delegate; |
1237 service.ReportSuccess(info, &test_delegate); | 1242 service.ReportSuccess(info, &test_delegate); |
1238 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); | 1243 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); |
1239 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 1244 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
1240 test_delegate.proxy_fallback_net_error()); | 1245 test_delegate.proxy_fallback_net_error()); |
1241 | 1246 |
1242 TestCompletionCallback callback3; | 1247 TestCompletionCallback callback3; |
1243 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1248 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1244 callback3.callback(), nullptr, nullptr, | 1249 callback3.callback(), nullptr, nullptr, |
1245 BoundNetLog()); | 1250 BoundNetLog()); |
1246 EXPECT_EQ(ERR_IO_PENDING, rv); | 1251 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1247 | 1252 |
1248 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1253 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1249 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1254 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1250 | 1255 |
1251 // Set the result in proxy resolver -- the second result is already known | 1256 // Set the result in proxy resolver -- the second result is already known |
1252 // to be bad, so we will not try to use it initially. | 1257 // to be bad, so we will not try to use it initially. |
1253 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1258 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1254 "foopy3:7070;foopy1:8080;foopy2:9090"); | 1259 "foopy3:7070;foopy1:8080;foopy2:9090"); |
1255 resolver.pending_requests()[0]->CompleteNow(OK); | 1260 resolver.pending_requests()[0]->CompleteNow(OK); |
1256 | 1261 |
1257 EXPECT_EQ(OK, callback3.WaitForResult()); | 1262 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
1258 EXPECT_FALSE(info.is_direct()); | 1263 EXPECT_FALSE(info.is_direct()); |
1259 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1264 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1260 | 1265 |
1261 // Proxy times should have been updated, so get them again. | 1266 // Proxy times should have been updated, so get them again. |
1262 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1267 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1263 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1268 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1264 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1269 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1265 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1270 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1266 proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1271 proxy_resolve_start_time = info.proxy_resolve_start_time(); |
1267 proxy_resolve_end_time = info.proxy_resolve_end_time(); | 1272 proxy_resolve_end_time = info.proxy_resolve_end_time(); |
1268 | 1273 |
1269 // We fake another error. It should now try the third one. | 1274 // We fake another error. It should now try the third one. |
1270 TestCompletionCallback callback4; | 1275 TestCompletionCallback callback4; |
1271 rv = service.ReconsiderProxyAfterError( | 1276 rv = service.ReconsiderProxyAfterError( |
1272 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1277 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1273 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1278 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
1274 EXPECT_EQ(OK, rv); | 1279 EXPECT_THAT(rv, IsOk()); |
1275 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1280 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1276 | 1281 |
1277 // We fake another error. At this point we have tried all of the | 1282 // We fake another error. At this point we have tried all of the |
1278 // proxy servers we thought were valid; next we try the proxy server | 1283 // proxy servers we thought were valid; next we try the proxy server |
1279 // that was in our bad proxies map (foopy1:8080). | 1284 // that was in our bad proxies map (foopy1:8080). |
1280 TestCompletionCallback callback5; | 1285 TestCompletionCallback callback5; |
1281 rv = service.ReconsiderProxyAfterError( | 1286 rv = service.ReconsiderProxyAfterError( |
1282 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1287 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1283 callback5.callback(), nullptr, nullptr, BoundNetLog()); | 1288 callback5.callback(), nullptr, nullptr, BoundNetLog()); |
1284 EXPECT_EQ(OK, rv); | 1289 EXPECT_THAT(rv, IsOk()); |
1285 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1290 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1286 | 1291 |
1287 // Fake another error, the last proxy is gone, the list should now be empty, | 1292 // Fake another error, the last proxy is gone, the list should now be empty, |
1288 // so there is nothing left to try. | 1293 // so there is nothing left to try. |
1289 TestCompletionCallback callback6; | 1294 TestCompletionCallback callback6; |
1290 rv = service.ReconsiderProxyAfterError( | 1295 rv = service.ReconsiderProxyAfterError( |
1291 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1296 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1292 callback6.callback(), nullptr, nullptr, BoundNetLog()); | 1297 callback6.callback(), nullptr, nullptr, BoundNetLog()); |
1293 EXPECT_EQ(ERR_FAILED, rv); | 1298 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
1294 EXPECT_FALSE(info.is_direct()); | 1299 EXPECT_FALSE(info.is_direct()); |
1295 EXPECT_TRUE(info.is_empty()); | 1300 EXPECT_TRUE(info.is_empty()); |
1296 | 1301 |
1297 // Proxy times should not have been modified by fallback. | 1302 // Proxy times should not have been modified by fallback. |
1298 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1303 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
1299 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1304 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
1300 | 1305 |
1301 // Look up proxies again | 1306 // Look up proxies again |
1302 TestCompletionCallback callback7; | 1307 TestCompletionCallback callback7; |
1303 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1308 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1304 callback7.callback(), nullptr, nullptr, | 1309 callback7.callback(), nullptr, nullptr, |
1305 BoundNetLog()); | 1310 BoundNetLog()); |
1306 EXPECT_EQ(ERR_IO_PENDING, rv); | 1311 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1307 | 1312 |
1308 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1313 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1309 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1314 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1310 | 1315 |
1311 // This time, the first 3 results have been found to be bad, but only the | 1316 // This time, the first 3 results have been found to be bad, but only the |
1312 // first proxy has been confirmed ... | 1317 // first proxy has been confirmed ... |
1313 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1318 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1314 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 1319 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
1315 resolver.pending_requests()[0]->CompleteNow(OK); | 1320 resolver.pending_requests()[0]->CompleteNow(OK); |
1316 | 1321 |
1317 // ... therefore, we should see the second proxy first. | 1322 // ... therefore, we should see the second proxy first. |
1318 EXPECT_EQ(OK, callback7.WaitForResult()); | 1323 EXPECT_THAT(callback7.WaitForResult(), IsOk()); |
1319 EXPECT_FALSE(info.is_direct()); | 1324 EXPECT_FALSE(info.is_direct()); |
1320 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1325 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1321 | 1326 |
1322 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1327 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1323 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1328 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1324 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1329 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1325 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 1330 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
1326 } | 1331 } |
1327 | 1332 |
1328 // This test is similar to ProxyFallback, but this time we have an explicit | 1333 // This test is similar to ProxyFallback, but this time we have an explicit |
(...skipping 10 matching lines...) Expand all Loading... |
1339 base::WrapUnique(factory), nullptr); | 1344 base::WrapUnique(factory), nullptr); |
1340 | 1345 |
1341 GURL url("http://www.google.com/"); | 1346 GURL url("http://www.google.com/"); |
1342 | 1347 |
1343 // Get the proxy information. | 1348 // Get the proxy information. |
1344 ProxyInfo info; | 1349 ProxyInfo info; |
1345 TestCompletionCallback callback1; | 1350 TestCompletionCallback callback1; |
1346 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1351 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1347 callback1.callback(), nullptr, nullptr, | 1352 callback1.callback(), nullptr, nullptr, |
1348 BoundNetLog()); | 1353 BoundNetLog()); |
1349 EXPECT_EQ(ERR_IO_PENDING, rv); | 1354 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1350 | 1355 |
1351 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1356 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1352 factory->pending_requests()[0]->script_data()->url()); | 1357 factory->pending_requests()[0]->script_data()->url()); |
1353 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1358 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1354 | 1359 |
1355 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1360 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1356 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1361 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1357 | 1362 |
1358 // Set the result in proxy resolver. | 1363 // Set the result in proxy resolver. |
1359 resolver.pending_requests()[0]->results()->UsePacString( | 1364 resolver.pending_requests()[0]->results()->UsePacString( |
1360 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 1365 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
1361 resolver.pending_requests()[0]->CompleteNow(OK); | 1366 resolver.pending_requests()[0]->CompleteNow(OK); |
1362 | 1367 |
1363 // Get the first result. | 1368 // Get the first result. |
1364 EXPECT_EQ(OK, callback1.WaitForResult()); | 1369 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1365 EXPECT_FALSE(info.is_direct()); | 1370 EXPECT_FALSE(info.is_direct()); |
1366 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1371 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1367 | 1372 |
1368 // Fake an error on the proxy. | 1373 // Fake an error on the proxy. |
1369 TestCompletionCallback callback2; | 1374 TestCompletionCallback callback2; |
1370 rv = service.ReconsiderProxyAfterError( | 1375 rv = service.ReconsiderProxyAfterError( |
1371 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1376 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1372 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1377 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
1373 EXPECT_EQ(OK, rv); | 1378 EXPECT_THAT(rv, IsOk()); |
1374 | 1379 |
1375 // Now we get back the second proxy. | 1380 // Now we get back the second proxy. |
1376 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1381 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1377 | 1382 |
1378 // Fake an error on this proxy as well. | 1383 // Fake an error on this proxy as well. |
1379 TestCompletionCallback callback3; | 1384 TestCompletionCallback callback3; |
1380 rv = service.ReconsiderProxyAfterError( | 1385 rv = service.ReconsiderProxyAfterError( |
1381 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1386 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1382 callback3.callback(), nullptr, nullptr, BoundNetLog()); | 1387 callback3.callback(), nullptr, nullptr, BoundNetLog()); |
1383 EXPECT_EQ(OK, rv); | 1388 EXPECT_THAT(rv, IsOk()); |
1384 | 1389 |
1385 // Finally, we get back DIRECT. | 1390 // Finally, we get back DIRECT. |
1386 EXPECT_TRUE(info.is_direct()); | 1391 EXPECT_TRUE(info.is_direct()); |
1387 | 1392 |
1388 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1393 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1389 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1394 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1390 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1395 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1391 | 1396 |
1392 // Now we tell the proxy service that even DIRECT failed. | 1397 // Now we tell the proxy service that even DIRECT failed. |
1393 TestCompletionCallback callback4; | 1398 TestCompletionCallback callback4; |
1394 rv = service.ReconsiderProxyAfterError( | 1399 rv = service.ReconsiderProxyAfterError( |
1395 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1400 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1396 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1401 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
1397 // There was nothing left to try after DIRECT, so we are out of | 1402 // There was nothing left to try after DIRECT, so we are out of |
1398 // choices. | 1403 // choices. |
1399 EXPECT_EQ(ERR_FAILED, rv); | 1404 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
1400 } | 1405 } |
1401 | 1406 |
1402 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { | 1407 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { |
1403 // Test proxy failover when new settings are available. | 1408 // Test proxy failover when new settings are available. |
1404 | 1409 |
1405 MockProxyConfigService* config_service = | 1410 MockProxyConfigService* config_service = |
1406 new MockProxyConfigService("http://foopy/proxy.pac"); | 1411 new MockProxyConfigService("http://foopy/proxy.pac"); |
1407 | 1412 |
1408 MockAsyncProxyResolver resolver; | 1413 MockAsyncProxyResolver resolver; |
1409 MockAsyncProxyResolverFactory* factory = | 1414 MockAsyncProxyResolverFactory* factory = |
1410 new MockAsyncProxyResolverFactory(false); | 1415 new MockAsyncProxyResolverFactory(false); |
1411 | 1416 |
1412 ProxyService service(base::WrapUnique(config_service), | 1417 ProxyService service(base::WrapUnique(config_service), |
1413 base::WrapUnique(factory), nullptr); | 1418 base::WrapUnique(factory), nullptr); |
1414 | 1419 |
1415 GURL url("http://www.google.com/"); | 1420 GURL url("http://www.google.com/"); |
1416 | 1421 |
1417 // Get the proxy information. | 1422 // Get the proxy information. |
1418 ProxyInfo info; | 1423 ProxyInfo info; |
1419 TestCompletionCallback callback1; | 1424 TestCompletionCallback callback1; |
1420 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1425 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1421 callback1.callback(), nullptr, nullptr, | 1426 callback1.callback(), nullptr, nullptr, |
1422 BoundNetLog()); | 1427 BoundNetLog()); |
1423 EXPECT_EQ(ERR_IO_PENDING, rv); | 1428 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1424 | 1429 |
1425 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1430 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1426 factory->pending_requests()[0]->script_data()->url()); | 1431 factory->pending_requests()[0]->script_data()->url()); |
1427 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1432 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1428 | 1433 |
1429 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1434 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1430 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1435 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1431 | 1436 |
1432 // Set the result in proxy resolver. | 1437 // Set the result in proxy resolver. |
1433 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1438 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1434 "foopy1:8080;foopy2:9090"); | 1439 "foopy1:8080;foopy2:9090"); |
1435 resolver.pending_requests()[0]->CompleteNow(OK); | 1440 resolver.pending_requests()[0]->CompleteNow(OK); |
1436 | 1441 |
1437 // The first item is valid. | 1442 // The first item is valid. |
1438 EXPECT_EQ(OK, callback1.WaitForResult()); | 1443 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1439 EXPECT_FALSE(info.is_direct()); | 1444 EXPECT_FALSE(info.is_direct()); |
1440 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1445 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1441 | 1446 |
1442 // Fake an error on the proxy, and also a new configuration on the proxy. | 1447 // Fake an error on the proxy, and also a new configuration on the proxy. |
1443 config_service->SetConfig( | 1448 config_service->SetConfig( |
1444 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 1449 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
1445 | 1450 |
1446 TestCompletionCallback callback2; | 1451 TestCompletionCallback callback2; |
1447 rv = service.ReconsiderProxyAfterError( | 1452 rv = service.ReconsiderProxyAfterError( |
1448 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1453 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1449 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1454 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
1450 EXPECT_EQ(ERR_IO_PENDING, rv); | 1455 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1451 | 1456 |
1452 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 1457 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
1453 factory->pending_requests()[0]->script_data()->url()); | 1458 factory->pending_requests()[0]->script_data()->url()); |
1454 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1459 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1455 | 1460 |
1456 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1461 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1457 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1462 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1458 | 1463 |
1459 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1464 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1460 "foopy1:8080;foopy2:9090"); | 1465 "foopy1:8080;foopy2:9090"); |
1461 resolver.pending_requests()[0]->CompleteNow(OK); | 1466 resolver.pending_requests()[0]->CompleteNow(OK); |
1462 | 1467 |
1463 // The first proxy is still there since the configuration changed. | 1468 // The first proxy is still there since the configuration changed. |
1464 EXPECT_EQ(OK, callback2.WaitForResult()); | 1469 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
1465 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1470 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1466 | 1471 |
1467 // We fake another error. It should now ignore the first one. | 1472 // We fake another error. It should now ignore the first one. |
1468 TestCompletionCallback callback3; | 1473 TestCompletionCallback callback3; |
1469 rv = service.ReconsiderProxyAfterError( | 1474 rv = service.ReconsiderProxyAfterError( |
1470 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1475 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1471 callback3.callback(), nullptr, nullptr, BoundNetLog()); | 1476 callback3.callback(), nullptr, nullptr, BoundNetLog()); |
1472 EXPECT_EQ(OK, rv); | 1477 EXPECT_THAT(rv, IsOk()); |
1473 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1478 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1474 | 1479 |
1475 // We simulate a new configuration. | 1480 // We simulate a new configuration. |
1476 config_service->SetConfig( | 1481 config_service->SetConfig( |
1477 ProxyConfig::CreateFromCustomPacURL( | 1482 ProxyConfig::CreateFromCustomPacURL( |
1478 GURL("http://foopy-new2/proxy.pac"))); | 1483 GURL("http://foopy-new2/proxy.pac"))); |
1479 | 1484 |
1480 // We fake another error. It should go back to the first proxy. | 1485 // We fake another error. It should go back to the first proxy. |
1481 TestCompletionCallback callback4; | 1486 TestCompletionCallback callback4; |
1482 rv = service.ReconsiderProxyAfterError( | 1487 rv = service.ReconsiderProxyAfterError( |
1483 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1488 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1484 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1489 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
1485 EXPECT_EQ(ERR_IO_PENDING, rv); | 1490 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1486 | 1491 |
1487 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 1492 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
1488 factory->pending_requests()[0]->script_data()->url()); | 1493 factory->pending_requests()[0]->script_data()->url()); |
1489 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1494 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1490 | 1495 |
1491 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1496 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1492 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1497 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1493 | 1498 |
1494 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1499 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1495 "foopy1:8080;foopy2:9090"); | 1500 "foopy1:8080;foopy2:9090"); |
1496 resolver.pending_requests()[0]->CompleteNow(OK); | 1501 resolver.pending_requests()[0]->CompleteNow(OK); |
1497 | 1502 |
1498 EXPECT_EQ(OK, callback4.WaitForResult()); | 1503 EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
1499 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1504 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1500 | 1505 |
1501 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1506 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1502 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1507 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1503 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1508 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1504 } | 1509 } |
1505 | 1510 |
1506 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { | 1511 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { |
1507 // Test proxy failover when the configuration is bad. | 1512 // Test proxy failover when the configuration is bad. |
1508 | 1513 |
1509 MockProxyConfigService* config_service = | 1514 MockProxyConfigService* config_service = |
1510 new MockProxyConfigService("http://foopy/proxy.pac"); | 1515 new MockProxyConfigService("http://foopy/proxy.pac"); |
1511 | 1516 |
1512 MockAsyncProxyResolver resolver; | 1517 MockAsyncProxyResolver resolver; |
1513 MockAsyncProxyResolverFactory* factory = | 1518 MockAsyncProxyResolverFactory* factory = |
1514 new MockAsyncProxyResolverFactory(false); | 1519 new MockAsyncProxyResolverFactory(false); |
1515 | 1520 |
1516 ProxyService service(base::WrapUnique(config_service), | 1521 ProxyService service(base::WrapUnique(config_service), |
1517 base::WrapUnique(factory), nullptr); | 1522 base::WrapUnique(factory), nullptr); |
1518 | 1523 |
1519 GURL url("http://www.google.com/"); | 1524 GURL url("http://www.google.com/"); |
1520 | 1525 |
1521 // Get the proxy information. | 1526 // Get the proxy information. |
1522 ProxyInfo info; | 1527 ProxyInfo info; |
1523 TestCompletionCallback callback1; | 1528 TestCompletionCallback callback1; |
1524 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1529 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1525 callback1.callback(), nullptr, nullptr, | 1530 callback1.callback(), nullptr, nullptr, |
1526 BoundNetLog()); | 1531 BoundNetLog()); |
1527 EXPECT_EQ(ERR_IO_PENDING, rv); | 1532 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1528 | 1533 |
1529 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1534 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1530 factory->pending_requests()[0]->script_data()->url()); | 1535 factory->pending_requests()[0]->script_data()->url()); |
1531 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1536 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1532 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1537 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1533 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1538 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1534 | 1539 |
1535 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1540 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1536 "foopy1:8080;foopy2:9090"); | 1541 "foopy1:8080;foopy2:9090"); |
1537 resolver.pending_requests()[0]->CompleteNow(OK); | 1542 resolver.pending_requests()[0]->CompleteNow(OK); |
1538 | 1543 |
1539 // The first item is valid. | 1544 // The first item is valid. |
1540 EXPECT_EQ(OK, callback1.WaitForResult()); | 1545 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1541 EXPECT_FALSE(info.is_direct()); | 1546 EXPECT_FALSE(info.is_direct()); |
1542 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1547 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1543 | 1548 |
1544 // Fake a proxy error. | 1549 // Fake a proxy error. |
1545 TestCompletionCallback callback2; | 1550 TestCompletionCallback callback2; |
1546 rv = service.ReconsiderProxyAfterError( | 1551 rv = service.ReconsiderProxyAfterError( |
1547 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1552 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1548 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1553 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
1549 EXPECT_EQ(OK, rv); | 1554 EXPECT_THAT(rv, IsOk()); |
1550 | 1555 |
1551 // The first proxy is ignored, and the second one is selected. | 1556 // The first proxy is ignored, and the second one is selected. |
1552 EXPECT_FALSE(info.is_direct()); | 1557 EXPECT_FALSE(info.is_direct()); |
1553 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1558 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1554 | 1559 |
1555 // Fake a PAC failure. | 1560 // Fake a PAC failure. |
1556 ProxyInfo info2; | 1561 ProxyInfo info2; |
1557 TestCompletionCallback callback3; | 1562 TestCompletionCallback callback3; |
1558 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info2, | 1563 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info2, |
1559 callback3.callback(), nullptr, nullptr, | 1564 callback3.callback(), nullptr, nullptr, |
1560 BoundNetLog()); | 1565 BoundNetLog()); |
1561 EXPECT_EQ(ERR_IO_PENDING, rv); | 1566 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1562 | 1567 |
1563 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1568 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1564 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1569 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1565 | 1570 |
1566 // This simulates a javascript runtime error in the PAC script. | 1571 // This simulates a javascript runtime error in the PAC script. |
1567 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1572 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1568 | 1573 |
1569 // Although the resolver failed, the ProxyService will implicitly fall-back | 1574 // Although the resolver failed, the ProxyService will implicitly fall-back |
1570 // to a DIRECT connection. | 1575 // to a DIRECT connection. |
1571 EXPECT_EQ(OK, callback3.WaitForResult()); | 1576 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
1572 EXPECT_TRUE(info2.is_direct()); | 1577 EXPECT_TRUE(info2.is_direct()); |
1573 EXPECT_FALSE(info2.is_empty()); | 1578 EXPECT_FALSE(info2.is_empty()); |
1574 | 1579 |
1575 // The PAC script will work properly next time and successfully return a | 1580 // The PAC script will work properly next time and successfully return a |
1576 // proxy list. Since we have not marked the configuration as bad, it should | 1581 // proxy list. Since we have not marked the configuration as bad, it should |
1577 // "just work" the next time we call it. | 1582 // "just work" the next time we call it. |
1578 ProxyInfo info3; | 1583 ProxyInfo info3; |
1579 TestCompletionCallback callback4; | 1584 TestCompletionCallback callback4; |
1580 rv = service.ReconsiderProxyAfterError( | 1585 rv = service.ReconsiderProxyAfterError( |
1581 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, | 1586 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, |
1582 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1587 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
1583 EXPECT_EQ(ERR_IO_PENDING, rv); | 1588 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1584 | 1589 |
1585 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1590 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1586 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1591 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1587 | 1592 |
1588 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1593 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1589 "foopy1:8080;foopy2:9090"); | 1594 "foopy1:8080;foopy2:9090"); |
1590 resolver.pending_requests()[0]->CompleteNow(OK); | 1595 resolver.pending_requests()[0]->CompleteNow(OK); |
1591 | 1596 |
1592 // The first proxy is not there since the it was added to the bad proxies | 1597 // The first proxy is not there since the it was added to the bad proxies |
1593 // list by the earlier ReconsiderProxyAfterError(). | 1598 // list by the earlier ReconsiderProxyAfterError(). |
1594 EXPECT_EQ(OK, callback4.WaitForResult()); | 1599 EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
1595 EXPECT_FALSE(info3.is_direct()); | 1600 EXPECT_FALSE(info3.is_direct()); |
1596 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 1601 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
1597 | 1602 |
1598 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1603 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1599 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1604 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1600 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1605 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1601 } | 1606 } |
1602 | 1607 |
1603 TEST_F(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { | 1608 TEST_F(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { |
1604 // Test proxy failover when the configuration is bad. | 1609 // Test proxy failover when the configuration is bad. |
(...skipping 12 matching lines...) Expand all Loading... |
1617 base::WrapUnique(factory), nullptr); | 1622 base::WrapUnique(factory), nullptr); |
1618 | 1623 |
1619 GURL url("http://www.google.com/"); | 1624 GURL url("http://www.google.com/"); |
1620 | 1625 |
1621 // Get the proxy information. | 1626 // Get the proxy information. |
1622 ProxyInfo info; | 1627 ProxyInfo info; |
1623 TestCompletionCallback callback1; | 1628 TestCompletionCallback callback1; |
1624 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 1629 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
1625 callback1.callback(), nullptr, nullptr, | 1630 callback1.callback(), nullptr, nullptr, |
1626 BoundNetLog()); | 1631 BoundNetLog()); |
1627 EXPECT_EQ(ERR_IO_PENDING, rv); | 1632 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1628 | 1633 |
1629 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1634 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1630 factory->pending_requests()[0]->script_data()->url()); | 1635 factory->pending_requests()[0]->script_data()->url()); |
1631 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1636 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1632 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1637 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1633 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1638 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1634 | 1639 |
1635 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1640 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1636 "foopy1:8080;foopy2:9090"); | 1641 "foopy1:8080;foopy2:9090"); |
1637 resolver.pending_requests()[0]->CompleteNow(OK); | 1642 resolver.pending_requests()[0]->CompleteNow(OK); |
1638 | 1643 |
1639 // The first item is valid. | 1644 // The first item is valid. |
1640 EXPECT_EQ(OK, callback1.WaitForResult()); | 1645 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1641 EXPECT_FALSE(info.is_direct()); | 1646 EXPECT_FALSE(info.is_direct()); |
1642 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1647 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1643 | 1648 |
1644 // Fake a proxy error. | 1649 // Fake a proxy error. |
1645 TestCompletionCallback callback2; | 1650 TestCompletionCallback callback2; |
1646 rv = service.ReconsiderProxyAfterError( | 1651 rv = service.ReconsiderProxyAfterError( |
1647 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1652 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1648 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1653 callback2.callback(), nullptr, nullptr, BoundNetLog()); |
1649 EXPECT_EQ(OK, rv); | 1654 EXPECT_THAT(rv, IsOk()); |
1650 | 1655 |
1651 // The first proxy is ignored, and the second one is selected. | 1656 // The first proxy is ignored, and the second one is selected. |
1652 EXPECT_FALSE(info.is_direct()); | 1657 EXPECT_FALSE(info.is_direct()); |
1653 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1658 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1654 | 1659 |
1655 // Fake a PAC failure. | 1660 // Fake a PAC failure. |
1656 ProxyInfo info2; | 1661 ProxyInfo info2; |
1657 TestCompletionCallback callback3; | 1662 TestCompletionCallback callback3; |
1658 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info2, | 1663 rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info2, |
1659 callback3.callback(), nullptr, nullptr, | 1664 callback3.callback(), nullptr, nullptr, |
1660 BoundNetLog()); | 1665 BoundNetLog()); |
1661 EXPECT_EQ(ERR_IO_PENDING, rv); | 1666 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1662 | 1667 |
1663 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1668 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1664 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1669 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1665 | 1670 |
1666 // This simulates a javascript runtime error in the PAC script. | 1671 // This simulates a javascript runtime error in the PAC script. |
1667 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1672 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1668 | 1673 |
1669 // Although the resolver failed, the ProxyService will NOT fall-back | 1674 // Although the resolver failed, the ProxyService will NOT fall-back |
1670 // to a DIRECT connection as it is configured as mandatory. | 1675 // to a DIRECT connection as it is configured as mandatory. |
1671 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1676 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1672 callback3.WaitForResult()); | 1677 callback3.WaitForResult()); |
1673 EXPECT_FALSE(info2.is_direct()); | 1678 EXPECT_FALSE(info2.is_direct()); |
1674 EXPECT_TRUE(info2.is_empty()); | 1679 EXPECT_TRUE(info2.is_empty()); |
1675 | 1680 |
1676 // The PAC script will work properly next time and successfully return a | 1681 // The PAC script will work properly next time and successfully return a |
1677 // proxy list. Since we have not marked the configuration as bad, it should | 1682 // proxy list. Since we have not marked the configuration as bad, it should |
1678 // "just work" the next time we call it. | 1683 // "just work" the next time we call it. |
1679 ProxyInfo info3; | 1684 ProxyInfo info3; |
1680 TestCompletionCallback callback4; | 1685 TestCompletionCallback callback4; |
1681 rv = service.ReconsiderProxyAfterError( | 1686 rv = service.ReconsiderProxyAfterError( |
1682 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, | 1687 url, std::string(), LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, |
1683 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1688 callback4.callback(), nullptr, nullptr, BoundNetLog()); |
1684 EXPECT_EQ(ERR_IO_PENDING, rv); | 1689 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1685 | 1690 |
1686 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1691 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1687 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1692 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1688 | 1693 |
1689 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1694 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1690 "foopy1:8080;foopy2:9090"); | 1695 "foopy1:8080;foopy2:9090"); |
1691 resolver.pending_requests()[0]->CompleteNow(OK); | 1696 resolver.pending_requests()[0]->CompleteNow(OK); |
1692 | 1697 |
1693 // The first proxy is not there since the it was added to the bad proxies | 1698 // The first proxy is not there since the it was added to the bad proxies |
1694 // list by the earlier ReconsiderProxyAfterError(). | 1699 // list by the earlier ReconsiderProxyAfterError(). |
1695 EXPECT_EQ(OK, callback4.WaitForResult()); | 1700 EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
1696 EXPECT_FALSE(info3.is_direct()); | 1701 EXPECT_FALSE(info3.is_direct()); |
1697 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 1702 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
1698 } | 1703 } |
1699 | 1704 |
1700 TEST_F(ProxyServiceTest, ProxyBypassList) { | 1705 TEST_F(ProxyServiceTest, ProxyBypassList) { |
1701 // Test that the proxy bypass rules are consulted. | 1706 // Test that the proxy bypass rules are consulted. |
1702 | 1707 |
1703 TestCompletionCallback callback[2]; | 1708 TestCompletionCallback callback[2]; |
1704 ProxyInfo info[2]; | 1709 ProxyInfo info[2]; |
1705 ProxyConfig config; | 1710 ProxyConfig config; |
1706 config.proxy_rules().ParseFromString("foopy1:8080;foopy2:9090"); | 1711 config.proxy_rules().ParseFromString("foopy1:8080;foopy2:9090"); |
1707 config.set_auto_detect(false); | 1712 config.set_auto_detect(false); |
1708 config.proxy_rules().bypass_rules.ParseFromString("*.org"); | 1713 config.proxy_rules().bypass_rules.ParseFromString("*.org"); |
1709 | 1714 |
1710 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1715 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1711 nullptr, nullptr); | 1716 nullptr, nullptr); |
1712 | 1717 |
1713 int rv; | 1718 int rv; |
1714 GURL url1("http://www.webkit.org"); | 1719 GURL url1("http://www.webkit.org"); |
1715 GURL url2("http://www.webkit.com"); | 1720 GURL url2("http://www.webkit.com"); |
1716 | 1721 |
1717 // Request for a .org domain should bypass proxy. | 1722 // Request for a .org domain should bypass proxy. |
1718 rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info[0], | 1723 rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info[0], |
1719 callback[0].callback(), nullptr, nullptr, | 1724 callback[0].callback(), nullptr, nullptr, |
1720 BoundNetLog()); | 1725 BoundNetLog()); |
1721 EXPECT_EQ(OK, rv); | 1726 EXPECT_THAT(rv, IsOk()); |
1722 EXPECT_TRUE(info[0].is_direct()); | 1727 EXPECT_TRUE(info[0].is_direct()); |
1723 | 1728 |
1724 // Request for a .com domain hits the proxy. | 1729 // Request for a .com domain hits the proxy. |
1725 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info[1], | 1730 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info[1], |
1726 callback[1].callback(), nullptr, nullptr, | 1731 callback[1].callback(), nullptr, nullptr, |
1727 BoundNetLog()); | 1732 BoundNetLog()); |
1728 EXPECT_EQ(OK, rv); | 1733 EXPECT_THAT(rv, IsOk()); |
1729 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1734 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
1730 } | 1735 } |
1731 | 1736 |
1732 TEST_F(ProxyServiceTest, MarkProxiesAsBadTests) { | 1737 TEST_F(ProxyServiceTest, MarkProxiesAsBadTests) { |
1733 ProxyConfig config; | 1738 ProxyConfig config; |
1734 config.proxy_rules().ParseFromString( | 1739 config.proxy_rules().ParseFromString( |
1735 "http=foopy1:8080;http=foopy2:8080;http=foopy3.8080;http=foopy4:8080"); | 1740 "http=foopy1:8080;http=foopy2:8080;http=foopy3.8080;http=foopy4:8080"); |
1736 config.set_auto_detect(false); | 1741 config.set_auto_detect(false); |
1737 | 1742 |
1738 ProxyList proxy_list; | 1743 ProxyList proxy_list; |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1770 config.set_auto_detect(false); | 1775 config.set_auto_detect(false); |
1771 { | 1776 { |
1772 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1777 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1773 nullptr, nullptr); | 1778 nullptr, nullptr); |
1774 GURL test_url("http://www.msn.com"); | 1779 GURL test_url("http://www.msn.com"); |
1775 ProxyInfo info; | 1780 ProxyInfo info; |
1776 TestCompletionCallback callback; | 1781 TestCompletionCallback callback; |
1777 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1782 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1778 callback.callback(), nullptr, nullptr, | 1783 callback.callback(), nullptr, nullptr, |
1779 BoundNetLog()); | 1784 BoundNetLog()); |
1780 EXPECT_EQ(OK, rv); | 1785 EXPECT_THAT(rv, IsOk()); |
1781 EXPECT_FALSE(info.is_direct()); | 1786 EXPECT_FALSE(info.is_direct()); |
1782 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1787 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1783 } | 1788 } |
1784 { | 1789 { |
1785 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1790 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1786 nullptr, nullptr); | 1791 nullptr, nullptr); |
1787 GURL test_url("ftp://ftp.google.com"); | 1792 GURL test_url("ftp://ftp.google.com"); |
1788 ProxyInfo info; | 1793 ProxyInfo info; |
1789 TestCompletionCallback callback; | 1794 TestCompletionCallback callback; |
1790 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1795 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1791 callback.callback(), nullptr, nullptr, | 1796 callback.callback(), nullptr, nullptr, |
1792 BoundNetLog()); | 1797 BoundNetLog()); |
1793 EXPECT_EQ(OK, rv); | 1798 EXPECT_THAT(rv, IsOk()); |
1794 EXPECT_TRUE(info.is_direct()); | 1799 EXPECT_TRUE(info.is_direct()); |
1795 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 1800 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
1796 } | 1801 } |
1797 { | 1802 { |
1798 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1803 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1799 nullptr, nullptr); | 1804 nullptr, nullptr); |
1800 GURL test_url("https://webbranch.techcu.com"); | 1805 GURL test_url("https://webbranch.techcu.com"); |
1801 ProxyInfo info; | 1806 ProxyInfo info; |
1802 TestCompletionCallback callback; | 1807 TestCompletionCallback callback; |
1803 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1808 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1804 callback.callback(), nullptr, nullptr, | 1809 callback.callback(), nullptr, nullptr, |
1805 BoundNetLog()); | 1810 BoundNetLog()); |
1806 EXPECT_EQ(OK, rv); | 1811 EXPECT_THAT(rv, IsOk()); |
1807 EXPECT_FALSE(info.is_direct()); | 1812 EXPECT_FALSE(info.is_direct()); |
1808 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1813 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1809 } | 1814 } |
1810 { | 1815 { |
1811 config.proxy_rules().ParseFromString("foopy1:8080"); | 1816 config.proxy_rules().ParseFromString("foopy1:8080"); |
1812 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1817 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1813 nullptr, nullptr); | 1818 nullptr, nullptr); |
1814 GURL test_url("http://www.microsoft.com"); | 1819 GURL test_url("http://www.microsoft.com"); |
1815 ProxyInfo info; | 1820 ProxyInfo info; |
1816 TestCompletionCallback callback; | 1821 TestCompletionCallback callback; |
1817 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1822 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1818 callback.callback(), nullptr, nullptr, | 1823 callback.callback(), nullptr, nullptr, |
1819 BoundNetLog()); | 1824 BoundNetLog()); |
1820 EXPECT_EQ(OK, rv); | 1825 EXPECT_THAT(rv, IsOk()); |
1821 EXPECT_FALSE(info.is_direct()); | 1826 EXPECT_FALSE(info.is_direct()); |
1822 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1827 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1823 } | 1828 } |
1824 } | 1829 } |
1825 | 1830 |
1826 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { | 1831 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { |
1827 // Test that the proxy config source is set correctly when resolving proxies | 1832 // Test that the proxy config source is set correctly when resolving proxies |
1828 // using manual proxy rules. Namely, the config source should only be set if | 1833 // using manual proxy rules. Namely, the config source should only be set if |
1829 // any of the rules were applied. | 1834 // any of the rules were applied. |
1830 { | 1835 { |
1831 ProxyConfig config; | 1836 ProxyConfig config; |
1832 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1837 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1833 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1838 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1834 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1839 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1835 nullptr, nullptr); | 1840 nullptr, nullptr); |
1836 GURL test_url("http://www.google.com"); | 1841 GURL test_url("http://www.google.com"); |
1837 ProxyInfo info; | 1842 ProxyInfo info; |
1838 TestCompletionCallback callback; | 1843 TestCompletionCallback callback; |
1839 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1844 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1840 callback.callback(), nullptr, nullptr, | 1845 callback.callback(), nullptr, nullptr, |
1841 BoundNetLog()); | 1846 BoundNetLog()); |
1842 ASSERT_EQ(OK, rv); | 1847 ASSERT_THAT(rv, IsOk()); |
1843 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. | 1848 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. |
1844 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1849 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1845 } | 1850 } |
1846 { | 1851 { |
1847 ProxyConfig config; | 1852 ProxyConfig config; |
1848 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1853 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1849 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1854 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1850 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1855 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1851 nullptr, nullptr); | 1856 nullptr, nullptr); |
1852 GURL test_url("https://www.google.com"); | 1857 GURL test_url("https://www.google.com"); |
1853 ProxyInfo info; | 1858 ProxyInfo info; |
1854 TestCompletionCallback callback; | 1859 TestCompletionCallback callback; |
1855 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1860 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1856 callback.callback(), nullptr, nullptr, | 1861 callback.callback(), nullptr, nullptr, |
1857 BoundNetLog()); | 1862 BoundNetLog()); |
1858 ASSERT_EQ(OK, rv); | 1863 ASSERT_THAT(rv, IsOk()); |
1859 // Used the HTTPS proxy. So source should be TEST. | 1864 // Used the HTTPS proxy. So source should be TEST. |
1860 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1865 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1861 } | 1866 } |
1862 { | 1867 { |
1863 ProxyConfig config; | 1868 ProxyConfig config; |
1864 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1869 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1865 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1870 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1866 nullptr, nullptr); | 1871 nullptr, nullptr); |
1867 GURL test_url("http://www.google.com"); | 1872 GURL test_url("http://www.google.com"); |
1868 ProxyInfo info; | 1873 ProxyInfo info; |
1869 TestCompletionCallback callback; | 1874 TestCompletionCallback callback; |
1870 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1875 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1871 callback.callback(), nullptr, nullptr, | 1876 callback.callback(), nullptr, nullptr, |
1872 BoundNetLog()); | 1877 BoundNetLog()); |
1873 ASSERT_EQ(OK, rv); | 1878 ASSERT_THAT(rv, IsOk()); |
1874 // ProxyConfig is empty. Source should still be TEST. | 1879 // ProxyConfig is empty. Source should still be TEST. |
1875 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1880 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1876 } | 1881 } |
1877 } | 1882 } |
1878 | 1883 |
1879 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1884 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
1880 // fall back to the SOCKS proxy. | 1885 // fall back to the SOCKS proxy. |
1881 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1886 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
1882 ProxyConfig config; | 1887 ProxyConfig config; |
1883 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1888 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
1884 config.set_auto_detect(false); | 1889 config.set_auto_detect(false); |
1885 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1890 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
1886 config.proxy_rules().type); | 1891 config.proxy_rules().type); |
1887 | 1892 |
1888 { | 1893 { |
1889 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1894 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1890 nullptr, nullptr); | 1895 nullptr, nullptr); |
1891 GURL test_url("http://www.msn.com"); | 1896 GURL test_url("http://www.msn.com"); |
1892 ProxyInfo info; | 1897 ProxyInfo info; |
1893 TestCompletionCallback callback; | 1898 TestCompletionCallback callback; |
1894 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1899 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1895 callback.callback(), nullptr, nullptr, | 1900 callback.callback(), nullptr, nullptr, |
1896 BoundNetLog()); | 1901 BoundNetLog()); |
1897 EXPECT_EQ(OK, rv); | 1902 EXPECT_THAT(rv, IsOk()); |
1898 EXPECT_FALSE(info.is_direct()); | 1903 EXPECT_FALSE(info.is_direct()); |
1899 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1904 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1900 } | 1905 } |
1901 { | 1906 { |
1902 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1907 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1903 nullptr, nullptr); | 1908 nullptr, nullptr); |
1904 GURL test_url("ftp://ftp.google.com"); | 1909 GURL test_url("ftp://ftp.google.com"); |
1905 ProxyInfo info; | 1910 ProxyInfo info; |
1906 TestCompletionCallback callback; | 1911 TestCompletionCallback callback; |
1907 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1912 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1908 callback.callback(), nullptr, nullptr, | 1913 callback.callback(), nullptr, nullptr, |
1909 BoundNetLog()); | 1914 BoundNetLog()); |
1910 EXPECT_EQ(OK, rv); | 1915 EXPECT_THAT(rv, IsOk()); |
1911 EXPECT_FALSE(info.is_direct()); | 1916 EXPECT_FALSE(info.is_direct()); |
1912 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1917 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1913 } | 1918 } |
1914 { | 1919 { |
1915 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1920 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1916 nullptr, nullptr); | 1921 nullptr, nullptr); |
1917 GURL test_url("https://webbranch.techcu.com"); | 1922 GURL test_url("https://webbranch.techcu.com"); |
1918 ProxyInfo info; | 1923 ProxyInfo info; |
1919 TestCompletionCallback callback; | 1924 TestCompletionCallback callback; |
1920 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1925 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1921 callback.callback(), nullptr, nullptr, | 1926 callback.callback(), nullptr, nullptr, |
1922 BoundNetLog()); | 1927 BoundNetLog()); |
1923 EXPECT_EQ(OK, rv); | 1928 EXPECT_THAT(rv, IsOk()); |
1924 EXPECT_FALSE(info.is_direct()); | 1929 EXPECT_FALSE(info.is_direct()); |
1925 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1930 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1926 } | 1931 } |
1927 { | 1932 { |
1928 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1933 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1929 nullptr, nullptr); | 1934 nullptr, nullptr); |
1930 GURL test_url("unknown://www.microsoft.com"); | 1935 GURL test_url("unknown://www.microsoft.com"); |
1931 ProxyInfo info; | 1936 ProxyInfo info; |
1932 TestCompletionCallback callback; | 1937 TestCompletionCallback callback; |
1933 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, | 1938 int rv = service.ResolveProxy(test_url, std::string(), LOAD_NORMAL, &info, |
1934 callback.callback(), nullptr, nullptr, | 1939 callback.callback(), nullptr, nullptr, |
1935 BoundNetLog()); | 1940 BoundNetLog()); |
1936 EXPECT_EQ(OK, rv); | 1941 EXPECT_THAT(rv, IsOk()); |
1937 EXPECT_FALSE(info.is_direct()); | 1942 EXPECT_FALSE(info.is_direct()); |
1938 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1943 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1939 } | 1944 } |
1940 } | 1945 } |
1941 | 1946 |
1942 // Test cancellation of an in-progress request. | 1947 // Test cancellation of an in-progress request. |
1943 TEST_F(ProxyServiceTest, CancelInProgressRequest) { | 1948 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
1944 const GURL url1("http://request1"); | 1949 const GURL url1("http://request1"); |
1945 const GURL url2("http://request2"); | 1950 const GURL url2("http://request2"); |
1946 const GURL url3("http://request3"); | 1951 const GURL url3("http://request3"); |
1947 MockProxyConfigService* config_service = | 1952 MockProxyConfigService* config_service = |
1948 new MockProxyConfigService("http://foopy/proxy.pac"); | 1953 new MockProxyConfigService("http://foopy/proxy.pac"); |
1949 | 1954 |
1950 MockAsyncProxyResolver resolver; | 1955 MockAsyncProxyResolver resolver; |
1951 MockAsyncProxyResolverFactory* factory = | 1956 MockAsyncProxyResolverFactory* factory = |
1952 new MockAsyncProxyResolverFactory(false); | 1957 new MockAsyncProxyResolverFactory(false); |
1953 | 1958 |
1954 ProxyService service(base::WrapUnique(config_service), | 1959 ProxyService service(base::WrapUnique(config_service), |
1955 base::WrapUnique(factory), nullptr); | 1960 base::WrapUnique(factory), nullptr); |
1956 | 1961 |
1957 // Start 3 requests. | 1962 // Start 3 requests. |
1958 | 1963 |
1959 ProxyInfo info1; | 1964 ProxyInfo info1; |
1960 TestCompletionCallback callback1; | 1965 TestCompletionCallback callback1; |
1961 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 1966 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, |
1962 callback1.callback(), nullptr, nullptr, | 1967 callback1.callback(), nullptr, nullptr, |
1963 BoundNetLog()); | 1968 BoundNetLog()); |
1964 EXPECT_EQ(ERR_IO_PENDING, rv); | 1969 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1965 | 1970 |
1966 // Successfully initialize the PAC script. | 1971 // Successfully initialize the PAC script. |
1967 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1972 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1968 factory->pending_requests()[0]->script_data()->url()); | 1973 factory->pending_requests()[0]->script_data()->url()); |
1969 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1974 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1970 | 1975 |
1971 GetPendingRequestsForURLs(resolver, url1); | 1976 GetPendingRequestsForURLs(resolver, url1); |
1972 | 1977 |
1973 ProxyInfo info2; | 1978 ProxyInfo info2; |
1974 TestCompletionCallback callback2; | 1979 TestCompletionCallback callback2; |
1975 ProxyService::PacRequest* request2; | 1980 ProxyService::PacRequest* request2; |
1976 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 1981 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, |
1977 callback2.callback(), &request2, nullptr, | 1982 callback2.callback(), &request2, nullptr, |
1978 BoundNetLog()); | 1983 BoundNetLog()); |
1979 EXPECT_EQ(ERR_IO_PENDING, rv); | 1984 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1980 | 1985 |
1981 GetPendingRequestsForURLs(resolver, url1, url2); | 1986 GetPendingRequestsForURLs(resolver, url1, url2); |
1982 | 1987 |
1983 ProxyInfo info3; | 1988 ProxyInfo info3; |
1984 TestCompletionCallback callback3; | 1989 TestCompletionCallback callback3; |
1985 rv = service.ResolveProxy(url3, std::string(), LOAD_NORMAL, &info3, | 1990 rv = service.ResolveProxy(url3, std::string(), LOAD_NORMAL, &info3, |
1986 callback3.callback(), nullptr, nullptr, | 1991 callback3.callback(), nullptr, nullptr, |
1987 BoundNetLog()); | 1992 BoundNetLog()); |
1988 EXPECT_EQ(ERR_IO_PENDING, rv); | 1993 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1989 GetPendingRequestsForURLs(resolver, url1, url2, url3); | 1994 GetPendingRequestsForURLs(resolver, url1, url2, url3); |
1990 | 1995 |
1991 // Cancel the second request | 1996 // Cancel the second request |
1992 service.CancelPacRequest(request2); | 1997 service.CancelPacRequest(request2); |
1993 | 1998 |
1994 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); | 1999 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); |
1995 | 2000 |
1996 // Complete the two un-cancelled requests. | 2001 // Complete the two un-cancelled requests. |
1997 // We complete the last one first, just to mix it up a bit. | 2002 // We complete the last one first, just to mix it up a bit. |
1998 requests[url3]->results()->UseNamedProxy("request3:80"); | 2003 requests[url3]->results()->UseNamedProxy("request3:80"); |
1999 requests[url3]->CompleteNow(OK); | 2004 requests[url3]->CompleteNow(OK); |
2000 | 2005 |
2001 requests[url1]->results()->UseNamedProxy("request1:80"); | 2006 requests[url1]->results()->UseNamedProxy("request1:80"); |
2002 requests[url1]->CompleteNow(OK); | 2007 requests[url1]->CompleteNow(OK); |
2003 | 2008 |
2004 // Complete and verify that requests ran as expected. | 2009 // Complete and verify that requests ran as expected. |
2005 EXPECT_EQ(OK, callback1.WaitForResult()); | 2010 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2006 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2011 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2007 | 2012 |
2008 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 2013 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
2009 GetCancelledRequestsForURLs(resolver, url2); | 2014 GetCancelledRequestsForURLs(resolver, url2); |
2010 | 2015 |
2011 EXPECT_EQ(OK, callback3.WaitForResult()); | 2016 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
2012 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 2017 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
2013 } | 2018 } |
2014 | 2019 |
2015 // Test the initial PAC download for resolver that expects bytes. | 2020 // Test the initial PAC download for resolver that expects bytes. |
2016 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { | 2021 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { |
2017 const GURL url1("http://request1"); | 2022 const GURL url1("http://request1"); |
2018 const GURL url2("http://request2"); | 2023 const GURL url2("http://request2"); |
2019 const GURL url3("http://request3"); | 2024 const GURL url3("http://request3"); |
2020 MockProxyConfigService* config_service = | 2025 MockProxyConfigService* config_service = |
2021 new MockProxyConfigService("http://foopy/proxy.pac"); | 2026 new MockProxyConfigService("http://foopy/proxy.pac"); |
(...skipping 10 matching lines...) Expand all Loading... |
2032 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2037 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2033 | 2038 |
2034 // Start 3 requests. | 2039 // Start 3 requests. |
2035 | 2040 |
2036 ProxyInfo info1; | 2041 ProxyInfo info1; |
2037 TestCompletionCallback callback1; | 2042 TestCompletionCallback callback1; |
2038 ProxyService::PacRequest* request1; | 2043 ProxyService::PacRequest* request1; |
2039 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 2044 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, |
2040 callback1.callback(), &request1, nullptr, | 2045 callback1.callback(), &request1, nullptr, |
2041 BoundNetLog()); | 2046 BoundNetLog()); |
2042 EXPECT_EQ(ERR_IO_PENDING, rv); | 2047 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2043 | 2048 |
2044 // The first request should have triggered download of PAC script. | 2049 // The first request should have triggered download of PAC script. |
2045 EXPECT_TRUE(fetcher->has_pending_request()); | 2050 EXPECT_TRUE(fetcher->has_pending_request()); |
2046 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2051 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2047 | 2052 |
2048 ProxyInfo info2; | 2053 ProxyInfo info2; |
2049 TestCompletionCallback callback2; | 2054 TestCompletionCallback callback2; |
2050 ProxyService::PacRequest* request2; | 2055 ProxyService::PacRequest* request2; |
2051 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 2056 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, |
2052 callback2.callback(), &request2, nullptr, | 2057 callback2.callback(), &request2, nullptr, |
2053 BoundNetLog()); | 2058 BoundNetLog()); |
2054 EXPECT_EQ(ERR_IO_PENDING, rv); | 2059 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2055 | 2060 |
2056 ProxyInfo info3; | 2061 ProxyInfo info3; |
2057 TestCompletionCallback callback3; | 2062 TestCompletionCallback callback3; |
2058 ProxyService::PacRequest* request3; | 2063 ProxyService::PacRequest* request3; |
2059 rv = service.ResolveProxy(url3, std::string(), LOAD_NORMAL, &info3, | 2064 rv = service.ResolveProxy(url3, std::string(), LOAD_NORMAL, &info3, |
2060 callback3.callback(), &request3, nullptr, | 2065 callback3.callback(), &request3, nullptr, |
2061 BoundNetLog()); | 2066 BoundNetLog()); |
2062 EXPECT_EQ(ERR_IO_PENDING, rv); | 2067 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2063 | 2068 |
2064 // Nothing has been sent to the factory yet. | 2069 // Nothing has been sent to the factory yet. |
2065 EXPECT_TRUE(factory->pending_requests().empty()); | 2070 EXPECT_TRUE(factory->pending_requests().empty()); |
2066 | 2071 |
2067 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2072 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
2068 service.GetLoadState(request1)); | 2073 service.GetLoadState(request1)); |
2069 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2074 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
2070 service.GetLoadState(request2)); | 2075 service.GetLoadState(request2)); |
2071 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2076 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
2072 service.GetLoadState(request3)); | 2077 service.GetLoadState(request3)); |
(...skipping 20 matching lines...) Expand all Loading... |
2093 requests[url3]->results()->UseNamedProxy("request3:80"); | 2098 requests[url3]->results()->UseNamedProxy("request3:80"); |
2094 requests[url3]->CompleteNow(OK); | 2099 requests[url3]->CompleteNow(OK); |
2095 | 2100 |
2096 requests[url1]->results()->UseNamedProxy("request1:80"); | 2101 requests[url1]->results()->UseNamedProxy("request1:80"); |
2097 requests[url1]->CompleteNow(OK); | 2102 requests[url1]->CompleteNow(OK); |
2098 | 2103 |
2099 requests[url2]->results()->UseNamedProxy("request2:80"); | 2104 requests[url2]->results()->UseNamedProxy("request2:80"); |
2100 requests[url2]->CompleteNow(OK); | 2105 requests[url2]->CompleteNow(OK); |
2101 | 2106 |
2102 // Complete and verify that requests ran as expected. | 2107 // Complete and verify that requests ran as expected. |
2103 EXPECT_EQ(OK, callback1.WaitForResult()); | 2108 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2104 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2109 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2105 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); | 2110 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); |
2106 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); | 2111 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); |
2107 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); | 2112 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); |
2108 | 2113 |
2109 EXPECT_EQ(OK, callback2.WaitForResult()); | 2114 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2110 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2115 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2111 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); | 2116 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); |
2112 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); | 2117 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); |
2113 EXPECT_LE(info2.proxy_resolve_start_time(), info2.proxy_resolve_end_time()); | 2118 EXPECT_LE(info2.proxy_resolve_start_time(), info2.proxy_resolve_end_time()); |
2114 | 2119 |
2115 EXPECT_EQ(OK, callback3.WaitForResult()); | 2120 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
2116 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 2121 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
2117 EXPECT_FALSE(info3.proxy_resolve_start_time().is_null()); | 2122 EXPECT_FALSE(info3.proxy_resolve_start_time().is_null()); |
2118 EXPECT_FALSE(info3.proxy_resolve_end_time().is_null()); | 2123 EXPECT_FALSE(info3.proxy_resolve_end_time().is_null()); |
2119 EXPECT_LE(info3.proxy_resolve_start_time(), info3.proxy_resolve_end_time()); | 2124 EXPECT_LE(info3.proxy_resolve_start_time(), info3.proxy_resolve_end_time()); |
2120 } | 2125 } |
2121 | 2126 |
2122 // Test changing the ProxyScriptFetcher while PAC download is in progress. | 2127 // Test changing the ProxyScriptFetcher while PAC download is in progress. |
2123 TEST_F(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { | 2128 TEST_F(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { |
2124 const GURL url1("http://request1"); | 2129 const GURL url1("http://request1"); |
2125 const GURL url2("http://request2"); | 2130 const GURL url2("http://request2"); |
(...skipping 11 matching lines...) Expand all Loading... |
2137 service.SetProxyScriptFetchers( | 2142 service.SetProxyScriptFetchers( |
2138 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2143 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2139 | 2144 |
2140 // Start 2 requests. | 2145 // Start 2 requests. |
2141 | 2146 |
2142 ProxyInfo info1; | 2147 ProxyInfo info1; |
2143 TestCompletionCallback callback1; | 2148 TestCompletionCallback callback1; |
2144 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 2149 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, |
2145 callback1.callback(), nullptr, nullptr, | 2150 callback1.callback(), nullptr, nullptr, |
2146 BoundNetLog()); | 2151 BoundNetLog()); |
2147 EXPECT_EQ(ERR_IO_PENDING, rv); | 2152 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2148 | 2153 |
2149 // The first request should have triggered download of PAC script. | 2154 // The first request should have triggered download of PAC script. |
2150 EXPECT_TRUE(fetcher->has_pending_request()); | 2155 EXPECT_TRUE(fetcher->has_pending_request()); |
2151 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2156 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2152 | 2157 |
2153 ProxyInfo info2; | 2158 ProxyInfo info2; |
2154 TestCompletionCallback callback2; | 2159 TestCompletionCallback callback2; |
2155 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 2160 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, |
2156 callback2.callback(), nullptr, nullptr, | 2161 callback2.callback(), nullptr, nullptr, |
2157 BoundNetLog()); | 2162 BoundNetLog()); |
2158 EXPECT_EQ(ERR_IO_PENDING, rv); | 2163 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2159 | 2164 |
2160 // At this point the ProxyService should be waiting for the | 2165 // At this point the ProxyService should be waiting for the |
2161 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2166 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2162 // PAC script download completion. | 2167 // PAC script download completion. |
2163 | 2168 |
2164 // We now change out the ProxyService's script fetcher. We should restart | 2169 // We now change out the ProxyService's script fetcher. We should restart |
2165 // the initialization with the new fetcher. | 2170 // the initialization with the new fetcher. |
2166 | 2171 |
2167 fetcher = new MockProxyScriptFetcher; | 2172 fetcher = new MockProxyScriptFetcher; |
2168 service.SetProxyScriptFetchers( | 2173 service.SetProxyScriptFetchers( |
(...skipping 30 matching lines...) Expand all Loading... |
2199 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2204 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2200 | 2205 |
2201 // Start 3 requests. | 2206 // Start 3 requests. |
2202 ProxyInfo info1; | 2207 ProxyInfo info1; |
2203 TestCompletionCallback callback1; | 2208 TestCompletionCallback callback1; |
2204 ProxyService::PacRequest* request1; | 2209 ProxyService::PacRequest* request1; |
2205 BoundTestNetLog log1; | 2210 BoundTestNetLog log1; |
2206 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2211 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
2207 LOAD_NORMAL, &info1, callback1.callback(), | 2212 LOAD_NORMAL, &info1, callback1.callback(), |
2208 &request1, nullptr, log1.bound()); | 2213 &request1, nullptr, log1.bound()); |
2209 EXPECT_EQ(ERR_IO_PENDING, rv); | 2214 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2210 | 2215 |
2211 // The first request should have triggered download of PAC script. | 2216 // The first request should have triggered download of PAC script. |
2212 EXPECT_TRUE(fetcher->has_pending_request()); | 2217 EXPECT_TRUE(fetcher->has_pending_request()); |
2213 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2218 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2214 | 2219 |
2215 ProxyInfo info2; | 2220 ProxyInfo info2; |
2216 TestCompletionCallback callback2; | 2221 TestCompletionCallback callback2; |
2217 ProxyService::PacRequest* request2; | 2222 ProxyService::PacRequest* request2; |
2218 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2223 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
2219 &info2, callback2.callback(), &request2, nullptr, | 2224 &info2, callback2.callback(), &request2, nullptr, |
2220 BoundNetLog()); | 2225 BoundNetLog()); |
2221 EXPECT_EQ(ERR_IO_PENDING, rv); | 2226 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2222 | 2227 |
2223 ProxyInfo info3; | 2228 ProxyInfo info3; |
2224 TestCompletionCallback callback3; | 2229 TestCompletionCallback callback3; |
2225 rv = service.ResolveProxy(GURL("http://request3"), std::string(), LOAD_NORMAL, | 2230 rv = service.ResolveProxy(GURL("http://request3"), std::string(), LOAD_NORMAL, |
2226 &info3, callback3.callback(), nullptr, nullptr, | 2231 &info3, callback3.callback(), nullptr, nullptr, |
2227 BoundNetLog()); | 2232 BoundNetLog()); |
2228 EXPECT_EQ(ERR_IO_PENDING, rv); | 2233 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2229 | 2234 |
2230 // Nothing has been sent to the factory yet. | 2235 // Nothing has been sent to the factory yet. |
2231 EXPECT_TRUE(factory->pending_requests().empty()); | 2236 EXPECT_TRUE(factory->pending_requests().empty()); |
2232 | 2237 |
2233 // Cancel the first 2 requests. | 2238 // Cancel the first 2 requests. |
2234 service.CancelPacRequest(request1); | 2239 service.CancelPacRequest(request1); |
2235 service.CancelPacRequest(request2); | 2240 service.CancelPacRequest(request2); |
2236 | 2241 |
2237 // At this point the ProxyService should be waiting for the | 2242 // At this point the ProxyService should be waiting for the |
2238 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2243 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2239 // PAC script download completion. | 2244 // PAC script download completion. |
2240 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2245 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2241 | 2246 |
2242 // Now that the PAC script is downloaded, it will have been sent to the | 2247 // Now that the PAC script is downloaded, it will have been sent to the |
2243 // proxy resolver. | 2248 // proxy resolver. |
2244 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2249 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2245 factory->pending_requests()[0]->script_data()->utf16()); | 2250 factory->pending_requests()[0]->script_data()->utf16()); |
2246 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2251 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2247 | 2252 |
2248 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2253 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2249 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url()); | 2254 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url()); |
2250 | 2255 |
2251 // Complete all the requests. | 2256 // Complete all the requests. |
2252 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80"); | 2257 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80"); |
2253 resolver.pending_requests()[0]->CompleteNow(OK); | 2258 resolver.pending_requests()[0]->CompleteNow(OK); |
2254 | 2259 |
2255 EXPECT_EQ(OK, callback3.WaitForResult()); | 2260 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
2256 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 2261 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
2257 | 2262 |
2258 EXPECT_TRUE(resolver.cancelled_requests().empty()); | 2263 EXPECT_TRUE(resolver.cancelled_requests().empty()); |
2259 | 2264 |
2260 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 2265 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
2261 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 2266 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
2262 | 2267 |
2263 TestNetLogEntry::List entries1; | 2268 TestNetLogEntry::List entries1; |
2264 log1.GetEntries(&entries1); | 2269 log1.GetEntries(&entries1); |
2265 | 2270 |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2297 service.SetProxyScriptFetchers( | 2302 service.SetProxyScriptFetchers( |
2298 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2303 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2299 | 2304 |
2300 // Start 2 requests. | 2305 // Start 2 requests. |
2301 | 2306 |
2302 ProxyInfo info1; | 2307 ProxyInfo info1; |
2303 TestCompletionCallback callback1; | 2308 TestCompletionCallback callback1; |
2304 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 2309 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, |
2305 callback1.callback(), nullptr, nullptr, | 2310 callback1.callback(), nullptr, nullptr, |
2306 BoundNetLog()); | 2311 BoundNetLog()); |
2307 EXPECT_EQ(ERR_IO_PENDING, rv); | 2312 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2308 | 2313 |
2309 ProxyInfo info2; | 2314 ProxyInfo info2; |
2310 TestCompletionCallback callback2; | 2315 TestCompletionCallback callback2; |
2311 ProxyService::PacRequest* request2; | 2316 ProxyService::PacRequest* request2; |
2312 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 2317 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, |
2313 callback2.callback(), &request2, nullptr, | 2318 callback2.callback(), &request2, nullptr, |
2314 BoundNetLog()); | 2319 BoundNetLog()); |
2315 EXPECT_EQ(ERR_IO_PENDING, rv); | 2320 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2316 | 2321 |
2317 // Check that nothing has been sent to the proxy resolver factory yet. | 2322 // Check that nothing has been sent to the proxy resolver factory yet. |
2318 ASSERT_EQ(0u, factory->pending_requests().size()); | 2323 ASSERT_EQ(0u, factory->pending_requests().size()); |
2319 | 2324 |
2320 // It should be trying to auto-detect first -- FAIL the autodetect during | 2325 // It should be trying to auto-detect first -- FAIL the autodetect during |
2321 // the script download. | 2326 // the script download. |
2322 EXPECT_TRUE(fetcher->has_pending_request()); | 2327 EXPECT_TRUE(fetcher->has_pending_request()); |
2323 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2328 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2324 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2329 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2325 | 2330 |
(...skipping 11 matching lines...) Expand all Loading... |
2337 | 2342 |
2338 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 2343 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); |
2339 | 2344 |
2340 // Complete the pending requests. | 2345 // Complete the pending requests. |
2341 requests[url2]->results()->UseNamedProxy("request2:80"); | 2346 requests[url2]->results()->UseNamedProxy("request2:80"); |
2342 requests[url2]->CompleteNow(OK); | 2347 requests[url2]->CompleteNow(OK); |
2343 requests[url1]->results()->UseNamedProxy("request1:80"); | 2348 requests[url1]->results()->UseNamedProxy("request1:80"); |
2344 requests[url1]->CompleteNow(OK); | 2349 requests[url1]->CompleteNow(OK); |
2345 | 2350 |
2346 // Verify that requests ran as expected. | 2351 // Verify that requests ran as expected. |
2347 EXPECT_EQ(OK, callback1.WaitForResult()); | 2352 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2348 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2353 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2349 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); | 2354 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); |
2350 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); | 2355 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); |
2351 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); | 2356 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); |
2352 | 2357 |
2353 EXPECT_EQ(OK, callback2.WaitForResult()); | 2358 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2354 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2359 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2355 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); | 2360 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); |
2356 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); | 2361 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); |
2357 EXPECT_LE(info2.proxy_resolve_start_time(), info2.proxy_resolve_end_time()); | 2362 EXPECT_LE(info2.proxy_resolve_start_time(), info2.proxy_resolve_end_time()); |
2358 } | 2363 } |
2359 | 2364 |
2360 // This is the same test as FallbackFromAutodetectToCustomPac, except | 2365 // This is the same test as FallbackFromAutodetectToCustomPac, except |
2361 // the auto-detect script fails parsing rather than downloading. | 2366 // the auto-detect script fails parsing rather than downloading. |
2362 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { | 2367 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { |
2363 const GURL url1("http://request1"); | 2368 const GURL url1("http://request1"); |
(...skipping 14 matching lines...) Expand all Loading... |
2378 service.SetProxyScriptFetchers( | 2383 service.SetProxyScriptFetchers( |
2379 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2384 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2380 | 2385 |
2381 // Start 2 requests. | 2386 // Start 2 requests. |
2382 | 2387 |
2383 ProxyInfo info1; | 2388 ProxyInfo info1; |
2384 TestCompletionCallback callback1; | 2389 TestCompletionCallback callback1; |
2385 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, | 2390 int rv = service.ResolveProxy(url1, std::string(), LOAD_NORMAL, &info1, |
2386 callback1.callback(), nullptr, nullptr, | 2391 callback1.callback(), nullptr, nullptr, |
2387 BoundNetLog()); | 2392 BoundNetLog()); |
2388 EXPECT_EQ(ERR_IO_PENDING, rv); | 2393 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2389 | 2394 |
2390 ProxyInfo info2; | 2395 ProxyInfo info2; |
2391 TestCompletionCallback callback2; | 2396 TestCompletionCallback callback2; |
2392 ProxyService::PacRequest* request2; | 2397 ProxyService::PacRequest* request2; |
2393 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, | 2398 rv = service.ResolveProxy(url2, std::string(), LOAD_NORMAL, &info2, |
2394 callback2.callback(), &request2, nullptr, | 2399 callback2.callback(), &request2, nullptr, |
2395 BoundNetLog()); | 2400 BoundNetLog()); |
2396 EXPECT_EQ(ERR_IO_PENDING, rv); | 2401 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2397 | 2402 |
2398 // Check that nothing has been sent to the proxy resolver factory yet. | 2403 // Check that nothing has been sent to the proxy resolver factory yet. |
2399 ASSERT_EQ(0u, factory->pending_requests().size()); | 2404 ASSERT_EQ(0u, factory->pending_requests().size()); |
2400 | 2405 |
2401 // It should be trying to auto-detect first -- succeed the download. | 2406 // It should be trying to auto-detect first -- succeed the download. |
2402 EXPECT_TRUE(fetcher->has_pending_request()); | 2407 EXPECT_TRUE(fetcher->has_pending_request()); |
2403 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2408 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2404 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 2409 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
2405 | 2410 |
2406 // The script contents passed failed basic verification step (since didn't | 2411 // The script contents passed failed basic verification step (since didn't |
(...skipping 13 matching lines...) Expand all Loading... |
2420 | 2425 |
2421 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 2426 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); |
2422 | 2427 |
2423 // Complete the pending requests. | 2428 // Complete the pending requests. |
2424 requests[url2]->results()->UseNamedProxy("request2:80"); | 2429 requests[url2]->results()->UseNamedProxy("request2:80"); |
2425 requests[url2]->CompleteNow(OK); | 2430 requests[url2]->CompleteNow(OK); |
2426 requests[url1]->results()->UseNamedProxy("request1:80"); | 2431 requests[url1]->results()->UseNamedProxy("request1:80"); |
2427 requests[url1]->CompleteNow(OK); | 2432 requests[url1]->CompleteNow(OK); |
2428 | 2433 |
2429 // Verify that requests ran as expected. | 2434 // Verify that requests ran as expected. |
2430 EXPECT_EQ(OK, callback1.WaitForResult()); | 2435 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2431 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2436 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2432 | 2437 |
2433 EXPECT_EQ(OK, callback2.WaitForResult()); | 2438 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2434 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2439 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2435 } | 2440 } |
2436 | 2441 |
2437 // Test that if all of auto-detect, a custom PAC script, and manual settings | 2442 // Test that if all of auto-detect, a custom PAC script, and manual settings |
2438 // are given, then we will try them in that order. | 2443 // are given, then we will try them in that order. |
2439 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { | 2444 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { |
2440 ProxyConfig config; | 2445 ProxyConfig config; |
2441 config.set_auto_detect(true); | 2446 config.set_auto_detect(true); |
2442 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2447 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
2443 config.proxy_rules().ParseFromString("http=foopy:80"); | 2448 config.proxy_rules().ParseFromString("http=foopy:80"); |
2444 | 2449 |
2445 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2450 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2446 MockAsyncProxyResolverFactory* factory = | 2451 MockAsyncProxyResolverFactory* factory = |
2447 new MockAsyncProxyResolverFactory(true); | 2452 new MockAsyncProxyResolverFactory(true); |
2448 ProxyService service(base::WrapUnique(config_service), | 2453 ProxyService service(base::WrapUnique(config_service), |
2449 base::WrapUnique(factory), nullptr); | 2454 base::WrapUnique(factory), nullptr); |
2450 | 2455 |
2451 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2456 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2452 service.SetProxyScriptFetchers( | 2457 service.SetProxyScriptFetchers( |
2453 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2458 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2454 | 2459 |
2455 // Start 2 requests. | 2460 // Start 2 requests. |
2456 | 2461 |
2457 ProxyInfo info1; | 2462 ProxyInfo info1; |
2458 TestCompletionCallback callback1; | 2463 TestCompletionCallback callback1; |
2459 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2464 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
2460 LOAD_NORMAL, &info1, callback1.callback(), | 2465 LOAD_NORMAL, &info1, callback1.callback(), |
2461 nullptr, nullptr, BoundNetLog()); | 2466 nullptr, nullptr, BoundNetLog()); |
2462 EXPECT_EQ(ERR_IO_PENDING, rv); | 2467 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2463 | 2468 |
2464 ProxyInfo info2; | 2469 ProxyInfo info2; |
2465 TestCompletionCallback callback2; | 2470 TestCompletionCallback callback2; |
2466 ProxyService::PacRequest* request2; | 2471 ProxyService::PacRequest* request2; |
2467 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2472 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
2468 &info2, callback2.callback(), &request2, nullptr, | 2473 &info2, callback2.callback(), &request2, nullptr, |
2469 BoundNetLog()); | 2474 BoundNetLog()); |
2470 EXPECT_EQ(ERR_IO_PENDING, rv); | 2475 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2471 | 2476 |
2472 // Check that nothing has been sent to the proxy resolver factory yet. | 2477 // Check that nothing has been sent to the proxy resolver factory yet. |
2473 ASSERT_EQ(0u, factory->pending_requests().size()); | 2478 ASSERT_EQ(0u, factory->pending_requests().size()); |
2474 | 2479 |
2475 // It should be trying to auto-detect first -- fail the download. | 2480 // It should be trying to auto-detect first -- fail the download. |
2476 EXPECT_TRUE(fetcher->has_pending_request()); | 2481 EXPECT_TRUE(fetcher->has_pending_request()); |
2477 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2482 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2478 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2483 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2479 | 2484 |
2480 // Next it should be trying the custom PAC url -- fail the download. | 2485 // Next it should be trying the custom PAC url -- fail the download. |
2481 EXPECT_TRUE(fetcher->has_pending_request()); | 2486 EXPECT_TRUE(fetcher->has_pending_request()); |
2482 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2487 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2483 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2488 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2484 | 2489 |
2485 // Since we never managed to initialize a resolver, nothing should have been | 2490 // Since we never managed to initialize a resolver, nothing should have been |
2486 // sent to it. | 2491 // sent to it. |
2487 ASSERT_EQ(0u, factory->pending_requests().size()); | 2492 ASSERT_EQ(0u, factory->pending_requests().size()); |
2488 | 2493 |
2489 // Verify that requests ran as expected -- they should have fallen back to | 2494 // Verify that requests ran as expected -- they should have fallen back to |
2490 // the manual proxy configuration for HTTP urls. | 2495 // the manual proxy configuration for HTTP urls. |
2491 EXPECT_EQ(OK, callback1.WaitForResult()); | 2496 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2492 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); | 2497 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); |
2493 | 2498 |
2494 EXPECT_EQ(OK, callback2.WaitForResult()); | 2499 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2495 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); | 2500 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); |
2496 } | 2501 } |
2497 | 2502 |
2498 // Test that the bypass rules are NOT applied when using autodetect. | 2503 // Test that the bypass rules are NOT applied when using autodetect. |
2499 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { | 2504 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { |
2500 ProxyConfig config; | 2505 ProxyConfig config; |
2501 config.set_auto_detect(true); | 2506 config.set_auto_detect(true); |
2502 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2507 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
2503 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. | 2508 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. |
2504 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); | 2509 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); |
2505 | 2510 |
2506 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2511 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2507 MockAsyncProxyResolver resolver; | 2512 MockAsyncProxyResolver resolver; |
2508 MockAsyncProxyResolverFactory* factory = | 2513 MockAsyncProxyResolverFactory* factory = |
2509 new MockAsyncProxyResolverFactory(true); | 2514 new MockAsyncProxyResolverFactory(true); |
2510 ProxyService service(base::WrapUnique(config_service), | 2515 ProxyService service(base::WrapUnique(config_service), |
2511 base::WrapUnique(factory), nullptr); | 2516 base::WrapUnique(factory), nullptr); |
2512 | 2517 |
2513 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2518 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2514 service.SetProxyScriptFetchers( | 2519 service.SetProxyScriptFetchers( |
2515 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2520 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2516 | 2521 |
2517 // Start 1 requests. | 2522 // Start 1 requests. |
2518 | 2523 |
2519 ProxyInfo info1; | 2524 ProxyInfo info1; |
2520 TestCompletionCallback callback1; | 2525 TestCompletionCallback callback1; |
2521 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2526 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2522 LOAD_NORMAL, &info1, callback1.callback(), | 2527 LOAD_NORMAL, &info1, callback1.callback(), |
2523 nullptr, nullptr, BoundNetLog()); | 2528 nullptr, nullptr, BoundNetLog()); |
2524 EXPECT_EQ(ERR_IO_PENDING, rv); | 2529 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2525 | 2530 |
2526 // Check that nothing has been sent to the proxy resolver factory yet. | 2531 // Check that nothing has been sent to the proxy resolver factory yet. |
2527 ASSERT_EQ(0u, factory->pending_requests().size()); | 2532 ASSERT_EQ(0u, factory->pending_requests().size()); |
2528 | 2533 |
2529 // It should be trying to auto-detect first -- succeed the download. | 2534 // It should be trying to auto-detect first -- succeed the download. |
2530 EXPECT_TRUE(fetcher->has_pending_request()); | 2535 EXPECT_TRUE(fetcher->has_pending_request()); |
2531 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2536 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2532 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2537 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2533 | 2538 |
2534 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2539 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2535 factory->pending_requests()[0]->script_data()->utf16()); | 2540 factory->pending_requests()[0]->script_data()->utf16()); |
2536 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2541 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2537 | 2542 |
2538 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2543 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2539 EXPECT_EQ(GURL("http://www.google.com"), | 2544 EXPECT_EQ(GURL("http://www.google.com"), |
2540 resolver.pending_requests()[0]->url()); | 2545 resolver.pending_requests()[0]->url()); |
2541 | 2546 |
2542 // Complete the pending request. | 2547 // Complete the pending request. |
2543 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2548 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2544 resolver.pending_requests()[0]->CompleteNow(OK); | 2549 resolver.pending_requests()[0]->CompleteNow(OK); |
2545 | 2550 |
2546 // Verify that request ran as expected. | 2551 // Verify that request ran as expected. |
2547 EXPECT_EQ(OK, callback1.WaitForResult()); | 2552 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2548 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2553 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2549 | 2554 |
2550 // Start another request, it should pickup the bypass item. | 2555 // Start another request, it should pickup the bypass item. |
2551 ProxyInfo info2; | 2556 ProxyInfo info2; |
2552 TestCompletionCallback callback2; | 2557 TestCompletionCallback callback2; |
2553 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2558 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2554 LOAD_NORMAL, &info2, callback2.callback(), nullptr, | 2559 LOAD_NORMAL, &info2, callback2.callback(), nullptr, |
2555 nullptr, BoundNetLog()); | 2560 nullptr, BoundNetLog()); |
2556 EXPECT_EQ(ERR_IO_PENDING, rv); | 2561 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2557 | 2562 |
2558 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2563 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2559 EXPECT_EQ(GURL("http://www.google.com"), | 2564 EXPECT_EQ(GURL("http://www.google.com"), |
2560 resolver.pending_requests()[0]->url()); | 2565 resolver.pending_requests()[0]->url()); |
2561 | 2566 |
2562 // Complete the pending request. | 2567 // Complete the pending request. |
2563 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2568 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2564 resolver.pending_requests()[0]->CompleteNow(OK); | 2569 resolver.pending_requests()[0]->CompleteNow(OK); |
2565 | 2570 |
2566 EXPECT_EQ(OK, callback2.WaitForResult()); | 2571 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2567 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2572 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2568 } | 2573 } |
2569 | 2574 |
2570 // Delete the ProxyService while InitProxyResolver has an outstanding | 2575 // Delete the ProxyService while InitProxyResolver has an outstanding |
2571 // request to the script fetcher. When run under valgrind, should not | 2576 // request to the script fetcher. When run under valgrind, should not |
2572 // have any memory errors (used to be that the ProxyScriptFetcher was | 2577 // have any memory errors (used to be that the ProxyScriptFetcher was |
2573 // being deleted prior to the InitProxyResolver). | 2578 // being deleted prior to the InitProxyResolver). |
2574 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { | 2579 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { |
2575 ProxyConfig config = | 2580 ProxyConfig config = |
2576 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 2581 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
2577 | 2582 |
2578 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2583 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2579 MockAsyncProxyResolverFactory* factory = | 2584 MockAsyncProxyResolverFactory* factory = |
2580 new MockAsyncProxyResolverFactory(true); | 2585 new MockAsyncProxyResolverFactory(true); |
2581 ProxyService service(base::WrapUnique(config_service), | 2586 ProxyService service(base::WrapUnique(config_service), |
2582 base::WrapUnique(factory), nullptr); | 2587 base::WrapUnique(factory), nullptr); |
2583 | 2588 |
2584 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2589 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2585 service.SetProxyScriptFetchers( | 2590 service.SetProxyScriptFetchers( |
2586 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2591 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2587 | 2592 |
2588 // Start 1 request. | 2593 // Start 1 request. |
2589 | 2594 |
2590 ProxyInfo info1; | 2595 ProxyInfo info1; |
2591 TestCompletionCallback callback1; | 2596 TestCompletionCallback callback1; |
2592 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2597 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2593 LOAD_NORMAL, &info1, callback1.callback(), | 2598 LOAD_NORMAL, &info1, callback1.callback(), |
2594 nullptr, nullptr, BoundNetLog()); | 2599 nullptr, nullptr, BoundNetLog()); |
2595 EXPECT_EQ(ERR_IO_PENDING, rv); | 2600 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2596 | 2601 |
2597 // Check that nothing has been sent to the proxy resolver factory yet. | 2602 // Check that nothing has been sent to the proxy resolver factory yet. |
2598 ASSERT_EQ(0u, factory->pending_requests().size()); | 2603 ASSERT_EQ(0u, factory->pending_requests().size()); |
2599 | 2604 |
2600 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 2605 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
2601 // and be waiting on that to complete. | 2606 // and be waiting on that to complete. |
2602 EXPECT_TRUE(fetcher->has_pending_request()); | 2607 EXPECT_TRUE(fetcher->has_pending_request()); |
2603 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2608 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2604 } | 2609 } |
2605 | 2610 |
(...skipping 11 matching lines...) Expand all Loading... |
2617 ProxyService service(base::WrapUnique(config_service), | 2622 ProxyService service(base::WrapUnique(config_service), |
2618 base::WrapUnique(factory), nullptr); | 2623 base::WrapUnique(factory), nullptr); |
2619 | 2624 |
2620 GURL url("http://www.google.com/"); | 2625 GURL url("http://www.google.com/"); |
2621 | 2626 |
2622 ProxyInfo info; | 2627 ProxyInfo info; |
2623 TestCompletionCallback callback; | 2628 TestCompletionCallback callback; |
2624 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 2629 int rv = service.ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
2625 callback.callback(), nullptr, nullptr, | 2630 callback.callback(), nullptr, nullptr, |
2626 BoundNetLog()); | 2631 BoundNetLog()); |
2627 EXPECT_EQ(ERR_IO_PENDING, rv); | 2632 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2628 | 2633 |
2629 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 2634 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
2630 factory->pending_requests()[0]->script_data()->url()); | 2635 factory->pending_requests()[0]->script_data()->url()); |
2631 } | 2636 } |
2632 | 2637 |
2633 TEST_F(ProxyServiceTest, ResetProxyConfigService) { | 2638 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
2634 ProxyConfig config1; | 2639 ProxyConfig config1; |
2635 config1.proxy_rules().ParseFromString("foopy1:8080"); | 2640 config1.proxy_rules().ParseFromString("foopy1:8080"); |
2636 config1.set_auto_detect(false); | 2641 config1.set_auto_detect(false); |
2637 ProxyService service(base::WrapUnique(new MockProxyConfigService(config1)), | 2642 ProxyService service(base::WrapUnique(new MockProxyConfigService(config1)), |
2638 nullptr, nullptr); | 2643 nullptr, nullptr); |
2639 | 2644 |
2640 ProxyInfo info; | 2645 ProxyInfo info; |
2641 TestCompletionCallback callback1; | 2646 TestCompletionCallback callback1; |
2642 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2647 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
2643 LOAD_NORMAL, &info, callback1.callback(), | 2648 LOAD_NORMAL, &info, callback1.callback(), |
2644 nullptr, nullptr, BoundNetLog()); | 2649 nullptr, nullptr, BoundNetLog()); |
2645 EXPECT_EQ(OK, rv); | 2650 EXPECT_THAT(rv, IsOk()); |
2646 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 2651 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
2647 | 2652 |
2648 ProxyConfig config2; | 2653 ProxyConfig config2; |
2649 config2.proxy_rules().ParseFromString("foopy2:8080"); | 2654 config2.proxy_rules().ParseFromString("foopy2:8080"); |
2650 config2.set_auto_detect(false); | 2655 config2.set_auto_detect(false); |
2651 service.ResetConfigService( | 2656 service.ResetConfigService( |
2652 base::WrapUnique(new MockProxyConfigService(config2))); | 2657 base::WrapUnique(new MockProxyConfigService(config2))); |
2653 TestCompletionCallback callback2; | 2658 TestCompletionCallback callback2; |
2654 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2659 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
2655 &info, callback2.callback(), nullptr, nullptr, | 2660 &info, callback2.callback(), nullptr, nullptr, |
2656 BoundNetLog()); | 2661 BoundNetLog()); |
2657 EXPECT_EQ(OK, rv); | 2662 EXPECT_THAT(rv, IsOk()); |
2658 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 2663 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
2659 } | 2664 } |
2660 | 2665 |
2661 // Test that when going from a configuration that required PAC to one | 2666 // Test that when going from a configuration that required PAC to one |
2662 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 2667 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
2663 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 2668 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
2664 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 2669 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
2665 | 2670 |
2666 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2671 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2667 MockAsyncProxyResolver resolver; | 2672 MockAsyncProxyResolver resolver; |
2668 MockAsyncProxyResolverFactory* factory = | 2673 MockAsyncProxyResolverFactory* factory = |
2669 new MockAsyncProxyResolverFactory(false); | 2674 new MockAsyncProxyResolverFactory(false); |
2670 ProxyService service(base::WrapUnique(config_service), | 2675 ProxyService service(base::WrapUnique(config_service), |
2671 base::WrapUnique(factory), nullptr); | 2676 base::WrapUnique(factory), nullptr); |
2672 | 2677 |
2673 // Start 1 request. | 2678 // Start 1 request. |
2674 | 2679 |
2675 ProxyInfo info1; | 2680 ProxyInfo info1; |
2676 TestCompletionCallback callback1; | 2681 TestCompletionCallback callback1; |
2677 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2682 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2678 LOAD_NORMAL, &info1, callback1.callback(), | 2683 LOAD_NORMAL, &info1, callback1.callback(), |
2679 nullptr, nullptr, BoundNetLog()); | 2684 nullptr, nullptr, BoundNetLog()); |
2680 EXPECT_EQ(ERR_IO_PENDING, rv); | 2685 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2681 | 2686 |
2682 // Successfully set the autodetect script. | 2687 // Successfully set the autodetect script. |
2683 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2688 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2684 factory->pending_requests()[0]->script_data()->type()); | 2689 factory->pending_requests()[0]->script_data()->type()); |
2685 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2690 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2686 | 2691 |
2687 // Complete the pending request. | 2692 // Complete the pending request. |
2688 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2693 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2689 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2694 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2690 resolver.pending_requests()[0]->CompleteNow(OK); | 2695 resolver.pending_requests()[0]->CompleteNow(OK); |
2691 | 2696 |
2692 // Verify that request ran as expected. | 2697 // Verify that request ran as expected. |
2693 EXPECT_EQ(OK, callback1.WaitForResult()); | 2698 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2694 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2699 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2695 | 2700 |
2696 // Force the ProxyService to pull down a new proxy configuration. | 2701 // Force the ProxyService to pull down a new proxy configuration. |
2697 // (Even though the configuration isn't old/bad). | 2702 // (Even though the configuration isn't old/bad). |
2698 // | 2703 // |
2699 // This new configuration no longer has auto_detect set, so | 2704 // This new configuration no longer has auto_detect set, so |
2700 // requests should complete synchronously now as direct-connect. | 2705 // requests should complete synchronously now as direct-connect. |
2701 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2706 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2702 | 2707 |
2703 // Start another request -- the effective configuration has changed. | 2708 // Start another request -- the effective configuration has changed. |
2704 ProxyInfo info2; | 2709 ProxyInfo info2; |
2705 TestCompletionCallback callback2; | 2710 TestCompletionCallback callback2; |
2706 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2711 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2707 LOAD_NORMAL, &info2, callback2.callback(), nullptr, | 2712 LOAD_NORMAL, &info2, callback2.callback(), nullptr, |
2708 nullptr, BoundNetLog()); | 2713 nullptr, BoundNetLog()); |
2709 EXPECT_EQ(OK, rv); | 2714 EXPECT_THAT(rv, IsOk()); |
2710 | 2715 |
2711 EXPECT_TRUE(info2.is_direct()); | 2716 EXPECT_TRUE(info2.is_direct()); |
2712 } | 2717 } |
2713 | 2718 |
2714 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 2719 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
2715 MockProxyConfigService* config_service = | 2720 MockProxyConfigService* config_service = |
2716 new MockProxyConfigService("http://foopy/proxy.pac"); | 2721 new MockProxyConfigService("http://foopy/proxy.pac"); |
2717 | 2722 |
2718 MockAsyncProxyResolver resolver; | 2723 MockAsyncProxyResolver resolver; |
2719 MockAsyncProxyResolverFactory* factory = | 2724 MockAsyncProxyResolverFactory* factory = |
(...skipping 12 matching lines...) Expand all Loading... |
2732 // complete quickly. | 2737 // complete quickly. |
2733 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 2738 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
2734 | 2739 |
2735 // Start 1 request. | 2740 // Start 1 request. |
2736 | 2741 |
2737 ProxyInfo info1; | 2742 ProxyInfo info1; |
2738 TestCompletionCallback callback1; | 2743 TestCompletionCallback callback1; |
2739 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2744 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
2740 LOAD_NORMAL, &info1, callback1.callback(), | 2745 LOAD_NORMAL, &info1, callback1.callback(), |
2741 nullptr, nullptr, BoundNetLog()); | 2746 nullptr, nullptr, BoundNetLog()); |
2742 EXPECT_EQ(ERR_IO_PENDING, rv); | 2747 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2743 | 2748 |
2744 // The first request should have triggered initial download of PAC script. | 2749 // The first request should have triggered initial download of PAC script. |
2745 EXPECT_TRUE(fetcher->has_pending_request()); | 2750 EXPECT_TRUE(fetcher->has_pending_request()); |
2746 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2751 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2747 | 2752 |
2748 // Nothing has been sent to the factory yet. | 2753 // Nothing has been sent to the factory yet. |
2749 EXPECT_TRUE(factory->pending_requests().empty()); | 2754 EXPECT_TRUE(factory->pending_requests().empty()); |
2750 | 2755 |
2751 // At this point the ProxyService should be waiting for the | 2756 // At this point the ProxyService should be waiting for the |
2752 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2757 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2753 // PAC script download completion. | 2758 // PAC script download completion. |
2754 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2759 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2755 | 2760 |
2756 // Now that the PAC script is downloaded, the request will have been sent to | 2761 // Now that the PAC script is downloaded, the request will have been sent to |
2757 // the proxy resolver. | 2762 // the proxy resolver. |
2758 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2763 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2759 factory->pending_requests()[0]->script_data()->utf16()); | 2764 factory->pending_requests()[0]->script_data()->utf16()); |
2760 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2765 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2761 | 2766 |
2762 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2767 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2763 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2768 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
2764 | 2769 |
2765 // Complete the pending request. | 2770 // Complete the pending request. |
2766 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2771 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2767 resolver.pending_requests()[0]->CompleteNow(OK); | 2772 resolver.pending_requests()[0]->CompleteNow(OK); |
2768 | 2773 |
2769 // Wait for completion callback, and verify that the request ran as expected. | 2774 // Wait for completion callback, and verify that the request ran as expected. |
2770 EXPECT_EQ(OK, callback1.WaitForResult()); | 2775 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2771 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2776 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2772 | 2777 |
2773 // Now simluate a change in the network. The ProxyConfigService is still | 2778 // Now simluate a change in the network. The ProxyConfigService is still |
2774 // going to return the same PAC URL as before, but this URL needs to be | 2779 // going to return the same PAC URL as before, but this URL needs to be |
2775 // refetched on the new network. | 2780 // refetched on the new network. |
2776 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2781 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2777 base::RunLoop().RunUntilIdle(); // Notification happens async. | 2782 base::RunLoop().RunUntilIdle(); // Notification happens async. |
2778 | 2783 |
2779 // Start a second request. | 2784 // Start a second request. |
2780 ProxyInfo info2; | 2785 ProxyInfo info2; |
2781 TestCompletionCallback callback2; | 2786 TestCompletionCallback callback2; |
2782 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2787 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
2783 &info2, callback2.callback(), nullptr, nullptr, | 2788 &info2, callback2.callback(), nullptr, nullptr, |
2784 BoundNetLog()); | 2789 BoundNetLog()); |
2785 EXPECT_EQ(ERR_IO_PENDING, rv); | 2790 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2786 | 2791 |
2787 // This second request should have triggered the re-download of the PAC | 2792 // This second request should have triggered the re-download of the PAC |
2788 // script (since we marked the network as having changed). | 2793 // script (since we marked the network as having changed). |
2789 EXPECT_TRUE(fetcher->has_pending_request()); | 2794 EXPECT_TRUE(fetcher->has_pending_request()); |
2790 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2795 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2791 | 2796 |
2792 // Nothing has been sent to the factory yet. | 2797 // Nothing has been sent to the factory yet. |
2793 EXPECT_TRUE(factory->pending_requests().empty()); | 2798 EXPECT_TRUE(factory->pending_requests().empty()); |
2794 | 2799 |
2795 // Simulate the PAC script fetch as having completed (this time with | 2800 // Simulate the PAC script fetch as having completed (this time with |
2796 // different data). | 2801 // different data). |
2797 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 2802 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
2798 | 2803 |
2799 // Now that the PAC script is downloaded, the second request will have been | 2804 // Now that the PAC script is downloaded, the second request will have been |
2800 // sent to the proxy resolver. | 2805 // sent to the proxy resolver. |
2801 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2806 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
2802 factory->pending_requests()[0]->script_data()->utf16()); | 2807 factory->pending_requests()[0]->script_data()->utf16()); |
2803 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2808 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2804 | 2809 |
2805 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2810 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2806 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2811 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
2807 | 2812 |
2808 // Complete the pending second request. | 2813 // Complete the pending second request. |
2809 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2814 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2810 resolver.pending_requests()[0]->CompleteNow(OK); | 2815 resolver.pending_requests()[0]->CompleteNow(OK); |
2811 | 2816 |
2812 // Wait for completion callback, and verify that the request ran as expected. | 2817 // Wait for completion callback, and verify that the request ran as expected. |
2813 EXPECT_EQ(OK, callback2.WaitForResult()); | 2818 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2814 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2819 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2815 | 2820 |
2816 // Check that the expected events were output to the log stream. In particular | 2821 // Check that the expected events were output to the log stream. In particular |
2817 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial | 2822 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial |
2818 // setup), and NOT a second time when the IP address changed. | 2823 // setup), and NOT a second time when the IP address changed. |
2819 TestNetLogEntry::List entries; | 2824 TestNetLogEntry::List entries; |
2820 log.GetEntries(&entries); | 2825 log.GetEntries(&entries); |
2821 | 2826 |
2822 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, | 2827 EXPECT_TRUE(LogContainsEntryWithType(entries, 0, |
2823 NetLog::TYPE_PROXY_CONFIG_CHANGED)); | 2828 NetLog::TYPE_PROXY_CONFIG_CHANGED)); |
(...skipping 26 matching lines...) Expand all Loading... |
2850 service.SetProxyScriptFetchers( | 2855 service.SetProxyScriptFetchers( |
2851 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2856 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2852 | 2857 |
2853 // Start 1 request. | 2858 // Start 1 request. |
2854 | 2859 |
2855 ProxyInfo info1; | 2860 ProxyInfo info1; |
2856 TestCompletionCallback callback1; | 2861 TestCompletionCallback callback1; |
2857 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2862 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
2858 LOAD_NORMAL, &info1, callback1.callback(), | 2863 LOAD_NORMAL, &info1, callback1.callback(), |
2859 nullptr, nullptr, BoundNetLog()); | 2864 nullptr, nullptr, BoundNetLog()); |
2860 EXPECT_EQ(ERR_IO_PENDING, rv); | 2865 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2861 | 2866 |
2862 // The first request should have triggered initial download of PAC script. | 2867 // The first request should have triggered initial download of PAC script. |
2863 EXPECT_TRUE(fetcher->has_pending_request()); | 2868 EXPECT_TRUE(fetcher->has_pending_request()); |
2864 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2869 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2865 | 2870 |
2866 // Nothing has been sent to the factory yet. | 2871 // Nothing has been sent to the factory yet. |
2867 EXPECT_TRUE(factory->pending_requests().empty()); | 2872 EXPECT_TRUE(factory->pending_requests().empty()); |
2868 | 2873 |
2869 // At this point the ProxyService should be waiting for the | 2874 // At this point the ProxyService should be waiting for the |
2870 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2875 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2871 // PAC script download completion. | 2876 // PAC script download completion. |
2872 // | 2877 // |
2873 // We simulate a failed download attempt, the proxy service should now | 2878 // We simulate a failed download attempt, the proxy service should now |
2874 // fall-back to DIRECT connections. | 2879 // fall-back to DIRECT connections. |
2875 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2880 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2876 | 2881 |
2877 ASSERT_TRUE(factory->pending_requests().empty()); | 2882 ASSERT_TRUE(factory->pending_requests().empty()); |
2878 | 2883 |
2879 // Wait for completion callback, and verify it used DIRECT. | 2884 // Wait for completion callback, and verify it used DIRECT. |
2880 EXPECT_EQ(OK, callback1.WaitForResult()); | 2885 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2881 EXPECT_TRUE(info1.is_direct()); | 2886 EXPECT_TRUE(info1.is_direct()); |
2882 | 2887 |
2883 // At this point we have initialized the proxy service using a PAC script, | 2888 // At this point we have initialized the proxy service using a PAC script, |
2884 // however it failed and fell-back to DIRECT. | 2889 // however it failed and fell-back to DIRECT. |
2885 // | 2890 // |
2886 // A background task to periodically re-check the PAC script for validity will | 2891 // A background task to periodically re-check the PAC script for validity will |
2887 // have been started. We will now wait for the next download attempt to start. | 2892 // have been started. We will now wait for the next download attempt to start. |
2888 // | 2893 // |
2889 // Note that we shouldn't have to wait long here, since our test enables a | 2894 // Note that we shouldn't have to wait long here, since our test enables a |
2890 // special unit-test mode. | 2895 // special unit-test mode. |
(...skipping 20 matching lines...) Expand all Loading... |
2911 // PAC script (thereby recovering from the initial fetch failure). We will | 2916 // PAC script (thereby recovering from the initial fetch failure). We will |
2912 // verify that the next Resolve request uses the resolver rather than | 2917 // verify that the next Resolve request uses the resolver rather than |
2913 // DIRECT. | 2918 // DIRECT. |
2914 | 2919 |
2915 // Start a second request. | 2920 // Start a second request. |
2916 ProxyInfo info2; | 2921 ProxyInfo info2; |
2917 TestCompletionCallback callback2; | 2922 TestCompletionCallback callback2; |
2918 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 2923 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
2919 &info2, callback2.callback(), nullptr, nullptr, | 2924 &info2, callback2.callback(), nullptr, nullptr, |
2920 BoundNetLog()); | 2925 BoundNetLog()); |
2921 EXPECT_EQ(ERR_IO_PENDING, rv); | 2926 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2922 | 2927 |
2923 // Check that it was sent to the resolver. | 2928 // Check that it was sent to the resolver. |
2924 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2929 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2925 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2930 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
2926 | 2931 |
2927 // Complete the pending second request. | 2932 // Complete the pending second request. |
2928 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2933 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2929 resolver.pending_requests()[0]->CompleteNow(OK); | 2934 resolver.pending_requests()[0]->CompleteNow(OK); |
2930 | 2935 |
2931 // Wait for completion callback, and verify that the request ran as expected. | 2936 // Wait for completion callback, and verify that the request ran as expected. |
2932 EXPECT_EQ(OK, callback2.WaitForResult()); | 2937 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2933 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2938 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2934 } | 2939 } |
2935 | 2940 |
2936 // This test verifies that the PAC script specified by the settings is | 2941 // This test verifies that the PAC script specified by the settings is |
2937 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 2942 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
2938 // however at a later time its *contents* change, we will eventually | 2943 // however at a later time its *contents* change, we will eventually |
2939 // re-configure the service to use the new script. | 2944 // re-configure the service to use the new script. |
2940 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) { | 2945 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) { |
2941 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2946 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
2942 // runs quickly. | 2947 // runs quickly. |
(...skipping 14 matching lines...) Expand all Loading... |
2957 service.SetProxyScriptFetchers( | 2962 service.SetProxyScriptFetchers( |
2958 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2963 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2959 | 2964 |
2960 // Start 1 request. | 2965 // Start 1 request. |
2961 | 2966 |
2962 ProxyInfo info1; | 2967 ProxyInfo info1; |
2963 TestCompletionCallback callback1; | 2968 TestCompletionCallback callback1; |
2964 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 2969 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
2965 LOAD_NORMAL, &info1, callback1.callback(), | 2970 LOAD_NORMAL, &info1, callback1.callback(), |
2966 nullptr, nullptr, BoundNetLog()); | 2971 nullptr, nullptr, BoundNetLog()); |
2967 EXPECT_EQ(ERR_IO_PENDING, rv); | 2972 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2968 | 2973 |
2969 // The first request should have triggered initial download of PAC script. | 2974 // The first request should have triggered initial download of PAC script. |
2970 EXPECT_TRUE(fetcher->has_pending_request()); | 2975 EXPECT_TRUE(fetcher->has_pending_request()); |
2971 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2976 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2972 | 2977 |
2973 // Nothing has been sent to the factory yet. | 2978 // Nothing has been sent to the factory yet. |
2974 EXPECT_TRUE(factory->pending_requests().empty()); | 2979 EXPECT_TRUE(factory->pending_requests().empty()); |
2975 | 2980 |
2976 // At this point the ProxyService should be waiting for the | 2981 // At this point the ProxyService should be waiting for the |
2977 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2982 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2978 // PAC script download completion. | 2983 // PAC script download completion. |
2979 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2984 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2980 | 2985 |
2981 // Now that the PAC script is downloaded, the request will have been sent to | 2986 // Now that the PAC script is downloaded, the request will have been sent to |
2982 // the proxy resolver. | 2987 // the proxy resolver. |
2983 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2988 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2984 factory->pending_requests()[0]->script_data()->utf16()); | 2989 factory->pending_requests()[0]->script_data()->utf16()); |
2985 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2990 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2986 | 2991 |
2987 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2992 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2988 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2993 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
2989 | 2994 |
2990 // Complete the pending request. | 2995 // Complete the pending request. |
2991 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2996 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2992 resolver.pending_requests()[0]->CompleteNow(OK); | 2997 resolver.pending_requests()[0]->CompleteNow(OK); |
2993 | 2998 |
2994 // Wait for completion callback, and verify that the request ran as expected. | 2999 // Wait for completion callback, and verify that the request ran as expected. |
2995 EXPECT_EQ(OK, callback1.WaitForResult()); | 3000 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2996 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3001 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2997 | 3002 |
2998 // At this point we have initialized the proxy service using a PAC script. | 3003 // At this point we have initialized the proxy service using a PAC script. |
2999 // | 3004 // |
3000 // A background task to periodically re-check the PAC script for validity will | 3005 // A background task to periodically re-check the PAC script for validity will |
3001 // have been started. We will now wait for the next download attempt to start. | 3006 // have been started. We will now wait for the next download attempt to start. |
3002 // | 3007 // |
3003 // Note that we shouldn't have to wait long here, since our test enables a | 3008 // Note that we shouldn't have to wait long here, since our test enables a |
3004 // special unit-test mode. | 3009 // special unit-test mode. |
3005 fetcher->WaitUntilFetch(); | 3010 fetcher->WaitUntilFetch(); |
(...skipping 18 matching lines...) Expand all Loading... |
3024 | 3029 |
3025 // At this point the ProxyService should have re-configured itself to use the | 3030 // At this point the ProxyService should have re-configured itself to use the |
3026 // new PAC script. | 3031 // new PAC script. |
3027 | 3032 |
3028 // Start a second request. | 3033 // Start a second request. |
3029 ProxyInfo info2; | 3034 ProxyInfo info2; |
3030 TestCompletionCallback callback2; | 3035 TestCompletionCallback callback2; |
3031 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 3036 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
3032 &info2, callback2.callback(), nullptr, nullptr, | 3037 &info2, callback2.callback(), nullptr, nullptr, |
3033 BoundNetLog()); | 3038 BoundNetLog()); |
3034 EXPECT_EQ(ERR_IO_PENDING, rv); | 3039 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3035 | 3040 |
3036 // Check that it was sent to the resolver. | 3041 // Check that it was sent to the resolver. |
3037 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3042 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3038 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3043 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
3039 | 3044 |
3040 // Complete the pending second request. | 3045 // Complete the pending second request. |
3041 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3046 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
3042 resolver.pending_requests()[0]->CompleteNow(OK); | 3047 resolver.pending_requests()[0]->CompleteNow(OK); |
3043 | 3048 |
3044 // Wait for completion callback, and verify that the request ran as expected. | 3049 // Wait for completion callback, and verify that the request ran as expected. |
3045 EXPECT_EQ(OK, callback2.WaitForResult()); | 3050 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
3046 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3051 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3047 } | 3052 } |
3048 | 3053 |
3049 // This test verifies that the PAC script specified by the settings is | 3054 // This test verifies that the PAC script specified by the settings is |
3050 // periodically polled for changes. Specifically, if the initial fetch succeeds | 3055 // periodically polled for changes. Specifically, if the initial fetch succeeds |
3051 // and so does the next poll, however the contents of the downloaded script | 3056 // and so does the next poll, however the contents of the downloaded script |
3052 // have NOT changed, then we do not bother to re-initialize the proxy resolver. | 3057 // have NOT changed, then we do not bother to re-initialize the proxy resolver. |
3053 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) { | 3058 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) { |
3054 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 3059 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
3055 // runs quickly. | 3060 // runs quickly. |
(...skipping 14 matching lines...) Expand all Loading... |
3070 service.SetProxyScriptFetchers( | 3075 service.SetProxyScriptFetchers( |
3071 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3076 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
3072 | 3077 |
3073 // Start 1 request. | 3078 // Start 1 request. |
3074 | 3079 |
3075 ProxyInfo info1; | 3080 ProxyInfo info1; |
3076 TestCompletionCallback callback1; | 3081 TestCompletionCallback callback1; |
3077 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 3082 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
3078 LOAD_NORMAL, &info1, callback1.callback(), | 3083 LOAD_NORMAL, &info1, callback1.callback(), |
3079 nullptr, nullptr, BoundNetLog()); | 3084 nullptr, nullptr, BoundNetLog()); |
3080 EXPECT_EQ(ERR_IO_PENDING, rv); | 3085 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3081 | 3086 |
3082 // The first request should have triggered initial download of PAC script. | 3087 // The first request should have triggered initial download of PAC script. |
3083 EXPECT_TRUE(fetcher->has_pending_request()); | 3088 EXPECT_TRUE(fetcher->has_pending_request()); |
3084 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3089 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3085 | 3090 |
3086 // Nothing has been sent to the factory yet. | 3091 // Nothing has been sent to the factory yet. |
3087 EXPECT_TRUE(factory->pending_requests().empty()); | 3092 EXPECT_TRUE(factory->pending_requests().empty()); |
3088 | 3093 |
3089 // At this point the ProxyService should be waiting for the | 3094 // At this point the ProxyService should be waiting for the |
3090 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3095 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3091 // PAC script download completion. | 3096 // PAC script download completion. |
3092 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3097 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3093 | 3098 |
3094 // Now that the PAC script is downloaded, the request will have been sent to | 3099 // Now that the PAC script is downloaded, the request will have been sent to |
3095 // the proxy resolver. | 3100 // the proxy resolver. |
3096 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3101 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3097 factory->pending_requests()[0]->script_data()->utf16()); | 3102 factory->pending_requests()[0]->script_data()->utf16()); |
3098 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3103 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3099 | 3104 |
3100 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3105 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3101 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3106 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
3102 | 3107 |
3103 // Complete the pending request. | 3108 // Complete the pending request. |
3104 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3109 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
3105 resolver.pending_requests()[0]->CompleteNow(OK); | 3110 resolver.pending_requests()[0]->CompleteNow(OK); |
3106 | 3111 |
3107 // Wait for completion callback, and verify that the request ran as expected. | 3112 // Wait for completion callback, and verify that the request ran as expected. |
3108 EXPECT_EQ(OK, callback1.WaitForResult()); | 3113 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
3109 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3114 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3110 | 3115 |
3111 // At this point we have initialized the proxy service using a PAC script. | 3116 // At this point we have initialized the proxy service using a PAC script. |
3112 // | 3117 // |
3113 // A background task to periodically re-check the PAC script for validity will | 3118 // A background task to periodically re-check the PAC script for validity will |
3114 // have been started. We will now wait for the next download attempt to start. | 3119 // have been started. We will now wait for the next download attempt to start. |
3115 // | 3120 // |
3116 // Note that we shouldn't have to wait long here, since our test enables a | 3121 // Note that we shouldn't have to wait long here, since our test enables a |
3117 // special unit-test mode. | 3122 // special unit-test mode. |
3118 fetcher->WaitUntilFetch(); | 3123 fetcher->WaitUntilFetch(); |
(...skipping 15 matching lines...) Expand all Loading... |
3134 | 3139 |
3135 // At this point the ProxyService is still running the same PAC script as | 3140 // At this point the ProxyService is still running the same PAC script as |
3136 // before. | 3141 // before. |
3137 | 3142 |
3138 // Start a second request. | 3143 // Start a second request. |
3139 ProxyInfo info2; | 3144 ProxyInfo info2; |
3140 TestCompletionCallback callback2; | 3145 TestCompletionCallback callback2; |
3141 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 3146 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
3142 &info2, callback2.callback(), nullptr, nullptr, | 3147 &info2, callback2.callback(), nullptr, nullptr, |
3143 BoundNetLog()); | 3148 BoundNetLog()); |
3144 EXPECT_EQ(ERR_IO_PENDING, rv); | 3149 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3145 | 3150 |
3146 // Check that it was sent to the resolver. | 3151 // Check that it was sent to the resolver. |
3147 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3152 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3148 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3153 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
3149 | 3154 |
3150 // Complete the pending second request. | 3155 // Complete the pending second request. |
3151 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3156 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
3152 resolver.pending_requests()[0]->CompleteNow(OK); | 3157 resolver.pending_requests()[0]->CompleteNow(OK); |
3153 | 3158 |
3154 // Wait for completion callback, and verify that the request ran as expected. | 3159 // Wait for completion callback, and verify that the request ran as expected. |
3155 EXPECT_EQ(OK, callback2.WaitForResult()); | 3160 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
3156 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3161 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3157 } | 3162 } |
3158 | 3163 |
3159 // This test verifies that the PAC script specified by the settings is | 3164 // This test verifies that the PAC script specified by the settings is |
3160 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 3165 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
3161 // however at a later time it starts to fail, we should re-configure the | 3166 // however at a later time it starts to fail, we should re-configure the |
3162 // ProxyService to stop using that PAC script. | 3167 // ProxyService to stop using that PAC script. |
3163 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) { | 3168 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) { |
3164 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 3169 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
3165 // runs quickly. | 3170 // runs quickly. |
(...skipping 14 matching lines...) Expand all Loading... |
3180 service.SetProxyScriptFetchers( | 3185 service.SetProxyScriptFetchers( |
3181 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3186 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
3182 | 3187 |
3183 // Start 1 request. | 3188 // Start 1 request. |
3184 | 3189 |
3185 ProxyInfo info1; | 3190 ProxyInfo info1; |
3186 TestCompletionCallback callback1; | 3191 TestCompletionCallback callback1; |
3187 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 3192 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
3188 LOAD_NORMAL, &info1, callback1.callback(), | 3193 LOAD_NORMAL, &info1, callback1.callback(), |
3189 nullptr, nullptr, BoundNetLog()); | 3194 nullptr, nullptr, BoundNetLog()); |
3190 EXPECT_EQ(ERR_IO_PENDING, rv); | 3195 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3191 | 3196 |
3192 // The first request should have triggered initial download of PAC script. | 3197 // The first request should have triggered initial download of PAC script. |
3193 EXPECT_TRUE(fetcher->has_pending_request()); | 3198 EXPECT_TRUE(fetcher->has_pending_request()); |
3194 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3199 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3195 | 3200 |
3196 // Nothing has been sent to the factory yet. | 3201 // Nothing has been sent to the factory yet. |
3197 EXPECT_TRUE(factory->pending_requests().empty()); | 3202 EXPECT_TRUE(factory->pending_requests().empty()); |
3198 | 3203 |
3199 // At this point the ProxyService should be waiting for the | 3204 // At this point the ProxyService should be waiting for the |
3200 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3205 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3201 // PAC script download completion. | 3206 // PAC script download completion. |
3202 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3207 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3203 | 3208 |
3204 // Now that the PAC script is downloaded, the request will have been sent to | 3209 // Now that the PAC script is downloaded, the request will have been sent to |
3205 // the proxy resolver. | 3210 // the proxy resolver. |
3206 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3211 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3207 factory->pending_requests()[0]->script_data()->utf16()); | 3212 factory->pending_requests()[0]->script_data()->utf16()); |
3208 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3213 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3209 | 3214 |
3210 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3215 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3211 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3216 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
3212 | 3217 |
3213 // Complete the pending request. | 3218 // Complete the pending request. |
3214 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3219 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
3215 resolver.pending_requests()[0]->CompleteNow(OK); | 3220 resolver.pending_requests()[0]->CompleteNow(OK); |
3216 | 3221 |
3217 // Wait for completion callback, and verify that the request ran as expected. | 3222 // Wait for completion callback, and verify that the request ran as expected. |
3218 EXPECT_EQ(OK, callback1.WaitForResult()); | 3223 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
3219 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3224 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3220 | 3225 |
3221 // At this point we have initialized the proxy service using a PAC script. | 3226 // At this point we have initialized the proxy service using a PAC script. |
3222 // | 3227 // |
3223 // A background task to periodically re-check the PAC script for validity will | 3228 // A background task to periodically re-check the PAC script for validity will |
3224 // have been started. We will now wait for the next download attempt to start. | 3229 // have been started. We will now wait for the next download attempt to start. |
3225 // | 3230 // |
3226 // Note that we shouldn't have to wait long here, since our test enables a | 3231 // Note that we shouldn't have to wait long here, since our test enables a |
3227 // special unit-test mode. | 3232 // special unit-test mode. |
3228 fetcher->WaitUntilFetch(); | 3233 fetcher->WaitUntilFetch(); |
(...skipping 12 matching lines...) Expand all Loading... |
3241 | 3246 |
3242 // At this point the ProxyService should have re-configured itself to use | 3247 // At this point the ProxyService should have re-configured itself to use |
3243 // DIRECT connections rather than the given proxy resolver. | 3248 // DIRECT connections rather than the given proxy resolver. |
3244 | 3249 |
3245 // Start a second request. | 3250 // Start a second request. |
3246 ProxyInfo info2; | 3251 ProxyInfo info2; |
3247 TestCompletionCallback callback2; | 3252 TestCompletionCallback callback2; |
3248 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 3253 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
3249 &info2, callback2.callback(), nullptr, nullptr, | 3254 &info2, callback2.callback(), nullptr, nullptr, |
3250 BoundNetLog()); | 3255 BoundNetLog()); |
3251 EXPECT_EQ(OK, rv); | 3256 EXPECT_THAT(rv, IsOk()); |
3252 EXPECT_TRUE(info2.is_direct()); | 3257 EXPECT_TRUE(info2.is_direct()); |
3253 } | 3258 } |
3254 | 3259 |
3255 // Tests that the code which decides at what times to poll the PAC | 3260 // Tests that the code which decides at what times to poll the PAC |
3256 // script follows the expected policy. | 3261 // script follows the expected policy. |
3257 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { | 3262 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { |
3258 // Retrieve the internal polling policy implementation used by ProxyService. | 3263 // Retrieve the internal polling policy implementation used by ProxyService. |
3259 std::unique_ptr<ProxyService::PacPollPolicy> policy = | 3264 std::unique_ptr<ProxyService::PacPollPolicy> policy = |
3260 ProxyService::CreateDefaultPacPollPolicy(); | 3265 ProxyService::CreateDefaultPacPollPolicy(); |
3261 | 3266 |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3335 service.SetProxyScriptFetchers( | 3340 service.SetProxyScriptFetchers( |
3336 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3341 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
3337 | 3342 |
3338 // Start 1 request. | 3343 // Start 1 request. |
3339 | 3344 |
3340 ProxyInfo info1; | 3345 ProxyInfo info1; |
3341 TestCompletionCallback callback1; | 3346 TestCompletionCallback callback1; |
3342 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), | 3347 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), |
3343 LOAD_NORMAL, &info1, callback1.callback(), | 3348 LOAD_NORMAL, &info1, callback1.callback(), |
3344 nullptr, nullptr, BoundNetLog()); | 3349 nullptr, nullptr, BoundNetLog()); |
3345 EXPECT_EQ(ERR_IO_PENDING, rv); | 3350 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3346 | 3351 |
3347 // The first request should have triggered initial download of PAC script. | 3352 // The first request should have triggered initial download of PAC script. |
3348 EXPECT_TRUE(fetcher->has_pending_request()); | 3353 EXPECT_TRUE(fetcher->has_pending_request()); |
3349 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3354 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3350 | 3355 |
3351 // Nothing has been sent to the factory yet. | 3356 // Nothing has been sent to the factory yet. |
3352 EXPECT_TRUE(factory->pending_requests().empty()); | 3357 EXPECT_TRUE(factory->pending_requests().empty()); |
3353 | 3358 |
3354 // At this point the ProxyService should be waiting for the | 3359 // At this point the ProxyService should be waiting for the |
3355 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3360 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3356 // PAC script download completion. | 3361 // PAC script download completion. |
3357 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3362 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3358 | 3363 |
3359 // Now that the PAC script is downloaded, the request will have been sent to | 3364 // Now that the PAC script is downloaded, the request will have been sent to |
3360 // the proxy resolver. | 3365 // the proxy resolver. |
3361 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3366 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3362 factory->pending_requests()[0]->script_data()->utf16()); | 3367 factory->pending_requests()[0]->script_data()->utf16()); |
3363 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3368 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3364 | 3369 |
3365 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3370 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3366 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3371 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
3367 | 3372 |
3368 // Complete the pending request. | 3373 // Complete the pending request. |
3369 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3374 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
3370 resolver.pending_requests()[0]->CompleteNow(OK); | 3375 resolver.pending_requests()[0]->CompleteNow(OK); |
3371 | 3376 |
3372 // Wait for completion callback, and verify that the request ran as expected. | 3377 // Wait for completion callback, and verify that the request ran as expected. |
3373 EXPECT_EQ(OK, callback1.WaitForResult()); | 3378 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
3374 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3379 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3375 | 3380 |
3376 // At this point we have initialized the proxy service using a PAC script. | 3381 // At this point we have initialized the proxy service using a PAC script. |
3377 // Our PAC poller is set to update ONLY in response to network activity, | 3382 // Our PAC poller is set to update ONLY in response to network activity, |
3378 // (i.e. another call to ResolveProxy()). | 3383 // (i.e. another call to ResolveProxy()). |
3379 | 3384 |
3380 ASSERT_FALSE(fetcher->has_pending_request()); | 3385 ASSERT_FALSE(fetcher->has_pending_request()); |
3381 ASSERT_TRUE(factory->pending_requests().empty()); | 3386 ASSERT_TRUE(factory->pending_requests().empty()); |
3382 ASSERT_TRUE(resolver.pending_requests().empty()); | 3387 ASSERT_TRUE(resolver.pending_requests().empty()); |
3383 | 3388 |
3384 // Start a second request. | 3389 // Start a second request. |
3385 ProxyInfo info2; | 3390 ProxyInfo info2; |
3386 TestCompletionCallback callback2; | 3391 TestCompletionCallback callback2; |
3387 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, | 3392 rv = service.ResolveProxy(GURL("http://request2"), std::string(), LOAD_NORMAL, |
3388 &info2, callback2.callback(), nullptr, nullptr, | 3393 &info2, callback2.callback(), nullptr, nullptr, |
3389 BoundNetLog()); | 3394 BoundNetLog()); |
3390 EXPECT_EQ(ERR_IO_PENDING, rv); | 3395 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3391 | 3396 |
3392 // This request should have sent work to the resolver; complete it. | 3397 // This request should have sent work to the resolver; complete it. |
3393 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3398 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3394 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3399 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
3395 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3400 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
3396 resolver.pending_requests()[0]->CompleteNow(OK); | 3401 resolver.pending_requests()[0]->CompleteNow(OK); |
3397 | 3402 |
3398 EXPECT_EQ(OK, callback2.WaitForResult()); | 3403 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
3399 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3404 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3400 | 3405 |
3401 // In response to getting that resolve request, the poller should have | 3406 // In response to getting that resolve request, the poller should have |
3402 // started the next poll, and made it as far as to request the download. | 3407 // started the next poll, and made it as far as to request the download. |
3403 | 3408 |
3404 EXPECT_TRUE(fetcher->has_pending_request()); | 3409 EXPECT_TRUE(fetcher->has_pending_request()); |
3405 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3410 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3406 | 3411 |
3407 // This time we will fail the download, to simulate a PAC script change. | 3412 // This time we will fail the download, to simulate a PAC script change. |
3408 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 3413 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
3409 | 3414 |
3410 // Drain the message loop, so ProxyService is notified of the change | 3415 // Drain the message loop, so ProxyService is notified of the change |
3411 // and has a chance to re-configure itself. | 3416 // and has a chance to re-configure itself. |
3412 base::RunLoop().RunUntilIdle(); | 3417 base::RunLoop().RunUntilIdle(); |
3413 | 3418 |
3414 // Start a third request -- this time we expect to get a direct connection | 3419 // Start a third request -- this time we expect to get a direct connection |
3415 // since the PAC script poller experienced a failure. | 3420 // since the PAC script poller experienced a failure. |
3416 ProxyInfo info3; | 3421 ProxyInfo info3; |
3417 TestCompletionCallback callback3; | 3422 TestCompletionCallback callback3; |
3418 rv = service.ResolveProxy(GURL("http://request3"), std::string(), LOAD_NORMAL, | 3423 rv = service.ResolveProxy(GURL("http://request3"), std::string(), LOAD_NORMAL, |
3419 &info3, callback3.callback(), nullptr, nullptr, | 3424 &info3, callback3.callback(), nullptr, nullptr, |
3420 BoundNetLog()); | 3425 BoundNetLog()); |
3421 EXPECT_EQ(OK, rv); | 3426 EXPECT_THAT(rv, IsOk()); |
3422 EXPECT_TRUE(info3.is_direct()); | 3427 EXPECT_TRUE(info3.is_direct()); |
3423 } | 3428 } |
3424 | 3429 |
3425 // Test that the synchronous resolution fails when a PAC script is active. | 3430 // Test that the synchronous resolution fails when a PAC script is active. |
3426 TEST_F(ProxyServiceTest, SynchronousWithPAC) { | 3431 TEST_F(ProxyServiceTest, SynchronousWithPAC) { |
3427 MockProxyConfigService* config_service = | 3432 MockProxyConfigService* config_service = |
3428 new MockProxyConfigService("http://foopy/proxy.pac"); | 3433 new MockProxyConfigService("http://foopy/proxy.pac"); |
3429 | 3434 |
3430 MockAsyncProxyResolverFactory* factory = | 3435 MockAsyncProxyResolverFactory* factory = |
3431 new MockAsyncProxyResolverFactory(false); | 3436 new MockAsyncProxyResolverFactory(false); |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3492 | 3497 |
3493 // Do an initial request to initialize the service (configure the PAC | 3498 // Do an initial request to initialize the service (configure the PAC |
3494 // script). | 3499 // script). |
3495 GURL url("http://example.com"); | 3500 GURL url("http://example.com"); |
3496 | 3501 |
3497 ProxyInfo info; | 3502 ProxyInfo info; |
3498 TestCompletionCallback callback; | 3503 TestCompletionCallback callback; |
3499 int rv = service_->ResolveProxy(url, std::string(), LOAD_NORMAL, &info, | 3504 int rv = service_->ResolveProxy(url, std::string(), LOAD_NORMAL, &info, |
3500 callback.callback(), nullptr, nullptr, | 3505 callback.callback(), nullptr, nullptr, |
3501 BoundNetLog()); | 3506 BoundNetLog()); |
3502 EXPECT_EQ(ERR_IO_PENDING, rv); | 3507 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3503 | 3508 |
3504 // First step is to download the PAC script. | 3509 // First step is to download the PAC script. |
3505 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 3510 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
3506 factory->pending_requests()[0]->script_data()->url()); | 3511 factory->pending_requests()[0]->script_data()->url()); |
3507 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3512 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3508 | 3513 |
3509 EXPECT_EQ(1u, resolver.pending_requests().size()); | 3514 EXPECT_EQ(1u, resolver.pending_requests().size()); |
3510 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 3515 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
3511 | 3516 |
3512 // Complete the request. | 3517 // Complete the request. |
3513 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); | 3518 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); |
3514 resolver.pending_requests()[0]->CompleteNow(OK); | 3519 resolver.pending_requests()[0]->CompleteNow(OK); |
3515 EXPECT_EQ(OK, callback.WaitForResult()); | 3520 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
3516 EXPECT_TRUE(info.is_direct()); | 3521 EXPECT_TRUE(info.is_direct()); |
3517 } | 3522 } |
3518 | 3523 |
3519 // Changes the URL sanitization policy for the underlying ProxyService. This | 3524 // Changes the URL sanitization policy for the underlying ProxyService. This |
3520 // will affect subsequent calls to SanitizeUrl. | 3525 // will affect subsequent calls to SanitizeUrl. |
3521 void SetSanitizeUrlPolicy(ProxyService::SanitizeUrlPolicy policy) { | 3526 void SetSanitizeUrlPolicy(ProxyService::SanitizeUrlPolicy policy) { |
3522 service_->set_sanitize_url_policy(policy); | 3527 service_->set_sanitize_url_policy(policy); |
3523 } | 3528 } |
3524 | 3529 |
3525 // Makes a proxy resolution request through the ProxyService, and returns the | 3530 // Makes a proxy resolution request through the ProxyService, and returns the |
3526 // URL that was submitted to the Proxy Resolver. | 3531 // URL that was submitted to the Proxy Resolver. |
3527 GURL SanitizeUrl(const GURL& raw_url) { | 3532 GURL SanitizeUrl(const GURL& raw_url) { |
3528 // Issue a request and see what URL is sent to the proxy resolver. | 3533 // Issue a request and see what URL is sent to the proxy resolver. |
3529 ProxyInfo info; | 3534 ProxyInfo info; |
3530 TestCompletionCallback callback; | 3535 TestCompletionCallback callback; |
3531 int rv = service_->ResolveProxy(raw_url, std::string(), LOAD_NORMAL, &info, | 3536 int rv = service_->ResolveProxy(raw_url, std::string(), LOAD_NORMAL, &info, |
3532 callback.callback(), nullptr, nullptr, | 3537 callback.callback(), nullptr, nullptr, |
3533 BoundNetLog()); | 3538 BoundNetLog()); |
3534 EXPECT_EQ(ERR_IO_PENDING, rv); | 3539 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3535 | 3540 |
3536 EXPECT_EQ(1u, resolver.pending_requests().size()); | 3541 EXPECT_EQ(1u, resolver.pending_requests().size()); |
3537 | 3542 |
3538 GURL sanitized_url = resolver.pending_requests()[0]->url(); | 3543 GURL sanitized_url = resolver.pending_requests()[0]->url(); |
3539 | 3544 |
3540 // Complete the request. | 3545 // Complete the request. |
3541 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); | 3546 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); |
3542 resolver.pending_requests()[0]->CompleteNow(OK); | 3547 resolver.pending_requests()[0]->CompleteNow(OK); |
3543 EXPECT_EQ(OK, callback.WaitForResult()); | 3548 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
3544 EXPECT_TRUE(info.is_direct()); | 3549 EXPECT_TRUE(info.is_direct()); |
3545 | 3550 |
3546 return sanitized_url; | 3551 return sanitized_url; |
3547 } | 3552 } |
3548 | 3553 |
3549 // Changes the ProxyService's URL sanitization policy and then sanitizes | 3554 // Changes the ProxyService's URL sanitization policy and then sanitizes |
3550 // |raw_url|. | 3555 // |raw_url|. |
3551 GURL SanitizeUrl(const GURL& raw_url, | 3556 GURL SanitizeUrl(const GURL& raw_url, |
3552 ProxyService::SanitizeUrlPolicy policy) { | 3557 ProxyService::SanitizeUrlPolicy policy) { |
3553 service_->set_sanitize_url_policy(policy); | 3558 service_->set_sanitize_url_policy(policy); |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3689 GURL(test.sanitized_url_unstripped), | 3694 GURL(test.sanitized_url_unstripped), |
3690 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); | 3695 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); |
3691 | 3696 |
3692 EXPECT_EQ( | 3697 EXPECT_EQ( |
3693 GURL(test.sanitized_url), | 3698 GURL(test.sanitized_url), |
3694 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); | 3699 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); |
3695 } | 3700 } |
3696 } | 3701 } |
3697 | 3702 |
3698 } // namespace net | 3703 } // namespace net |
OLD | NEW |