diff options
author | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 20:19:57 +0000 |
---|---|---|
committer | ericroman@google.com <ericroman@google.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2009-03-27 20:19:57 +0000 |
commit | 96ce2236c77dad045d6003848c4a15f067a992ff (patch) | |
tree | 3386773b3ad8ad69a0db793d74ef82d3e7c6cb01 /net | |
parent | 899444114171abea60072f2b3980e3730c59058c (diff) | |
download | chromium_src-96ce2236c77dad045d6003848c4a15f067a992ff.zip chromium_src-96ce2236c77dad045d6003848c4a15f067a992ff.tar.gz chromium_src-96ce2236c77dad045d6003848c4a15f067a992ff.tar.bz2 |
Add a unit test for ProxyConfigServiceWin.
Review URL: http://codereview.chromium.org/55001
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@12695 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'net')
-rw-r--r-- | net/net.gyp | 2 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_win.cc | 25 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_win.h | 12 | ||||
-rw-r--r-- | net/proxy/proxy_config_service_win_unittest.cc | 166 |
4 files changed, 195 insertions, 10 deletions
diff --git a/net/net.gyp b/net/net.gyp index df06d07..e7ed8bd 100644 --- a/net/net.gyp +++ b/net/net.gyp @@ -426,6 +426,7 @@ 'http/http_transaction_unittest.h', 'http/http_util_unittest.cc', 'http/http_vary_data_unittest.cc', + 'proxy/proxy_config_service_win_unittest.cc', 'proxy/proxy_list_unittest.cc', 'proxy/proxy_resolver_v8_unittest.cc', 'proxy/proxy_script_fetcher_unittest.cc', @@ -438,6 +439,7 @@ [ 'OS != "win"', { 'sources!': [ 'base/wininet_util_unittest.cc', + 'proxy/proxy_config_service_win_unittest.cc', ], }, ], diff --git a/net/proxy/proxy_config_service_win.cc b/net/proxy/proxy_config_service_win.cc index 0521f1d..ab02c66 100644 --- a/net/proxy/proxy_config_service_win.cc +++ b/net/proxy/proxy_config_service_win.cc @@ -17,13 +17,13 @@ namespace net { -static void FreeConfig(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* config) { - if (config->lpszAutoConfigUrl) - GlobalFree(config->lpszAutoConfigUrl); - if (config->lpszProxy) - GlobalFree(config->lpszProxy); - if (config->lpszProxyBypass) - GlobalFree(config->lpszProxyBypass); +static void FreeIEConfig(WINHTTP_CURRENT_USER_IE_PROXY_CONFIG* ie_config) { + if (ie_config->lpszAutoConfigUrl) + GlobalFree(ie_config->lpszAutoConfigUrl); + if (ie_config->lpszProxy) + GlobalFree(ie_config->lpszProxy); + if (ie_config->lpszProxyBypass) + GlobalFree(ie_config->lpszProxyBypass); } int ProxyConfigServiceWin::GetProxyConfig(ProxyConfig* config) { @@ -33,7 +33,15 @@ int ProxyConfigServiceWin::GetProxyConfig(ProxyConfig* config) { GetLastError(); return ERR_FAILED; // TODO(darin): Bug 1189288: translate error code. } + SetFromIEConfig(config, ie_config); + FreeIEConfig(&ie_config); + return OK; +} +// static +void ProxyConfigServiceWin::SetFromIEConfig( + ProxyConfig* config, + const WINHTTP_CURRENT_USER_IE_PROXY_CONFIG& ie_config) { if (ie_config.fAutoDetect) config->auto_detect = true; if (ie_config.lpszProxy) @@ -52,9 +60,6 @@ int ProxyConfigServiceWin::GetProxyConfig(ProxyConfig* config) { } if (ie_config.lpszAutoConfigUrl) config->pac_url = GURL(ie_config.lpszAutoConfigUrl); - - FreeConfig(&ie_config); - return OK; } } // namespace net diff --git a/net/proxy/proxy_config_service_win.h b/net/proxy/proxy_config_service_win.h index 59b14c6..76f8ced 100644 --- a/net/proxy/proxy_config_service_win.h +++ b/net/proxy/proxy_config_service_win.h @@ -5,7 +5,11 @@ #ifndef NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ #define NET_PROXY_PROXY_CONFIG_SERVICE_WIN_H_ +#include <windows.h> +#include <winhttp.h> + #include "net/proxy/proxy_config_service.h" +#include "testing/gtest/include/gtest/gtest_prod.h" namespace net { @@ -15,6 +19,14 @@ class ProxyConfigServiceWin : public ProxyConfigService { public: // ProxyConfigService methods. virtual int GetProxyConfig(ProxyConfig* config); + + private: + FRIEND_TEST(ProxyConfigServiceWinTest, SetFromIEConfig); + + // Set |config| using the proxy configuration values of |ie_config|. + static void SetFromIEConfig( + ProxyConfig* config, + const WINHTTP_CURRENT_USER_IE_PROXY_CONFIG& ie_config); }; } // namespace net diff --git a/net/proxy/proxy_config_service_win_unittest.cc b/net/proxy/proxy_config_service_win_unittest.cc new file mode 100644 index 0000000..8d88eb3 --- /dev/null +++ b/net/proxy/proxy_config_service_win_unittest.cc @@ -0,0 +1,166 @@ +// Copyright (c) 2009 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "net/proxy/proxy_config_service_win.h" + +#include "net/base/net_errors.h" +#include "net/proxy/proxy_config.h" +#include "testing/gtest/include/gtest/gtest.h" + +namespace net { + +TEST(ProxyConfigServiceWinTest, SetFromIEConfig) { + const struct { + // Input. + WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config; + + // Expected outputs (fields of the ProxyConfig). + bool auto_detect; + GURL pac_url; + const char* proxy_rules; + const char* proxy_bypass_list; // newline separated + bool bypass_local_names; + } tests[] = { + // Auto detect. + { + { // Input. + TRUE, // fAutoDetect + NULL, // lpszAutoConfigUrl + NULL, // lpszProxy + NULL, // lpszProxyBypass + }, + + // Expected result. + true, // auto_detect + GURL(), // pac_url + "", // proxy_rules + "", // proxy_bypass_list + false, // bypass_local_names + }, + + // Valid PAC url + { + { // Input. + FALSE, // fAutoDetect + L"http://wpad/wpad.dat", // lpszAutoConfigUrl + NULL, // lpszProxy + NULL, // lpszProxy_bypass + }, + + // Expected result. + false, // auto_detect + GURL("http://wpad/wpad.dat"), // pac_url + "", // proxy_rules + "", // proxy_bypass_list + false, // bypass_local_names + }, + + // Invalid PAC url string. + { + { // Input. + FALSE, // fAutoDetect + L"wpad.dat", // lpszAutoConfigUrl + NULL, // lpszProxy + NULL, // lpszProxy_bypass + }, + + // Expected result. + false, // auto_detect + GURL(), // pac_url + "", // proxy_rules + "", // proxy_bypass_list + false, // bypass_local_names + }, + + // Single-host in proxy list. + { + { // Input. + FALSE, // fAutoDetect + NULL, // lpszAutoConfigUrl + L"www.google.com", // lpszProxy + NULL, // lpszProxy_bypass + }, + + // Expected result. + false, // auto_detect + GURL(), // pac_url + "www.google.com", // proxy_rules + "", // proxy_bypass_list + false, // bypass_local_names + }, + + // Bypass local names. + { + { // Input. + TRUE, // fAutoDetect + NULL, // lpszAutoConfigUrl + NULL, // lpszProxy + L"<local>", // lpszProxy_bypass + }, + + true, // auto_detect + GURL(), // pac_url + "", // proxy_rules + "", // proxy_bypass_list + true, // bypass_local_names + }, + + // Bypass "google.com" and local names, using semicolon as delimeter + // (ignoring white space). + { + { // Input. + TRUE, // fAutoDetect + NULL, // lpszAutoConfigUrl + NULL, // lpszProxy + L"<local> ; google.com", // lpszProxy_bypass + }, + + // Expected result. + true, // auto_detect + GURL(), // pac_url + "", // proxy_rules + "google.com\n", // proxy_bypass_list + true, // bypass_local_names + }, + + // Bypass "foo.com" and "google.com", using lines as delimeter. + { + { // Input. + TRUE, // fAutoDetect + NULL, // lpszAutoConfigUrl + NULL, // lpszProxy + L"foo.com\r\ngoogle.com", // lpszProxy_bypass + }, + + // Expected result. + true, // auto_detect + GURL(), // pac_url + "", // proxy_rules + "foo.com\ngoogle.com\n", // proxy_bypass_list + false, // bypass_local_names + }, + }; + + for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { + 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); + + // Join the proxy bypass list using "\n" to make it into a single string. + std::string flattened_proxy_bypass; + typedef std::vector<std::string> BypassList; + for (BypassList::const_iterator it = config.proxy_bypass.begin(); + it != config.proxy_bypass.end(); ++it) { + flattened_proxy_bypass += *it + "\n"; + } + + EXPECT_EQ(tests[i].proxy_bypass_list, flattened_proxy_bypass); + EXPECT_EQ(tests[i].bypass_local_names, config.proxy_bypass_local_names); + EXPECT_EQ(tests[i].proxy_rules, config.proxy_rules); + } +} + +} // namespace net |