summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoreroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 00:20:48 +0000
committereroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-02-24 00:20:48 +0000
commited4ed0fa4e964e416cd3ac65df64bc238f65461c (patch)
tree83a492355815043301313a6cced9fb96a033c37f
parentb07408332337cd6f10b31e87cbed0886e872fa93 (diff)
downloadchromium_src-ed4ed0fa4e964e416cd3ac65df64bc238f65461c.zip
chromium_src-ed4ed0fa4e964e416cd3ac65df64bc238f65461c.tar.gz
chromium_src-ed4ed0fa4e964e416cd3ac65df64bc238f65461c.tar.bz2
ProxyConfig behaved like a struct, but was defined as a class.
Changed it to be a proper class with hidden implementation variables, setters etc. Also seized this opportunity to move the bypass list from being a member of ProxyConfig, to being a member of ProxyRules. This is a more correct hiearchy, since the bypass rules only apply to the manual settings. Lastly, this makes it possible to have the manual rules evaluation be a method on ProxyRules, and shift some more code out of proxy_service. Review URL: http://codereview.chromium.org/651070 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@39818 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/browser/automation/automation_provider.cc8
-rw-r--r--chrome/browser/net/chrome_url_request_context.cc10
-rw-r--r--chrome/browser/net/chrome_url_request_context_unittest.cc54
-rw-r--r--chrome/browser/net/resolve_proxy_msg_helper_unittest.cc2
-rw-r--r--net/http/http_network_transaction_unittest.cc2
-rw-r--r--net/proxy/init_proxy_resolver.cc6
-rw-r--r--net/proxy/init_proxy_resolver_unittest.cc30
-rw-r--r--net/proxy/proxy_config.cc98
-rw-r--r--net/proxy/proxy_config.h111
-rw-r--r--net/proxy/proxy_config_service_common_unittest.cc143
-rw-r--r--net/proxy/proxy_config_service_common_unittest.h88
-rw-r--r--net/proxy/proxy_config_service_linux.cc56
-rw-r--r--net/proxy/proxy_config_service_linux_unittest.cc263
-rw-r--r--net/proxy/proxy_config_service_mac.cc30
-rw-r--r--net/proxy/proxy_config_service_win.cc8
-rw-r--r--net/proxy/proxy_config_service_win_unittest.cc49
-rw-r--r--net/proxy/proxy_config_unittest.cc74
-rw-r--r--net/proxy/proxy_service.cc41
-rw-r--r--net/proxy/proxy_service.h7
-rw-r--r--net/proxy/proxy_service_unittest.cc66
-rw-r--r--net/spdy/spdy_network_transaction_unittest.cc14
-rw-r--r--net/url_request/url_request_unittest.h2
22 files changed, 656 insertions, 506 deletions
diff --git a/chrome/browser/automation/automation_provider.cc b/chrome/browser/automation/automation_provider.cc
index 52e424b..5bf39b0 100644
--- a/chrome/browser/automation/automation_provider.cc
+++ b/chrome/browser/automation/automation_provider.cc
@@ -1323,19 +1323,19 @@ class SetProxyConfigTask : public Task {
}
bool auto_config;
if (dict.GetBoolean(automation::kJSONProxyAutoconfig, &auto_config)) {
- pc->auto_detect = true;
+ pc->set_auto_detect(true);
}
std::string pac_url;
if (dict.GetString(automation::kJSONProxyPacUrl, &pac_url)) {
- pc->pac_url = GURL(pac_url);
+ pc->set_pac_url(GURL(pac_url));
}
std::string proxy_bypass_list;
if (dict.GetString(automation::kJSONProxyBypassList, &proxy_bypass_list)) {
- pc->bypass_rules.ParseFromString(proxy_bypass_list);
+ pc->proxy_rules().bypass_rules.ParseFromString(proxy_bypass_list);
}
std::string proxy_server;
if (dict.GetString(automation::kJSONProxyServer, &proxy_server)) {
- pc->proxy_rules.ParseFromString(proxy_server);
+ pc->proxy_rules().ParseFromString(proxy_server);
}
}
diff --git a/chrome/browser/net/chrome_url_request_context.cc b/chrome/browser/net/chrome_url_request_context.cc
index bb8cba9..01181bc2 100644
--- a/chrome/browser/net/chrome_url_request_context.cc
+++ b/chrome/browser/net/chrome_url_request_context.cc
@@ -934,21 +934,21 @@ net::ProxyConfig* CreateProxyConfig(const CommandLine& command_line) {
if (command_line.HasSwitch(switches::kProxyServer)) {
const std::wstring& proxy_server =
command_line.GetSwitchValue(switches::kProxyServer);
- proxy_config->proxy_rules.ParseFromString(WideToASCII(proxy_server));
+ proxy_config->proxy_rules().ParseFromString(WideToASCII(proxy_server));
}
if (command_line.HasSwitch(switches::kProxyPacUrl)) {
- proxy_config->pac_url =
+ proxy_config->set_pac_url(
GURL(WideToASCII(command_line.GetSwitchValue(
- switches::kProxyPacUrl)));
+ switches::kProxyPacUrl))));
}
if (command_line.HasSwitch(switches::kProxyAutoDetect)) {
- proxy_config->auto_detect = true;
+ proxy_config->set_auto_detect(true);
}
if (command_line.HasSwitch(switches::kProxyBypassList)) {
- proxy_config->bypass_rules.ParseFromString(
+ proxy_config->proxy_rules().bypass_rules.ParseFromString(
WideToASCII(command_line.GetSwitchValue(
switches::kProxyBypassList)));
}
diff --git a/chrome/browser/net/chrome_url_request_context_unittest.cc b/chrome/browser/net/chrome_url_request_context_unittest.cc
index e7d679c..676340e 100644
--- a/chrome/browser/net/chrome_url_request_context_unittest.cc
+++ b/chrome/browser/net/chrome_url_request_context_unittest.cc
@@ -57,8 +57,7 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
bool is_null;
bool auto_detect;
GURL pac_url;
- net::ProxyConfig::ProxyRules proxy_rules;
- const char* proxy_bypass_list; // newline separated
+ net::ProxyRulesExpectation proxy_rules;
} tests[] = {
{
TEST_DESC("Empty command line"),
@@ -68,8 +67,7 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
true, // is_null
false, // auto_detect
GURL(), // pac_url
- net::ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ net::ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("No proxy"),
@@ -79,8 +77,7 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
false, // is_null
false, // auto_detect
GURL(), // pac_url
- net::ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ net::ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("No proxy with extra parameters."),
@@ -90,8 +87,7 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
false, // is_null
false, // auto_detect
GURL(), // pac_url
- net::ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ net::ProxyRulesExpectation::Empty(),
},
{
TEST_DESC("Single proxy."),
@@ -101,8 +97,9 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
false, // is_null
false, // auto_detect
GURL(), // pac_url
- net::MakeSingleProxyRules("http://proxy:8888"), // proxy_rules
- "", // proxy_bypass_list
+ net::ProxyRulesExpectation::Single(
+ "proxy:8888", // single proxy
+ ""), // bypass rules
},
{
TEST_DESC("Per scheme proxy."),
@@ -112,10 +109,11 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
false, // is_null
false, // auto_detect
GURL(), // pac_url
- net::MakeProxyPerSchemeRules("httpproxy:8888",
- "",
- "ftpproxy:8889"), // proxy_rules
- "", // proxy_bypass_list
+ net::ProxyRulesExpectation::PerScheme(
+ "httpproxy:8888", // http
+ "", // https
+ "ftpproxy:8889", // ftp
+ ""), // bypass rules
},
{
TEST_DESC("Per scheme proxy with bypass URLs."),
@@ -125,11 +123,12 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
false, // is_null
false, // auto_detect
GURL(), // pac_url
- net::MakeProxyPerSchemeRules("httpproxy:8888",
- "",
- "ftpproxy:8889"), // proxy_rules
- // TODO(eroman): 127.0.0.1/8 is unsupported, so it was dropped
- "*.google.com\nfoo.com:99\n1.2.3.4:22\n",
+ net::ProxyRulesExpectation::PerScheme(
+ "httpproxy:8888", // http
+ "", // https
+ "ftpproxy:8889", // ftp
+ // TODO(eroman): 127.0.0.1/8 is unsupported, so it was dropped
+ "*.google.com,foo.com:99,1.2.3.4:22"),
},
{
TEST_DESC("Pac URL with proxy bypass URLs"),
@@ -139,9 +138,9 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
false, // is_null
false, // auto_detect
GURL("http://wpad/wpad.dat"), // pac_url
- net::ProxyConfig::ProxyRules(), // proxy_rules
- // TODO(eroman): 127.0.0.1/8 is unsupported, so it was dropped
- "*.google.com\nfoo.com:99\n1.2.3.4:22\n",
+ net::ProxyRulesExpectation::EmptyWithBypass(
+ // TODO(eroman): 127.0.0.1/8 is unsupported, so it was dropped
+ "*.google.com,foo.com:99,1.2.3.4:22"),
},
{
TEST_DESC("Autodetect"),
@@ -151,8 +150,7 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
false, // is_null
true, // auto_detect
GURL(), // pac_url
- net::ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ net::ProxyRulesExpectation::Empty(),
}
};
@@ -166,11 +164,9 @@ TEST(ChromeUrlRequestContextTest, CreateProxyConfigTest) {
EXPECT_TRUE(config == NULL);
} else {
EXPECT_TRUE(config != NULL);
- EXPECT_EQ(tests[i].auto_detect, config->auto_detect);
- EXPECT_EQ(tests[i].pac_url, config->pac_url);
- EXPECT_EQ(tests[i].proxy_bypass_list,
- net::FlattenProxyBypass(config->bypass_rules));
- EXPECT_EQ(tests[i].proxy_rules, config->proxy_rules);
+ EXPECT_EQ(tests[i].auto_detect, config->auto_detect());
+ EXPECT_EQ(tests[i].pac_url, config->pac_url());
+ EXPECT_TRUE(tests[i].proxy_rules.Matches(config->proxy_rules()));
}
}
}
diff --git a/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc b/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
index bb4c1b3..4d2eeb8 100644
--- a/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
+++ b/chrome/browser/net/resolve_proxy_msg_helper_unittest.cc
@@ -14,7 +14,7 @@
class MockProxyConfigService : public net::ProxyConfigService {
public:
virtual int GetProxyConfig(net::ProxyConfig* results) {
- results->pac_url = GURL("http://pac");
+ results->set_pac_url(GURL("http://pac"));
return net::OK;
}
};
diff --git a/net/http/http_network_transaction_unittest.cc b/net/http/http_network_transaction_unittest.cc
index 09380a4..af4f2a3 100644
--- a/net/http/http_network_transaction_unittest.cc
+++ b/net/http/http_network_transaction_unittest.cc
@@ -63,7 +63,7 @@ class SessionDependencies {
ProxyService* CreateFixedProxyService(const std::string& proxy) {
net::ProxyConfig proxy_config;
- proxy_config.proxy_rules.ParseFromString(proxy);
+ proxy_config.proxy_rules().ParseFromString(proxy);
return ProxyService::CreateFixed(proxy_config);
}
diff --git a/net/proxy/init_proxy_resolver.cc b/net/proxy/init_proxy_resolver.cc
index 236e094..dd6d28e 100644
--- a/net/proxy/init_proxy_resolver.cc
+++ b/net/proxy/init_proxy_resolver.cc
@@ -64,13 +64,13 @@ int InitProxyResolver::Init(const ProxyConfig& config,
InitProxyResolver::UrlList InitProxyResolver::BuildPacUrlsFallbackList(
const ProxyConfig& config) const {
UrlList pac_urls;
- if (config.auto_detect) {
+ if (config.auto_detect()) {
GURL pac_url = resolver_->expects_pac_bytes() ?
GURL("http://wpad/wpad.dat") : GURL();
pac_urls.push_back(pac_url);
}
- if (config.pac_url.is_valid())
- pac_urls.push_back(config.pac_url);
+ if (config.has_pac_url())
+ pac_urls.push_back(config.pac_url());
return pac_urls;
}
diff --git a/net/proxy/init_proxy_resolver_unittest.cc b/net/proxy/init_proxy_resolver_unittest.cc
index 46b8b79..1ed62e8 100644
--- a/net/proxy/init_proxy_resolver_unittest.cc
+++ b/net/proxy/init_proxy_resolver_unittest.cc
@@ -167,7 +167,7 @@ TEST(InitProxyResolverTest, CustomPacSucceeds) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac");
@@ -199,7 +199,7 @@ TEST(InitProxyResolverTest, CustomPacFails1) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
rules.AddFailDownloadRule("http://custom/proxy.pac");
@@ -227,7 +227,7 @@ TEST(InitProxyResolverTest, CustomPacFails2) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
rules.AddFailParsingRule("http://custom/proxy.pac");
@@ -243,7 +243,7 @@ TEST(InitProxyResolverTest, HasNullProxyScriptFetcher) {
RuleBasedProxyResolver resolver(&rules, true /*expects_pac_bytes*/);
ProxyConfig config;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
TestCompletionCallback callback;
InitProxyResolver init(&resolver, NULL);
@@ -258,7 +258,7 @@ TEST(InitProxyResolverTest, AutodetectSuccess) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.auto_detect = true;
+ config.set_auto_detect(true);
Rules::Rule rule = rules.AddSuccessRule("http://wpad/wpad.dat");
@@ -275,8 +275,8 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess1) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
rules.AddFailDownloadRule("http://wpad/wpad.dat");
Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac");
@@ -294,8 +294,8 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
rules.AddFailParsingRule("http://wpad/wpad.dat");
Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac");
@@ -338,8 +338,8 @@ TEST(InitProxyResolverTest, AutodetectFailCustomFails1) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
rules.AddFailDownloadRule("http://wpad/wpad.dat");
rules.AddFailDownloadRule("http://custom/proxy.pac");
@@ -357,8 +357,8 @@ TEST(InitProxyResolverTest, AutodetectFailCustomFails2) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
rules.AddFailDownloadRule("http://wpad/wpad.dat");
rules.AddFailParsingRule("http://custom/proxy.pac");
@@ -378,8 +378,8 @@ TEST(InitProxyResolverTest, AutodetectFailCustomSuccess2_NoFetch) {
RuleBasedProxyScriptFetcher fetcher(&rules);
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://custom/proxy.pac");
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://custom/proxy.pac"));
rules.AddFailParsingRule(""); // Autodetect.
Rules::Rule rule = rules.AddSuccessRule("http://custom/proxy.pac");
diff --git a/net/proxy/proxy_config.cc b/net/proxy/proxy_config.cc
index f8fe9f6..6196330 100644
--- a/net/proxy/proxy_config.cc
+++ b/net/proxy/proxy_config.cc
@@ -6,25 +6,48 @@
#include "base/string_tokenizer.h"
#include "base/string_util.h"
+#include "net/proxy/proxy_info.h"
namespace net {
-ProxyConfig::ProxyConfig()
- : auto_detect(false),
- id_(INVALID_ID) {
-}
-
-bool ProxyConfig::Equals(const ProxyConfig& other) const {
- // The two configs can have different IDs. We are just interested in if they
- // have the same settings.
- return auto_detect == other.auto_detect &&
- pac_url == other.pac_url &&
- proxy_rules == other.proxy_rules &&
+bool ProxyConfig::ProxyRules::Equals(const ProxyRules& other) const {
+ return type == other.type &&
+ single_proxy == other.single_proxy &&
+ proxy_for_http == other.proxy_for_http &&
+ proxy_for_https == other.proxy_for_https &&
+ proxy_for_ftp == other.proxy_for_ftp &&
+ socks_proxy == other.socks_proxy &&
bypass_rules.Equals(other.bypass_rules);
}
-bool ProxyConfig::MayRequirePACResolver() const {
- return auto_detect || pac_url.is_valid();
+void ProxyConfig::ProxyRules::Apply(const GURL& url, ProxyInfo* result) {
+ if (empty() || bypass_rules.Matches(url)) {
+ result->UseDirect();
+ return;
+ }
+
+ switch (type) {
+ case ProxyRules::TYPE_SINGLE_PROXY: {
+ result->UseProxyServer(single_proxy);
+ return;
+ }
+ case ProxyRules::TYPE_PROXY_PER_SCHEME: {
+ const ProxyServer* entry = MapUrlSchemeToProxy(url.scheme());
+ if (entry) {
+ result->UseProxyServer(*entry);
+ } else {
+ // We failed to find a matching proxy server for the current URL
+ // scheme. Default to direct.
+ result->UseDirect();
+ }
+ return;
+ }
+ default: {
+ result->UseDirect();
+ NOTREACHED();
+ return;
+ }
+ }
}
void ProxyConfig::ProxyRules::ParseFromString(const std::string& proxy_rules) {
@@ -96,6 +119,21 @@ ProxyServer* ProxyConfig::ProxyRules::MapSchemeToProxy(
return NULL; // No mapping for this scheme.
}
+ProxyConfig::ProxyConfig() : auto_detect_(false), id_(INVALID_ID) {
+}
+
+bool ProxyConfig::Equals(const ProxyConfig& other) const {
+ // The two configs can have different IDs. We are just interested in if they
+ // have the same settings.
+ return auto_detect_ == other.auto_detect_ &&
+ pac_url_ == other.pac_url_ &&
+ proxy_rules_.Equals(other.proxy_rules());
+}
+
+bool ProxyConfig::MayRequirePACResolver() const {
+ return auto_detect_ || has_pac_url();
+}
+
} // namespace net
namespace {
@@ -145,10 +183,10 @@ std::ostream& operator<<(std::ostream& out,
std::ostream& operator<<(std::ostream& out, const net::ProxyConfig& config) {
// "Automatic" settings.
out << "Automatic settings:\n";
- out << " Auto-detect: " << BoolToYesNoString(config.auto_detect) << "\n";
+ out << " Auto-detect: " << BoolToYesNoString(config.auto_detect()) << "\n";
out << " Custom PAC script: ";
- if (config.pac_url.is_valid())
- out << config.pac_url;
+ if (config.has_pac_url())
+ out << config.pac_url();
else
out << "[None]";
out << "\n";
@@ -157,34 +195,36 @@ std::ostream& operator<<(std::ostream& out, const net::ProxyConfig& config) {
out << "Manual settings:\n";
out << " Proxy server: ";
- switch (config.proxy_rules.type) {
+ switch (config.proxy_rules().type) {
case net::ProxyConfig::ProxyRules::TYPE_NO_RULES:
out << "[None]\n";
break;
case net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY:
- out << config.proxy_rules.single_proxy;
+ out << config.proxy_rules().single_proxy;
out << "\n";
break;
case net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME:
out << "\n";
- if (config.proxy_rules.proxy_for_http.is_valid())
- out << " HTTP: " << config.proxy_rules.proxy_for_http << "\n";
- if (config.proxy_rules.proxy_for_https.is_valid())
- out << " HTTPS: " << config.proxy_rules.proxy_for_https << "\n";
- if (config.proxy_rules.proxy_for_ftp.is_valid())
- out << " FTP: " << config.proxy_rules.proxy_for_ftp << "\n";
- if (config.proxy_rules.socks_proxy.is_valid())
- out << " SOCKS: " << config.proxy_rules.socks_proxy << "\n";
+ if (config.proxy_rules().proxy_for_http.is_valid())
+ out << " HTTP: " << config.proxy_rules().proxy_for_http << "\n";
+ if (config.proxy_rules().proxy_for_https.is_valid())
+ out << " HTTPS: " << config.proxy_rules().proxy_for_https << "\n";
+ if (config.proxy_rules().proxy_for_ftp.is_valid())
+ out << " FTP: " << config.proxy_rules().proxy_for_ftp << "\n";
+ if (config.proxy_rules().socks_proxy.is_valid())
+ out << " SOCKS: " << config.proxy_rules().socks_proxy << "\n";
break;
}
out << " Bypass list: ";
- if (config.bypass_rules.rules().empty()) {
+ if (config.proxy_rules().bypass_rules.rules().empty()) {
out << "[None]";
} else {
+ const net::ProxyBypassRules& bypass_rules =
+ config.proxy_rules().bypass_rules;
net::ProxyBypassRules::RuleList::const_iterator it;
- for (it = config.bypass_rules.rules().begin();
- it != config.bypass_rules.rules().end(); ++it) {
+ for (it = bypass_rules.rules().begin();
+ it != bypass_rules.rules().end(); ++it) {
out << "\n " << (*it)->ToString();
}
}
diff --git a/net/proxy/proxy_config.h b/net/proxy/proxy_config.h
index bd62465..c641bbf 100644
--- a/net/proxy/proxy_config.h
+++ b/net/proxy/proxy_config.h
@@ -15,28 +15,23 @@
namespace net {
-// Proxy configuration used to by the ProxyService.
+class ProxyInfo;
+
+// ProxyConfig describes a user's proxy settings.
+//
+// There are two categories of proxy settings:
+// (1) Automatic (indicates the methods to obtain a PAC script)
+// (2) Manual (simple set of proxy servers per scheme, and bypass patterns)
+//
+// When both automatic and manual settings are specified, the Automatic ones
+// take precedence over the manual ones.
+//
+// For more details see:
+// http://www.chromium.org/developers/design-documents/proxy-settings-fallback
class ProxyConfig {
public:
- typedef int ID;
-
- // Indicates an invalid proxy config.
- enum { INVALID_ID = 0 };
-
- ProxyConfig();
- // Default copy-constructor and assignment operator are OK!
-
- // Used to numerically identify this configuration.
- ID id() const { return id_; }
- void set_id(int id) { id_ = id; }
- bool is_valid() { return id_ != INVALID_ID; }
-
- // True if the proxy configuration should be auto-detected.
- bool auto_detect;
-
- // If non-empty, indicates the URL of the proxy auto-config file to use.
- GURL pac_url;
-
+ // ProxyRules describes the "manual" proxy settings.
+ // TODO(eroman): Turn this into a class.
struct ProxyRules {
enum Type {
TYPE_NO_RULES,
@@ -52,9 +47,12 @@ class ProxyConfig {
return type == TYPE_NO_RULES;
}
+ // Sets |result| with the proxy to use for |url| based on the current rules.
+ void Apply(const GURL& url, ProxyInfo* result);
+
// Parses the rules from a string, indicating which proxies to use.
//
- // proxy-uri = [<proxy-scheme>://]<proxy-host>[:"<proxy-port>]
+ // proxy-uri = [<proxy-scheme>"://"]<proxy-host>[":"<proxy-port>]
//
// If the proxy to use depends on the scheme of the URL, can instead specify
// a semicolon separated list of:
@@ -62,8 +60,9 @@ class ProxyConfig {
// <url-scheme>"="<proxy-uri>
//
// For example:
- // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http URLs,
- // and HTTP proxy "foopy2:80" for ftp URLs.
+ // "http=foopy:80;ftp=foopy2" -- use HTTP proxy "foopy:80" for http://
+ // URLs, and HTTP proxy "foopy2:80" for
+ // ftp:// URLs.
// "foopy:80" -- use HTTP proxy "foopy:80" for all URLs.
// "socks4://foopy" -- use SOCKS v4 proxy "foopy:1080" for all
// URLs.
@@ -76,14 +75,11 @@ class ProxyConfig {
// Should only call this if the type is TYPE_PROXY_PER_SCHEME.
const ProxyServer* MapUrlSchemeToProxy(const std::string& url_scheme) const;
- bool operator==(const ProxyRules& other) const {
- return type == other.type &&
- single_proxy == other.single_proxy &&
- proxy_for_http == other.proxy_for_http &&
- proxy_for_https == other.proxy_for_https &&
- proxy_for_ftp == other.proxy_for_ftp &&
- socks_proxy == other.socks_proxy;
- }
+ // Returns true if |*this| describes the same configuration as |other|.
+ bool Equals(const ProxyRules& other) const;
+
+ // Exceptions for when not to use a proxy.
+ ProxyBypassRules bypass_rules;
Type type;
@@ -95,8 +91,9 @@ class ProxyConfig {
ProxyServer proxy_for_https;
ProxyServer proxy_for_ftp;
- // Set if configuration has SOCKS proxy.
+ // Set if the configuration has a SOCKS proxy fallback.
ProxyServer socks_proxy;
+
private:
// Returns one of {&proxy_for_http, &proxy_for_https, &proxy_for_ftp,
// &socks_proxy}, or NULL if it is a scheme that we don't have a mapping
@@ -104,8 +101,17 @@ class ProxyConfig {
ProxyServer* MapSchemeToProxy(const std::string& scheme);
};
- ProxyRules proxy_rules;
- ProxyBypassRules bypass_rules;
+ typedef int ID;
+
+ // Indicates an invalid proxy config.
+ enum { INVALID_ID = 0 };
+
+ ProxyConfig();
+
+ // Used to numerically identify this configuration.
+ ID id() const { return id_; }
+ void set_id(int id) { id_ = id; }
+ bool is_valid() { return id_ != INVALID_ID; }
// Returns true if the given config is equivalent to this config.
bool Equals(const ProxyConfig& other) const;
@@ -114,7 +120,44 @@ class ProxyConfig {
// use a PAC resolver.
bool MayRequirePACResolver() const;
+ ProxyRules& proxy_rules() {
+ return proxy_rules_;
+ }
+
+ const ProxyRules& proxy_rules() const {
+ return proxy_rules_;
+ }
+
+ void set_pac_url(const GURL& url) {
+ pac_url_ = url;
+ }
+
+ const GURL& pac_url() const {
+ return pac_url_;
+ }
+
+ bool has_pac_url() const {
+ return pac_url_.is_valid();
+ }
+
+ void set_auto_detect(bool enable_auto_detect) {
+ auto_detect_ = enable_auto_detect;
+ }
+
+ bool auto_detect() const {
+ return auto_detect_;
+ }
+
private:
+ // True if the proxy configuration should be auto-detected.
+ bool auto_detect_;
+
+ // If non-empty, indicates the URL of the proxy auto-config file to use.
+ GURL pac_url_;
+
+ // Manual proxy settings.
+ ProxyRules proxy_rules_;
+
int id_;
};
diff --git a/net/proxy/proxy_config_service_common_unittest.cc b/net/proxy/proxy_config_service_common_unittest.cc
index 74baa49..7757cca 100644
--- a/net/proxy/proxy_config_service_common_unittest.cc
+++ b/net/proxy/proxy_config_service_common_unittest.cc
@@ -9,59 +9,120 @@
#include "net/proxy/proxy_config.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
namespace net {
-ProxyConfig::ProxyRules MakeProxyRules(
- ProxyConfig::ProxyRules::Type type,
- const char* single_proxy,
- const char* proxy_for_http,
- const char* proxy_for_https,
- const char* proxy_for_ftp,
- const char* socks_proxy) {
- ProxyConfig::ProxyRules rules;
- rules.type = type;
- rules.single_proxy = ProxyServer::FromURI(single_proxy,
- ProxyServer::SCHEME_HTTP);
- rules.proxy_for_http = ProxyServer::FromURI(proxy_for_http,
- ProxyServer::SCHEME_HTTP);
- rules.proxy_for_https = ProxyServer::FromURI(proxy_for_https,
- ProxyServer::SCHEME_HTTP);
- rules.proxy_for_ftp = ProxyServer::FromURI(proxy_for_ftp,
- ProxyServer::SCHEME_HTTP);
- rules.socks_proxy = ProxyServer::FromURI(socks_proxy,
- ProxyServer::SCHEME_SOCKS4);
- return rules;
-}
+namespace {
-ProxyConfig::ProxyRules MakeSingleProxyRules(const char* single_proxy) {
- return MakeProxyRules(ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
- single_proxy, "", "", "", "");
-}
+// Helper to verify that |expected_proxy| matches |actual_proxy|. If it does
+// not, then |*did_fail| is set to true, and |*failure_details| is filled with
+// a description of the failure.
+void MatchesProxyServerHelper(const char* failure_message,
+ const char* expected_proxy,
+ const ProxyServer& actual_proxy,
+ ::testing::AssertionResult* failure_details,
+ bool* did_fail) {
+ std::string actual_proxy_string;
+ if (actual_proxy.is_valid())
+ actual_proxy_string = actual_proxy.ToURI();
-ProxyConfig::ProxyRules MakeProxyPerSchemeRules(
- const char* proxy_http,
- const char* proxy_https,
- const char* proxy_ftp) {
- return MakeProxyRules(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
- "", proxy_http, proxy_https, proxy_ftp, "");
-}
-ProxyConfig::ProxyRules MakeProxyPerSchemeRules(
- const char* proxy_http,
- const char* proxy_https,
- const char* proxy_ftp,
- const char* socks_proxy) {
- return MakeProxyRules(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
- "", proxy_http, proxy_https, proxy_ftp, socks_proxy);
+ if (std::string(expected_proxy) != actual_proxy_string) {
+ *failure_details
+ << failure_message << ". Was expecting: \"" << expected_proxy
+ << "\" but got: \"" << actual_proxy_string << "\"";
+ *did_fail = true;
+ }
}
std::string FlattenProxyBypass(const ProxyBypassRules& bypass_rules) {
std::string flattened_proxy_bypass;
for (ProxyBypassRules::RuleList::const_iterator it =
- bypass_rules.rules().begin();
+ bypass_rules.rules().begin();
it != bypass_rules.rules().end(); ++it) {
- flattened_proxy_bypass += (*it)->ToString() + "\n";
+ if (!flattened_proxy_bypass.empty())
+ flattened_proxy_bypass += ",";
+ flattened_proxy_bypass += (*it)->ToString();
}
return flattened_proxy_bypass;
}
+} // namespace
+
+::testing::AssertionResult ProxyRulesExpectation::Matches(
+ const ProxyConfig::ProxyRules& rules) const {
+ ::testing::AssertionResult failure_details = ::testing::AssertionFailure();
+ bool failed = false;
+
+ if (rules.type != type) {
+ failure_details << "Type mismatch. Expected: "
+ << type << " but was: " << rules.type;
+ failed = true;
+ }
+
+ MatchesProxyServerHelper("Bad single_proxy", single_proxy,
+ rules.single_proxy, &failure_details, &failed);
+ MatchesProxyServerHelper("Bad proxy_for_http", proxy_for_http,
+ rules.proxy_for_http, &failure_details, &failed);
+ MatchesProxyServerHelper("Bad proxy_for_https", proxy_for_https,
+ rules.proxy_for_https, &failure_details, &failed);
+ MatchesProxyServerHelper("Bad proxy_for_socks", socks_proxy,
+ rules.socks_proxy, &failure_details, &failed);
+
+ std::string actual_flattened_bypass = FlattenProxyBypass(rules.bypass_rules);
+ if (std::string(flattened_bypass_rules) != actual_flattened_bypass) {
+ failure_details
+ << "Bad bypass rules. Expected: \"" << flattened_bypass_rules
+ << "\" but got: \"" << actual_flattened_bypass << "\"";
+ failed = true;
+ }
+
+ return failed ? failure_details : ::testing::AssertionSuccess();
+}
+
+// static
+ProxyRulesExpectation ProxyRulesExpectation::Empty() {
+ return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_NO_RULES,
+ "", "", "", "", "", "");
+}
+
+// static
+ProxyRulesExpectation ProxyRulesExpectation::EmptyWithBypass(
+ const char* flattened_bypass_rules) {
+ return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_NO_RULES,
+ "", "", "", "", "", flattened_bypass_rules);
+}
+
+// static
+ProxyRulesExpectation ProxyRulesExpectation::Single(
+ const char* single_proxy,
+ const char* flattened_bypass_rules) {
+ return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
+ single_proxy, "", "", "", "",
+ flattened_bypass_rules);
+}
+
+// static
+ProxyRulesExpectation ProxyRulesExpectation::PerScheme(
+ const char* proxy_http,
+ const char* proxy_https,
+ const char* proxy_ftp,
+ const char* flattened_bypass_rules) {
+ return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
+ "", proxy_http, proxy_https, proxy_ftp, "",
+ flattened_bypass_rules);
+}
+
+// static
+ProxyRulesExpectation ProxyRulesExpectation::PerSchemeWithSocks(
+ const char* proxy_http,
+ const char* proxy_https,
+ const char* proxy_ftp,
+ const char* socks_proxy,
+ const char* flattened_bypass_rules) {
+ return ProxyRulesExpectation(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
+ "", proxy_http, proxy_https, proxy_ftp,
+ socks_proxy, flattened_bypass_rules);
+}
+
} // namespace net
diff --git a/net/proxy/proxy_config_service_common_unittest.h b/net/proxy/proxy_config_service_common_unittest.h
index 66ddfa6..c6f14b7 100644
--- a/net/proxy/proxy_config_service_common_unittest.h
+++ b/net/proxy/proxy_config_service_common_unittest.h
@@ -9,36 +9,76 @@
#include <vector>
#include "net/proxy/proxy_config.h"
+#include "testing/gtest/include/gtest/gtest.h"
-// A few small helper functions common to the win and linux unittests.
+// Helper functions to describe the expected value of a
+// ProxyConfig::ProxyRules, and to check for a match.
namespace net {
class ProxyBypassRules;
-ProxyConfig::ProxyRules MakeProxyRules(
- ProxyConfig::ProxyRules::Type type,
- const char* single_proxy,
- const char* proxy_for_http,
- const char* proxy_for_https,
- const char* proxy_for_ftp,
- const char* socks_proxy);
-
-ProxyConfig::ProxyRules MakeSingleProxyRules(const char* single_proxy);
-
-ProxyConfig::ProxyRules MakeProxyPerSchemeRules(
- const char* proxy_http,
- const char* proxy_https,
- const char* proxy_ftp);
-
-ProxyConfig::ProxyRules MakeProxyPerSchemeRules(
- const char* proxy_http,
- const char* proxy_https,
- const char* proxy_ftp,
- const char* socks_proxy);
-
-// Joins the proxy bypass list using "\n" to make it into a single string.
-std::string FlattenProxyBypass(const ProxyBypassRules& bypass_rules);
+// This structure contains our expectations on what values the ProxyRules
+// should have.
+struct ProxyRulesExpectation {
+ ProxyRulesExpectation(ProxyConfig::ProxyRules::Type type,
+ const char* single_proxy,
+ const char* proxy_for_http,
+ const char* proxy_for_https,
+ const char* proxy_for_ftp,
+ const char* socks_proxy,
+ const char* flattened_bypass_rules)
+ : type(type),
+ single_proxy(single_proxy),
+ proxy_for_http(proxy_for_http),
+ proxy_for_https(proxy_for_https),
+ proxy_for_ftp(proxy_for_ftp),
+ socks_proxy(socks_proxy),
+ flattened_bypass_rules(flattened_bypass_rules) {
+ }
+
+
+ // Call this within an EXPECT_TRUE(), to assert that |rules| matches
+ // our expected values |*this|.
+ ::testing::AssertionResult Matches(
+ const ProxyConfig::ProxyRules& rules) const;
+
+ // Creates an expectation that the ProxyRules has no rules.
+ static ProxyRulesExpectation Empty();
+
+ // Creates an expectation that the ProxyRules has nothing other than
+ // the specified bypass rules.
+ static ProxyRulesExpectation EmptyWithBypass(
+ const char* flattened_bypass_rules);
+
+ // Creates an expectation that the ProxyRules is for a single proxy
+ // server for all schemes.
+ static ProxyRulesExpectation Single(const char* single_proxy,
+ const char* flattened_bypass_rules);
+
+ // Creates an expectation that the ProxyRules specifies a different
+ // proxy server for each URL scheme.
+ static ProxyRulesExpectation PerScheme(const char* proxy_http,
+ const char* proxy_https,
+ const char* proxy_ftp,
+ const char* flattened_bypass_rules);
+
+ // Same as above, but additionally with a SOCKS fallback.
+ static ProxyRulesExpectation PerSchemeWithSocks(
+ const char* proxy_http,
+ const char* proxy_https,
+ const char* proxy_ftp,
+ const char* socks_proxy,
+ const char* flattened_bypass_rules);
+
+ ProxyConfig::ProxyRules::Type type;
+ const char* single_proxy;
+ const char* proxy_for_http;
+ const char* proxy_for_https;
+ const char* proxy_for_ftp;
+ const char* socks_proxy;
+ const char* flattened_bypass_rules;
+};
} // namespace net
diff --git a/net/proxy/proxy_config_service_linux.cc b/net/proxy/proxy_config_service_linux.cc
index 4eb6779..795c644 100644
--- a/net/proxy/proxy_config_service_linux.cc
+++ b/net/proxy/proxy_config_service_linux.cc
@@ -109,22 +109,22 @@ bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) {
if (env_var_getter_->Getenv("auto_proxy", &auto_proxy)) {
if (auto_proxy.empty()) {
// Defined and empty => autodetect
- config->auto_detect = true;
+ config->set_auto_detect(true);
} else {
// specified autoconfig URL
- config->pac_url = GURL(auto_proxy);
+ config->set_pac_url(GURL(auto_proxy));
}
return true;
}
// "all_proxy" is a shortcut to avoid defining {http,https,ftp}_proxy.
ProxyServer proxy_server;
if (GetProxyFromEnvVar("all_proxy", &proxy_server)) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
- config->proxy_rules.single_proxy = proxy_server;
+ config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
+ config->proxy_rules().single_proxy = proxy_server;
} else {
bool have_http = GetProxyFromEnvVar("http_proxy", &proxy_server);
if (have_http)
- config->proxy_rules.proxy_for_http = proxy_server;
+ config->proxy_rules().proxy_for_http = proxy_server;
// It would be tempting to let http_proxy apply for all protocols
// if https_proxy and ftp_proxy are not defined. Googling turns up
// several documents that mention only http_proxy. But then the
@@ -132,16 +132,17 @@ bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) {
// like other apps do this. So we will refrain.
bool have_https = GetProxyFromEnvVar("https_proxy", &proxy_server);
if (have_https)
- config->proxy_rules.proxy_for_https = proxy_server;
+ config->proxy_rules().proxy_for_https = proxy_server;
bool have_ftp = GetProxyFromEnvVar("ftp_proxy", &proxy_server);
if (have_ftp)
- config->proxy_rules.proxy_for_ftp = proxy_server;
+ config->proxy_rules().proxy_for_ftp = proxy_server;
if (have_http || have_https || have_ftp) {
// mustn't change type unless some rules are actually set.
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules().type =
+ ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
}
}
- if (config->proxy_rules.empty()) {
+ if (config->proxy_rules().empty()) {
// If the above were not defined, try for socks.
ProxyServer::Scheme scheme = ProxyServer::SCHEME_SOCKS4;
std::string env_version;
@@ -149,14 +150,14 @@ bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) {
&& env_version == "5")
scheme = ProxyServer::SCHEME_SOCKS5;
if (GetProxyFromEnvVarForScheme("SOCKS_SERVER", scheme, &proxy_server)) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
- config->proxy_rules.single_proxy = proxy_server;
+ config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
+ config->proxy_rules().single_proxy = proxy_server;
}
}
// Look for the proxy bypass list.
std::string no_proxy;
env_var_getter_->Getenv("no_proxy", &no_proxy);
- if (config->proxy_rules.empty()) {
+ if (config->proxy_rules().empty()) {
// Having only "no_proxy" set, presumably to "*", makes it
// explicit that env vars do specify a configuration: having no
// rules specified only means the user explicitly asks for direct
@@ -165,7 +166,8 @@ bool ProxyConfigServiceLinux::Delegate::GetConfigFromEnv(ProxyConfig* config) {
}
// Note that this uses "suffix" matching. So a bypass of "google.com"
// is understood to mean a bypass of "*google.com".
- config->bypass_rules.ParseFromStringUsingSuffixMatching(no_proxy);
+ config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching(
+ no_proxy);
return true;
}
@@ -864,11 +866,11 @@ bool ProxyConfigServiceLinux::Delegate::GetConfigFromGConf(
GURL pac_url(pac_url_str);
if (!pac_url.is_valid())
return false;
- config->pac_url = pac_url;
+ config->set_pac_url(pac_url);
return true;
}
}
- config->auto_detect = true;
+ config->set_auto_detect(true);
return true;
}
@@ -898,37 +900,37 @@ bool ProxyConfigServiceLinux::Delegate::GetConfigFromGConf(
if (GetProxyFromGConf("/system/proxy/socks_", true, &proxy_server)) {
// gconf settings do not appear to distinguish between socks
// version. We default to version 4.
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
- config->proxy_rules.single_proxy = proxy_server;
+ config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
+ config->proxy_rules().single_proxy = proxy_server;
}
}
- if (config->proxy_rules.empty()) {
+ if (config->proxy_rules().empty()) {
bool have_http = GetProxyFromGConf("/system/http_proxy/", false,
&proxy_server);
if (same_proxy) {
if (have_http) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
- config->proxy_rules.single_proxy = proxy_server;
+ config->proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
+ config->proxy_rules().single_proxy = proxy_server;
}
} else {
// Protocol specific settings.
if (have_http)
- config->proxy_rules.proxy_for_http = proxy_server;
+ config->proxy_rules().proxy_for_http = proxy_server;
bool have_secure = GetProxyFromGConf("/system/proxy/secure_", false,
&proxy_server);
if (have_secure)
- config->proxy_rules.proxy_for_https = proxy_server;
+ config->proxy_rules().proxy_for_https = proxy_server;
bool have_ftp = GetProxyFromGConf("/system/proxy/ftp_", false,
&proxy_server);
if (have_ftp)
- config->proxy_rules.proxy_for_ftp = proxy_server;
+ config->proxy_rules().proxy_for_ftp = proxy_server;
if (have_http || have_secure || have_ftp)
- config->proxy_rules.type =
+ config->proxy_rules().type =
ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
}
}
- if (config->proxy_rules.empty()) {
+ if (config->proxy_rules().empty()) {
// Manual mode but we couldn't parse any rules.
return false;
}
@@ -949,9 +951,9 @@ bool ProxyConfigServiceLinux::Delegate::GetConfigFromGConf(
gconf_getter_->GetStringList("/system/http_proxy/ignore_hosts",
&ignore_hosts_list);
- config->bypass_rules.Clear();
+ config->proxy_rules().bypass_rules.Clear();
for (size_t i = 0; i < ignore_hosts_list.size(); ++i)
- config->bypass_rules.AddRuleFromString(ignore_hosts_list[i]);
+ config->proxy_rules().bypass_rules.AddRuleFromString(ignore_hosts_list[i]);
// Note that there are no settings with semantics corresponding to
// bypass of local names.
diff --git a/net/proxy/proxy_config_service_linux_unittest.cc b/net/proxy/proxy_config_service_linux_unittest.cc
index 0940ddf..689b8b6 100644
--- a/net/proxy/proxy_config_service_linux_unittest.cc
+++ b/net/proxy/proxy_config_service_linux_unittest.cc
@@ -365,8 +365,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected outputs (fields of the ProxyConfig).
bool auto_detect;
GURL pac_url;
- ProxyConfig::ProxyRules proxy_rules;
- const char* proxy_bypass_list; // newline separated
+ ProxyRulesExpectation proxy_rules;
} tests[] = {
{
TEST_DESC("No proxying"),
@@ -382,8 +381,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -400,8 +398,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
true, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -418,8 +415,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL("http://wpad/wpad.dat"), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -436,8 +432,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -454,8 +449,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("www.google.com"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "www.google.com:80", // single proxy
+ ""), // bypass rules
},
{
@@ -472,8 +468,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -490,9 +485,11 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com", // proxy_rules
- "", ""),
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -509,8 +506,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("www.google.com:88"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "www.google.com:88", // single proxy
+ ""), // bypass rules
},
{
@@ -530,10 +528,11 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com:88", // proxy_rules
- "www.foo.com:110",
- "ftp.foo.com:121"),
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:88", // http
+ "www.foo.com:110", // https
+ "ftp.foo.com:121", // ftp
+ ""), // bypass rules
},
{
@@ -550,8 +549,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("socks4://socks.com:99"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "socks4://socks.com:99", // single proxy
+ "") // bypass rules
},
{
@@ -567,8 +567,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("www.google.com"), // proxy_rules
- "*.google.com\n", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "www.google.com:80", // single proxy
+ "*.google.com"), // bypass rules
},
};
@@ -585,11 +586,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicGConfTest) {
sync_config_getter.SetupAndInitialFetch();
sync_config_getter.SyncGetProxyConfig(&config);
- EXPECT_EQ(tests[i].auto_detect, config.auto_detect);
- EXPECT_EQ(tests[i].pac_url, config.pac_url);
- EXPECT_EQ(tests[i].proxy_bypass_list,
- FlattenProxyBypass(config.bypass_rules));
- EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules);
+ EXPECT_EQ(tests[i].auto_detect, config.auto_detect());
+ EXPECT_EQ(tests[i].pac_url, config.pac_url());
+ EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules()));
}
}
@@ -605,8 +604,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected outputs (fields of the ProxyConfig).
bool auto_detect;
GURL pac_url;
- ProxyConfig::ProxyRules proxy_rules;
- const char* proxy_bypass_list; // newline separated
+ ProxyRulesExpectation proxy_rules;
} tests[] = {
{
TEST_DESC("No proxying"),
@@ -623,8 +621,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -642,8 +639,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
true, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -661,8 +657,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL("http://wpad/wpad.dat"), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -680,8 +675,7 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -699,8 +693,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("www.google.com"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "www.google.com:80", // single proxy
+ ""), // bypass rules
},
{
@@ -718,8 +713,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("www.google.com:99"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "www.google.com:99", // single
+ ""), // bypass rules
},
{
@@ -737,8 +733,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("www.google.com:99"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "www.google.com:99", // single proxy
+ ""), // bypass rules
},
{
@@ -756,9 +753,11 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com", "www.foo.com:110",
- "ftp.foo.com:121"),
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "www.foo.com:110", // https
+ "ftp.foo.com:121", // ftp
+ ""), // bypass rules
},
{
@@ -776,8 +775,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("socks4://socks.com:888"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "socks4://socks.com:888", // single proxy
+ ""), // bypass rules
},
{
@@ -795,8 +795,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("socks5://socks.com:888"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "socks5://socks.com:888", // single proxy
+ ""), // bypass rules
},
{
@@ -814,8 +815,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("socks4://socks.com"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "socks4://socks.com:1080", // single proxy
+ ""), // bypass rules
},
{
@@ -832,10 +834,10 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("www.google.com"), // proxy_rules
- // proxy_bypass_list
- // TODO(eroman): 127.0.0.1/8 is unsupported, so it was dropped
- "*.google.com\n*foo.com:99\n1.2.3.4:22\n",
+ ProxyRulesExpectation::Single(
+ "www.google.com:80",
+ // TODO(eroman): 127.0.0.1/8 is unsupported, so it was dropped
+ "*.google.com,*foo.com:99,1.2.3.4:22"),
},
};
@@ -852,11 +854,9 @@ TEST_F(ProxyConfigServiceLinuxTest, BasicEnvTest) {
sync_config_getter.SetupAndInitialFetch();
sync_config_getter.SyncGetProxyConfig(&config);
- EXPECT_EQ(tests[i].auto_detect, config.auto_detect);
- EXPECT_EQ(tests[i].pac_url, config.pac_url);
- EXPECT_EQ(tests[i].proxy_bypass_list,
- FlattenProxyBypass(config.bypass_rules));
- EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules);
+ EXPECT_EQ(tests[i].auto_detect, config.auto_detect());
+ EXPECT_EQ(tests[i].pac_url, config.pac_url());
+ EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules()));
}
}
@@ -873,14 +873,14 @@ TEST_F(ProxyConfigServiceLinuxTest, GconfNotification) {
gconf_getter->values.mode = "none";
sync_config_getter.SetupAndInitialFetch();
sync_config_getter.SyncGetProxyConfig(&config);
- EXPECT_FALSE(config.auto_detect);
+ EXPECT_FALSE(config.auto_detect());
// Now set to auto-detect.
gconf_getter->values.mode = "auto";
// Simulate gconf notification callback.
service->OnCheckProxyConfigSettings();
sync_config_getter.SyncGetProxyConfig(&config);
- EXPECT_TRUE(config.auto_detect);
+ EXPECT_TRUE(config.auto_detect());
}
TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
@@ -902,7 +902,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
// Expected outputs (fields of the ProxyConfig).
bool auto_detect;
GURL pac_url;
- ProxyConfig::ProxyRules proxy_rules;
+ ProxyRulesExpectation proxy_rules;
const char* proxy_bypass_list; // newline separated
} tests[] = {
{
@@ -914,8 +914,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -927,8 +926,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
// Expected result.
true, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -941,8 +939,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
// Expected result.
false, // auto_detect
GURL("http://wpad/wpad.dat"), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -955,10 +952,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "www.foo.com",
- "ftp.foo.com"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "www.foo.com:80", // https
+ "ftp.foo.com:80", // http
+ ""), // bypass rules
},
{
@@ -971,9 +969,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -986,9 +986,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com:88",
- "", ""), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:88", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -1000,9 +1002,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "*.google.com\n", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ "*.google.com"), // bypass rules
},
{
@@ -1014,9 +1018,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "*.google.com\n*.kde.org\n", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ "*.google.com,*.kde.org"), // bypass rules
},
{
@@ -1028,9 +1034,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -1042,9 +1050,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -1056,9 +1066,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -1069,9 +1081,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -1082,9 +1096,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -1095,9 +1111,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", ""), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "", // ftp
+ ""), // bypass rules
},
{
@@ -1109,9 +1127,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", "ftp.foo.com"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "ftp.foo.com:80", // ftp
+ ""), // bypass rules
},
{
@@ -1123,8 +1143,7 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL("http:// foo"), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
{
@@ -1136,9 +1155,11 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com",
- "", "ftp.foo.com"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "", // https
+ "ftp.foo.com:80", // ftp
+ ""), // bypass rules
},
};
@@ -1159,11 +1180,9 @@ TEST_F(ProxyConfigServiceLinuxTest, KDEConfigParser) {
sync_config_getter.SetupAndInitialFetch();
sync_config_getter.SyncGetProxyConfig(&config);
- EXPECT_EQ(tests[i].auto_detect, config.auto_detect);
- EXPECT_EQ(tests[i].pac_url, config.pac_url);
- EXPECT_EQ(tests[i].proxy_bypass_list,
- FlattenProxyBypass(config.bypass_rules));
- EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules);
+ EXPECT_EQ(tests[i].auto_detect, config.auto_detect());
+ EXPECT_EQ(tests[i].pac_url, config.pac_url());
+ EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules()));
}
}
diff --git a/net/proxy/proxy_config_service_mac.cc b/net/proxy/proxy_config_service_mac.cc
index 74b1ea6..1e04ff0 100644
--- a/net/proxy/proxy_config_service_mac.cc
+++ b/net/proxy/proxy_config_service_mac.cc
@@ -49,10 +49,10 @@ int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
// There appears to be no UI for this configuration option, and we're not sure
// if Apple's proxy code even takes it into account. But the constant is in
// the header file so we'll use it.
- config->auto_detect =
+ config->set_auto_detect(
GetBoolFromDictionary(config_dict.get(),
kSCPropNetProxiesProxyAutoDiscoveryEnable,
- false);
+ false));
// PAC file
@@ -64,7 +64,7 @@ int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
kSCPropNetProxiesProxyAutoConfigURLString,
CFStringGetTypeID());
if (pac_url_ref)
- config->pac_url = GURL(base::SysCFStringRefToUTF8(pac_url_ref));
+ config->set_pac_url(GURL(base::SysCFStringRefToUTF8(pac_url_ref)));
}
// proxies (for now ftp, http, https, and SOCKS)
@@ -78,8 +78,9 @@ int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
kSCPropNetProxiesFTPProxy,
kSCPropNetProxiesFTPPort);
if (proxy_server.is_valid()) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
- config->proxy_rules.proxy_for_ftp = proxy_server;
+ config->proxy_rules().type =
+ ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules().proxy_for_ftp = proxy_server;
}
}
if (GetBoolFromDictionary(config_dict.get(),
@@ -91,8 +92,9 @@ int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
kSCPropNetProxiesHTTPProxy,
kSCPropNetProxiesHTTPPort);
if (proxy_server.is_valid()) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
- config->proxy_rules.proxy_for_http = proxy_server;
+ config->proxy_rules().type =
+ ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules().proxy_for_http = proxy_server;
}
}
if (GetBoolFromDictionary(config_dict.get(),
@@ -104,8 +106,9 @@ int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
kSCPropNetProxiesHTTPSProxy,
kSCPropNetProxiesHTTPSPort);
if (proxy_server.is_valid()) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
- config->proxy_rules.proxy_for_https = proxy_server;
+ config->proxy_rules().type =
+ ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules().proxy_for_https = proxy_server;
}
}
if (GetBoolFromDictionary(config_dict.get(),
@@ -117,8 +120,9 @@ int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
kSCPropNetProxiesSOCKSProxy,
kSCPropNetProxiesSOCKSPort);
if (proxy_server.is_valid()) {
- config->proxy_rules.type = ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
- config->proxy_rules.socks_proxy = proxy_server;
+ config->proxy_rules().type =
+ ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME;
+ config->proxy_rules().socks_proxy = proxy_server;
}
}
@@ -140,7 +144,7 @@ int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
" to be a CFStringRef but it was not";
} else {
- config->bypass_rules.AddRuleFromString(
+ config->proxy_rules().bypass_rules.AddRuleFromString(
base::SysCFStringRefToUTF8(bypass_item_ref));
}
}
@@ -151,7 +155,7 @@ int ProxyConfigServiceMac::GetProxyConfig(ProxyConfig* config) {
if (GetBoolFromDictionary(config_dict.get(),
kSCPropNetProxiesExcludeSimpleHostnames,
false)) {
- config->bypass_rules.AddRuleToBypassLocal();
+ config->proxy_rules().bypass_rules.AddRuleToBypassLocal();
}
return OK;
diff --git a/net/proxy/proxy_config_service_win.cc b/net/proxy/proxy_config_service_win.cc
index c39c510..38819de 100644
--- a/net/proxy/proxy_config_service_win.cc
+++ b/net/proxy/proxy_config_service_win.cc
@@ -43,11 +43,11 @@ void ProxyConfigServiceWin::SetFromIEConfig(
ProxyConfig* config,
const WINHTTP_CURRENT_USER_IE_PROXY_CONFIG& ie_config) {
if (ie_config.fAutoDetect)
- config->auto_detect = true;
+ config->set_auto_detect(true);
if (ie_config.lpszProxy) {
// lpszProxy may be a single proxy, or a proxy per scheme. The format
// is compatible with ProxyConfig::ProxyRules's string format.
- config->proxy_rules.ParseFromString(WideToASCII(ie_config.lpszProxy));
+ config->proxy_rules().ParseFromString(WideToASCII(ie_config.lpszProxy));
}
if (ie_config.lpszProxyBypass) {
std::string proxy_bypass = WideToASCII(ie_config.lpszProxyBypass);
@@ -55,11 +55,11 @@ void ProxyConfigServiceWin::SetFromIEConfig(
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();
- config->bypass_rules.AddRuleFromString(bypass_url_domain);
+ config->proxy_rules().bypass_rules.AddRuleFromString(bypass_url_domain);
}
}
if (ie_config.lpszAutoConfigUrl)
- config->pac_url = GURL(ie_config.lpszAutoConfigUrl);
+ config->set_pac_url(GURL(ie_config.lpszAutoConfigUrl));
}
} // namespace net
diff --git a/net/proxy/proxy_config_service_win_unittest.cc b/net/proxy/proxy_config_service_win_unittest.cc
index ffcb0be..1d4f45d 100644
--- a/net/proxy/proxy_config_service_win_unittest.cc
+++ b/net/proxy/proxy_config_service_win_unittest.cc
@@ -19,7 +19,7 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected outputs (fields of the ProxyConfig).
bool auto_detect;
GURL pac_url;
- ProxyConfig::ProxyRules proxy_rules;
+ ProxyRulesExpectation proxy_rules;
const char* proxy_bypass_list; // newline separated
} tests[] = {
// Auto detect.
@@ -34,8 +34,7 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected result.
true, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
// Valid PAC url
@@ -50,8 +49,7 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected result.
false, // auto_detect
GURL("http://wpad/wpad.dat"), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
// Invalid PAC url string.
@@ -66,8 +64,7 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Empty(),
},
// Single-host in proxy list.
@@ -82,8 +79,9 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeSingleProxyRules("www.google.com"), // proxy_rules
- "", // proxy_bypass_list
+ ProxyRulesExpectation::Single(
+ "www.google.com:80", // single proxy
+ ""), // bypass rules
},
// Per-scheme proxy rules.
@@ -98,8 +96,11 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com:80", "www.foo.com:110", ""),
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerScheme(
+ "www.google.com:80", // http
+ "www.foo.com:110", // https
+ "", // ftp
+ ""), // bypass rules
},
// SOCKS proxy configuration
@@ -115,9 +116,12 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected result.
false, // auto_detect
GURL(), // pac_url
- MakeProxyPerSchemeRules("www.google.com:80", "www.foo.com:110",
- "ftpproxy:20", "foopy:130"),
- "", // proxy_bypass_list
+ ProxyRulesExpectation::PerSchemeWithSocks(
+ "www.google.com:80", // http
+ "www.foo.com:110", // https
+ "ftpproxy:20", // ftp
+ "socks4://foopy:130", // socks
+ ""), // bypass rules
},
// Bypass local names.
@@ -131,8 +135,7 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
true, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "<local>\n", // proxy_bypass_list
+ ProxyRulesExpectation::EmptyWithBypass("<local>"),
},
// Bypass "google.com" and local names, using semicolon as delimeter
@@ -148,8 +151,7 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected result.
true, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "<local>\ngoogle.com\n", // proxy_bypass_list
+ ProxyRulesExpectation::EmptyWithBypass("<local>,google.com"),
},
// Bypass "foo.com" and "google.com", using lines as delimeter.
@@ -164,8 +166,7 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
// Expected result.
true, // auto_detect
GURL(), // pac_url
- ProxyConfig::ProxyRules(), // proxy_rules
- "foo.com\ngoogle.com\n", // proxy_bypass_list
+ ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"),
},
};
@@ -173,11 +174,9 @@ TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
ProxyConfig config;
ProxyConfigServiceWin::SetFromIEConfig(&config, tests[i].ie_config);
- EXPECT_EQ(tests[i].auto_detect, config.auto_detect);
- EXPECT_EQ(tests[i].pac_url, config.pac_url);
- EXPECT_EQ(tests[i].proxy_bypass_list,
- FlattenProxyBypass(config.bypass_rules));
- EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules);
+ EXPECT_EQ(tests[i].auto_detect, config.auto_detect());
+ EXPECT_EQ(tests[i].pac_url, config.pac_url());
+ EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules()));
}
}
diff --git a/net/proxy/proxy_config_unittest.cc b/net/proxy/proxy_config_unittest.cc
index 9f6cbaf..2182897 100644
--- a/net/proxy/proxy_config_unittest.cc
+++ b/net/proxy/proxy_config_unittest.cc
@@ -24,48 +24,48 @@ TEST(ProxyConfigTest, Equals) {
// Test |ProxyConfig::auto_detect|.
ProxyConfig config1;
- config1.auto_detect = true;
+ config1.set_auto_detect(true);
ProxyConfig config2;
- config2.auto_detect = false;
+ config2.set_auto_detect(false);
EXPECT_FALSE(config1.Equals(config2));
EXPECT_FALSE(config2.Equals(config1));
- config2.auto_detect = true;
+ config2.set_auto_detect(true);
EXPECT_TRUE(config1.Equals(config2));
EXPECT_TRUE(config2.Equals(config1));
// Test |ProxyConfig::pac_url|.
- config2.pac_url = GURL("http://wpad/wpad.dat");
+ config2.set_pac_url(GURL("http://wpad/wpad.dat"));
EXPECT_FALSE(config1.Equals(config2));
EXPECT_FALSE(config2.Equals(config1));
- config1.pac_url = GURL("http://wpad/wpad.dat");
+ config1.set_pac_url(GURL("http://wpad/wpad.dat"));
EXPECT_TRUE(config1.Equals(config2));
EXPECT_TRUE(config2.Equals(config1));
// Test |ProxyConfig::proxy_rules|.
- config2.proxy_rules.type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
- config2.proxy_rules.single_proxy =
+ config2.proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
+ config2.proxy_rules().single_proxy =
ProxyServer::FromURI("myproxy:80", ProxyServer::SCHEME_HTTP);
EXPECT_FALSE(config1.Equals(config2));
EXPECT_FALSE(config2.Equals(config1));
- config1.proxy_rules.type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
- config1.proxy_rules.single_proxy =
+ config1.proxy_rules().type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
+ config1.proxy_rules().single_proxy =
ProxyServer::FromURI("myproxy:100", ProxyServer::SCHEME_HTTP);
EXPECT_FALSE(config1.Equals(config2));
EXPECT_FALSE(config2.Equals(config1));
- config1.proxy_rules.single_proxy =
+ config1.proxy_rules().single_proxy =
ProxyServer::FromURI("myproxy", ProxyServer::SCHEME_HTTP);
EXPECT_TRUE(config1.Equals(config2));
@@ -73,12 +73,12 @@ TEST(ProxyConfigTest, Equals) {
// Test |ProxyConfig::bypass_rules|.
- config2.bypass_rules.AddRuleFromString("*.google.com");
+ config2.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
EXPECT_FALSE(config1.Equals(config2));
EXPECT_FALSE(config2.Equals(config1));
- config1.bypass_rules.AddRuleFromString("*.google.com");
+ config1.proxy_rules().bypass_rules.AddRuleFromString("*.google.com");
EXPECT_TRUE(config1.Equals(config2));
EXPECT_TRUE(config2.Equals(config1));
@@ -224,19 +224,19 @@ TEST(ProxyConfigTest, ParseProxyRules) {
ProxyConfig config;
for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
- config.proxy_rules.ParseFromString(tests[i].proxy_rules);
+ config.proxy_rules().ParseFromString(tests[i].proxy_rules);
- EXPECT_EQ(tests[i].type, config.proxy_rules.type);
+ EXPECT_EQ(tests[i].type, config.proxy_rules().type);
ExpectProxyServerEquals(tests[i].single_proxy,
- config.proxy_rules.single_proxy);
+ config.proxy_rules().single_proxy);
ExpectProxyServerEquals(tests[i].proxy_for_http,
- config.proxy_rules.proxy_for_http);
+ config.proxy_rules().proxy_for_http);
ExpectProxyServerEquals(tests[i].proxy_for_https,
- config.proxy_rules.proxy_for_https);
+ config.proxy_rules().proxy_for_https);
ExpectProxyServerEquals(tests[i].proxy_for_ftp,
- config.proxy_rules.proxy_for_ftp);
+ config.proxy_rules().proxy_for_ftp);
ExpectProxyServerEquals(tests[i].socks_proxy,
- config.proxy_rules.socks_proxy);
+ config.proxy_rules().socks_proxy);
}
}
@@ -250,8 +250,8 @@ TEST(ProxyConfigTest, ToString) {
// Manual proxy.
{
ProxyConfig config;
- config.auto_detect = false;
- config.proxy_rules.ParseFromString("http://single-proxy:81");
+ config.set_auto_detect(false);
+ config.proxy_rules().ParseFromString("http://single-proxy:81");
EXPECT_EQ("Automatic settings:\n"
" Auto-detect: No\n"
@@ -265,9 +265,9 @@ TEST(ProxyConfigTest, ToString) {
// Autodetect + custom PAC + manual proxy.
{
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://custom/pac.js");
- config.proxy_rules.ParseFromString("http://single-proxy:81");
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://custom/pac.js"));
+ config.proxy_rules().ParseFromString("http://single-proxy:81");
EXPECT_EQ("Automatic settings:\n"
" Auto-detect: Yes\n"
@@ -281,11 +281,11 @@ TEST(ProxyConfigTest, ToString) {
// Manual proxy with bypass list + bypass local.
{
ProxyConfig config;
- config.auto_detect = false;
- config.proxy_rules.ParseFromString("http://single-proxy:81");
- config.bypass_rules.AddRuleFromString("google.com");
- config.bypass_rules.AddRuleFromString("bypass2.net:1730");
- config.bypass_rules.AddRuleToBypassLocal();
+ config.set_auto_detect(false);
+ config.proxy_rules().ParseFromString("http://single-proxy:81");
+ config.proxy_rules().bypass_rules.AddRuleFromString("google.com");
+ config.proxy_rules().bypass_rules.AddRuleFromString("bypass2.net:1730");
+ config.proxy_rules().bypass_rules.AddRuleToBypassLocal();
EXPECT_EQ("Automatic settings:\n"
" Auto-detect: No\n"
@@ -302,8 +302,8 @@ TEST(ProxyConfigTest, ToString) {
// Proxy-per scheme (HTTP and HTTPS)
{
ProxyConfig config;
- config.auto_detect = false;
- config.proxy_rules.ParseFromString(
+ config.set_auto_detect(false);
+ config.proxy_rules().ParseFromString(
"http=proxy-for-http:1801; https=proxy-for-https:1802");
EXPECT_EQ("Automatic settings:\n"
@@ -320,8 +320,8 @@ TEST(ProxyConfigTest, ToString) {
// Proxy-per scheme (HTTP and SOCKS)
{
ProxyConfig config;
- config.auto_detect = false;
- config.proxy_rules.ParseFromString(
+ config.set_auto_detect(false);
+ config.proxy_rules().ParseFromString(
"http=http://proxy-for-http:1801; socks=socks-server:6083");
EXPECT_EQ("Automatic settings:\n"
@@ -338,7 +338,7 @@ TEST(ProxyConfigTest, ToString) {
// No proxy.
{
ProxyConfig config;
- config.auto_detect = false;
+ config.set_auto_detect(false);
EXPECT_EQ("Automatic settings:\n"
" Auto-detect: No\n"
@@ -357,17 +357,17 @@ TEST(ProxyConfigTest, MayRequirePACResolver) {
}
{
ProxyConfig config;
- config.auto_detect = true;
+ config.set_auto_detect(true);
EXPECT_TRUE(config.MayRequirePACResolver());
}
{
ProxyConfig config;
- config.pac_url = GURL("http://custom/pac.js");
+ config.set_pac_url(GURL("http://custom/pac.js"));
EXPECT_TRUE(config.MayRequirePACResolver());
}
{
ProxyConfig config;
- config.pac_url = GURL("notvalid");
+ config.set_pac_url(GURL("notvalid"));
EXPECT_FALSE(config.MayRequirePACResolver());
}
}
diff --git a/net/proxy/proxy_service.cc b/net/proxy/proxy_service.cc
index fa7ba4d..1ff2999 100644
--- a/net/proxy/proxy_service.cc
+++ b/net/proxy/proxy_service.cc
@@ -319,48 +319,11 @@ int ProxyService::TryToCompleteSynchronously(const GURL& url,
return ERR_IO_PENDING;
}
- if (!config_.proxy_rules.empty()) {
- ApplyProxyRules(url, config_.proxy_rules, result);
- return OK;
- }
-
- // otherwise, we have no proxy config
- result->UseDirect();
+ // Use the manual proxy settings.
+ config_.proxy_rules().Apply(url, result);
return OK;
}
-void ProxyService::ApplyProxyRules(const GURL& url,
- const ProxyConfig::ProxyRules& proxy_rules,
- ProxyInfo* result) {
- DCHECK(!proxy_rules.empty());
-
- if (config_.bypass_rules.Matches(url)) {
- result->UseDirect();
- return;
- }
-
- switch (proxy_rules.type) {
- case ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY:
- result->UseProxyServer(proxy_rules.single_proxy);
- break;
- case ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME: {
- const ProxyServer* entry = proxy_rules.MapUrlSchemeToProxy(url.scheme());
- if (entry) {
- result->UseProxyServer(*entry);
- } else {
- // We failed to find a matching proxy server for the current URL
- // scheme. Default to direct.
- result->UseDirect();
- }
- break;
- }
- default:
- result->UseDirect();
- NOTREACHED();
- break;
- }
-}
-
ProxyService::~ProxyService() {
// Unregister to receive network change notifications.
if (network_change_notifier_)
diff --git a/net/proxy/proxy_service.h b/net/proxy/proxy_service.h
index 5798214..7ad83d5 100644
--- a/net/proxy/proxy_service.h
+++ b/net/proxy/proxy_service.h
@@ -227,12 +227,7 @@ class ProxyService : public base::RefCountedThreadSafe<ProxyService>,
// Completing synchronously means we don't need to query ProxyResolver.
int TryToCompleteSynchronously(const GURL& url, ProxyInfo* result);
- // Set |result| with the proxy to use for |url|, based on |rules|.
- void ApplyProxyRules(const GURL& url,
- const ProxyConfig::ProxyRules& rules,
- ProxyInfo* result);
-
- // Cancel all of the requests sent to the ProxyResolver. These will be
+ // Cancels all of the requests sent to the ProxyResolver. These will be
// restarted when calling ResumeAllPendingRequests().
void SuspendAllPendingRequests();
diff --git a/net/proxy/proxy_service_unittest.cc b/net/proxy/proxy_service_unittest.cc
index 802806c..309a4654 100644
--- a/net/proxy/proxy_service_unittest.cc
+++ b/net/proxy/proxy_service_unittest.cc
@@ -31,7 +31,7 @@ class MockProxyConfigService: public ProxyConfigService {
MockProxyConfigService() {} // Direct connect.
explicit MockProxyConfigService(const ProxyConfig& pc) : config(pc) {}
explicit MockProxyConfigService(const std::string& pac_url) {
- config.pac_url = GURL(pac_url);
+ config.set_pac_url(GURL(pac_url));
}
virtual int GetProxyConfig(ProxyConfig* results) {
@@ -539,7 +539,7 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) {
// Fake an error on the proxy, and also a new configuration on the proxy.
config_service->config = ProxyConfig();
- config_service->config.pac_url = GURL("http://foopy-new/proxy.pac");
+ config_service->config.set_pac_url(GURL("http://foopy-new/proxy.pac"));
TestCompletionCallback callback2;
rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL);
@@ -568,7 +568,7 @@ TEST(ProxyServiceTest, ProxyFallback_NewSettings) {
// We simulate a new configuration.
config_service->config = ProxyConfig();
- config_service->config.pac_url = GURL("http://foopy-new2/proxy.pac");
+ config_service->config.set_pac_url(GURL("http://foopy-new2/proxy.pac"));
// We fake another error. It should go back to the first proxy.
TestCompletionCallback callback4;
@@ -679,9 +679,9 @@ TEST(ProxyServiceTest, ProxyBypassList) {
TestCompletionCallback callback[2];
ProxyInfo info[2];
ProxyConfig config;
- config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090");
- config.auto_detect = false;
- config.bypass_rules.ParseFromString("*.org");
+ config.proxy_rules().ParseFromString("foopy1:8080;foopy2:9090");
+ config.set_auto_detect(false);
+ config.proxy_rules().bypass_rules.ParseFromString("*.org");
scoped_refptr<ProxyService> service(new ProxyService(
new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
@@ -704,8 +704,8 @@ TEST(ProxyServiceTest, ProxyBypassList) {
TEST(ProxyServiceTest, PerProtocolProxyTests) {
ProxyConfig config;
- config.proxy_rules.ParseFromString("http=foopy1:8080;https=foopy2:8080");
- config.auto_detect = false;
+ config.proxy_rules().ParseFromString("http=foopy1:8080;https=foopy2:8080");
+ config.set_auto_detect(false);
{
scoped_refptr<ProxyService> service(new ProxyService(
new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
@@ -740,7 +740,7 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) {
EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI());
}
{
- config.proxy_rules.ParseFromString("foopy1:8080");
+ config.proxy_rules().ParseFromString("foopy1:8080");
scoped_refptr<ProxyService> service(new ProxyService(
new MockProxyConfigService(config), new MockAsyncProxyResolver, NULL));
GURL test_url("http://www.microsoft.com");
@@ -757,10 +757,10 @@ TEST(ProxyServiceTest, PerProtocolProxyTests) {
// fall back to the SOCKS proxy.
TEST(ProxyServiceTest, DefaultProxyFallbackToSOCKS) {
ProxyConfig config;
- config.proxy_rules.ParseFromString("http=foopy1:8080;socks=foopy2:1080");
- config.auto_detect = false;
+ config.proxy_rules().ParseFromString("http=foopy1:8080;socks=foopy2:1080");
+ config.set_auto_detect(false);
EXPECT_EQ(ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
- config.proxy_rules.type);
+ config.proxy_rules().type);
{
scoped_refptr<ProxyService> service(new ProxyService(
@@ -1105,9 +1105,9 @@ TEST(ProxyServiceTest, CancelWhilePACFetching) {
// Test that if auto-detect fails, we fall-back to the custom pac.
TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) {
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://foopy/proxy.pac");
- config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used.
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://foopy/proxy.pac"));
+ config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used.
MockProxyConfigService* config_service = new MockProxyConfigService(config);
MockAsyncProxyResolverExpectsBytes* resolver =
@@ -1176,9 +1176,9 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac) {
// the auto-detect script fails parsing rather than downloading.
TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) {
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://foopy/proxy.pac");
- config.proxy_rules.ParseFromString("http=foopy:80"); // Won't be used.
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://foopy/proxy.pac"));
+ config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used.
MockProxyConfigService* config_service = new MockProxyConfigService(config);
MockAsyncProxyResolverExpectsBytes* resolver =
@@ -1252,9 +1252,9 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) {
// are given, then we will try them in that order.
TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) {
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://foopy/proxy.pac");
- config.proxy_rules.ParseFromString("http=foopy:80");
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://foopy/proxy.pac"));
+ config.proxy_rules().ParseFromString("http=foopy:80");
MockProxyConfigService* config_service = new MockProxyConfigService(config);
MockAsyncProxyResolverExpectsBytes* resolver =
@@ -1309,10 +1309,10 @@ TEST(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) {
// Test that the bypass rules are NOT applied when using autodetect.
TEST(ProxyServiceTest, BypassDoesntApplyToPac) {
ProxyConfig config;
- config.auto_detect = true;
- config.pac_url = GURL("http://foopy/proxy.pac");
- config.proxy_rules.ParseFromString("http=foopy:80"); // Not used.
- config.bypass_rules.ParseFromString("www.google.com");
+ config.set_auto_detect(true);
+ config.set_pac_url(GURL("http://foopy/proxy.pac"));
+ config.proxy_rules().ParseFromString("http=foopy:80"); // Not used.
+ config.proxy_rules().bypass_rules.ParseFromString("www.google.com");
MockProxyConfigService* config_service = new MockProxyConfigService(config);
MockAsyncProxyResolverExpectsBytes* resolver =
@@ -1380,7 +1380,7 @@ TEST(ProxyServiceTest, BypassDoesntApplyToPac) {
// being deleted prior to the InitProxyResolver).
TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) {
ProxyConfig config;
- config.pac_url = GURL("http://foopy/proxy.pac");
+ config.set_pac_url(GURL("http://foopy/proxy.pac"));
MockProxyConfigService* config_service = new MockProxyConfigService(config);
MockAsyncProxyResolverExpectsBytes* resolver =
@@ -1440,8 +1440,8 @@ TEST(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) {
TEST(ProxyServiceTest, ResetProxyConfigService) {
ProxyConfig config1;
- config1.proxy_rules.ParseFromString("foopy1:8080");
- config1.auto_detect = false;
+ config1.proxy_rules().ParseFromString("foopy1:8080");
+ config1.set_auto_detect(false);
scoped_refptr<ProxyService> service(new ProxyService(
new MockProxyConfigService(config1),
new MockAsyncProxyResolverExpectsBytes,
@@ -1455,8 +1455,8 @@ TEST(ProxyServiceTest, ResetProxyConfigService) {
EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
ProxyConfig config2;
- config2.proxy_rules.ParseFromString("foopy2:8080");
- config2.auto_detect = false;
+ config2.proxy_rules().ParseFromString("foopy2:8080");
+ config2.set_auto_detect(false);
service->ResetConfigService(new MockProxyConfigService(config2));
TestCompletionCallback callback2;
rv = service->ResolveProxy(
@@ -1472,7 +1472,7 @@ TEST(ProxyServiceTest, ResetProxyConfigService) {
// thought it had received a new configuration.
TEST(ProxyServiceTest, UpdateConfigAfterFailedAutodetect) {
ProxyConfig config;
- config.auto_detect = true;
+ config.set_auto_detect(true);
MockProxyConfigService* config_service = new MockProxyConfigService(config);
MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
@@ -1518,7 +1518,7 @@ TEST(ProxyServiceTest, UpdateConfigAfterFailedAutodetect) {
// that does NOT, we unset the variable |should_use_proxy_resolver_|.
TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) {
ProxyConfig config;
- config.auto_detect = true;
+ config.set_auto_detect(true);
MockProxyConfigService* config_service = new MockProxyConfigService(config);
MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
@@ -1554,7 +1554,7 @@ TEST(ProxyServiceTest, UpdateConfigFromPACToDirect) {
//
// This new configuration no longer has auto_detect set, so
// requests should complete synchronously now as direct-connect.
- config.auto_detect = false;
+ config.set_auto_detect(false);
config_service->config = config;
service->UpdateConfig(NULL);
diff --git a/net/spdy/spdy_network_transaction_unittest.cc b/net/spdy/spdy_network_transaction_unittest.cc
index 888685a..31847ef 100644
--- a/net/spdy/spdy_network_transaction_unittest.cc
+++ b/net/spdy/spdy_network_transaction_unittest.cc
@@ -26,11 +26,6 @@ namespace net {
namespace {
-// Create a proxy service which fails on all requests (falls back to direct).
-ProxyService* CreateNullProxyService() {
- return ProxyService::CreateNull();
-}
-
// Helper to manage the lifetimes of the dependencies for a
// SpdyNetworkTransaction.
class SessionDependencies {
@@ -38,7 +33,7 @@ class SessionDependencies {
// Default set of dependencies -- "null" proxy service.
SessionDependencies()
: host_resolver(new MockHostResolver),
- proxy_service(CreateNullProxyService()),
+ proxy_service(ProxyService::CreateNull()),
ssl_config_service(new SSLConfigServiceDefaults),
http_auth_handler_factory(HttpAuthHandlerFactory::CreateDefault()),
spdy_session_pool(new SpdySessionPool) {
@@ -67,13 +62,6 @@ class SessionDependencies {
scoped_refptr<SpdySessionPool> spdy_session_pool;
};
-ProxyService* CreateFixedProxyService(const std::string& proxy) {
- ProxyConfig proxy_config;
- proxy_config.proxy_rules.ParseFromString(proxy);
- return ProxyService::CreateFixed(proxy_config);
-}
-
-
HttpNetworkSession* CreateSession(SessionDependencies* session_deps) {
return new HttpNetworkSession(NULL,
session_deps->host_resolver,
diff --git a/net/url_request/url_request_unittest.h b/net/url_request/url_request_unittest.h
index e0868ff..2b1806e 100644
--- a/net/url_request/url_request_unittest.h
+++ b/net/url_request/url_request_unittest.h
@@ -139,7 +139,7 @@ class TestURLRequestContext : public URLRequestContext {
explicit TestURLRequestContext(const std::string& proxy) {
host_resolver_ = net::CreateSystemHostResolver(NULL);
net::ProxyConfig proxy_config;
- proxy_config.proxy_rules.ParseFromString(proxy);
+ proxy_config.proxy_rules().ParseFromString(proxy);
proxy_service_ = net::ProxyService::CreateFixed(proxy_config);
Init();
}