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

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

Issue 552164: Merge 34903, 34928, 35008, 35549, 36054 to the 249s branch.... (Closed) Base URL: svn://chrome-svn/chrome/branches/249s/src/
Patch Set: Fix some other merge conflicts Created 10 years, 11 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_service.cc ('k') | net/socket/socks5_client_socket.h » ('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) 2006-2008 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2006-2008 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 <vector> 5 #include <vector>
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "googleurl/src/gurl.h" 9 #include "googleurl/src/gurl.h"
10 #include "net/base/load_log.h" 10 #include "net/base/load_log.h"
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 176
177 ASSERT_EQ(1u, resolver->pending_requests().size()); 177 ASSERT_EQ(1u, resolver->pending_requests().size());
178 // The URL should have been simplified, stripping the username/password/hash. 178 // The URL should have been simplified, stripping the username/password/hash.
179 EXPECT_EQ(GURL("http://www.google.com/?ref"), 179 EXPECT_EQ(GURL("http://www.google.com/?ref"),
180 resolver->pending_requests()[0]->url()); 180 resolver->pending_requests()[0]->url());
181 181
182 // We end here without ever completing the request -- destruction of 182 // We end here without ever completing the request -- destruction of
183 // ProxyService will cancel the outstanding request. 183 // ProxyService will cancel the outstanding request.
184 } 184 }
185 185
186 TEST(ProxyServiceTest, PAC_FailoverToDirect) { 186 TEST(ProxyServiceTest, PAC_FailoverWithoutDirect) {
187 MockProxyConfigService* config_service = 187 MockProxyConfigService* config_service =
188 new MockProxyConfigService("http://foopy/proxy.pac"); 188 new MockProxyConfigService("http://foopy/proxy.pac");
189 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 189 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
190 190
191 scoped_refptr<ProxyService> service( 191 scoped_refptr<ProxyService> service(
192 new ProxyService(config_service, resolver)); 192 new ProxyService(config_service, resolver));
193 193
194 GURL url("http://www.google.com/"); 194 GURL url("http://www.google.com/");
195 195
196 ProxyInfo info; 196 ProxyInfo info;
197 TestCompletionCallback callback1; 197 TestCompletionCallback callback1;
198 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 198 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
199 EXPECT_EQ(ERR_IO_PENDING, rv); 199 EXPECT_EQ(ERR_IO_PENDING, rv);
200 200
201 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 201 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
202 resolver->pending_set_pac_script_request()->pac_url()); 202 resolver->pending_set_pac_script_request()->pac_url());
203 resolver->pending_set_pac_script_request()->CompleteNow(OK); 203 resolver->pending_set_pac_script_request()->CompleteNow(OK);
204 204
205 ASSERT_EQ(1u, resolver->pending_requests().size()); 205 ASSERT_EQ(1u, resolver->pending_requests().size());
206 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 206 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
207 207
208 // Set the result in proxy resolver. 208 // Set the result in proxy resolver.
209 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); 209 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy:8080");
210 resolver->pending_requests()[0]->CompleteNow(OK); 210 resolver->pending_requests()[0]->CompleteNow(OK);
211 211
212 EXPECT_EQ(OK, callback1.WaitForResult()); 212 EXPECT_EQ(OK, callback1.WaitForResult());
213 EXPECT_FALSE(info.is_direct()); 213 EXPECT_FALSE(info.is_direct());
214 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); 214 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI());
215 215
216 // Now, imagine that connecting to foopy:8080 fails. 216 // Now, imagine that connecting to foopy:8080 fails: there is nothing
217 // left to fallback to, since our proxy list was NOT terminated by
218 // DIRECT.
219 TestCompletionCallback callback2;
220 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL);
221 // ReconsiderProxyAfterError returns error indicating nothing left.
222 EXPECT_EQ(ERR_FAILED, rv);
223 EXPECT_TRUE(info.is_empty());
224 }
225
226 // The proxy list could potentially contain the DIRECT fallback choice
227 // in a location other than the very end of the list, and could even
228 // specify it multiple times.
229 //
230 // This is not a typical usage, but we will obey it.
231 // (If we wanted to disallow this type of input, the right place to
232 // enforce it would be in parsing the PAC result string).
233 //
234 // This test will use the PAC result string:
235 //
236 // "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"
237 //
238 // For which we expect it to try DIRECT, then foobar:10, then DIRECT again,
239 // then foobar:20, and then give up and error.
240 //
241 // The important check of this test is to make sure that DIRECT is not somehow
242 // cached as being a bad proxy.
243 TEST(ProxyServiceTest, PAC_FailoverAfterDirect) {
244 MockProxyConfigService* config_service =
245 new MockProxyConfigService("http://foopy/proxy.pac");
246 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
247
248 scoped_refptr<ProxyService> service(
249 new ProxyService(config_service, resolver));
250
251 GURL url("http://www.google.com/");
252
253 ProxyInfo info;
254 TestCompletionCallback callback1;
255 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
256 EXPECT_EQ(ERR_IO_PENDING, rv);
257
258 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
259 resolver->pending_set_pac_script_request()->pac_url());
260 resolver->pending_set_pac_script_request()->CompleteNow(OK);
261
262 ASSERT_EQ(1u, resolver->pending_requests().size());
263 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
264
265 // Set the result in proxy resolver.
266 resolver->pending_requests()[0]->results()->UsePacString(
267 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20");
268 resolver->pending_requests()[0]->CompleteNow(OK);
269
270 EXPECT_EQ(OK, callback1.WaitForResult());
271 EXPECT_TRUE(info.is_direct());
272
273 // Fallback 1.
217 TestCompletionCallback callback2; 274 TestCompletionCallback callback2;
218 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL); 275 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL);
219 EXPECT_EQ(OK, rv); 276 EXPECT_EQ(OK, rv);
277 EXPECT_FALSE(info.is_direct());
278 EXPECT_EQ("foobar:10", info.proxy_server().ToURI());
279
280 // Fallback 2.
281 TestCompletionCallback callback3;
282 rv = service->ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL);
283 EXPECT_EQ(OK, rv);
220 EXPECT_TRUE(info.is_direct()); 284 EXPECT_TRUE(info.is_direct());
285
286 // Fallback 3.
287 TestCompletionCallback callback4;
288 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL);
289 EXPECT_EQ(OK, rv);
290 EXPECT_FALSE(info.is_direct());
291 EXPECT_EQ("foobar:20", info.proxy_server().ToURI());
292
293 // Fallback 4 -- Nothing to fall back to!
294 TestCompletionCallback callback5;
295 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL);
296 EXPECT_EQ(ERR_FAILED, rv);
297 EXPECT_TRUE(info.is_empty());
221 } 298 }
222 299
223 TEST(ProxyServiceTest, ProxyResolverFails) { 300 TEST(ProxyServiceTest, ProxyResolverFails) {
224 // Test what happens when the ProxyResolver fails (this could represent 301 // Test what happens when the ProxyResolver fails. The download and setting
225 // a failure to download the PAC script in the case of ProxyResolvers which 302 // of the PAC script have already succeeded, so this corresponds with a
226 // do the fetch internally.) 303 // javascript runtime error while calling FindProxyForURL().
227 // TODO(eroman): change this comment.
228 304
229 MockProxyConfigService* config_service = 305 MockProxyConfigService* config_service =
230 new MockProxyConfigService("http://foopy/proxy.pac"); 306 new MockProxyConfigService("http://foopy/proxy.pac");
231 307
232 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 308 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
233 309
234 scoped_refptr<ProxyService> service( 310 scoped_refptr<ProxyService> service(
235 new ProxyService(config_service, resolver)); 311 new ProxyService(config_service, resolver));
236 312
237 // Start first resolve request. 313 // Start first resolve request.
238 GURL url("http://www.google.com/"); 314 GURL url("http://www.google.com/");
239 ProxyInfo info; 315 ProxyInfo info;
240 TestCompletionCallback callback1; 316 TestCompletionCallback callback1;
241 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL); 317 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
242 EXPECT_EQ(ERR_IO_PENDING, rv); 318 EXPECT_EQ(ERR_IO_PENDING, rv);
243 319
244 EXPECT_EQ(GURL("http://foopy/proxy.pac"), 320 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
245 resolver->pending_set_pac_script_request()->pac_url()); 321 resolver->pending_set_pac_script_request()->pac_url());
246 resolver->pending_set_pac_script_request()->CompleteNow(OK); 322 resolver->pending_set_pac_script_request()->CompleteNow(OK);
247 323
248 ASSERT_EQ(1u, resolver->pending_requests().size()); 324 ASSERT_EQ(1u, resolver->pending_requests().size());
249 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 325 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
250 326
251 // Fail the first resolve request in MockAsyncProxyResolver. 327 // Fail the first resolve request in MockAsyncProxyResolver.
252 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); 328 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED);
253 329
254 EXPECT_EQ(ERR_FAILED, callback1.WaitForResult()); 330 EXPECT_EQ(ERR_FAILED, callback1.WaitForResult());
255 331
256 // The second resolve request will automatically select direct connect, 332 // The second resolve request will try to run through the proxy resolver,
257 // because it has cached the configuration as being bad. 333 // regardless of whether the first request failed in it.
258 TestCompletionCallback callback2; 334 TestCompletionCallback callback2;
259 rv = service->ResolveProxy(url, &info, &callback2, NULL, NULL); 335 rv = service->ResolveProxy(url, &info, &callback2, NULL, NULL);
260 EXPECT_EQ(OK, rv);
261 EXPECT_TRUE(info.is_direct());
262 EXPECT_TRUE(resolver->pending_requests().empty());
263
264 // But, if that fails, then we should give the proxy config another shot
265 // since we have never tried it with this URL before.
266 TestCompletionCallback callback3;
267 rv = service->ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL);
268 EXPECT_EQ(ERR_IO_PENDING, rv); 336 EXPECT_EQ(ERR_IO_PENDING, rv);
269 337
270 ASSERT_EQ(1u, resolver->pending_requests().size()); 338 ASSERT_EQ(1u, resolver->pending_requests().size());
271 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 339 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
272 340
273 // Set the result in proxy resolver. 341 // This time we will have the resolver succeed (perhaps the PAC script has
342 // a dependency on the current time).
274 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); 343 resolver->pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080");
275 resolver->pending_requests()[0]->CompleteNow(OK); 344 resolver->pending_requests()[0]->CompleteNow(OK);
276 345
277 EXPECT_EQ(OK, callback3.WaitForResult()); 346 EXPECT_EQ(OK, callback2.WaitForResult());
278 EXPECT_FALSE(info.is_direct()); 347 EXPECT_FALSE(info.is_direct());
279 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); 348 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI());
280 } 349 }
281 350
282 TEST(ProxyServiceTest, ProxyFallback) { 351 TEST(ProxyServiceTest, ProxyFallback) {
283 // Test what happens when we specify multiple proxy servers and some of them 352 // Test what happens when we specify multiple proxy servers and some of them
284 // are bad. 353 // are bad.
285 354
286 MockProxyConfigService* config_service = 355 MockProxyConfigService* config_service =
287 new MockProxyConfigService("http://foopy/proxy.pac"); 356 new MockProxyConfigService("http://foopy/proxy.pac");
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 394 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
326 395
327 TestCompletionCallback callback3; 396 TestCompletionCallback callback3;
328 rv = service->ResolveProxy(url, &info, &callback3, NULL, NULL); 397 rv = service->ResolveProxy(url, &info, &callback3, NULL, NULL);
329 EXPECT_EQ(ERR_IO_PENDING, rv); 398 EXPECT_EQ(ERR_IO_PENDING, rv);
330 399
331 ASSERT_EQ(1u, resolver->pending_requests().size()); 400 ASSERT_EQ(1u, resolver->pending_requests().size());
332 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 401 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
333 402
334 // Set the result in proxy resolver -- the second result is already known 403 // Set the result in proxy resolver -- the second result is already known
335 // to be bad. 404 // to be bad, so we will not try to use it initially.
336 resolver->pending_requests()[0]->results()->UseNamedProxy( 405 resolver->pending_requests()[0]->results()->UseNamedProxy(
337 "foopy3:7070;foopy1:8080;foopy2:9090"); 406 "foopy3:7070;foopy1:8080;foopy2:9090");
338 resolver->pending_requests()[0]->CompleteNow(OK); 407 resolver->pending_requests()[0]->CompleteNow(OK);
339 408
340 EXPECT_EQ(OK, callback3.WaitForResult()); 409 EXPECT_EQ(OK, callback3.WaitForResult());
341 EXPECT_FALSE(info.is_direct()); 410 EXPECT_FALSE(info.is_direct());
342 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); 411 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI());
343 412
344 // We fake another error. It should now try the third one. 413 // We fake another error. It should now try the third one.
345 TestCompletionCallback callback4; 414 TestCompletionCallback callback4;
346 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL); 415 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL);
347 EXPECT_EQ(OK, rv); 416 EXPECT_EQ(OK, rv);
348 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); 417 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
349 418
350 // Fake another error, the last proxy is gone, the list should now be empty. 419 // We fake another error. At this point we have tried all of the
420 // proxy servers we thought were valid; next we try the proxy server
421 // that was in our bad proxies map (foopy1:8080).
351 TestCompletionCallback callback5; 422 TestCompletionCallback callback5;
352 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL); 423 rv = service->ReconsiderProxyAfterError(url, &info, &callback5, NULL, NULL);
353 EXPECT_EQ(OK, rv); // We try direct. 424 EXPECT_EQ(OK, rv);
354 EXPECT_TRUE(info.is_direct()); 425 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
355 426
356 // If it fails again, we don't have anything else to try. 427 // Fake another error, the last proxy is gone, the list should now be empty,
428 // so there is nothing left to try.
357 TestCompletionCallback callback6; 429 TestCompletionCallback callback6;
358 rv = service->ReconsiderProxyAfterError(url, &info, &callback6, NULL, NULL); 430 rv = service->ReconsiderProxyAfterError(url, &info, &callback6, NULL, NULL);
359 EXPECT_EQ(ERR_FAILED, rv); 431 EXPECT_EQ(ERR_FAILED, rv);
432 EXPECT_FALSE(info.is_direct());
433 EXPECT_TRUE(info.is_empty());
360 434
361 // TODO(nsylvain): Test that the proxy can be retried after the delay. 435 // TODO(nsylvain): Test that the proxy can be retried after the delay.
362 } 436 }
363 437
438 // This test is similar to ProxyFallback, but this time we have an explicit
439 // fallback choice to DIRECT.
440 TEST(ProxyServiceTest, ProxyFallbackToDirect) {
441 MockProxyConfigService* config_service =
442 new MockProxyConfigService("http://foopy/proxy.pac");
443
444 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
445
446 scoped_refptr<ProxyService> service(
447 new ProxyService(config_service, resolver));
448
449 GURL url("http://www.google.com/");
450
451 // Get the proxy information.
452 ProxyInfo info;
453 TestCompletionCallback callback1;
454 int rv = service->ResolveProxy(url, &info, &callback1, NULL, NULL);
455 EXPECT_EQ(ERR_IO_PENDING, rv);
456
457 EXPECT_EQ(GURL("http://foopy/proxy.pac"),
458 resolver->pending_set_pac_script_request()->pac_url());
459 resolver->pending_set_pac_script_request()->CompleteNow(OK);
460
461 ASSERT_EQ(1u, resolver->pending_requests().size());
462 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
463
464 // Set the result in proxy resolver.
465 resolver->pending_requests()[0]->results()->UsePacString(
466 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT");
467 resolver->pending_requests()[0]->CompleteNow(OK);
468
469 // Get the first result.
470 EXPECT_EQ(OK, callback1.WaitForResult());
471 EXPECT_FALSE(info.is_direct());
472 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI());
473
474 // Fake an error on the proxy.
475 TestCompletionCallback callback2;
476 rv = service->ReconsiderProxyAfterError(url, &info, &callback2, NULL, NULL);
477 EXPECT_EQ(OK, rv);
478
479 // Now we get back the second proxy.
480 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI());
481
482 // Fake an error on this proxy as well.
483 TestCompletionCallback callback3;
484 rv = service->ReconsiderProxyAfterError(url, &info, &callback3, NULL, NULL);
485 EXPECT_EQ(OK, rv);
486
487 // Finally, we get back DIRECT.
488 EXPECT_TRUE(info.is_direct());
489
490 // Now we tell the proxy service that even DIRECT failed.
491 TestCompletionCallback callback4;
492 rv = service->ReconsiderProxyAfterError(url, &info, &callback4, NULL, NULL);
493 // There was nothing left to try after DIRECT, so we are out of
494 // choices.
495 EXPECT_EQ(ERR_FAILED, rv);
496 }
497
364 TEST(ProxyServiceTest, ProxyFallback_NewSettings) { 498 TEST(ProxyServiceTest, ProxyFallback_NewSettings) {
365 // Test proxy failover when new settings are available. 499 // Test proxy failover when new settings are available.
366 500
367 MockProxyConfigService* config_service = 501 MockProxyConfigService* config_service =
368 new MockProxyConfigService("http://foopy/proxy.pac"); 502 new MockProxyConfigService("http://foopy/proxy.pac");
369 503
370 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver; 504 MockAsyncProxyResolver* resolver = new MockAsyncProxyResolver;
371 505
372 scoped_refptr<ProxyService> service( 506 scoped_refptr<ProxyService> service(
373 new ProxyService(config_service, resolver)); 507 new ProxyService(config_service, resolver));
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
495 629
496 // Fake a PAC failure. 630 // Fake a PAC failure.
497 ProxyInfo info2; 631 ProxyInfo info2;
498 TestCompletionCallback callback3; 632 TestCompletionCallback callback3;
499 rv = service->ResolveProxy(url, &info2, &callback3, NULL, NULL); 633 rv = service->ResolveProxy(url, &info2, &callback3, NULL, NULL);
500 EXPECT_EQ(ERR_IO_PENDING, rv); 634 EXPECT_EQ(ERR_IO_PENDING, rv);
501 635
502 ASSERT_EQ(1u, resolver->pending_requests().size()); 636 ASSERT_EQ(1u, resolver->pending_requests().size());
503 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 637 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
504 638
639 // This simulates a javascript runtime error in the PAC script.
505 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED); 640 resolver->pending_requests()[0]->CompleteNow(ERR_FAILED);
506 641
507 // No proxy servers are returned. It's a direct connection. 642 // No proxy servers are returned, since we failed.
508 EXPECT_EQ(ERR_FAILED, callback3.WaitForResult()); 643 EXPECT_EQ(ERR_FAILED, callback3.WaitForResult());
509 EXPECT_TRUE(info2.is_direct()); 644 EXPECT_FALSE(info2.is_direct());
645 EXPECT_TRUE(info2.is_empty());
510 646
511 // The PAC will now be fixed and will return a proxy server. 647 // The PAC script will work properly next time and successfully return a
512 // It should also clear the list of bad proxies. 648 // proxy list. Since we have not marked the configuration as bad, it should
513 649 // "just work" the next time we call it.
514 // Try to resolve, it will still return "direct" because we have no reason
515 // to check the config since everything works.
516 ProxyInfo info3; 650 ProxyInfo info3;
517 TestCompletionCallback callback4; 651 TestCompletionCallback callback4;
518 rv = service->ResolveProxy(url, &info3, &callback4, NULL, NULL); 652 rv = service->ReconsiderProxyAfterError(url, &info3, &callback4, NULL, NULL);
519 EXPECT_EQ(OK, rv);
520 EXPECT_TRUE(info3.is_direct());
521
522 // But if the direct connection fails, we check if the ProxyInfo tried to
523 // resolve the proxy before, and if not (like in this case), we give the
524 // PAC another try.
525 TestCompletionCallback callback5;
526 rv = service->ReconsiderProxyAfterError(url, &info3, &callback5, NULL, NULL);
527 EXPECT_EQ(ERR_IO_PENDING, rv); 653 EXPECT_EQ(ERR_IO_PENDING, rv);
528 654
529 ASSERT_EQ(1u, resolver->pending_requests().size()); 655 ASSERT_EQ(1u, resolver->pending_requests().size());
530 EXPECT_EQ(url, resolver->pending_requests()[0]->url()); 656 EXPECT_EQ(url, resolver->pending_requests()[0]->url());
531 657
532 resolver->pending_requests()[0]->results()->UseNamedProxy( 658 resolver->pending_requests()[0]->results()->UseNamedProxy(
533 "foopy1:8080;foopy2:9090"); 659 "foopy1:8080;foopy2:9090");
534 resolver->pending_requests()[0]->CompleteNow(OK); 660 resolver->pending_requests()[0]->CompleteNow(OK);
535 661
536 // The first proxy is still there since the list of bad proxies got cleared. 662 // The first proxy is not there since the it was added to the bad proxies
537 EXPECT_EQ(OK, callback5.WaitForResult()); 663 // list by the earlier ReconsiderProxyAfterError().
664 EXPECT_EQ(OK, callback4.WaitForResult());
538 EXPECT_FALSE(info3.is_direct()); 665 EXPECT_FALSE(info3.is_direct());
539 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); 666 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI());
540 } 667 }
541 668
542 TEST(ProxyServiceTest, ProxyBypassList) { 669 TEST(ProxyServiceTest, ProxyBypassList) {
543 // Test what happens when a proxy bypass list is specified. 670 // Test what happens when a proxy bypass list is specified.
544 671
545 ProxyInfo info; 672 ProxyInfo info;
546 ProxyConfig config; 673 ProxyConfig config;
547 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090"); 674 config.proxy_rules.ParseFromString("foopy1:8080;foopy2:9090");
(...skipping 972 matching lines...) Expand 10 before | Expand all | Expand 10 after
1520 ProxyInfo info2; 1647 ProxyInfo info2;
1521 TestCompletionCallback callback2; 1648 TestCompletionCallback callback2;
1522 rv = service->ResolveProxy( 1649 rv = service->ResolveProxy(
1523 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL); 1650 GURL("http://www.google.com"), &info2, &callback2, NULL, NULL);
1524 EXPECT_EQ(OK, rv); 1651 EXPECT_EQ(OK, rv);
1525 1652
1526 EXPECT_TRUE(info2.is_direct()); 1653 EXPECT_TRUE(info2.is_direct());
1527 } 1654 }
1528 1655
1529 } // namespace net 1656 } // namespace net
OLDNEW
« no previous file with comments | « net/proxy/proxy_service.cc ('k') | net/socket/socks5_client_socket.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698