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_service.h" | 5 #include "net/proxy/proxy_service.h" |
6 | 6 |
7 #include <cstdarg> | 7 #include <cstdarg> |
8 #include <vector> | 8 #include <vector> |
9 | 9 |
10 #include "base/format_macros.h" | 10 #include "base/format_macros.h" |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 int proxy_fallback_net_error() const { | 267 int proxy_fallback_net_error() const { |
268 return proxy_fallback_net_error_; | 268 return proxy_fallback_net_error_; |
269 } | 269 } |
270 | 270 |
271 private: | 271 private: |
272 bool on_proxy_fallback_called_; | 272 bool on_proxy_fallback_called_; |
273 ProxyServer proxy_server_; | 273 ProxyServer proxy_server_; |
274 int proxy_fallback_net_error_; | 274 int proxy_fallback_net_error_; |
275 }; | 275 }; |
276 | 276 |
277 using JobMap = std::map<GURL, MockAsyncProxyResolver::Job*>; | 277 using RequestMap = |
| 278 std::map<GURL, scoped_refptr<MockAsyncProxyResolver::Request>>; |
278 | 279 |
279 // Given a jobmap and a list of target URLs |urls|, asserts that the set of URLs | 280 // Given a list of requests |list| from a MockAsyncProxyResolver and a list of |
280 // of the jobs appearing in |list| is exactly the set of URLs in |urls|. | 281 // target URLs |_urls|, asserts that the set of URLs of the requests appearing |
281 JobMap GetJobsForURLs(const JobMap& map, const std::vector<GURL>& urls) { | 282 // in |list| is exactly the set of URLs in |_urls|, and produces a RequestMap in |
282 size_t a = urls.size(); | 283 // |*map| containing the requests corresponding to those target |_urls|. |
283 size_t b = map.size(); | 284 // |
284 if (a != b) { | 285 // Note that this function must return void to allow use of gtest's ASSERT_* |
| 286 // macros inside it. |
| 287 RequestMap GetRequestsForURLs( |
| 288 const MockAsyncProxyResolver::RequestsList& requests, |
| 289 const std::vector<GURL>& urls) { |
| 290 RequestMap map; |
| 291 |
| 292 for (const auto& it : requests) |
| 293 map[it->url()] = it; |
| 294 |
| 295 if (urls.size() != map.size()) { |
285 ADD_FAILURE() << "map size (" << map.size() << ") != urls size (" | 296 ADD_FAILURE() << "map size (" << map.size() << ") != urls size (" |
286 << urls.size() << ")"; | 297 << urls.size() << ")"; |
287 return map; | 298 return map; |
288 } | 299 } |
289 for (const auto& it : urls) { | 300 for (const auto& it : urls) { |
290 if (map.count(it) != 1U) { | 301 if (map.count(it) != 1U) { |
291 ADD_FAILURE() << "url not in map: " << it.spec(); | 302 ADD_FAILURE() << "url not in map: " << it.spec(); |
292 break; | 303 break; |
293 } | 304 } |
294 } | 305 } |
295 return map; | 306 return map; |
296 } | 307 } |
297 | 308 |
298 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the | 309 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the |
299 // set of pending request URLs for |resolver| is exactly the supplied list of | 310 // set of pending request URLs for |resolver| is exactly the supplied list of |
300 // URLs and returns a map from URLs to the corresponding pending jobs. | 311 // URLs and returns a map from URLs to the corresponding pending requests. |
301 JobMap GetPendingJobsForURLs(const MockAsyncProxyResolver& resolver, | 312 RequestMap GetPendingRequestsForURLs(const MockAsyncProxyResolver& resolver, |
302 const GURL& url1 = GURL(), | 313 const GURL& url1 = GURL(), |
303 const GURL& url2 = GURL(), | 314 const GURL& url2 = GURL(), |
304 const GURL& url3 = GURL()) { | 315 const GURL& url3 = GURL()) { |
305 std::vector<GURL> urls; | 316 std::vector<GURL> urls; |
306 if (!url1.is_empty()) | 317 if (!url1.is_empty()) |
307 urls.push_back(url1); | 318 urls.push_back(url1); |
308 if (!url2.is_empty()) | 319 if (!url2.is_empty()) |
309 urls.push_back(url2); | 320 urls.push_back(url2); |
310 if (!url3.is_empty()) | 321 if (!url3.is_empty()) |
311 urls.push_back(url3); | 322 urls.push_back(url3); |
312 | 323 return GetRequestsForURLs(resolver.pending_requests(), urls); |
313 JobMap map; | |
314 for (MockAsyncProxyResolver::Job* it : resolver.pending_jobs()) { | |
315 DCHECK(it); | |
316 map[it->url()] = it; | |
317 } | |
318 | |
319 return GetJobsForURLs(map, urls); | |
320 } | 324 } |
321 | 325 |
322 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the | 326 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the |
323 // set of cancelled request URLs for |resolver| is exactly the supplied list of | 327 // set of cancelled request URLs for |resolver| is exactly the supplied list of |
324 // URLs and returns a map from URLs to the corresponding cancelled jobs. | 328 // URLs and returns a map from URLs to the corresponding cancelled requests. |
325 JobMap GetCancelledJobsForURLs(const MockAsyncProxyResolver& resolver, | 329 RequestMap GetCancelledRequestsForURLs(const MockAsyncProxyResolver& resolver, |
326 const GURL& url1 = GURL(), | 330 const GURL& url1 = GURL(), |
327 const GURL& url2 = GURL(), | 331 const GURL& url2 = GURL(), |
328 const GURL& url3 = GURL()) { | 332 const GURL& url3 = GURL()) { |
329 std::vector<GURL> urls; | 333 std::vector<GURL> urls; |
330 if (!url1.is_empty()) | 334 if (!url1.is_empty()) |
331 urls.push_back(url1); | 335 urls.push_back(url1); |
332 if (!url2.is_empty()) | 336 if (!url2.is_empty()) |
333 urls.push_back(url2); | 337 urls.push_back(url2); |
334 if (!url3.is_empty()) | 338 if (!url3.is_empty()) |
335 urls.push_back(url3); | 339 urls.push_back(url3); |
336 | 340 return GetRequestsForURLs(resolver.cancelled_requests(), urls); |
337 JobMap map; | |
338 for (const scoped_ptr<MockAsyncProxyResolver::Job>& it : | |
339 resolver.cancelled_jobs()) { | |
340 DCHECK(it); | |
341 map[it->url()] = it.get(); | |
342 } | |
343 | |
344 return GetJobsForURLs(map, urls); | |
345 } | 341 } |
346 | 342 |
347 } // namespace | 343 } // namespace |
348 | 344 |
349 TEST_F(ProxyServiceTest, Direct) { | 345 TEST_F(ProxyServiceTest, Direct) { |
350 MockAsyncProxyResolverFactory* factory = | 346 MockAsyncProxyResolverFactory* factory = |
351 new MockAsyncProxyResolverFactory(false); | 347 new MockAsyncProxyResolverFactory(false); |
352 ProxyService service( | 348 ProxyService service( |
353 make_scoped_ptr(new MockProxyConfigService(ProxyConfig::CreateDirect())), | 349 make_scoped_ptr(new MockProxyConfigService(ProxyConfig::CreateDirect())), |
354 make_scoped_ptr(factory), NULL); | 350 make_scoped_ptr(factory), NULL); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
404 | 400 |
405 // Verify that network delegate is invoked. | 401 // Verify that network delegate is invoked. |
406 TestResolveProxyDelegate delegate; | 402 TestResolveProxyDelegate delegate; |
407 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), NULL, | 403 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), NULL, |
408 &delegate, log.bound()); | 404 &delegate, log.bound()); |
409 EXPECT_TRUE(delegate.on_resolve_proxy_called()); | 405 EXPECT_TRUE(delegate.on_resolve_proxy_called()); |
410 EXPECT_EQ(&service, delegate.proxy_service()); | 406 EXPECT_EQ(&service, delegate.proxy_service()); |
411 | 407 |
412 // Verify that the ProxyDelegate's behavior is stateless across | 408 // Verify that the ProxyDelegate's behavior is stateless across |
413 // invocations of ResolveProxy. Start by having the callback add a proxy | 409 // invocations of ResolveProxy. Start by having the callback add a proxy |
414 // and checking that subsequent jobs are not affected. | 410 // and checking that subsequent requests are not affected. |
415 delegate.set_add_proxy(true); | 411 delegate.set_add_proxy(true); |
416 | 412 |
417 // Callback should interpose: | 413 // Callback should interpose: |
418 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), NULL, | 414 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), NULL, |
419 &delegate, log.bound()); | 415 &delegate, log.bound()); |
420 EXPECT_FALSE(info.is_direct()); | 416 EXPECT_FALSE(info.is_direct()); |
421 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); | 417 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); |
422 delegate.set_add_proxy(false); | 418 delegate.set_add_proxy(false); |
423 | 419 |
424 // Check non-bypassed URL: | 420 // Check non-bypassed URL: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
500 &request, NULL, log.bound()); | 496 &request, NULL, log.bound()); |
501 EXPECT_EQ(ERR_IO_PENDING, rv); | 497 EXPECT_EQ(ERR_IO_PENDING, rv); |
502 | 498 |
503 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 499 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
504 | 500 |
505 ASSERT_EQ(1u, factory->pending_requests().size()); | 501 ASSERT_EQ(1u, factory->pending_requests().size()); |
506 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 502 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
507 factory->pending_requests()[0]->script_data()->url()); | 503 factory->pending_requests()[0]->script_data()->url()); |
508 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 504 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
509 | 505 |
510 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 506 ASSERT_EQ(1u, resolver.pending_requests().size()); |
511 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 507 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
512 | 508 |
513 // Set the result in proxy resolver. | 509 // Set the result in proxy resolver. |
514 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy"); | 510 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); |
515 resolver.pending_jobs()[0]->CompleteNow(OK); | 511 resolver.pending_requests()[0]->CompleteNow(OK); |
516 | 512 |
517 EXPECT_EQ(OK, callback.WaitForResult()); | 513 EXPECT_EQ(OK, callback.WaitForResult()); |
518 EXPECT_FALSE(info.is_direct()); | 514 EXPECT_FALSE(info.is_direct()); |
519 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); | 515 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); |
520 EXPECT_TRUE(info.did_use_pac_script()); | 516 EXPECT_TRUE(info.did_use_pac_script()); |
521 | 517 |
522 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 518 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
523 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 519 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
524 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 520 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
525 | 521 |
(...skipping 30 matching lines...) Expand all Loading... |
556 ProxyInfo info; | 552 ProxyInfo info; |
557 TestCompletionCallback callback; | 553 TestCompletionCallback callback; |
558 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 554 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
559 NULL, NULL, BoundNetLog()); | 555 NULL, NULL, BoundNetLog()); |
560 EXPECT_EQ(ERR_IO_PENDING, rv); | 556 EXPECT_EQ(ERR_IO_PENDING, rv); |
561 | 557 |
562 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 558 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
563 factory->pending_requests()[0]->script_data()->url()); | 559 factory->pending_requests()[0]->script_data()->url()); |
564 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 560 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
565 | 561 |
566 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 562 ASSERT_EQ(1u, resolver.pending_requests().size()); |
567 // The URL should have been simplified, stripping the username/password/hash. | 563 // The URL should have been simplified, stripping the username/password/hash. |
568 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 564 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
569 resolver.pending_jobs()[0]->url()); | 565 resolver.pending_requests()[0]->url()); |
570 | 566 |
571 // We end here without ever completing the request -- destruction of | 567 // We end here without ever completing the request -- destruction of |
572 // ProxyService will cancel the outstanding request. | 568 // ProxyService will cancel the outstanding request. |
573 } | 569 } |
574 | 570 |
575 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 571 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
576 MockProxyConfigService* config_service = | 572 MockProxyConfigService* config_service = |
577 new MockProxyConfigService("http://foopy/proxy.pac"); | 573 new MockProxyConfigService("http://foopy/proxy.pac"); |
578 MockAsyncProxyResolver resolver; | 574 MockAsyncProxyResolver resolver; |
579 MockAsyncProxyResolverFactory* factory = | 575 MockAsyncProxyResolverFactory* factory = |
580 new MockAsyncProxyResolverFactory(false); | 576 new MockAsyncProxyResolverFactory(false); |
581 | 577 |
582 ProxyService service(make_scoped_ptr(config_service), | 578 ProxyService service(make_scoped_ptr(config_service), |
583 make_scoped_ptr(factory), NULL); | 579 make_scoped_ptr(factory), NULL); |
584 | 580 |
585 GURL url("http://www.google.com/"); | 581 GURL url("http://www.google.com/"); |
586 | 582 |
587 ProxyInfo info; | 583 ProxyInfo info; |
588 TestCompletionCallback callback1; | 584 TestCompletionCallback callback1; |
589 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 585 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
590 NULL, NULL, BoundNetLog()); | 586 NULL, NULL, BoundNetLog()); |
591 EXPECT_EQ(ERR_IO_PENDING, rv); | 587 EXPECT_EQ(ERR_IO_PENDING, rv); |
592 | 588 |
593 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 589 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
594 factory->pending_requests()[0]->script_data()->url()); | 590 factory->pending_requests()[0]->script_data()->url()); |
595 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 591 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
596 | 592 |
597 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 593 ASSERT_EQ(1u, resolver.pending_requests().size()); |
598 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 594 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
599 | 595 |
600 // Set the result in proxy resolver. | 596 // Set the result in proxy resolver. |
601 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy:8080"); | 597 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
602 resolver.pending_jobs()[0]->CompleteNow(OK); | 598 resolver.pending_requests()[0]->CompleteNow(OK); |
603 | 599 |
604 EXPECT_EQ(OK, callback1.WaitForResult()); | 600 EXPECT_EQ(OK, callback1.WaitForResult()); |
605 EXPECT_FALSE(info.is_direct()); | 601 EXPECT_FALSE(info.is_direct()); |
606 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 602 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
607 EXPECT_TRUE(info.did_use_pac_script()); | 603 EXPECT_TRUE(info.did_use_pac_script()); |
608 | 604 |
609 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 605 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
610 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 606 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
611 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 607 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
612 | 608 |
(...skipping 28 matching lines...) Expand all Loading... |
641 ProxyInfo info; | 637 ProxyInfo info; |
642 TestCompletionCallback callback1; | 638 TestCompletionCallback callback1; |
643 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 639 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
644 NULL, NULL, BoundNetLog()); | 640 NULL, NULL, BoundNetLog()); |
645 EXPECT_EQ(ERR_IO_PENDING, rv); | 641 EXPECT_EQ(ERR_IO_PENDING, rv); |
646 | 642 |
647 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 643 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
648 factory->pending_requests()[0]->script_data()->url()); | 644 factory->pending_requests()[0]->script_data()->url()); |
649 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 645 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
650 | 646 |
651 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 647 ASSERT_EQ(1u, resolver.pending_requests().size()); |
652 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 648 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
653 | 649 |
654 // Simulate a failure in the PAC executor. | 650 // Simulate a failure in the PAC executor. |
655 resolver.pending_jobs()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); | 651 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); |
656 | 652 |
657 EXPECT_EQ(OK, callback1.WaitForResult()); | 653 EXPECT_EQ(OK, callback1.WaitForResult()); |
658 | 654 |
659 // Since the PAC script was non-mandatory, we should have fallen-back to | 655 // Since the PAC script was non-mandatory, we should have fallen-back to |
660 // DIRECT. | 656 // DIRECT. |
661 EXPECT_TRUE(info.is_direct()); | 657 EXPECT_TRUE(info.is_direct()); |
662 EXPECT_TRUE(info.did_use_pac_script()); | 658 EXPECT_TRUE(info.did_use_pac_script()); |
663 EXPECT_EQ(1, info.config_id()); | 659 EXPECT_EQ(1, info.config_id()); |
664 | 660 |
665 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 661 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
699 ProxyInfo info; | 695 ProxyInfo info; |
700 TestCompletionCallback callback1; | 696 TestCompletionCallback callback1; |
701 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 697 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
702 NULL, NULL, BoundNetLog()); | 698 NULL, NULL, BoundNetLog()); |
703 EXPECT_EQ(ERR_IO_PENDING, rv); | 699 EXPECT_EQ(ERR_IO_PENDING, rv); |
704 | 700 |
705 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 701 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
706 factory->pending_requests()[0]->script_data()->url()); | 702 factory->pending_requests()[0]->script_data()->url()); |
707 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 703 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
708 | 704 |
709 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 705 ASSERT_EQ(1u, resolver.pending_requests().size()); |
710 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 706 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
711 | 707 |
712 // Set the result in proxy resolver. | 708 // Set the result in proxy resolver. |
713 resolver.pending_jobs()[0]->results()->UsePacString( | 709 resolver.pending_requests()[0]->results()->UsePacString( |
714 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 710 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
715 resolver.pending_jobs()[0]->CompleteNow(OK); | 711 resolver.pending_requests()[0]->CompleteNow(OK); |
716 | 712 |
717 EXPECT_EQ(OK, callback1.WaitForResult()); | 713 EXPECT_EQ(OK, callback1.WaitForResult()); |
718 EXPECT_TRUE(info.is_direct()); | 714 EXPECT_TRUE(info.is_direct()); |
719 | 715 |
720 // Fallback 1. | 716 // Fallback 1. |
721 TestCompletionCallback callback2; | 717 TestCompletionCallback callback2; |
722 rv = service.ReconsiderProxyAfterError( | 718 rv = service.ReconsiderProxyAfterError( |
723 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 719 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
724 callback2.callback(), NULL, NULL, BoundNetLog()); | 720 callback2.callback(), NULL, NULL, BoundNetLog()); |
725 EXPECT_EQ(OK, rv); | 721 EXPECT_EQ(OK, rv); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
771 make_scoped_ptr(factory), NULL); | 767 make_scoped_ptr(factory), NULL); |
772 | 768 |
773 // Resolve something. | 769 // Resolve something. |
774 GURL url("http://www.google.com/"); | 770 GURL url("http://www.google.com/"); |
775 ProxyInfo info; | 771 ProxyInfo info; |
776 TestCompletionCallback callback; | 772 TestCompletionCallback callback; |
777 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 773 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
778 NULL, NULL, BoundNetLog()); | 774 NULL, NULL, BoundNetLog()); |
779 ASSERT_EQ(ERR_IO_PENDING, rv); | 775 ASSERT_EQ(ERR_IO_PENDING, rv); |
780 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 776 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
781 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 777 ASSERT_EQ(1u, resolver.pending_requests().size()); |
782 | 778 |
783 // Set the result in proxy resolver. | 779 // Set the result in proxy resolver. |
784 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy"); | 780 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); |
785 resolver.pending_jobs()[0]->CompleteNow(OK); | 781 resolver.pending_requests()[0]->CompleteNow(OK); |
786 | 782 |
787 EXPECT_EQ(OK, callback.WaitForResult()); | 783 EXPECT_EQ(OK, callback.WaitForResult()); |
788 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 784 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
789 EXPECT_TRUE(info.did_use_pac_script()); | 785 EXPECT_TRUE(info.did_use_pac_script()); |
790 | 786 |
791 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 787 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
792 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 788 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
793 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 789 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
794 } | 790 } |
795 | 791 |
(...skipping 17 matching lines...) Expand all Loading... |
813 ProxyInfo info; | 809 ProxyInfo info; |
814 TestCompletionCallback callback1; | 810 TestCompletionCallback callback1; |
815 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 811 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
816 NULL, NULL, BoundNetLog()); | 812 NULL, NULL, BoundNetLog()); |
817 EXPECT_EQ(ERR_IO_PENDING, rv); | 813 EXPECT_EQ(ERR_IO_PENDING, rv); |
818 | 814 |
819 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 815 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
820 factory->pending_requests()[0]->script_data()->url()); | 816 factory->pending_requests()[0]->script_data()->url()); |
821 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 817 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
822 | 818 |
823 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 819 ASSERT_EQ(1u, resolver.pending_requests().size()); |
824 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 820 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
825 | 821 |
826 // Fail the first resolve request in MockAsyncProxyResolver. | 822 // Fail the first resolve request in MockAsyncProxyResolver. |
827 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); | 823 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
828 | 824 |
829 // Although the proxy resolver failed the request, ProxyService implicitly | 825 // Although the proxy resolver failed the request, ProxyService implicitly |
830 // falls-back to DIRECT. | 826 // falls-back to DIRECT. |
831 EXPECT_EQ(OK, callback1.WaitForResult()); | 827 EXPECT_EQ(OK, callback1.WaitForResult()); |
832 EXPECT_TRUE(info.is_direct()); | 828 EXPECT_TRUE(info.is_direct()); |
833 | 829 |
834 // Failed PAC executions still have proxy resolution times. | 830 // Failed PAC executions still have proxy resolution times. |
835 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 831 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
836 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 832 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
837 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 833 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
838 | 834 |
839 // The second resolve request will try to run through the proxy resolver, | 835 // The second resolve request will try to run through the proxy resolver, |
840 // regardless of whether the first request failed in it. | 836 // regardless of whether the first request failed in it. |
841 TestCompletionCallback callback2; | 837 TestCompletionCallback callback2; |
842 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, | 838 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, |
843 NULL, BoundNetLog()); | 839 NULL, BoundNetLog()); |
844 EXPECT_EQ(ERR_IO_PENDING, rv); | 840 EXPECT_EQ(ERR_IO_PENDING, rv); |
845 | 841 |
846 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 842 ASSERT_EQ(1u, resolver.pending_requests().size()); |
847 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 843 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
848 | 844 |
849 // This time we will have the resolver succeed (perhaps the PAC script has | 845 // This time we will have the resolver succeed (perhaps the PAC script has |
850 // a dependency on the current time). | 846 // a dependency on the current time). |
851 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 847 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
852 resolver.pending_jobs()[0]->CompleteNow(OK); | 848 resolver.pending_requests()[0]->CompleteNow(OK); |
853 | 849 |
854 EXPECT_EQ(OK, callback2.WaitForResult()); | 850 EXPECT_EQ(OK, callback2.WaitForResult()); |
855 EXPECT_FALSE(info.is_direct()); | 851 EXPECT_FALSE(info.is_direct()); |
856 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 852 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
857 } | 853 } |
858 | 854 |
859 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { | 855 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { |
860 // Test what happens when the ProxyResolver fails with a fatal error while | 856 // Test what happens when the ProxyResolver fails with a fatal error while |
861 // a GetProxyForURL() call is in progress. | 857 // a GetProxyForURL() call is in progress. |
862 | 858 |
(...skipping 14 matching lines...) Expand all Loading... |
877 int rv = | 873 int rv = |
878 service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback1.callback(), | 874 service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback1.callback(), |
879 nullptr, nullptr, BoundNetLog()); | 875 nullptr, nullptr, BoundNetLog()); |
880 EXPECT_EQ(ERR_IO_PENDING, rv); | 876 EXPECT_EQ(ERR_IO_PENDING, rv); |
881 | 877 |
882 ASSERT_EQ(1u, factory->pending_requests().size()); | 878 ASSERT_EQ(1u, factory->pending_requests().size()); |
883 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 879 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
884 factory->pending_requests()[0]->script_data()->url()); | 880 factory->pending_requests()[0]->script_data()->url()); |
885 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 881 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
886 | 882 |
887 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 883 ASSERT_EQ(1u, resolver.pending_requests().size()); |
888 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 884 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
889 | 885 |
890 // Fail the first resolve request in MockAsyncProxyResolver. | 886 // Fail the first resolve request in MockAsyncProxyResolver. |
891 resolver.pending_jobs()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 887 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
892 | 888 |
893 // Although the proxy resolver failed the request, ProxyService implicitly | 889 // Although the proxy resolver failed the request, ProxyService implicitly |
894 // falls-back to DIRECT. | 890 // falls-back to DIRECT. |
895 EXPECT_EQ(OK, callback1.WaitForResult()); | 891 EXPECT_EQ(OK, callback1.WaitForResult()); |
896 EXPECT_TRUE(info.is_direct()); | 892 EXPECT_TRUE(info.is_direct()); |
897 | 893 |
898 // Failed PAC executions still have proxy resolution times. | 894 // Failed PAC executions still have proxy resolution times. |
899 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 895 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
900 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 896 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
901 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 897 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
902 | 898 |
903 // With no other requests, the ProxyService waits for a new request before | 899 // With no other requests, the ProxyService waits for a new request before |
904 // initializing a new ProxyResolver. | 900 // initializing a new ProxyResolver. |
905 EXPECT_TRUE(factory->pending_requests().empty()); | 901 EXPECT_TRUE(factory->pending_requests().empty()); |
906 | 902 |
907 TestCompletionCallback callback2; | 903 TestCompletionCallback callback2; |
908 rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback2.callback(), | 904 rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback2.callback(), |
909 nullptr, nullptr, BoundNetLog()); | 905 nullptr, nullptr, BoundNetLog()); |
910 EXPECT_EQ(ERR_IO_PENDING, rv); | 906 EXPECT_EQ(ERR_IO_PENDING, rv); |
911 | 907 |
912 ASSERT_EQ(1u, factory->pending_requests().size()); | 908 ASSERT_EQ(1u, factory->pending_requests().size()); |
913 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 909 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
914 factory->pending_requests()[0]->script_data()->url()); | 910 factory->pending_requests()[0]->script_data()->url()); |
915 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 911 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
916 | 912 |
917 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 913 ASSERT_EQ(1u, resolver.pending_requests().size()); |
918 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 914 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
919 | 915 |
920 // This time we will have the resolver succeed. | 916 // This time we will have the resolver succeed. |
921 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 917 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
922 resolver.pending_jobs()[0]->CompleteNow(OK); | 918 resolver.pending_requests()[0]->CompleteNow(OK); |
923 | 919 |
924 EXPECT_EQ(OK, callback2.WaitForResult()); | 920 EXPECT_EQ(OK, callback2.WaitForResult()); |
925 EXPECT_FALSE(info.is_direct()); | 921 EXPECT_FALSE(info.is_direct()); |
926 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 922 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
927 } | 923 } |
928 | 924 |
929 TEST_F(ProxyServiceTest, | 925 TEST_F(ProxyServiceTest, |
930 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { | 926 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { |
931 // Test what happens when the ProxyResolver fails with a fatal error while | 927 // Test what happens when the ProxyResolver fails with a fatal error while |
932 // a GetProxyForURL() call is in progress. | 928 // a GetProxyForURL() call is in progress. |
(...skipping 20 matching lines...) Expand all Loading... |
953 TestCompletionCallback callback2; | 949 TestCompletionCallback callback2; |
954 rv = service.ResolveProxy(url2, net::LOAD_NORMAL, &info, callback2.callback(), | 950 rv = service.ResolveProxy(url2, net::LOAD_NORMAL, &info, callback2.callback(), |
955 nullptr, nullptr, BoundNetLog()); | 951 nullptr, nullptr, BoundNetLog()); |
956 EXPECT_EQ(ERR_IO_PENDING, rv); | 952 EXPECT_EQ(ERR_IO_PENDING, rv); |
957 | 953 |
958 ASSERT_EQ(1u, factory->pending_requests().size()); | 954 ASSERT_EQ(1u, factory->pending_requests().size()); |
959 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 955 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
960 factory->pending_requests()[0]->script_data()->url()); | 956 factory->pending_requests()[0]->script_data()->url()); |
961 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 957 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
962 | 958 |
963 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); | 959 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); |
964 | 960 |
965 // Fail the first resolve request in MockAsyncProxyResolver. | 961 // Fail the first resolve request in MockAsyncProxyResolver. |
966 jobs[url1]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 962 requests[url1]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
967 | 963 |
968 // Although the proxy resolver failed the request, ProxyService implicitly | 964 // Although the proxy resolver failed the request, ProxyService implicitly |
969 // falls-back to DIRECT. | 965 // falls-back to DIRECT. |
970 EXPECT_EQ(OK, callback1.WaitForResult()); | 966 EXPECT_EQ(OK, callback1.WaitForResult()); |
971 EXPECT_TRUE(info.is_direct()); | 967 EXPECT_TRUE(info.is_direct()); |
972 | 968 |
973 // Failed PAC executions still have proxy resolution times. | 969 // Failed PAC executions still have proxy resolution times. |
974 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 970 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
975 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 971 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
976 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 972 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
977 | 973 |
978 // The second request is cancelled when the proxy resolver terminates. | 974 // The second request is cancelled when the proxy resolver terminates. |
979 jobs = GetCancelledJobsForURLs(resolver, url2); | 975 requests = GetCancelledRequestsForURLs(resolver, url2); |
980 | 976 |
981 // Since a second request was in progress, the ProxyService starts | 977 // Since a second request was in progress, the ProxyService starts |
982 // initializating a new ProxyResolver. | 978 // initializating a new ProxyResolver. |
983 ASSERT_EQ(1u, factory->pending_requests().size()); | 979 ASSERT_EQ(1u, factory->pending_requests().size()); |
984 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 980 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
985 factory->pending_requests()[0]->script_data()->url()); | 981 factory->pending_requests()[0]->script_data()->url()); |
986 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 982 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
987 | 983 |
988 jobs = GetPendingJobsForURLs(resolver, url2); | 984 requests = GetPendingRequestsForURLs(resolver, url2); |
989 | 985 |
990 // This request succeeds. | 986 // This request succeeds. |
991 jobs[url2]->results()->UseNamedProxy("foopy_valid:8080"); | 987 requests[url2]->results()->UseNamedProxy("foopy_valid:8080"); |
992 jobs[url2]->CompleteNow(OK); | 988 requests[url2]->CompleteNow(OK); |
993 | 989 |
994 EXPECT_EQ(OK, callback2.WaitForResult()); | 990 EXPECT_EQ(OK, callback2.WaitForResult()); |
995 EXPECT_FALSE(info.is_direct()); | 991 EXPECT_FALSE(info.is_direct()); |
996 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 992 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
997 } | 993 } |
998 | 994 |
999 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { | 995 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { |
1000 // Test what happens when the ProxyScriptResolver fails to download a | 996 // Test what happens when the ProxyScriptResolver fails to download a |
1001 // mandatory PAC script. | 997 // mandatory PAC script. |
1002 | 998 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1112 ProxyInfo info; | 1108 ProxyInfo info; |
1113 TestCompletionCallback callback1; | 1109 TestCompletionCallback callback1; |
1114 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1110 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1115 NULL, NULL, BoundNetLog()); | 1111 NULL, NULL, BoundNetLog()); |
1116 EXPECT_EQ(ERR_IO_PENDING, rv); | 1112 EXPECT_EQ(ERR_IO_PENDING, rv); |
1117 | 1113 |
1118 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1114 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1119 factory->pending_requests()[0]->script_data()->url()); | 1115 factory->pending_requests()[0]->script_data()->url()); |
1120 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1116 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1121 | 1117 |
1122 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1118 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1123 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1119 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1124 | 1120 |
1125 // Fail the first resolve request in MockAsyncProxyResolver. | 1121 // Fail the first resolve request in MockAsyncProxyResolver. |
1126 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); | 1122 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1127 | 1123 |
1128 // As the proxy resolver failed the request and is configured for a mandatory | 1124 // As the proxy resolver failed the request and is configured for a mandatory |
1129 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1125 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1130 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1126 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1131 callback1.WaitForResult()); | 1127 callback1.WaitForResult()); |
1132 EXPECT_FALSE(info.is_direct()); | 1128 EXPECT_FALSE(info.is_direct()); |
1133 | 1129 |
1134 // The second resolve request will try to run through the proxy resolver, | 1130 // The second resolve request will try to run through the proxy resolver, |
1135 // regardless of whether the first request failed in it. | 1131 // regardless of whether the first request failed in it. |
1136 TestCompletionCallback callback2; | 1132 TestCompletionCallback callback2; |
1137 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, | 1133 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, |
1138 NULL, BoundNetLog()); | 1134 NULL, BoundNetLog()); |
1139 EXPECT_EQ(ERR_IO_PENDING, rv); | 1135 EXPECT_EQ(ERR_IO_PENDING, rv); |
1140 | 1136 |
1141 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1137 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1142 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1138 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1143 | 1139 |
1144 // This time we will have the resolver succeed (perhaps the PAC script has | 1140 // This time we will have the resolver succeed (perhaps the PAC script has |
1145 // a dependency on the current time). | 1141 // a dependency on the current time). |
1146 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 1142 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
1147 resolver.pending_jobs()[0]->CompleteNow(OK); | 1143 resolver.pending_requests()[0]->CompleteNow(OK); |
1148 | 1144 |
1149 EXPECT_EQ(OK, callback2.WaitForResult()); | 1145 EXPECT_EQ(OK, callback2.WaitForResult()); |
1150 EXPECT_FALSE(info.is_direct()); | 1146 EXPECT_FALSE(info.is_direct()); |
1151 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 1147 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
1152 } | 1148 } |
1153 | 1149 |
1154 TEST_F(ProxyServiceTest, ProxyFallback) { | 1150 TEST_F(ProxyServiceTest, ProxyFallback) { |
1155 // Test what happens when we specify multiple proxy servers and some of them | 1151 // Test what happens when we specify multiple proxy servers and some of them |
1156 // are bad. | 1152 // are bad. |
1157 | 1153 |
(...skipping 13 matching lines...) Expand all Loading... |
1171 ProxyInfo info; | 1167 ProxyInfo info; |
1172 TestCompletionCallback callback1; | 1168 TestCompletionCallback callback1; |
1173 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1169 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1174 NULL, NULL, BoundNetLog()); | 1170 NULL, NULL, BoundNetLog()); |
1175 EXPECT_EQ(ERR_IO_PENDING, rv); | 1171 EXPECT_EQ(ERR_IO_PENDING, rv); |
1176 | 1172 |
1177 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1173 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1178 factory->pending_requests()[0]->script_data()->url()); | 1174 factory->pending_requests()[0]->script_data()->url()); |
1179 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1175 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1180 | 1176 |
1181 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1177 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1182 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1178 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1183 | 1179 |
1184 // Set the result in proxy resolver. | 1180 // Set the result in proxy resolver. |
1185 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1181 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1186 "foopy1:8080;foopy2:9090"); | 1182 "foopy1:8080;foopy2:9090"); |
1187 resolver.pending_jobs()[0]->CompleteNow(OK); | 1183 resolver.pending_requests()[0]->CompleteNow(OK); |
1188 | 1184 |
1189 // The first item is valid. | 1185 // The first item is valid. |
1190 EXPECT_EQ(OK, callback1.WaitForResult()); | 1186 EXPECT_EQ(OK, callback1.WaitForResult()); |
1191 EXPECT_FALSE(info.is_direct()); | 1187 EXPECT_FALSE(info.is_direct()); |
1192 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1188 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1193 | 1189 |
1194 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1190 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1195 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1191 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1196 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1192 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1197 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1193 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); |
(...skipping 18 matching lines...) Expand all Loading... |
1216 service.ReportSuccess(info, &test_delegate); | 1212 service.ReportSuccess(info, &test_delegate); |
1217 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); | 1213 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); |
1218 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 1214 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
1219 test_delegate.proxy_fallback_net_error()); | 1215 test_delegate.proxy_fallback_net_error()); |
1220 | 1216 |
1221 TestCompletionCallback callback3; | 1217 TestCompletionCallback callback3; |
1222 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback3.callback(), NULL, | 1218 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback3.callback(), NULL, |
1223 NULL, BoundNetLog()); | 1219 NULL, BoundNetLog()); |
1224 EXPECT_EQ(ERR_IO_PENDING, rv); | 1220 EXPECT_EQ(ERR_IO_PENDING, rv); |
1225 | 1221 |
1226 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1222 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1227 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1223 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1228 | 1224 |
1229 // Set the result in proxy resolver -- the second result is already known | 1225 // Set the result in proxy resolver -- the second result is already known |
1230 // to be bad, so we will not try to use it initially. | 1226 // to be bad, so we will not try to use it initially. |
1231 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1227 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1232 "foopy3:7070;foopy1:8080;foopy2:9090"); | 1228 "foopy3:7070;foopy1:8080;foopy2:9090"); |
1233 resolver.pending_jobs()[0]->CompleteNow(OK); | 1229 resolver.pending_requests()[0]->CompleteNow(OK); |
1234 | 1230 |
1235 EXPECT_EQ(OK, callback3.WaitForResult()); | 1231 EXPECT_EQ(OK, callback3.WaitForResult()); |
1236 EXPECT_FALSE(info.is_direct()); | 1232 EXPECT_FALSE(info.is_direct()); |
1237 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1233 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1238 | 1234 |
1239 // Proxy times should have been updated, so get them again. | 1235 // Proxy times should have been updated, so get them again. |
1240 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1236 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1241 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1237 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1242 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1238 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1243 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1239 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1275 // Proxy times should not have been modified by fallback. | 1271 // Proxy times should not have been modified by fallback. |
1276 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1272 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
1277 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1273 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
1278 | 1274 |
1279 // Look up proxies again | 1275 // Look up proxies again |
1280 TestCompletionCallback callback7; | 1276 TestCompletionCallback callback7; |
1281 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback7.callback(), NULL, | 1277 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback7.callback(), NULL, |
1282 NULL, BoundNetLog()); | 1278 NULL, BoundNetLog()); |
1283 EXPECT_EQ(ERR_IO_PENDING, rv); | 1279 EXPECT_EQ(ERR_IO_PENDING, rv); |
1284 | 1280 |
1285 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1281 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1286 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1282 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1287 | 1283 |
1288 // This time, the first 3 results have been found to be bad, but only the | 1284 // This time, the first 3 results have been found to be bad, but only the |
1289 // first proxy has been confirmed ... | 1285 // first proxy has been confirmed ... |
1290 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1286 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1291 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 1287 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
1292 resolver.pending_jobs()[0]->CompleteNow(OK); | 1288 resolver.pending_requests()[0]->CompleteNow(OK); |
1293 | 1289 |
1294 // ... therefore, we should see the second proxy first. | 1290 // ... therefore, we should see the second proxy first. |
1295 EXPECT_EQ(OK, callback7.WaitForResult()); | 1291 EXPECT_EQ(OK, callback7.WaitForResult()); |
1296 EXPECT_FALSE(info.is_direct()); | 1292 EXPECT_FALSE(info.is_direct()); |
1297 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1293 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1298 | 1294 |
1299 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1295 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1300 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1296 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1301 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1297 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1302 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 1298 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
(...skipping 18 matching lines...) Expand all Loading... |
1321 ProxyInfo info; | 1317 ProxyInfo info; |
1322 TestCompletionCallback callback1; | 1318 TestCompletionCallback callback1; |
1323 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1319 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1324 NULL, NULL, BoundNetLog()); | 1320 NULL, NULL, BoundNetLog()); |
1325 EXPECT_EQ(ERR_IO_PENDING, rv); | 1321 EXPECT_EQ(ERR_IO_PENDING, rv); |
1326 | 1322 |
1327 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1323 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1328 factory->pending_requests()[0]->script_data()->url()); | 1324 factory->pending_requests()[0]->script_data()->url()); |
1329 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1325 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1330 | 1326 |
1331 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1327 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1332 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1328 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1333 | 1329 |
1334 // Set the result in proxy resolver. | 1330 // Set the result in proxy resolver. |
1335 resolver.pending_jobs()[0]->results()->UsePacString( | 1331 resolver.pending_requests()[0]->results()->UsePacString( |
1336 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 1332 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
1337 resolver.pending_jobs()[0]->CompleteNow(OK); | 1333 resolver.pending_requests()[0]->CompleteNow(OK); |
1338 | 1334 |
1339 // Get the first result. | 1335 // Get the first result. |
1340 EXPECT_EQ(OK, callback1.WaitForResult()); | 1336 EXPECT_EQ(OK, callback1.WaitForResult()); |
1341 EXPECT_FALSE(info.is_direct()); | 1337 EXPECT_FALSE(info.is_direct()); |
1342 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1338 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1343 | 1339 |
1344 // Fake an error on the proxy. | 1340 // Fake an error on the proxy. |
1345 TestCompletionCallback callback2; | 1341 TestCompletionCallback callback2; |
1346 rv = service.ReconsiderProxyAfterError( | 1342 rv = service.ReconsiderProxyAfterError( |
1347 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1343 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1394 ProxyInfo info; | 1390 ProxyInfo info; |
1395 TestCompletionCallback callback1; | 1391 TestCompletionCallback callback1; |
1396 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1392 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1397 NULL, NULL, BoundNetLog()); | 1393 NULL, NULL, BoundNetLog()); |
1398 EXPECT_EQ(ERR_IO_PENDING, rv); | 1394 EXPECT_EQ(ERR_IO_PENDING, rv); |
1399 | 1395 |
1400 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1396 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1401 factory->pending_requests()[0]->script_data()->url()); | 1397 factory->pending_requests()[0]->script_data()->url()); |
1402 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1398 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1403 | 1399 |
1404 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1400 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1405 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1401 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1406 | 1402 |
1407 // Set the result in proxy resolver. | 1403 // Set the result in proxy resolver. |
1408 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1404 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1409 "foopy1:8080;foopy2:9090"); | 1405 "foopy1:8080;foopy2:9090"); |
1410 resolver.pending_jobs()[0]->CompleteNow(OK); | 1406 resolver.pending_requests()[0]->CompleteNow(OK); |
1411 | 1407 |
1412 // The first item is valid. | 1408 // The first item is valid. |
1413 EXPECT_EQ(OK, callback1.WaitForResult()); | 1409 EXPECT_EQ(OK, callback1.WaitForResult()); |
1414 EXPECT_FALSE(info.is_direct()); | 1410 EXPECT_FALSE(info.is_direct()); |
1415 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1411 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1416 | 1412 |
1417 // Fake an error on the proxy, and also a new configuration on the proxy. | 1413 // Fake an error on the proxy, and also a new configuration on the proxy. |
1418 config_service->SetConfig( | 1414 config_service->SetConfig( |
1419 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 1415 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
1420 | 1416 |
1421 TestCompletionCallback callback2; | 1417 TestCompletionCallback callback2; |
1422 rv = service.ReconsiderProxyAfterError( | 1418 rv = service.ReconsiderProxyAfterError( |
1423 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1419 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1424 callback2.callback(), NULL, NULL, BoundNetLog()); | 1420 callback2.callback(), NULL, NULL, BoundNetLog()); |
1425 EXPECT_EQ(ERR_IO_PENDING, rv); | 1421 EXPECT_EQ(ERR_IO_PENDING, rv); |
1426 | 1422 |
1427 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 1423 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
1428 factory->pending_requests()[0]->script_data()->url()); | 1424 factory->pending_requests()[0]->script_data()->url()); |
1429 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1425 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1430 | 1426 |
1431 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1427 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1432 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1428 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1433 | 1429 |
1434 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1430 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1435 "foopy1:8080;foopy2:9090"); | 1431 "foopy1:8080;foopy2:9090"); |
1436 resolver.pending_jobs()[0]->CompleteNow(OK); | 1432 resolver.pending_requests()[0]->CompleteNow(OK); |
1437 | 1433 |
1438 // The first proxy is still there since the configuration changed. | 1434 // The first proxy is still there since the configuration changed. |
1439 EXPECT_EQ(OK, callback2.WaitForResult()); | 1435 EXPECT_EQ(OK, callback2.WaitForResult()); |
1440 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1436 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1441 | 1437 |
1442 // We fake another error. It should now ignore the first one. | 1438 // We fake another error. It should now ignore the first one. |
1443 TestCompletionCallback callback3; | 1439 TestCompletionCallback callback3; |
1444 rv = service.ReconsiderProxyAfterError( | 1440 rv = service.ReconsiderProxyAfterError( |
1445 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1441 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1446 callback3.callback(), NULL, NULL, BoundNetLog()); | 1442 callback3.callback(), NULL, NULL, BoundNetLog()); |
1447 EXPECT_EQ(OK, rv); | 1443 EXPECT_EQ(OK, rv); |
1448 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1444 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1449 | 1445 |
1450 // We simulate a new configuration. | 1446 // We simulate a new configuration. |
1451 config_service->SetConfig( | 1447 config_service->SetConfig( |
1452 ProxyConfig::CreateFromCustomPacURL( | 1448 ProxyConfig::CreateFromCustomPacURL( |
1453 GURL("http://foopy-new2/proxy.pac"))); | 1449 GURL("http://foopy-new2/proxy.pac"))); |
1454 | 1450 |
1455 // We fake another error. It should go back to the first proxy. | 1451 // We fake another error. It should go back to the first proxy. |
1456 TestCompletionCallback callback4; | 1452 TestCompletionCallback callback4; |
1457 rv = service.ReconsiderProxyAfterError( | 1453 rv = service.ReconsiderProxyAfterError( |
1458 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1454 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1459 callback4.callback(), NULL, NULL, BoundNetLog()); | 1455 callback4.callback(), NULL, NULL, BoundNetLog()); |
1460 EXPECT_EQ(ERR_IO_PENDING, rv); | 1456 EXPECT_EQ(ERR_IO_PENDING, rv); |
1461 | 1457 |
1462 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 1458 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
1463 factory->pending_requests()[0]->script_data()->url()); | 1459 factory->pending_requests()[0]->script_data()->url()); |
1464 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1460 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1465 | 1461 |
1466 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1462 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1467 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1463 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1468 | 1464 |
1469 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1465 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1470 "foopy1:8080;foopy2:9090"); | 1466 "foopy1:8080;foopy2:9090"); |
1471 resolver.pending_jobs()[0]->CompleteNow(OK); | 1467 resolver.pending_requests()[0]->CompleteNow(OK); |
1472 | 1468 |
1473 EXPECT_EQ(OK, callback4.WaitForResult()); | 1469 EXPECT_EQ(OK, callback4.WaitForResult()); |
1474 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1470 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1475 | 1471 |
1476 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1472 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1477 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1473 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1478 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1474 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1479 } | 1475 } |
1480 | 1476 |
1481 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { | 1477 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { |
(...skipping 14 matching lines...) Expand all Loading... |
1496 // Get the proxy information. | 1492 // Get the proxy information. |
1497 ProxyInfo info; | 1493 ProxyInfo info; |
1498 TestCompletionCallback callback1; | 1494 TestCompletionCallback callback1; |
1499 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1495 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1500 NULL, NULL, BoundNetLog()); | 1496 NULL, NULL, BoundNetLog()); |
1501 EXPECT_EQ(ERR_IO_PENDING, rv); | 1497 EXPECT_EQ(ERR_IO_PENDING, rv); |
1502 | 1498 |
1503 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1499 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1504 factory->pending_requests()[0]->script_data()->url()); | 1500 factory->pending_requests()[0]->script_data()->url()); |
1505 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1501 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1506 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1502 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1507 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1503 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1508 | 1504 |
1509 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1505 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1510 "foopy1:8080;foopy2:9090"); | 1506 "foopy1:8080;foopy2:9090"); |
1511 resolver.pending_jobs()[0]->CompleteNow(OK); | 1507 resolver.pending_requests()[0]->CompleteNow(OK); |
1512 | 1508 |
1513 // The first item is valid. | 1509 // The first item is valid. |
1514 EXPECT_EQ(OK, callback1.WaitForResult()); | 1510 EXPECT_EQ(OK, callback1.WaitForResult()); |
1515 EXPECT_FALSE(info.is_direct()); | 1511 EXPECT_FALSE(info.is_direct()); |
1516 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1512 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1517 | 1513 |
1518 // Fake a proxy error. | 1514 // Fake a proxy error. |
1519 TestCompletionCallback callback2; | 1515 TestCompletionCallback callback2; |
1520 rv = service.ReconsiderProxyAfterError( | 1516 rv = service.ReconsiderProxyAfterError( |
1521 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1517 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1522 callback2.callback(), NULL, NULL, BoundNetLog()); | 1518 callback2.callback(), NULL, NULL, BoundNetLog()); |
1523 EXPECT_EQ(OK, rv); | 1519 EXPECT_EQ(OK, rv); |
1524 | 1520 |
1525 // The first proxy is ignored, and the second one is selected. | 1521 // The first proxy is ignored, and the second one is selected. |
1526 EXPECT_FALSE(info.is_direct()); | 1522 EXPECT_FALSE(info.is_direct()); |
1527 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1523 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1528 | 1524 |
1529 // Fake a PAC failure. | 1525 // Fake a PAC failure. |
1530 ProxyInfo info2; | 1526 ProxyInfo info2; |
1531 TestCompletionCallback callback3; | 1527 TestCompletionCallback callback3; |
1532 rv = service.ResolveProxy(url, LOAD_NORMAL, &info2, callback3.callback(), | 1528 rv = service.ResolveProxy(url, LOAD_NORMAL, &info2, callback3.callback(), |
1533 NULL, NULL, BoundNetLog()); | 1529 NULL, NULL, BoundNetLog()); |
1534 EXPECT_EQ(ERR_IO_PENDING, rv); | 1530 EXPECT_EQ(ERR_IO_PENDING, rv); |
1535 | 1531 |
1536 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1532 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1537 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1533 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1538 | 1534 |
1539 // This simulates a javascript runtime error in the PAC script. | 1535 // This simulates a javascript runtime error in the PAC script. |
1540 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); | 1536 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1541 | 1537 |
1542 // Although the resolver failed, the ProxyService will implicitly fall-back | 1538 // Although the resolver failed, the ProxyService will implicitly fall-back |
1543 // to a DIRECT connection. | 1539 // to a DIRECT connection. |
1544 EXPECT_EQ(OK, callback3.WaitForResult()); | 1540 EXPECT_EQ(OK, callback3.WaitForResult()); |
1545 EXPECT_TRUE(info2.is_direct()); | 1541 EXPECT_TRUE(info2.is_direct()); |
1546 EXPECT_FALSE(info2.is_empty()); | 1542 EXPECT_FALSE(info2.is_empty()); |
1547 | 1543 |
1548 // The PAC script will work properly next time and successfully return a | 1544 // The PAC script will work properly next time and successfully return a |
1549 // proxy list. Since we have not marked the configuration as bad, it should | 1545 // proxy list. Since we have not marked the configuration as bad, it should |
1550 // "just work" the next time we call it. | 1546 // "just work" the next time we call it. |
1551 ProxyInfo info3; | 1547 ProxyInfo info3; |
1552 TestCompletionCallback callback4; | 1548 TestCompletionCallback callback4; |
1553 rv = service.ReconsiderProxyAfterError( | 1549 rv = service.ReconsiderProxyAfterError( |
1554 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, | 1550 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, |
1555 callback4.callback(), NULL, NULL, BoundNetLog()); | 1551 callback4.callback(), NULL, NULL, BoundNetLog()); |
1556 EXPECT_EQ(ERR_IO_PENDING, rv); | 1552 EXPECT_EQ(ERR_IO_PENDING, rv); |
1557 | 1553 |
1558 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1554 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1559 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1555 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1560 | 1556 |
1561 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1557 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1562 "foopy1:8080;foopy2:9090"); | 1558 "foopy1:8080;foopy2:9090"); |
1563 resolver.pending_jobs()[0]->CompleteNow(OK); | 1559 resolver.pending_requests()[0]->CompleteNow(OK); |
1564 | 1560 |
1565 // The first proxy is not there since the it was added to the bad proxies | 1561 // The first proxy is not there since the it was added to the bad proxies |
1566 // list by the earlier ReconsiderProxyAfterError(). | 1562 // list by the earlier ReconsiderProxyAfterError(). |
1567 EXPECT_EQ(OK, callback4.WaitForResult()); | 1563 EXPECT_EQ(OK, callback4.WaitForResult()); |
1568 EXPECT_FALSE(info3.is_direct()); | 1564 EXPECT_FALSE(info3.is_direct()); |
1569 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 1565 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
1570 | 1566 |
1571 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1567 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1572 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1568 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1573 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1569 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
(...skipping 20 matching lines...) Expand all Loading... |
1594 // Get the proxy information. | 1590 // Get the proxy information. |
1595 ProxyInfo info; | 1591 ProxyInfo info; |
1596 TestCompletionCallback callback1; | 1592 TestCompletionCallback callback1; |
1597 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1593 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1598 NULL, NULL, BoundNetLog()); | 1594 NULL, NULL, BoundNetLog()); |
1599 EXPECT_EQ(ERR_IO_PENDING, rv); | 1595 EXPECT_EQ(ERR_IO_PENDING, rv); |
1600 | 1596 |
1601 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1597 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1602 factory->pending_requests()[0]->script_data()->url()); | 1598 factory->pending_requests()[0]->script_data()->url()); |
1603 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1599 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1604 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1600 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1605 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1601 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1606 | 1602 |
1607 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1603 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1608 "foopy1:8080;foopy2:9090"); | 1604 "foopy1:8080;foopy2:9090"); |
1609 resolver.pending_jobs()[0]->CompleteNow(OK); | 1605 resolver.pending_requests()[0]->CompleteNow(OK); |
1610 | 1606 |
1611 // The first item is valid. | 1607 // The first item is valid. |
1612 EXPECT_EQ(OK, callback1.WaitForResult()); | 1608 EXPECT_EQ(OK, callback1.WaitForResult()); |
1613 EXPECT_FALSE(info.is_direct()); | 1609 EXPECT_FALSE(info.is_direct()); |
1614 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1610 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1615 | 1611 |
1616 // Fake a proxy error. | 1612 // Fake a proxy error. |
1617 TestCompletionCallback callback2; | 1613 TestCompletionCallback callback2; |
1618 rv = service.ReconsiderProxyAfterError( | 1614 rv = service.ReconsiderProxyAfterError( |
1619 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1615 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1620 callback2.callback(), NULL, NULL, BoundNetLog()); | 1616 callback2.callback(), NULL, NULL, BoundNetLog()); |
1621 EXPECT_EQ(OK, rv); | 1617 EXPECT_EQ(OK, rv); |
1622 | 1618 |
1623 // The first proxy is ignored, and the second one is selected. | 1619 // The first proxy is ignored, and the second one is selected. |
1624 EXPECT_FALSE(info.is_direct()); | 1620 EXPECT_FALSE(info.is_direct()); |
1625 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1621 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1626 | 1622 |
1627 // Fake a PAC failure. | 1623 // Fake a PAC failure. |
1628 ProxyInfo info2; | 1624 ProxyInfo info2; |
1629 TestCompletionCallback callback3; | 1625 TestCompletionCallback callback3; |
1630 rv = service.ResolveProxy(url, LOAD_NORMAL, &info2, callback3.callback(), | 1626 rv = service.ResolveProxy(url, LOAD_NORMAL, &info2, callback3.callback(), |
1631 NULL, NULL, BoundNetLog()); | 1627 NULL, NULL, BoundNetLog()); |
1632 EXPECT_EQ(ERR_IO_PENDING, rv); | 1628 EXPECT_EQ(ERR_IO_PENDING, rv); |
1633 | 1629 |
1634 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1630 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1635 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1631 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1636 | 1632 |
1637 // This simulates a javascript runtime error in the PAC script. | 1633 // This simulates a javascript runtime error in the PAC script. |
1638 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); | 1634 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
1639 | 1635 |
1640 // Although the resolver failed, the ProxyService will NOT fall-back | 1636 // Although the resolver failed, the ProxyService will NOT fall-back |
1641 // to a DIRECT connection as it is configured as mandatory. | 1637 // to a DIRECT connection as it is configured as mandatory. |
1642 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1638 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1643 callback3.WaitForResult()); | 1639 callback3.WaitForResult()); |
1644 EXPECT_FALSE(info2.is_direct()); | 1640 EXPECT_FALSE(info2.is_direct()); |
1645 EXPECT_TRUE(info2.is_empty()); | 1641 EXPECT_TRUE(info2.is_empty()); |
1646 | 1642 |
1647 // The PAC script will work properly next time and successfully return a | 1643 // The PAC script will work properly next time and successfully return a |
1648 // proxy list. Since we have not marked the configuration as bad, it should | 1644 // proxy list. Since we have not marked the configuration as bad, it should |
1649 // "just work" the next time we call it. | 1645 // "just work" the next time we call it. |
1650 ProxyInfo info3; | 1646 ProxyInfo info3; |
1651 TestCompletionCallback callback4; | 1647 TestCompletionCallback callback4; |
1652 rv = service.ReconsiderProxyAfterError( | 1648 rv = service.ReconsiderProxyAfterError( |
1653 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, | 1649 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, |
1654 callback4.callback(), NULL, NULL, BoundNetLog()); | 1650 callback4.callback(), NULL, NULL, BoundNetLog()); |
1655 EXPECT_EQ(ERR_IO_PENDING, rv); | 1651 EXPECT_EQ(ERR_IO_PENDING, rv); |
1656 | 1652 |
1657 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 1653 ASSERT_EQ(1u, resolver.pending_requests().size()); |
1658 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); | 1654 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
1659 | 1655 |
1660 resolver.pending_jobs()[0]->results()->UseNamedProxy( | 1656 resolver.pending_requests()[0]->results()->UseNamedProxy( |
1661 "foopy1:8080;foopy2:9090"); | 1657 "foopy1:8080;foopy2:9090"); |
1662 resolver.pending_jobs()[0]->CompleteNow(OK); | 1658 resolver.pending_requests()[0]->CompleteNow(OK); |
1663 | 1659 |
1664 // The first proxy is not there since the it was added to the bad proxies | 1660 // The first proxy is not there since the it was added to the bad proxies |
1665 // list by the earlier ReconsiderProxyAfterError(). | 1661 // list by the earlier ReconsiderProxyAfterError(). |
1666 EXPECT_EQ(OK, callback4.WaitForResult()); | 1662 EXPECT_EQ(OK, callback4.WaitForResult()); |
1667 EXPECT_FALSE(info3.is_direct()); | 1663 EXPECT_FALSE(info3.is_direct()); |
1668 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 1664 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
1669 } | 1665 } |
1670 | 1666 |
1671 TEST_F(ProxyServiceTest, ProxyBypassList) { | 1667 TEST_F(ProxyServiceTest, ProxyBypassList) { |
1672 // Test that the proxy bypass rules are consulted. | 1668 // Test that the proxy bypass rules are consulted. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1929 TestCompletionCallback callback1; | 1925 TestCompletionCallback callback1; |
1930 int rv = service.ResolveProxy(url1, LOAD_NORMAL, &info1, callback1.callback(), | 1926 int rv = service.ResolveProxy(url1, LOAD_NORMAL, &info1, callback1.callback(), |
1931 NULL, NULL, BoundNetLog()); | 1927 NULL, NULL, BoundNetLog()); |
1932 EXPECT_EQ(ERR_IO_PENDING, rv); | 1928 EXPECT_EQ(ERR_IO_PENDING, rv); |
1933 | 1929 |
1934 // Successfully initialize the PAC script. | 1930 // Successfully initialize the PAC script. |
1935 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1931 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1936 factory->pending_requests()[0]->script_data()->url()); | 1932 factory->pending_requests()[0]->script_data()->url()); |
1937 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1933 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1938 | 1934 |
1939 GetPendingJobsForURLs(resolver, url1); | 1935 GetPendingRequestsForURLs(resolver, url1); |
1940 | 1936 |
1941 ProxyInfo info2; | 1937 ProxyInfo info2; |
1942 TestCompletionCallback callback2; | 1938 TestCompletionCallback callback2; |
1943 ProxyService::PacRequest* request2; | 1939 ProxyService::PacRequest* request2; |
1944 rv = service.ResolveProxy(url2, LOAD_NORMAL, &info2, callback2.callback(), | 1940 rv = service.ResolveProxy(url2, LOAD_NORMAL, &info2, callback2.callback(), |
1945 &request2, NULL, BoundNetLog()); | 1941 &request2, NULL, BoundNetLog()); |
1946 EXPECT_EQ(ERR_IO_PENDING, rv); | 1942 EXPECT_EQ(ERR_IO_PENDING, rv); |
1947 | 1943 |
1948 GetPendingJobsForURLs(resolver, url1, url2); | 1944 GetPendingRequestsForURLs(resolver, url1, url2); |
1949 | 1945 |
1950 ProxyInfo info3; | 1946 ProxyInfo info3; |
1951 TestCompletionCallback callback3; | 1947 TestCompletionCallback callback3; |
1952 rv = service.ResolveProxy(url3, LOAD_NORMAL, &info3, callback3.callback(), | 1948 rv = service.ResolveProxy(url3, LOAD_NORMAL, &info3, callback3.callback(), |
1953 NULL, NULL, BoundNetLog()); | 1949 NULL, NULL, BoundNetLog()); |
1954 EXPECT_EQ(ERR_IO_PENDING, rv); | 1950 EXPECT_EQ(ERR_IO_PENDING, rv); |
1955 GetPendingJobsForURLs(resolver, url1, url2, url3); | 1951 GetPendingRequestsForURLs(resolver, url1, url2, url3); |
1956 | 1952 |
1957 // Cancel the second request | 1953 // Cancel the second request |
1958 service.CancelPacRequest(request2); | 1954 service.CancelPacRequest(request2); |
1959 | 1955 |
1960 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url3); | 1956 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); |
1961 | 1957 |
1962 // Complete the two un-cancelled jobs. | 1958 // Complete the two un-cancelled requests. |
1963 // We complete the last one first, just to mix it up a bit. | 1959 // We complete the last one first, just to mix it up a bit. |
1964 jobs[url3]->results()->UseNamedProxy("request3:80"); | 1960 requests[url3]->results()->UseNamedProxy("request3:80"); |
1965 jobs[url3]->CompleteNow(OK); // dsaadsasd | 1961 requests[url3]->CompleteNow(OK); |
1966 | 1962 |
1967 jobs[url1]->results()->UseNamedProxy("request1:80"); | 1963 requests[url1]->results()->UseNamedProxy("request1:80"); |
1968 jobs[url1]->CompleteNow(OK); | 1964 requests[url1]->CompleteNow(OK); |
1969 | 1965 |
1970 // Complete and verify that jobs ran as expected. | 1966 // Complete and verify that requests ran as expected. |
1971 EXPECT_EQ(OK, callback1.WaitForResult()); | 1967 EXPECT_EQ(OK, callback1.WaitForResult()); |
1972 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1968 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1973 | 1969 |
1974 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 1970 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
1975 GetCancelledJobsForURLs(resolver, url2); | 1971 GetCancelledRequestsForURLs(resolver, url2); |
1976 | 1972 |
1977 EXPECT_EQ(OK, callback3.WaitForResult()); | 1973 EXPECT_EQ(OK, callback3.WaitForResult()); |
1978 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1974 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
1979 } | 1975 } |
1980 | 1976 |
1981 // Test the initial PAC download for resolver that expects bytes. | 1977 // Test the initial PAC download for resolver that expects bytes. |
1982 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { | 1978 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { |
1983 const GURL url1("http://request1"); | 1979 const GURL url1("http://request1"); |
1984 const GURL url2("http://request2"); | 1980 const GURL url2("http://request2"); |
1985 const GURL url3("http://request3"); | 1981 const GURL url3("http://request3"); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2038 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2034 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2039 // PAC script download completion. | 2035 // PAC script download completion. |
2040 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2036 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2041 | 2037 |
2042 // Now that the PAC script is downloaded, it will have been sent to the proxy | 2038 // Now that the PAC script is downloaded, it will have been sent to the proxy |
2043 // resolver. | 2039 // resolver. |
2044 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2040 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2045 factory->pending_requests()[0]->script_data()->utf16()); | 2041 factory->pending_requests()[0]->script_data()->utf16()); |
2046 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2042 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2047 | 2043 |
2048 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2, url3); | 2044 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2, url3); |
2049 | 2045 |
2050 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); | 2046 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); |
2051 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); | 2047 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); |
2052 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); | 2048 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); |
2053 | 2049 |
2054 // Complete all the jobs (in some order). | 2050 // Complete all the requests (in some order). |
2055 | 2051 |
2056 jobs[url3]->results()->UseNamedProxy("request3:80"); | 2052 requests[url3]->results()->UseNamedProxy("request3:80"); |
2057 jobs[url3]->CompleteNow(OK); | 2053 requests[url3]->CompleteNow(OK); |
2058 | 2054 |
2059 jobs[url1]->results()->UseNamedProxy("request1:80"); | 2055 requests[url1]->results()->UseNamedProxy("request1:80"); |
2060 jobs[url1]->CompleteNow(OK); | 2056 requests[url1]->CompleteNow(OK); |
2061 | 2057 |
2062 jobs[url2]->results()->UseNamedProxy("request2:80"); | 2058 requests[url2]->results()->UseNamedProxy("request2:80"); |
2063 jobs[url2]->CompleteNow(OK); | 2059 requests[url2]->CompleteNow(OK); |
2064 | 2060 |
2065 // Complete and verify that jobs ran as expected. | 2061 // Complete and verify that requests ran as expected. |
2066 EXPECT_EQ(OK, callback1.WaitForResult()); | 2062 EXPECT_EQ(OK, callback1.WaitForResult()); |
2067 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2063 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2068 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); | 2064 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); |
2069 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); | 2065 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); |
2070 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); | 2066 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); |
2071 | 2067 |
2072 EXPECT_EQ(OK, callback2.WaitForResult()); | 2068 EXPECT_EQ(OK, callback2.WaitForResult()); |
2073 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2069 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2074 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); | 2070 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); |
2075 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); | 2071 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); |
(...skipping 17 matching lines...) Expand all Loading... |
2093 MockAsyncProxyResolverFactory* factory = | 2089 MockAsyncProxyResolverFactory* factory = |
2094 new MockAsyncProxyResolverFactory(true); | 2090 new MockAsyncProxyResolverFactory(true); |
2095 | 2091 |
2096 ProxyService service(make_scoped_ptr(config_service), | 2092 ProxyService service(make_scoped_ptr(config_service), |
2097 make_scoped_ptr(factory), NULL); | 2093 make_scoped_ptr(factory), NULL); |
2098 | 2094 |
2099 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2095 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2100 service.SetProxyScriptFetchers( | 2096 service.SetProxyScriptFetchers( |
2101 fetcher, make_scoped_ptr(new DoNothingDhcpProxyScriptFetcher())); | 2097 fetcher, make_scoped_ptr(new DoNothingDhcpProxyScriptFetcher())); |
2102 | 2098 |
2103 // Start 2 jobs. | 2099 // Start 2 requests. |
2104 | 2100 |
2105 ProxyInfo info1; | 2101 ProxyInfo info1; |
2106 TestCompletionCallback callback1; | 2102 TestCompletionCallback callback1; |
2107 int rv = service.ResolveProxy(url1, LOAD_NORMAL, &info1, callback1.callback(), | 2103 int rv = service.ResolveProxy(url1, LOAD_NORMAL, &info1, callback1.callback(), |
2108 NULL, NULL, BoundNetLog()); | 2104 NULL, NULL, BoundNetLog()); |
2109 EXPECT_EQ(ERR_IO_PENDING, rv); | 2105 EXPECT_EQ(ERR_IO_PENDING, rv); |
2110 | 2106 |
2111 // The first request should have triggered download of PAC script. | 2107 // The first request should have triggered download of PAC script. |
2112 EXPECT_TRUE(fetcher->has_pending_request()); | 2108 EXPECT_TRUE(fetcher->has_pending_request()); |
2113 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2109 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
(...skipping 19 matching lines...) Expand all Loading... |
2133 EXPECT_TRUE(factory->pending_requests().empty()); | 2129 EXPECT_TRUE(factory->pending_requests().empty()); |
2134 | 2130 |
2135 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2131 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2136 | 2132 |
2137 // Now that the PAC script is downloaded, it will have been sent to the proxy | 2133 // Now that the PAC script is downloaded, it will have been sent to the proxy |
2138 // resolver. | 2134 // resolver. |
2139 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2135 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2140 factory->pending_requests()[0]->script_data()->utf16()); | 2136 factory->pending_requests()[0]->script_data()->utf16()); |
2141 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2137 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2142 | 2138 |
2143 GetPendingJobsForURLs(resolver, url1, url2); | 2139 GetPendingRequestsForURLs(resolver, url1, url2); |
2144 } | 2140 } |
2145 | 2141 |
2146 // Test cancellation of a request, while the PAC script is being fetched. | 2142 // Test cancellation of a request, while the PAC script is being fetched. |
2147 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { | 2143 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { |
2148 MockProxyConfigService* config_service = | 2144 MockProxyConfigService* config_service = |
2149 new MockProxyConfigService("http://foopy/proxy.pac"); | 2145 new MockProxyConfigService("http://foopy/proxy.pac"); |
2150 | 2146 |
2151 MockAsyncProxyResolver resolver; | 2147 MockAsyncProxyResolver resolver; |
2152 MockAsyncProxyResolverFactory* factory = | 2148 MockAsyncProxyResolverFactory* factory = |
2153 new MockAsyncProxyResolverFactory(true); | 2149 new MockAsyncProxyResolverFactory(true); |
(...skipping 29 matching lines...) Expand all Loading... |
2183 | 2179 |
2184 ProxyInfo info3; | 2180 ProxyInfo info3; |
2185 TestCompletionCallback callback3; | 2181 TestCompletionCallback callback3; |
2186 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3, | 2182 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3, |
2187 callback3.callback(), NULL, NULL, BoundNetLog()); | 2183 callback3.callback(), NULL, NULL, BoundNetLog()); |
2188 EXPECT_EQ(ERR_IO_PENDING, rv); | 2184 EXPECT_EQ(ERR_IO_PENDING, rv); |
2189 | 2185 |
2190 // Nothing has been sent to the factory yet. | 2186 // Nothing has been sent to the factory yet. |
2191 EXPECT_TRUE(factory->pending_requests().empty()); | 2187 EXPECT_TRUE(factory->pending_requests().empty()); |
2192 | 2188 |
2193 // Cancel the first 2 jobs. | 2189 // Cancel the first 2 requests. |
2194 service.CancelPacRequest(request1); | 2190 service.CancelPacRequest(request1); |
2195 service.CancelPacRequest(request2); | 2191 service.CancelPacRequest(request2); |
2196 | 2192 |
2197 // At this point the ProxyService should be waiting for the | 2193 // At this point the ProxyService should be waiting for the |
2198 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2194 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2199 // PAC script download completion. | 2195 // PAC script download completion. |
2200 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2196 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2201 | 2197 |
2202 // Now that the PAC script is downloaded, it will have been sent to the | 2198 // Now that the PAC script is downloaded, it will have been sent to the |
2203 // proxy resolver. | 2199 // proxy resolver. |
2204 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2200 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2205 factory->pending_requests()[0]->script_data()->utf16()); | 2201 factory->pending_requests()[0]->script_data()->utf16()); |
2206 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2202 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2207 | 2203 |
2208 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2204 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2209 EXPECT_EQ(GURL("http://request3"), resolver.pending_jobs()[0]->url()); | 2205 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url()); |
2210 | 2206 |
2211 // Complete all the jobs. | 2207 // Complete all the requests. |
2212 resolver.pending_jobs()[0]->results()->UseNamedProxy("request3:80"); | 2208 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80"); |
2213 resolver.pending_jobs()[0]->CompleteNow(OK); | 2209 resolver.pending_requests()[0]->CompleteNow(OK); |
2214 | 2210 |
2215 EXPECT_EQ(OK, callback3.WaitForResult()); | 2211 EXPECT_EQ(OK, callback3.WaitForResult()); |
2216 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 2212 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
2217 | 2213 |
2218 EXPECT_TRUE(resolver.cancelled_jobs().empty()); | 2214 EXPECT_TRUE(resolver.cancelled_requests().empty()); |
2219 | 2215 |
2220 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 2216 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
2221 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 2217 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
2222 | 2218 |
2223 TestNetLogEntry::List entries1; | 2219 TestNetLogEntry::List entries1; |
2224 log1.GetEntries(&entries1); | 2220 log1.GetEntries(&entries1); |
2225 | 2221 |
2226 // Check the NetLog for request 1 (which was cancelled) got filled properly. | 2222 // Check the NetLog for request 1 (which was cancelled) got filled properly. |
2227 EXPECT_EQ(4u, entries1.size()); | 2223 EXPECT_EQ(4u, entries1.size()); |
2228 EXPECT_TRUE(LogContainsBeginEvent( | 2224 EXPECT_TRUE(LogContainsBeginEvent( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2283 | 2279 |
2284 // Next it should be trying the custom PAC url. | 2280 // Next it should be trying the custom PAC url. |
2285 EXPECT_TRUE(fetcher->has_pending_request()); | 2281 EXPECT_TRUE(fetcher->has_pending_request()); |
2286 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2282 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2287 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2283 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2288 | 2284 |
2289 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2285 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2290 factory->pending_requests()[0]->script_data()->utf16()); | 2286 factory->pending_requests()[0]->script_data()->utf16()); |
2291 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2287 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2292 | 2288 |
2293 // Now finally, the pending jobs should have been sent to the resolver | 2289 // Now finally, the pending requests should have been sent to the resolver |
2294 // (which was initialized with custom PAC script). | 2290 // (which was initialized with custom PAC script). |
2295 | 2291 |
2296 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); | 2292 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); |
2297 | 2293 |
2298 // Complete the pending jobs. | 2294 // Complete the pending requests. |
2299 jobs[url2]->results()->UseNamedProxy("request2:80"); | 2295 requests[url2]->results()->UseNamedProxy("request2:80"); |
2300 jobs[url2]->CompleteNow(OK); | 2296 requests[url2]->CompleteNow(OK); |
2301 jobs[url1]->results()->UseNamedProxy("request1:80"); | 2297 requests[url1]->results()->UseNamedProxy("request1:80"); |
2302 jobs[url1]->CompleteNow(OK); | 2298 requests[url1]->CompleteNow(OK); |
2303 | 2299 |
2304 // Verify that jobs ran as expected. | 2300 // Verify that requests ran as expected. |
2305 EXPECT_EQ(OK, callback1.WaitForResult()); | 2301 EXPECT_EQ(OK, callback1.WaitForResult()); |
2306 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2302 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2307 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); | 2303 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); |
2308 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); | 2304 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); |
2309 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); | 2305 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); |
2310 | 2306 |
2311 EXPECT_EQ(OK, callback2.WaitForResult()); | 2307 EXPECT_EQ(OK, callback2.WaitForResult()); |
2312 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2308 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2313 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); | 2309 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); |
2314 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); | 2310 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2364 | 2360 |
2365 // Next it should be trying the custom PAC url. | 2361 // Next it should be trying the custom PAC url. |
2366 EXPECT_TRUE(fetcher->has_pending_request()); | 2362 EXPECT_TRUE(fetcher->has_pending_request()); |
2367 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2363 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2368 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2364 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2369 | 2365 |
2370 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2366 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2371 factory->pending_requests()[0]->script_data()->utf16()); | 2367 factory->pending_requests()[0]->script_data()->utf16()); |
2372 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2368 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2373 | 2369 |
2374 // Now finally, the pending jobs should have been sent to the resolver | 2370 // Now finally, the pending requests should have been sent to the resolver |
2375 // (which was initialized with custom PAC script). | 2371 // (which was initialized with custom PAC script). |
2376 | 2372 |
2377 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); | 2373 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); |
2378 | 2374 |
2379 // Complete the pending jobs. | 2375 // Complete the pending requests. |
2380 jobs[url2]->results()->UseNamedProxy("request2:80"); | 2376 requests[url2]->results()->UseNamedProxy("request2:80"); |
2381 jobs[url2]->CompleteNow(OK); | 2377 requests[url2]->CompleteNow(OK); |
2382 jobs[url1]->results()->UseNamedProxy("request1:80"); | 2378 requests[url1]->results()->UseNamedProxy("request1:80"); |
2383 jobs[url1]->CompleteNow(OK); | 2379 requests[url1]->CompleteNow(OK); |
2384 | 2380 |
2385 // Verify that jobs ran as expected. | 2381 // Verify that requests ran as expected. |
2386 EXPECT_EQ(OK, callback1.WaitForResult()); | 2382 EXPECT_EQ(OK, callback1.WaitForResult()); |
2387 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2383 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2388 | 2384 |
2389 EXPECT_EQ(OK, callback2.WaitForResult()); | 2385 EXPECT_EQ(OK, callback2.WaitForResult()); |
2390 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2386 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2391 } | 2387 } |
2392 | 2388 |
2393 // Test that if all of auto-detect, a custom PAC script, and manual settings | 2389 // Test that if all of auto-detect, a custom PAC script, and manual settings |
2394 // are given, then we will try them in that order. | 2390 // are given, then we will try them in that order. |
2395 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { | 2391 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { |
2396 ProxyConfig config; | 2392 ProxyConfig config; |
2397 config.set_auto_detect(true); | 2393 config.set_auto_detect(true); |
2398 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2394 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
2399 config.proxy_rules().ParseFromString("http=foopy:80"); | 2395 config.proxy_rules().ParseFromString("http=foopy:80"); |
2400 | 2396 |
2401 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2397 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2402 MockAsyncProxyResolverFactory* factory = | 2398 MockAsyncProxyResolverFactory* factory = |
2403 new MockAsyncProxyResolverFactory(true); | 2399 new MockAsyncProxyResolverFactory(true); |
2404 ProxyService service(make_scoped_ptr(config_service), | 2400 ProxyService service(make_scoped_ptr(config_service), |
2405 make_scoped_ptr(factory), NULL); | 2401 make_scoped_ptr(factory), NULL); |
2406 | 2402 |
2407 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2403 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2408 service.SetProxyScriptFetchers( | 2404 service.SetProxyScriptFetchers( |
2409 fetcher, make_scoped_ptr(new DoNothingDhcpProxyScriptFetcher())); | 2405 fetcher, make_scoped_ptr(new DoNothingDhcpProxyScriptFetcher())); |
2410 | 2406 |
2411 // Start 2 jobs. | 2407 // Start 2 requests. |
2412 | 2408 |
2413 ProxyInfo info1; | 2409 ProxyInfo info1; |
2414 TestCompletionCallback callback1; | 2410 TestCompletionCallback callback1; |
2415 int rv = | 2411 int rv = |
2416 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2412 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
2417 callback1.callback(), NULL, NULL, BoundNetLog()); | 2413 callback1.callback(), NULL, NULL, BoundNetLog()); |
2418 EXPECT_EQ(ERR_IO_PENDING, rv); | 2414 EXPECT_EQ(ERR_IO_PENDING, rv); |
2419 | 2415 |
2420 ProxyInfo info2; | 2416 ProxyInfo info2; |
2421 TestCompletionCallback callback2; | 2417 TestCompletionCallback callback2; |
(...skipping 13 matching lines...) Expand all Loading... |
2435 | 2431 |
2436 // Next it should be trying the custom PAC url -- fail the download. | 2432 // Next it should be trying the custom PAC url -- fail the download. |
2437 EXPECT_TRUE(fetcher->has_pending_request()); | 2433 EXPECT_TRUE(fetcher->has_pending_request()); |
2438 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2434 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2439 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2435 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2440 | 2436 |
2441 // Since we never managed to initialize a resolver, nothing should have been | 2437 // Since we never managed to initialize a resolver, nothing should have been |
2442 // sent to it. | 2438 // sent to it. |
2443 ASSERT_EQ(0u, factory->pending_requests().size()); | 2439 ASSERT_EQ(0u, factory->pending_requests().size()); |
2444 | 2440 |
2445 // Verify that jobs ran as expected -- they should have fallen back to | 2441 // Verify that requests ran as expected -- they should have fallen back to |
2446 // the manual proxy configuration for HTTP urls. | 2442 // the manual proxy configuration for HTTP urls. |
2447 EXPECT_EQ(OK, callback1.WaitForResult()); | 2443 EXPECT_EQ(OK, callback1.WaitForResult()); |
2448 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); | 2444 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); |
2449 | 2445 |
2450 EXPECT_EQ(OK, callback2.WaitForResult()); | 2446 EXPECT_EQ(OK, callback2.WaitForResult()); |
2451 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); | 2447 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); |
2452 } | 2448 } |
2453 | 2449 |
2454 // Test that the bypass rules are NOT applied when using autodetect. | 2450 // Test that the bypass rules are NOT applied when using autodetect. |
2455 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { | 2451 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { |
(...skipping 28 matching lines...) Expand all Loading... |
2484 | 2480 |
2485 // It should be trying to auto-detect first -- succeed the download. | 2481 // It should be trying to auto-detect first -- succeed the download. |
2486 EXPECT_TRUE(fetcher->has_pending_request()); | 2482 EXPECT_TRUE(fetcher->has_pending_request()); |
2487 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2483 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2488 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2484 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2489 | 2485 |
2490 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2486 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2491 factory->pending_requests()[0]->script_data()->utf16()); | 2487 factory->pending_requests()[0]->script_data()->utf16()); |
2492 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2488 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2493 | 2489 |
2494 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2490 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2495 EXPECT_EQ(GURL("http://www.google.com"), resolver.pending_jobs()[0]->url()); | 2491 EXPECT_EQ(GURL("http://www.google.com"), |
| 2492 resolver.pending_requests()[0]->url()); |
2496 | 2493 |
2497 // Complete the pending request. | 2494 // Complete the pending request. |
2498 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); | 2495 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2499 resolver.pending_jobs()[0]->CompleteNow(OK); | 2496 resolver.pending_requests()[0]->CompleteNow(OK); |
2500 | 2497 |
2501 // Verify that request ran as expected. | 2498 // Verify that request ran as expected. |
2502 EXPECT_EQ(OK, callback1.WaitForResult()); | 2499 EXPECT_EQ(OK, callback1.WaitForResult()); |
2503 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2500 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2504 | 2501 |
2505 // Start another request, it should pickup the bypass item. | 2502 // Start another request, it should pickup the bypass item. |
2506 ProxyInfo info2; | 2503 ProxyInfo info2; |
2507 TestCompletionCallback callback2; | 2504 TestCompletionCallback callback2; |
2508 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2, | 2505 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2, |
2509 callback2.callback(), NULL, NULL, BoundNetLog()); | 2506 callback2.callback(), NULL, NULL, BoundNetLog()); |
2510 EXPECT_EQ(ERR_IO_PENDING, rv); | 2507 EXPECT_EQ(ERR_IO_PENDING, rv); |
2511 | 2508 |
2512 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2509 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2513 EXPECT_EQ(GURL("http://www.google.com"), resolver.pending_jobs()[0]->url()); | 2510 EXPECT_EQ(GURL("http://www.google.com"), |
| 2511 resolver.pending_requests()[0]->url()); |
2514 | 2512 |
2515 // Complete the pending request. | 2513 // Complete the pending request. |
2516 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); | 2514 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2517 resolver.pending_jobs()[0]->CompleteNow(OK); | 2515 resolver.pending_requests()[0]->CompleteNow(OK); |
2518 | 2516 |
2519 EXPECT_EQ(OK, callback2.WaitForResult()); | 2517 EXPECT_EQ(OK, callback2.WaitForResult()); |
2520 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2518 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2521 } | 2519 } |
2522 | 2520 |
2523 // Delete the ProxyService while InitProxyResolver has an outstanding | 2521 // Delete the ProxyService while InitProxyResolver has an outstanding |
2524 // request to the script fetcher. When run under valgrind, should not | 2522 // request to the script fetcher. When run under valgrind, should not |
2525 // have any memory errors (used to be that the ProxyScriptFetcher was | 2523 // have any memory errors (used to be that the ProxyScriptFetcher was |
2526 // being deleted prior to the InitProxyResolver). | 2524 // being deleted prior to the InitProxyResolver). |
2527 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { | 2525 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2629 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, | 2627 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, |
2630 callback1.callback(), NULL, NULL, BoundNetLog()); | 2628 callback1.callback(), NULL, NULL, BoundNetLog()); |
2631 EXPECT_EQ(ERR_IO_PENDING, rv); | 2629 EXPECT_EQ(ERR_IO_PENDING, rv); |
2632 | 2630 |
2633 // Successfully set the autodetect script. | 2631 // Successfully set the autodetect script. |
2634 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2632 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2635 factory->pending_requests()[0]->script_data()->type()); | 2633 factory->pending_requests()[0]->script_data()->type()); |
2636 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2634 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2637 | 2635 |
2638 // Complete the pending request. | 2636 // Complete the pending request. |
2639 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2637 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2640 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); | 2638 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2641 resolver.pending_jobs()[0]->CompleteNow(OK); | 2639 resolver.pending_requests()[0]->CompleteNow(OK); |
2642 | 2640 |
2643 // Verify that request ran as expected. | 2641 // Verify that request ran as expected. |
2644 EXPECT_EQ(OK, callback1.WaitForResult()); | 2642 EXPECT_EQ(OK, callback1.WaitForResult()); |
2645 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2643 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2646 | 2644 |
2647 // Force the ProxyService to pull down a new proxy configuration. | 2645 // Force the ProxyService to pull down a new proxy configuration. |
2648 // (Even though the configuration isn't old/bad). | 2646 // (Even though the configuration isn't old/bad). |
2649 // | 2647 // |
2650 // This new configuration no longer has auto_detect set, so | 2648 // This new configuration no longer has auto_detect set, so |
2651 // jobs should complete synchronously now as direct-connect. | 2649 // requests should complete synchronously now as direct-connect. |
2652 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2650 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2653 | 2651 |
2654 // Start another request -- the effective configuration has changed. | 2652 // Start another request -- the effective configuration has changed. |
2655 ProxyInfo info2; | 2653 ProxyInfo info2; |
2656 TestCompletionCallback callback2; | 2654 TestCompletionCallback callback2; |
2657 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2, | 2655 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2, |
2658 callback2.callback(), NULL, NULL, BoundNetLog()); | 2656 callback2.callback(), NULL, NULL, BoundNetLog()); |
2659 EXPECT_EQ(OK, rv); | 2657 EXPECT_EQ(OK, rv); |
2660 | 2658 |
2661 EXPECT_TRUE(info2.is_direct()); | 2659 EXPECT_TRUE(info2.is_direct()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2702 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2700 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2703 // PAC script download completion. | 2701 // PAC script download completion. |
2704 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2702 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2705 | 2703 |
2706 // Now that the PAC script is downloaded, the request will have been sent to | 2704 // Now that the PAC script is downloaded, the request will have been sent to |
2707 // the proxy resolver. | 2705 // the proxy resolver. |
2708 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2706 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2709 factory->pending_requests()[0]->script_data()->utf16()); | 2707 factory->pending_requests()[0]->script_data()->utf16()); |
2710 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2708 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2711 | 2709 |
2712 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2710 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2713 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); | 2711 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
2714 | 2712 |
2715 // Complete the pending request. | 2713 // Complete the pending request. |
2716 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); | 2714 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2717 resolver.pending_jobs()[0]->CompleteNow(OK); | 2715 resolver.pending_requests()[0]->CompleteNow(OK); |
2718 | 2716 |
2719 // Wait for completion callback, and verify that the request ran as expected. | 2717 // Wait for completion callback, and verify that the request ran as expected. |
2720 EXPECT_EQ(OK, callback1.WaitForResult()); | 2718 EXPECT_EQ(OK, callback1.WaitForResult()); |
2721 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2719 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2722 | 2720 |
2723 // Now simluate a change in the network. The ProxyConfigService is still | 2721 // Now simluate a change in the network. The ProxyConfigService is still |
2724 // going to return the same PAC URL as before, but this URL needs to be | 2722 // going to return the same PAC URL as before, but this URL needs to be |
2725 // refetched on the new network. | 2723 // refetched on the new network. |
2726 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2724 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2727 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 2725 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
(...skipping 16 matching lines...) Expand all Loading... |
2744 // Simulate the PAC script fetch as having completed (this time with | 2742 // Simulate the PAC script fetch as having completed (this time with |
2745 // different data). | 2743 // different data). |
2746 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 2744 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
2747 | 2745 |
2748 // Now that the PAC script is downloaded, the second request will have been | 2746 // Now that the PAC script is downloaded, the second request will have been |
2749 // sent to the proxy resolver. | 2747 // sent to the proxy resolver. |
2750 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2748 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
2751 factory->pending_requests()[0]->script_data()->utf16()); | 2749 factory->pending_requests()[0]->script_data()->utf16()); |
2752 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2750 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2753 | 2751 |
2754 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2752 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2755 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); | 2753 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
2756 | 2754 |
2757 // Complete the pending second request. | 2755 // Complete the pending second request. |
2758 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); | 2756 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2759 resolver.pending_jobs()[0]->CompleteNow(OK); | 2757 resolver.pending_requests()[0]->CompleteNow(OK); |
2760 | 2758 |
2761 // Wait for completion callback, and verify that the request ran as expected. | 2759 // Wait for completion callback, and verify that the request ran as expected. |
2762 EXPECT_EQ(OK, callback2.WaitForResult()); | 2760 EXPECT_EQ(OK, callback2.WaitForResult()); |
2763 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2761 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2764 | 2762 |
2765 // Check that the expected events were output to the log stream. In particular | 2763 // Check that the expected events were output to the log stream. In particular |
2766 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial | 2764 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial |
2767 // setup), and NOT a second time when the IP address changed. | 2765 // setup), and NOT a second time when the IP address changed. |
2768 TestNetLogEntry::List entries; | 2766 TestNetLogEntry::List entries; |
2769 log.GetEntries(&entries); | 2767 log.GetEntries(&entries); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2862 // DIRECT. | 2860 // DIRECT. |
2863 | 2861 |
2864 // Start a second request. | 2862 // Start a second request. |
2865 ProxyInfo info2; | 2863 ProxyInfo info2; |
2866 TestCompletionCallback callback2; | 2864 TestCompletionCallback callback2; |
2867 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2865 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
2868 callback2.callback(), NULL, NULL, BoundNetLog()); | 2866 callback2.callback(), NULL, NULL, BoundNetLog()); |
2869 EXPECT_EQ(ERR_IO_PENDING, rv); | 2867 EXPECT_EQ(ERR_IO_PENDING, rv); |
2870 | 2868 |
2871 // Check that it was sent to the resolver. | 2869 // Check that it was sent to the resolver. |
2872 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2870 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2873 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); | 2871 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
2874 | 2872 |
2875 // Complete the pending second request. | 2873 // Complete the pending second request. |
2876 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); | 2874 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2877 resolver.pending_jobs()[0]->CompleteNow(OK); | 2875 resolver.pending_requests()[0]->CompleteNow(OK); |
2878 | 2876 |
2879 // Wait for completion callback, and verify that the request ran as expected. | 2877 // Wait for completion callback, and verify that the request ran as expected. |
2880 EXPECT_EQ(OK, callback2.WaitForResult()); | 2878 EXPECT_EQ(OK, callback2.WaitForResult()); |
2881 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2879 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2882 } | 2880 } |
2883 | 2881 |
2884 // This test verifies that the PAC script specified by the settings is | 2882 // This test verifies that the PAC script specified by the settings is |
2885 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 2883 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
2886 // however at a later time its *contents* change, we will eventually | 2884 // however at a later time its *contents* change, we will eventually |
2887 // re-configure the service to use the new script. | 2885 // re-configure the service to use the new script. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2925 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2923 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2926 // PAC script download completion. | 2924 // PAC script download completion. |
2927 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2925 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2928 | 2926 |
2929 // Now that the PAC script is downloaded, the request will have been sent to | 2927 // Now that the PAC script is downloaded, the request will have been sent to |
2930 // the proxy resolver. | 2928 // the proxy resolver. |
2931 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2929 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2932 factory->pending_requests()[0]->script_data()->utf16()); | 2930 factory->pending_requests()[0]->script_data()->utf16()); |
2933 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2931 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2934 | 2932 |
2935 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2933 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2936 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); | 2934 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
2937 | 2935 |
2938 // Complete the pending request. | 2936 // Complete the pending request. |
2939 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); | 2937 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
2940 resolver.pending_jobs()[0]->CompleteNow(OK); | 2938 resolver.pending_requests()[0]->CompleteNow(OK); |
2941 | 2939 |
2942 // Wait for completion callback, and verify that the request ran as expected. | 2940 // Wait for completion callback, and verify that the request ran as expected. |
2943 EXPECT_EQ(OK, callback1.WaitForResult()); | 2941 EXPECT_EQ(OK, callback1.WaitForResult()); |
2944 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2942 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2945 | 2943 |
2946 // At this point we have initialized the proxy service using a PAC script. | 2944 // At this point we have initialized the proxy service using a PAC script. |
2947 // | 2945 // |
2948 // A background task to periodically re-check the PAC script for validity will | 2946 // A background task to periodically re-check the PAC script for validity will |
2949 // have been started. We will now wait for the next download attempt to start. | 2947 // have been started. We will now wait for the next download attempt to start. |
2950 // | 2948 // |
2951 // Note that we shouldn't have to wait long here, since our test enables a | 2949 // Note that we shouldn't have to wait long here, since our test enables a |
2952 // special unit-test mode. | 2950 // special unit-test mode. |
2953 fetcher->WaitUntilFetch(); | 2951 fetcher->WaitUntilFetch(); |
2954 | 2952 |
2955 ASSERT_TRUE(factory->pending_requests().empty()); | 2953 ASSERT_TRUE(factory->pending_requests().empty()); |
2956 ASSERT_TRUE(resolver.pending_jobs().empty()); | 2954 ASSERT_TRUE(resolver.pending_requests().empty()); |
2957 | 2955 |
2958 // Make sure that our background checker is trying to download the expected | 2956 // Make sure that our background checker is trying to download the expected |
2959 // PAC script (same one as before). This time we will simulate a successful | 2957 // PAC script (same one as before). This time we will simulate a successful |
2960 // download of a DIFFERENT script. | 2958 // download of a DIFFERENT script. |
2961 EXPECT_TRUE(fetcher->has_pending_request()); | 2959 EXPECT_TRUE(fetcher->has_pending_request()); |
2962 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2960 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2963 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 2961 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
2964 | 2962 |
2965 base::MessageLoop::current()->RunUntilIdle(); | 2963 base::MessageLoop::current()->RunUntilIdle(); |
2966 | 2964 |
2967 // Now that the PAC script is downloaded, it should be used to initialize the | 2965 // Now that the PAC script is downloaded, it should be used to initialize the |
2968 // ProxyResolver. Simulate a successful parse. | 2966 // ProxyResolver. Simulate a successful parse. |
2969 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2967 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
2970 factory->pending_requests()[0]->script_data()->utf16()); | 2968 factory->pending_requests()[0]->script_data()->utf16()); |
2971 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2969 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2972 | 2970 |
2973 // At this point the ProxyService should have re-configured itself to use the | 2971 // At this point the ProxyService should have re-configured itself to use the |
2974 // new PAC script. | 2972 // new PAC script. |
2975 | 2973 |
2976 // Start a second request. | 2974 // Start a second request. |
2977 ProxyInfo info2; | 2975 ProxyInfo info2; |
2978 TestCompletionCallback callback2; | 2976 TestCompletionCallback callback2; |
2979 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2977 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
2980 callback2.callback(), NULL, NULL, BoundNetLog()); | 2978 callback2.callback(), NULL, NULL, BoundNetLog()); |
2981 EXPECT_EQ(ERR_IO_PENDING, rv); | 2979 EXPECT_EQ(ERR_IO_PENDING, rv); |
2982 | 2980 |
2983 // Check that it was sent to the resolver. | 2981 // Check that it was sent to the resolver. |
2984 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 2982 ASSERT_EQ(1u, resolver.pending_requests().size()); |
2985 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); | 2983 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
2986 | 2984 |
2987 // Complete the pending second request. | 2985 // Complete the pending second request. |
2988 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); | 2986 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
2989 resolver.pending_jobs()[0]->CompleteNow(OK); | 2987 resolver.pending_requests()[0]->CompleteNow(OK); |
2990 | 2988 |
2991 // Wait for completion callback, and verify that the request ran as expected. | 2989 // Wait for completion callback, and verify that the request ran as expected. |
2992 EXPECT_EQ(OK, callback2.WaitForResult()); | 2990 EXPECT_EQ(OK, callback2.WaitForResult()); |
2993 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2991 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2994 } | 2992 } |
2995 | 2993 |
2996 // This test verifies that the PAC script specified by the settings is | 2994 // This test verifies that the PAC script specified by the settings is |
2997 // periodically polled for changes. Specifically, if the initial fetch succeeds | 2995 // periodically polled for changes. Specifically, if the initial fetch succeeds |
2998 // and so does the next poll, however the contents of the downloaded script | 2996 // and so does the next poll, however the contents of the downloaded script |
2999 // have NOT changed, then we do not bother to re-initialize the proxy resolver. | 2997 // have NOT changed, then we do not bother to re-initialize the proxy resolver. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3037 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3035 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3038 // PAC script download completion. | 3036 // PAC script download completion. |
3039 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3037 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3040 | 3038 |
3041 // Now that the PAC script is downloaded, the request will have been sent to | 3039 // Now that the PAC script is downloaded, the request will have been sent to |
3042 // the proxy resolver. | 3040 // the proxy resolver. |
3043 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3041 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3044 factory->pending_requests()[0]->script_data()->utf16()); | 3042 factory->pending_requests()[0]->script_data()->utf16()); |
3045 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3043 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3046 | 3044 |
3047 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 3045 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3048 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); | 3046 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
3049 | 3047 |
3050 // Complete the pending request. | 3048 // Complete the pending request. |
3051 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); | 3049 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
3052 resolver.pending_jobs()[0]->CompleteNow(OK); | 3050 resolver.pending_requests()[0]->CompleteNow(OK); |
3053 | 3051 |
3054 // Wait for completion callback, and verify that the request ran as expected. | 3052 // Wait for completion callback, and verify that the request ran as expected. |
3055 EXPECT_EQ(OK, callback1.WaitForResult()); | 3053 EXPECT_EQ(OK, callback1.WaitForResult()); |
3056 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3054 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3057 | 3055 |
3058 // At this point we have initialized the proxy service using a PAC script. | 3056 // At this point we have initialized the proxy service using a PAC script. |
3059 // | 3057 // |
3060 // A background task to periodically re-check the PAC script for validity will | 3058 // A background task to periodically re-check the PAC script for validity will |
3061 // have been started. We will now wait for the next download attempt to start. | 3059 // have been started. We will now wait for the next download attempt to start. |
3062 // | 3060 // |
3063 // Note that we shouldn't have to wait long here, since our test enables a | 3061 // Note that we shouldn't have to wait long here, since our test enables a |
3064 // special unit-test mode. | 3062 // special unit-test mode. |
3065 fetcher->WaitUntilFetch(); | 3063 fetcher->WaitUntilFetch(); |
3066 | 3064 |
3067 ASSERT_TRUE(factory->pending_requests().empty()); | 3065 ASSERT_TRUE(factory->pending_requests().empty()); |
3068 ASSERT_TRUE(resolver.pending_jobs().empty()); | 3066 ASSERT_TRUE(resolver.pending_requests().empty()); |
3069 | 3067 |
3070 // Make sure that our background checker is trying to download the expected | 3068 // Make sure that our background checker is trying to download the expected |
3071 // PAC script (same one as before). We will simulate the same response as | 3069 // PAC script (same one as before). We will simulate the same response as |
3072 // last time (i.e. the script is unchanged). | 3070 // last time (i.e. the script is unchanged). |
3073 EXPECT_TRUE(fetcher->has_pending_request()); | 3071 EXPECT_TRUE(fetcher->has_pending_request()); |
3074 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3072 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3075 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3073 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3076 | 3074 |
3077 base::MessageLoop::current()->RunUntilIdle(); | 3075 base::MessageLoop::current()->RunUntilIdle(); |
3078 | 3076 |
3079 ASSERT_TRUE(factory->pending_requests().empty()); | 3077 ASSERT_TRUE(factory->pending_requests().empty()); |
3080 ASSERT_TRUE(resolver.pending_jobs().empty()); | 3078 ASSERT_TRUE(resolver.pending_requests().empty()); |
3081 | 3079 |
3082 // At this point the ProxyService is still running the same PAC script as | 3080 // At this point the ProxyService is still running the same PAC script as |
3083 // before. | 3081 // before. |
3084 | 3082 |
3085 // Start a second request. | 3083 // Start a second request. |
3086 ProxyInfo info2; | 3084 ProxyInfo info2; |
3087 TestCompletionCallback callback2; | 3085 TestCompletionCallback callback2; |
3088 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 3086 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
3089 callback2.callback(), NULL, NULL, BoundNetLog()); | 3087 callback2.callback(), NULL, NULL, BoundNetLog()); |
3090 EXPECT_EQ(ERR_IO_PENDING, rv); | 3088 EXPECT_EQ(ERR_IO_PENDING, rv); |
3091 | 3089 |
3092 // Check that it was sent to the resolver. | 3090 // Check that it was sent to the resolver. |
3093 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 3091 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3094 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); | 3092 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
3095 | 3093 |
3096 // Complete the pending second request. | 3094 // Complete the pending second request. |
3097 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); | 3095 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
3098 resolver.pending_jobs()[0]->CompleteNow(OK); | 3096 resolver.pending_requests()[0]->CompleteNow(OK); |
3099 | 3097 |
3100 // Wait for completion callback, and verify that the request ran as expected. | 3098 // Wait for completion callback, and verify that the request ran as expected. |
3101 EXPECT_EQ(OK, callback2.WaitForResult()); | 3099 EXPECT_EQ(OK, callback2.WaitForResult()); |
3102 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3100 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3103 } | 3101 } |
3104 | 3102 |
3105 // This test verifies that the PAC script specified by the settings is | 3103 // This test verifies that the PAC script specified by the settings is |
3106 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 3104 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
3107 // however at a later time it starts to fail, we should re-configure the | 3105 // however at a later time it starts to fail, we should re-configure the |
3108 // ProxyService to stop using that PAC script. | 3106 // ProxyService to stop using that PAC script. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3146 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3144 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3147 // PAC script download completion. | 3145 // PAC script download completion. |
3148 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3146 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3149 | 3147 |
3150 // Now that the PAC script is downloaded, the request will have been sent to | 3148 // Now that the PAC script is downloaded, the request will have been sent to |
3151 // the proxy resolver. | 3149 // the proxy resolver. |
3152 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3150 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3153 factory->pending_requests()[0]->script_data()->utf16()); | 3151 factory->pending_requests()[0]->script_data()->utf16()); |
3154 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3152 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3155 | 3153 |
3156 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 3154 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3157 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); | 3155 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
3158 | 3156 |
3159 // Complete the pending request. | 3157 // Complete the pending request. |
3160 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); | 3158 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
3161 resolver.pending_jobs()[0]->CompleteNow(OK); | 3159 resolver.pending_requests()[0]->CompleteNow(OK); |
3162 | 3160 |
3163 // Wait for completion callback, and verify that the request ran as expected. | 3161 // Wait for completion callback, and verify that the request ran as expected. |
3164 EXPECT_EQ(OK, callback1.WaitForResult()); | 3162 EXPECT_EQ(OK, callback1.WaitForResult()); |
3165 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3163 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3166 | 3164 |
3167 // At this point we have initialized the proxy service using a PAC script. | 3165 // At this point we have initialized the proxy service using a PAC script. |
3168 // | 3166 // |
3169 // A background task to periodically re-check the PAC script for validity will | 3167 // A background task to periodically re-check the PAC script for validity will |
3170 // have been started. We will now wait for the next download attempt to start. | 3168 // have been started. We will now wait for the next download attempt to start. |
3171 // | 3169 // |
3172 // Note that we shouldn't have to wait long here, since our test enables a | 3170 // Note that we shouldn't have to wait long here, since our test enables a |
3173 // special unit-test mode. | 3171 // special unit-test mode. |
3174 fetcher->WaitUntilFetch(); | 3172 fetcher->WaitUntilFetch(); |
3175 | 3173 |
3176 ASSERT_TRUE(factory->pending_requests().empty()); | 3174 ASSERT_TRUE(factory->pending_requests().empty()); |
3177 ASSERT_TRUE(resolver.pending_jobs().empty()); | 3175 ASSERT_TRUE(resolver.pending_requests().empty()); |
3178 | 3176 |
3179 // Make sure that our background checker is trying to download the expected | 3177 // Make sure that our background checker is trying to download the expected |
3180 // PAC script (same one as before). This time we will simulate a failure | 3178 // PAC script (same one as before). This time we will simulate a failure |
3181 // to download the script. | 3179 // to download the script. |
3182 EXPECT_TRUE(fetcher->has_pending_request()); | 3180 EXPECT_TRUE(fetcher->has_pending_request()); |
3183 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3181 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3184 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 3182 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
3185 | 3183 |
3186 base::MessageLoop::current()->RunUntilIdle(); | 3184 base::MessageLoop::current()->RunUntilIdle(); |
3187 | 3185 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3300 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3298 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3301 // PAC script download completion. | 3299 // PAC script download completion. |
3302 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3300 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3303 | 3301 |
3304 // Now that the PAC script is downloaded, the request will have been sent to | 3302 // Now that the PAC script is downloaded, the request will have been sent to |
3305 // the proxy resolver. | 3303 // the proxy resolver. |
3306 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3304 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3307 factory->pending_requests()[0]->script_data()->utf16()); | 3305 factory->pending_requests()[0]->script_data()->utf16()); |
3308 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3306 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3309 | 3307 |
3310 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 3308 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3311 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); | 3309 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
3312 | 3310 |
3313 // Complete the pending request. | 3311 // Complete the pending request. |
3314 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); | 3312 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
3315 resolver.pending_jobs()[0]->CompleteNow(OK); | 3313 resolver.pending_requests()[0]->CompleteNow(OK); |
3316 | 3314 |
3317 // Wait for completion callback, and verify that the request ran as expected. | 3315 // Wait for completion callback, and verify that the request ran as expected. |
3318 EXPECT_EQ(OK, callback1.WaitForResult()); | 3316 EXPECT_EQ(OK, callback1.WaitForResult()); |
3319 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3317 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3320 | 3318 |
3321 // At this point we have initialized the proxy service using a PAC script. | 3319 // At this point we have initialized the proxy service using a PAC script. |
3322 // Our PAC poller is set to update ONLY in response to network activity, | 3320 // Our PAC poller is set to update ONLY in response to network activity, |
3323 // (i.e. another call to ResolveProxy()). | 3321 // (i.e. another call to ResolveProxy()). |
3324 | 3322 |
3325 ASSERT_FALSE(fetcher->has_pending_request()); | 3323 ASSERT_FALSE(fetcher->has_pending_request()); |
3326 ASSERT_TRUE(factory->pending_requests().empty()); | 3324 ASSERT_TRUE(factory->pending_requests().empty()); |
3327 ASSERT_TRUE(resolver.pending_jobs().empty()); | 3325 ASSERT_TRUE(resolver.pending_requests().empty()); |
3328 | 3326 |
3329 // Start a second request. | 3327 // Start a second request. |
3330 ProxyInfo info2; | 3328 ProxyInfo info2; |
3331 TestCompletionCallback callback2; | 3329 TestCompletionCallback callback2; |
3332 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 3330 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
3333 callback2.callback(), NULL, NULL, BoundNetLog()); | 3331 callback2.callback(), NULL, NULL, BoundNetLog()); |
3334 EXPECT_EQ(ERR_IO_PENDING, rv); | 3332 EXPECT_EQ(ERR_IO_PENDING, rv); |
3335 | 3333 |
3336 // This request should have sent work to the resolver; complete it. | 3334 // This request should have sent work to the resolver; complete it. |
3337 ASSERT_EQ(1u, resolver.pending_jobs().size()); | 3335 ASSERT_EQ(1u, resolver.pending_requests().size()); |
3338 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); | 3336 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
3339 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); | 3337 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
3340 resolver.pending_jobs()[0]->CompleteNow(OK); | 3338 resolver.pending_requests()[0]->CompleteNow(OK); |
3341 | 3339 |
3342 EXPECT_EQ(OK, callback2.WaitForResult()); | 3340 EXPECT_EQ(OK, callback2.WaitForResult()); |
3343 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3341 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3344 | 3342 |
3345 // In response to getting that resolve request, the poller should have | 3343 // In response to getting that resolve request, the poller should have |
3346 // started the next poll, and made it as far as to request the download. | 3344 // started the next poll, and made it as far as to request the download. |
3347 | 3345 |
3348 EXPECT_TRUE(fetcher->has_pending_request()); | 3346 EXPECT_TRUE(fetcher->has_pending_request()); |
3349 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3347 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3350 | 3348 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3412 url, LOAD_NORMAL, &info, NULL, log.bound()); | 3410 url, LOAD_NORMAL, &info, NULL, log.bound()); |
3413 EXPECT_TRUE(synchronous_success); | 3411 EXPECT_TRUE(synchronous_success); |
3414 EXPECT_FALSE(info.is_direct()); | 3412 EXPECT_FALSE(info.is_direct()); |
3415 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); | 3413 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); |
3416 | 3414 |
3417 // No request should have been queued. | 3415 // No request should have been queued. |
3418 EXPECT_EQ(0u, factory->pending_requests().size()); | 3416 EXPECT_EQ(0u, factory->pending_requests().size()); |
3419 } | 3417 } |
3420 | 3418 |
3421 } // namespace net | 3419 } // namespace net |
OLD | NEW |