blob: 024863880ccd2d0cb80f8933751efe05fb0df25e [file] [log] [blame]
[email protected]db8ff912012-06-12 23:32:511// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]96ce22362009-03-27 20:19:572// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "net/proxy/proxy_config_service_win.h"
6
7#include "net/base/net_errors.h"
8#include "net/proxy/proxy_config.h"
[email protected]861c6c62009-04-20 16:50:569#include "net/proxy/proxy_config_service_common_unittest.h"
[email protected]96ce22362009-03-27 20:19:5710#include "testing/gtest/include/gtest/gtest.h"
11
12namespace net {
13
14TEST(ProxyConfigServiceWinTest, SetFromIEConfig) {
[email protected]900634e02014-07-23 22:04:5315 // Like WINHTTP_CURRENT_USER_IE_PROXY_CONFIG, but with const strings.
16 struct IEProxyConfig {
17 BOOL auto_detect;
18 const wchar_t* auto_config_url;
19 const wchar_t* proxy;
20 const wchar_t* proxy_bypass;
21 };
[email protected]96ce22362009-03-27 20:19:5722 const struct {
23 // Input.
[email protected]900634e02014-07-23 22:04:5324 IEProxyConfig ie_config;
[email protected]96ce22362009-03-27 20:19:5725
26 // Expected outputs (fields of the ProxyConfig).
27 bool auto_detect;
28 GURL pac_url;
[email protected]ed4ed0f2010-02-24 00:20:4829 ProxyRulesExpectation proxy_rules;
[email protected]96ce22362009-03-27 20:19:5730 const char* proxy_bypass_list; // newline separated
[email protected]96ce22362009-03-27 20:19:5731 } tests[] = {
32 // Auto detect.
33 {
34 { // Input.
35 TRUE, // fAutoDetect
36 NULL, // lpszAutoConfigUrl
37 NULL, // lpszProxy
38 NULL, // lpszProxyBypass
39 },
40
41 // Expected result.
[email protected]5b45aec02009-03-31 01:03:2342 true, // auto_detect
43 GURL(), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:4844 ProxyRulesExpectation::Empty(),
[email protected]96ce22362009-03-27 20:19:5745 },
46
47 // Valid PAC url
48 {
49 { // Input.
50 FALSE, // fAutoDetect
51 L"http://wpad/wpad.dat", // lpszAutoConfigUrl
52 NULL, // lpszProxy
53 NULL, // lpszProxy_bypass
54 },
55
56 // Expected result.
57 false, // auto_detect
58 GURL("http://wpad/wpad.dat"), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:4859 ProxyRulesExpectation::Empty(),
[email protected]96ce22362009-03-27 20:19:5760 },
61
62 // Invalid PAC url string.
63 {
64 { // Input.
65 FALSE, // fAutoDetect
66 L"wpad.dat", // lpszAutoConfigUrl
67 NULL, // lpszProxy
68 NULL, // lpszProxy_bypass
69 },
70
71 // Expected result.
[email protected]5b45aec02009-03-31 01:03:2372 false, // auto_detect
73 GURL(), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:4874 ProxyRulesExpectation::Empty(),
[email protected]96ce22362009-03-27 20:19:5775 },
76
77 // Single-host in proxy list.
78 {
79 { // Input.
80 FALSE, // fAutoDetect
81 NULL, // lpszAutoConfigUrl
82 L"www.google.com", // lpszProxy
83 NULL, // lpszProxy_bypass
84 },
85
86 // Expected result.
[email protected]5b45aec02009-03-31 01:03:2387 false, // auto_detect
88 GURL(), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:4889 ProxyRulesExpectation::Single(
90 "www.google.com:80", // single proxy
91 ""), // bypass rules
[email protected]5b45aec02009-03-31 01:03:2392 },
93
94 // Per-scheme proxy rules.
95 {
96 { // Input.
97 FALSE, // fAutoDetect
98 NULL, // lpszAutoConfigUrl
99 L"http=www.google.com:80;https=www.foo.com:110", // lpszProxy
100 NULL, // lpszProxy_bypass
101 },
102
103 // Expected result.
104 false, // auto_detect
105 GURL(), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:48106 ProxyRulesExpectation::PerScheme(
107 "www.google.com:80", // http
108 "www.foo.com:110", // https
109 "", // ftp
110 ""), // bypass rules
[email protected]96ce22362009-03-27 20:19:57111 },
112
[email protected]6be52b92010-09-27 19:13:36113 // SOCKS proxy configuration.
[email protected]87a102b2009-07-14 05:23:30114 {
115 { // Input.
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
121 },
122
123 // Expected result.
[email protected]6be52b92010-09-27 19:13:36124 // Note that "socks" is interprted as meaning "socks4", since that is how
125 // Internet Explorer applies the settings. For more details on this
126 // policy, see:
127 // http://code.google.com/p/chromium/issues/detail?id=55912#c2
[email protected]87a102b2009-07-14 05:23:30128 false, // auto_detect
129 GURL(), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:48130 ProxyRulesExpectation::PerSchemeWithSocks(
131 "www.google.com:80", // http
132 "www.foo.com:110", // https
133 "ftpproxy:20", // ftp
134 "socks4://foopy:130", // socks
135 ""), // bypass rules
[email protected]87a102b2009-07-14 05:23:30136 },
137
[email protected]96ce22362009-03-27 20:19:57138 // Bypass local names.
139 {
140 { // Input.
141 TRUE, // fAutoDetect
142 NULL, // lpszAutoConfigUrl
143 NULL, // lpszProxy
[email protected]5b45aec02009-03-31 01:03:23144 L"<local>", // lpszProxy_bypass
[email protected]96ce22362009-03-27 20:19:57145 },
146
[email protected]5b45aec02009-03-31 01:03:23147 true, // auto_detect
148 GURL(), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:48149 ProxyRulesExpectation::EmptyWithBypass("<local>"),
[email protected]96ce22362009-03-27 20:19:57150 },
151
[email protected]ba8732d2011-04-19 01:01:21152 // Bypass "google.com" and local names, using semicolon as delimiter
[email protected]96ce22362009-03-27 20:19:57153 // (ignoring white space).
154 {
155 { // Input.
156 TRUE, // fAutoDetect
157 NULL, // lpszAutoConfigUrl
158 NULL, // lpszProxy
[email protected]5b45aec02009-03-31 01:03:23159 L"<local> ; google.com", // lpszProxy_bypass
[email protected]96ce22362009-03-27 20:19:57160 },
161
162 // Expected result.
[email protected]5b45aec02009-03-31 01:03:23163 true, // auto_detect
164 GURL(), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:48165 ProxyRulesExpectation::EmptyWithBypass("<local>,google.com"),
[email protected]96ce22362009-03-27 20:19:57166 },
167
[email protected]ba8732d2011-04-19 01:01:21168 // Bypass "foo.com" and "google.com", using lines as delimiter.
[email protected]96ce22362009-03-27 20:19:57169 {
170 { // Input.
171 TRUE, // fAutoDetect
172 NULL, // lpszAutoConfigUrl
173 NULL, // lpszProxy
174 L"foo.com\r\ngoogle.com", // lpszProxy_bypass
175 },
176
177 // Expected result.
[email protected]5b45aec02009-03-31 01:03:23178 true, // auto_detect
179 GURL(), // pac_url
[email protected]ed4ed0f2010-02-24 00:20:48180 ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"),
[email protected]96ce22362009-03-27 20:19:57181 },
[email protected]ba8732d2011-04-19 01:01:21182
183 // Bypass "foo.com" and "google.com", using commas as delimiter.
184 {
185 { // Input.
186 TRUE, // fAutoDetect
187 NULL, // lpszAutoConfigUrl
188 NULL, // lpszProxy
189 L"foo.com, google.com", // lpszProxy_bypass
190 },
191
192 // Expected result.
193 true, // auto_detect
194 GURL(), // pac_url
195 ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"),
196 },
[email protected]96ce22362009-03-27 20:19:57197 };
198
viettrungluue4a8b882014-10-16 06:17:38199 for (size_t i = 0; i < arraysize(tests); ++i) {
[email protected]900634e02014-07-23 22:04:53200 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)};
[email protected]96ce22362009-03-27 20:19:57205 ProxyConfig config;
[email protected]900634e02014-07-23 22:04:53206 ProxyConfigServiceWin::SetFromIEConfig(&config, ie_config);
[email protected]96ce22362009-03-27 20:19:57207
[email protected]ed4ed0f2010-02-24 00:20:48208 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()));
[email protected]db8ff912012-06-12 23:32:51211 EXPECT_EQ(PROXY_CONFIG_SOURCE_SYSTEM, config.source());
[email protected]96ce22362009-03-27 20:19:57212 }
213}
214
215} // namespace net