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

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

Issue 1069483003: Handle ERR_PAC_SCRIPT_TERMINATED in ProxyService. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 5 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "net/proxy/proxy_service.h" 5 #include "net/proxy/proxy_service.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/logging.h" 10 #include "base/logging.h"
(...skipping 742 matching lines...) Expand 10 before | Expand all | Expand 10 after
753 // This time we will have the resolver succeed (perhaps the PAC script has 753 // This time we will have the resolver succeed (perhaps the PAC script has
754 // a dependency on the current time). 754 // a dependency on the current time).
755 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); 755 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080");
756 resolver.pending_requests()[0]->CompleteNow(OK); 756 resolver.pending_requests()[0]->CompleteNow(OK);
757 757
758 EXPECT_EQ(OK, callback2.WaitForResult()); 758 EXPECT_EQ(OK, callback2.WaitForResult());
759 EXPECT_FALSE(info.is_direct()); 759 EXPECT_FALSE(info.is_direct());
760 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); 760 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI());
761 } 761 }
762 762
763 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) {
764 // Test what happens when the ProxyResolver fails with a fatal error while
765 // a GetProxyForURL() call is in progress.
766
767 MockProxyConfigService* config_service =
768 new MockProxyConfigService("http://foopy/proxy.pac");
769
770 MockAsyncProxyResolver resolver;
771
772 ProxyService service(
773 config_service,
774 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), nullptr);
775
776 // Start first resolve request.
777 GURL url("http://www.google.com/");
778 ProxyInfo info;
779 TestCompletionCallback callback1;
780 int rv =
781 service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback1.callback(),
782 nullptr, nullptr, BoundNetLog());
783 EXPECT_EQ(ERR_IO_PENDING, rv);
784
785 ASSERT_TRUE(resolver.pending_set_pac_script_request());
786 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
787 resolver.pending_set_pac_script_request()->script_data()->url());
788 resolver.pending_set_pac_script_request()->CompleteNow(OK);
789
790 ASSERT_EQ(1u, resolver.pending_requests().size());
791 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
792
793 // Fail the first resolve request in MockAsyncProxyResolver.
794 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED);
795
796 // Although the proxy resolver failed the request, ProxyService implicitly
797 // falls-back to DIRECT.
798 EXPECT_EQ(OK, callback1.WaitForResult());
799 EXPECT_TRUE(info.is_direct());
800
801 // Failed PAC executions still have proxy resolution times.
802 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
803 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
804 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
805
806 // With no other requests, the ProxyService waits for a new request before
807 // initializing a new ProxyResolver.
808 EXPECT_FALSE(resolver.pending_set_pac_script_request());
809
810 TestCompletionCallback callback2;
811 rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback2.callback(),
812 nullptr, nullptr, BoundNetLog());
813 EXPECT_EQ(ERR_IO_PENDING, rv);
814
815 ASSERT_TRUE(resolver.pending_set_pac_script_request());
816 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
817 resolver.pending_set_pac_script_request()->script_data()->url());
818 resolver.pending_set_pac_script_request()->CompleteNow(OK);
819
820 ASSERT_EQ(1u, resolver.pending_requests().size());
821 EXPECT_EQ(url, resolver.pending_requests()[0]->url());
822
823 // This time we will have the resolver succeed.
824 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080");
825 resolver.pending_requests()[0]->CompleteNow(OK);
826
827 EXPECT_EQ(OK, callback2.WaitForResult());
828 EXPECT_FALSE(info.is_direct());
829 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI());
830 }
831
832 TEST_F(ProxyServiceTest,
833 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) {
834 // Test what happens when the ProxyResolver fails with a fatal error while
835 // a GetProxyForURL() call is in progress.
836
837 MockProxyConfigService* config_service =
838 new MockProxyConfigService("http://foopy/proxy.pac");
839
840 MockAsyncProxyResolver resolver;
841
842 ProxyService service(
843 config_service,
844 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), nullptr);
845
846 // Start two resolve requests.
847 GURL url1("http://www.google.com/");
848 GURL url2("https://www.google.com/");
849 ProxyInfo info;
850 TestCompletionCallback callback1;
851 int rv =
852 service.ResolveProxy(url1, net::LOAD_NORMAL, &info, callback1.callback(),
853 nullptr, nullptr, BoundNetLog());
854 EXPECT_EQ(ERR_IO_PENDING, rv);
855 TestCompletionCallback callback2;
856 rv = service.ResolveProxy(url2, net::LOAD_NORMAL, &info, callback2.callback(),
857 nullptr, nullptr, BoundNetLog());
858 EXPECT_EQ(ERR_IO_PENDING, rv);
859
860 ASSERT_TRUE(resolver.pending_set_pac_script_request());
861 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
862 resolver.pending_set_pac_script_request()->script_data()->url());
863 resolver.pending_set_pac_script_request()->CompleteNow(OK);
864
865 ASSERT_EQ(2u, resolver.pending_requests().size());
866 EXPECT_EQ(url1, resolver.pending_requests()[0]->url());
867 EXPECT_EQ(url2, resolver.pending_requests()[1]->url());
868
869 // Fail the first resolve request in MockAsyncProxyResolver.
870 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED);
871
872 // Although the proxy resolver failed the request, ProxyService implicitly
873 // falls-back to DIRECT.
874 EXPECT_EQ(OK, callback1.WaitForResult());
875 EXPECT_TRUE(info.is_direct());
876
877 // Failed PAC executions still have proxy resolution times.
878 EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
879 EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
880 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
881
882 // The second request is cancelled when the proxy resolver terminates.
883 ASSERT_EQ(1u, resolver.cancelled_requests().size());
884 EXPECT_EQ(url2, resolver.cancelled_requests()[0]->url());
885
886 // Since a second request was in progress, the ProxyService starts
887 // initializating a new ProxyResolver.
888 ASSERT_TRUE(resolver.pending_set_pac_script_request());
889 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
890 resolver.pending_set_pac_script_request()->script_data()->url());
891 resolver.pending_set_pac_script_request()->CompleteNow(OK);
892
893 ASSERT_EQ(1u, resolver.pending_requests().size());
894 EXPECT_EQ(url2, resolver.pending_requests()[0]->url());
895
896 // This request succeeds.
897 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080");
898 resolver.pending_requests()[0]->CompleteNow(OK);
899
900 EXPECT_EQ(OK, callback2.WaitForResult());
901 EXPECT_FALSE(info.is_direct());
902 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI());
903 }
904
763 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { 905 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) {
764 // Test what happens when the ProxyScriptResolver fails to download a 906 // Test what happens when the ProxyScriptResolver fails to download a
765 // mandatory PAC script. 907 // mandatory PAC script.
766 908
767 ProxyConfig config( 909 ProxyConfig config(
768 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); 910 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")));
769 config.set_pac_mandatory(true); 911 config.set_pac_mandatory(true);
770 912
771 MockProxyConfigService* config_service = new MockProxyConfigService(config); 913 MockProxyConfigService* config_service = new MockProxyConfigService(config);
772 914
(...skipping 2393 matching lines...) Expand 10 before | Expand all | Expand 10 after
3166 url, net::LOAD_NORMAL, &info, NULL, log.bound()); 3308 url, net::LOAD_NORMAL, &info, NULL, log.bound());
3167 EXPECT_TRUE(synchronous_success); 3309 EXPECT_TRUE(synchronous_success);
3168 EXPECT_FALSE(info.is_direct()); 3310 EXPECT_FALSE(info.is_direct());
3169 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); 3311 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host());
3170 3312
3171 // No request should have been queued. 3313 // No request should have been queued.
3172 EXPECT_EQ(0u, resolver.pending_requests().size()); 3314 EXPECT_EQ(0u, resolver.pending_requests().size());
3173 } 3315 }
3174 3316
3175 } // namespace net 3317 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698