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

Unified Diff: net/proxy/proxy_service_unittest.cc

Issue 10310179: Track sources of proxy settings. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Update copyright Created 8 years, 6 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
« net/proxy/proxy_info.cc ('K') | « 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 abd6d6aa075205326a184eef3174591f83fde48c..cec0035f721fd4d9ba96f545833dbb9554628617 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -216,6 +216,7 @@ TEST_F(ProxyServiceTest, PAC) {
EXPECT_EQ(OK, callback.WaitForResult());
EXPECT_FALSE(info.is_direct());
EXPECT_EQ("foopy:80", info.proxy_server().ToURI());
+ EXPECT_TRUE(info.did_use_pac_script());
// Check the NetLog was filled correctly.
CapturingNetLog::CapturedEntryList entries;
@@ -292,6 +293,7 @@ TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) {
EXPECT_EQ(OK, callback1.WaitForResult());
EXPECT_FALSE(info.is_direct());
EXPECT_EQ("foopy:8080", info.proxy_server().ToURI());
+ EXPECT_TRUE(info.did_use_pac_script());
// Now, imagine that connecting to foopy:8080 fails: there is nothing
// left to fallback to, since our proxy list was NOT terminated by
@@ -382,6 +384,36 @@ TEST_F(ProxyServiceTest, PAC_FailoverAfterDirect) {
EXPECT_TRUE(info.is_empty());
}
+TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) {
+ // Test whether the ProxyConfigSource set by the ProxyConfigService is applied
+ // to ProxyInfo after the proxy is resolved via a PAC script.
+ ProxyConfig config =
+ ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"));
+ config.set_source(PROXY_CONFIG_SOURCE_TEST);
+
+ MockProxyConfigService* config_service = new MockProxyConfigService(config);
+ MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
+ ProxyService service(config_service, resolver, NULL);
+
+ // Resolve something.
+ GURL url("http://www.google.com/");
+ ProxyInfo info;
+ TestCompletionCallback callback;
+ int rv = service.ResolveProxy(
+ url, &info, callback.callback(), NULL, BoundNetLog());
+ ASSERT_EQ(ERR_IO_PENDING, rv);
+ resolver->pending_set_pac_script_request()->CompleteNow(OK);
+ ASSERT_EQ(1u, resolver->pending_requests().size());
+
+ // Set the result in proxy resolver.
+ resolver->pending_requests()[0]->results()->UseNamedProxy("foopy");
+ resolver->pending_requests()[0]->CompleteNow(OK);
+
+ EXPECT_EQ(OK, callback.WaitForResult());
+ EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
+ EXPECT_TRUE(info.did_use_pac_script());
+}
+
TEST_F(ProxyServiceTest, ProxyResolverFails) {
// Test what happens when the ProxyResolver fails. The download and setting
// of the PAC script have already succeeded, so this corresponds with a
@@ -1120,6 +1152,56 @@ TEST_F(ProxyServiceTest, PerProtocolProxyTests) {
}
}
+TEST_F(ProxyServiceTest, ProxyConfigSourcePropagates) {
+ // Test that the proxy config source is set correctly when resolving proxies
+ // using manual proxy rules. Namely, the config source should only be set if
+ // any of the rules were applied.
+ {
+ ProxyConfig config;
+ config.set_source(PROXY_CONFIG_SOURCE_TEST);
+ config.proxy_rules().ParseFromString("https=foopy2:8080");
+ ProxyService service(
+ new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
+ GURL test_url("http://www.google.com");
+ ProxyInfo info;
+ TestCompletionCallback callback;
+ int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL,
+ BoundNetLog());
+ ASSERT_EQ(OK, rv);
+ // Should be SOURCE_TEST, even if there are no HTTP proxies configured.
+ EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
+ }
+ {
+ ProxyConfig config;
+ config.set_source(PROXY_CONFIG_SOURCE_TEST);
+ config.proxy_rules().ParseFromString("https=foopy2:8080");
+ ProxyService service(
+ new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
+ GURL test_url("https://www.google.com");
+ ProxyInfo info;
+ TestCompletionCallback callback;
+ int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL,
+ BoundNetLog());
+ ASSERT_EQ(OK, rv);
+ // Used the HTTPS proxy. So source should be TEST.
+ EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
+ }
+ {
+ ProxyConfig config;
+ config.set_source(PROXY_CONFIG_SOURCE_TEST);
+ ProxyService service(
+ new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL);
+ GURL test_url("http://www.google.com");
+ ProxyInfo info;
+ TestCompletionCallback callback;
+ int rv = service.ResolveProxy(test_url, &info, callback.callback(), NULL,
+ BoundNetLog());
+ ASSERT_EQ(OK, rv);
+ // ProxyConfig is empty. Source should still be TEST.
+ EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source());
+ }
+}
+
// If only HTTP and a SOCKS proxy are specified, check if ftp/https queries
// fall back to the SOCKS proxy.
TEST_F(ProxyServiceTest, DefaultProxyFallbackToSOCKS) {
« net/proxy/proxy_info.cc ('K') | « net/proxy/proxy_service.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698