diff options
Diffstat (limited to 'net/proxy')
-rw-r--r-- | net/proxy/proxy_service.cc | 55 | ||||
-rw-r--r-- | net/proxy/proxy_service.h | 55 | ||||
-rw-r--r-- | net/proxy/proxy_service_unittest.cc | 197 |
3 files changed, 199 insertions, 108 deletions
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc index 7cfb9ac..5f0f6b2 100644 --- a/net/proxy/proxy_service.cc +++ b/net/proxy/proxy_service.cc @@ -17,6 +17,14 @@ #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" +#if defined(OS_WIN) +#include "net/http/http_transaction_winhttp.h" +#include "net/proxy/proxy_resolver_winhttp.h" +#elif defined(OS_MACOSX) +#include "net/proxy/proxy_resolver_mac.h" +#endif using base::TimeDelta; using base::TimeTicks; @@ -88,13 +96,14 @@ std::string ProxyList::Get() const { return std::string(); } -std::string ProxyList::GetList() const { +std::string ProxyList::GetAnnotatedList() const { std::string proxy_list; std::vector<std::string>::const_iterator iter = proxies_.begin(); for (; iter != proxies_.end(); ++iter) { if (!proxy_list.empty()) - proxy_list += L';'; - + proxy_list += ";"; + // Assume every proxy is an HTTP proxy, as that is all we currently support. + proxy_list += "PROXY "; proxy_list += *iter; } @@ -168,6 +177,10 @@ void ProxyInfo::Apply(HINTERNET request_handle) { } #endif +std::string ProxyInfo::GetAnnotatedProxyList() { + return is_direct() ? "DIRECT" : proxy_list_.GetAnnotatedList(); +} + // ProxyService::PacRequest --------------------------------------------------- // We rely on the fact that the origin thread (and its message loop) will not @@ -261,8 +274,35 @@ class ProxyService::PacRequest : ProxyService::ProxyService(ProxyResolver* resolver) : resolver_(resolver), - config_is_bad_(false) { - UpdateConfig(); + config_is_bad_(false), + config_has_been_updated_(false) { +} + +// static +ProxyService* ProxyService::Create(const ProxyInfo* pi) { + if (pi) { + ProxyService* proxy_service = + new ProxyService(new ProxyResolverFixed(*pi)); + + // TODO(eroman): remove this WinHTTP hack once it is no more. + // We keep a copy of the ProxyInfo that was used to create the + // proxy service, so we can pass it to WinHTTP. + proxy_service->proxy_info_.reset(new ProxyInfo(*pi)); + + return proxy_service; + } +#if defined(OS_WIN) + return new ProxyService(new ProxyResolverWinHttp()); +#elif defined(OS_MACOSX) + return new ProxyService(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()); +#endif } int ProxyService::ResolveProxy(const GURL& url, ProxyInfo* result, @@ -272,7 +312,8 @@ int ProxyService::ResolveProxy(const GURL& url, ProxyInfo* result, const TimeDelta kProxyConfigMaxAge = TimeDelta::FromSeconds(5); // Periodically check for a new config. - if ((TimeTicks::Now() - config_last_update_time_) > kProxyConfigMaxAge) + if (!config_has_been_updated_ || + (TimeTicks::Now() - config_last_update_time_) > kProxyConfigMaxAge) UpdateConfig(); result->config_id_ = config_.id(); @@ -437,6 +478,8 @@ void ProxyService::DidCompletePacRequest(int config_id, int result_code) { } void ProxyService::UpdateConfig() { + config_has_been_updated_ = true; + ProxyConfig latest; if (resolver_->GetProxyConfig(&latest) != OK) return; diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h index ea83509..bea4aef 100644 --- a/net/proxy/proxy_service.h +++ b/net/proxy/proxy_service.h @@ -36,7 +36,7 @@ class ProxyConfig { enum { INVALID_ID = 0 }; ProxyConfig(); - // Default copy-constructor an assignment operator are OK! + // Default copy-constructor and assignment operator are OK! // Used to numerically identify this configuration. ID id() const { return id_; } @@ -55,7 +55,7 @@ class ProxyConfig { // Indicates a list of hosts that should bypass any proxy configuration. For // these hosts, a direct connection should always be used. std::vector<std::string> proxy_bypass; - + // Indicates whether local names (no dots) bypass proxies. bool proxy_bypass_local_names; @@ -81,12 +81,11 @@ struct ProxyRetryInfo { typedef std::map<std::string, ProxyRetryInfo> ProxyRetryInfoMap; // This class can be used to resolve the proxy server to use when loading a -// HTTP(S) URL. It uses to the given ProxyResolver to handle the actual proxy -// resolution. See ProxyResolverWinHttp for example. The consumer of this -// class is responsible for ensuring that the ProxyResolver instance remains -// valid for the lifetime of the ProxyService. +// HTTP(S) URL. It uses the given ProxyResolver to handle the actual proxy +// resolution. See ProxyResolverWinHttp for example. class ProxyService { public: + // The instance takes ownership of |resolver|. explicit ProxyService(ProxyResolver* resolver); // Used internally to handle PAC queries. @@ -100,7 +99,8 @@ class ProxyService { // The caller is responsible for ensuring that |results| and |callback| // remain valid until the callback is run or until |pac_request| is cancelled // via CancelPacRequest. |pac_request| is only valid while the completion - // callback is still pending. + // callback is still pending. NULL can be passed for |pac_request| if + // the caller will not need to cancel the request. // // We use the three possible proxy access types in the following order, and // we only use one of them (no falling back to other access types if the @@ -120,6 +120,9 @@ class ProxyService { // to ResolveProxy. The semantics of this call are otherwise similar to // ResolveProxy. // + // NULL can be passed for |pac_request| if the caller will not need to + // cancel the request. + // // Returns ERR_FAILED if there is not another proxy config to try. // int ReconsiderProxyAfterError(const GURL& url, @@ -130,10 +133,21 @@ class ProxyService { // Call this method with a non-null |pac_request| to cancel the PAC request. void CancelPacRequest(PacRequest* pac_request); + // Create a proxy service using the specified settings. If |pi| is NULL then + // the system's default proxy settings will be used (on Windows this will + // use IE's settings). + static ProxyService* Create(const ProxyInfo* pi); + + // 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 { + return proxy_info_.get(); + } + private: friend class PacRequest; - ProxyResolver* resolver() { return resolver_; } + ProxyResolver* resolver() { return resolver_.get(); } base::Thread* pac_thread() { return pac_thread_.get(); } // Identifies the proxy configuration. @@ -155,16 +169,22 @@ class ProxyService { // 2. The URL matches one of the entities in the proxy bypass list. bool ShouldBypassProxyForURL(const GURL& url); - ProxyResolver* resolver_; + scoped_ptr<ProxyResolver> resolver_; scoped_ptr<base::Thread> pac_thread_; - // We store the IE proxy config and a counter that is incremented each time + // We store the proxy config and a counter that is incremented each time // the config changes. ProxyConfig config_; + // TODO(eroman): remove this once WinHTTP stack is gone. + scoped_ptr<ProxyInfo> proxy_info_; + // Indicates that the configuration is bad and should be ignored. bool config_is_bad_; + // false if the ProxyService has not been initialized yet. + bool config_has_been_updated_; + // The time when the proxy configuration was last read from the system. base::TimeTicks config_last_update_time_; @@ -177,6 +197,8 @@ class ProxyService { // This class is used to hold a list of proxies returned by GetProxyForUrl or // manually configured. It handles proxy fallback if multiple servers are // specified. +// TODO(eroman): The proxy list should work for multiple proxy types. +// See http://crbug.com/469. class ProxyList { public: // Initializes the proxy list to a string containing one or more proxy servers @@ -193,8 +215,11 @@ class ProxyList { // Returns the first valid proxy server in the list. std::string Get() const; - // Returns all the valid proxies, delimited by a semicolon. - std::string GetList() const; + // Returns a PAC-style semicolon-separated list of valid proxy servers. + // For example: "PROXY xxx.xxx.xxx.xxx:xx; SOCKS yyy.yyy.yyy:yy". + // Since ProxyList is currently just used for HTTP, this will return only + // entries of type "PROXY" or "DIRECT". + std::string GetAnnotatedList() const; // Marks the current proxy server as bad and deletes it from the list. The // list of known bad proxies is given by proxy_retry_info. Returns true if @@ -210,6 +235,7 @@ class ProxyList { class ProxyInfo { public: ProxyInfo(); + // Default copy-constructor and assignment operator are OK! // Use the same proxy server as the given |proxy_info|. void Use(const ProxyInfo& proxy_info); @@ -232,6 +258,9 @@ class ProxyInfo { // Returns the first valid proxy server. std::string proxy_server() const { return proxy_list_.Get(); } + // See description in ProxyList::GetAnnotatedList(). + std::string GetAnnotatedProxyList(); + // Marks the current proxy as bad. Returns true if there is another proxy // available to try in proxy list_. bool Fallback(ProxyRetryInfoMap* proxy_retry_info) { @@ -257,8 +286,6 @@ class ProxyInfo { // proxy info does not yield a connection that we might want to reconsider // the proxy config given by config_id_. bool config_was_tried_; - - DISALLOW_COPY_AND_ASSIGN(ProxyInfo); }; // This interface provides the low-level functions to access the proxy diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc index 16a1649..1ad7d32 100644 --- a/net/proxy/proxy_service_unittest.cc +++ b/net/proxy/proxy_service_unittest.cc @@ -12,16 +12,18 @@ namespace { class MockProxyResolver : public net::ProxyResolver { public: MockProxyResolver() : fail_get_proxy_for_url(false) { - config.reset(new net::ProxyConfig); + } + // Init the MockProxyResolver with the specified ProxyConfig. + explicit MockProxyResolver(const net::ProxyConfig& c) : config(c) { } virtual int GetProxyConfig(net::ProxyConfig* results) { - *results = *(config.get()); + *results = config; return net::OK; } virtual int GetProxyForURL(const GURL& query_url, const GURL& pac_url, net::ProxyInfo* results) { - if (pac_url != config->pac_url) + if (pac_url != config.pac_url) return net::ERR_INVALID_ARGUMENT; if (fail_get_proxy_for_url) return net::ERR_FAILED; @@ -32,7 +34,7 @@ class MockProxyResolver : public net::ProxyResolver { } return net::OK; } - scoped_ptr<net::ProxyConfig> config; + net::ProxyConfig config; net::ProxyInfo info; // info is only returned if query_url in GetProxyForURL matches this: @@ -45,9 +47,22 @@ class MockProxyResolver : public net::ProxyResolver { } // namespace +// GetAnnotatedList() is used to generate a string for mozilla's GetProxyForUrl +// NPAPI extension. Check that it adheres to the expected format. +TEST(ProxyListTest, GetAnnotatedList) { + net::ProxyList proxy_list; + + std::vector<std::string> proxies; + proxies.push_back("www.first.com:80"); + proxies.push_back("www.second.com:80"); + proxy_list.SetVector(proxies); + + EXPECT_EQ(std::string("PROXY www.first.com:80;PROXY www.second.com:80"), + proxy_list.GetAnnotatedList()); +} + TEST(ProxyServiceTest, Direct) { - MockProxyResolver resolver; - net::ProxyService service(&resolver); + net::ProxyService service(new MockProxyResolver); GURL url("http://www.google.com/"); @@ -58,12 +73,12 @@ TEST(ProxyServiceTest, Direct) { } TEST(ProxyServiceTest, PAC) { - MockProxyResolver resolver; - resolver.config->pac_url = GURL("http://foopy/proxy.pac"); - resolver.info.UseNamedProxy("foopy"); - resolver.info_predicate_query_host = "www.google.com"; + 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(resolver); GURL url("http://www.google.com/"); @@ -75,12 +90,12 @@ TEST(ProxyServiceTest, PAC) { } TEST(ProxyServiceTest, PAC_FailoverToDirect) { - MockProxyResolver resolver; - resolver.config->pac_url = GURL("http://foopy/proxy.pac"); - resolver.info.UseNamedProxy("foopy:8080"); - resolver.info_predicate_query_host = "www.google.com"; + 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(resolver); GURL url("http://www.google.com/"); @@ -99,13 +114,13 @@ TEST(ProxyServiceTest, PAC_FailoverToDirect) { TEST(ProxyServiceTest, PAC_FailsToDownload) { // Test what happens when we fail to download the PAC URL. - MockProxyResolver resolver; - 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; + 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(resolver); GURL url("http://www.google.com/"); net::ProxyInfo info; @@ -117,8 +132,8 @@ TEST(ProxyServiceTest, PAC_FailsToDownload) { EXPECT_EQ(rv, net::OK); EXPECT_TRUE(info.is_direct()); - resolver.fail_get_proxy_for_url = false; - resolver.info.UseNamedProxy("foopy_valid:8080"); + resolver->fail_get_proxy_for_url = false; + resolver->info.UseNamedProxy("foopy_valid:8080"); // But, if that fails, then we should give the proxy config another shot // since we have never tried it with this URL before. @@ -132,13 +147,13 @@ TEST(ProxyServiceTest, ProxyFallback) { // Test what happens when we specify multiple proxy servers and some of them // are bad. - MockProxyResolver resolver; - 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; + 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(resolver); GURL url("http://www.google.com/"); @@ -160,10 +175,10 @@ 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"); - resolver.info.UseNamedProxy("foopy3:7070;foopy1:8080;foopy2:9090"); - resolver.info_predicate_query_host = "www.google.com"; - resolver.fail_get_proxy_for_url = false; + resolver->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; rv = service.ResolveProxy(url, &info, NULL, NULL); EXPECT_EQ(rv, net::OK); @@ -190,13 +205,13 @@ TEST(ProxyServiceTest, ProxyFallback) { TEST(ProxyServiceTest, ProxyFallback_NewSettings) { // Test proxy failover when new settings are available. - MockProxyResolver resolver; - 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; + 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(resolver); GURL url("http://www.google.com/"); @@ -210,8 +225,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.reset(new net::ProxyConfig); - resolver.config->pac_url = GURL("http://foopy-new/proxy.pac"); + resolver->config = net::ProxyConfig(); + resolver->config.pac_url = GURL("http://foopy-new/proxy.pac"); rv = service.ReconsiderProxyAfterError(url, &info, NULL, NULL); EXPECT_EQ(rv, net::OK); @@ -225,8 +240,8 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { EXPECT_EQ(info.proxy_server(), "foopy2:9090"); // We simulate a new configuration. - resolver.config.reset(new net::ProxyConfig); - resolver.config->pac_url = GURL("http://foopy-new2/proxy.pac"); + resolver->config = net::ProxyConfig(); + resolver->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); @@ -237,13 +252,13 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) { TEST(ProxyServiceTest, ProxyFallback_BadConfig) { // Test proxy failover when the configuration is bad. - MockProxyResolver resolver; - 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; + 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(resolver); GURL url("http://www.google.com/"); @@ -266,7 +281,7 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfig) { // Fake a PAC failure. net::ProxyInfo info2; - resolver.fail_get_proxy_for_url = true; + resolver->fail_get_proxy_for_url = true; rv = service.ResolveProxy(url, &info2, NULL, NULL); EXPECT_EQ(rv, net::OK); @@ -275,7 +290,7 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfig) { // The PAC is now fixed and will return a proxy server. // It should also clear the list of bad proxies. - resolver.fail_get_proxy_for_url = false; + resolver->fail_get_proxy_for_url = false; // Try to resolve, it will still return "direct" because we have no reason // to check the config since everything works. @@ -298,12 +313,12 @@ TEST(ProxyServiceTest, ProxyFallback_BadConfig) { TEST(ProxyServiceTest, ProxyBypassList) { // Test what happens when a proxy bypass list is specified. - MockProxyResolver resolver; - resolver.config->proxy_server = "foopy1:8080;foopy2:9090"; - resolver.config->auto_detect = false; - resolver.config->proxy_bypass_local_names = true; - - net::ProxyService service(&resolver); + net::ProxyConfig config; + config.proxy_server = "foopy1:8080;foopy2:9090"; + config.auto_detect = false; + config.proxy_bypass_local_names = true; + + net::ProxyService service(new MockProxyResolver(config)); GURL url("http://www.google.com/"); // Get the proxy information. net::ProxyInfo info; @@ -311,58 +326,63 @@ TEST(ProxyServiceTest, ProxyBypassList) { EXPECT_EQ(rv, net::OK); EXPECT_FALSE(info.is_direct()); - net::ProxyService service1(&resolver); + net::ProxyService service1(new MockProxyResolver(config)); GURL test_url1("local"); net::ProxyInfo info1; rv = service1.ResolveProxy(test_url1, &info1, NULL, NULL); EXPECT_EQ(rv, net::OK); EXPECT_TRUE(info1.is_direct()); - resolver.config->proxy_bypass.clear(); - resolver.config->proxy_bypass.push_back("*.org"); - resolver.config->proxy_bypass_local_names = true; - net::ProxyService service2(&resolver); + 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); GURL test_url2("http://www.webkit.org"); net::ProxyInfo info2; rv = service2.ResolveProxy(test_url2, &info2, NULL, NULL); EXPECT_EQ(rv, net::OK); EXPECT_TRUE(info2.is_direct()); - resolver.config->proxy_bypass.clear(); - resolver.config->proxy_bypass.push_back("*.org"); - resolver.config->proxy_bypass.push_back("7*"); - resolver.config->proxy_bypass_local_names = true; - net::ProxyService service3(&resolver); + config.proxy_bypass.clear(); + 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); GURL test_url3("http://74.125.19.147"); net::ProxyInfo info3; rv = service3.ResolveProxy(test_url3, &info3, NULL, NULL); EXPECT_EQ(rv, net::OK); EXPECT_TRUE(info3.is_direct()); - resolver.config->proxy_bypass.clear(); - resolver.config->proxy_bypass.push_back("*.org"); - resolver.config->proxy_bypass_local_names = true; - net::ProxyService service4(&resolver); + config.proxy_bypass.clear(); + config.proxy_bypass.push_back("*.org"); + config.proxy_bypass_local_names = true; + resolver = new MockProxyResolver(config); + net::ProxyService service4(resolver); GURL test_url4("http://www.msn.com"); net::ProxyInfo info4; rv = service4.ResolveProxy(test_url4, &info4, NULL, NULL); EXPECT_EQ(rv, net::OK); EXPECT_FALSE(info4.is_direct()); - resolver.config->proxy_bypass.clear(); - resolver.config->proxy_bypass.push_back("*.MSN.COM"); - resolver.config->proxy_bypass_local_names = true; - net::ProxyService service5(&resolver); + 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); GURL test_url5("http://www.msnbc.msn.com"); net::ProxyInfo info5; rv = service5.ResolveProxy(test_url5, &info5, NULL, NULL); EXPECT_EQ(rv, net::OK); EXPECT_TRUE(info5.is_direct()); - resolver.config->proxy_bypass.clear(); - resolver.config->proxy_bypass.push_back("*.msn.com"); - resolver.config->proxy_bypass_local_names = true; - net::ProxyService service6(&resolver); + 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); GURL test_url6("HTTP://WWW.MSNBC.MSN.COM"); net::ProxyInfo info6; rv = service6.ResolveProxy(test_url6, &info6, NULL, NULL); @@ -371,11 +391,11 @@ TEST(ProxyServiceTest, ProxyBypassList) { } TEST(ProxyServiceTest, PerProtocolProxyTests) { - MockProxyResolver resolver; - resolver.config->proxy_server = "http=foopy1:8080;https=foopy2:8080"; - resolver.config->auto_detect = false; + net::ProxyConfig config; + config.proxy_server = "http=foopy1:8080;https=foopy2:8080"; + config.auto_detect = false; - net::ProxyService service1(&resolver); + net::ProxyService service1(new MockProxyResolver(config)); GURL test_url1("http://www.msn.com"); net::ProxyInfo info1; int rv = service1.ResolveProxy(test_url1, &info1, NULL, NULL); @@ -383,7 +403,7 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { EXPECT_FALSE(info1.is_direct()); EXPECT_TRUE(info1.proxy_server() == "foopy1:8080"); - net::ProxyService service2(&resolver); + net::ProxyService service2(new MockProxyResolver(config)); GURL test_url2("ftp://ftp.google.com"); net::ProxyInfo info2; rv = service2.ResolveProxy(test_url2, &info2, NULL, NULL); @@ -391,7 +411,7 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { EXPECT_TRUE(info2.is_direct()); EXPECT_TRUE(info2.proxy_server() == ""); - net::ProxyService service3(&resolver); + net::ProxyService service3(new MockProxyResolver(config)); GURL test_url3("https://webbranch.techcu.com"); net::ProxyInfo info3; rv = service3.ResolveProxy(test_url3, &info3, NULL, NULL); @@ -399,8 +419,9 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) { EXPECT_FALSE(info3.is_direct()); EXPECT_TRUE(info3.proxy_server() == "foopy2:8080"); - resolver.config->proxy_server = "foopy1:8080"; - net::ProxyService service4(&resolver); + MockProxyResolver* resolver = new MockProxyResolver(config); + resolver->config.proxy_server = "foopy1:8080"; + net::ProxyService service4(resolver); GURL test_url4("www.microsoft.com"); net::ProxyInfo info4; rv = service4.ResolveProxy(test_url4, &info4, NULL, NULL); |