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

Unified Diff: net/proxy/proxy_service_unittest.cc

Issue 2845643003: Allow ProxyService to share URLRequestContext with everything else. (Closed)
Patch Set: Fix Created 3 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
Index: net/proxy/proxy_service_unittest.cc
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
index c57b23834f90683b68f594eb962f5dd284b2adfd..49d726805aa2f292a158d635defe236c8b787db0 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -3685,4 +3685,104 @@ TEST_F(ProxyServiceTest, SanitizeUrlForPacScriptCryptographic) {
}
}
+TEST_F(ProxyServiceTest, RequestsHangAfterShutdown) {
+ MockAsyncProxyResolverFactory* factory =
+ new MockAsyncProxyResolverFactory(false);
+ ProxyService service(
+ base::MakeUnique<MockProxyConfigService>(ProxyConfig::CreateDirect()),
+ base::WrapUnique(factory), nullptr);
+
+ GURL url("http://www.google.com/");
+
+ service.ShutDown();
+
+ ProxyInfo info;
+ TestCompletionCallback callback;
+ ProxyService::PacRequest* request;
+ int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(),
+ &request, nullptr, NetLogWithSource());
+ EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
+ EXPECT_TRUE(factory->pending_requests().empty());
+ EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request));
+ EXPECT_FALSE(callback.have_result());
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(callback.have_result());
+ service.CancelPacRequest(request);
+
+ EXPECT_FALSE(service.TryResolveProxySynchronously(
+ url, std::string(), &info, nullptr, NetLogWithSource()));
+}
+
+TEST_F(ProxyServiceTest, ProxyResolverShutdownDuringPacRequest) {
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
+ MockAsyncProxyResolver resolver;
+ MockAsyncProxyResolverFactory* factory =
+ new MockAsyncProxyResolverFactory(false);
+
+ ProxyService service(base::WrapUnique(config_service),
+ base::WrapUnique(factory), nullptr);
+
+ // Start request.
+ GURL url("http://www.google.com/");
+ ProxyInfo info;
+ ProxyService::PacRequest* request;
+ TestCompletionCallback callback;
+ int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(),
+ &request, nullptr, NetLogWithSource());
+ EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
+
+ ASSERT_EQ(1u, factory->pending_requests().size());
+ EXPECT_EQ(GURL("http://foopy/proxy.pac"),
+ factory->pending_requests()[0]->script_data()->url());
+
+ service.ShutDown();
+ EXPECT_EQ(0u, factory->pending_requests().size());
+ EXPECT_EQ(1u, factory->cancelled_requests().size());
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(callback.have_result());
+ service.CancelPacRequest(request);
+}
+
+TEST_F(ProxyServiceTest, ProxyResolverShutdownAfterPacRequestDuringResolve) {
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
+ MockAsyncProxyResolver resolver;
+ MockAsyncProxyResolverFactory* factory =
+ new MockAsyncProxyResolverFactory(false);
+
+ ProxyService service(base::WrapUnique(config_service),
+ base::WrapUnique(factory), nullptr);
+
+ // Start request.
+ GURL url("http://www.google.com/");
+ ProxyInfo info;
+ ProxyService::PacRequest* request;
+ TestCompletionCallback callback;
+ int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(),
+ &request, nullptr, NetLogWithSource());
+ EXPECT_THAT(rv, IsError(ERR_IO_PENDING));
+
+ ASSERT_EQ(1u, factory->pending_requests().size());
+ EXPECT_EQ(GURL("http://foopy/proxy.pac"),
+ factory->pending_requests()[0]->script_data()->url());
+ factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver);
+ EXPECT_EQ(0u, factory->pending_requests().size());
+ // Checks that the one resolve job for |url| is outstanding.
+ GetPendingJobsForURLs(resolver, url);
+
+ service.ShutDown();
+ EXPECT_EQ(0u, factory->cancelled_requests().size());
+ // Checks that no resolve jobs are outstanding.
+ GetPendingJobsForURLs(resolver);
+
+ base::RunLoop().RunUntilIdle();
+ EXPECT_FALSE(callback.have_result());
+ service.CancelPacRequest(request);
+}
+
} // namespace net

Powered by Google App Engine
This is Rietveld 408576698