summaryrefslogtreecommitdiffstats
path: root/net/proxy/proxy_service_unittest.cc
diff options
context:
space:
mode:
authorericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-19 22:17:53 +0000
committerericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2008-12-19 22:17:53 +0000
commit51fff29dc2dae1a8be5ea107d2b13205510c4e46 (patch)
tree56a82f110e5605f9aed8f75b2cf954cc5765ed1a /net/proxy/proxy_service_unittest.cc
parent4750a86ea19e14d99a6b5fc94cd18d08ced463da (diff)
downloadchromium_src-51fff29dc2dae1a8be5ea107d2b13205510c4e46.zip
chromium_src-51fff29dc2dae1a8be5ea107d2b13205510c4e46.tar.gz
chromium_src-51fff29dc2dae1a8be5ea107d2b13205510c4e46.tar.bz2
Split ProxyResolver into two interfaces: A. interface for retrieving the system proxy settings (ProxyConfigService) B. interface for resolving the proxy (ProxyResolver)The motivation behind this change is: 1. Simplify sharing the WinHTTP code that fetches IE settings, with the V8 proxy resolver (avoids having platform-specific code in ProxyResolverV8). 2. Restrict objects to one thread. (ProxyService calls the config getter on IO thread, and the proxy resolving on the PAC thread).(ProxyResolver is now only 1 method, but this will grow shortly).
Review URL: http://codereview.chromium.org/15070 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@7323 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net/proxy/proxy_service_unittest.cc')
-rw-r--r--net/proxy/proxy_service_unittest.cc116
1 files changed, 72 insertions, 44 deletions
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
index 1ad7d32..48a8721 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -9,22 +9,32 @@
namespace {
-class MockProxyResolver : public net::ProxyResolver {
+// TODO(eroman): get rid of synchronous usages of ProxyService::ResolveProxy().
+
+class MockProxyConfigService: public net::ProxyConfigService {
public:
- MockProxyResolver() : fail_get_proxy_for_url(false) {
- }
- // Init the MockProxyResolver with the specified ProxyConfig.
- explicit MockProxyResolver(const net::ProxyConfig& c) : config(c) {
+ MockProxyConfigService() {} // Direct connect.
+ explicit MockProxyConfigService(const net::ProxyConfig& pc) : config(pc) {}
+ explicit MockProxyConfigService(const std::string& pac_url) {
+ config.pac_url = GURL(pac_url);
}
+
virtual int GetProxyConfig(net::ProxyConfig* results) {
*results = config;
return net::OK;
}
+
+ net::ProxyConfig config;
+};
+
+class MockProxyResolver : public net::ProxyResolver {
+ public:
+ MockProxyResolver() : fail_get_proxy_for_url(false) {
+ }
+
virtual int GetProxyForURL(const GURL& query_url,
const GURL& pac_url,
net::ProxyInfo* results) {
- if (pac_url != config.pac_url)
- return net::ERR_INVALID_ARGUMENT;
if (fail_get_proxy_for_url)
return net::ERR_FAILED;
if (GURL(query_url).host() == info_predicate_query_host) {
@@ -34,7 +44,7 @@ class MockProxyResolver : public net::ProxyResolver {
}
return net::OK;
}
- net::ProxyConfig config;
+
net::ProxyInfo info;
// info is only returned if query_url in GetProxyForURL matches this:
@@ -62,7 +72,8 @@ TEST(ProxyListTest, GetAnnotatedList) {
}
TEST(ProxyServiceTest, Direct) {
- net::ProxyService service(new MockProxyResolver);
+ net::ProxyService service(new MockProxyConfigService,
+ new MockProxyResolver);
GURL url("http://www.google.com/");
@@ -73,12 +84,14 @@ TEST(ProxyServiceTest, Direct) {
}
TEST(ProxyServiceTest, PAC) {
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
MockProxyResolver* resolver = new MockProxyResolver;
- resolver->config.pac_url = GURL("http://foopy/proxy.pac");
resolver->info.UseNamedProxy("foopy");
resolver->info_predicate_query_host = "www.google.com";
- net::ProxyService service(resolver);
+ net::ProxyService service(config_service, resolver);
GURL url("http://www.google.com/");
@@ -90,12 +103,14 @@ TEST(ProxyServiceTest, PAC) {
}
TEST(ProxyServiceTest, PAC_FailoverToDirect) {
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
MockProxyResolver* resolver = new MockProxyResolver;
- resolver->config.pac_url = GURL("http://foopy/proxy.pac");
resolver->info.UseNamedProxy("foopy:8080");
resolver->info_predicate_query_host = "www.google.com";
- net::ProxyService service(resolver);
+ net::ProxyService service(config_service, resolver);
GURL url("http://www.google.com/");
@@ -114,13 +129,15 @@ TEST(ProxyServiceTest, PAC_FailoverToDirect) {
TEST(ProxyServiceTest, PAC_FailsToDownload) {
// Test what happens when we fail to download the PAC URL.
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
MockProxyResolver* resolver = new MockProxyResolver;
- resolver->config.pac_url = GURL("http://foopy/proxy.pac");
resolver->info.UseNamedProxy("foopy:8080");
resolver->info_predicate_query_host = "www.google.com";
resolver->fail_get_proxy_for_url = true;
- net::ProxyService service(resolver);
+ net::ProxyService service(config_service, resolver);
GURL url("http://www.google.com/");
net::ProxyInfo info;
@@ -147,13 +164,15 @@ TEST(ProxyServiceTest, ProxyFallback) {
// Test what happens when we specify multiple proxy servers and some of them
// are bad.
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
MockProxyResolver* resolver = new MockProxyResolver;
- resolver->config.pac_url = GURL("http://foopy/proxy.pac");
resolver->info.UseNamedProxy("foopy1:8080;foopy2:9090");
resolver->info_predicate_query_host = "www.google.com";
resolver->fail_get_proxy_for_url = false;
- net::ProxyService service(resolver);
+ net::ProxyService service(config_service, resolver);
GURL url("http://www.google.com/");
@@ -175,7 +194,7 @@ TEST(ProxyServiceTest, ProxyFallback) {
// Create a new resolver that returns 3 proxies. The second one is already
// known to be bad.
- resolver->config.pac_url = GURL("http://foopy/proxy.pac");
+ config_service->config.pac_url = GURL("http://foopy/proxy.pac");
resolver->info.UseNamedProxy("foopy3:7070;foopy1:8080;foopy2:9090");
resolver->info_predicate_query_host = "www.google.com";
resolver->fail_get_proxy_for_url = false;
@@ -205,13 +224,15 @@ TEST(ProxyServiceTest, ProxyFallback) {
TEST(ProxyServiceTest, ProxyFallback_NewSettings) {
// Test proxy failover when new settings are available.
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
MockProxyResolver* resolver = new MockProxyResolver;
- resolver->config.pac_url = GURL("http://foopy/proxy.pac");
resolver->info.UseNamedProxy("foopy1:8080;foopy2:9090");
resolver->info_predicate_query_host = "www.google.com";
resolver->fail_get_proxy_for_url = false;
- net::ProxyService service(resolver);
+ net::ProxyService service(config_service, resolver);
GURL url("http://www.google.com/");
@@ -225,8 +246,8 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) {
EXPECT_EQ(info.proxy_server(), "foopy1:8080");
// Fake an error on the proxy, and also a new configuration on the proxy.
- resolver->config = net::ProxyConfig();
- resolver->config.pac_url = GURL("http://foopy-new/proxy.pac");
+ config_service->config = net::ProxyConfig();
+ config_service->config.pac_url = GURL("http://foopy-new/proxy.pac");
rv = service.ReconsiderProxyAfterError(url, &info, NULL, NULL);
EXPECT_EQ(rv, net::OK);
@@ -240,8 +261,8 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) {
EXPECT_EQ(info.proxy_server(), "foopy2:9090");
// We simulate a new configuration.
- resolver->config = net::ProxyConfig();
- resolver->config.pac_url = GURL("http://foopy-new2/proxy.pac");
+ config_service->config = net::ProxyConfig();
+ config_service->config.pac_url = GURL("http://foopy-new2/proxy.pac");
// We fake anothe error. It should go back to the first proxy.
rv = service.ReconsiderProxyAfterError(url, &info, NULL, NULL);
@@ -252,13 +273,15 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) {
TEST(ProxyServiceTest, ProxyFallback_BadConfig) {
// Test proxy failover when the configuration is bad.
+ MockProxyConfigService* config_service =
+ new MockProxyConfigService("http://foopy/proxy.pac");
+
MockProxyResolver* resolver = new MockProxyResolver;
- resolver->config.pac_url = GURL("http://foopy/proxy.pac");
resolver->info.UseNamedProxy("foopy1:8080;foopy2:9090");
resolver->info_predicate_query_host = "www.google.com";
resolver->fail_get_proxy_for_url = false;
- net::ProxyService service(resolver);
+ net::ProxyService service(config_service, resolver);
GURL url("http://www.google.com/");
@@ -318,7 +341,8 @@ TEST(ProxyServiceTest, ProxyBypassList) {
config.auto_detect = false;
config.proxy_bypass_local_names = true;
- net::ProxyService service(new MockProxyResolver(config));
+ net::ProxyService service(new MockProxyConfigService(config),
+ new MockProxyResolver());
GURL url("http://www.google.com/");
// Get the proxy information.
net::ProxyInfo info;
@@ -326,7 +350,8 @@ TEST(ProxyServiceTest, ProxyBypassList) {
EXPECT_EQ(rv, net::OK);
EXPECT_FALSE(info.is_direct());
- net::ProxyService service1(new MockProxyResolver(config));
+ net::ProxyService service1(new MockProxyConfigService(config),
+ new MockProxyResolver());
GURL test_url1("local");
net::ProxyInfo info1;
rv = service1.ResolveProxy(test_url1, &info1, NULL, NULL);
@@ -336,8 +361,8 @@ TEST(ProxyServiceTest, ProxyBypassList) {
config.proxy_bypass.clear();
config.proxy_bypass.push_back("*.org");
config.proxy_bypass_local_names = true;
- MockProxyResolver* resolver = new MockProxyResolver(config);
- net::ProxyService service2(resolver);
+ net::ProxyService service2(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url2("http://www.webkit.org");
net::ProxyInfo info2;
rv = service2.ResolveProxy(test_url2, &info2, NULL, NULL);
@@ -348,8 +373,8 @@ TEST(ProxyServiceTest, ProxyBypassList) {
config.proxy_bypass.push_back("*.org");
config.proxy_bypass.push_back("7*");
config.proxy_bypass_local_names = true;
- resolver = new MockProxyResolver(config);
- net::ProxyService service3(resolver);
+ net::ProxyService service3(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url3("http://74.125.19.147");
net::ProxyInfo info3;
rv = service3.ResolveProxy(test_url3, &info3, NULL, NULL);
@@ -359,8 +384,8 @@ TEST(ProxyServiceTest, ProxyBypassList) {
config.proxy_bypass.clear();
config.proxy_bypass.push_back("*.org");
config.proxy_bypass_local_names = true;
- resolver = new MockProxyResolver(config);
- net::ProxyService service4(resolver);
+ net::ProxyService service4(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url4("http://www.msn.com");
net::ProxyInfo info4;
rv = service4.ResolveProxy(test_url4, &info4, NULL, NULL);
@@ -370,8 +395,8 @@ TEST(ProxyServiceTest, ProxyBypassList) {
config.proxy_bypass.clear();
config.proxy_bypass.push_back("*.MSN.COM");
config.proxy_bypass_local_names = true;
- resolver = new MockProxyResolver(config);
- net::ProxyService service5(resolver);
+ net::ProxyService service5(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url5("http://www.msnbc.msn.com");
net::ProxyInfo info5;
rv = service5.ResolveProxy(test_url5, &info5, NULL, NULL);
@@ -381,8 +406,8 @@ TEST(ProxyServiceTest, ProxyBypassList) {
config.proxy_bypass.clear();
config.proxy_bypass.push_back("*.msn.com");
config.proxy_bypass_local_names = true;
- resolver = new MockProxyResolver(config);
- net::ProxyService service6(resolver);
+ net::ProxyService service6(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url6("HTTP://WWW.MSNBC.MSN.COM");
net::ProxyInfo info6;
rv = service6.ResolveProxy(test_url6, &info6, NULL, NULL);
@@ -395,7 +420,8 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) {
config.proxy_server = "http=foopy1:8080;https=foopy2:8080";
config.auto_detect = false;
- net::ProxyService service1(new MockProxyResolver(config));
+ net::ProxyService service1(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url1("http://www.msn.com");
net::ProxyInfo info1;
int rv = service1.ResolveProxy(test_url1, &info1, NULL, NULL);
@@ -403,7 +429,8 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) {
EXPECT_FALSE(info1.is_direct());
EXPECT_TRUE(info1.proxy_server() == "foopy1:8080");
- net::ProxyService service2(new MockProxyResolver(config));
+ net::ProxyService service2(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url2("ftp://ftp.google.com");
net::ProxyInfo info2;
rv = service2.ResolveProxy(test_url2, &info2, NULL, NULL);
@@ -411,7 +438,8 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) {
EXPECT_TRUE(info2.is_direct());
EXPECT_TRUE(info2.proxy_server() == "");
- net::ProxyService service3(new MockProxyResolver(config));
+ net::ProxyService service3(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url3("https://webbranch.techcu.com");
net::ProxyInfo info3;
rv = service3.ResolveProxy(test_url3, &info3, NULL, NULL);
@@ -419,9 +447,9 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) {
EXPECT_FALSE(info3.is_direct());
EXPECT_TRUE(info3.proxy_server() == "foopy2:8080");
- MockProxyResolver* resolver = new MockProxyResolver(config);
- resolver->config.proxy_server = "foopy1:8080";
- net::ProxyService service4(resolver);
+ config.proxy_server = "foopy1:8080";
+ net::ProxyService service4(new MockProxyConfigService(config),
+ new MockProxyResolver);
GURL test_url4("www.microsoft.com");
net::ProxyInfo info4;
rv = service4.ResolveProxy(test_url4, &info4, NULL, NULL);