[email protected] | db8ff91 | 2012-06-12 23:32:51 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 2 | // 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] | 861c6c6 | 2009-04-20 16:50:56 | [diff] [blame] | 9 | #include "net/proxy/proxy_config_service_common_unittest.h" |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 10 | #include "testing/gtest/include/gtest/gtest.h" |
| 11 | |
| 12 | namespace net { |
| 13 | |
| 14 | TEST(ProxyConfigServiceWinTest, SetFromIEConfig) { |
[email protected] | 900634e0 | 2014-07-23 22:04:53 | [diff] [blame] | 15 | // 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] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 22 | const struct { |
| 23 | // Input. |
[email protected] | 900634e0 | 2014-07-23 22:04:53 | [diff] [blame] | 24 | IEProxyConfig ie_config; |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 25 | |
| 26 | // Expected outputs (fields of the ProxyConfig). |
| 27 | bool auto_detect; |
| 28 | GURL pac_url; |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 29 | ProxyRulesExpectation proxy_rules; |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 30 | const char* proxy_bypass_list; // newline separated |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 31 | } 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] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 42 | true, // auto_detect |
| 43 | GURL(), // pac_url |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 44 | ProxyRulesExpectation::Empty(), |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 45 | }, |
| 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] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 59 | ProxyRulesExpectation::Empty(), |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 60 | }, |
| 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] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 72 | false, // auto_detect |
| 73 | GURL(), // pac_url |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 74 | ProxyRulesExpectation::Empty(), |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 75 | }, |
| 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] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 87 | false, // auto_detect |
| 88 | GURL(), // pac_url |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 89 | ProxyRulesExpectation::Single( |
| 90 | "www.google.com:80", // single proxy |
| 91 | ""), // bypass rules |
[email protected] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 92 | }, |
| 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] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 106 | ProxyRulesExpectation::PerScheme( |
| 107 | "www.google.com:80", // http |
| 108 | "www.foo.com:110", // https |
| 109 | "", // ftp |
| 110 | ""), // bypass rules |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 111 | }, |
| 112 | |
[email protected] | 6be52b9 | 2010-09-27 19:13:36 | [diff] [blame] | 113 | // SOCKS proxy configuration. |
[email protected] | 87a102b | 2009-07-14 05:23:30 | [diff] [blame] | 114 | { |
| 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] | 6be52b9 | 2010-09-27 19:13:36 | [diff] [blame] | 124 | // 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] | 87a102b | 2009-07-14 05:23:30 | [diff] [blame] | 128 | false, // auto_detect |
| 129 | GURL(), // pac_url |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 130 | 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] | 87a102b | 2009-07-14 05:23:30 | [diff] [blame] | 136 | }, |
| 137 | |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 138 | // Bypass local names. |
| 139 | { |
| 140 | { // Input. |
| 141 | TRUE, // fAutoDetect |
| 142 | NULL, // lpszAutoConfigUrl |
| 143 | NULL, // lpszProxy |
[email protected] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 144 | L"<local>", // lpszProxy_bypass |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 145 | }, |
| 146 | |
[email protected] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 147 | true, // auto_detect |
| 148 | GURL(), // pac_url |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 149 | ProxyRulesExpectation::EmptyWithBypass("<local>"), |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 150 | }, |
| 151 | |
[email protected] | ba8732d | 2011-04-19 01:01:21 | [diff] [blame] | 152 | // Bypass "google.com" and local names, using semicolon as delimiter |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 153 | // (ignoring white space). |
| 154 | { |
| 155 | { // Input. |
| 156 | TRUE, // fAutoDetect |
| 157 | NULL, // lpszAutoConfigUrl |
| 158 | NULL, // lpszProxy |
[email protected] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 159 | L"<local> ; google.com", // lpszProxy_bypass |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 160 | }, |
| 161 | |
| 162 | // Expected result. |
[email protected] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 163 | true, // auto_detect |
| 164 | GURL(), // pac_url |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 165 | ProxyRulesExpectation::EmptyWithBypass("<local>,google.com"), |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 166 | }, |
| 167 | |
[email protected] | ba8732d | 2011-04-19 01:01:21 | [diff] [blame] | 168 | // Bypass "foo.com" and "google.com", using lines as delimiter. |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 169 | { |
| 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] | 5b45aec0 | 2009-03-31 01:03:23 | [diff] [blame] | 178 | true, // auto_detect |
| 179 | GURL(), // pac_url |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 180 | ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"), |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 181 | }, |
[email protected] | ba8732d | 2011-04-19 01:01:21 | [diff] [blame] | 182 | |
| 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] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 197 | }; |
| 198 | |
viettrungluu | e4a8b88 | 2014-10-16 06:17:38 | [diff] [blame] | 199 | for (size_t i = 0; i < arraysize(tests); ++i) { |
[email protected] | 900634e0 | 2014-07-23 22:04:53 | [diff] [blame] | 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)}; |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 205 | ProxyConfig config; |
[email protected] | 900634e0 | 2014-07-23 22:04:53 | [diff] [blame] | 206 | ProxyConfigServiceWin::SetFromIEConfig(&config, ie_config); |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 207 | |
[email protected] | ed4ed0f | 2010-02-24 00:20:48 | [diff] [blame] | 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())); |
[email protected] | db8ff91 | 2012-06-12 23:32:51 | [diff] [blame] | 211 | EXPECT_EQ(PROXY_CONFIG_SOURCE_SYSTEM, config.source()); |
[email protected] | 96ce2236 | 2009-03-27 20:19:57 | [diff] [blame] | 212 | } |
| 213 | } |
| 214 | |
| 215 | } // namespace net |