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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: net/proxy/proxy_service_unittest.cc
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
index db4151dbc51557aedae644b8fdc9ac13b1d18b86..12a2ce5504f47893cfba457850e6cd16afe9f98b 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -760,6 +760,148 @@ TEST_F(ProxyServiceTest, ProxyResolverFails) {
EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI());
}
+TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) {
+ // Test what happens when the ProxyResolver fails with a fatal error while
+ // a GetProxyForURL() call is in progress.
+
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
+ MockAsyncProxyResolver resolver;
+
+ ProxyService service(
+ config_service,
+ make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), nullptr);
+
+ // Start first resolve request.
+ GURL url("http://www.google.com/");
+ ProxyInfo info;
+ TestCompletionCallback callback1;
+ int rv =
+ service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback1.callback(),
+ nullptr, nullptr, BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ ASSERT_TRUE(resolver.pending_set_pac_script_request());
+ EXPECT_EQ(GURL("http://foopy/proxy.pac"),
+ resolver.pending_set_pac_script_request()->script_data()->url());
+ resolver.pending_set_pac_script_request()->CompleteNow(OK);
+
+ ASSERT_EQ(1u, resolver.pending_requests().size());
+ EXPECT_EQ(url, resolver.pending_requests()[0]->url());
+
+ // Fail the first resolve request in MockAsyncProxyResolver.
+ resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED);
+
+ // Although the proxy resolver failed the request, ProxyService implicitly
+ // falls-back to DIRECT.
+ EXPECT_EQ(OK, callback1.WaitForResult());
+ EXPECT_TRUE(info.is_direct());
+
+ // Failed PAC executions still have proxy resolution times.
+ EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
+ EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
+ EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
+
+ // With no other requests, the ProxyService waits for a new request before
+ // initializing a new ProxyResolver.
+ EXPECT_FALSE(resolver.pending_set_pac_script_request());
+
+ TestCompletionCallback callback2;
+ rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback2.callback(),
+ nullptr, nullptr, BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ ASSERT_TRUE(resolver.pending_set_pac_script_request());
+ EXPECT_EQ(GURL("http://foopy/proxy.pac"),
+ resolver.pending_set_pac_script_request()->script_data()->url());
+ resolver.pending_set_pac_script_request()->CompleteNow(OK);
+
+ ASSERT_EQ(1u, resolver.pending_requests().size());
+ EXPECT_EQ(url, resolver.pending_requests()[0]->url());
+
+ // This time we will have the resolver succeed.
+ resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080");
+ resolver.pending_requests()[0]->CompleteNow(OK);
+
+ EXPECT_EQ(OK, callback2.WaitForResult());
+ EXPECT_FALSE(info.is_direct());
+ EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI());
+}
+
+TEST_F(ProxyServiceTest,
+ ProxyResolverTerminatedDuringRequestWithConcurrentRequest) {
+ // Test what happens when the ProxyResolver fails with a fatal error while
+ // a GetProxyForURL() call is in progress.
+
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
+ MockAsyncProxyResolver resolver;
+
+ ProxyService service(
+ config_service,
+ make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), nullptr);
+
+ // Start two resolve requests.
+ GURL url1("http://www.google.com/");
+ GURL url2("https://www.google.com/");
+ ProxyInfo info;
+ TestCompletionCallback callback1;
+ int rv =
+ service.ResolveProxy(url1, net::LOAD_NORMAL, &info, callback1.callback(),
+ nullptr, nullptr, BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+ TestCompletionCallback callback2;
+ rv = service.ResolveProxy(url2, net::LOAD_NORMAL, &info, callback2.callback(),
+ nullptr, nullptr, BoundNetLog());
+ EXPECT_EQ(ERR_IO_PENDING, rv);
+
+ ASSERT_TRUE(resolver.pending_set_pac_script_request());
+ EXPECT_EQ(GURL("http://foopy/proxy.pac"),
+ resolver.pending_set_pac_script_request()->script_data()->url());
+ resolver.pending_set_pac_script_request()->CompleteNow(OK);
+
+ ASSERT_EQ(2u, resolver.pending_requests().size());
+ EXPECT_EQ(url1, resolver.pending_requests()[0]->url());
+ EXPECT_EQ(url2, resolver.pending_requests()[1]->url());
+
+ // Fail the first resolve request in MockAsyncProxyResolver.
+ resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED);
+
+ // Although the proxy resolver failed the request, ProxyService implicitly
+ // falls-back to DIRECT.
+ EXPECT_EQ(OK, callback1.WaitForResult());
+ EXPECT_TRUE(info.is_direct());
+
+ // Failed PAC executions still have proxy resolution times.
+ EXPECT_FALSE(info.proxy_resolve_start_time().is_null());
+ EXPECT_FALSE(info.proxy_resolve_end_time().is_null());
+ EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time());
+
+ // The second request is cancelled when the proxy resolver terminates.
+ ASSERT_EQ(1u, resolver.cancelled_requests().size());
+ EXPECT_EQ(url2, resolver.cancelled_requests()[0]->url());
+
+ // Since a second request was in progress, the ProxyService starts
+ // initializating a new ProxyResolver.
+ ASSERT_TRUE(resolver.pending_set_pac_script_request());
+ EXPECT_EQ(GURL("http://foopy/proxy.pac"),
+ resolver.pending_set_pac_script_request()->script_data()->url());
+ resolver.pending_set_pac_script_request()->CompleteNow(OK);
+
+ ASSERT_EQ(1u, resolver.pending_requests().size());
+ EXPECT_EQ(url2, resolver.pending_requests()[0]->url());
+
+ // This request succeeds.
+ resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080");
+ resolver.pending_requests()[0]->CompleteNow(OK);
+
+ EXPECT_EQ(OK, callback2.WaitForResult());
+ EXPECT_FALSE(info.is_direct());
+ EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI());
+}
+
TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) {
// Test what happens when the ProxyScriptResolver fails to download a
// mandatory PAC script.
« 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