summaryrefslogtreecommitdiffstats
path: root/net/proxy
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
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')
-rw-r--r--net/proxy/proxy_config_service_fixed.h30
-rw-r--r--net/proxy/proxy_config_service_win.cc58
-rw-r--r--net/proxy/proxy_config_service_win.h23
-rw-r--r--net/proxy/proxy_resolver_fixed.cc24
-rw-r--r--net/proxy/proxy_resolver_fixed.h30
-rw-r--r--net/proxy/proxy_resolver_mac.cc2
-rw-r--r--net/proxy/proxy_resolver_mac.h7
-rw-r--r--net/proxy/proxy_resolver_null.h28
-rw-r--r--net/proxy/proxy_resolver_winhttp.cc41
-rw-r--r--net/proxy/proxy_resolver_winhttp.h1
-rw-r--r--net/proxy/proxy_service.cc42
-rw-r--r--net/proxy/proxy_service.h28
-rw-r--r--net/proxy/proxy_service_unittest.cc116
13 files changed, 243 insertions, 187 deletions
diff --git a/net/proxy/proxy_config_service_fixed.h b/net/proxy/proxy_config_service_fixed.h
new file mode 100644
index 0000000..633af95
--- /dev/null
+++ b/net/proxy/proxy_config_service_fixed.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_PROXY_PROXY_CONFIG_SERVICE_FIXED_H_
+#define NET_PROXY_PROXY_CONFIG_SERVICE_FIXED_H_
+
+#include "net/proxy/proxy_service.h"
+
+namespace net {
+
+// Implementation of ProxyConfigService that returns a fixed result.
+class ProxyConfigServiceFixed : public ProxyConfigService {
+ public:
+ explicit ProxyConfigServiceFixed(const ProxyInfo& pi) { pi_.Use(pi); }
+
+ // ProxyConfigService methods:
+ virtual int GetProxyConfig(ProxyConfig* config) {
+ config->proxy_server = pi_.proxy_server();
+ return OK;
+ }
+
+ private:
+ ProxyInfo pi_;
+};
+
+} // namespace net
+
+#endif // NET_PROXY_PROXY_CONFIG_SERVICE_FIXED_H_
+
diff --git a/net/proxy/proxy_config_service_win.cc b/net/proxy/proxy_config_service_win.cc
new file mode 100644
index 0000000..f356ac9
--- /dev/null
+++ b/net/proxy/proxy_config_service_win.cc
@@ -0,0 +1,58 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "net/proxy/proxy_config_service_win.h"
+
+#include <windows.h>
+#include <winhttp.h>
+
+#include "base/string_tokenizer.h"
+#include "net/base/net_errors.h"
+
+#pragma comment(lib, "winhttp.lib")
+
+namespace net {
+
+static void FreeConfig(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* config) {
+ if (config->lpszAutoConfigUrl)
+ GlobalFree(config->lpszAutoConfigUrl);
+ if (config->lpszProxy)
+ GlobalFree(config->lpszProxy);
+ if (config->lpszProxyBypass)
+ GlobalFree(config->lpszProxyBypass);
+}
+
+int ProxyConfigServiceWin::GetProxyConfig(ProxyConfig* config) {
+ WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config = {0};
+ if (!WinHttpGetIEProxyConfigForCurrentUser(&ie_config)) {
+ LOG(ERROR) << "WinHttpGetIEProxyConfigForCurrentUser failed: " <<
+ GetLastError();
+ return ERR_FAILED; // TODO(darin): Bug 1189288: translate error code.
+ }
+
+ if (ie_config.fAutoDetect)
+ config->auto_detect = true;
+ if (ie_config.lpszProxy)
+ config->proxy_server = WideToASCII(ie_config.lpszProxy);
+ if (ie_config.lpszProxyBypass) {
+ std::string proxy_bypass = WideToASCII(ie_config.lpszProxyBypass);
+
+ StringTokenizer proxy_server_bypass_list(proxy_bypass, "; \t\n\r");
+ while (proxy_server_bypass_list.GetNext()) {
+ std::string bypass_url_domain = proxy_server_bypass_list.token();
+ if (bypass_url_domain == "<local>")
+ config->proxy_bypass_local_names = true;
+ else
+ config->proxy_bypass.push_back(bypass_url_domain);
+ }
+ }
+ if (ie_config.lpszAutoConfigUrl)
+ config->pac_url = GURL(ie_config.lpszAutoConfigUrl);
+
+ FreeConfig(&ie_config);
+ return OK;
+}
+
+} // namespace net
+
diff --git a/net/proxy/proxy_config_service_win.h b/net/proxy/proxy_config_service_win.h
new file mode 100644
index 0000000..f2a5e47
--- /dev/null
+++ b/net/proxy/proxy_config_service_win.h
@@ -0,0 +1,23 @@
+// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_
+#define NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_
+
+#include "net/proxy/proxy_service.h"
+
+namespace net {
+
+// Implementation of ProxyConfigService that retrieves the system proxy
+// settings.
+class ProxyConfigServiceWin : public ProxyConfigService {
+ public:
+ // ProxyConfigService methods.
+ virtual int GetProxyConfig(ProxyConfig* config);
+};
+
+} // namespace net
+
+#endif // NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_
+
diff --git a/net/proxy/proxy_resolver_fixed.cc b/net/proxy/proxy_resolver_fixed.cc
deleted file mode 100644
index b064803..0000000
--- a/net/proxy/proxy_resolver_fixed.cc
+++ /dev/null
@@ -1,24 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#include "net/proxy/proxy_resolver_fixed.h"
-
-#include "net/base/net_errors.h"
-
-namespace net {
-
-int ProxyResolverFixed::GetProxyConfig(ProxyConfig* config) {
- config->proxy_server = pi_.proxy_server();
- return OK;
-}
-
-int ProxyResolverFixed::GetProxyForURL(const GURL& query_url,
- const GURL& pac_url,
- ProxyInfo* results) {
- NOTREACHED() << "Should not be asked to do proxy auto config";
- return ERR_FAILED;
-}
-
-} // namespace net
-
diff --git a/net/proxy/proxy_resolver_fixed.h b/net/proxy/proxy_resolver_fixed.h
deleted file mode 100644
index 2ecd62c..0000000
--- a/net/proxy/proxy_resolver_fixed.h
+++ /dev/null
@@ -1,30 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_PROXY_PROXY_RESOLVER_FIXED_H_
-#define NET_PROXY_PROXY_RESOLVER_FIXED_H_
-
-#include "net/proxy/proxy_service.h"
-
-namespace net {
-
-// Implementation of ProxyResolver that returns a fixed result.
-class ProxyResolverFixed : public ProxyResolver {
- public:
- ProxyResolverFixed(const ProxyInfo& pi) { pi_.Use(pi); }
-
- // ProxyResolver methods:
- virtual int GetProxyConfig(ProxyConfig* config);
- virtual int GetProxyForURL(const GURL& query_url,
- const GURL& pac_url,
- ProxyInfo* results);
-
- private:
- ProxyInfo pi_;
-};
-
-} // namespace net
-
-#endif // NET_PROXY_PROXY_RESOLVER_FIXED_H_
-
diff --git a/net/proxy/proxy_resolver_mac.cc b/net/proxy/proxy_resolver_mac.cc
index f58cc85..4f021a4 100644
--- a/net/proxy/proxy_resolver_mac.cc
+++ b/net/proxy/proxy_resolver_mac.cc
@@ -115,7 +115,7 @@ void ResultCallback(void* client, CFArrayRef proxies, CFErrorRef error) {
namespace net {
-int ProxyResolverMac::GetProxyConfig(ProxyConfig* config) {
+int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
scoped_cftyperef<CFDictionaryRef> config_dict(
SCDynamicStoreCopyProxies(NULL));
DCHECK(config_dict);
diff --git a/net/proxy/proxy_resolver_mac.h b/net/proxy/proxy_resolver_mac.h
index a3b56fc..f207e1b 100644
--- a/net/proxy/proxy_resolver_mac.h
+++ b/net/proxy/proxy_resolver_mac.h
@@ -14,12 +14,17 @@ namespace net {
class ProxyResolverMac : public ProxyResolver {
public:
// ProxyResolver methods:
- virtual int GetProxyConfig(ProxyConfig* config);
virtual int GetProxyForURL(const GURL& query_url,
const GURL& pac_url,
ProxyInfo* results);
};
+class ProxyConfigServiceMac : public ProxyConfigService {
+ public:
+ // ProxyConfigService methods:
+ virtual int GetProxyConfig(ProxyConfig* config);
+};
+
} // namespace net
#endif // NET_PROXY_PROXY_RESOLVER_MAC_H_
diff --git a/net/proxy/proxy_resolver_null.h b/net/proxy/proxy_resolver_null.h
deleted file mode 100644
index e1bdcbd..0000000
--- a/net/proxy/proxy_resolver_null.h
+++ /dev/null
@@ -1,28 +0,0 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
-// Use of this source code is governed by a BSD-style license that can be
-// found in the LICENSE file.
-
-#ifndef NET_PROXY_PROXY_RESOLVER_NULL_H_
-#define NET_PROXY_PROXY_RESOLVER_NULL_H_
-
-#include "net/proxy/proxy_service.h"
-
-namespace net {
-
-// Implementation of ProxyResolver that always fails.
-class ProxyResolverNull : public ProxyResolver {
- public:
- virtual int GetProxyConfig(ProxyConfig* config) {
- return ERR_NOT_IMPLEMENTED;
- }
- virtual int GetProxyForURL(const GURL& query_url,
- const GURL& pac_url,
- ProxyInfo* results) {
- return ERR_NOT_IMPLEMENTED;
- }
-};
-
-} // namespace net
-
-#endif // NET_PROXY_PROXY_RESOLVER_NULL_H_
-
diff --git a/net/proxy/proxy_resolver_winhttp.cc b/net/proxy/proxy_resolver_winhttp.cc
index 382914f..d4877ac 100644
--- a/net/proxy/proxy_resolver_winhttp.cc
+++ b/net/proxy/proxy_resolver_winhttp.cc
@@ -8,7 +8,6 @@
#include <winhttp.h>
#include "base/histogram.h"
-#include "base/string_tokenizer.h"
#include "net/base/net_errors.h"
#pragma comment(lib, "winhttp.lib")
@@ -35,15 +34,6 @@ static BOOL CallWinHttpGetProxyForUrl(HINTERNET session, LPCWSTR url,
return rv;
}
-static void FreeConfig(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* config) {
- if (config->lpszAutoConfigUrl)
- GlobalFree(config->lpszAutoConfigUrl);
- if (config->lpszProxy)
- GlobalFree(config->lpszProxy);
- if (config->lpszProxyBypass)
- GlobalFree(config->lpszProxyBypass);
-}
-
static void FreeInfo(WINHTTP_PROXY_INFO* info) {
if (info->lpszProxy)
GlobalFree(info->lpszProxy);
@@ -59,37 +49,6 @@ ProxyResolverWinHttp::~ProxyResolverWinHttp() {
CloseWinHttpSession();
}
-int ProxyResolverWinHttp::GetProxyConfig(ProxyConfig* config) {
- WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config = {0};
- if (!WinHttpGetIEProxyConfigForCurrentUser(&ie_config)) {
- LOG(ERROR) << "WinHttpGetIEProxyConfigForCurrentUser failed: " <<
- GetLastError();
- return ERR_FAILED; // TODO(darin): Bug 1189288: translate error code.
- }
-
- if (ie_config.fAutoDetect)
- config->auto_detect = true;
- if (ie_config.lpszProxy)
- config->proxy_server = WideToASCII(ie_config.lpszProxy);
- if (ie_config.lpszProxyBypass) {
- std::string proxy_bypass = WideToASCII(ie_config.lpszProxyBypass);
-
- StringTokenizer proxy_server_bypass_list(proxy_bypass, "; \t\n\r");
- while (proxy_server_bypass_list.GetNext()) {
- std::string bypass_url_domain = proxy_server_bypass_list.token();
- if (bypass_url_domain == "<local>")
- config->proxy_bypass_local_names = true;
- else
- config->proxy_bypass.push_back(bypass_url_domain);
- }
- }
- if (ie_config.lpszAutoConfigUrl)
- config->pac_url = GURL(ie_config.lpszAutoConfigUrl);
-
- FreeConfig(&ie_config);
- return OK;
-}
-
int ProxyResolverWinHttp::GetProxyForURL(const GURL& query_url,
const GURL& pac_url,
ProxyInfo* results) {
diff --git a/net/proxy/proxy_resolver_winhttp.h b/net/proxy/proxy_resolver_winhttp.h
index ac981686..032cab7 100644
--- a/net/proxy/proxy_resolver_winhttp.h
+++ b/net/proxy/proxy_resolver_winhttp.h
@@ -19,7 +19,6 @@ class ProxyResolverWinHttp : public ProxyResolver {
~ProxyResolverWinHttp();
// ProxyResolver implementation:
- virtual int GetProxyConfig(ProxyConfig* config);
virtual int GetProxyForURL(const GURL& query_url,
const GURL& pac_url,
ProxyInfo* results);
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index 5f0f6b2..7f51f52 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -17,10 +17,10 @@
#include "base/string_util.h"
#include "googleurl/src/gurl.h"
#include "net/base/net_errors.h"
-#include "net/proxy/proxy_resolver_fixed.h"
-#include "net/proxy/proxy_resolver_null.h"
+#include "net/proxy/proxy_config_service_fixed.h"
#if defined(OS_WIN)
#include "net/http/http_transaction_winhttp.h"
+#include "net/proxy/proxy_config_service_win.h"
#include "net/proxy/proxy_resolver_winhttp.h"
#elif defined(OS_MACOSX)
#include "net/proxy/proxy_resolver_mac.h"
@@ -31,6 +31,15 @@ using base::TimeTicks;
namespace net {
+// Config getter that fails every time.
+class ProxyConfigServiceNull : public ProxyConfigService {
+ public:
+ virtual int GetProxyConfig(ProxyConfig* config) {
+ return ERR_NOT_IMPLEMENTED;
+ }
+};
+
+
// ProxyConfig ----------------------------------------------------------------
// static
@@ -272,8 +281,10 @@ class ProxyService::PacRequest :
// ProxyService ---------------------------------------------------------------
-ProxyService::ProxyService(ProxyResolver* resolver)
- : resolver_(resolver),
+ProxyService::ProxyService(ProxyConfigService* config_service,
+ ProxyResolver* resolver)
+ : config_service_(config_service),
+ resolver_(resolver),
config_is_bad_(false),
config_has_been_updated_(false) {
}
@@ -281,8 +292,10 @@ ProxyService::ProxyService(ProxyResolver* resolver)
// static
ProxyService* ProxyService::Create(const ProxyInfo* pi) {
if (pi) {
+ // The ProxyResolver is set to NULL, since it should never be called
+ // (because the configuration will never require PAC).
ProxyService* proxy_service =
- new ProxyService(new ProxyResolverFixed(*pi));
+ new ProxyService(new ProxyConfigServiceFixed(*pi), NULL);
// TODO(eroman): remove this WinHTTP hack once it is no more.
// We keep a copy of the ProxyInfo that was used to create the
@@ -292,23 +305,32 @@ ProxyService* ProxyService::Create(const ProxyInfo* pi) {
return proxy_service;
}
#if defined(OS_WIN)
- return new ProxyService(new ProxyResolverWinHttp());
+ return new ProxyService(new ProxyConfigServiceWin(),
+ new ProxyResolverWinHttp());
#elif defined(OS_MACOSX)
- return new ProxyService(new ProxyResolverMac());
+ return new ProxyService(new ProxyConfigServiceMac(),
+ new ProxyResolverMac());
#else
// This used to be a NOTIMPLEMENTED(), but that logs as an error,
// screwing up layout tests.
LOG(WARNING) << "Proxies are not implemented; remove me once that's fixed.";
// http://code.google.com/p/chromium/issues/detail?id=4523 is the bug
// to implement this.
- return new ProxyService(new ProxyResolverNull());
+ return CreateNull();
#endif
}
+// static
+ProxyService* ProxyService::CreateNull() {
+ // The ProxyResolver is set to NULL, since it should never be called
+ // (because the configuration will never require PAC).
+ return new ProxyService(new ProxyConfigServiceNull, NULL);
+}
+
int ProxyService::ResolveProxy(const GURL& url, ProxyInfo* result,
CompletionCallback* callback,
PacRequest** pac_request) {
- // The overhead of calling WinHttpGetIEProxyConfigForCurrentUser is very low.
+ // The overhead of calling ProxyConfigService::GetProxyConfig is very low.
const TimeDelta kProxyConfigMaxAge = TimeDelta::FromSeconds(5);
// Periodically check for a new config.
@@ -481,7 +503,7 @@ void ProxyService::UpdateConfig() {
config_has_been_updated_ = true;
ProxyConfig latest;
- if (resolver_->GetProxyConfig(&latest) != OK)
+ if (config_service_->GetProxyConfig(&latest) != OK)
return;
config_last_update_time_ = TimeTicks::Now();
diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h
index bea4aef..6a9c04b 100644
--- a/net/proxy/proxy_service.h
+++ b/net/proxy/proxy_service.h
@@ -24,6 +24,7 @@ class GURL;
namespace net {
+class ProxyConfigService;
class ProxyInfo;
class ProxyResolver;
@@ -85,8 +86,9 @@ typedef std::map<std::string, ProxyRetryInfo> ProxyRetryInfoMap;
// resolution. See ProxyResolverWinHttp for example.
class ProxyService {
public:
- // The instance takes ownership of |resolver|.
- explicit ProxyService(ProxyResolver* resolver);
+ // The instance takes ownership of |config_service| and |resolver|.
+ ProxyService(ProxyConfigService* config_service,
+ ProxyResolver* resolver);
// Used internally to handle PAC queries.
class PacRequest;
@@ -138,6 +140,10 @@ class ProxyService {
// use IE's settings).
static ProxyService* Create(const ProxyInfo* pi);
+ // Create a proxy service that always fails to fetch the proxy configuration,
+ // so it falls back to direct connect.
+ static ProxyService* CreateNull();
+
// TODO(eroman): remove once WinHTTP is gone.
// Get the ProxyInfo used to create this proxy service (only used by WinHTTP).
const ProxyInfo* proxy_info() const {
@@ -169,6 +175,7 @@ class ProxyService {
// 2. The URL matches one of the entities in the proxy bypass list.
bool ShouldBypassProxyForURL(const GURL& url);
+ scoped_ptr<ProxyConfigService> config_service_;
scoped_ptr<ProxyResolver> resolver_;
scoped_ptr<base::Thread> pac_thread_;
@@ -288,20 +295,27 @@ class ProxyInfo {
bool config_was_tried_;
};
-// This interface provides the low-level functions to access the proxy
-// configuration and resolve proxies for given URLs synchronously.
-class ProxyResolver {
+// Synchronously fetch the system's proxy configuration settings. Called on
+// the IO Thread.
+class ProxyConfigService {
public:
- virtual ~ProxyResolver() {}
+ virtual ~ProxyConfigService() {}
// Get the proxy configuration. Returns OK if successful or an error code if
// otherwise. |config| should be in its initial state when this method is
// called.
virtual int GetProxyConfig(ProxyConfig* config) = 0;
+};
+
+// Synchronously resolve the proxy for a URL, using a PAC script. Called on the
+// PAC Thread.
+class ProxyResolver {
+ public:
+ virtual ~ProxyResolver() {}
// Query the proxy auto-config file (specified by |pac_url|) for the proxy to
// use to load the given |query_url|. Returns OK if successful or an error
- // code if otherwise.
+ // code otherwise.
virtual int GetProxyForURL(const GURL& query_url,
const GURL& pac_url,
ProxyInfo* results) = 0;
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);