1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "net/proxy/proxy_config_service_win.h"
7 #include "net/base/net_errors.h"
8 #include "net/proxy/proxy_config.h"
9 #include "net/proxy/proxy_config_service_common_unittest.h"
10 #include "testing/gtest/include/gtest/gtest.h"
14 TEST(ProxyConfigServiceWinTest
, SetFromIEConfig
) {
15 // Like WINHTTP_CURRENT_USER_IE_PROXY_CONFIG, but with const strings.
16 struct IEProxyConfig
{
18 const wchar_t* auto_config_url
;
20 const wchar_t* proxy_bypass
;
24 IEProxyConfig ie_config
;
26 // Expected outputs (fields of the ProxyConfig).
29 ProxyRulesExpectation proxy_rules
;
30 const char* proxy_bypass_list
; // newline separated
36 NULL
, // lpszAutoConfigUrl
38 NULL
, // lpszProxyBypass
44 ProxyRulesExpectation::Empty(),
51 L
"http://wpad/wpad.dat", // lpszAutoConfigUrl
53 NULL
, // lpszProxy_bypass
58 GURL("http://wpad/wpad.dat"), // pac_url
59 ProxyRulesExpectation::Empty(),
62 // Invalid PAC url string.
66 L
"wpad.dat", // lpszAutoConfigUrl
68 NULL
, // lpszProxy_bypass
74 ProxyRulesExpectation::Empty(),
77 // Single-host in proxy list.
81 NULL
, // lpszAutoConfigUrl
82 L
"www.google.com", // lpszProxy
83 NULL
, // lpszProxy_bypass
89 ProxyRulesExpectation::Single(
90 "www.google.com:80", // single proxy
94 // Per-scheme proxy rules.
98 NULL
, // lpszAutoConfigUrl
99 L
"http=www.google.com:80;https=www.foo.com:110", // lpszProxy
100 NULL
, // lpszProxy_bypass
104 false, // auto_detect
106 ProxyRulesExpectation::PerScheme(
107 "www.google.com:80", // http
108 "www.foo.com:110", // https
113 // SOCKS proxy configuration.
116 FALSE
, // fAutoDetect
117 NULL
, // lpszAutoConfigUrl
118 L
"http=www.google.com:80;https=www.foo.com:110;"
119 L
"ftp=ftpproxy:20;socks=foopy:130", // lpszProxy
120 NULL
, // lpszProxy_bypass
124 // Note that "socks" is interprted as meaning "socks4", since that is how
125 // Internet Explorer applies the settings. For more details on this
127 // http://code.google.com/p/chromium/issues/detail?id=55912#c2
128 false, // auto_detect
130 ProxyRulesExpectation::PerSchemeWithSocks(
131 "www.google.com:80", // http
132 "www.foo.com:110", // https
133 "ftpproxy:20", // ftp
134 "socks4://foopy:130", // socks
138 // Bypass local names.
142 NULL
, // lpszAutoConfigUrl
144 L
"<local>", // lpszProxy_bypass
149 ProxyRulesExpectation::EmptyWithBypass("<local>"),
152 // Bypass "google.com" and local names, using semicolon as delimiter
153 // (ignoring white space).
157 NULL
, // lpszAutoConfigUrl
159 L
"<local> ; google.com", // lpszProxy_bypass
165 ProxyRulesExpectation::EmptyWithBypass("<local>,google.com"),
168 // Bypass "foo.com" and "google.com", using lines as delimiter.
172 NULL
, // lpszAutoConfigUrl
174 L
"foo.com\r\ngoogle.com", // lpszProxy_bypass
180 ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"),
183 // Bypass "foo.com" and "google.com", using commas as delimiter.
187 NULL
, // lpszAutoConfigUrl
189 L
"foo.com, google.com", // lpszProxy_bypass
195 ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"),
199 for (size_t i
= 0; i
< ARRAYSIZE_UNSAFE(tests
); ++i
) {
200 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config
= {
201 tests
[i
].ie_config
.auto_detect
,
202 const_cast<wchar_t*>(tests
[i
].ie_config
.auto_config_url
),
203 const_cast<wchar_t*>(tests
[i
].ie_config
.proxy
),
204 const_cast<wchar_t*>(tests
[i
].ie_config
.proxy_bypass
)};
206 ProxyConfigServiceWin::SetFromIEConfig(&config
, ie_config
);
208 EXPECT_EQ(tests
[i
].auto_detect
, config
.auto_detect());
209 EXPECT_EQ(tests
[i
].pac_url
, config
.pac_url());
210 EXPECT_TRUE(tests
[i
].proxy_rules
.Matches(config
.proxy_rules()));
211 EXPECT_EQ(PROXY_CONFIG_SOURCE_SYSTEM
, config
.source());