OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "net/proxy/proxy_config_service_win.h" | 5 #include "net/proxy/proxy_config_service_win.h" |
6 | 6 |
7 #include "net/base/net_errors.h" | 7 #include "net/base/net_errors.h" |
8 #include "net/proxy/proxy_config.h" | 8 #include "net/proxy/proxy_config.h" |
9 #include "net/proxy/proxy_config_service_common_unittest.h" | 9 #include "net/proxy/proxy_config_service_common_unittest.h" |
10 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
11 | 11 |
12 namespace net { | 12 namespace net { |
13 | 13 |
14 TEST(ProxyConfigServiceWinTest, SetFromIEConfig) { | 14 TEST(ProxyConfigServiceWinTest, SetFromIEConfig) { |
15 const struct { | 15 const struct { |
16 // Input. | 16 // Input. |
17 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config; | 17 WINHTTP_CURRENT_USER_IE_PROXY_CONFIG ie_config; |
18 | 18 |
19 // Expected outputs (fields of the ProxyConfig). | 19 // Expected outputs (fields of the ProxyConfig). |
20 bool auto_detect; | 20 bool auto_detect; |
21 GURL pac_url; | 21 GURL pac_url; |
22 ProxyRulesExpectation proxy_rules; | 22 ProxyRulesExpectation proxy_rules; |
23 const char* proxy_bypass_list; // newline separated | 23 const char* proxy_bypass_list; // newline separated |
24 } tests[] = { | 24 } tests[] = { |
25 // Auto detect. | 25 // Auto detect. |
26 { | 26 { |
27 { // Input. | 27 { // Input. |
28 TRUE, // fAutoDetect | 28 TRUE, // fAutoDetect |
29 NULL, // lpszAutoConfigUrl | 29 NULL, // lpszAutoConfigUrl |
30 NULL, // lpszProxy | 30 NULL, // lpszProxy |
31 NULL, // lpszProxyBypass | 31 NULL, // lpszProxyBypass |
32 }, | 32 }, |
33 | 33 |
34 // Expected result. | 34 // Expected result. |
35 true, // auto_detect | 35 true, // auto_detect |
36 GURL(), // pac_url | 36 GURL(), // pac_url |
37 ProxyRulesExpectation::Empty(), | 37 ProxyRulesExpectation::Empty(), |
38 }, | 38 }, |
39 | 39 |
40 // Valid PAC url | 40 // Valid PAC url |
41 { | 41 { |
42 { // Input. | 42 { // Input. |
43 FALSE, // fAutoDetect | 43 FALSE, // fAutoDetect |
44 L"http://wpad/wpad.dat", // lpszAutoConfigUrl | 44 L"http://wpad/wpad.dat", // lpszAutoConfigUrl |
45 NULL, // lpszProxy | 45 NULL, // lpszProxy |
46 NULL, // lpszProxy_bypass | 46 NULL, // lpszProxy_bypass |
47 }, | 47 }, |
48 | 48 |
49 // Expected result. | 49 // Expected result. |
50 false, // auto_detect | 50 false, // auto_detect |
51 GURL("http://wpad/wpad.dat"), // pac_url | 51 GURL("http://wpad/wpad.dat"), // pac_url |
52 ProxyRulesExpectation::Empty(), | 52 ProxyRulesExpectation::Empty(), |
53 }, | 53 }, |
54 | 54 |
55 // Invalid PAC url string. | 55 // Invalid PAC url string. |
56 { | 56 { |
57 { // Input. | 57 { // Input. |
58 FALSE, // fAutoDetect | 58 FALSE, // fAutoDetect |
59 L"wpad.dat", // lpszAutoConfigUrl | 59 L"wpad.dat", // lpszAutoConfigUrl |
60 NULL, // lpszProxy | 60 NULL, // lpszProxy |
61 NULL, // lpszProxy_bypass | 61 NULL, // lpszProxy_bypass |
62 }, | 62 }, |
63 | 63 |
64 // Expected result. | 64 // Expected result. |
65 false, // auto_detect | 65 false, // auto_detect |
66 GURL(), // pac_url | 66 GURL(), // pac_url |
67 ProxyRulesExpectation::Empty(), | 67 ProxyRulesExpectation::Empty(), |
68 }, | 68 }, |
69 | 69 |
70 // Single-host in proxy list. | 70 // Single-host in proxy list. |
71 { | 71 { |
72 { // Input. | 72 { // Input. |
73 FALSE, // fAutoDetect | 73 FALSE, // fAutoDetect |
74 NULL, // lpszAutoConfigUrl | 74 NULL, // lpszAutoConfigUrl |
75 L"www.google.com", // lpszProxy | 75 L"www.google.com", // lpszProxy |
76 NULL, // lpszProxy_bypass | 76 NULL, // lpszProxy_bypass |
77 }, | 77 }, |
78 | 78 |
79 // Expected result. | 79 // Expected result. |
80 false, // auto_detect | 80 false, // auto_detect |
81 GURL(), // pac_url | 81 GURL(), // pac_url |
82 ProxyRulesExpectation::Single( | 82 ProxyRulesExpectation::Single("www.google.com:80", // single proxy |
83 "www.google.com:80", // single proxy | 83 ""), // bypass rules |
84 ""), // bypass rules | 84 }, |
85 }, | |
86 | 85 |
87 // Per-scheme proxy rules. | 86 // Per-scheme proxy rules. |
88 { | 87 { |
89 { // Input. | 88 { // Input. |
90 FALSE, // fAutoDetect | 89 FALSE, // fAutoDetect |
91 NULL, // lpszAutoConfigUrl | 90 NULL, // lpszAutoConfigUrl |
92 L"http=www.google.com:80;https=www.foo.com:110", // lpszProxy | 91 L"http=www.google.com:80;https=www.foo.com:110", // lpszProxy |
93 NULL, // lpszProxy_bypass | 92 NULL, // lpszProxy_bypass |
94 }, | 93 }, |
95 | 94 |
96 // Expected result. | 95 // Expected result. |
97 false, // auto_detect | 96 false, // auto_detect |
98 GURL(), // pac_url | 97 GURL(), // pac_url |
99 ProxyRulesExpectation::PerScheme( | 98 ProxyRulesExpectation::PerScheme("www.google.com:80", // http |
100 "www.google.com:80", // http | 99 "www.foo.com:110", // https |
101 "www.foo.com:110", // https | 100 "", // ftp |
102 "", // ftp | 101 ""), // bypass rules |
103 ""), // bypass rules | 102 }, |
104 }, | |
105 | 103 |
106 // SOCKS proxy configuration. | 104 // SOCKS proxy configuration. |
107 { | 105 { |
108 { // Input. | 106 { // Input. |
109 FALSE, // fAutoDetect | 107 FALSE, // fAutoDetect |
110 NULL, // lpszAutoConfigUrl | 108 NULL, // lpszAutoConfigUrl |
111 L"http=www.google.com:80;https=www.foo.com:110;" | 109 L"http=www.google.com:80;https=www.foo.com:110;" |
112 L"ftp=ftpproxy:20;socks=foopy:130", // lpszProxy | 110 L"ftp=ftpproxy:20;socks=foopy:130", // lpszProxy |
113 NULL, // lpszProxy_bypass | 111 NULL, // lpszProxy_bypass |
114 }, | 112 }, |
115 | 113 |
116 // Expected result. | 114 // Expected result. |
117 // Note that "socks" is interprted as meaning "socks4", since that is how | 115 // Note that "socks" is interprted as meaning "socks4", since that is |
118 // Internet Explorer applies the settings. For more details on this | 116 // how |
119 // policy, see: | 117 // Internet Explorer applies the settings. For more details on this |
120 // http://code.google.com/p/chromium/issues/detail?id=55912#c2 | 118 // policy, see: |
121 false, // auto_detect | 119 // http://code.google.com/p/chromium/issues/detail?id=55912#c2 |
122 GURL(), // pac_url | 120 false, // auto_detect |
123 ProxyRulesExpectation::PerSchemeWithSocks( | 121 GURL(), // pac_url |
124 "www.google.com:80", // http | 122 ProxyRulesExpectation::PerSchemeWithSocks( |
125 "www.foo.com:110", // https | 123 "www.google.com:80", // http |
126 "ftpproxy:20", // ftp | 124 "www.foo.com:110", // https |
127 "socks4://foopy:130", // socks | 125 "ftpproxy:20", // ftp |
128 ""), // bypass rules | 126 "socks4://foopy:130", // socks |
129 }, | 127 ""), // bypass rules |
| 128 }, |
130 | 129 |
131 // Bypass local names. | 130 // Bypass local names. |
132 { | 131 { |
133 { // Input. | 132 { // Input. |
134 TRUE, // fAutoDetect | 133 TRUE, // fAutoDetect |
135 NULL, // lpszAutoConfigUrl | 134 NULL, // lpszAutoConfigUrl |
136 NULL, // lpszProxy | 135 NULL, // lpszProxy |
137 L"<local>", // lpszProxy_bypass | 136 L"<local>", // lpszProxy_bypass |
138 }, | 137 }, |
| 138 true, // auto_detect |
| 139 GURL(), // pac_url |
| 140 ProxyRulesExpectation::EmptyWithBypass("<local>"), |
| 141 }, |
139 | 142 |
140 true, // auto_detect | 143 // Bypass "google.com" and local names, using semicolon as delimiter |
141 GURL(), // pac_url | 144 // (ignoring white space). |
142 ProxyRulesExpectation::EmptyWithBypass("<local>"), | 145 { |
143 }, | 146 { // Input. |
| 147 TRUE, // fAutoDetect |
| 148 NULL, // lpszAutoConfigUrl |
| 149 NULL, // lpszProxy |
| 150 L"<local> ; google.com", // lpszProxy_bypass |
| 151 }, |
144 | 152 |
145 // Bypass "google.com" and local names, using semicolon as delimiter | 153 // Expected result. |
146 // (ignoring white space). | 154 true, // auto_detect |
147 { | 155 GURL(), // pac_url |
148 { // Input. | 156 ProxyRulesExpectation::EmptyWithBypass("<local>,google.com"), |
149 TRUE, // fAutoDetect | 157 }, |
150 NULL, // lpszAutoConfigUrl | |
151 NULL, // lpszProxy | |
152 L"<local> ; google.com", // lpszProxy_bypass | |
153 }, | |
154 | 158 |
155 // Expected result. | 159 // Bypass "foo.com" and "google.com", using lines as delimiter. |
156 true, // auto_detect | 160 { |
157 GURL(), // pac_url | 161 { // Input. |
158 ProxyRulesExpectation::EmptyWithBypass("<local>,google.com"), | 162 TRUE, // fAutoDetect |
159 }, | 163 NULL, // lpszAutoConfigUrl |
| 164 NULL, // lpszProxy |
| 165 L"foo.com\r\ngoogle.com", // lpszProxy_bypass |
| 166 }, |
160 | 167 |
161 // Bypass "foo.com" and "google.com", using lines as delimiter. | 168 // Expected result. |
162 { | 169 true, // auto_detect |
163 { // Input. | 170 GURL(), // pac_url |
164 TRUE, // fAutoDetect | 171 ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"), |
165 NULL, // lpszAutoConfigUrl | 172 }, |
166 NULL, // lpszProxy | |
167 L"foo.com\r\ngoogle.com", // lpszProxy_bypass | |
168 }, | |
169 | 173 |
170 // Expected result. | 174 // Bypass "foo.com" and "google.com", using commas as delimiter. |
171 true, // auto_detect | 175 { |
172 GURL(), // pac_url | 176 { // Input. |
173 ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"), | 177 TRUE, // fAutoDetect |
174 }, | 178 NULL, // lpszAutoConfigUrl |
| 179 NULL, // lpszProxy |
| 180 L"foo.com, google.com", // lpszProxy_bypass |
| 181 }, |
175 | 182 |
176 // Bypass "foo.com" and "google.com", using commas as delimiter. | 183 // Expected result. |
177 { | 184 true, // auto_detect |
178 { // Input. | 185 GURL(), // pac_url |
179 TRUE, // fAutoDetect | 186 ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"), |
180 NULL, // lpszAutoConfigUrl | 187 }, |
181 NULL, // lpszProxy | 188 }; |
182 L"foo.com, google.com", // lpszProxy_bypass | |
183 }, | |
184 | |
185 // Expected result. | |
186 true, // auto_detect | |
187 GURL(), // pac_url | |
188 ProxyRulesExpectation::EmptyWithBypass("foo.com,google.com"), | |
189 }, | |
190 }; | |
191 | 189 |
192 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { | 190 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { |
193 ProxyConfig config; | 191 ProxyConfig config; |
194 ProxyConfigServiceWin::SetFromIEConfig(&config, tests[i].ie_config); | 192 ProxyConfigServiceWin::SetFromIEConfig(&config, tests[i].ie_config); |
195 | 193 |
196 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); | 194 EXPECT_EQ(tests[i].auto_detect, config.auto_detect()); |
197 EXPECT_EQ(tests[i].pac_url, config.pac_url()); | 195 EXPECT_EQ(tests[i].pac_url, config.pac_url()); |
198 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); | 196 EXPECT_TRUE(tests[i].proxy_rules.Matches(config.proxy_rules())); |
199 EXPECT_EQ(PROXY_CONFIG_SOURCE_SYSTEM, config.source()); | 197 EXPECT_EQ(PROXY_CONFIG_SOURCE_SYSTEM, config.source()); |
200 } | 198 } |
201 } | 199 } |
202 | 200 |
203 } // namespace net | 201 } // namespace net |
OLD | NEW |