Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(153)

Side by Side Diff: net/proxy/proxy_config_unittest.cc

Issue 198039: Aesthetic changes to the proxy configuration log format.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Split up another long line Created 11 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « net/proxy/proxy_config.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <ostream>
6
5 #include "net/proxy/proxy_config.h" 7 #include "net/proxy/proxy_config.h"
6 #include "net/proxy/proxy_config_service_common_unittest.h" 8 #include "net/proxy/proxy_config_service_common_unittest.h"
7 #include "testing/gtest/include/gtest/gtest.h" 9 #include "testing/gtest/include/gtest/gtest.h"
8 10
11 namespace net {
9 namespace { 12 namespace {
10 static void ExpectProxyServerEquals(const char* expectation, 13
11 const net::ProxyServer& proxy_server) { 14 void ExpectProxyServerEquals(const char* expectation,
15 const ProxyServer& proxy_server) {
12 if (expectation == NULL) { 16 if (expectation == NULL) {
13 EXPECT_FALSE(proxy_server.is_valid()); 17 EXPECT_FALSE(proxy_server.is_valid());
14 } else { 18 } else {
15 EXPECT_EQ(expectation, proxy_server.ToURI()); 19 EXPECT_EQ(expectation, proxy_server.ToURI());
16 } 20 }
17 } 21 }
18 }
19 22
20 TEST(ProxyConfigTest, Equals) { 23 TEST(ProxyConfigTest, Equals) {
21 // Test |ProxyConfig::auto_detect|. 24 // Test |ProxyConfig::auto_detect|.
22 25
23 net::ProxyConfig config1; 26 ProxyConfig config1;
24 config1.auto_detect = true; 27 config1.auto_detect = true;
25 28
26 net::ProxyConfig config2; 29 ProxyConfig config2;
27 config2.auto_detect = false; 30 config2.auto_detect = false;
28 31
29 EXPECT_FALSE(config1.Equals(config2)); 32 EXPECT_FALSE(config1.Equals(config2));
30 EXPECT_FALSE(config2.Equals(config1)); 33 EXPECT_FALSE(config2.Equals(config1));
31 34
32 config2.auto_detect = true; 35 config2.auto_detect = true;
33 36
34 EXPECT_TRUE(config1.Equals(config2)); 37 EXPECT_TRUE(config1.Equals(config2));
35 EXPECT_TRUE(config2.Equals(config1)); 38 EXPECT_TRUE(config2.Equals(config1));
36 39
37 // Test |ProxyConfig::pac_url|. 40 // Test |ProxyConfig::pac_url|.
38 41
39 config2.pac_url = GURL("http://wpad/wpad.dat"); 42 config2.pac_url = GURL("http://wpad/wpad.dat");
40 43
41 EXPECT_FALSE(config1.Equals(config2)); 44 EXPECT_FALSE(config1.Equals(config2));
42 EXPECT_FALSE(config2.Equals(config1)); 45 EXPECT_FALSE(config2.Equals(config1));
43 46
44 config1.pac_url = GURL("http://wpad/wpad.dat"); 47 config1.pac_url = GURL("http://wpad/wpad.dat");
45 48
46 EXPECT_TRUE(config1.Equals(config2)); 49 EXPECT_TRUE(config1.Equals(config2));
47 EXPECT_TRUE(config2.Equals(config1)); 50 EXPECT_TRUE(config2.Equals(config1));
48 51
49 // Test |ProxyConfig::proxy_rules|. 52 // Test |ProxyConfig::proxy_rules|.
50 53
51 config2.proxy_rules.type = net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; 54 config2.proxy_rules.type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
52 config2.proxy_rules.single_proxy = 55 config2.proxy_rules.single_proxy =
53 net::ProxyServer::FromURI("myproxy:80", net::ProxyServer::SCHEME_HTTP); 56 ProxyServer::FromURI("myproxy:80", ProxyServer::SCHEME_HTTP);
54 57
55 EXPECT_FALSE(config1.Equals(config2)); 58 EXPECT_FALSE(config1.Equals(config2));
56 EXPECT_FALSE(config2.Equals(config1)); 59 EXPECT_FALSE(config2.Equals(config1));
57 60
58 config1.proxy_rules.type = net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY; 61 config1.proxy_rules.type = ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY;
59 config1.proxy_rules.single_proxy = 62 config1.proxy_rules.single_proxy =
60 net::ProxyServer::FromURI("myproxy:100", net::ProxyServer::SCHEME_HTTP); 63 ProxyServer::FromURI("myproxy:100", ProxyServer::SCHEME_HTTP);
61 64
62 EXPECT_FALSE(config1.Equals(config2)); 65 EXPECT_FALSE(config1.Equals(config2));
63 EXPECT_FALSE(config2.Equals(config1)); 66 EXPECT_FALSE(config2.Equals(config1));
64 67
65 config1.proxy_rules.single_proxy = 68 config1.proxy_rules.single_proxy =
66 net::ProxyServer::FromURI("myproxy", net::ProxyServer::SCHEME_HTTP); 69 ProxyServer::FromURI("myproxy", ProxyServer::SCHEME_HTTP);
67 70
68 EXPECT_TRUE(config1.Equals(config2)); 71 EXPECT_TRUE(config1.Equals(config2));
69 EXPECT_TRUE(config2.Equals(config1)); 72 EXPECT_TRUE(config2.Equals(config1));
70 73
71 // Test |ProxyConfig::proxy_bypass|. 74 // Test |ProxyConfig::proxy_bypass|.
72 75
73 config2.proxy_bypass.push_back("*.google.com"); 76 config2.proxy_bypass.push_back("*.google.com");
74 77
75 EXPECT_FALSE(config1.Equals(config2)); 78 EXPECT_FALSE(config1.Equals(config2));
76 EXPECT_FALSE(config2.Equals(config1)); 79 EXPECT_FALSE(config2.Equals(config1));
(...skipping 13 matching lines...) Expand all
90 config2.proxy_bypass_local_names = true; 93 config2.proxy_bypass_local_names = true;
91 94
92 EXPECT_TRUE(config1.Equals(config2)); 95 EXPECT_TRUE(config1.Equals(config2));
93 EXPECT_TRUE(config2.Equals(config1)); 96 EXPECT_TRUE(config2.Equals(config1));
94 } 97 }
95 98
96 TEST(ProxyConfigTest, ParseProxyRules) { 99 TEST(ProxyConfigTest, ParseProxyRules) {
97 const struct { 100 const struct {
98 const char* proxy_rules; 101 const char* proxy_rules;
99 102
100 net::ProxyConfig::ProxyRules::Type type; 103 ProxyConfig::ProxyRules::Type type;
101 const char* single_proxy; 104 const char* single_proxy;
102 const char* proxy_for_http; 105 const char* proxy_for_http;
103 const char* proxy_for_https; 106 const char* proxy_for_https;
104 const char* proxy_for_ftp; 107 const char* proxy_for_ftp;
105 const char* socks_proxy; 108 const char* socks_proxy;
106 } tests[] = { 109 } tests[] = {
107 // One HTTP proxy for all schemes. 110 // One HTTP proxy for all schemes.
108 { 111 {
109 "myproxy:80", 112 "myproxy:80",
110 113
111 net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 114 ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
112 "myproxy:80", 115 "myproxy:80",
113 NULL, 116 NULL,
114 NULL, 117 NULL,
115 NULL, 118 NULL,
116 NULL, 119 NULL,
117 }, 120 },
118 121
119 // Only specify a proxy server for "http://" urls. 122 // Only specify a proxy server for "http://" urls.
120 { 123 {
121 "http=myproxy:80", 124 "http=myproxy:80",
122 125
123 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 126 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
124 NULL, 127 NULL,
125 "myproxy:80", 128 "myproxy:80",
126 NULL, 129 NULL,
127 NULL, 130 NULL,
128 NULL, 131 NULL,
129 }, 132 },
130 133
131 // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://" urls. 134 // Specify an HTTP proxy for "ftp://" and a SOCKS proxy for "https://" urls.
132 { 135 {
133 "ftp=ftp-proxy ; https=socks4://foopy", 136 "ftp=ftp-proxy ; https=socks4://foopy",
134 137
135 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 138 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
136 NULL, 139 NULL,
137 NULL, 140 NULL,
138 "socks4://foopy:1080", 141 "socks4://foopy:1080",
139 "ftp-proxy:80", 142 "ftp-proxy:80",
140 NULL, 143 NULL,
141 }, 144 },
142 145
143 // Give a scheme-specific proxy as well as a non-scheme specific. 146 // Give a scheme-specific proxy as well as a non-scheme specific.
144 // The first entry "foopy" takes precedance marking this list as 147 // The first entry "foopy" takes precedance marking this list as
145 // TYPE_SINGLE_PROXY. 148 // TYPE_SINGLE_PROXY.
146 { 149 {
147 "foopy ; ftp=ftp-proxy", 150 "foopy ; ftp=ftp-proxy",
148 151
149 net::ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY, 152 ProxyConfig::ProxyRules::TYPE_SINGLE_PROXY,
150 "foopy:80", 153 "foopy:80",
151 NULL, 154 NULL,
152 NULL, 155 NULL,
153 NULL, 156 NULL,
154 NULL, 157 NULL,
155 }, 158 },
156 159
157 // Give a scheme-specific proxy as well as a non-scheme specific. 160 // Give a scheme-specific proxy as well as a non-scheme specific.
158 // The first entry "ftp=ftp-proxy" takes precedance marking this list as 161 // The first entry "ftp=ftp-proxy" takes precedance marking this list as
159 // TYPE_PROXY_PER_SCHEME. 162 // TYPE_PROXY_PER_SCHEME.
160 { 163 {
161 "ftp=ftp-proxy ; foopy", 164 "ftp=ftp-proxy ; foopy",
162 165
163 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 166 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
164 NULL, 167 NULL,
165 NULL, 168 NULL,
166 NULL, 169 NULL,
167 "ftp-proxy:80", 170 "ftp-proxy:80",
168 NULL, 171 NULL,
169 }, 172 },
170 173
171 // Include duplicate entries -- last one wins. 174 // Include duplicate entries -- last one wins.
172 { 175 {
173 "ftp=ftp1 ; ftp=ftp2 ; ftp=ftp3", 176 "ftp=ftp1 ; ftp=ftp2 ; ftp=ftp3",
174 177
175 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 178 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
176 NULL, 179 NULL,
177 NULL, 180 NULL,
178 NULL, 181 NULL,
179 "ftp3:80", 182 "ftp3:80",
180 NULL, 183 NULL,
181 }, 184 },
182 185
183 // Only SOCKS proxy present, others being blank. 186 // Only SOCKS proxy present, others being blank.
184 { 187 {
185 "socks=foopy", 188 "socks=foopy",
186 189
187 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 190 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
188 NULL, 191 NULL,
189 NULL, 192 NULL,
190 NULL, 193 NULL,
191 NULL, 194 NULL,
192 "socks4://foopy:1080", 195 "socks4://foopy:1080",
193 }, 196 },
194 197
195 // SOCKS proxy present along with other proxies too 198 // SOCKS proxy present along with other proxies too
196 { 199 {
197 "http=httpproxy ; https=httpsproxy ; ftp=ftpproxy ; socks=foopy ", 200 "http=httpproxy ; https=httpsproxy ; ftp=ftpproxy ; socks=foopy ",
198 201
199 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 202 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
200 NULL, 203 NULL,
201 "httpproxy:80", 204 "httpproxy:80",
202 "httpsproxy:80", 205 "httpsproxy:80",
203 "ftpproxy:80", 206 "ftpproxy:80",
204 "socks4://foopy:1080", 207 "socks4://foopy:1080",
205 }, 208 },
206 209
207 // SOCKS proxy (with modifier) present along with some proxies 210 // SOCKS proxy (with modifier) present along with some proxies
208 // (FTP being blank) 211 // (FTP being blank)
209 { 212 {
210 "http=httpproxy ; https=httpsproxy ; socks=socks5://foopy ", 213 "http=httpproxy ; https=httpsproxy ; socks=socks5://foopy ",
211 214
212 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 215 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
213 NULL, 216 NULL,
214 "httpproxy:80", 217 "httpproxy:80",
215 "httpsproxy:80", 218 "httpsproxy:80",
216 NULL, 219 NULL,
217 "socks5://foopy:1080", 220 "socks5://foopy:1080",
218 }, 221 },
219 222
220 // Include unsupported schemes -- they are discarded. 223 // Include unsupported schemes -- they are discarded.
221 { 224 {
222 "crazy=foopy ; foo=bar ; https=myhttpsproxy", 225 "crazy=foopy ; foo=bar ; https=myhttpsproxy",
223 226
224 net::ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME, 227 ProxyConfig::ProxyRules::TYPE_PROXY_PER_SCHEME,
225 NULL, 228 NULL,
226 NULL, 229 NULL,
227 "myhttpsproxy:80", 230 "myhttpsproxy:80",
228 NULL, 231 NULL,
229 NULL, 232 NULL,
230 }, 233 },
231 }; 234 };
232 235
233 net::ProxyConfig config; 236 ProxyConfig config;
234 237
235 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 238 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
236 config.proxy_rules.ParseFromString(tests[i].proxy_rules); 239 config.proxy_rules.ParseFromString(tests[i].proxy_rules);
237 240
238 EXPECT_EQ(tests[i].type, config.proxy_rules.type); 241 EXPECT_EQ(tests[i].type, config.proxy_rules.type);
239 ExpectProxyServerEquals(tests[i].single_proxy, 242 ExpectProxyServerEquals(tests[i].single_proxy,
240 config.proxy_rules.single_proxy); 243 config.proxy_rules.single_proxy);
241 ExpectProxyServerEquals(tests[i].proxy_for_http, 244 ExpectProxyServerEquals(tests[i].proxy_for_http,
242 config.proxy_rules.proxy_for_http); 245 config.proxy_rules.proxy_for_http);
243 ExpectProxyServerEquals(tests[i].proxy_for_https, 246 ExpectProxyServerEquals(tests[i].proxy_for_https,
(...skipping 22 matching lines...) Expand all
266 { 269 {
267 ".google.com, .foo.com:42", 270 ".google.com, .foo.com:42",
268 "*.google.com\n*.foo.com:42\n" 271 "*.google.com\n*.foo.com:42\n"
269 }, 272 },
270 { 273 {
271 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8", 274 ".google.com, foo.com:99, 1.2.3.4:22, 127.0.0.1/8",
272 "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n" 275 "*.google.com\n*foo.com:99\n1.2.3.4:22\n127.0.0.1/8\n"
273 } 276 }
274 }; 277 };
275 278
276 net::ProxyConfig config; 279 ProxyConfig config;
277 280
278 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) { 281 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(tests); ++i) {
279 config.ParseNoProxyList(tests[i].proxy_bypass_input); 282 config.ParseNoProxyList(tests[i].proxy_bypass_input);
280 EXPECT_EQ(tests[i].flattened_output, 283 EXPECT_EQ(tests[i].flattened_output,
281 net::FlattenProxyBypass(config.proxy_bypass)); 284 FlattenProxyBypass(config.proxy_bypass));
282 } 285 }
283 } 286 }
287
288 std::string ProxyConfigToString(const ProxyConfig& config) {
289 std::ostringstream stream;
290 stream << config;
291 return stream.str();
292 }
293
294 TEST(ProxyConfigTest, ToString) {
295 // Manual proxy.
296 {
297 ProxyConfig config;
298 config.auto_detect = false;
299 config.proxy_rules.ParseFromString("http://single-proxy:81");
300
301 EXPECT_EQ("Automatic settings:\n"
302 " Auto-detect: No\n"
303 " Custom PAC script: [None]\n"
304 "Manual settings:\n"
305 " Proxy server: single-proxy:81\n"
306 " Bypass list: [None]\n"
307 " Bypass local names: No",
308 ProxyConfigToString(config));
309 }
310
311 // Autodetect + custom PAC + manual proxy.
312 {
313 ProxyConfig config;
314 config.auto_detect = true;
315 config.pac_url = GURL("http://custom/pac.js");
316 config.proxy_rules.ParseFromString("http://single-proxy:81");
317
318 EXPECT_EQ("Automatic settings:\n"
319 " Auto-detect: Yes\n"
320 " Custom PAC script: http://custom/pac.js\n"
321 "Manual settings:\n"
322 " Proxy server: single-proxy:81\n"
323 " Bypass list: [None]\n"
324 " Bypass local names: No",
325 ProxyConfigToString(config));
326 }
327
328 // Manual proxy with bypass list + bypass local.
329 {
330 ProxyConfig config;
331 config.auto_detect = false;
332 config.proxy_rules.ParseFromString("http://single-proxy:81");
333 config.proxy_bypass.push_back("google.com");
334 config.proxy_bypass.push_back("bypass2.net:1730");
335 config.proxy_bypass_local_names = true;
336
337 EXPECT_EQ("Automatic settings:\n"
338 " Auto-detect: No\n"
339 " Custom PAC script: [None]\n"
340 "Manual settings:\n"
341 " Proxy server: single-proxy:81\n"
342 " Bypass list: \n"
343 " google.com\n"
344 " bypass2.net:1730\n"
345 " Bypass local names: Yes",
346 ProxyConfigToString(config));
347 }
348
349 // Proxy-per scheme (HTTP and HTTPS)
350 {
351 ProxyConfig config;
352 config.auto_detect = false;
353 config.proxy_rules.ParseFromString(
354 "http=proxy-for-http:1801; https=proxy-for-https:1802");
355
356 EXPECT_EQ("Automatic settings:\n"
357 " Auto-detect: No\n"
358 " Custom PAC script: [None]\n"
359 "Manual settings:\n"
360 " Proxy server: \n"
361 " HTTP: proxy-for-http:1801\n"
362 " HTTPS: proxy-for-https:1802\n"
363 " Bypass list: [None]\n"
364 " Bypass local names: No",
365 ProxyConfigToString(config));
366 }
367
368 // Proxy-per scheme (HTTP and SOCKS)
369 {
370 ProxyConfig config;
371 config.auto_detect = false;
372 config.proxy_rules.ParseFromString(
373 "http=http://proxy-for-http:1801; socks=socks-server:6083");
374
375 EXPECT_EQ("Automatic settings:\n"
376 " Auto-detect: No\n"
377 " Custom PAC script: [None]\n"
378 "Manual settings:\n"
379 " Proxy server: \n"
380 " HTTP: proxy-for-http:1801\n"
381 " SOCKS: socks4://socks-server:6083\n"
382 " Bypass list: [None]\n"
383 " Bypass local names: No",
384 ProxyConfigToString(config));
385 }
386
387 // No proxy.
388 {
389 ProxyConfig config;
390 config.auto_detect = false;
391
392 EXPECT_EQ("Automatic settings:\n"
393 " Auto-detect: No\n"
394 " Custom PAC script: [None]\n"
395 "Manual settings:\n"
396 " Proxy server: [None]\n"
397 " Bypass list: [None]\n"
398 " Bypass local names: No",
399 ProxyConfigToString(config));
400 }
401 }
402
403 } // namespace
404 } // namespace net
405
OLDNEW
« no previous file with comments | « net/proxy/proxy_config.cc ('k') | net/proxy/proxy_service.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698