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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 new MockAsyncProxyResolverFactory(false); | 562 new MockAsyncProxyResolverFactory(false); |
563 | 563 |
564 ProxyService service(base::WrapUnique(config_service), | 564 ProxyService service(base::WrapUnique(config_service), |
565 base::WrapUnique(factory), nullptr); | 565 base::WrapUnique(factory), nullptr); |
566 | 566 |
567 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 567 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
568 | 568 |
569 ProxyInfo info; | 569 ProxyInfo info; |
570 TestCompletionCallback callback; | 570 TestCompletionCallback callback; |
571 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), | 571 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
572 nullptr, nullptr, BoundNetLog()); | 572 nullptr, nullptr, NetLogWithSource()); |
573 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 573 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
574 | 574 |
575 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 575 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
576 factory->pending_requests()[0]->script_data()->url()); | 576 factory->pending_requests()[0]->script_data()->url()); |
577 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 577 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
578 | 578 |
579 ASSERT_EQ(1u, resolver.pending_requests().size()); | 579 ASSERT_EQ(1u, resolver.pending_requests().size()); |
580 // The URL should have been simplified, stripping the username/password/hash. | 580 // The URL should have been simplified, stripping the username/password/hash. |
581 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 581 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
582 resolver.pending_requests()[0]->url()); | 582 resolver.pending_requests()[0]->url()); |
(...skipping 10 matching lines...) Expand all Loading... |
593 new MockAsyncProxyResolverFactory(false); | 593 new MockAsyncProxyResolverFactory(false); |
594 | 594 |
595 ProxyService service(base::WrapUnique(config_service), | 595 ProxyService service(base::WrapUnique(config_service), |
596 base::WrapUnique(factory), nullptr); | 596 base::WrapUnique(factory), nullptr); |
597 | 597 |
598 GURL url("http://www.google.com/"); | 598 GURL url("http://www.google.com/"); |
599 | 599 |
600 ProxyInfo info; | 600 ProxyInfo info; |
601 TestCompletionCallback callback1; | 601 TestCompletionCallback callback1; |
602 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 602 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
603 nullptr, nullptr, BoundNetLog()); | 603 nullptr, nullptr, NetLogWithSource()); |
604 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 604 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
605 | 605 |
606 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 606 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
607 factory->pending_requests()[0]->script_data()->url()); | 607 factory->pending_requests()[0]->script_data()->url()); |
608 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 608 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
609 | 609 |
610 ASSERT_EQ(1u, resolver.pending_requests().size()); | 610 ASSERT_EQ(1u, resolver.pending_requests().size()); |
611 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 611 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
612 | 612 |
613 // Set the result in proxy resolver. | 613 // Set the result in proxy resolver. |
(...skipping 10 matching lines...) Expand all Loading... |
624 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()); |
625 | 625 |
626 // Now, imagine that connecting to foopy:8080 fails: there is nothing | 626 // Now, imagine that connecting to foopy:8080 fails: there is nothing |
627 // 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 |
628 // DIRECT. | 628 // DIRECT. |
629 TestResolveProxyDelegate proxy_delegate; | 629 TestResolveProxyDelegate proxy_delegate; |
630 TestCompletionCallback callback2; | 630 TestCompletionCallback callback2; |
631 ProxyServer expected_proxy_server = info.proxy_server(); | 631 ProxyServer expected_proxy_server = info.proxy_server(); |
632 rv = service.ReconsiderProxyAfterError( | 632 rv = service.ReconsiderProxyAfterError( |
633 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback2.callback(), | 633 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback2.callback(), |
634 nullptr, &proxy_delegate, BoundNetLog()); | 634 nullptr, &proxy_delegate, NetLogWithSource()); |
635 // ReconsiderProxyAfterError returns error indicating nothing left. | 635 // ReconsiderProxyAfterError returns error indicating nothing left. |
636 EXPECT_THAT(rv, IsError(ERR_FAILED)); | 636 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
637 EXPECT_TRUE(info.is_empty()); | 637 EXPECT_TRUE(info.is_empty()); |
638 } | 638 } |
639 | 639 |
640 // 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 |
641 // 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. |
642 TEST_F(ProxyServiceTest, PAC_RuntimeError) { | 642 TEST_F(ProxyServiceTest, PAC_RuntimeError) { |
643 MockProxyConfigService* config_service = | 643 MockProxyConfigService* config_service = |
644 new MockProxyConfigService("http://foopy/proxy.pac"); | 644 new MockProxyConfigService("http://foopy/proxy.pac"); |
645 MockAsyncProxyResolver resolver; | 645 MockAsyncProxyResolver resolver; |
646 MockAsyncProxyResolverFactory* factory = | 646 MockAsyncProxyResolverFactory* factory = |
647 new MockAsyncProxyResolverFactory(false); | 647 new MockAsyncProxyResolverFactory(false); |
648 | 648 |
649 ProxyService service(base::WrapUnique(config_service), | 649 ProxyService service(base::WrapUnique(config_service), |
650 base::WrapUnique(factory), nullptr); | 650 base::WrapUnique(factory), nullptr); |
651 | 651 |
652 GURL url("http://this-causes-js-error/"); | 652 GURL url("http://this-causes-js-error/"); |
653 | 653 |
654 ProxyInfo info; | 654 ProxyInfo info; |
655 TestCompletionCallback callback1; | 655 TestCompletionCallback callback1; |
656 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 656 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
657 nullptr, nullptr, BoundNetLog()); | 657 nullptr, nullptr, NetLogWithSource()); |
658 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 658 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
659 | 659 |
660 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 660 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
661 factory->pending_requests()[0]->script_data()->url()); | 661 factory->pending_requests()[0]->script_data()->url()); |
662 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 662 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
663 | 663 |
664 ASSERT_EQ(1u, resolver.pending_requests().size()); | 664 ASSERT_EQ(1u, resolver.pending_requests().size()); |
665 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 665 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
666 | 666 |
667 // Simulate a failure in the PAC executor. | 667 // Simulate a failure in the PAC executor. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
705 new MockAsyncProxyResolverFactory(false); | 705 new MockAsyncProxyResolverFactory(false); |
706 | 706 |
707 ProxyService service(base::WrapUnique(config_service), | 707 ProxyService service(base::WrapUnique(config_service), |
708 base::WrapUnique(factory), nullptr); | 708 base::WrapUnique(factory), nullptr); |
709 | 709 |
710 GURL url("http://www.google.com/"); | 710 GURL url("http://www.google.com/"); |
711 | 711 |
712 ProxyInfo info; | 712 ProxyInfo info; |
713 TestCompletionCallback callback1; | 713 TestCompletionCallback callback1; |
714 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 714 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
715 nullptr, nullptr, BoundNetLog()); | 715 nullptr, nullptr, NetLogWithSource()); |
716 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 716 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
717 | 717 |
718 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 718 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
719 factory->pending_requests()[0]->script_data()->url()); | 719 factory->pending_requests()[0]->script_data()->url()); |
720 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 720 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
721 | 721 |
722 ASSERT_EQ(1u, resolver.pending_requests().size()); | 722 ASSERT_EQ(1u, resolver.pending_requests().size()); |
723 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 723 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
724 | 724 |
725 // Set the result in proxy resolver. | 725 // Set the result in proxy resolver. |
726 resolver.pending_requests()[0]->results()->UsePacString( | 726 resolver.pending_requests()[0]->results()->UsePacString( |
727 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 727 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
728 resolver.pending_requests()[0]->CompleteNow(OK); | 728 resolver.pending_requests()[0]->CompleteNow(OK); |
729 | 729 |
730 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 730 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
731 EXPECT_TRUE(info.is_direct()); | 731 EXPECT_TRUE(info.is_direct()); |
732 | 732 |
733 // Fallback 1. | 733 // Fallback 1. |
734 TestCompletionCallback callback2; | 734 TestCompletionCallback callback2; |
735 rv = service.ReconsiderProxyAfterError( | 735 rv = service.ReconsiderProxyAfterError( |
736 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 736 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
737 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 737 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
738 EXPECT_THAT(rv, IsOk()); | 738 EXPECT_THAT(rv, IsOk()); |
739 EXPECT_FALSE(info.is_direct()); | 739 EXPECT_FALSE(info.is_direct()); |
740 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); | 740 EXPECT_EQ("foobar:10", info.proxy_server().ToURI()); |
741 | 741 |
742 // Fallback 2. | 742 // Fallback 2. |
743 TestResolveProxyDelegate proxy_delegate; | 743 TestResolveProxyDelegate proxy_delegate; |
744 ProxyServer expected_proxy_server3 = info.proxy_server(); | 744 ProxyServer expected_proxy_server3 = info.proxy_server(); |
745 TestCompletionCallback callback3; | 745 TestCompletionCallback callback3; |
746 rv = service.ReconsiderProxyAfterError( | 746 rv = service.ReconsiderProxyAfterError( |
747 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback3.callback(), | 747 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback3.callback(), |
748 nullptr, &proxy_delegate, BoundNetLog()); | 748 nullptr, &proxy_delegate, NetLogWithSource()); |
749 EXPECT_THAT(rv, IsOk()); | 749 EXPECT_THAT(rv, IsOk()); |
750 EXPECT_TRUE(info.is_direct()); | 750 EXPECT_TRUE(info.is_direct()); |
751 | 751 |
752 // Fallback 3. | 752 // Fallback 3. |
753 ProxyServer expected_proxy_server4 = info.proxy_server(); | 753 ProxyServer expected_proxy_server4 = info.proxy_server(); |
754 TestCompletionCallback callback4; | 754 TestCompletionCallback callback4; |
755 rv = service.ReconsiderProxyAfterError( | 755 rv = service.ReconsiderProxyAfterError( |
756 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback4.callback(), | 756 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback4.callback(), |
757 nullptr, &proxy_delegate, BoundNetLog()); | 757 nullptr, &proxy_delegate, NetLogWithSource()); |
758 EXPECT_THAT(rv, IsOk()); | 758 EXPECT_THAT(rv, IsOk()); |
759 EXPECT_FALSE(info.is_direct()); | 759 EXPECT_FALSE(info.is_direct()); |
760 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); | 760 EXPECT_EQ("foobar:20", info.proxy_server().ToURI()); |
761 | 761 |
762 // Fallback 4 -- Nothing to fall back to! | 762 // Fallback 4 -- Nothing to fall back to! |
763 ProxyServer expected_proxy_server5 = info.proxy_server(); | 763 ProxyServer expected_proxy_server5 = info.proxy_server(); |
764 TestCompletionCallback callback5; | 764 TestCompletionCallback callback5; |
765 rv = service.ReconsiderProxyAfterError( | 765 rv = service.ReconsiderProxyAfterError( |
766 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback5.callback(), | 766 url, "GET", ERR_PROXY_CONNECTION_FAILED, &info, callback5.callback(), |
767 nullptr, &proxy_delegate, BoundNetLog()); | 767 nullptr, &proxy_delegate, NetLogWithSource()); |
768 EXPECT_THAT(rv, IsError(ERR_FAILED)); | 768 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
769 EXPECT_TRUE(info.is_empty()); | 769 EXPECT_TRUE(info.is_empty()); |
770 } | 770 } |
771 | 771 |
772 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { | 772 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { |
773 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied | 773 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied |
774 // to ProxyInfo after the proxy is resolved via a PAC script. | 774 // to ProxyInfo after the proxy is resolved via a PAC script. |
775 ProxyConfig config = | 775 ProxyConfig config = |
776 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 776 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
777 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 777 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
778 | 778 |
779 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 779 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
780 MockAsyncProxyResolver resolver; | 780 MockAsyncProxyResolver resolver; |
781 MockAsyncProxyResolverFactory* factory = | 781 MockAsyncProxyResolverFactory* factory = |
782 new MockAsyncProxyResolverFactory(false); | 782 new MockAsyncProxyResolverFactory(false); |
783 ProxyService service(base::WrapUnique(config_service), | 783 ProxyService service(base::WrapUnique(config_service), |
784 base::WrapUnique(factory), nullptr); | 784 base::WrapUnique(factory), nullptr); |
785 | 785 |
786 // Resolve something. | 786 // Resolve something. |
787 GURL url("http://www.google.com/"); | 787 GURL url("http://www.google.com/"); |
788 ProxyInfo info; | 788 ProxyInfo info; |
789 TestCompletionCallback callback; | 789 TestCompletionCallback callback; |
790 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), | 790 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
791 nullptr, nullptr, BoundNetLog()); | 791 nullptr, nullptr, NetLogWithSource()); |
792 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); | 792 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
793 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 793 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
794 ASSERT_EQ(1u, resolver.pending_requests().size()); | 794 ASSERT_EQ(1u, resolver.pending_requests().size()); |
795 | 795 |
796 // Set the result in proxy resolver. | 796 // Set the result in proxy resolver. |
797 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 797 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); |
798 resolver.pending_requests()[0]->CompleteNow(OK); | 798 resolver.pending_requests()[0]->CompleteNow(OK); |
799 | 799 |
800 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 800 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
801 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 801 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
(...skipping 17 matching lines...) Expand all Loading... |
819 new MockAsyncProxyResolverFactory(false); | 819 new MockAsyncProxyResolverFactory(false); |
820 | 820 |
821 ProxyService service(base::WrapUnique(config_service), | 821 ProxyService service(base::WrapUnique(config_service), |
822 base::WrapUnique(factory), nullptr); | 822 base::WrapUnique(factory), nullptr); |
823 | 823 |
824 // Start first resolve request. | 824 // Start first resolve request. |
825 GURL url("http://www.google.com/"); | 825 GURL url("http://www.google.com/"); |
826 ProxyInfo info; | 826 ProxyInfo info; |
827 TestCompletionCallback callback1; | 827 TestCompletionCallback callback1; |
828 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 828 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
829 nullptr, nullptr, BoundNetLog()); | 829 nullptr, nullptr, NetLogWithSource()); |
830 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 830 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
831 | 831 |
832 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 832 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
833 factory->pending_requests()[0]->script_data()->url()); | 833 factory->pending_requests()[0]->script_data()->url()); |
834 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 834 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
835 | 835 |
836 ASSERT_EQ(1u, resolver.pending_requests().size()); | 836 ASSERT_EQ(1u, resolver.pending_requests().size()); |
837 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 837 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
838 | 838 |
839 // Fail the first resolve request in MockAsyncProxyResolver. | 839 // Fail the first resolve request in MockAsyncProxyResolver. |
840 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 840 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
841 | 841 |
842 // Although the proxy resolver failed the request, ProxyService implicitly | 842 // Although the proxy resolver failed the request, ProxyService implicitly |
843 // falls-back to DIRECT. | 843 // falls-back to DIRECT. |
844 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 844 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
845 EXPECT_TRUE(info.is_direct()); | 845 EXPECT_TRUE(info.is_direct()); |
846 | 846 |
847 // Failed PAC executions still have proxy resolution times. | 847 // Failed PAC executions still have proxy resolution times. |
848 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 848 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
849 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 849 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
850 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 850 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
851 | 851 |
852 // The second resolve request will try to run through the proxy resolver, | 852 // The second resolve request will try to run through the proxy resolver, |
853 // regardless of whether the first request failed in it. | 853 // regardless of whether the first request failed in it. |
854 TestCompletionCallback callback2; | 854 TestCompletionCallback callback2; |
855 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), | 855 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
856 nullptr, nullptr, BoundNetLog()); | 856 nullptr, nullptr, NetLogWithSource()); |
857 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 857 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
858 | 858 |
859 ASSERT_EQ(1u, resolver.pending_requests().size()); | 859 ASSERT_EQ(1u, resolver.pending_requests().size()); |
860 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 860 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
861 | 861 |
862 // This time we will have the resolver succeed (perhaps the PAC script has | 862 // This time we will have the resolver succeed (perhaps the PAC script has |
863 // a dependency on the current time). | 863 // a dependency on the current time). |
864 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 864 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
865 resolver.pending_requests()[0]->CompleteNow(OK); | 865 resolver.pending_requests()[0]->CompleteNow(OK); |
866 | 866 |
(...skipping 14 matching lines...) Expand all Loading... |
881 new MockAsyncProxyResolverFactory(false); | 881 new MockAsyncProxyResolverFactory(false); |
882 | 882 |
883 ProxyService service(base::WrapUnique(config_service), | 883 ProxyService service(base::WrapUnique(config_service), |
884 base::WrapUnique(factory), nullptr); | 884 base::WrapUnique(factory), nullptr); |
885 | 885 |
886 // Start first resolve request. | 886 // Start first resolve request. |
887 GURL url("http://www.google.com/"); | 887 GURL url("http://www.google.com/"); |
888 ProxyInfo info; | 888 ProxyInfo info; |
889 TestCompletionCallback callback1; | 889 TestCompletionCallback callback1; |
890 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 890 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
891 nullptr, nullptr, BoundNetLog()); | 891 nullptr, nullptr, NetLogWithSource()); |
892 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 892 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
893 | 893 |
894 ASSERT_EQ(1u, factory->pending_requests().size()); | 894 ASSERT_EQ(1u, factory->pending_requests().size()); |
895 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 895 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
896 factory->pending_requests()[0]->script_data()->url()); | 896 factory->pending_requests()[0]->script_data()->url()); |
897 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 897 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
898 | 898 |
899 ASSERT_EQ(1u, resolver.pending_requests().size()); | 899 ASSERT_EQ(1u, resolver.pending_requests().size()); |
900 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 900 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
901 | 901 |
902 // Fail the first resolve request in MockAsyncProxyResolver. | 902 // Fail the first resolve request in MockAsyncProxyResolver. |
903 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 903 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
904 | 904 |
905 // Although the proxy resolver failed the request, ProxyService implicitly | 905 // Although the proxy resolver failed the request, ProxyService implicitly |
906 // falls-back to DIRECT. | 906 // falls-back to DIRECT. |
907 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 907 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
908 EXPECT_TRUE(info.is_direct()); | 908 EXPECT_TRUE(info.is_direct()); |
909 | 909 |
910 // Failed PAC executions still have proxy resolution times. | 910 // Failed PAC executions still have proxy resolution times. |
911 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 911 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
912 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 912 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
913 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 913 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
914 | 914 |
915 // With no other requests, the ProxyService waits for a new request before | 915 // With no other requests, the ProxyService waits for a new request before |
916 // initializing a new ProxyResolver. | 916 // initializing a new ProxyResolver. |
917 EXPECT_TRUE(factory->pending_requests().empty()); | 917 EXPECT_TRUE(factory->pending_requests().empty()); |
918 | 918 |
919 TestCompletionCallback callback2; | 919 TestCompletionCallback callback2; |
920 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), | 920 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
921 nullptr, nullptr, BoundNetLog()); | 921 nullptr, nullptr, NetLogWithSource()); |
922 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 922 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
923 | 923 |
924 ASSERT_EQ(1u, factory->pending_requests().size()); | 924 ASSERT_EQ(1u, factory->pending_requests().size()); |
925 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 925 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
926 factory->pending_requests()[0]->script_data()->url()); | 926 factory->pending_requests()[0]->script_data()->url()); |
927 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 927 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
928 | 928 |
929 ASSERT_EQ(1u, resolver.pending_requests().size()); | 929 ASSERT_EQ(1u, resolver.pending_requests().size()); |
930 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 930 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
931 | 931 |
(...skipping 21 matching lines...) Expand all Loading... |
953 ProxyService service(base::WrapUnique(config_service), | 953 ProxyService service(base::WrapUnique(config_service), |
954 base::WrapUnique(factory), nullptr); | 954 base::WrapUnique(factory), nullptr); |
955 | 955 |
956 // Start two resolve requests. | 956 // Start two resolve requests. |
957 GURL url1("http://www.google.com/"); | 957 GURL url1("http://www.google.com/"); |
958 GURL url2("https://www.google.com/"); | 958 GURL url2("https://www.google.com/"); |
959 ProxyInfo info; | 959 ProxyInfo info; |
960 TestCompletionCallback callback1; | 960 TestCompletionCallback callback1; |
961 int rv = | 961 int rv = |
962 service.ResolveProxy(url1, std::string(), &info, callback1.callback(), | 962 service.ResolveProxy(url1, std::string(), &info, callback1.callback(), |
963 nullptr, nullptr, BoundNetLog()); | 963 nullptr, nullptr, NetLogWithSource()); |
964 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 964 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
965 TestCompletionCallback callback2; | 965 TestCompletionCallback callback2; |
966 rv = service.ResolveProxy(url2, std::string(), &info, callback2.callback(), | 966 rv = service.ResolveProxy(url2, std::string(), &info, callback2.callback(), |
967 nullptr, nullptr, BoundNetLog()); | 967 nullptr, nullptr, NetLogWithSource()); |
968 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 968 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
969 | 969 |
970 ASSERT_EQ(1u, factory->pending_requests().size()); | 970 ASSERT_EQ(1u, factory->pending_requests().size()); |
971 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 971 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
972 factory->pending_requests()[0]->script_data()->url()); | 972 factory->pending_requests()[0]->script_data()->url()); |
973 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 973 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
974 | 974 |
975 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 975 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); |
976 | 976 |
977 // Fail the first resolve request in MockAsyncProxyResolver. | 977 // Fail the first resolve request in MockAsyncProxyResolver. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1022 new MockAsyncProxyResolverFactory(false); | 1022 new MockAsyncProxyResolverFactory(false); |
1023 | 1023 |
1024 ProxyService service(base::WrapUnique(config_service), | 1024 ProxyService service(base::WrapUnique(config_service), |
1025 base::WrapUnique(factory), nullptr); | 1025 base::WrapUnique(factory), nullptr); |
1026 | 1026 |
1027 // Start first resolve request. | 1027 // Start first resolve request. |
1028 GURL url("http://www.google.com/"); | 1028 GURL url("http://www.google.com/"); |
1029 ProxyInfo info; | 1029 ProxyInfo info; |
1030 TestCompletionCallback callback1; | 1030 TestCompletionCallback callback1; |
1031 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1031 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1032 nullptr, nullptr, BoundNetLog()); | 1032 nullptr, nullptr, NetLogWithSource()); |
1033 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1033 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1034 | 1034 |
1035 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1035 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1036 factory->pending_requests()[0]->script_data()->url()); | 1036 factory->pending_requests()[0]->script_data()->url()); |
1037 factory->pending_requests()[0]->CompleteNow(ERR_FAILED, nullptr); | 1037 factory->pending_requests()[0]->CompleteNow(ERR_FAILED, nullptr); |
1038 | 1038 |
1039 ASSERT_EQ(0u, factory->pending_requests().size()); | 1039 ASSERT_EQ(0u, factory->pending_requests().size()); |
1040 // As the proxy resolver factory failed the request and is configured for a | 1040 // As the proxy resolver factory failed the request and is configured for a |
1041 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1041 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1042 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1042 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1043 callback1.WaitForResult()); | 1043 callback1.WaitForResult()); |
1044 EXPECT_FALSE(info.is_direct()); | 1044 EXPECT_FALSE(info.is_direct()); |
1045 | 1045 |
1046 // As the proxy resolver factory failed the request and is configured for a | 1046 // As the proxy resolver factory failed the request and is configured for a |
1047 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1047 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1048 TestCompletionCallback callback2; | 1048 TestCompletionCallback callback2; |
1049 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), | 1049 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
1050 nullptr, nullptr, BoundNetLog()); | 1050 nullptr, nullptr, NetLogWithSource()); |
1051 EXPECT_THAT(rv, IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); | 1051 EXPECT_THAT(rv, IsError(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED)); |
1052 EXPECT_FALSE(info.is_direct()); | 1052 EXPECT_FALSE(info.is_direct()); |
1053 } | 1053 } |
1054 | 1054 |
1055 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 1055 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
1056 // Test what happens when the ProxyResolver fails that is configured to use a | 1056 // Test what happens when the ProxyResolver fails that is configured to use a |
1057 // mandatory PAC script. The download of the PAC script has already | 1057 // mandatory PAC script. The download of the PAC script has already |
1058 // succeeded but the PAC script contains no valid javascript. | 1058 // succeeded but the PAC script contains no valid javascript. |
1059 | 1059 |
1060 ProxyConfig config( | 1060 ProxyConfig config( |
(...skipping 10 matching lines...) Expand all Loading... |
1071 | 1071 |
1072 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1072 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
1073 service.SetProxyScriptFetchers( | 1073 service.SetProxyScriptFetchers( |
1074 fetcher, base::MakeUnique<DoNothingDhcpProxyScriptFetcher>()); | 1074 fetcher, base::MakeUnique<DoNothingDhcpProxyScriptFetcher>()); |
1075 | 1075 |
1076 // Start resolve request. | 1076 // Start resolve request. |
1077 GURL url("http://www.google.com/"); | 1077 GURL url("http://www.google.com/"); |
1078 ProxyInfo info; | 1078 ProxyInfo info; |
1079 TestCompletionCallback callback; | 1079 TestCompletionCallback callback; |
1080 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), | 1080 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
1081 nullptr, nullptr, BoundNetLog()); | 1081 nullptr, nullptr, NetLogWithSource()); |
1082 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1082 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1083 | 1083 |
1084 // Check that nothing has been sent to the proxy resolver factory yet. | 1084 // Check that nothing has been sent to the proxy resolver factory yet. |
1085 ASSERT_EQ(0u, factory->pending_requests().size()); | 1085 ASSERT_EQ(0u, factory->pending_requests().size()); |
1086 | 1086 |
1087 // Downloading the PAC script succeeds. | 1087 // Downloading the PAC script succeeds. |
1088 EXPECT_TRUE(fetcher->has_pending_request()); | 1088 EXPECT_TRUE(fetcher->has_pending_request()); |
1089 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 1089 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
1090 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 1090 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
1091 | 1091 |
(...skipping 25 matching lines...) Expand all Loading... |
1117 new MockAsyncProxyResolverFactory(false); | 1117 new MockAsyncProxyResolverFactory(false); |
1118 | 1118 |
1119 ProxyService service(base::WrapUnique(config_service), | 1119 ProxyService service(base::WrapUnique(config_service), |
1120 base::WrapUnique(factory), nullptr); | 1120 base::WrapUnique(factory), nullptr); |
1121 | 1121 |
1122 // Start first resolve request. | 1122 // Start first resolve request. |
1123 GURL url("http://www.google.com/"); | 1123 GURL url("http://www.google.com/"); |
1124 ProxyInfo info; | 1124 ProxyInfo info; |
1125 TestCompletionCallback callback1; | 1125 TestCompletionCallback callback1; |
1126 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1126 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1127 nullptr, nullptr, BoundNetLog()); | 1127 nullptr, nullptr, NetLogWithSource()); |
1128 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1128 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1129 | 1129 |
1130 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1130 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1131 factory->pending_requests()[0]->script_data()->url()); | 1131 factory->pending_requests()[0]->script_data()->url()); |
1132 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1132 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1133 | 1133 |
1134 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1134 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1135 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1135 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1136 | 1136 |
1137 // Fail the first resolve request in MockAsyncProxyResolver. | 1137 // Fail the first resolve request in MockAsyncProxyResolver. |
1138 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1138 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1139 | 1139 |
1140 // As the proxy resolver failed the request and is configured for a mandatory | 1140 // As the proxy resolver failed the request and is configured for a mandatory |
1141 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1141 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1142 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1142 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1143 callback1.WaitForResult()); | 1143 callback1.WaitForResult()); |
1144 EXPECT_FALSE(info.is_direct()); | 1144 EXPECT_FALSE(info.is_direct()); |
1145 | 1145 |
1146 // The second resolve request will try to run through the proxy resolver, | 1146 // The second resolve request will try to run through the proxy resolver, |
1147 // regardless of whether the first request failed in it. | 1147 // regardless of whether the first request failed in it. |
1148 TestCompletionCallback callback2; | 1148 TestCompletionCallback callback2; |
1149 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), | 1149 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
1150 nullptr, nullptr, BoundNetLog()); | 1150 nullptr, nullptr, NetLogWithSource()); |
1151 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1151 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1152 | 1152 |
1153 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1153 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1154 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1154 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1155 | 1155 |
1156 // This time we will have the resolver succeed (perhaps the PAC script has | 1156 // This time we will have the resolver succeed (perhaps the PAC script has |
1157 // a dependency on the current time). | 1157 // a dependency on the current time). |
1158 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 1158 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
1159 resolver.pending_requests()[0]->CompleteNow(OK); | 1159 resolver.pending_requests()[0]->CompleteNow(OK); |
1160 | 1160 |
(...skipping 15 matching lines...) Expand all Loading... |
1176 | 1176 |
1177 ProxyService service(base::WrapUnique(config_service), | 1177 ProxyService service(base::WrapUnique(config_service), |
1178 base::WrapUnique(factory), nullptr); | 1178 base::WrapUnique(factory), nullptr); |
1179 | 1179 |
1180 GURL url("http://www.google.com/"); | 1180 GURL url("http://www.google.com/"); |
1181 | 1181 |
1182 // Get the proxy information. | 1182 // Get the proxy information. |
1183 ProxyInfo info; | 1183 ProxyInfo info; |
1184 TestCompletionCallback callback1; | 1184 TestCompletionCallback callback1; |
1185 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1185 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1186 nullptr, nullptr, BoundNetLog()); | 1186 nullptr, nullptr, NetLogWithSource()); |
1187 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1187 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1188 | 1188 |
1189 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1189 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1190 factory->pending_requests()[0]->script_data()->url()); | 1190 factory->pending_requests()[0]->script_data()->url()); |
1191 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1191 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1192 | 1192 |
1193 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1193 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1194 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1194 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1195 | 1195 |
1196 // Set the result in proxy resolver. | 1196 // Set the result in proxy resolver. |
1197 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1197 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1198 "foopy1:8080;foopy2:9090"); | 1198 "foopy1:8080;foopy2:9090"); |
1199 resolver.pending_requests()[0]->CompleteNow(OK); | 1199 resolver.pending_requests()[0]->CompleteNow(OK); |
1200 | 1200 |
1201 // The first item is valid. | 1201 // The first item is valid. |
1202 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1202 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1203 EXPECT_FALSE(info.is_direct()); | 1203 EXPECT_FALSE(info.is_direct()); |
1204 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1204 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1205 | 1205 |
1206 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1206 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1207 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1207 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1208 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1208 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1209 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1209 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); |
1210 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); | 1210 base::TimeTicks proxy_resolve_end_time = info.proxy_resolve_end_time(); |
1211 | 1211 |
1212 // Fake an error on the proxy. | 1212 // Fake an error on the proxy. |
1213 TestCompletionCallback callback2; | 1213 TestCompletionCallback callback2; |
1214 rv = service.ReconsiderProxyAfterError( | 1214 rv = service.ReconsiderProxyAfterError( |
1215 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1215 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1216 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1216 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
1217 EXPECT_THAT(rv, IsOk()); | 1217 EXPECT_THAT(rv, IsOk()); |
1218 | 1218 |
1219 // Proxy times should not have been modified by fallback. | 1219 // Proxy times should not have been modified by fallback. |
1220 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1220 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
1221 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1221 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
1222 | 1222 |
1223 // The second proxy should be specified. | 1223 // The second proxy should be specified. |
1224 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1224 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1225 // Report back that the second proxy worked. This will globally mark the | 1225 // Report back that the second proxy worked. This will globally mark the |
1226 // first proxy as bad. | 1226 // first proxy as bad. |
1227 TestProxyFallbackProxyDelegate test_delegate; | 1227 TestProxyFallbackProxyDelegate test_delegate; |
1228 service.ReportSuccess(info, &test_delegate); | 1228 service.ReportSuccess(info, &test_delegate); |
1229 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); | 1229 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); |
1230 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 1230 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
1231 test_delegate.proxy_fallback_net_error()); | 1231 test_delegate.proxy_fallback_net_error()); |
1232 | 1232 |
1233 TestCompletionCallback callback3; | 1233 TestCompletionCallback callback3; |
1234 rv = service.ResolveProxy(url, std::string(), &info, callback3.callback(), | 1234 rv = service.ResolveProxy(url, std::string(), &info, callback3.callback(), |
1235 nullptr, nullptr, BoundNetLog()); | 1235 nullptr, nullptr, NetLogWithSource()); |
1236 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1236 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1237 | 1237 |
1238 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1238 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1239 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1239 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1240 | 1240 |
1241 // Set the result in proxy resolver -- the second result is already known | 1241 // Set the result in proxy resolver -- the second result is already known |
1242 // to be bad, so we will not try to use it initially. | 1242 // to be bad, so we will not try to use it initially. |
1243 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1243 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1244 "foopy3:7070;foopy1:8080;foopy2:9090"); | 1244 "foopy3:7070;foopy1:8080;foopy2:9090"); |
1245 resolver.pending_requests()[0]->CompleteNow(OK); | 1245 resolver.pending_requests()[0]->CompleteNow(OK); |
1246 | 1246 |
1247 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 1247 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
1248 EXPECT_FALSE(info.is_direct()); | 1248 EXPECT_FALSE(info.is_direct()); |
1249 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1249 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1250 | 1250 |
1251 // Proxy times should have been updated, so get them again. | 1251 // Proxy times should have been updated, so get them again. |
1252 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1252 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1253 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1253 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1254 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1254 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1255 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1255 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1256 proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1256 proxy_resolve_start_time = info.proxy_resolve_start_time(); |
1257 proxy_resolve_end_time = info.proxy_resolve_end_time(); | 1257 proxy_resolve_end_time = info.proxy_resolve_end_time(); |
1258 | 1258 |
1259 // We fake another error. It should now try the third one. | 1259 // We fake another error. It should now try the third one. |
1260 TestCompletionCallback callback4; | 1260 TestCompletionCallback callback4; |
1261 rv = service.ReconsiderProxyAfterError( | 1261 rv = service.ReconsiderProxyAfterError( |
1262 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1262 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1263 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1263 callback4.callback(), nullptr, nullptr, NetLogWithSource()); |
1264 EXPECT_THAT(rv, IsOk()); | 1264 EXPECT_THAT(rv, IsOk()); |
1265 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1265 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1266 | 1266 |
1267 // We fake another error. At this point we have tried all of the | 1267 // We fake another error. At this point we have tried all of the |
1268 // proxy servers we thought were valid; next we try the proxy server | 1268 // proxy servers we thought were valid; next we try the proxy server |
1269 // that was in our bad proxies map (foopy1:8080). | 1269 // that was in our bad proxies map (foopy1:8080). |
1270 TestCompletionCallback callback5; | 1270 TestCompletionCallback callback5; |
1271 rv = service.ReconsiderProxyAfterError( | 1271 rv = service.ReconsiderProxyAfterError( |
1272 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1272 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1273 callback5.callback(), nullptr, nullptr, BoundNetLog()); | 1273 callback5.callback(), nullptr, nullptr, NetLogWithSource()); |
1274 EXPECT_THAT(rv, IsOk()); | 1274 EXPECT_THAT(rv, IsOk()); |
1275 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1275 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1276 | 1276 |
1277 // Fake another error, the last proxy is gone, the list should now be empty, | 1277 // Fake another error, the last proxy is gone, the list should now be empty, |
1278 // so there is nothing left to try. | 1278 // so there is nothing left to try. |
1279 TestCompletionCallback callback6; | 1279 TestCompletionCallback callback6; |
1280 rv = service.ReconsiderProxyAfterError( | 1280 rv = service.ReconsiderProxyAfterError( |
1281 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1281 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1282 callback6.callback(), nullptr, nullptr, BoundNetLog()); | 1282 callback6.callback(), nullptr, nullptr, NetLogWithSource()); |
1283 EXPECT_THAT(rv, IsError(ERR_FAILED)); | 1283 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
1284 EXPECT_FALSE(info.is_direct()); | 1284 EXPECT_FALSE(info.is_direct()); |
1285 EXPECT_TRUE(info.is_empty()); | 1285 EXPECT_TRUE(info.is_empty()); |
1286 | 1286 |
1287 // Proxy times should not have been modified by fallback. | 1287 // Proxy times should not have been modified by fallback. |
1288 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1288 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
1289 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1289 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
1290 | 1290 |
1291 // Look up proxies again | 1291 // Look up proxies again |
1292 TestCompletionCallback callback7; | 1292 TestCompletionCallback callback7; |
1293 rv = service.ResolveProxy(url, std::string(), &info, callback7.callback(), | 1293 rv = service.ResolveProxy(url, std::string(), &info, callback7.callback(), |
1294 nullptr, nullptr, BoundNetLog()); | 1294 nullptr, nullptr, NetLogWithSource()); |
1295 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1295 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1296 | 1296 |
1297 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1297 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1298 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1298 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1299 | 1299 |
1300 // This time, the first 3 results have been found to be bad, but only the | 1300 // This time, the first 3 results have been found to be bad, but only the |
1301 // first proxy has been confirmed ... | 1301 // first proxy has been confirmed ... |
1302 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1302 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1303 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 1303 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
1304 resolver.pending_requests()[0]->CompleteNow(OK); | 1304 resolver.pending_requests()[0]->CompleteNow(OK); |
(...skipping 21 matching lines...) Expand all Loading... |
1326 | 1326 |
1327 ProxyService service(base::WrapUnique(config_service), | 1327 ProxyService service(base::WrapUnique(config_service), |
1328 base::WrapUnique(factory), nullptr); | 1328 base::WrapUnique(factory), nullptr); |
1329 | 1329 |
1330 GURL url("http://www.google.com/"); | 1330 GURL url("http://www.google.com/"); |
1331 | 1331 |
1332 // Get the proxy information. | 1332 // Get the proxy information. |
1333 ProxyInfo info; | 1333 ProxyInfo info; |
1334 TestCompletionCallback callback1; | 1334 TestCompletionCallback callback1; |
1335 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1335 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1336 nullptr, nullptr, BoundNetLog()); | 1336 nullptr, nullptr, NetLogWithSource()); |
1337 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1337 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1338 | 1338 |
1339 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1339 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1340 factory->pending_requests()[0]->script_data()->url()); | 1340 factory->pending_requests()[0]->script_data()->url()); |
1341 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1341 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1342 | 1342 |
1343 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1343 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1344 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1344 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1345 | 1345 |
1346 // Set the result in proxy resolver. | 1346 // Set the result in proxy resolver. |
1347 resolver.pending_requests()[0]->results()->UsePacString( | 1347 resolver.pending_requests()[0]->results()->UsePacString( |
1348 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 1348 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
1349 resolver.pending_requests()[0]->CompleteNow(OK); | 1349 resolver.pending_requests()[0]->CompleteNow(OK); |
1350 | 1350 |
1351 // Get the first result. | 1351 // Get the first result. |
1352 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1352 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1353 EXPECT_FALSE(info.is_direct()); | 1353 EXPECT_FALSE(info.is_direct()); |
1354 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1354 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1355 | 1355 |
1356 // Fake an error on the proxy. | 1356 // Fake an error on the proxy. |
1357 TestCompletionCallback callback2; | 1357 TestCompletionCallback callback2; |
1358 rv = service.ReconsiderProxyAfterError( | 1358 rv = service.ReconsiderProxyAfterError( |
1359 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1359 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1360 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1360 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
1361 EXPECT_THAT(rv, IsOk()); | 1361 EXPECT_THAT(rv, IsOk()); |
1362 | 1362 |
1363 // Now we get back the second proxy. | 1363 // Now we get back the second proxy. |
1364 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1364 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1365 | 1365 |
1366 // Fake an error on this proxy as well. | 1366 // Fake an error on this proxy as well. |
1367 TestCompletionCallback callback3; | 1367 TestCompletionCallback callback3; |
1368 rv = service.ReconsiderProxyAfterError( | 1368 rv = service.ReconsiderProxyAfterError( |
1369 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1369 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1370 callback3.callback(), nullptr, nullptr, BoundNetLog()); | 1370 callback3.callback(), nullptr, nullptr, NetLogWithSource()); |
1371 EXPECT_THAT(rv, IsOk()); | 1371 EXPECT_THAT(rv, IsOk()); |
1372 | 1372 |
1373 // Finally, we get back DIRECT. | 1373 // Finally, we get back DIRECT. |
1374 EXPECT_TRUE(info.is_direct()); | 1374 EXPECT_TRUE(info.is_direct()); |
1375 | 1375 |
1376 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1376 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1377 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1377 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1378 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1378 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1379 | 1379 |
1380 // Now we tell the proxy service that even DIRECT failed. | 1380 // Now we tell the proxy service that even DIRECT failed. |
1381 TestCompletionCallback callback4; | 1381 TestCompletionCallback callback4; |
1382 rv = service.ReconsiderProxyAfterError( | 1382 rv = service.ReconsiderProxyAfterError( |
1383 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1383 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1384 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1384 callback4.callback(), nullptr, nullptr, NetLogWithSource()); |
1385 // There was nothing left to try after DIRECT, so we are out of | 1385 // There was nothing left to try after DIRECT, so we are out of |
1386 // choices. | 1386 // choices. |
1387 EXPECT_THAT(rv, IsError(ERR_FAILED)); | 1387 EXPECT_THAT(rv, IsError(ERR_FAILED)); |
1388 } | 1388 } |
1389 | 1389 |
1390 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { | 1390 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { |
1391 // Test proxy failover when new settings are available. | 1391 // Test proxy failover when new settings are available. |
1392 | 1392 |
1393 MockProxyConfigService* config_service = | 1393 MockProxyConfigService* config_service = |
1394 new MockProxyConfigService("http://foopy/proxy.pac"); | 1394 new MockProxyConfigService("http://foopy/proxy.pac"); |
1395 | 1395 |
1396 MockAsyncProxyResolver resolver; | 1396 MockAsyncProxyResolver resolver; |
1397 MockAsyncProxyResolverFactory* factory = | 1397 MockAsyncProxyResolverFactory* factory = |
1398 new MockAsyncProxyResolverFactory(false); | 1398 new MockAsyncProxyResolverFactory(false); |
1399 | 1399 |
1400 ProxyService service(base::WrapUnique(config_service), | 1400 ProxyService service(base::WrapUnique(config_service), |
1401 base::WrapUnique(factory), nullptr); | 1401 base::WrapUnique(factory), nullptr); |
1402 | 1402 |
1403 GURL url("http://www.google.com/"); | 1403 GURL url("http://www.google.com/"); |
1404 | 1404 |
1405 // Get the proxy information. | 1405 // Get the proxy information. |
1406 ProxyInfo info; | 1406 ProxyInfo info; |
1407 TestCompletionCallback callback1; | 1407 TestCompletionCallback callback1; |
1408 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1408 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1409 nullptr, nullptr, BoundNetLog()); | 1409 nullptr, nullptr, NetLogWithSource()); |
1410 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1410 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1411 | 1411 |
1412 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1412 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1413 factory->pending_requests()[0]->script_data()->url()); | 1413 factory->pending_requests()[0]->script_data()->url()); |
1414 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1414 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1415 | 1415 |
1416 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1416 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1417 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1417 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1418 | 1418 |
1419 // Set the result in proxy resolver. | 1419 // Set the result in proxy resolver. |
1420 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1420 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1421 "foopy1:8080;foopy2:9090"); | 1421 "foopy1:8080;foopy2:9090"); |
1422 resolver.pending_requests()[0]->CompleteNow(OK); | 1422 resolver.pending_requests()[0]->CompleteNow(OK); |
1423 | 1423 |
1424 // The first item is valid. | 1424 // The first item is valid. |
1425 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1425 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1426 EXPECT_FALSE(info.is_direct()); | 1426 EXPECT_FALSE(info.is_direct()); |
1427 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1427 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1428 | 1428 |
1429 // Fake an error on the proxy, and also a new configuration on the proxy. | 1429 // Fake an error on the proxy, and also a new configuration on the proxy. |
1430 config_service->SetConfig( | 1430 config_service->SetConfig( |
1431 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 1431 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
1432 | 1432 |
1433 TestCompletionCallback callback2; | 1433 TestCompletionCallback callback2; |
1434 rv = service.ReconsiderProxyAfterError( | 1434 rv = service.ReconsiderProxyAfterError( |
1435 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1435 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1436 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1436 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
1437 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1437 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1438 | 1438 |
1439 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 1439 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
1440 factory->pending_requests()[0]->script_data()->url()); | 1440 factory->pending_requests()[0]->script_data()->url()); |
1441 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1441 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1442 | 1442 |
1443 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1443 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1444 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1444 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1445 | 1445 |
1446 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1446 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1447 "foopy1:8080;foopy2:9090"); | 1447 "foopy1:8080;foopy2:9090"); |
1448 resolver.pending_requests()[0]->CompleteNow(OK); | 1448 resolver.pending_requests()[0]->CompleteNow(OK); |
1449 | 1449 |
1450 // The first proxy is still there since the configuration changed. | 1450 // The first proxy is still there since the configuration changed. |
1451 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 1451 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
1452 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1452 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1453 | 1453 |
1454 // We fake another error. It should now ignore the first one. | 1454 // We fake another error. It should now ignore the first one. |
1455 TestCompletionCallback callback3; | 1455 TestCompletionCallback callback3; |
1456 rv = service.ReconsiderProxyAfterError( | 1456 rv = service.ReconsiderProxyAfterError( |
1457 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1457 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1458 callback3.callback(), nullptr, nullptr, BoundNetLog()); | 1458 callback3.callback(), nullptr, nullptr, NetLogWithSource()); |
1459 EXPECT_THAT(rv, IsOk()); | 1459 EXPECT_THAT(rv, IsOk()); |
1460 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1460 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1461 | 1461 |
1462 // We simulate a new configuration. | 1462 // We simulate a new configuration. |
1463 config_service->SetConfig( | 1463 config_service->SetConfig( |
1464 ProxyConfig::CreateFromCustomPacURL( | 1464 ProxyConfig::CreateFromCustomPacURL( |
1465 GURL("http://foopy-new2/proxy.pac"))); | 1465 GURL("http://foopy-new2/proxy.pac"))); |
1466 | 1466 |
1467 // We fake another error. It should go back to the first proxy. | 1467 // We fake another error. It should go back to the first proxy. |
1468 TestCompletionCallback callback4; | 1468 TestCompletionCallback callback4; |
1469 rv = service.ReconsiderProxyAfterError( | 1469 rv = service.ReconsiderProxyAfterError( |
1470 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1470 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1471 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1471 callback4.callback(), nullptr, nullptr, NetLogWithSource()); |
1472 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1472 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1473 | 1473 |
1474 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 1474 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
1475 factory->pending_requests()[0]->script_data()->url()); | 1475 factory->pending_requests()[0]->script_data()->url()); |
1476 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1476 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1477 | 1477 |
1478 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1478 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1479 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1479 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1480 | 1480 |
1481 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1481 resolver.pending_requests()[0]->results()->UseNamedProxy( |
(...skipping 20 matching lines...) Expand all Loading... |
1502 | 1502 |
1503 ProxyService service(base::WrapUnique(config_service), | 1503 ProxyService service(base::WrapUnique(config_service), |
1504 base::WrapUnique(factory), nullptr); | 1504 base::WrapUnique(factory), nullptr); |
1505 | 1505 |
1506 GURL url("http://www.google.com/"); | 1506 GURL url("http://www.google.com/"); |
1507 | 1507 |
1508 // Get the proxy information. | 1508 // Get the proxy information. |
1509 ProxyInfo info; | 1509 ProxyInfo info; |
1510 TestCompletionCallback callback1; | 1510 TestCompletionCallback callback1; |
1511 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1511 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1512 nullptr, nullptr, BoundNetLog()); | 1512 nullptr, nullptr, NetLogWithSource()); |
1513 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1513 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1514 | 1514 |
1515 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1515 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1516 factory->pending_requests()[0]->script_data()->url()); | 1516 factory->pending_requests()[0]->script_data()->url()); |
1517 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1517 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1518 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1518 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1519 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1519 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1520 | 1520 |
1521 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1521 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1522 "foopy1:8080;foopy2:9090"); | 1522 "foopy1:8080;foopy2:9090"); |
1523 resolver.pending_requests()[0]->CompleteNow(OK); | 1523 resolver.pending_requests()[0]->CompleteNow(OK); |
1524 | 1524 |
1525 // The first item is valid. | 1525 // The first item is valid. |
1526 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1526 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1527 EXPECT_FALSE(info.is_direct()); | 1527 EXPECT_FALSE(info.is_direct()); |
1528 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1528 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1529 | 1529 |
1530 // Fake a proxy error. | 1530 // Fake a proxy error. |
1531 TestCompletionCallback callback2; | 1531 TestCompletionCallback callback2; |
1532 rv = service.ReconsiderProxyAfterError( | 1532 rv = service.ReconsiderProxyAfterError( |
1533 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1533 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1534 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1534 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
1535 EXPECT_THAT(rv, IsOk()); | 1535 EXPECT_THAT(rv, IsOk()); |
1536 | 1536 |
1537 // The first proxy is ignored, and the second one is selected. | 1537 // The first proxy is ignored, and the second one is selected. |
1538 EXPECT_FALSE(info.is_direct()); | 1538 EXPECT_FALSE(info.is_direct()); |
1539 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1539 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1540 | 1540 |
1541 // Fake a PAC failure. | 1541 // Fake a PAC failure. |
1542 ProxyInfo info2; | 1542 ProxyInfo info2; |
1543 TestCompletionCallback callback3; | 1543 TestCompletionCallback callback3; |
1544 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), | 1544 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), |
1545 nullptr, nullptr, BoundNetLog()); | 1545 nullptr, nullptr, NetLogWithSource()); |
1546 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1546 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1547 | 1547 |
1548 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1548 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1549 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1549 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1550 | 1550 |
1551 // This simulates a javascript runtime error in the PAC script. | 1551 // This simulates a javascript runtime error in the PAC script. |
1552 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1552 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1553 | 1553 |
1554 // Although the resolver failed, the ProxyService will implicitly fall-back | 1554 // Although the resolver failed, the ProxyService will implicitly fall-back |
1555 // to a DIRECT connection. | 1555 // to a DIRECT connection. |
1556 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 1556 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
1557 EXPECT_TRUE(info2.is_direct()); | 1557 EXPECT_TRUE(info2.is_direct()); |
1558 EXPECT_FALSE(info2.is_empty()); | 1558 EXPECT_FALSE(info2.is_empty()); |
1559 | 1559 |
1560 // The PAC script will work properly next time and successfully return a | 1560 // The PAC script will work properly next time and successfully return a |
1561 // proxy list. Since we have not marked the configuration as bad, it should | 1561 // proxy list. Since we have not marked the configuration as bad, it should |
1562 // "just work" the next time we call it. | 1562 // "just work" the next time we call it. |
1563 ProxyInfo info3; | 1563 ProxyInfo info3; |
1564 TestCompletionCallback callback4; | 1564 TestCompletionCallback callback4; |
1565 rv = service.ReconsiderProxyAfterError( | 1565 rv = service.ReconsiderProxyAfterError( |
1566 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, | 1566 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, |
1567 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1567 callback4.callback(), nullptr, nullptr, NetLogWithSource()); |
1568 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1568 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1569 | 1569 |
1570 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1570 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1571 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1571 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1572 | 1572 |
1573 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1573 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1574 "foopy1:8080;foopy2:9090"); | 1574 "foopy1:8080;foopy2:9090"); |
1575 resolver.pending_requests()[0]->CompleteNow(OK); | 1575 resolver.pending_requests()[0]->CompleteNow(OK); |
1576 | 1576 |
1577 // The first proxy is not there since the it was added to the bad proxies | 1577 // The first proxy is not there since the it was added to the bad proxies |
(...skipping 22 matching lines...) Expand all Loading... |
1600 | 1600 |
1601 ProxyService service(base::WrapUnique(config_service), | 1601 ProxyService service(base::WrapUnique(config_service), |
1602 base::WrapUnique(factory), nullptr); | 1602 base::WrapUnique(factory), nullptr); |
1603 | 1603 |
1604 GURL url("http://www.google.com/"); | 1604 GURL url("http://www.google.com/"); |
1605 | 1605 |
1606 // Get the proxy information. | 1606 // Get the proxy information. |
1607 ProxyInfo info; | 1607 ProxyInfo info; |
1608 TestCompletionCallback callback1; | 1608 TestCompletionCallback callback1; |
1609 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1609 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1610 nullptr, nullptr, BoundNetLog()); | 1610 nullptr, nullptr, NetLogWithSource()); |
1611 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1611 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1612 | 1612 |
1613 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1613 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1614 factory->pending_requests()[0]->script_data()->url()); | 1614 factory->pending_requests()[0]->script_data()->url()); |
1615 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1615 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1616 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1616 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1617 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1617 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1618 | 1618 |
1619 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1619 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1620 "foopy1:8080;foopy2:9090"); | 1620 "foopy1:8080;foopy2:9090"); |
1621 resolver.pending_requests()[0]->CompleteNow(OK); | 1621 resolver.pending_requests()[0]->CompleteNow(OK); |
1622 | 1622 |
1623 // The first item is valid. | 1623 // The first item is valid. |
1624 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1624 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1625 EXPECT_FALSE(info.is_direct()); | 1625 EXPECT_FALSE(info.is_direct()); |
1626 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1626 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1627 | 1627 |
1628 // Fake a proxy error. | 1628 // Fake a proxy error. |
1629 TestCompletionCallback callback2; | 1629 TestCompletionCallback callback2; |
1630 rv = service.ReconsiderProxyAfterError( | 1630 rv = service.ReconsiderProxyAfterError( |
1631 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1631 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1632 callback2.callback(), nullptr, nullptr, BoundNetLog()); | 1632 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
1633 EXPECT_THAT(rv, IsOk()); | 1633 EXPECT_THAT(rv, IsOk()); |
1634 | 1634 |
1635 // The first proxy is ignored, and the second one is selected. | 1635 // The first proxy is ignored, and the second one is selected. |
1636 EXPECT_FALSE(info.is_direct()); | 1636 EXPECT_FALSE(info.is_direct()); |
1637 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1637 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1638 | 1638 |
1639 // Fake a PAC failure. | 1639 // Fake a PAC failure. |
1640 ProxyInfo info2; | 1640 ProxyInfo info2; |
1641 TestCompletionCallback callback3; | 1641 TestCompletionCallback callback3; |
1642 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), | 1642 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), |
1643 nullptr, nullptr, BoundNetLog()); | 1643 nullptr, nullptr, NetLogWithSource()); |
1644 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1644 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1645 | 1645 |
1646 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1646 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1647 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1647 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1648 | 1648 |
1649 // This simulates a javascript runtime error in the PAC script. | 1649 // This simulates a javascript runtime error in the PAC script. |
1650 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1650 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1651 | 1651 |
1652 // Although the resolver failed, the ProxyService will NOT fall-back | 1652 // Although the resolver failed, the ProxyService will NOT fall-back |
1653 // to a DIRECT connection as it is configured as mandatory. | 1653 // to a DIRECT connection as it is configured as mandatory. |
1654 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1654 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1655 callback3.WaitForResult()); | 1655 callback3.WaitForResult()); |
1656 EXPECT_FALSE(info2.is_direct()); | 1656 EXPECT_FALSE(info2.is_direct()); |
1657 EXPECT_TRUE(info2.is_empty()); | 1657 EXPECT_TRUE(info2.is_empty()); |
1658 | 1658 |
1659 // The PAC script will work properly next time and successfully return a | 1659 // The PAC script will work properly next time and successfully return a |
1660 // proxy list. Since we have not marked the configuration as bad, it should | 1660 // proxy list. Since we have not marked the configuration as bad, it should |
1661 // "just work" the next time we call it. | 1661 // "just work" the next time we call it. |
1662 ProxyInfo info3; | 1662 ProxyInfo info3; |
1663 TestCompletionCallback callback4; | 1663 TestCompletionCallback callback4; |
1664 rv = service.ReconsiderProxyAfterError( | 1664 rv = service.ReconsiderProxyAfterError( |
1665 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, | 1665 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, |
1666 callback4.callback(), nullptr, nullptr, BoundNetLog()); | 1666 callback4.callback(), nullptr, nullptr, NetLogWithSource()); |
1667 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1667 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1668 | 1668 |
1669 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1669 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1670 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1670 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1671 | 1671 |
1672 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1672 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1673 "foopy1:8080;foopy2:9090"); | 1673 "foopy1:8080;foopy2:9090"); |
1674 resolver.pending_requests()[0]->CompleteNow(OK); | 1674 resolver.pending_requests()[0]->CompleteNow(OK); |
1675 | 1675 |
1676 // The first proxy is not there since the it was added to the bad proxies | 1676 // The first proxy is not there since the it was added to the bad proxies |
(...skipping 16 matching lines...) Expand all Loading... |
1693 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1693 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1694 nullptr, nullptr); | 1694 nullptr, nullptr); |
1695 | 1695 |
1696 int rv; | 1696 int rv; |
1697 GURL url1("http://www.webkit.org"); | 1697 GURL url1("http://www.webkit.org"); |
1698 GURL url2("http://www.webkit.com"); | 1698 GURL url2("http://www.webkit.com"); |
1699 | 1699 |
1700 // Request for a .org domain should bypass proxy. | 1700 // Request for a .org domain should bypass proxy. |
1701 rv = service.ResolveProxy(url1, std::string(), &info[0], | 1701 rv = service.ResolveProxy(url1, std::string(), &info[0], |
1702 callback[0].callback(), nullptr, nullptr, | 1702 callback[0].callback(), nullptr, nullptr, |
1703 BoundNetLog()); | 1703 NetLogWithSource()); |
1704 EXPECT_THAT(rv, IsOk()); | 1704 EXPECT_THAT(rv, IsOk()); |
1705 EXPECT_TRUE(info[0].is_direct()); | 1705 EXPECT_TRUE(info[0].is_direct()); |
1706 | 1706 |
1707 // Request for a .com domain hits the proxy. | 1707 // Request for a .com domain hits the proxy. |
1708 rv = service.ResolveProxy(url2, std::string(), &info[1], | 1708 rv = service.ResolveProxy(url2, std::string(), &info[1], |
1709 callback[1].callback(), nullptr, nullptr, | 1709 callback[1].callback(), nullptr, nullptr, |
1710 BoundNetLog()); | 1710 NetLogWithSource()); |
1711 EXPECT_THAT(rv, IsOk()); | 1711 EXPECT_THAT(rv, IsOk()); |
1712 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); | 1712 EXPECT_EQ("foopy1:8080", info[1].proxy_server().ToURI()); |
1713 } | 1713 } |
1714 | 1714 |
1715 TEST_F(ProxyServiceTest, MarkProxiesAsBadTests) { | 1715 TEST_F(ProxyServiceTest, MarkProxiesAsBadTests) { |
1716 ProxyConfig config; | 1716 ProxyConfig config; |
1717 config.proxy_rules().ParseFromString( | 1717 config.proxy_rules().ParseFromString( |
1718 "http=foopy1:8080;http=foopy2:8080;http=foopy3.8080;http=foopy4:8080"); | 1718 "http=foopy1:8080;http=foopy2:8080;http=foopy3.8080;http=foopy4:8080"); |
1719 config.set_auto_detect(false); | 1719 config.set_auto_detect(false); |
1720 | 1720 |
1721 ProxyList proxy_list; | 1721 ProxyList proxy_list; |
1722 std::vector<ProxyServer> additional_bad_proxies; | 1722 std::vector<ProxyServer> additional_bad_proxies; |
1723 for (const ProxyServer& proxy_server : | 1723 for (const ProxyServer& proxy_server : |
1724 config.proxy_rules().proxies_for_http.GetAll()) { | 1724 config.proxy_rules().proxies_for_http.GetAll()) { |
1725 proxy_list.AddProxyServer(proxy_server); | 1725 proxy_list.AddProxyServer(proxy_server); |
1726 if (proxy_server == config.proxy_rules().proxies_for_http.Get()) | 1726 if (proxy_server == config.proxy_rules().proxies_for_http.Get()) |
1727 continue; | 1727 continue; |
1728 | 1728 |
1729 additional_bad_proxies.push_back(proxy_server); | 1729 additional_bad_proxies.push_back(proxy_server); |
1730 } | 1730 } |
1731 | 1731 |
1732 EXPECT_EQ(3u, additional_bad_proxies.size()); | 1732 EXPECT_EQ(3u, additional_bad_proxies.size()); |
1733 | 1733 |
1734 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1734 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1735 nullptr, nullptr); | 1735 nullptr, nullptr); |
1736 ProxyInfo proxy_info; | 1736 ProxyInfo proxy_info; |
1737 proxy_info.UseProxyList(proxy_list); | 1737 proxy_info.UseProxyList(proxy_list); |
1738 const ProxyRetryInfoMap& retry_info = service.proxy_retry_info(); | 1738 const ProxyRetryInfoMap& retry_info = service.proxy_retry_info(); |
1739 service.MarkProxiesAsBadUntil(proxy_info, base::TimeDelta::FromSeconds(1), | 1739 service.MarkProxiesAsBadUntil(proxy_info, base::TimeDelta::FromSeconds(1), |
1740 additional_bad_proxies, BoundNetLog()); | 1740 additional_bad_proxies, NetLogWithSource()); |
1741 ASSERT_EQ(4u, retry_info.size()); | 1741 ASSERT_EQ(4u, retry_info.size()); |
1742 for (const ProxyServer& proxy_server : | 1742 for (const ProxyServer& proxy_server : |
1743 config.proxy_rules().proxies_for_http.GetAll()) { | 1743 config.proxy_rules().proxies_for_http.GetAll()) { |
1744 ProxyRetryInfoMap::const_iterator i = | 1744 ProxyRetryInfoMap::const_iterator i = |
1745 retry_info.find(proxy_server.host_port_pair().ToString()); | 1745 retry_info.find(proxy_server.host_port_pair().ToString()); |
1746 ASSERT_TRUE(i != retry_info.end()); | 1746 ASSERT_TRUE(i != retry_info.end()); |
1747 } | 1747 } |
1748 } | 1748 } |
1749 | 1749 |
1750 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { | 1750 TEST_F(ProxyServiceTest, PerProtocolProxyTests) { |
1751 ProxyConfig config; | 1751 ProxyConfig config; |
1752 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); | 1752 config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080"); |
1753 config.set_auto_detect(false); | 1753 config.set_auto_detect(false); |
1754 { | 1754 { |
1755 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1755 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1756 nullptr, nullptr); | 1756 nullptr, nullptr); |
1757 GURL test_url("http://www.msn.com"); | 1757 GURL test_url("http://www.msn.com"); |
1758 ProxyInfo info; | 1758 ProxyInfo info; |
1759 TestCompletionCallback callback; | 1759 TestCompletionCallback callback; |
1760 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1760 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1761 callback.callback(), nullptr, nullptr, | 1761 callback.callback(), nullptr, nullptr, |
1762 BoundNetLog()); | 1762 NetLogWithSource()); |
1763 EXPECT_THAT(rv, IsOk()); | 1763 EXPECT_THAT(rv, IsOk()); |
1764 EXPECT_FALSE(info.is_direct()); | 1764 EXPECT_FALSE(info.is_direct()); |
1765 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1765 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1766 } | 1766 } |
1767 { | 1767 { |
1768 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1768 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1769 nullptr, nullptr); | 1769 nullptr, nullptr); |
1770 GURL test_url("ftp://ftp.google.com"); | 1770 GURL test_url("ftp://ftp.google.com"); |
1771 ProxyInfo info; | 1771 ProxyInfo info; |
1772 TestCompletionCallback callback; | 1772 TestCompletionCallback callback; |
1773 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1773 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1774 callback.callback(), nullptr, nullptr, | 1774 callback.callback(), nullptr, nullptr, |
1775 BoundNetLog()); | 1775 NetLogWithSource()); |
1776 EXPECT_THAT(rv, IsOk()); | 1776 EXPECT_THAT(rv, IsOk()); |
1777 EXPECT_TRUE(info.is_direct()); | 1777 EXPECT_TRUE(info.is_direct()); |
1778 EXPECT_EQ("direct://", info.proxy_server().ToURI()); | 1778 EXPECT_EQ("direct://", info.proxy_server().ToURI()); |
1779 } | 1779 } |
1780 { | 1780 { |
1781 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1781 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1782 nullptr, nullptr); | 1782 nullptr, nullptr); |
1783 GURL test_url("https://webbranch.techcu.com"); | 1783 GURL test_url("https://webbranch.techcu.com"); |
1784 ProxyInfo info; | 1784 ProxyInfo info; |
1785 TestCompletionCallback callback; | 1785 TestCompletionCallback callback; |
1786 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1786 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1787 callback.callback(), nullptr, nullptr, | 1787 callback.callback(), nullptr, nullptr, |
1788 BoundNetLog()); | 1788 NetLogWithSource()); |
1789 EXPECT_THAT(rv, IsOk()); | 1789 EXPECT_THAT(rv, IsOk()); |
1790 EXPECT_FALSE(info.is_direct()); | 1790 EXPECT_FALSE(info.is_direct()); |
1791 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 1791 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
1792 } | 1792 } |
1793 { | 1793 { |
1794 config.proxy_rules().ParseFromString("foopy1:8080"); | 1794 config.proxy_rules().ParseFromString("foopy1:8080"); |
1795 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1795 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1796 nullptr, nullptr); | 1796 nullptr, nullptr); |
1797 GURL test_url("http://www.microsoft.com"); | 1797 GURL test_url("http://www.microsoft.com"); |
1798 ProxyInfo info; | 1798 ProxyInfo info; |
1799 TestCompletionCallback callback; | 1799 TestCompletionCallback callback; |
1800 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1800 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1801 callback.callback(), nullptr, nullptr, | 1801 callback.callback(), nullptr, nullptr, |
1802 BoundNetLog()); | 1802 NetLogWithSource()); |
1803 EXPECT_THAT(rv, IsOk()); | 1803 EXPECT_THAT(rv, IsOk()); |
1804 EXPECT_FALSE(info.is_direct()); | 1804 EXPECT_FALSE(info.is_direct()); |
1805 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1805 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1806 } | 1806 } |
1807 } | 1807 } |
1808 | 1808 |
1809 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { | 1809 TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) { |
1810 // Test that the proxy config source is set correctly when resolving proxies | 1810 // Test that the proxy config source is set correctly when resolving proxies |
1811 // using manual proxy rules. Namely, the config source should only be set if | 1811 // using manual proxy rules. Namely, the config source should only be set if |
1812 // any of the rules were applied. | 1812 // any of the rules were applied. |
1813 { | 1813 { |
1814 ProxyConfig config; | 1814 ProxyConfig config; |
1815 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1815 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1816 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1816 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1817 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1817 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1818 nullptr, nullptr); | 1818 nullptr, nullptr); |
1819 GURL test_url("http://www.google.com"); | 1819 GURL test_url("http://www.google.com"); |
1820 ProxyInfo info; | 1820 ProxyInfo info; |
1821 TestCompletionCallback callback; | 1821 TestCompletionCallback callback; |
1822 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1822 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1823 callback.callback(), nullptr, nullptr, | 1823 callback.callback(), nullptr, nullptr, |
1824 BoundNetLog()); | 1824 NetLogWithSource()); |
1825 ASSERT_THAT(rv, IsOk()); | 1825 ASSERT_THAT(rv, IsOk()); |
1826 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. | 1826 // Should be SOURCE_TEST, even if there are no HTTP proxies configured. |
1827 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1827 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1828 } | 1828 } |
1829 { | 1829 { |
1830 ProxyConfig config; | 1830 ProxyConfig config; |
1831 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1831 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1832 config.proxy_rules().ParseFromString("https=foopy2:8080"); | 1832 config.proxy_rules().ParseFromString("https=foopy2:8080"); |
1833 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1833 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1834 nullptr, nullptr); | 1834 nullptr, nullptr); |
1835 GURL test_url("https://www.google.com"); | 1835 GURL test_url("https://www.google.com"); |
1836 ProxyInfo info; | 1836 ProxyInfo info; |
1837 TestCompletionCallback callback; | 1837 TestCompletionCallback callback; |
1838 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1838 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1839 callback.callback(), nullptr, nullptr, | 1839 callback.callback(), nullptr, nullptr, |
1840 BoundNetLog()); | 1840 NetLogWithSource()); |
1841 ASSERT_THAT(rv, IsOk()); | 1841 ASSERT_THAT(rv, IsOk()); |
1842 // Used the HTTPS proxy. So source should be TEST. | 1842 // Used the HTTPS proxy. So source should be TEST. |
1843 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1843 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1844 } | 1844 } |
1845 { | 1845 { |
1846 ProxyConfig config; | 1846 ProxyConfig config; |
1847 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 1847 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
1848 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), | 1848 ProxyService service(base::MakeUnique<MockProxyConfigService>(config), |
1849 nullptr, nullptr); | 1849 nullptr, nullptr); |
1850 GURL test_url("http://www.google.com"); | 1850 GURL test_url("http://www.google.com"); |
1851 ProxyInfo info; | 1851 ProxyInfo info; |
1852 TestCompletionCallback callback; | 1852 TestCompletionCallback callback; |
1853 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1853 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1854 callback.callback(), nullptr, nullptr, | 1854 callback.callback(), nullptr, nullptr, |
1855 BoundNetLog()); | 1855 NetLogWithSource()); |
1856 ASSERT_THAT(rv, IsOk()); | 1856 ASSERT_THAT(rv, IsOk()); |
1857 // ProxyConfig is empty. Source should still be TEST. | 1857 // ProxyConfig is empty. Source should still be TEST. |
1858 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 1858 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
1859 } | 1859 } |
1860 } | 1860 } |
1861 | 1861 |
1862 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries | 1862 // If only HTTP and a SOCKS proxy are specified, check if ftp/https queries |
1863 // fall back to the SOCKS proxy. | 1863 // fall back to the SOCKS proxy. |
1864 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { | 1864 TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) { |
1865 ProxyConfig config; | 1865 ProxyConfig config; |
1866 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); | 1866 config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080"); |
1867 config.set_auto_detect(false); | 1867 config.set_auto_detect(false); |
1868 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, | 1868 EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, |
1869 config.proxy_rules().type); | 1869 config.proxy_rules().type); |
1870 | 1870 |
1871 { | 1871 { |
1872 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1872 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1873 nullptr, nullptr); | 1873 nullptr, nullptr); |
1874 GURL test_url("http://www.msn.com"); | 1874 GURL test_url("http://www.msn.com"); |
1875 ProxyInfo info; | 1875 ProxyInfo info; |
1876 TestCompletionCallback callback; | 1876 TestCompletionCallback callback; |
1877 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1877 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1878 callback.callback(), nullptr, nullptr, | 1878 callback.callback(), nullptr, nullptr, |
1879 BoundNetLog()); | 1879 NetLogWithSource()); |
1880 EXPECT_THAT(rv, IsOk()); | 1880 EXPECT_THAT(rv, IsOk()); |
1881 EXPECT_FALSE(info.is_direct()); | 1881 EXPECT_FALSE(info.is_direct()); |
1882 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1882 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1883 } | 1883 } |
1884 { | 1884 { |
1885 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1885 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1886 nullptr, nullptr); | 1886 nullptr, nullptr); |
1887 GURL test_url("ftp://ftp.google.com"); | 1887 GURL test_url("ftp://ftp.google.com"); |
1888 ProxyInfo info; | 1888 ProxyInfo info; |
1889 TestCompletionCallback callback; | 1889 TestCompletionCallback callback; |
1890 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1890 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1891 callback.callback(), nullptr, nullptr, | 1891 callback.callback(), nullptr, nullptr, |
1892 BoundNetLog()); | 1892 NetLogWithSource()); |
1893 EXPECT_THAT(rv, IsOk()); | 1893 EXPECT_THAT(rv, IsOk()); |
1894 EXPECT_FALSE(info.is_direct()); | 1894 EXPECT_FALSE(info.is_direct()); |
1895 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1895 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1896 } | 1896 } |
1897 { | 1897 { |
1898 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1898 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1899 nullptr, nullptr); | 1899 nullptr, nullptr); |
1900 GURL test_url("https://webbranch.techcu.com"); | 1900 GURL test_url("https://webbranch.techcu.com"); |
1901 ProxyInfo info; | 1901 ProxyInfo info; |
1902 TestCompletionCallback callback; | 1902 TestCompletionCallback callback; |
1903 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1903 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1904 callback.callback(), nullptr, nullptr, | 1904 callback.callback(), nullptr, nullptr, |
1905 BoundNetLog()); | 1905 NetLogWithSource()); |
1906 EXPECT_THAT(rv, IsOk()); | 1906 EXPECT_THAT(rv, IsOk()); |
1907 EXPECT_FALSE(info.is_direct()); | 1907 EXPECT_FALSE(info.is_direct()); |
1908 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1908 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1909 } | 1909 } |
1910 { | 1910 { |
1911 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), | 1911 ProxyService service(base::WrapUnique(new MockProxyConfigService(config)), |
1912 nullptr, nullptr); | 1912 nullptr, nullptr); |
1913 GURL test_url("unknown://www.microsoft.com"); | 1913 GURL test_url("unknown://www.microsoft.com"); |
1914 ProxyInfo info; | 1914 ProxyInfo info; |
1915 TestCompletionCallback callback; | 1915 TestCompletionCallback callback; |
1916 int rv = service.ResolveProxy(test_url, std::string(), &info, | 1916 int rv = service.ResolveProxy(test_url, std::string(), &info, |
1917 callback.callback(), nullptr, nullptr, | 1917 callback.callback(), nullptr, nullptr, |
1918 BoundNetLog()); | 1918 NetLogWithSource()); |
1919 EXPECT_THAT(rv, IsOk()); | 1919 EXPECT_THAT(rv, IsOk()); |
1920 EXPECT_FALSE(info.is_direct()); | 1920 EXPECT_FALSE(info.is_direct()); |
1921 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1921 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
1922 } | 1922 } |
1923 } | 1923 } |
1924 | 1924 |
1925 // Test cancellation of an in-progress request. | 1925 // Test cancellation of an in-progress request. |
1926 TEST_F(ProxyServiceTest, CancelInProgressRequest) { | 1926 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
1927 const GURL url1("http://request1"); | 1927 const GURL url1("http://request1"); |
1928 const GURL url2("http://request2"); | 1928 const GURL url2("http://request2"); |
1929 const GURL url3("http://request3"); | 1929 const GURL url3("http://request3"); |
1930 MockProxyConfigService* config_service = | 1930 MockProxyConfigService* config_service = |
1931 new MockProxyConfigService("http://foopy/proxy.pac"); | 1931 new MockProxyConfigService("http://foopy/proxy.pac"); |
1932 | 1932 |
1933 MockAsyncProxyResolver resolver; | 1933 MockAsyncProxyResolver resolver; |
1934 MockAsyncProxyResolverFactory* factory = | 1934 MockAsyncProxyResolverFactory* factory = |
1935 new MockAsyncProxyResolverFactory(false); | 1935 new MockAsyncProxyResolverFactory(false); |
1936 | 1936 |
1937 ProxyService service(base::WrapUnique(config_service), | 1937 ProxyService service(base::WrapUnique(config_service), |
1938 base::WrapUnique(factory), nullptr); | 1938 base::WrapUnique(factory), nullptr); |
1939 | 1939 |
1940 // Start 3 requests. | 1940 // Start 3 requests. |
1941 | 1941 |
1942 ProxyInfo info1; | 1942 ProxyInfo info1; |
1943 TestCompletionCallback callback1; | 1943 TestCompletionCallback callback1; |
1944 int rv = | 1944 int rv = |
1945 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), | 1945 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
1946 nullptr, nullptr, BoundNetLog()); | 1946 nullptr, nullptr, NetLogWithSource()); |
1947 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1947 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1948 | 1948 |
1949 // Successfully initialize the PAC script. | 1949 // Successfully initialize the PAC script. |
1950 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1950 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1951 factory->pending_requests()[0]->script_data()->url()); | 1951 factory->pending_requests()[0]->script_data()->url()); |
1952 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1952 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1953 | 1953 |
1954 GetPendingRequestsForURLs(resolver, url1); | 1954 GetPendingRequestsForURLs(resolver, url1); |
1955 | 1955 |
1956 ProxyInfo info2; | 1956 ProxyInfo info2; |
1957 TestCompletionCallback callback2; | 1957 TestCompletionCallback callback2; |
1958 ProxyService::PacRequest* request2; | 1958 ProxyService::PacRequest* request2; |
1959 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), | 1959 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
1960 &request2, nullptr, BoundNetLog()); | 1960 &request2, nullptr, NetLogWithSource()); |
1961 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1961 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1962 | 1962 |
1963 GetPendingRequestsForURLs(resolver, url1, url2); | 1963 GetPendingRequestsForURLs(resolver, url1, url2); |
1964 | 1964 |
1965 ProxyInfo info3; | 1965 ProxyInfo info3; |
1966 TestCompletionCallback callback3; | 1966 TestCompletionCallback callback3; |
1967 rv = service.ResolveProxy(url3, std::string(), &info3, callback3.callback(), | 1967 rv = service.ResolveProxy(url3, std::string(), &info3, callback3.callback(), |
1968 nullptr, nullptr, BoundNetLog()); | 1968 nullptr, nullptr, NetLogWithSource()); |
1969 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1969 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1970 GetPendingRequestsForURLs(resolver, url1, url2, url3); | 1970 GetPendingRequestsForURLs(resolver, url1, url2, url3); |
1971 | 1971 |
1972 // Cancel the second request | 1972 // Cancel the second request |
1973 service.CancelPacRequest(request2); | 1973 service.CancelPacRequest(request2); |
1974 | 1974 |
1975 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); | 1975 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); |
1976 | 1976 |
1977 // Complete the two un-cancelled requests. | 1977 // Complete the two un-cancelled requests. |
1978 // We complete the last one first, just to mix it up a bit. | 1978 // We complete the last one first, just to mix it up a bit. |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2012 service.SetProxyScriptFetchers( | 2012 service.SetProxyScriptFetchers( |
2013 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2013 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2014 | 2014 |
2015 // Start 3 requests. | 2015 // Start 3 requests. |
2016 | 2016 |
2017 ProxyInfo info1; | 2017 ProxyInfo info1; |
2018 TestCompletionCallback callback1; | 2018 TestCompletionCallback callback1; |
2019 ProxyService::PacRequest* request1; | 2019 ProxyService::PacRequest* request1; |
2020 int rv = | 2020 int rv = |
2021 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), | 2021 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
2022 &request1, nullptr, BoundNetLog()); | 2022 &request1, nullptr, NetLogWithSource()); |
2023 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2023 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2024 | 2024 |
2025 // The first request should have triggered download of PAC script. | 2025 // The first request should have triggered download of PAC script. |
2026 EXPECT_TRUE(fetcher->has_pending_request()); | 2026 EXPECT_TRUE(fetcher->has_pending_request()); |
2027 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2027 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2028 | 2028 |
2029 ProxyInfo info2; | 2029 ProxyInfo info2; |
2030 TestCompletionCallback callback2; | 2030 TestCompletionCallback callback2; |
2031 ProxyService::PacRequest* request2; | 2031 ProxyService::PacRequest* request2; |
2032 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), | 2032 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
2033 &request2, nullptr, BoundNetLog()); | 2033 &request2, nullptr, NetLogWithSource()); |
2034 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2034 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2035 | 2035 |
2036 ProxyInfo info3; | 2036 ProxyInfo info3; |
2037 TestCompletionCallback callback3; | 2037 TestCompletionCallback callback3; |
2038 ProxyService::PacRequest* request3; | 2038 ProxyService::PacRequest* request3; |
2039 rv = service.ResolveProxy(url3, std::string(), &info3, callback3.callback(), | 2039 rv = service.ResolveProxy(url3, std::string(), &info3, callback3.callback(), |
2040 &request3, nullptr, BoundNetLog()); | 2040 &request3, nullptr, NetLogWithSource()); |
2041 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2041 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2042 | 2042 |
2043 // Nothing has been sent to the factory yet. | 2043 // Nothing has been sent to the factory yet. |
2044 EXPECT_TRUE(factory->pending_requests().empty()); | 2044 EXPECT_TRUE(factory->pending_requests().empty()); |
2045 | 2045 |
2046 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2046 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
2047 service.GetLoadState(request1)); | 2047 service.GetLoadState(request1)); |
2048 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2048 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
2049 service.GetLoadState(request2)); | 2049 service.GetLoadState(request2)); |
2050 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 2050 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2115 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2115 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2116 service.SetProxyScriptFetchers( | 2116 service.SetProxyScriptFetchers( |
2117 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2117 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2118 | 2118 |
2119 // Start 2 requests. | 2119 // Start 2 requests. |
2120 | 2120 |
2121 ProxyInfo info1; | 2121 ProxyInfo info1; |
2122 TestCompletionCallback callback1; | 2122 TestCompletionCallback callback1; |
2123 int rv = | 2123 int rv = |
2124 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), | 2124 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
2125 nullptr, nullptr, BoundNetLog()); | 2125 nullptr, nullptr, NetLogWithSource()); |
2126 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2126 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2127 | 2127 |
2128 // The first request should have triggered download of PAC script. | 2128 // The first request should have triggered download of PAC script. |
2129 EXPECT_TRUE(fetcher->has_pending_request()); | 2129 EXPECT_TRUE(fetcher->has_pending_request()); |
2130 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2130 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2131 | 2131 |
2132 ProxyInfo info2; | 2132 ProxyInfo info2; |
2133 TestCompletionCallback callback2; | 2133 TestCompletionCallback callback2; |
2134 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), | 2134 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
2135 nullptr, nullptr, BoundNetLog()); | 2135 nullptr, nullptr, NetLogWithSource()); |
2136 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2136 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2137 | 2137 |
2138 // At this point the ProxyService should be waiting for the | 2138 // At this point the ProxyService should be waiting for the |
2139 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2139 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2140 // PAC script download completion. | 2140 // PAC script download completion. |
2141 | 2141 |
2142 // We now change out the ProxyService's script fetcher. We should restart | 2142 // We now change out the ProxyService's script fetcher. We should restart |
2143 // the initialization with the new fetcher. | 2143 // the initialization with the new fetcher. |
2144 | 2144 |
2145 fetcher = new MockProxyScriptFetcher; | 2145 fetcher = new MockProxyScriptFetcher; |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2188 | 2188 |
2189 // The first request should have triggered download of PAC script. | 2189 // The first request should have triggered download of PAC script. |
2190 EXPECT_TRUE(fetcher->has_pending_request()); | 2190 EXPECT_TRUE(fetcher->has_pending_request()); |
2191 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2191 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2192 | 2192 |
2193 ProxyInfo info2; | 2193 ProxyInfo info2; |
2194 TestCompletionCallback callback2; | 2194 TestCompletionCallback callback2; |
2195 ProxyService::PacRequest* request2; | 2195 ProxyService::PacRequest* request2; |
2196 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 2196 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
2197 callback2.callback(), &request2, nullptr, | 2197 callback2.callback(), &request2, nullptr, |
2198 BoundNetLog()); | 2198 NetLogWithSource()); |
2199 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2199 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2200 | 2200 |
2201 ProxyInfo info3; | 2201 ProxyInfo info3; |
2202 TestCompletionCallback callback3; | 2202 TestCompletionCallback callback3; |
2203 rv = service.ResolveProxy(GURL("http://request3"), std::string(), &info3, | 2203 rv = service.ResolveProxy(GURL("http://request3"), std::string(), &info3, |
2204 callback3.callback(), nullptr, nullptr, | 2204 callback3.callback(), nullptr, nullptr, |
2205 BoundNetLog()); | 2205 NetLogWithSource()); |
2206 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2206 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2207 | 2207 |
2208 // Nothing has been sent to the factory yet. | 2208 // Nothing has been sent to the factory yet. |
2209 EXPECT_TRUE(factory->pending_requests().empty()); | 2209 EXPECT_TRUE(factory->pending_requests().empty()); |
2210 | 2210 |
2211 // Cancel the first 2 requests. | 2211 // Cancel the first 2 requests. |
2212 service.CancelPacRequest(request1); | 2212 service.CancelPacRequest(request1); |
2213 service.CancelPacRequest(request2); | 2213 service.CancelPacRequest(request2); |
2214 | 2214 |
2215 // At this point the ProxyService should be waiting for the | 2215 // At this point the ProxyService should be waiting for the |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2273 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2273 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2274 service.SetProxyScriptFetchers( | 2274 service.SetProxyScriptFetchers( |
2275 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2275 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2276 | 2276 |
2277 // Start 2 requests. | 2277 // Start 2 requests. |
2278 | 2278 |
2279 ProxyInfo info1; | 2279 ProxyInfo info1; |
2280 TestCompletionCallback callback1; | 2280 TestCompletionCallback callback1; |
2281 int rv = | 2281 int rv = |
2282 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), | 2282 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
2283 nullptr, nullptr, BoundNetLog()); | 2283 nullptr, nullptr, NetLogWithSource()); |
2284 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2284 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2285 | 2285 |
2286 ProxyInfo info2; | 2286 ProxyInfo info2; |
2287 TestCompletionCallback callback2; | 2287 TestCompletionCallback callback2; |
2288 ProxyService::PacRequest* request2; | 2288 ProxyService::PacRequest* request2; |
2289 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), | 2289 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
2290 &request2, nullptr, BoundNetLog()); | 2290 &request2, nullptr, NetLogWithSource()); |
2291 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2291 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2292 | 2292 |
2293 // Check that nothing has been sent to the proxy resolver factory yet. | 2293 // Check that nothing has been sent to the proxy resolver factory yet. |
2294 ASSERT_EQ(0u, factory->pending_requests().size()); | 2294 ASSERT_EQ(0u, factory->pending_requests().size()); |
2295 | 2295 |
2296 // It should be trying to auto-detect first -- FAIL the autodetect during | 2296 // It should be trying to auto-detect first -- FAIL the autodetect during |
2297 // the script download. | 2297 // the script download. |
2298 EXPECT_TRUE(fetcher->has_pending_request()); | 2298 EXPECT_TRUE(fetcher->has_pending_request()); |
2299 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2299 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2300 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2300 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2353 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2353 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2354 service.SetProxyScriptFetchers( | 2354 service.SetProxyScriptFetchers( |
2355 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2355 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2356 | 2356 |
2357 // Start 2 requests. | 2357 // Start 2 requests. |
2358 | 2358 |
2359 ProxyInfo info1; | 2359 ProxyInfo info1; |
2360 TestCompletionCallback callback1; | 2360 TestCompletionCallback callback1; |
2361 int rv = | 2361 int rv = |
2362 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), | 2362 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
2363 nullptr, nullptr, BoundNetLog()); | 2363 nullptr, nullptr, NetLogWithSource()); |
2364 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2364 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2365 | 2365 |
2366 ProxyInfo info2; | 2366 ProxyInfo info2; |
2367 TestCompletionCallback callback2; | 2367 TestCompletionCallback callback2; |
2368 ProxyService::PacRequest* request2; | 2368 ProxyService::PacRequest* request2; |
2369 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), | 2369 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
2370 &request2, nullptr, BoundNetLog()); | 2370 &request2, nullptr, NetLogWithSource()); |
2371 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2371 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2372 | 2372 |
2373 // Check that nothing has been sent to the proxy resolver factory yet. | 2373 // Check that nothing has been sent to the proxy resolver factory yet. |
2374 ASSERT_EQ(0u, factory->pending_requests().size()); | 2374 ASSERT_EQ(0u, factory->pending_requests().size()); |
2375 | 2375 |
2376 // It should be trying to auto-detect first -- succeed the download. | 2376 // It should be trying to auto-detect first -- succeed the download. |
2377 EXPECT_TRUE(fetcher->has_pending_request()); | 2377 EXPECT_TRUE(fetcher->has_pending_request()); |
2378 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2378 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2379 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 2379 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
2380 | 2380 |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2426 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2426 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2427 service.SetProxyScriptFetchers( | 2427 service.SetProxyScriptFetchers( |
2428 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2428 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2429 | 2429 |
2430 // Start 2 requests. | 2430 // Start 2 requests. |
2431 | 2431 |
2432 ProxyInfo info1; | 2432 ProxyInfo info1; |
2433 TestCompletionCallback callback1; | 2433 TestCompletionCallback callback1; |
2434 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, | 2434 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
2435 callback1.callback(), nullptr, nullptr, | 2435 callback1.callback(), nullptr, nullptr, |
2436 BoundNetLog()); | 2436 NetLogWithSource()); |
2437 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2437 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2438 | 2438 |
2439 ProxyInfo info2; | 2439 ProxyInfo info2; |
2440 TestCompletionCallback callback2; | 2440 TestCompletionCallback callback2; |
2441 ProxyService::PacRequest* request2; | 2441 ProxyService::PacRequest* request2; |
2442 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 2442 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
2443 callback2.callback(), &request2, nullptr, | 2443 callback2.callback(), &request2, nullptr, |
2444 BoundNetLog()); | 2444 NetLogWithSource()); |
2445 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2445 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2446 | 2446 |
2447 // Check that nothing has been sent to the proxy resolver factory yet. | 2447 // Check that nothing has been sent to the proxy resolver factory yet. |
2448 ASSERT_EQ(0u, factory->pending_requests().size()); | 2448 ASSERT_EQ(0u, factory->pending_requests().size()); |
2449 | 2449 |
2450 // It should be trying to auto-detect first -- fail the download. | 2450 // It should be trying to auto-detect first -- fail the download. |
2451 EXPECT_TRUE(fetcher->has_pending_request()); | 2451 EXPECT_TRUE(fetcher->has_pending_request()); |
2452 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2452 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2453 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2453 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2454 | 2454 |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2488 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2488 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2489 service.SetProxyScriptFetchers( | 2489 service.SetProxyScriptFetchers( |
2490 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2490 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2491 | 2491 |
2492 // Start 1 requests. | 2492 // Start 1 requests. |
2493 | 2493 |
2494 ProxyInfo info1; | 2494 ProxyInfo info1; |
2495 TestCompletionCallback callback1; | 2495 TestCompletionCallback callback1; |
2496 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2496 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2497 &info1, callback1.callback(), nullptr, nullptr, | 2497 &info1, callback1.callback(), nullptr, nullptr, |
2498 BoundNetLog()); | 2498 NetLogWithSource()); |
2499 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2499 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2500 | 2500 |
2501 // Check that nothing has been sent to the proxy resolver factory yet. | 2501 // Check that nothing has been sent to the proxy resolver factory yet. |
2502 ASSERT_EQ(0u, factory->pending_requests().size()); | 2502 ASSERT_EQ(0u, factory->pending_requests().size()); |
2503 | 2503 |
2504 // It should be trying to auto-detect first -- succeed the download. | 2504 // It should be trying to auto-detect first -- succeed the download. |
2505 EXPECT_TRUE(fetcher->has_pending_request()); | 2505 EXPECT_TRUE(fetcher->has_pending_request()); |
2506 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2506 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2507 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2507 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2508 | 2508 |
(...skipping 11 matching lines...) Expand all Loading... |
2520 | 2520 |
2521 // Verify that request ran as expected. | 2521 // Verify that request ran as expected. |
2522 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2522 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2523 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2523 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2524 | 2524 |
2525 // Start another request, it should pickup the bypass item. | 2525 // Start another request, it should pickup the bypass item. |
2526 ProxyInfo info2; | 2526 ProxyInfo info2; |
2527 TestCompletionCallback callback2; | 2527 TestCompletionCallback callback2; |
2528 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2528 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2529 &info2, callback2.callback(), nullptr, nullptr, | 2529 &info2, callback2.callback(), nullptr, nullptr, |
2530 BoundNetLog()); | 2530 NetLogWithSource()); |
2531 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2531 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2532 | 2532 |
2533 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2533 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2534 EXPECT_EQ(GURL("http://www.google.com"), | 2534 EXPECT_EQ(GURL("http://www.google.com"), |
2535 resolver.pending_requests()[0]->url()); | 2535 resolver.pending_requests()[0]->url()); |
2536 | 2536 |
2537 // Complete the pending request. | 2537 // Complete the pending request. |
2538 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2538 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2539 resolver.pending_requests()[0]->CompleteNow(OK); | 2539 resolver.pending_requests()[0]->CompleteNow(OK); |
2540 | 2540 |
(...skipping 18 matching lines...) Expand all Loading... |
2559 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2559 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2560 service.SetProxyScriptFetchers( | 2560 service.SetProxyScriptFetchers( |
2561 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2561 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2562 | 2562 |
2563 // Start 1 request. | 2563 // Start 1 request. |
2564 | 2564 |
2565 ProxyInfo info1; | 2565 ProxyInfo info1; |
2566 TestCompletionCallback callback1; | 2566 TestCompletionCallback callback1; |
2567 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2567 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2568 &info1, callback1.callback(), nullptr, nullptr, | 2568 &info1, callback1.callback(), nullptr, nullptr, |
2569 BoundNetLog()); | 2569 NetLogWithSource()); |
2570 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2570 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2571 | 2571 |
2572 // Check that nothing has been sent to the proxy resolver factory yet. | 2572 // Check that nothing has been sent to the proxy resolver factory yet. |
2573 ASSERT_EQ(0u, factory->pending_requests().size()); | 2573 ASSERT_EQ(0u, factory->pending_requests().size()); |
2574 | 2574 |
2575 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 2575 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
2576 // and be waiting on that to complete. | 2576 // and be waiting on that to complete. |
2577 EXPECT_TRUE(fetcher->has_pending_request()); | 2577 EXPECT_TRUE(fetcher->has_pending_request()); |
2578 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2578 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2579 } | 2579 } |
(...skipping 10 matching lines...) Expand all Loading... |
2590 new MockAsyncProxyResolverFactory(false); | 2590 new MockAsyncProxyResolverFactory(false); |
2591 | 2591 |
2592 ProxyService service(base::WrapUnique(config_service), | 2592 ProxyService service(base::WrapUnique(config_service), |
2593 base::WrapUnique(factory), nullptr); | 2593 base::WrapUnique(factory), nullptr); |
2594 | 2594 |
2595 GURL url("http://www.google.com/"); | 2595 GURL url("http://www.google.com/"); |
2596 | 2596 |
2597 ProxyInfo info; | 2597 ProxyInfo info; |
2598 TestCompletionCallback callback; | 2598 TestCompletionCallback callback; |
2599 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), | 2599 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
2600 nullptr, nullptr, BoundNetLog()); | 2600 nullptr, nullptr, NetLogWithSource()); |
2601 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2601 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2602 | 2602 |
2603 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 2603 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
2604 factory->pending_requests()[0]->script_data()->url()); | 2604 factory->pending_requests()[0]->script_data()->url()); |
2605 } | 2605 } |
2606 | 2606 |
2607 TEST_F(ProxyServiceTest, ResetProxyConfigService) { | 2607 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
2608 ProxyConfig config1; | 2608 ProxyConfig config1; |
2609 config1.proxy_rules().ParseFromString("foopy1:8080"); | 2609 config1.proxy_rules().ParseFromString("foopy1:8080"); |
2610 config1.set_auto_detect(false); | 2610 config1.set_auto_detect(false); |
2611 ProxyService service(base::MakeUnique<MockProxyConfigService>(config1), | 2611 ProxyService service(base::MakeUnique<MockProxyConfigService>(config1), |
2612 nullptr, nullptr); | 2612 nullptr, nullptr); |
2613 | 2613 |
2614 ProxyInfo info; | 2614 ProxyInfo info; |
2615 TestCompletionCallback callback1; | 2615 TestCompletionCallback callback1; |
2616 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info, | 2616 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info, |
2617 callback1.callback(), nullptr, nullptr, | 2617 callback1.callback(), nullptr, nullptr, |
2618 BoundNetLog()); | 2618 NetLogWithSource()); |
2619 EXPECT_THAT(rv, IsOk()); | 2619 EXPECT_THAT(rv, IsOk()); |
2620 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 2620 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
2621 | 2621 |
2622 ProxyConfig config2; | 2622 ProxyConfig config2; |
2623 config2.proxy_rules().ParseFromString("foopy2:8080"); | 2623 config2.proxy_rules().ParseFromString("foopy2:8080"); |
2624 config2.set_auto_detect(false); | 2624 config2.set_auto_detect(false); |
2625 service.ResetConfigService(base::MakeUnique<MockProxyConfigService>(config2)); | 2625 service.ResetConfigService(base::MakeUnique<MockProxyConfigService>(config2)); |
2626 TestCompletionCallback callback2; | 2626 TestCompletionCallback callback2; |
2627 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info, | 2627 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info, |
2628 callback2.callback(), nullptr, nullptr, | 2628 callback2.callback(), nullptr, nullptr, |
2629 BoundNetLog()); | 2629 NetLogWithSource()); |
2630 EXPECT_THAT(rv, IsOk()); | 2630 EXPECT_THAT(rv, IsOk()); |
2631 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 2631 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
2632 } | 2632 } |
2633 | 2633 |
2634 // Test that when going from a configuration that required PAC to one | 2634 // Test that when going from a configuration that required PAC to one |
2635 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 2635 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
2636 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 2636 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
2637 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 2637 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
2638 | 2638 |
2639 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2639 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2640 MockAsyncProxyResolver resolver; | 2640 MockAsyncProxyResolver resolver; |
2641 MockAsyncProxyResolverFactory* factory = | 2641 MockAsyncProxyResolverFactory* factory = |
2642 new MockAsyncProxyResolverFactory(false); | 2642 new MockAsyncProxyResolverFactory(false); |
2643 ProxyService service(base::WrapUnique(config_service), | 2643 ProxyService service(base::WrapUnique(config_service), |
2644 base::WrapUnique(factory), nullptr); | 2644 base::WrapUnique(factory), nullptr); |
2645 | 2645 |
2646 // Start 1 request. | 2646 // Start 1 request. |
2647 | 2647 |
2648 ProxyInfo info1; | 2648 ProxyInfo info1; |
2649 TestCompletionCallback callback1; | 2649 TestCompletionCallback callback1; |
2650 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2650 int rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2651 &info1, callback1.callback(), nullptr, nullptr, | 2651 &info1, callback1.callback(), nullptr, nullptr, |
2652 BoundNetLog()); | 2652 NetLogWithSource()); |
2653 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2653 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2654 | 2654 |
2655 // Successfully set the autodetect script. | 2655 // Successfully set the autodetect script. |
2656 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2656 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2657 factory->pending_requests()[0]->script_data()->type()); | 2657 factory->pending_requests()[0]->script_data()->type()); |
2658 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2658 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2659 | 2659 |
2660 // Complete the pending request. | 2660 // Complete the pending request. |
2661 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2661 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2662 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2662 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2663 resolver.pending_requests()[0]->CompleteNow(OK); | 2663 resolver.pending_requests()[0]->CompleteNow(OK); |
2664 | 2664 |
2665 // Verify that request ran as expected. | 2665 // Verify that request ran as expected. |
2666 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2666 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2667 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2667 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2668 | 2668 |
2669 // Force the ProxyService to pull down a new proxy configuration. | 2669 // Force the ProxyService to pull down a new proxy configuration. |
2670 // (Even though the configuration isn't old/bad). | 2670 // (Even though the configuration isn't old/bad). |
2671 // | 2671 // |
2672 // This new configuration no longer has auto_detect set, so | 2672 // This new configuration no longer has auto_detect set, so |
2673 // requests should complete synchronously now as direct-connect. | 2673 // requests should complete synchronously now as direct-connect. |
2674 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2674 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2675 | 2675 |
2676 // Start another request -- the effective configuration has changed. | 2676 // Start another request -- the effective configuration has changed. |
2677 ProxyInfo info2; | 2677 ProxyInfo info2; |
2678 TestCompletionCallback callback2; | 2678 TestCompletionCallback callback2; |
2679 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2679 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2680 &info2, callback2.callback(), nullptr, nullptr, | 2680 &info2, callback2.callback(), nullptr, nullptr, |
2681 BoundNetLog()); | 2681 NetLogWithSource()); |
2682 EXPECT_THAT(rv, IsOk()); | 2682 EXPECT_THAT(rv, IsOk()); |
2683 | 2683 |
2684 EXPECT_TRUE(info2.is_direct()); | 2684 EXPECT_TRUE(info2.is_direct()); |
2685 } | 2685 } |
2686 | 2686 |
2687 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 2687 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
2688 MockProxyConfigService* config_service = | 2688 MockProxyConfigService* config_service = |
2689 new MockProxyConfigService("http://foopy/proxy.pac"); | 2689 new MockProxyConfigService("http://foopy/proxy.pac"); |
2690 | 2690 |
2691 MockAsyncProxyResolver resolver; | 2691 MockAsyncProxyResolver resolver; |
(...skipping 12 matching lines...) Expand all Loading... |
2704 // Disable the "wait after IP address changes" hack, so this unit-test can | 2704 // Disable the "wait after IP address changes" hack, so this unit-test can |
2705 // complete quickly. | 2705 // complete quickly. |
2706 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 2706 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
2707 | 2707 |
2708 // Start 1 request. | 2708 // Start 1 request. |
2709 | 2709 |
2710 ProxyInfo info1; | 2710 ProxyInfo info1; |
2711 TestCompletionCallback callback1; | 2711 TestCompletionCallback callback1; |
2712 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, | 2712 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
2713 callback1.callback(), nullptr, nullptr, | 2713 callback1.callback(), nullptr, nullptr, |
2714 BoundNetLog()); | 2714 NetLogWithSource()); |
2715 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2715 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2716 | 2716 |
2717 // The first request should have triggered initial download of PAC script. | 2717 // The first request should have triggered initial download of PAC script. |
2718 EXPECT_TRUE(fetcher->has_pending_request()); | 2718 EXPECT_TRUE(fetcher->has_pending_request()); |
2719 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2719 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2720 | 2720 |
2721 // Nothing has been sent to the factory yet. | 2721 // Nothing has been sent to the factory yet. |
2722 EXPECT_TRUE(factory->pending_requests().empty()); | 2722 EXPECT_TRUE(factory->pending_requests().empty()); |
2723 | 2723 |
2724 // At this point the ProxyService should be waiting for the | 2724 // At this point the ProxyService should be waiting for the |
(...skipping 22 matching lines...) Expand all Loading... |
2747 // going to return the same PAC URL as before, but this URL needs to be | 2747 // going to return the same PAC URL as before, but this URL needs to be |
2748 // refetched on the new network. | 2748 // refetched on the new network. |
2749 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2749 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2750 base::RunLoop().RunUntilIdle(); // Notification happens async. | 2750 base::RunLoop().RunUntilIdle(); // Notification happens async. |
2751 | 2751 |
2752 // Start a second request. | 2752 // Start a second request. |
2753 ProxyInfo info2; | 2753 ProxyInfo info2; |
2754 TestCompletionCallback callback2; | 2754 TestCompletionCallback callback2; |
2755 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 2755 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
2756 callback2.callback(), nullptr, nullptr, | 2756 callback2.callback(), nullptr, nullptr, |
2757 BoundNetLog()); | 2757 NetLogWithSource()); |
2758 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2758 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2759 | 2759 |
2760 // This second request should have triggered the re-download of the PAC | 2760 // This second request should have triggered the re-download of the PAC |
2761 // script (since we marked the network as having changed). | 2761 // script (since we marked the network as having changed). |
2762 EXPECT_TRUE(fetcher->has_pending_request()); | 2762 EXPECT_TRUE(fetcher->has_pending_request()); |
2763 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2763 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2764 | 2764 |
2765 // Nothing has been sent to the factory yet. | 2765 // Nothing has been sent to the factory yet. |
2766 EXPECT_TRUE(factory->pending_requests().empty()); | 2766 EXPECT_TRUE(factory->pending_requests().empty()); |
2767 | 2767 |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2822 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2822 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2823 service.SetProxyScriptFetchers( | 2823 service.SetProxyScriptFetchers( |
2824 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2824 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2825 | 2825 |
2826 // Start 1 request. | 2826 // Start 1 request. |
2827 | 2827 |
2828 ProxyInfo info1; | 2828 ProxyInfo info1; |
2829 TestCompletionCallback callback1; | 2829 TestCompletionCallback callback1; |
2830 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, | 2830 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
2831 callback1.callback(), nullptr, nullptr, | 2831 callback1.callback(), nullptr, nullptr, |
2832 BoundNetLog()); | 2832 NetLogWithSource()); |
2833 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2833 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2834 | 2834 |
2835 // The first request should have triggered initial download of PAC script. | 2835 // The first request should have triggered initial download of PAC script. |
2836 EXPECT_TRUE(fetcher->has_pending_request()); | 2836 EXPECT_TRUE(fetcher->has_pending_request()); |
2837 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2837 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2838 | 2838 |
2839 // Nothing has been sent to the factory yet. | 2839 // Nothing has been sent to the factory yet. |
2840 EXPECT_TRUE(factory->pending_requests().empty()); | 2840 EXPECT_TRUE(factory->pending_requests().empty()); |
2841 | 2841 |
2842 // At this point the ProxyService should be waiting for the | 2842 // At this point the ProxyService should be waiting for the |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2883 // At this point the ProxyService should have re-configured itself to use the | 2883 // At this point the ProxyService should have re-configured itself to use the |
2884 // PAC script (thereby recovering from the initial fetch failure). We will | 2884 // PAC script (thereby recovering from the initial fetch failure). We will |
2885 // verify that the next Resolve request uses the resolver rather than | 2885 // verify that the next Resolve request uses the resolver rather than |
2886 // DIRECT. | 2886 // DIRECT. |
2887 | 2887 |
2888 // Start a second request. | 2888 // Start a second request. |
2889 ProxyInfo info2; | 2889 ProxyInfo info2; |
2890 TestCompletionCallback callback2; | 2890 TestCompletionCallback callback2; |
2891 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 2891 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
2892 callback2.callback(), nullptr, nullptr, | 2892 callback2.callback(), nullptr, nullptr, |
2893 BoundNetLog()); | 2893 NetLogWithSource()); |
2894 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2894 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2895 | 2895 |
2896 // Check that it was sent to the resolver. | 2896 // Check that it was sent to the resolver. |
2897 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2897 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2898 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2898 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
2899 | 2899 |
2900 // Complete the pending second request. | 2900 // Complete the pending second request. |
2901 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2901 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2902 resolver.pending_requests()[0]->CompleteNow(OK); | 2902 resolver.pending_requests()[0]->CompleteNow(OK); |
2903 | 2903 |
(...skipping 25 matching lines...) Expand all Loading... |
2929 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2929 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2930 service.SetProxyScriptFetchers( | 2930 service.SetProxyScriptFetchers( |
2931 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2931 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2932 | 2932 |
2933 // Start 1 request. | 2933 // Start 1 request. |
2934 | 2934 |
2935 ProxyInfo info1; | 2935 ProxyInfo info1; |
2936 TestCompletionCallback callback1; | 2936 TestCompletionCallback callback1; |
2937 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, | 2937 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
2938 callback1.callback(), nullptr, nullptr, | 2938 callback1.callback(), nullptr, nullptr, |
2939 BoundNetLog()); | 2939 NetLogWithSource()); |
2940 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2940 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2941 | 2941 |
2942 // The first request should have triggered initial download of PAC script. | 2942 // The first request should have triggered initial download of PAC script. |
2943 EXPECT_TRUE(fetcher->has_pending_request()); | 2943 EXPECT_TRUE(fetcher->has_pending_request()); |
2944 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2944 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2945 | 2945 |
2946 // Nothing has been sent to the factory yet. | 2946 // Nothing has been sent to the factory yet. |
2947 EXPECT_TRUE(factory->pending_requests().empty()); | 2947 EXPECT_TRUE(factory->pending_requests().empty()); |
2948 | 2948 |
2949 // At this point the ProxyService should be waiting for the | 2949 // At this point the ProxyService should be waiting for the |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2996 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2996 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2997 | 2997 |
2998 // At this point the ProxyService should have re-configured itself to use the | 2998 // At this point the ProxyService should have re-configured itself to use the |
2999 // new PAC script. | 2999 // new PAC script. |
3000 | 3000 |
3001 // Start a second request. | 3001 // Start a second request. |
3002 ProxyInfo info2; | 3002 ProxyInfo info2; |
3003 TestCompletionCallback callback2; | 3003 TestCompletionCallback callback2; |
3004 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 3004 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
3005 callback2.callback(), nullptr, nullptr, | 3005 callback2.callback(), nullptr, nullptr, |
3006 BoundNetLog()); | 3006 NetLogWithSource()); |
3007 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3007 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3008 | 3008 |
3009 // Check that it was sent to the resolver. | 3009 // Check that it was sent to the resolver. |
3010 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3010 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3011 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3011 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
3012 | 3012 |
3013 // Complete the pending second request. | 3013 // Complete the pending second request. |
3014 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3014 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
3015 resolver.pending_requests()[0]->CompleteNow(OK); | 3015 resolver.pending_requests()[0]->CompleteNow(OK); |
3016 | 3016 |
(...skipping 25 matching lines...) Expand all Loading... |
3042 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 3042 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
3043 service.SetProxyScriptFetchers( | 3043 service.SetProxyScriptFetchers( |
3044 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3044 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
3045 | 3045 |
3046 // Start 1 request. | 3046 // Start 1 request. |
3047 | 3047 |
3048 ProxyInfo info1; | 3048 ProxyInfo info1; |
3049 TestCompletionCallback callback1; | 3049 TestCompletionCallback callback1; |
3050 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, | 3050 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
3051 callback1.callback(), nullptr, nullptr, | 3051 callback1.callback(), nullptr, nullptr, |
3052 BoundNetLog()); | 3052 NetLogWithSource()); |
3053 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3053 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3054 | 3054 |
3055 // The first request should have triggered initial download of PAC script. | 3055 // The first request should have triggered initial download of PAC script. |
3056 EXPECT_TRUE(fetcher->has_pending_request()); | 3056 EXPECT_TRUE(fetcher->has_pending_request()); |
3057 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3057 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3058 | 3058 |
3059 // Nothing has been sent to the factory yet. | 3059 // Nothing has been sent to the factory yet. |
3060 EXPECT_TRUE(factory->pending_requests().empty()); | 3060 EXPECT_TRUE(factory->pending_requests().empty()); |
3061 | 3061 |
3062 // At this point the ProxyService should be waiting for the | 3062 // At this point the ProxyService should be waiting for the |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3106 ASSERT_TRUE(resolver.pending_requests().empty()); | 3106 ASSERT_TRUE(resolver.pending_requests().empty()); |
3107 | 3107 |
3108 // At this point the ProxyService is still running the same PAC script as | 3108 // At this point the ProxyService is still running the same PAC script as |
3109 // before. | 3109 // before. |
3110 | 3110 |
3111 // Start a second request. | 3111 // Start a second request. |
3112 ProxyInfo info2; | 3112 ProxyInfo info2; |
3113 TestCompletionCallback callback2; | 3113 TestCompletionCallback callback2; |
3114 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 3114 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
3115 callback2.callback(), nullptr, nullptr, | 3115 callback2.callback(), nullptr, nullptr, |
3116 BoundNetLog()); | 3116 NetLogWithSource()); |
3117 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3117 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3118 | 3118 |
3119 // Check that it was sent to the resolver. | 3119 // Check that it was sent to the resolver. |
3120 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3120 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3121 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3121 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
3122 | 3122 |
3123 // Complete the pending second request. | 3123 // Complete the pending second request. |
3124 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3124 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
3125 resolver.pending_requests()[0]->CompleteNow(OK); | 3125 resolver.pending_requests()[0]->CompleteNow(OK); |
3126 | 3126 |
(...skipping 25 matching lines...) Expand all Loading... |
3152 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 3152 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
3153 service.SetProxyScriptFetchers( | 3153 service.SetProxyScriptFetchers( |
3154 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3154 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
3155 | 3155 |
3156 // Start 1 request. | 3156 // Start 1 request. |
3157 | 3157 |
3158 ProxyInfo info1; | 3158 ProxyInfo info1; |
3159 TestCompletionCallback callback1; | 3159 TestCompletionCallback callback1; |
3160 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, | 3160 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
3161 callback1.callback(), nullptr, nullptr, | 3161 callback1.callback(), nullptr, nullptr, |
3162 BoundNetLog()); | 3162 NetLogWithSource()); |
3163 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3163 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3164 | 3164 |
3165 // The first request should have triggered initial download of PAC script. | 3165 // The first request should have triggered initial download of PAC script. |
3166 EXPECT_TRUE(fetcher->has_pending_request()); | 3166 EXPECT_TRUE(fetcher->has_pending_request()); |
3167 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3167 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3168 | 3168 |
3169 // Nothing has been sent to the factory yet. | 3169 // Nothing has been sent to the factory yet. |
3170 EXPECT_TRUE(factory->pending_requests().empty()); | 3170 EXPECT_TRUE(factory->pending_requests().empty()); |
3171 | 3171 |
3172 // At this point the ProxyService should be waiting for the | 3172 // At this point the ProxyService should be waiting for the |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3213 base::RunLoop().RunUntilIdle(); | 3213 base::RunLoop().RunUntilIdle(); |
3214 | 3214 |
3215 // At this point the ProxyService should have re-configured itself to use | 3215 // At this point the ProxyService should have re-configured itself to use |
3216 // DIRECT connections rather than the given proxy resolver. | 3216 // DIRECT connections rather than the given proxy resolver. |
3217 | 3217 |
3218 // Start a second request. | 3218 // Start a second request. |
3219 ProxyInfo info2; | 3219 ProxyInfo info2; |
3220 TestCompletionCallback callback2; | 3220 TestCompletionCallback callback2; |
3221 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 3221 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
3222 callback2.callback(), nullptr, nullptr, | 3222 callback2.callback(), nullptr, nullptr, |
3223 BoundNetLog()); | 3223 NetLogWithSource()); |
3224 EXPECT_THAT(rv, IsOk()); | 3224 EXPECT_THAT(rv, IsOk()); |
3225 EXPECT_TRUE(info2.is_direct()); | 3225 EXPECT_TRUE(info2.is_direct()); |
3226 } | 3226 } |
3227 | 3227 |
3228 // Tests that the code which decides at what times to poll the PAC | 3228 // Tests that the code which decides at what times to poll the PAC |
3229 // script follows the expected policy. | 3229 // script follows the expected policy. |
3230 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { | 3230 TEST_F(ProxyServiceTest, PACScriptPollingPolicy) { |
3231 // Retrieve the internal polling policy implementation used by ProxyService. | 3231 // Retrieve the internal polling policy implementation used by ProxyService. |
3232 std::unique_ptr<ProxyService::PacPollPolicy> policy = | 3232 std::unique_ptr<ProxyService::PacPollPolicy> policy = |
3233 ProxyService::CreateDefaultPacPollPolicy(); | 3233 ProxyService::CreateDefaultPacPollPolicy(); |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3307 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 3307 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
3308 service.SetProxyScriptFetchers( | 3308 service.SetProxyScriptFetchers( |
3309 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 3309 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
3310 | 3310 |
3311 // Start 1 request. | 3311 // Start 1 request. |
3312 | 3312 |
3313 ProxyInfo info1; | 3313 ProxyInfo info1; |
3314 TestCompletionCallback callback1; | 3314 TestCompletionCallback callback1; |
3315 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, | 3315 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
3316 callback1.callback(), nullptr, nullptr, | 3316 callback1.callback(), nullptr, nullptr, |
3317 BoundNetLog()); | 3317 NetLogWithSource()); |
3318 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3318 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3319 | 3319 |
3320 // The first request should have triggered initial download of PAC script. | 3320 // The first request should have triggered initial download of PAC script. |
3321 EXPECT_TRUE(fetcher->has_pending_request()); | 3321 EXPECT_TRUE(fetcher->has_pending_request()); |
3322 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3322 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3323 | 3323 |
3324 // Nothing has been sent to the factory yet. | 3324 // Nothing has been sent to the factory yet. |
3325 EXPECT_TRUE(factory->pending_requests().empty()); | 3325 EXPECT_TRUE(factory->pending_requests().empty()); |
3326 | 3326 |
3327 // At this point the ProxyService should be waiting for the | 3327 // At this point the ProxyService should be waiting for the |
(...skipping 24 matching lines...) Expand all Loading... |
3352 | 3352 |
3353 ASSERT_FALSE(fetcher->has_pending_request()); | 3353 ASSERT_FALSE(fetcher->has_pending_request()); |
3354 ASSERT_TRUE(factory->pending_requests().empty()); | 3354 ASSERT_TRUE(factory->pending_requests().empty()); |
3355 ASSERT_TRUE(resolver.pending_requests().empty()); | 3355 ASSERT_TRUE(resolver.pending_requests().empty()); |
3356 | 3356 |
3357 // Start a second request. | 3357 // Start a second request. |
3358 ProxyInfo info2; | 3358 ProxyInfo info2; |
3359 TestCompletionCallback callback2; | 3359 TestCompletionCallback callback2; |
3360 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 3360 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
3361 callback2.callback(), nullptr, nullptr, | 3361 callback2.callback(), nullptr, nullptr, |
3362 BoundNetLog()); | 3362 NetLogWithSource()); |
3363 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3363 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3364 | 3364 |
3365 // This request should have sent work to the resolver; complete it. | 3365 // This request should have sent work to the resolver; complete it. |
3366 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3366 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3367 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3367 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
3368 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3368 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
3369 resolver.pending_requests()[0]->CompleteNow(OK); | 3369 resolver.pending_requests()[0]->CompleteNow(OK); |
3370 | 3370 |
3371 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 3371 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
3372 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3372 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
(...skipping 10 matching lines...) Expand all Loading... |
3383 // Drain the message loop, so ProxyService is notified of the change | 3383 // Drain the message loop, so ProxyService is notified of the change |
3384 // and has a chance to re-configure itself. | 3384 // and has a chance to re-configure itself. |
3385 base::RunLoop().RunUntilIdle(); | 3385 base::RunLoop().RunUntilIdle(); |
3386 | 3386 |
3387 // Start a third request -- this time we expect to get a direct connection | 3387 // Start a third request -- this time we expect to get a direct connection |
3388 // since the PAC script poller experienced a failure. | 3388 // since the PAC script poller experienced a failure. |
3389 ProxyInfo info3; | 3389 ProxyInfo info3; |
3390 TestCompletionCallback callback3; | 3390 TestCompletionCallback callback3; |
3391 rv = service.ResolveProxy(GURL("http://request3"), std::string(), &info3, | 3391 rv = service.ResolveProxy(GURL("http://request3"), std::string(), &info3, |
3392 callback3.callback(), nullptr, nullptr, | 3392 callback3.callback(), nullptr, nullptr, |
3393 BoundNetLog()); | 3393 NetLogWithSource()); |
3394 EXPECT_THAT(rv, IsOk()); | 3394 EXPECT_THAT(rv, IsOk()); |
3395 EXPECT_TRUE(info3.is_direct()); | 3395 EXPECT_TRUE(info3.is_direct()); |
3396 } | 3396 } |
3397 | 3397 |
3398 // Test that the synchronous resolution fails when a PAC script is active. | 3398 // Test that the synchronous resolution fails when a PAC script is active. |
3399 TEST_F(ProxyServiceTest, SynchronousWithPAC) { | 3399 TEST_F(ProxyServiceTest, SynchronousWithPAC) { |
3400 MockProxyConfigService* config_service = | 3400 MockProxyConfigService* config_service = |
3401 new MockProxyConfigService("http://foopy/proxy.pac"); | 3401 new MockProxyConfigService("http://foopy/proxy.pac"); |
3402 | 3402 |
3403 MockAsyncProxyResolverFactory* factory = | 3403 MockAsyncProxyResolverFactory* factory = |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3464 base::WrapUnique(factory), nullptr)); | 3464 base::WrapUnique(factory), nullptr)); |
3465 | 3465 |
3466 // Do an initial request to initialize the service (configure the PAC | 3466 // Do an initial request to initialize the service (configure the PAC |
3467 // script). | 3467 // script). |
3468 GURL url("http://example.com"); | 3468 GURL url("http://example.com"); |
3469 | 3469 |
3470 ProxyInfo info; | 3470 ProxyInfo info; |
3471 TestCompletionCallback callback; | 3471 TestCompletionCallback callback; |
3472 int rv = | 3472 int rv = |
3473 service_->ResolveProxy(url, std::string(), &info, callback.callback(), | 3473 service_->ResolveProxy(url, std::string(), &info, callback.callback(), |
3474 nullptr, nullptr, BoundNetLog()); | 3474 nullptr, nullptr, NetLogWithSource()); |
3475 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3475 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3476 | 3476 |
3477 // First step is to download the PAC script. | 3477 // First step is to download the PAC script. |
3478 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 3478 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
3479 factory->pending_requests()[0]->script_data()->url()); | 3479 factory->pending_requests()[0]->script_data()->url()); |
3480 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3480 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3481 | 3481 |
3482 EXPECT_EQ(1u, resolver.pending_requests().size()); | 3482 EXPECT_EQ(1u, resolver.pending_requests().size()); |
3483 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 3483 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
3484 | 3484 |
(...skipping 11 matching lines...) Expand all Loading... |
3496 } | 3496 } |
3497 | 3497 |
3498 // Makes a proxy resolution request through the ProxyService, and returns the | 3498 // Makes a proxy resolution request through the ProxyService, and returns the |
3499 // URL that was submitted to the Proxy Resolver. | 3499 // URL that was submitted to the Proxy Resolver. |
3500 GURL SanitizeUrl(const GURL& raw_url) { | 3500 GURL SanitizeUrl(const GURL& raw_url) { |
3501 // Issue a request and see what URL is sent to the proxy resolver. | 3501 // Issue a request and see what URL is sent to the proxy resolver. |
3502 ProxyInfo info; | 3502 ProxyInfo info; |
3503 TestCompletionCallback callback; | 3503 TestCompletionCallback callback; |
3504 int rv = service_->ResolveProxy(raw_url, std::string(), &info, | 3504 int rv = service_->ResolveProxy(raw_url, std::string(), &info, |
3505 callback.callback(), nullptr, nullptr, | 3505 callback.callback(), nullptr, nullptr, |
3506 BoundNetLog()); | 3506 NetLogWithSource()); |
3507 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3507 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3508 | 3508 |
3509 EXPECT_EQ(1u, resolver.pending_requests().size()); | 3509 EXPECT_EQ(1u, resolver.pending_requests().size()); |
3510 | 3510 |
3511 GURL sanitized_url = resolver.pending_requests()[0]->url(); | 3511 GURL sanitized_url = resolver.pending_requests()[0]->url(); |
3512 | 3512 |
3513 // Complete the request. | 3513 // Complete the request. |
3514 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); | 3514 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); |
3515 resolver.pending_requests()[0]->CompleteNow(OK); | 3515 resolver.pending_requests()[0]->CompleteNow(OK); |
3516 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 3516 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3662 GURL(test.sanitized_url_unstripped), | 3662 GURL(test.sanitized_url_unstripped), |
3663 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); | 3663 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); |
3664 | 3664 |
3665 EXPECT_EQ( | 3665 EXPECT_EQ( |
3666 GURL(test.sanitized_url), | 3666 GURL(test.sanitized_url), |
3667 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); | 3667 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); |
3668 } | 3668 } |
3669 } | 3669 } |
3670 | 3670 |
3671 } // namespace net | 3671 } // namespace net |
OLD | NEW |