diff options
author | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-04 20:41:24 +0000 |
---|---|---|
committer | eroman@chromium.org <eroman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-05-04 20:41:24 +0000 |
commit | 483bf127599968f88d42f4ae6fb62b4c30d4aba7 (patch) | |
tree | 78ef31c7971999504a85d15a1347c6c2b113258f /chrome/browser/importer | |
parent | dffed056d438c98bad557de56e6da549c6912ca5 (diff) | |
download | chromium_src-483bf127599968f88d42f4ae6fb62b4c30d4aba7.zip chromium_src-483bf127599968f88d42f4ae6fb62b4c30d4aba7.tar.gz chromium_src-483bf127599968f88d42f4ae6fb62b4c30d4aba7.tar.bz2 |
Add a tool for testing your network setup.
It runs a series of experiments using alternate network settings, to try and discover what the misconfiguration is.
DESIGN=http://docs.google.com/Doc?id=dfhcnb2v_22cjtdznvg
TEST=ConnectionTesterTest.*
Review URL: http://codereview.chromium.org/1937001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@46387 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/importer')
-rw-r--r-- | chrome/browser/importer/firefox_proxy_settings.cc | 70 | ||||
-rw-r--r-- | chrome/browser/importer/firefox_proxy_settings.h | 12 | ||||
-rw-r--r-- | chrome/browser/importer/firefox_proxy_settings_unittest.cc | 29 |
3 files changed, 109 insertions, 2 deletions
diff --git a/chrome/browser/importer/firefox_proxy_settings.cc b/chrome/browser/importer/firefox_proxy_settings.cc index 493beff..d4d0d88 100644 --- a/chrome/browser/importer/firefox_proxy_settings.cc +++ b/chrome/browser/importer/firefox_proxy_settings.cc @@ -8,6 +8,7 @@ #include "base/string_util.h" #include "base/values.h" #include "chrome/browser/importer/firefox_importer_utils.h" +#include "net/proxy/proxy_config.h" namespace { @@ -82,7 +83,7 @@ void FirefoxProxySettings::Reset() { } // static - bool FirefoxProxySettings::GetSettings(FirefoxProxySettings* settings) { +bool FirefoxProxySettings::GetSettings(FirefoxProxySettings* settings) { DCHECK(settings); settings->Reset(); @@ -93,6 +94,73 @@ void FirefoxProxySettings::Reset() { return GetSettingsFromFile(pref_file, settings); } +bool FirefoxProxySettings::ToProxyConfig(net::ProxyConfig* config) { + switch (config_type()) { + case NO_PROXY: + *config = net::ProxyConfig::CreateDirect(); + return true; + case AUTO_DETECT: + *config = net::ProxyConfig::CreateAutoDetect(); + return true; + case AUTO_FROM_URL: + *config = net::ProxyConfig::CreateFromCustomPacURL( + GURL(autoconfig_url())); + return true; + case SYSTEM: + // Can't convert this directly to a ProxyConfig. + return false; + case MANUAL: + // Handled outside of the switch (since it is a lot of code.) + break; + default: + NOTREACHED(); + return false; + } + + // The rest of this funciton is for handling the MANUAL case. + DCHECK_EQ(MANUAL, config_type()); + + *config = net::ProxyConfig(); + config->proxy_rules().type = + net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME; + + if (!http_proxy().empty()) { + config->proxy_rules().proxy_for_http = net::ProxyServer( + net::ProxyServer::SCHEME_HTTP, + http_proxy(), + http_proxy_port()); + } + + if (!ftp_proxy().empty()) { + config->proxy_rules().proxy_for_ftp = net::ProxyServer( + net::ProxyServer::SCHEME_HTTP, + ftp_proxy(), + ftp_proxy_port()); + } + + if (!ssl_proxy().empty()) { + config->proxy_rules().proxy_for_https = net::ProxyServer( + net::ProxyServer::SCHEME_HTTP, + ssl_proxy(), + ssl_proxy_port()); + } + + if (!socks_host().empty()) { + net::ProxyServer::Scheme proxy_scheme = V5 == socks_version() ? + net::ProxyServer::SCHEME_SOCKS5 : net::ProxyServer::SCHEME_SOCKS4; + + config->proxy_rules().socks_proxy = net::ProxyServer( + proxy_scheme, + socks_host(), + socks_port()); + } + + config->proxy_rules().bypass_rules.ParseFromStringUsingSuffixMatching( + JoinString(proxy_bypass_list_, ';')); + + return true; +} + // static bool FirefoxProxySettings::GetSettingsFromFile(const FilePath& pref_file, FirefoxProxySettings* settings) { diff --git a/chrome/browser/importer/firefox_proxy_settings.h b/chrome/browser/importer/firefox_proxy_settings.h index eb624bd..80e1e24 100644 --- a/chrome/browser/importer/firefox_proxy_settings.h +++ b/chrome/browser/importer/firefox_proxy_settings.h @@ -12,6 +12,10 @@ class FilePath; +namespace net { +class ProxyConfig; +} + class FirefoxProxySettings { public: enum ProxyConfig { @@ -62,6 +66,14 @@ class FirefoxProxySettings { return proxy_bypass_list_; } + const std::string autoconfig_url() const { + return autoconfig_url_; + } + + // Converts a FirefoxProxySettings object to a net::ProxyConfig. + // On success returns true and fills |config| with the result. + bool ToProxyConfig(net::ProxyConfig* config); + protected: // Gets the settings from the passed prefs.js file and returns true if // successful. diff --git a/chrome/browser/importer/firefox_proxy_settings_unittest.cc b/chrome/browser/importer/firefox_proxy_settings_unittest.cc index 8c854f4..8926f47 100644 --- a/chrome/browser/importer/firefox_proxy_settings_unittest.cc +++ b/chrome/browser/importer/firefox_proxy_settings_unittest.cc @@ -2,12 +2,15 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +#include <sstream> + #include "testing/gtest/include/gtest/gtest.h" #include "base/file_path.h" #include "base/path_service.h" #include "chrome/browser/importer/firefox_proxy_settings.h" #include "chrome/common/chrome_paths.h" +#include "net/proxy/proxy_config.h" class FirefoxProxySettingsTest : public testing::Test { }; @@ -47,5 +50,29 @@ TEST_F(FirefoxProxySettingsTest, TestParse) { EXPECT_EQ("localhost", settings.proxy_bypass_list()[0]); EXPECT_EQ("127.0.0.1", settings.proxy_bypass_list()[1]); EXPECT_EQ("noproxy.com", settings.proxy_bypass_list()[2]); -} + // Test that ToProxyConfig() properly translates into a net::ProxyConfig. + net::ProxyConfig config; + EXPECT_TRUE(settings.ToProxyConfig(&config)); + + // Pretty-print |config| to a string (easy way to define the expectations). + std::ostringstream stream; + stream << config; + std::string pretty_printed_config = stream.str(); + + EXPECT_EQ( + "Automatic settings:\n" + " Auto-detect: No\n" + " Custom PAC script: [None]\n" + "Manual settings:\n" + " Proxy server: \n" + " HTTP: http_proxy:1111\n" + " HTTPS: ssl_proxy:2222\n" + " FTP: ftp_proxy:3333\n" + " SOCKS: socks4://socks_host:5555\n" + " Bypass list: \n" + " *localhost\n" + " 127.0.0.1\n" + " *noproxy.com", + pretty_printed_config); +} |