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 <string> | 8 #include <string> |
9 #include <vector> | 9 #include <vector> |
10 | 10 |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
285 int proxy_fallback_net_error() const { | 285 int proxy_fallback_net_error() const { |
286 return proxy_fallback_net_error_; | 286 return proxy_fallback_net_error_; |
287 } | 287 } |
288 | 288 |
289 private: | 289 private: |
290 bool on_proxy_fallback_called_; | 290 bool on_proxy_fallback_called_; |
291 ProxyServer proxy_server_; | 291 ProxyServer proxy_server_; |
292 int proxy_fallback_net_error_; | 292 int proxy_fallback_net_error_; |
293 }; | 293 }; |
294 | 294 |
295 using RequestMap = | 295 using JobMap = std::map<GURL, MockAsyncProxyResolver::Job*>; |
296 std::map<GURL, scoped_refptr<MockAsyncProxyResolver::Request>>; | |
297 | 296 |
298 // Given a list of requests |list| from a MockAsyncProxyResolver and a list of | 297 // Given a jobmap and a list of target URLs |urls|, asserts that the set of URLs |
299 // target URLs |_urls|, asserts that the set of URLs of the requests appearing | 298 // of the jobs appearing in |list| is exactly the set of URLs in |urls|. |
300 // in |list| is exactly the set of URLs in |_urls|, and produces a RequestMap in | 299 JobMap GetJobsForURLs(const JobMap& map, const std::vector<GURL>& urls) { |
301 // |*map| containing the requests corresponding to those target |_urls|. | 300 size_t a = urls.size(); |
302 // | 301 size_t b = map.size(); |
303 // Note that this function must return void to allow use of gtest's ASSERT_* | 302 if (a != b) { |
304 // macros inside it. | |
305 RequestMap GetRequestsForURLs( | |
306 const MockAsyncProxyResolver::RequestsList& requests, | |
307 const std::vector<GURL>& urls) { | |
308 RequestMap map; | |
309 | |
310 for (const auto& it : requests) | |
311 map[it->url()] = it; | |
312 | |
313 if (urls.size() != map.size()) { | |
314 ADD_FAILURE() << "map size (" << map.size() << ") != urls size (" | 303 ADD_FAILURE() << "map size (" << map.size() << ") != urls size (" |
315 << urls.size() << ")"; | 304 << urls.size() << ")"; |
316 return map; | 305 return map; |
317 } | 306 } |
318 for (const auto& it : urls) { | 307 for (const auto& it : urls) { |
319 if (map.count(it) != 1U) { | 308 if (map.count(it) != 1U) { |
320 ADD_FAILURE() << "url not in map: " << it.spec(); | 309 ADD_FAILURE() << "url not in map: " << it.spec(); |
321 break; | 310 break; |
322 } | 311 } |
323 } | 312 } |
324 return map; | 313 return map; |
325 } | 314 } |
326 | 315 |
327 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the | 316 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the |
328 // set of pending request URLs for |resolver| is exactly the supplied list of | 317 // set of pending request URLs for |resolver| is exactly the supplied list of |
329 // URLs and returns a map from URLs to the corresponding pending requests. | 318 // URLs and returns a map from URLs to the corresponding pending jobs. |
330 RequestMap GetPendingRequestsForURLs(const MockAsyncProxyResolver& resolver, | 319 JobMap GetPendingJobsForURLs(const MockAsyncProxyResolver& resolver, |
331 const GURL& url1 = GURL(), | 320 const GURL& url1 = GURL(), |
332 const GURL& url2 = GURL(), | 321 const GURL& url2 = GURL(), |
333 const GURL& url3 = GURL()) { | 322 const GURL& url3 = GURL()) { |
334 std::vector<GURL> urls; | 323 std::vector<GURL> urls; |
335 if (!url1.is_empty()) | 324 if (!url1.is_empty()) |
336 urls.push_back(url1); | 325 urls.push_back(url1); |
337 if (!url2.is_empty()) | 326 if (!url2.is_empty()) |
338 urls.push_back(url2); | 327 urls.push_back(url2); |
339 if (!url3.is_empty()) | 328 if (!url3.is_empty()) |
340 urls.push_back(url3); | 329 urls.push_back(url3); |
341 return GetRequestsForURLs(resolver.pending_requests(), urls); | 330 |
| 331 JobMap map; |
| 332 for (MockAsyncProxyResolver::Job* it : resolver.pending_jobs()) { |
| 333 DCHECK(it); |
| 334 map[it->url()] = it; |
| 335 } |
| 336 |
| 337 return GetJobsForURLs(map, urls); |
342 } | 338 } |
343 | 339 |
344 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the | 340 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the |
345 // set of cancelled request URLs for |resolver| is exactly the supplied list of | 341 // set of cancelled request URLs for |resolver| is exactly the supplied list of |
346 // URLs and returns a map from URLs to the corresponding cancelled requests. | 342 // URLs and returns a map from URLs to the corresponding cancelled jobs. |
347 RequestMap GetCancelledRequestsForURLs(const MockAsyncProxyResolver& resolver, | 343 JobMap GetCancelledJobsForURLs(const MockAsyncProxyResolver& resolver, |
348 const GURL& url1 = GURL(), | 344 const GURL& url1 = GURL(), |
349 const GURL& url2 = GURL(), | 345 const GURL& url2 = GURL(), |
350 const GURL& url3 = GURL()) { | 346 const GURL& url3 = GURL()) { |
351 std::vector<GURL> urls; | 347 std::vector<GURL> urls; |
352 if (!url1.is_empty()) | 348 if (!url1.is_empty()) |
353 urls.push_back(url1); | 349 urls.push_back(url1); |
354 if (!url2.is_empty()) | 350 if (!url2.is_empty()) |
355 urls.push_back(url2); | 351 urls.push_back(url2); |
356 if (!url3.is_empty()) | 352 if (!url3.is_empty()) |
357 urls.push_back(url3); | 353 urls.push_back(url3); |
358 return GetRequestsForURLs(resolver.cancelled_requests(), urls); | 354 |
| 355 JobMap map; |
| 356 for (const std::unique_ptr<MockAsyncProxyResolver::Job>& it : |
| 357 resolver.cancelled_jobs()) { |
| 358 DCHECK(it); |
| 359 map[it->url()] = it.get(); |
| 360 } |
| 361 |
| 362 return GetJobsForURLs(map, urls); |
359 } | 363 } |
360 | 364 |
361 } // namespace | 365 } // namespace |
362 | 366 |
363 TEST_F(ProxyServiceTest, Direct) { | 367 TEST_F(ProxyServiceTest, Direct) { |
364 MockAsyncProxyResolverFactory* factory = | 368 MockAsyncProxyResolverFactory* factory = |
365 new MockAsyncProxyResolverFactory(false); | 369 new MockAsyncProxyResolverFactory(false); |
366 ProxyService service( | 370 ProxyService service( |
367 base::MakeUnique<MockProxyConfigService>(ProxyConfig::CreateDirect()), | 371 base::MakeUnique<MockProxyConfigService>(ProxyConfig::CreateDirect()), |
368 base::WrapUnique(factory), nullptr); | 372 base::WrapUnique(factory), nullptr); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
418 // Verify that network delegate is invoked. | 422 // Verify that network delegate is invoked. |
419 TestResolveProxyDelegate delegate; | 423 TestResolveProxyDelegate delegate; |
420 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, | 424 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, |
421 &delegate, log.bound()); | 425 &delegate, log.bound()); |
422 EXPECT_TRUE(delegate.on_resolve_proxy_called()); | 426 EXPECT_TRUE(delegate.on_resolve_proxy_called()); |
423 EXPECT_EQ(&service, delegate.proxy_service()); | 427 EXPECT_EQ(&service, delegate.proxy_service()); |
424 EXPECT_EQ(delegate.method(), "GET"); | 428 EXPECT_EQ(delegate.method(), "GET"); |
425 | 429 |
426 // Verify that the ProxyDelegate's behavior is stateless across | 430 // Verify that the ProxyDelegate's behavior is stateless across |
427 // invocations of ResolveProxy. Start by having the callback add a proxy | 431 // invocations of ResolveProxy. Start by having the callback add a proxy |
428 // and checking that subsequent requests are not affected. | 432 // and checking that subsequent jobs are not affected. |
429 delegate.set_add_proxy(true); | 433 delegate.set_add_proxy(true); |
430 | 434 |
431 // Callback should interpose: | 435 // Callback should interpose: |
432 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, | 436 rv = service.ResolveProxy(url, "GET", &info, callback.callback(), nullptr, |
433 &delegate, log.bound()); | 437 &delegate, log.bound()); |
434 EXPECT_FALSE(info.is_direct()); | 438 EXPECT_FALSE(info.is_direct()); |
435 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); | 439 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); |
436 delegate.set_add_proxy(false); | 440 delegate.set_add_proxy(false); |
437 | 441 |
438 // Check non-bypassed URL: | 442 // Check non-bypassed URL: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
514 &request, nullptr, log.bound()); | 518 &request, nullptr, log.bound()); |
515 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 519 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
516 | 520 |
517 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 521 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
518 | 522 |
519 ASSERT_EQ(1u, factory->pending_requests().size()); | 523 ASSERT_EQ(1u, factory->pending_requests().size()); |
520 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 524 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
521 factory->pending_requests()[0]->script_data()->url()); | 525 factory->pending_requests()[0]->script_data()->url()); |
522 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 526 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
523 | 527 |
524 ASSERT_EQ(1u, resolver.pending_requests().size()); | 528 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
525 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 529 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
526 | 530 |
527 // Set the result in proxy resolver. | 531 // Set the result in proxy resolver. |
528 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 532 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy"); |
529 resolver.pending_requests()[0]->CompleteNow(OK); | 533 resolver.pending_jobs()[0]->CompleteNow(OK); |
530 | 534 |
531 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 535 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
532 EXPECT_FALSE(info.is_direct()); | 536 EXPECT_FALSE(info.is_direct()); |
533 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); | 537 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); |
534 EXPECT_TRUE(info.did_use_pac_script()); | 538 EXPECT_TRUE(info.did_use_pac_script()); |
535 | 539 |
536 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 540 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
537 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 541 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
538 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 542 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
539 | 543 |
(...skipping 29 matching lines...) Expand all Loading... |
569 ProxyInfo info; | 573 ProxyInfo info; |
570 TestCompletionCallback callback; | 574 TestCompletionCallback callback; |
571 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), | 575 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
572 nullptr, nullptr, NetLogWithSource()); | 576 nullptr, nullptr, NetLogWithSource()); |
573 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 577 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
574 | 578 |
575 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 579 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
576 factory->pending_requests()[0]->script_data()->url()); | 580 factory->pending_requests()[0]->script_data()->url()); |
577 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 581 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
578 | 582 |
579 ASSERT_EQ(1u, resolver.pending_requests().size()); | 583 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
580 // The URL should have been simplified, stripping the username/password/hash. | 584 // The URL should have been simplified, stripping the username/password/hash. |
581 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 585 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
582 resolver.pending_requests()[0]->url()); | 586 resolver.pending_jobs()[0]->url()); |
583 | 587 |
584 // We end here without ever completing the request -- destruction of | 588 // We end here without ever completing the request -- destruction of |
585 // ProxyService will cancel the outstanding request. | 589 // ProxyService will cancel the outstanding request. |
586 } | 590 } |
587 | 591 |
588 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 592 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
589 MockProxyConfigService* config_service = | 593 MockProxyConfigService* config_service = |
590 new MockProxyConfigService("http://foopy/proxy.pac"); | 594 new MockProxyConfigService("http://foopy/proxy.pac"); |
591 MockAsyncProxyResolver resolver; | 595 MockAsyncProxyResolver resolver; |
592 MockAsyncProxyResolverFactory* factory = | 596 MockAsyncProxyResolverFactory* factory = |
593 new MockAsyncProxyResolverFactory(false); | 597 new MockAsyncProxyResolverFactory(false); |
594 | 598 |
595 ProxyService service(base::WrapUnique(config_service), | 599 ProxyService service(base::WrapUnique(config_service), |
596 base::WrapUnique(factory), nullptr); | 600 base::WrapUnique(factory), nullptr); |
597 | 601 |
598 GURL url("http://www.google.com/"); | 602 GURL url("http://www.google.com/"); |
599 | 603 |
600 ProxyInfo info; | 604 ProxyInfo info; |
601 TestCompletionCallback callback1; | 605 TestCompletionCallback callback1; |
602 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 606 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
603 nullptr, nullptr, NetLogWithSource()); | 607 nullptr, nullptr, NetLogWithSource()); |
604 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 608 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
605 | 609 |
606 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 610 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
607 factory->pending_requests()[0]->script_data()->url()); | 611 factory->pending_requests()[0]->script_data()->url()); |
608 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 612 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
609 | 613 |
610 ASSERT_EQ(1u, resolver.pending_requests().size()); | 614 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
611 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 615 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
612 | 616 |
613 // Set the result in proxy resolver. | 617 // Set the result in proxy resolver. |
614 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 618 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy:8080"); |
615 resolver.pending_requests()[0]->CompleteNow(OK); | 619 resolver.pending_jobs()[0]->CompleteNow(OK); |
616 | 620 |
617 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 621 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
618 EXPECT_FALSE(info.is_direct()); | 622 EXPECT_FALSE(info.is_direct()); |
619 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 623 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
620 EXPECT_TRUE(info.did_use_pac_script()); | 624 EXPECT_TRUE(info.did_use_pac_script()); |
621 | 625 |
622 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 626 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
623 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 627 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
624 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 628 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
625 | 629 |
(...skipping 28 matching lines...) Expand all Loading... |
654 ProxyInfo info; | 658 ProxyInfo info; |
655 TestCompletionCallback callback1; | 659 TestCompletionCallback callback1; |
656 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 660 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
657 nullptr, nullptr, NetLogWithSource()); | 661 nullptr, nullptr, NetLogWithSource()); |
658 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 662 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
659 | 663 |
660 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 664 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
661 factory->pending_requests()[0]->script_data()->url()); | 665 factory->pending_requests()[0]->script_data()->url()); |
662 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 666 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
663 | 667 |
664 ASSERT_EQ(1u, resolver.pending_requests().size()); | 668 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
665 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 669 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
666 | 670 |
667 // Simulate a failure in the PAC executor. | 671 // Simulate a failure in the PAC executor. |
668 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); | 672 resolver.pending_jobs()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); |
669 | 673 |
670 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 674 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
671 | 675 |
672 // Since the PAC script was non-mandatory, we should have fallen-back to | 676 // Since the PAC script was non-mandatory, we should have fallen-back to |
673 // DIRECT. | 677 // DIRECT. |
674 EXPECT_TRUE(info.is_direct()); | 678 EXPECT_TRUE(info.is_direct()); |
675 EXPECT_TRUE(info.did_use_pac_script()); | 679 EXPECT_TRUE(info.did_use_pac_script()); |
676 EXPECT_EQ(1, info.config_id()); | 680 EXPECT_EQ(1, info.config_id()); |
677 | 681 |
678 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 682 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
712 ProxyInfo info; | 716 ProxyInfo info; |
713 TestCompletionCallback callback1; | 717 TestCompletionCallback callback1; |
714 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 718 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
715 nullptr, nullptr, NetLogWithSource()); | 719 nullptr, nullptr, NetLogWithSource()); |
716 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 720 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
717 | 721 |
718 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 722 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
719 factory->pending_requests()[0]->script_data()->url()); | 723 factory->pending_requests()[0]->script_data()->url()); |
720 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 724 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
721 | 725 |
722 ASSERT_EQ(1u, resolver.pending_requests().size()); | 726 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
723 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 727 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
724 | 728 |
725 // Set the result in proxy resolver. | 729 // Set the result in proxy resolver. |
726 resolver.pending_requests()[0]->results()->UsePacString( | 730 resolver.pending_jobs()[0]->results()->UsePacString( |
727 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 731 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
728 resolver.pending_requests()[0]->CompleteNow(OK); | 732 resolver.pending_jobs()[0]->CompleteNow(OK); |
729 | 733 |
730 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 734 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
731 EXPECT_TRUE(info.is_direct()); | 735 EXPECT_TRUE(info.is_direct()); |
732 | 736 |
733 // Fallback 1. | 737 // Fallback 1. |
734 TestCompletionCallback callback2; | 738 TestCompletionCallback callback2; |
735 rv = service.ReconsiderProxyAfterError( | 739 rv = service.ReconsiderProxyAfterError( |
736 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 740 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
737 callback2.callback(), nullptr, nullptr, NetLogWithSource()); | 741 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
738 EXPECT_THAT(rv, IsOk()); | 742 EXPECT_THAT(rv, IsOk()); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
784 base::WrapUnique(factory), nullptr); | 788 base::WrapUnique(factory), nullptr); |
785 | 789 |
786 // Resolve something. | 790 // Resolve something. |
787 GURL url("http://www.google.com/"); | 791 GURL url("http://www.google.com/"); |
788 ProxyInfo info; | 792 ProxyInfo info; |
789 TestCompletionCallback callback; | 793 TestCompletionCallback callback; |
790 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), | 794 int rv = service.ResolveProxy(url, std::string(), &info, callback.callback(), |
791 nullptr, nullptr, NetLogWithSource()); | 795 nullptr, nullptr, NetLogWithSource()); |
792 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); | 796 ASSERT_THAT(rv, IsError(ERR_IO_PENDING)); |
793 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 797 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
794 ASSERT_EQ(1u, resolver.pending_requests().size()); | 798 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
795 | 799 |
796 // Set the result in proxy resolver. | 800 // Set the result in proxy resolver. |
797 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 801 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy"); |
798 resolver.pending_requests()[0]->CompleteNow(OK); | 802 resolver.pending_jobs()[0]->CompleteNow(OK); |
799 | 803 |
800 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 804 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
801 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 805 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
802 EXPECT_TRUE(info.did_use_pac_script()); | 806 EXPECT_TRUE(info.did_use_pac_script()); |
803 | 807 |
804 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 808 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
805 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 809 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
806 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 810 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
807 } | 811 } |
808 | 812 |
(...skipping 17 matching lines...) Expand all Loading... |
826 ProxyInfo info; | 830 ProxyInfo info; |
827 TestCompletionCallback callback1; | 831 TestCompletionCallback callback1; |
828 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 832 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
829 nullptr, nullptr, NetLogWithSource()); | 833 nullptr, nullptr, NetLogWithSource()); |
830 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 834 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
831 | 835 |
832 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 836 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
833 factory->pending_requests()[0]->script_data()->url()); | 837 factory->pending_requests()[0]->script_data()->url()); |
834 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 838 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
835 | 839 |
836 ASSERT_EQ(1u, resolver.pending_requests().size()); | 840 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
837 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 841 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
838 | 842 |
839 // Fail the first resolve request in MockAsyncProxyResolver. | 843 // Fail the first resolve request in MockAsyncProxyResolver. |
840 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 844 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); |
841 | 845 |
842 // Although the proxy resolver failed the request, ProxyService implicitly | 846 // Although the proxy resolver failed the request, ProxyService implicitly |
843 // falls-back to DIRECT. | 847 // falls-back to DIRECT. |
844 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 848 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
845 EXPECT_TRUE(info.is_direct()); | 849 EXPECT_TRUE(info.is_direct()); |
846 | 850 |
847 // Failed PAC executions still have proxy resolution times. | 851 // Failed PAC executions still have proxy resolution times. |
848 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 852 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
849 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 853 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
850 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 854 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
851 | 855 |
852 // The second resolve request will try to run through the proxy resolver, | 856 // The second resolve request will try to run through the proxy resolver, |
853 // regardless of whether the first request failed in it. | 857 // regardless of whether the first request failed in it. |
854 TestCompletionCallback callback2; | 858 TestCompletionCallback callback2; |
855 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), | 859 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
856 nullptr, nullptr, NetLogWithSource()); | 860 nullptr, nullptr, NetLogWithSource()); |
857 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 861 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
858 | 862 |
859 ASSERT_EQ(1u, resolver.pending_requests().size()); | 863 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
860 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 864 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
861 | 865 |
862 // This time we will have the resolver succeed (perhaps the PAC script has | 866 // This time we will have the resolver succeed (perhaps the PAC script has |
863 // a dependency on the current time). | 867 // a dependency on the current time). |
864 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 868 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
865 resolver.pending_requests()[0]->CompleteNow(OK); | 869 resolver.pending_jobs()[0]->CompleteNow(OK); |
866 | 870 |
867 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 871 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
868 EXPECT_FALSE(info.is_direct()); | 872 EXPECT_FALSE(info.is_direct()); |
869 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 873 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
870 } | 874 } |
871 | 875 |
872 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { | 876 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { |
873 // Test what happens when the ProxyResolver fails with a fatal error while | 877 // Test what happens when the ProxyResolver fails with a fatal error while |
874 // a GetProxyForURL() call is in progress. | 878 // a GetProxyForURL() call is in progress. |
875 | 879 |
(...skipping 13 matching lines...) Expand all Loading... |
889 TestCompletionCallback callback1; | 893 TestCompletionCallback callback1; |
890 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 894 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
891 nullptr, nullptr, NetLogWithSource()); | 895 nullptr, nullptr, NetLogWithSource()); |
892 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 896 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
893 | 897 |
894 ASSERT_EQ(1u, factory->pending_requests().size()); | 898 ASSERT_EQ(1u, factory->pending_requests().size()); |
895 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 899 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
896 factory->pending_requests()[0]->script_data()->url()); | 900 factory->pending_requests()[0]->script_data()->url()); |
897 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 901 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
898 | 902 |
899 ASSERT_EQ(1u, resolver.pending_requests().size()); | 903 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
900 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 904 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
901 | 905 |
902 // Fail the first resolve request in MockAsyncProxyResolver. | 906 // Fail the first resolve request in MockAsyncProxyResolver. |
903 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 907 resolver.pending_jobs()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
904 | 908 |
905 // Although the proxy resolver failed the request, ProxyService implicitly | 909 // Although the proxy resolver failed the request, ProxyService implicitly |
906 // falls-back to DIRECT. | 910 // falls-back to DIRECT. |
907 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 911 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
908 EXPECT_TRUE(info.is_direct()); | 912 EXPECT_TRUE(info.is_direct()); |
909 | 913 |
910 // Failed PAC executions still have proxy resolution times. | 914 // Failed PAC executions still have proxy resolution times. |
911 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 915 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
912 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 916 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
913 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 917 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
914 | 918 |
915 // With no other requests, the ProxyService waits for a new request before | 919 // With no other requests, the ProxyService waits for a new request before |
916 // initializing a new ProxyResolver. | 920 // initializing a new ProxyResolver. |
917 EXPECT_TRUE(factory->pending_requests().empty()); | 921 EXPECT_TRUE(factory->pending_requests().empty()); |
918 | 922 |
919 TestCompletionCallback callback2; | 923 TestCompletionCallback callback2; |
920 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), | 924 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
921 nullptr, nullptr, NetLogWithSource()); | 925 nullptr, nullptr, NetLogWithSource()); |
922 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 926 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
923 | 927 |
924 ASSERT_EQ(1u, factory->pending_requests().size()); | 928 ASSERT_EQ(1u, factory->pending_requests().size()); |
925 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 929 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
926 factory->pending_requests()[0]->script_data()->url()); | 930 factory->pending_requests()[0]->script_data()->url()); |
927 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 931 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
928 | 932 |
929 ASSERT_EQ(1u, resolver.pending_requests().size()); | 933 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
930 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 934 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
931 | 935 |
932 // This time we will have the resolver succeed. | 936 // This time we will have the resolver succeed. |
933 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 937 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
934 resolver.pending_requests()[0]->CompleteNow(OK); | 938 resolver.pending_jobs()[0]->CompleteNow(OK); |
935 | 939 |
936 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 940 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
937 EXPECT_FALSE(info.is_direct()); | 941 EXPECT_FALSE(info.is_direct()); |
938 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 942 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
939 } | 943 } |
940 | 944 |
941 TEST_F(ProxyServiceTest, | 945 TEST_F(ProxyServiceTest, |
942 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { | 946 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { |
943 // Test what happens when the ProxyResolver fails with a fatal error while | 947 // Test what happens when the ProxyResolver fails with a fatal error while |
944 // a GetProxyForURL() call is in progress. | 948 // a GetProxyForURL() call is in progress. |
(...skipping 20 matching lines...) Expand all Loading... |
965 TestCompletionCallback callback2; | 969 TestCompletionCallback callback2; |
966 rv = service.ResolveProxy(url2, std::string(), &info, callback2.callback(), | 970 rv = service.ResolveProxy(url2, std::string(), &info, callback2.callback(), |
967 nullptr, nullptr, NetLogWithSource()); | 971 nullptr, nullptr, NetLogWithSource()); |
968 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 972 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
969 | 973 |
970 ASSERT_EQ(1u, factory->pending_requests().size()); | 974 ASSERT_EQ(1u, factory->pending_requests().size()); |
971 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 975 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
972 factory->pending_requests()[0]->script_data()->url()); | 976 factory->pending_requests()[0]->script_data()->url()); |
973 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 977 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
974 | 978 |
975 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 979 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); |
976 | 980 |
977 // Fail the first resolve request in MockAsyncProxyResolver. | 981 // Fail the first resolve request in MockAsyncProxyResolver. |
978 requests[url1]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 982 jobs[url1]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
979 | 983 |
980 // Although the proxy resolver failed the request, ProxyService implicitly | 984 // Although the proxy resolver failed the request, ProxyService implicitly |
981 // falls-back to DIRECT. | 985 // falls-back to DIRECT. |
982 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 986 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
983 EXPECT_TRUE(info.is_direct()); | 987 EXPECT_TRUE(info.is_direct()); |
984 | 988 |
985 // Failed PAC executions still have proxy resolution times. | 989 // Failed PAC executions still have proxy resolution times. |
986 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 990 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
987 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 991 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
988 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 992 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
989 | 993 |
990 // The second request is cancelled when the proxy resolver terminates. | 994 // The second request is cancelled when the proxy resolver terminates. |
991 requests = GetCancelledRequestsForURLs(resolver, url2); | 995 jobs = GetCancelledJobsForURLs(resolver, url2); |
992 | 996 |
993 // Since a second request was in progress, the ProxyService starts | 997 // Since a second request was in progress, the ProxyService starts |
994 // initializating a new ProxyResolver. | 998 // initializating a new ProxyResolver. |
995 ASSERT_EQ(1u, factory->pending_requests().size()); | 999 ASSERT_EQ(1u, factory->pending_requests().size()); |
996 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1000 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
997 factory->pending_requests()[0]->script_data()->url()); | 1001 factory->pending_requests()[0]->script_data()->url()); |
998 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1002 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
999 | 1003 |
1000 requests = GetPendingRequestsForURLs(resolver, url2); | 1004 jobs = GetPendingJobsForURLs(resolver, url2); |
1001 | 1005 |
1002 // This request succeeds. | 1006 // This request succeeds. |
1003 requests[url2]->results()->UseNamedProxy("foopy_valid:8080"); | 1007 jobs[url2]->results()->UseNamedProxy("foopy_valid:8080"); |
1004 requests[url2]->CompleteNow(OK); | 1008 jobs[url2]->CompleteNow(OK); |
1005 | 1009 |
1006 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 1010 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
1007 EXPECT_FALSE(info.is_direct()); | 1011 EXPECT_FALSE(info.is_direct()); |
1008 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 1012 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
1009 } | 1013 } |
1010 | 1014 |
1011 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { | 1015 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { |
1012 // Test what happens when the ProxyScriptResolver fails to download a | 1016 // Test what happens when the ProxyScriptResolver fails to download a |
1013 // mandatory PAC script. | 1017 // mandatory PAC script. |
1014 | 1018 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1124 ProxyInfo info; | 1128 ProxyInfo info; |
1125 TestCompletionCallback callback1; | 1129 TestCompletionCallback callback1; |
1126 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1130 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1127 nullptr, nullptr, NetLogWithSource()); | 1131 nullptr, nullptr, NetLogWithSource()); |
1128 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1132 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1129 | 1133 |
1130 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1134 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1131 factory->pending_requests()[0]->script_data()->url()); | 1135 factory->pending_requests()[0]->script_data()->url()); |
1132 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1136 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1133 | 1137 |
1134 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1138 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1135 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1139 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1136 | 1140 |
1137 // Fail the first resolve request in MockAsyncProxyResolver. | 1141 // Fail the first resolve request in MockAsyncProxyResolver. |
1138 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1142 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); |
1139 | 1143 |
1140 // As the proxy resolver failed the request and is configured for a mandatory | 1144 // As the proxy resolver failed the request and is configured for a mandatory |
1141 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1145 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1142 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1146 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1143 callback1.WaitForResult()); | 1147 callback1.WaitForResult()); |
1144 EXPECT_FALSE(info.is_direct()); | 1148 EXPECT_FALSE(info.is_direct()); |
1145 | 1149 |
1146 // The second resolve request will try to run through the proxy resolver, | 1150 // The second resolve request will try to run through the proxy resolver, |
1147 // regardless of whether the first request failed in it. | 1151 // regardless of whether the first request failed in it. |
1148 TestCompletionCallback callback2; | 1152 TestCompletionCallback callback2; |
1149 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), | 1153 rv = service.ResolveProxy(url, std::string(), &info, callback2.callback(), |
1150 nullptr, nullptr, NetLogWithSource()); | 1154 nullptr, nullptr, NetLogWithSource()); |
1151 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1155 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1152 | 1156 |
1153 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1157 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1154 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1158 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1155 | 1159 |
1156 // This time we will have the resolver succeed (perhaps the PAC script has | 1160 // This time we will have the resolver succeed (perhaps the PAC script has |
1157 // a dependency on the current time). | 1161 // a dependency on the current time). |
1158 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 1162 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
1159 resolver.pending_requests()[0]->CompleteNow(OK); | 1163 resolver.pending_jobs()[0]->CompleteNow(OK); |
1160 | 1164 |
1161 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 1165 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
1162 EXPECT_FALSE(info.is_direct()); | 1166 EXPECT_FALSE(info.is_direct()); |
1163 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 1167 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
1164 } | 1168 } |
1165 | 1169 |
1166 TEST_F(ProxyServiceTest, ProxyFallback) { | 1170 TEST_F(ProxyServiceTest, ProxyFallback) { |
1167 // Test what happens when we specify multiple proxy servers and some of them | 1171 // Test what happens when we specify multiple proxy servers and some of them |
1168 // are bad. | 1172 // are bad. |
1169 | 1173 |
(...skipping 13 matching lines...) Expand all Loading... |
1183 ProxyInfo info; | 1187 ProxyInfo info; |
1184 TestCompletionCallback callback1; | 1188 TestCompletionCallback callback1; |
1185 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1189 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1186 nullptr, nullptr, NetLogWithSource()); | 1190 nullptr, nullptr, NetLogWithSource()); |
1187 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1191 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1188 | 1192 |
1189 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1193 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1190 factory->pending_requests()[0]->script_data()->url()); | 1194 factory->pending_requests()[0]->script_data()->url()); |
1191 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1195 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1192 | 1196 |
1193 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1197 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1194 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1198 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1195 | 1199 |
1196 // Set the result in proxy resolver. | 1200 // Set the result in proxy resolver. |
1197 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1201 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1198 "foopy1:8080;foopy2:9090"); | 1202 "foopy1:8080;foopy2:9090"); |
1199 resolver.pending_requests()[0]->CompleteNow(OK); | 1203 resolver.pending_jobs()[0]->CompleteNow(OK); |
1200 | 1204 |
1201 // The first item is valid. | 1205 // The first item is valid. |
1202 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1206 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1203 EXPECT_FALSE(info.is_direct()); | 1207 EXPECT_FALSE(info.is_direct()); |
1204 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1208 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1205 | 1209 |
1206 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1210 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1207 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1211 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1208 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1212 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1209 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1213 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); |
(...skipping 18 matching lines...) Expand all Loading... |
1228 service.ReportSuccess(info, &test_delegate); | 1232 service.ReportSuccess(info, &test_delegate); |
1229 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); | 1233 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); |
1230 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 1234 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
1231 test_delegate.proxy_fallback_net_error()); | 1235 test_delegate.proxy_fallback_net_error()); |
1232 | 1236 |
1233 TestCompletionCallback callback3; | 1237 TestCompletionCallback callback3; |
1234 rv = service.ResolveProxy(url, std::string(), &info, callback3.callback(), | 1238 rv = service.ResolveProxy(url, std::string(), &info, callback3.callback(), |
1235 nullptr, nullptr, NetLogWithSource()); | 1239 nullptr, nullptr, NetLogWithSource()); |
1236 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1240 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1237 | 1241 |
1238 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1242 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1239 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1243 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1240 | 1244 |
1241 // Set the result in proxy resolver -- the second result is already known | 1245 // Set the result in proxy resolver -- the second result is already known |
1242 // to be bad, so we will not try to use it initially. | 1246 // to be bad, so we will not try to use it initially. |
1243 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1247 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1244 "foopy3:7070;foopy1:8080;foopy2:9090"); | 1248 "foopy3:7070;foopy1:8080;foopy2:9090"); |
1245 resolver.pending_requests()[0]->CompleteNow(OK); | 1249 resolver.pending_jobs()[0]->CompleteNow(OK); |
1246 | 1250 |
1247 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 1251 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
1248 EXPECT_FALSE(info.is_direct()); | 1252 EXPECT_FALSE(info.is_direct()); |
1249 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1253 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1250 | 1254 |
1251 // Proxy times should have been updated, so get them again. | 1255 // Proxy times should have been updated, so get them again. |
1252 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1256 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1253 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1257 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1254 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1258 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1255 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1259 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... |
1287 // Proxy times should not have been modified by fallback. | 1291 // Proxy times should not have been modified by fallback. |
1288 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1292 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
1289 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1293 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
1290 | 1294 |
1291 // Look up proxies again | 1295 // Look up proxies again |
1292 TestCompletionCallback callback7; | 1296 TestCompletionCallback callback7; |
1293 rv = service.ResolveProxy(url, std::string(), &info, callback7.callback(), | 1297 rv = service.ResolveProxy(url, std::string(), &info, callback7.callback(), |
1294 nullptr, nullptr, NetLogWithSource()); | 1298 nullptr, nullptr, NetLogWithSource()); |
1295 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1299 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1296 | 1300 |
1297 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1301 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1298 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1302 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1299 | 1303 |
1300 // This time, the first 3 results have been found to be bad, but only the | 1304 // This time, the first 3 results have been found to be bad, but only the |
1301 // first proxy has been confirmed ... | 1305 // first proxy has been confirmed ... |
1302 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1306 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1303 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 1307 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
1304 resolver.pending_requests()[0]->CompleteNow(OK); | 1308 resolver.pending_jobs()[0]->CompleteNow(OK); |
1305 | 1309 |
1306 // ... therefore, we should see the second proxy first. | 1310 // ... therefore, we should see the second proxy first. |
1307 EXPECT_THAT(callback7.WaitForResult(), IsOk()); | 1311 EXPECT_THAT(callback7.WaitForResult(), IsOk()); |
1308 EXPECT_FALSE(info.is_direct()); | 1312 EXPECT_FALSE(info.is_direct()); |
1309 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1313 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1310 | 1314 |
1311 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1315 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1312 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1316 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1313 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1317 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1314 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 1318 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
(...skipping 18 matching lines...) Expand all Loading... |
1333 ProxyInfo info; | 1337 ProxyInfo info; |
1334 TestCompletionCallback callback1; | 1338 TestCompletionCallback callback1; |
1335 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1339 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1336 nullptr, nullptr, NetLogWithSource()); | 1340 nullptr, nullptr, NetLogWithSource()); |
1337 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1341 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1338 | 1342 |
1339 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1343 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1340 factory->pending_requests()[0]->script_data()->url()); | 1344 factory->pending_requests()[0]->script_data()->url()); |
1341 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1345 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1342 | 1346 |
1343 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1347 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1344 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1348 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1345 | 1349 |
1346 // Set the result in proxy resolver. | 1350 // Set the result in proxy resolver. |
1347 resolver.pending_requests()[0]->results()->UsePacString( | 1351 resolver.pending_jobs()[0]->results()->UsePacString( |
1348 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 1352 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
1349 resolver.pending_requests()[0]->CompleteNow(OK); | 1353 resolver.pending_jobs()[0]->CompleteNow(OK); |
1350 | 1354 |
1351 // Get the first result. | 1355 // Get the first result. |
1352 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1356 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1353 EXPECT_FALSE(info.is_direct()); | 1357 EXPECT_FALSE(info.is_direct()); |
1354 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1358 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1355 | 1359 |
1356 // Fake an error on the proxy. | 1360 // Fake an error on the proxy. |
1357 TestCompletionCallback callback2; | 1361 TestCompletionCallback callback2; |
1358 rv = service.ReconsiderProxyAfterError( | 1362 rv = service.ReconsiderProxyAfterError( |
1359 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1363 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1406 ProxyInfo info; | 1410 ProxyInfo info; |
1407 TestCompletionCallback callback1; | 1411 TestCompletionCallback callback1; |
1408 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1412 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1409 nullptr, nullptr, NetLogWithSource()); | 1413 nullptr, nullptr, NetLogWithSource()); |
1410 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1414 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1411 | 1415 |
1412 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1416 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1413 factory->pending_requests()[0]->script_data()->url()); | 1417 factory->pending_requests()[0]->script_data()->url()); |
1414 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1418 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1415 | 1419 |
1416 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1420 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1417 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1421 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1418 | 1422 |
1419 // Set the result in proxy resolver. | 1423 // Set the result in proxy resolver. |
1420 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1424 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1421 "foopy1:8080;foopy2:9090"); | 1425 "foopy1:8080;foopy2:9090"); |
1422 resolver.pending_requests()[0]->CompleteNow(OK); | 1426 resolver.pending_jobs()[0]->CompleteNow(OK); |
1423 | 1427 |
1424 // The first item is valid. | 1428 // The first item is valid. |
1425 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1429 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1426 EXPECT_FALSE(info.is_direct()); | 1430 EXPECT_FALSE(info.is_direct()); |
1427 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1431 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1428 | 1432 |
1429 // Fake an error on the proxy, and also a new configuration on the proxy. | 1433 // Fake an error on the proxy, and also a new configuration on the proxy. |
1430 config_service->SetConfig( | 1434 config_service->SetConfig( |
1431 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 1435 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
1432 | 1436 |
1433 TestCompletionCallback callback2; | 1437 TestCompletionCallback callback2; |
1434 rv = service.ReconsiderProxyAfterError( | 1438 rv = service.ReconsiderProxyAfterError( |
1435 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1439 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1436 callback2.callback(), nullptr, nullptr, NetLogWithSource()); | 1440 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
1437 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1441 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1438 | 1442 |
1439 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 1443 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
1440 factory->pending_requests()[0]->script_data()->url()); | 1444 factory->pending_requests()[0]->script_data()->url()); |
1441 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1445 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1442 | 1446 |
1443 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1447 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1444 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1448 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1445 | 1449 |
1446 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1450 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1447 "foopy1:8080;foopy2:9090"); | 1451 "foopy1:8080;foopy2:9090"); |
1448 resolver.pending_requests()[0]->CompleteNow(OK); | 1452 resolver.pending_jobs()[0]->CompleteNow(OK); |
1449 | 1453 |
1450 // The first proxy is still there since the configuration changed. | 1454 // The first proxy is still there since the configuration changed. |
1451 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 1455 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
1452 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1456 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1453 | 1457 |
1454 // We fake another error. It should now ignore the first one. | 1458 // We fake another error. It should now ignore the first one. |
1455 TestCompletionCallback callback3; | 1459 TestCompletionCallback callback3; |
1456 rv = service.ReconsiderProxyAfterError( | 1460 rv = service.ReconsiderProxyAfterError( |
1457 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1461 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1458 callback3.callback(), nullptr, nullptr, NetLogWithSource()); | 1462 callback3.callback(), nullptr, nullptr, NetLogWithSource()); |
1459 EXPECT_THAT(rv, IsOk()); | 1463 EXPECT_THAT(rv, IsOk()); |
1460 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1464 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1461 | 1465 |
1462 // We simulate a new configuration. | 1466 // We simulate a new configuration. |
1463 config_service->SetConfig( | 1467 config_service->SetConfig( |
1464 ProxyConfig::CreateFromCustomPacURL( | 1468 ProxyConfig::CreateFromCustomPacURL( |
1465 GURL("http://foopy-new2/proxy.pac"))); | 1469 GURL("http://foopy-new2/proxy.pac"))); |
1466 | 1470 |
1467 // We fake another error. It should go back to the first proxy. | 1471 // We fake another error. It should go back to the first proxy. |
1468 TestCompletionCallback callback4; | 1472 TestCompletionCallback callback4; |
1469 rv = service.ReconsiderProxyAfterError( | 1473 rv = service.ReconsiderProxyAfterError( |
1470 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1474 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1471 callback4.callback(), nullptr, nullptr, NetLogWithSource()); | 1475 callback4.callback(), nullptr, nullptr, NetLogWithSource()); |
1472 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1476 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1473 | 1477 |
1474 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 1478 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
1475 factory->pending_requests()[0]->script_data()->url()); | 1479 factory->pending_requests()[0]->script_data()->url()); |
1476 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1480 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1477 | 1481 |
1478 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1482 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1479 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1483 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1480 | 1484 |
1481 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1485 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1482 "foopy1:8080;foopy2:9090"); | 1486 "foopy1:8080;foopy2:9090"); |
1483 resolver.pending_requests()[0]->CompleteNow(OK); | 1487 resolver.pending_jobs()[0]->CompleteNow(OK); |
1484 | 1488 |
1485 EXPECT_THAT(callback4.WaitForResult(), IsOk()); | 1489 EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
1486 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1490 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1487 | 1491 |
1488 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1492 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1489 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1493 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1490 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1494 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1491 } | 1495 } |
1492 | 1496 |
1493 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { | 1497 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { |
(...skipping 14 matching lines...) Expand all Loading... |
1508 // Get the proxy information. | 1512 // Get the proxy information. |
1509 ProxyInfo info; | 1513 ProxyInfo info; |
1510 TestCompletionCallback callback1; | 1514 TestCompletionCallback callback1; |
1511 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1515 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1512 nullptr, nullptr, NetLogWithSource()); | 1516 nullptr, nullptr, NetLogWithSource()); |
1513 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1517 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1514 | 1518 |
1515 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1519 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1516 factory->pending_requests()[0]->script_data()->url()); | 1520 factory->pending_requests()[0]->script_data()->url()); |
1517 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1521 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1518 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1522 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1519 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1523 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1520 | 1524 |
1521 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1525 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1522 "foopy1:8080;foopy2:9090"); | 1526 "foopy1:8080;foopy2:9090"); |
1523 resolver.pending_requests()[0]->CompleteNow(OK); | 1527 resolver.pending_jobs()[0]->CompleteNow(OK); |
1524 | 1528 |
1525 // The first item is valid. | 1529 // The first item is valid. |
1526 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1530 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1527 EXPECT_FALSE(info.is_direct()); | 1531 EXPECT_FALSE(info.is_direct()); |
1528 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1532 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1529 | 1533 |
1530 // Fake a proxy error. | 1534 // Fake a proxy error. |
1531 TestCompletionCallback callback2; | 1535 TestCompletionCallback callback2; |
1532 rv = service.ReconsiderProxyAfterError( | 1536 rv = service.ReconsiderProxyAfterError( |
1533 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1537 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1534 callback2.callback(), nullptr, nullptr, NetLogWithSource()); | 1538 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
1535 EXPECT_THAT(rv, IsOk()); | 1539 EXPECT_THAT(rv, IsOk()); |
1536 | 1540 |
1537 // The first proxy is ignored, and the second one is selected. | 1541 // The first proxy is ignored, and the second one is selected. |
1538 EXPECT_FALSE(info.is_direct()); | 1542 EXPECT_FALSE(info.is_direct()); |
1539 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1543 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1540 | 1544 |
1541 // Fake a PAC failure. | 1545 // Fake a PAC failure. |
1542 ProxyInfo info2; | 1546 ProxyInfo info2; |
1543 TestCompletionCallback callback3; | 1547 TestCompletionCallback callback3; |
1544 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), | 1548 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), |
1545 nullptr, nullptr, NetLogWithSource()); | 1549 nullptr, nullptr, NetLogWithSource()); |
1546 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1550 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1547 | 1551 |
1548 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1552 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1549 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1553 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1550 | 1554 |
1551 // This simulates a javascript runtime error in the PAC script. | 1555 // This simulates a javascript runtime error in the PAC script. |
1552 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1556 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); |
1553 | 1557 |
1554 // Although the resolver failed, the ProxyService will implicitly fall-back | 1558 // Although the resolver failed, the ProxyService will implicitly fall-back |
1555 // to a DIRECT connection. | 1559 // to a DIRECT connection. |
1556 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 1560 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
1557 EXPECT_TRUE(info2.is_direct()); | 1561 EXPECT_TRUE(info2.is_direct()); |
1558 EXPECT_FALSE(info2.is_empty()); | 1562 EXPECT_FALSE(info2.is_empty()); |
1559 | 1563 |
1560 // The PAC script will work properly next time and successfully return a | 1564 // The PAC script will work properly next time and successfully return a |
1561 // proxy list. Since we have not marked the configuration as bad, it should | 1565 // proxy list. Since we have not marked the configuration as bad, it should |
1562 // "just work" the next time we call it. | 1566 // "just work" the next time we call it. |
1563 ProxyInfo info3; | 1567 ProxyInfo info3; |
1564 TestCompletionCallback callback4; | 1568 TestCompletionCallback callback4; |
1565 rv = service.ReconsiderProxyAfterError( | 1569 rv = service.ReconsiderProxyAfterError( |
1566 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, | 1570 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, |
1567 callback4.callback(), nullptr, nullptr, NetLogWithSource()); | 1571 callback4.callback(), nullptr, nullptr, NetLogWithSource()); |
1568 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1572 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1569 | 1573 |
1570 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1574 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1571 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1575 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1572 | 1576 |
1573 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1577 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1574 "foopy1:8080;foopy2:9090"); | 1578 "foopy1:8080;foopy2:9090"); |
1575 resolver.pending_requests()[0]->CompleteNow(OK); | 1579 resolver.pending_jobs()[0]->CompleteNow(OK); |
1576 | 1580 |
1577 // The first proxy is not there since the it was added to the bad proxies | 1581 // The first proxy is not there since the it was added to the bad proxies |
1578 // list by the earlier ReconsiderProxyAfterError(). | 1582 // list by the earlier ReconsiderProxyAfterError(). |
1579 EXPECT_THAT(callback4.WaitForResult(), IsOk()); | 1583 EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
1580 EXPECT_FALSE(info3.is_direct()); | 1584 EXPECT_FALSE(info3.is_direct()); |
1581 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 1585 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
1582 | 1586 |
1583 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1587 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1584 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1588 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1585 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1589 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
(...skipping 20 matching lines...) Expand all Loading... |
1606 // Get the proxy information. | 1610 // Get the proxy information. |
1607 ProxyInfo info; | 1611 ProxyInfo info; |
1608 TestCompletionCallback callback1; | 1612 TestCompletionCallback callback1; |
1609 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), | 1613 int rv = service.ResolveProxy(url, std::string(), &info, callback1.callback(), |
1610 nullptr, nullptr, NetLogWithSource()); | 1614 nullptr, nullptr, NetLogWithSource()); |
1611 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1615 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1612 | 1616 |
1613 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1617 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1614 factory->pending_requests()[0]->script_data()->url()); | 1618 factory->pending_requests()[0]->script_data()->url()); |
1615 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1619 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1616 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1620 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1617 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1621 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1618 | 1622 |
1619 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1623 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1620 "foopy1:8080;foopy2:9090"); | 1624 "foopy1:8080;foopy2:9090"); |
1621 resolver.pending_requests()[0]->CompleteNow(OK); | 1625 resolver.pending_jobs()[0]->CompleteNow(OK); |
1622 | 1626 |
1623 // The first item is valid. | 1627 // The first item is valid. |
1624 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 1628 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
1625 EXPECT_FALSE(info.is_direct()); | 1629 EXPECT_FALSE(info.is_direct()); |
1626 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1630 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1627 | 1631 |
1628 // Fake a proxy error. | 1632 // Fake a proxy error. |
1629 TestCompletionCallback callback2; | 1633 TestCompletionCallback callback2; |
1630 rv = service.ReconsiderProxyAfterError( | 1634 rv = service.ReconsiderProxyAfterError( |
1631 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, | 1635 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info, |
1632 callback2.callback(), nullptr, nullptr, NetLogWithSource()); | 1636 callback2.callback(), nullptr, nullptr, NetLogWithSource()); |
1633 EXPECT_THAT(rv, IsOk()); | 1637 EXPECT_THAT(rv, IsOk()); |
1634 | 1638 |
1635 // The first proxy is ignored, and the second one is selected. | 1639 // The first proxy is ignored, and the second one is selected. |
1636 EXPECT_FALSE(info.is_direct()); | 1640 EXPECT_FALSE(info.is_direct()); |
1637 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1641 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1638 | 1642 |
1639 // Fake a PAC failure. | 1643 // Fake a PAC failure. |
1640 ProxyInfo info2; | 1644 ProxyInfo info2; |
1641 TestCompletionCallback callback3; | 1645 TestCompletionCallback callback3; |
1642 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), | 1646 rv = service.ResolveProxy(url, std::string(), &info2, callback3.callback(), |
1643 nullptr, nullptr, NetLogWithSource()); | 1647 nullptr, nullptr, NetLogWithSource()); |
1644 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1648 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1645 | 1649 |
1646 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1650 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1647 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1651 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1648 | 1652 |
1649 // This simulates a javascript runtime error in the PAC script. | 1653 // This simulates a javascript runtime error in the PAC script. |
1650 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1654 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); |
1651 | 1655 |
1652 // Although the resolver failed, the ProxyService will NOT fall-back | 1656 // Although the resolver failed, the ProxyService will NOT fall-back |
1653 // to a DIRECT connection as it is configured as mandatory. | 1657 // to a DIRECT connection as it is configured as mandatory. |
1654 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1658 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1655 callback3.WaitForResult()); | 1659 callback3.WaitForResult()); |
1656 EXPECT_FALSE(info2.is_direct()); | 1660 EXPECT_FALSE(info2.is_direct()); |
1657 EXPECT_TRUE(info2.is_empty()); | 1661 EXPECT_TRUE(info2.is_empty()); |
1658 | 1662 |
1659 // The PAC script will work properly next time and successfully return a | 1663 // The PAC script will work properly next time and successfully return a |
1660 // proxy list. Since we have not marked the configuration as bad, it should | 1664 // proxy list. Since we have not marked the configuration as bad, it should |
1661 // "just work" the next time we call it. | 1665 // "just work" the next time we call it. |
1662 ProxyInfo info3; | 1666 ProxyInfo info3; |
1663 TestCompletionCallback callback4; | 1667 TestCompletionCallback callback4; |
1664 rv = service.ReconsiderProxyAfterError( | 1668 rv = service.ReconsiderProxyAfterError( |
1665 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, | 1669 url, std::string(), ERR_PROXY_CONNECTION_FAILED, &info3, |
1666 callback4.callback(), nullptr, nullptr, NetLogWithSource()); | 1670 callback4.callback(), nullptr, nullptr, NetLogWithSource()); |
1667 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1671 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1668 | 1672 |
1669 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1673 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1670 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1674 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1671 | 1675 |
1672 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1676 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1673 "foopy1:8080;foopy2:9090"); | 1677 "foopy1:8080;foopy2:9090"); |
1674 resolver.pending_requests()[0]->CompleteNow(OK); | 1678 resolver.pending_jobs()[0]->CompleteNow(OK); |
1675 | 1679 |
1676 // The first proxy is not there since the it was added to the bad proxies | 1680 // The first proxy is not there since the it was added to the bad proxies |
1677 // list by the earlier ReconsiderProxyAfterError(). | 1681 // list by the earlier ReconsiderProxyAfterError(). |
1678 EXPECT_THAT(callback4.WaitForResult(), IsOk()); | 1682 EXPECT_THAT(callback4.WaitForResult(), IsOk()); |
1679 EXPECT_FALSE(info3.is_direct()); | 1683 EXPECT_FALSE(info3.is_direct()); |
1680 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 1684 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
1681 } | 1685 } |
1682 | 1686 |
1683 TEST_F(ProxyServiceTest, ProxyBypassList) { | 1687 TEST_F(ProxyServiceTest, ProxyBypassList) { |
1684 // Test that the proxy bypass rules are consulted. | 1688 // Test that the proxy bypass rules are consulted. |
(...skipping 259 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1944 int rv = | 1948 int rv = |
1945 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), | 1949 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
1946 nullptr, nullptr, NetLogWithSource()); | 1950 nullptr, nullptr, NetLogWithSource()); |
1947 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1951 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1948 | 1952 |
1949 // Successfully initialize the PAC script. | 1953 // Successfully initialize the PAC script. |
1950 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1954 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1951 factory->pending_requests()[0]->script_data()->url()); | 1955 factory->pending_requests()[0]->script_data()->url()); |
1952 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1956 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1953 | 1957 |
1954 GetPendingRequestsForURLs(resolver, url1); | 1958 GetPendingJobsForURLs(resolver, url1); |
1955 | 1959 |
1956 ProxyInfo info2; | 1960 ProxyInfo info2; |
1957 TestCompletionCallback callback2; | 1961 TestCompletionCallback callback2; |
1958 ProxyService::PacRequest* request2; | 1962 ProxyService::PacRequest* request2; |
1959 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), | 1963 rv = service.ResolveProxy(url2, std::string(), &info2, callback2.callback(), |
1960 &request2, nullptr, NetLogWithSource()); | 1964 &request2, nullptr, NetLogWithSource()); |
1961 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1965 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1962 | 1966 |
1963 GetPendingRequestsForURLs(resolver, url1, url2); | 1967 GetPendingJobsForURLs(resolver, url1, url2); |
1964 | 1968 |
1965 ProxyInfo info3; | 1969 ProxyInfo info3; |
1966 TestCompletionCallback callback3; | 1970 TestCompletionCallback callback3; |
1967 rv = service.ResolveProxy(url3, std::string(), &info3, callback3.callback(), | 1971 rv = service.ResolveProxy(url3, std::string(), &info3, callback3.callback(), |
1968 nullptr, nullptr, NetLogWithSource()); | 1972 nullptr, nullptr, NetLogWithSource()); |
1969 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 1973 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
1970 GetPendingRequestsForURLs(resolver, url1, url2, url3); | 1974 GetPendingJobsForURLs(resolver, url1, url2, url3); |
1971 | 1975 |
1972 // Cancel the second request | 1976 // Cancel the second request |
1973 service.CancelPacRequest(request2); | 1977 service.CancelPacRequest(request2); |
1974 | 1978 |
1975 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); | 1979 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url3); |
1976 | 1980 |
1977 // Complete the two un-cancelled requests. | 1981 // Complete the two un-cancelled jobs. |
1978 // We complete the last one first, just to mix it up a bit. | 1982 // We complete the last one first, just to mix it up a bit. |
1979 requests[url3]->results()->UseNamedProxy("request3:80"); | 1983 jobs[url3]->results()->UseNamedProxy("request3:80"); |
1980 requests[url3]->CompleteNow(OK); | 1984 jobs[url3]->CompleteNow(OK); // dsaadsasd |
1981 | 1985 |
1982 requests[url1]->results()->UseNamedProxy("request1:80"); | 1986 jobs[url1]->results()->UseNamedProxy("request1:80"); |
1983 requests[url1]->CompleteNow(OK); | 1987 jobs[url1]->CompleteNow(OK); |
1984 | 1988 |
1985 // Complete and verify that requests ran as expected. | 1989 EXPECT_EQ(OK, callback1.WaitForResult()); |
1986 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | |
1987 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1990 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1988 | 1991 |
1989 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 1992 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
1990 GetCancelledRequestsForURLs(resolver, url2); | 1993 GetCancelledJobsForURLs(resolver, url2); |
1991 | 1994 |
1992 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 1995 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
1993 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1996 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
1994 } | 1997 } |
1995 | 1998 |
1996 // Test the initial PAC download for resolver that expects bytes. | 1999 // Test the initial PAC download for resolver that expects bytes. |
1997 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { | 2000 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { |
1998 const GURL url1("http://request1"); | 2001 const GURL url1("http://request1"); |
1999 const GURL url2("http://request2"); | 2002 const GURL url2("http://request2"); |
2000 const GURL url3("http://request3"); | 2003 const GURL url3("http://request3"); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2054 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2057 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2055 // PAC script download completion. | 2058 // PAC script download completion. |
2056 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2059 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2057 | 2060 |
2058 // Now that the PAC script is downloaded, it will have been sent to the proxy | 2061 // Now that the PAC script is downloaded, it will have been sent to the proxy |
2059 // resolver. | 2062 // resolver. |
2060 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2063 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2061 factory->pending_requests()[0]->script_data()->utf16()); | 2064 factory->pending_requests()[0]->script_data()->utf16()); |
2062 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2065 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2063 | 2066 |
2064 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2, url3); | 2067 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2, url3); |
2065 | 2068 |
2066 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); | 2069 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); |
2067 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); | 2070 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); |
2068 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); | 2071 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); |
2069 | 2072 |
2070 // Complete all the requests (in some order). | 2073 // Complete all the jobs (in some order). |
2071 | 2074 |
2072 requests[url3]->results()->UseNamedProxy("request3:80"); | 2075 jobs[url3]->results()->UseNamedProxy("request3:80"); |
2073 requests[url3]->CompleteNow(OK); | 2076 jobs[url3]->CompleteNow(OK); |
2074 | 2077 |
2075 requests[url1]->results()->UseNamedProxy("request1:80"); | 2078 jobs[url1]->results()->UseNamedProxy("request1:80"); |
2076 requests[url1]->CompleteNow(OK); | 2079 jobs[url1]->CompleteNow(OK); |
2077 | 2080 |
2078 requests[url2]->results()->UseNamedProxy("request2:80"); | 2081 jobs[url2]->results()->UseNamedProxy("request2:80"); |
2079 requests[url2]->CompleteNow(OK); | 2082 jobs[url2]->CompleteNow(OK); |
2080 | 2083 |
2081 // Complete and verify that requests ran as expected. | 2084 //<<<<<<< HEAD |
2082 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2085 // // Complete and verify that requests ran as expected. |
| 2086 // EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 2087 //======= |
| 2088 // Complete and verify that jobs ran as expected. |
| 2089 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2090 //>>>>>>> parent of 9c8f424... Revert of Change |
| 2091 // ProxyResolver::GetProxyForURL() to take a std::unique_ptr<Request>* rather |
| 2092 // than a RequestHandle* (patchset #11 id:200001 of |
| 2093 // https://codereview.chromium.org/1439053002/ ) |
2083 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2094 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2084 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); | 2095 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); |
2085 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); | 2096 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); |
2086 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); | 2097 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); |
2087 | 2098 |
2088 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 2099 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2089 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2100 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2090 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); | 2101 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); |
2091 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); | 2102 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); |
2092 EXPECT_LE(info2.proxy_resolve_start_time(), info2.proxy_resolve_end_time()); | 2103 EXPECT_LE(info2.proxy_resolve_start_time(), info2.proxy_resolve_end_time()); |
(...skipping 16 matching lines...) Expand all Loading... |
2109 MockAsyncProxyResolverFactory* factory = | 2120 MockAsyncProxyResolverFactory* factory = |
2110 new MockAsyncProxyResolverFactory(true); | 2121 new MockAsyncProxyResolverFactory(true); |
2111 | 2122 |
2112 ProxyService service(base::WrapUnique(config_service), | 2123 ProxyService service(base::WrapUnique(config_service), |
2113 base::WrapUnique(factory), nullptr); | 2124 base::WrapUnique(factory), nullptr); |
2114 | 2125 |
2115 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2126 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2116 service.SetProxyScriptFetchers( | 2127 service.SetProxyScriptFetchers( |
2117 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2128 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2118 | 2129 |
2119 // Start 2 requests. | 2130 // Start 2 jobs. |
2120 | 2131 |
2121 ProxyInfo info1; | 2132 ProxyInfo info1; |
2122 TestCompletionCallback callback1; | 2133 TestCompletionCallback callback1; |
2123 int rv = | 2134 int rv = |
2124 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), | 2135 service.ResolveProxy(url1, std::string(), &info1, callback1.callback(), |
2125 nullptr, nullptr, NetLogWithSource()); | 2136 nullptr, nullptr, NetLogWithSource()); |
2126 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2137 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2127 | 2138 |
2128 // The first request should have triggered download of PAC script. | 2139 // The first request should have triggered download of PAC script. |
2129 EXPECT_TRUE(fetcher->has_pending_request()); | 2140 EXPECT_TRUE(fetcher->has_pending_request()); |
(...skipping 20 matching lines...) Expand all Loading... |
2150 EXPECT_TRUE(factory->pending_requests().empty()); | 2161 EXPECT_TRUE(factory->pending_requests().empty()); |
2151 | 2162 |
2152 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2163 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2153 | 2164 |
2154 // Now that the PAC script is downloaded, it will have been sent to the proxy | 2165 // Now that the PAC script is downloaded, it will have been sent to the proxy |
2155 // resolver. | 2166 // resolver. |
2156 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2167 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2157 factory->pending_requests()[0]->script_data()->utf16()); | 2168 factory->pending_requests()[0]->script_data()->utf16()); |
2158 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2169 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2159 | 2170 |
2160 GetPendingRequestsForURLs(resolver, url1, url2); | 2171 GetPendingJobsForURLs(resolver, url1, url2); |
2161 } | 2172 } |
2162 | 2173 |
2163 // Test cancellation of a request, while the PAC script is being fetched. | 2174 // Test cancellation of a request, while the PAC script is being fetched. |
2164 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { | 2175 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { |
2165 MockProxyConfigService* config_service = | 2176 MockProxyConfigService* config_service = |
2166 new MockProxyConfigService("http://foopy/proxy.pac"); | 2177 new MockProxyConfigService("http://foopy/proxy.pac"); |
2167 | 2178 |
2168 MockAsyncProxyResolver resolver; | 2179 MockAsyncProxyResolver resolver; |
2169 MockAsyncProxyResolverFactory* factory = | 2180 MockAsyncProxyResolverFactory* factory = |
2170 new MockAsyncProxyResolverFactory(true); | 2181 new MockAsyncProxyResolverFactory(true); |
(...skipping 30 matching lines...) Expand all Loading... |
2201 ProxyInfo info3; | 2212 ProxyInfo info3; |
2202 TestCompletionCallback callback3; | 2213 TestCompletionCallback callback3; |
2203 rv = service.ResolveProxy(GURL("http://request3"), std::string(), &info3, | 2214 rv = service.ResolveProxy(GURL("http://request3"), std::string(), &info3, |
2204 callback3.callback(), nullptr, nullptr, | 2215 callback3.callback(), nullptr, nullptr, |
2205 NetLogWithSource()); | 2216 NetLogWithSource()); |
2206 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2217 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2207 | 2218 |
2208 // Nothing has been sent to the factory yet. | 2219 // Nothing has been sent to the factory yet. |
2209 EXPECT_TRUE(factory->pending_requests().empty()); | 2220 EXPECT_TRUE(factory->pending_requests().empty()); |
2210 | 2221 |
2211 // Cancel the first 2 requests. | 2222 // Cancel the first 2 jobs. |
2212 service.CancelPacRequest(request1); | 2223 service.CancelPacRequest(request1); |
2213 service.CancelPacRequest(request2); | 2224 service.CancelPacRequest(request2); |
2214 | 2225 |
2215 // At this point the ProxyService should be waiting for the | 2226 // At this point the ProxyService should be waiting for the |
2216 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2227 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2217 // PAC script download completion. | 2228 // PAC script download completion. |
2218 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2229 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2219 | 2230 |
2220 // Now that the PAC script is downloaded, it will have been sent to the | 2231 // Now that the PAC script is downloaded, it will have been sent to the |
2221 // proxy resolver. | 2232 // proxy resolver. |
2222 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2233 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2223 factory->pending_requests()[0]->script_data()->utf16()); | 2234 factory->pending_requests()[0]->script_data()->utf16()); |
2224 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2235 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2225 | 2236 |
2226 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2237 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2227 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url()); | 2238 EXPECT_EQ(GURL("http://request3"), resolver.pending_jobs()[0]->url()); |
2228 | 2239 |
2229 // Complete all the requests. | 2240 // Complete all the jobs. |
2230 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80"); | 2241 resolver.pending_jobs()[0]->results()->UseNamedProxy("request3:80"); |
2231 resolver.pending_requests()[0]->CompleteNow(OK); | 2242 resolver.pending_jobs()[0]->CompleteNow(OK); |
2232 | 2243 |
2233 EXPECT_THAT(callback3.WaitForResult(), IsOk()); | 2244 EXPECT_THAT(callback3.WaitForResult(), IsOk()); |
2234 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 2245 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
2235 | 2246 |
2236 EXPECT_TRUE(resolver.cancelled_requests().empty()); | 2247 EXPECT_TRUE(resolver.cancelled_jobs().empty()); |
2237 | 2248 |
2238 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 2249 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
2239 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 2250 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
2240 | 2251 |
2241 TestNetLogEntry::List entries1; | 2252 TestNetLogEntry::List entries1; |
2242 log1.GetEntries(&entries1); | 2253 log1.GetEntries(&entries1); |
2243 | 2254 |
2244 // Check the NetLog for request 1 (which was cancelled) got filled properly. | 2255 // Check the NetLog for request 1 (which was cancelled) got filled properly. |
2245 EXPECT_EQ(4u, entries1.size()); | 2256 EXPECT_EQ(4u, entries1.size()); |
2246 EXPECT_TRUE( | 2257 EXPECT_TRUE( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2301 | 2312 |
2302 // Next it should be trying the custom PAC url. | 2313 // Next it should be trying the custom PAC url. |
2303 EXPECT_TRUE(fetcher->has_pending_request()); | 2314 EXPECT_TRUE(fetcher->has_pending_request()); |
2304 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2315 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2305 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2316 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2306 | 2317 |
2307 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2318 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2308 factory->pending_requests()[0]->script_data()->utf16()); | 2319 factory->pending_requests()[0]->script_data()->utf16()); |
2309 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2320 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2310 | 2321 |
2311 // Now finally, the pending requests should have been sent to the resolver | 2322 // Now finally, the pending jobs should have been sent to the resolver |
2312 // (which was initialized with custom PAC script). | 2323 // (which was initialized with custom PAC script). |
2313 | 2324 |
2314 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 2325 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); |
2315 | 2326 |
2316 // Complete the pending requests. | 2327 // Complete the pending jobs. |
2317 requests[url2]->results()->UseNamedProxy("request2:80"); | 2328 jobs[url2]->results()->UseNamedProxy("request2:80"); |
2318 requests[url2]->CompleteNow(OK); | 2329 jobs[url2]->CompleteNow(OK); |
2319 requests[url1]->results()->UseNamedProxy("request1:80"); | 2330 jobs[url1]->results()->UseNamedProxy("request1:80"); |
2320 requests[url1]->CompleteNow(OK); | 2331 jobs[url1]->CompleteNow(OK); |
2321 | 2332 |
2322 // Verify that requests ran as expected. | 2333 //<<<<<<< HEAD |
2323 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2334 // // Verify that requests ran as expected. |
| 2335 // EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 2336 //======= |
| 2337 // Verify that jobs ran as expected. |
| 2338 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2339 //>>>>>>> parent of 9c8f424... Revert of Change |
| 2340 // ProxyResolver::GetProxyForURL() to take a std::unique_ptr<Request>* rather |
| 2341 // than a RequestHandle* (patchset #11 id:200001 of |
| 2342 // https://codereview.chromium.org/1439053002/ ) |
2324 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2343 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2325 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); | 2344 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); |
2326 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); | 2345 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); |
2327 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); | 2346 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); |
2328 | 2347 |
2329 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 2348 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2330 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2349 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2331 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); | 2350 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); |
2332 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); | 2351 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); |
2333 EXPECT_LE(info2.proxy_resolve_start_time(), info2.proxy_resolve_end_time()); | 2352 EXPECT_LE(info2.proxy_resolve_start_time(), info2.proxy_resolve_end_time()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2383 | 2402 |
2384 // Next it should be trying the custom PAC url. | 2403 // Next it should be trying the custom PAC url. |
2385 EXPECT_TRUE(fetcher->has_pending_request()); | 2404 EXPECT_TRUE(fetcher->has_pending_request()); |
2386 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2405 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2387 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2406 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2388 | 2407 |
2389 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2408 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2390 factory->pending_requests()[0]->script_data()->utf16()); | 2409 factory->pending_requests()[0]->script_data()->utf16()); |
2391 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2410 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2392 | 2411 |
2393 // Now finally, the pending requests should have been sent to the resolver | 2412 // Now finally, the pending jobs should have been sent to the resolver |
2394 // (which was initialized with custom PAC script). | 2413 // (which was initialized with custom PAC script). |
2395 | 2414 |
2396 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 2415 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); |
2397 | 2416 |
2398 // Complete the pending requests. | 2417 // Complete the pending jobs. |
2399 requests[url2]->results()->UseNamedProxy("request2:80"); | 2418 jobs[url2]->results()->UseNamedProxy("request2:80"); |
2400 requests[url2]->CompleteNow(OK); | 2419 jobs[url2]->CompleteNow(OK); |
2401 requests[url1]->results()->UseNamedProxy("request1:80"); | 2420 jobs[url1]->results()->UseNamedProxy("request1:80"); |
2402 requests[url1]->CompleteNow(OK); | 2421 jobs[url1]->CompleteNow(OK); |
2403 | 2422 |
2404 // Verify that requests ran as expected. | 2423 //<<<<<<< HEAD |
2405 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2424 // // Verify that requests ran as expected. |
| 2425 // EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
| 2426 //======= |
| 2427 // Verify that jobs ran as expected. |
| 2428 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2429 //>>>>>>> parent of 9c8f424... Revert of Change |
| 2430 // ProxyResolver::GetProxyForURL() to take a std::unique_ptr<Request>* rather |
| 2431 // than a RequestHandle* (patchset #11 id:200001 of |
| 2432 // https://codereview.chromium.org/1439053002/ ) |
2406 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2433 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2407 | 2434 |
2408 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 2435 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2409 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2436 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2410 } | 2437 } |
2411 | 2438 |
2412 // Test that if all of auto-detect, a custom PAC script, and manual settings | 2439 // Test that if all of auto-detect, a custom PAC script, and manual settings |
2413 // are given, then we will try them in that order. | 2440 // are given, then we will try them in that order. |
2414 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { | 2441 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { |
2415 ProxyConfig config; | 2442 ProxyConfig config; |
2416 config.set_auto_detect(true); | 2443 config.set_auto_detect(true); |
2417 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2444 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
2418 config.proxy_rules().ParseFromString("http=foopy:80"); | 2445 config.proxy_rules().ParseFromString("http=foopy:80"); |
2419 | 2446 |
2420 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2447 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2421 MockAsyncProxyResolverFactory* factory = | 2448 MockAsyncProxyResolverFactory* factory = |
2422 new MockAsyncProxyResolverFactory(true); | 2449 new MockAsyncProxyResolverFactory(true); |
2423 ProxyService service(base::WrapUnique(config_service), | 2450 ProxyService service(base::WrapUnique(config_service), |
2424 base::WrapUnique(factory), nullptr); | 2451 base::WrapUnique(factory), nullptr); |
2425 | 2452 |
2426 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2453 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2427 service.SetProxyScriptFetchers( | 2454 service.SetProxyScriptFetchers( |
2428 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); | 2455 fetcher, base::WrapUnique(new DoNothingDhcpProxyScriptFetcher())); |
2429 | 2456 |
2430 // Start 2 requests. | 2457 // Start 2 jobs. |
2431 | 2458 |
2432 ProxyInfo info1; | 2459 ProxyInfo info1; |
2433 TestCompletionCallback callback1; | 2460 TestCompletionCallback callback1; |
2434 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, | 2461 int rv = service.ResolveProxy(GURL("http://request1"), std::string(), &info1, |
2435 callback1.callback(), nullptr, nullptr, | 2462 callback1.callback(), nullptr, nullptr, |
2436 NetLogWithSource()); | 2463 NetLogWithSource()); |
2437 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2464 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2438 | 2465 |
2439 ProxyInfo info2; | 2466 ProxyInfo info2; |
2440 TestCompletionCallback callback2; | 2467 TestCompletionCallback callback2; |
(...skipping 13 matching lines...) Expand all Loading... |
2454 | 2481 |
2455 // Next it should be trying the custom PAC url -- fail the download. | 2482 // Next it should be trying the custom PAC url -- fail the download. |
2456 EXPECT_TRUE(fetcher->has_pending_request()); | 2483 EXPECT_TRUE(fetcher->has_pending_request()); |
2457 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2484 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2458 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2485 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2459 | 2486 |
2460 // Since we never managed to initialize a resolver, nothing should have been | 2487 // Since we never managed to initialize a resolver, nothing should have been |
2461 // sent to it. | 2488 // sent to it. |
2462 ASSERT_EQ(0u, factory->pending_requests().size()); | 2489 ASSERT_EQ(0u, factory->pending_requests().size()); |
2463 | 2490 |
2464 // Verify that requests ran as expected -- they should have fallen back to | 2491 // Verify that jobs ran as expected -- they should have fallen back to |
2465 // the manual proxy configuration for HTTP urls. | 2492 // the manual proxy configuration for HTTP urls. |
2466 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2493 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2467 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); | 2494 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); |
2468 | 2495 |
2469 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 2496 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2470 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); | 2497 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); |
2471 } | 2498 } |
2472 | 2499 |
2473 // Test that the bypass rules are NOT applied when using autodetect. | 2500 // Test that the bypass rules are NOT applied when using autodetect. |
2474 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { | 2501 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { |
(...skipping 28 matching lines...) Expand all Loading... |
2503 | 2530 |
2504 // It should be trying to auto-detect first -- succeed the download. | 2531 // It should be trying to auto-detect first -- succeed the download. |
2505 EXPECT_TRUE(fetcher->has_pending_request()); | 2532 EXPECT_TRUE(fetcher->has_pending_request()); |
2506 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2533 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2507 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2534 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2508 | 2535 |
2509 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2536 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2510 factory->pending_requests()[0]->script_data()->utf16()); | 2537 factory->pending_requests()[0]->script_data()->utf16()); |
2511 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2538 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2512 | 2539 |
2513 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2540 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2514 EXPECT_EQ(GURL("http://www.google.com"), | 2541 EXPECT_EQ(GURL("http://www.google.com"), resolver.pending_jobs()[0]->url()); |
2515 resolver.pending_requests()[0]->url()); | |
2516 | 2542 |
2517 // Complete the pending request. | 2543 // Complete the pending request. |
2518 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2544 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
2519 resolver.pending_requests()[0]->CompleteNow(OK); | 2545 resolver.pending_jobs()[0]->CompleteNow(OK); |
2520 | 2546 |
2521 // Verify that request ran as expected. | 2547 // Verify that request ran as expected. |
2522 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2548 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2523 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2549 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2524 | 2550 |
2525 // Start another request, it should pickup the bypass item. | 2551 // Start another request, it should pickup the bypass item. |
2526 ProxyInfo info2; | 2552 ProxyInfo info2; |
2527 TestCompletionCallback callback2; | 2553 TestCompletionCallback callback2; |
2528 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2554 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2529 &info2, callback2.callback(), nullptr, nullptr, | 2555 &info2, callback2.callback(), nullptr, nullptr, |
2530 NetLogWithSource()); | 2556 NetLogWithSource()); |
2531 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2557 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2532 | 2558 |
2533 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2559 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2534 EXPECT_EQ(GURL("http://www.google.com"), | 2560 EXPECT_EQ(GURL("http://www.google.com"), resolver.pending_jobs()[0]->url()); |
2535 resolver.pending_requests()[0]->url()); | |
2536 | 2561 |
2537 // Complete the pending request. | 2562 // Complete the pending request. |
2538 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2563 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
2539 resolver.pending_requests()[0]->CompleteNow(OK); | 2564 resolver.pending_jobs()[0]->CompleteNow(OK); |
2540 | 2565 |
2541 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 2566 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2542 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2567 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2543 } | 2568 } |
2544 | 2569 |
2545 // Delete the ProxyService while InitProxyResolver has an outstanding | 2570 // Delete the ProxyService while InitProxyResolver has an outstanding |
2546 // request to the script fetcher. When run under valgrind, should not | 2571 // request to the script fetcher. When run under valgrind, should not |
2547 // have any memory errors (used to be that the ProxyScriptFetcher was | 2572 // have any memory errors (used to be that the ProxyScriptFetcher was |
2548 // being deleted prior to the InitProxyResolver). | 2573 // being deleted prior to the InitProxyResolver). |
2549 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { | 2574 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2651 &info1, callback1.callback(), nullptr, nullptr, | 2676 &info1, callback1.callback(), nullptr, nullptr, |
2652 NetLogWithSource()); | 2677 NetLogWithSource()); |
2653 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2678 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2654 | 2679 |
2655 // Successfully set the autodetect script. | 2680 // Successfully set the autodetect script. |
2656 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2681 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2657 factory->pending_requests()[0]->script_data()->type()); | 2682 factory->pending_requests()[0]->script_data()->type()); |
2658 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2683 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2659 | 2684 |
2660 // Complete the pending request. | 2685 // Complete the pending request. |
2661 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2686 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2662 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2687 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
2663 resolver.pending_requests()[0]->CompleteNow(OK); | 2688 resolver.pending_jobs()[0]->CompleteNow(OK); |
2664 | 2689 |
2665 // Verify that request ran as expected. | 2690 // Verify that request ran as expected. |
2666 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2691 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2667 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2692 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2668 | 2693 |
2669 // Force the ProxyService to pull down a new proxy configuration. | 2694 // Force the ProxyService to pull down a new proxy configuration. |
2670 // (Even though the configuration isn't old/bad). | 2695 // (Even though the configuration isn't old/bad). |
2671 // | 2696 // |
2672 // This new configuration no longer has auto_detect set, so | 2697 // This new configuration no longer has auto_detect set, so |
2673 // requests should complete synchronously now as direct-connect. | 2698 // jobs should complete synchronously now as direct-connect. |
2674 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2699 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2675 | 2700 |
2676 // Start another request -- the effective configuration has changed. | 2701 // Start another request -- the effective configuration has changed. |
2677 ProxyInfo info2; | 2702 ProxyInfo info2; |
2678 TestCompletionCallback callback2; | 2703 TestCompletionCallback callback2; |
2679 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), | 2704 rv = service.ResolveProxy(GURL("http://www.google.com"), std::string(), |
2680 &info2, callback2.callback(), nullptr, nullptr, | 2705 &info2, callback2.callback(), nullptr, nullptr, |
2681 NetLogWithSource()); | 2706 NetLogWithSource()); |
2682 EXPECT_THAT(rv, IsOk()); | 2707 EXPECT_THAT(rv, IsOk()); |
2683 | 2708 |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2725 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2750 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2726 // PAC script download completion. | 2751 // PAC script download completion. |
2727 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2752 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2728 | 2753 |
2729 // Now that the PAC script is downloaded, the request will have been sent to | 2754 // Now that the PAC script is downloaded, the request will have been sent to |
2730 // the proxy resolver. | 2755 // the proxy resolver. |
2731 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2756 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2732 factory->pending_requests()[0]->script_data()->utf16()); | 2757 factory->pending_requests()[0]->script_data()->utf16()); |
2733 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2758 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2734 | 2759 |
2735 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2760 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2736 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2761 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
2737 | 2762 |
2738 // Complete the pending request. | 2763 // Complete the pending request. |
2739 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2764 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
2740 resolver.pending_requests()[0]->CompleteNow(OK); | 2765 resolver.pending_jobs()[0]->CompleteNow(OK); |
2741 | 2766 |
2742 // Wait for completion callback, and verify that the request ran as expected. | 2767 // Wait for completion callback, and verify that the request ran as expected. |
2743 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2768 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2744 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2769 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2745 | 2770 |
2746 // Now simluate a change in the network. The ProxyConfigService is still | 2771 // Now simluate a change in the network. The ProxyConfigService is still |
2747 // going to return the same PAC URL as before, but this URL needs to be | 2772 // going to return the same PAC URL as before, but this URL needs to be |
2748 // refetched on the new network. | 2773 // refetched on the new network. |
2749 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2774 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2750 base::RunLoop().RunUntilIdle(); // Notification happens async. | 2775 base::RunLoop().RunUntilIdle(); // Notification happens async. |
(...skipping 17 matching lines...) Expand all Loading... |
2768 // Simulate the PAC script fetch as having completed (this time with | 2793 // Simulate the PAC script fetch as having completed (this time with |
2769 // different data). | 2794 // different data). |
2770 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 2795 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
2771 | 2796 |
2772 // Now that the PAC script is downloaded, the second request will have been | 2797 // Now that the PAC script is downloaded, the second request will have been |
2773 // sent to the proxy resolver. | 2798 // sent to the proxy resolver. |
2774 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2799 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
2775 factory->pending_requests()[0]->script_data()->utf16()); | 2800 factory->pending_requests()[0]->script_data()->utf16()); |
2776 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2801 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2777 | 2802 |
2778 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2803 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2779 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2804 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
2780 | 2805 |
2781 // Complete the pending second request. | 2806 // Complete the pending second request. |
2782 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2807 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
2783 resolver.pending_requests()[0]->CompleteNow(OK); | 2808 resolver.pending_jobs()[0]->CompleteNow(OK); |
2784 | 2809 |
2785 // Wait for completion callback, and verify that the request ran as expected. | 2810 // Wait for completion callback, and verify that the request ran as expected. |
2786 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 2811 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2787 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2812 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2788 | 2813 |
2789 // Check that the expected events were output to the log stream. In particular | 2814 // Check that the expected events were output to the log stream. In particular |
2790 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial | 2815 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial |
2791 // setup), and NOT a second time when the IP address changed. | 2816 // setup), and NOT a second time when the IP address changed. |
2792 TestNetLogEntry::List entries; | 2817 TestNetLogEntry::List entries; |
2793 log.GetEntries(&entries); | 2818 log.GetEntries(&entries); |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2887 | 2912 |
2888 // Start a second request. | 2913 // Start a second request. |
2889 ProxyInfo info2; | 2914 ProxyInfo info2; |
2890 TestCompletionCallback callback2; | 2915 TestCompletionCallback callback2; |
2891 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 2916 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
2892 callback2.callback(), nullptr, nullptr, | 2917 callback2.callback(), nullptr, nullptr, |
2893 NetLogWithSource()); | 2918 NetLogWithSource()); |
2894 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 2919 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
2895 | 2920 |
2896 // Check that it was sent to the resolver. | 2921 // Check that it was sent to the resolver. |
2897 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2922 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2898 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2923 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
2899 | 2924 |
2900 // Complete the pending second request. | 2925 // Complete the pending second request. |
2901 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2926 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
2902 resolver.pending_requests()[0]->CompleteNow(OK); | 2927 resolver.pending_jobs()[0]->CompleteNow(OK); |
2903 | 2928 |
2904 // Wait for completion callback, and verify that the request ran as expected. | 2929 // Wait for completion callback, and verify that the request ran as expected. |
2905 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 2930 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
2906 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2931 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2907 } | 2932 } |
2908 | 2933 |
2909 // This test verifies that the PAC script specified by the settings is | 2934 // This test verifies that the PAC script specified by the settings is |
2910 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 2935 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
2911 // however at a later time its *contents* change, we will eventually | 2936 // however at a later time its *contents* change, we will eventually |
2912 // re-configure the service to use the new script. | 2937 // re-configure the service to use the new script. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2950 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2975 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2951 // PAC script download completion. | 2976 // PAC script download completion. |
2952 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2977 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2953 | 2978 |
2954 // Now that the PAC script is downloaded, the request will have been sent to | 2979 // Now that the PAC script is downloaded, the request will have been sent to |
2955 // the proxy resolver. | 2980 // the proxy resolver. |
2956 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2981 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2957 factory->pending_requests()[0]->script_data()->utf16()); | 2982 factory->pending_requests()[0]->script_data()->utf16()); |
2958 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2983 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2959 | 2984 |
2960 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2985 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2961 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2986 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
2962 | 2987 |
2963 // Complete the pending request. | 2988 // Complete the pending request. |
2964 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2989 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
2965 resolver.pending_requests()[0]->CompleteNow(OK); | 2990 resolver.pending_jobs()[0]->CompleteNow(OK); |
2966 | 2991 |
2967 // Wait for completion callback, and verify that the request ran as expected. | 2992 // Wait for completion callback, and verify that the request ran as expected. |
2968 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 2993 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
2969 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2994 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2970 | 2995 |
2971 // At this point we have initialized the proxy service using a PAC script. | 2996 // At this point we have initialized the proxy service using a PAC script. |
2972 // | 2997 // |
2973 // A background task to periodically re-check the PAC script for validity will | 2998 // A background task to periodically re-check the PAC script for validity will |
2974 // have been started. We will now wait for the next download attempt to start. | 2999 // have been started. We will now wait for the next download attempt to start. |
2975 // | 3000 // |
2976 // Note that we shouldn't have to wait long here, since our test enables a | 3001 // Note that we shouldn't have to wait long here, since our test enables a |
2977 // special unit-test mode. | 3002 // special unit-test mode. |
2978 fetcher->WaitUntilFetch(); | 3003 fetcher->WaitUntilFetch(); |
2979 | 3004 |
2980 ASSERT_TRUE(factory->pending_requests().empty()); | 3005 ASSERT_TRUE(factory->pending_requests().empty()); |
2981 ASSERT_TRUE(resolver.pending_requests().empty()); | 3006 ASSERT_TRUE(resolver.pending_jobs().empty()); |
2982 | 3007 |
2983 // Make sure that our background checker is trying to download the expected | 3008 // Make sure that our background checker is trying to download the expected |
2984 // PAC script (same one as before). This time we will simulate a successful | 3009 // PAC script (same one as before). This time we will simulate a successful |
2985 // download of a DIFFERENT script. | 3010 // download of a DIFFERENT script. |
2986 EXPECT_TRUE(fetcher->has_pending_request()); | 3011 EXPECT_TRUE(fetcher->has_pending_request()); |
2987 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3012 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2988 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 3013 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
2989 | 3014 |
2990 base::RunLoop().RunUntilIdle(); | 3015 base::RunLoop().RunUntilIdle(); |
2991 | 3016 |
2992 // Now that the PAC script is downloaded, it should be used to initialize the | 3017 // Now that the PAC script is downloaded, it should be used to initialize the |
2993 // ProxyResolver. Simulate a successful parse. | 3018 // ProxyResolver. Simulate a successful parse. |
2994 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 3019 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
2995 factory->pending_requests()[0]->script_data()->utf16()); | 3020 factory->pending_requests()[0]->script_data()->utf16()); |
2996 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3021 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2997 | 3022 |
2998 // At this point the ProxyService should have re-configured itself to use the | 3023 // At this point the ProxyService should have re-configured itself to use the |
2999 // new PAC script. | 3024 // new PAC script. |
3000 | 3025 |
3001 // Start a second request. | 3026 // Start a second request. |
3002 ProxyInfo info2; | 3027 ProxyInfo info2; |
3003 TestCompletionCallback callback2; | 3028 TestCompletionCallback callback2; |
3004 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 3029 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
3005 callback2.callback(), nullptr, nullptr, | 3030 callback2.callback(), nullptr, nullptr, |
3006 NetLogWithSource()); | 3031 NetLogWithSource()); |
3007 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3032 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3008 | 3033 |
3009 // Check that it was sent to the resolver. | 3034 // Check that it was sent to the resolver. |
3010 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3035 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3011 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3036 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
3012 | 3037 |
3013 // Complete the pending second request. | 3038 // Complete the pending second request. |
3014 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3039 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
3015 resolver.pending_requests()[0]->CompleteNow(OK); | 3040 resolver.pending_jobs()[0]->CompleteNow(OK); |
3016 | 3041 |
3017 // Wait for completion callback, and verify that the request ran as expected. | 3042 // Wait for completion callback, and verify that the request ran as expected. |
3018 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 3043 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
3019 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3044 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3020 } | 3045 } |
3021 | 3046 |
3022 // This test verifies that the PAC script specified by the settings is | 3047 // This test verifies that the PAC script specified by the settings is |
3023 // periodically polled for changes. Specifically, if the initial fetch succeeds | 3048 // periodically polled for changes. Specifically, if the initial fetch succeeds |
3024 // and so does the next poll, however the contents of the downloaded script | 3049 // and so does the next poll, however the contents of the downloaded script |
3025 // have NOT changed, then we do not bother to re-initialize the proxy resolver. | 3050 // 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... |
3063 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3088 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3064 // PAC script download completion. | 3089 // PAC script download completion. |
3065 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3090 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3066 | 3091 |
3067 // Now that the PAC script is downloaded, the request will have been sent to | 3092 // Now that the PAC script is downloaded, the request will have been sent to |
3068 // the proxy resolver. | 3093 // the proxy resolver. |
3069 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3094 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3070 factory->pending_requests()[0]->script_data()->utf16()); | 3095 factory->pending_requests()[0]->script_data()->utf16()); |
3071 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3096 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3072 | 3097 |
3073 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3098 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3074 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3099 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
3075 | 3100 |
3076 // Complete the pending request. | 3101 // Complete the pending request. |
3077 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3102 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
3078 resolver.pending_requests()[0]->CompleteNow(OK); | 3103 resolver.pending_jobs()[0]->CompleteNow(OK); |
3079 | 3104 |
3080 // Wait for completion callback, and verify that the request ran as expected. | 3105 // Wait for completion callback, and verify that the request ran as expected. |
3081 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 3106 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
3082 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3107 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3083 | 3108 |
3084 // At this point we have initialized the proxy service using a PAC script. | 3109 // At this point we have initialized the proxy service using a PAC script. |
3085 // | 3110 // |
3086 // A background task to periodically re-check the PAC script for validity will | 3111 // A background task to periodically re-check the PAC script for validity will |
3087 // have been started. We will now wait for the next download attempt to start. | 3112 // have been started. We will now wait for the next download attempt to start. |
3088 // | 3113 // |
3089 // Note that we shouldn't have to wait long here, since our test enables a | 3114 // Note that we shouldn't have to wait long here, since our test enables a |
3090 // special unit-test mode. | 3115 // special unit-test mode. |
3091 fetcher->WaitUntilFetch(); | 3116 fetcher->WaitUntilFetch(); |
3092 | 3117 |
3093 ASSERT_TRUE(factory->pending_requests().empty()); | 3118 ASSERT_TRUE(factory->pending_requests().empty()); |
3094 ASSERT_TRUE(resolver.pending_requests().empty()); | 3119 ASSERT_TRUE(resolver.pending_jobs().empty()); |
3095 | 3120 |
3096 // Make sure that our background checker is trying to download the expected | 3121 // Make sure that our background checker is trying to download the expected |
3097 // PAC script (same one as before). We will simulate the same response as | 3122 // PAC script (same one as before). We will simulate the same response as |
3098 // last time (i.e. the script is unchanged). | 3123 // last time (i.e. the script is unchanged). |
3099 EXPECT_TRUE(fetcher->has_pending_request()); | 3124 EXPECT_TRUE(fetcher->has_pending_request()); |
3100 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3125 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3101 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3126 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3102 | 3127 |
3103 base::RunLoop().RunUntilIdle(); | 3128 base::RunLoop().RunUntilIdle(); |
3104 | 3129 |
3105 ASSERT_TRUE(factory->pending_requests().empty()); | 3130 ASSERT_TRUE(factory->pending_requests().empty()); |
3106 ASSERT_TRUE(resolver.pending_requests().empty()); | 3131 ASSERT_TRUE(resolver.pending_jobs().empty()); |
3107 | 3132 |
3108 // At this point the ProxyService is still running the same PAC script as | 3133 // At this point the ProxyService is still running the same PAC script as |
3109 // before. | 3134 // before. |
3110 | 3135 |
3111 // Start a second request. | 3136 // Start a second request. |
3112 ProxyInfo info2; | 3137 ProxyInfo info2; |
3113 TestCompletionCallback callback2; | 3138 TestCompletionCallback callback2; |
3114 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 3139 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
3115 callback2.callback(), nullptr, nullptr, | 3140 callback2.callback(), nullptr, nullptr, |
3116 NetLogWithSource()); | 3141 NetLogWithSource()); |
3117 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3142 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3118 | 3143 |
3119 // Check that it was sent to the resolver. | 3144 // Check that it was sent to the resolver. |
3120 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3145 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3121 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3146 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
3122 | 3147 |
3123 // Complete the pending second request. | 3148 // Complete the pending second request. |
3124 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3149 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
3125 resolver.pending_requests()[0]->CompleteNow(OK); | 3150 resolver.pending_jobs()[0]->CompleteNow(OK); |
3126 | 3151 |
3127 // Wait for completion callback, and verify that the request ran as expected. | 3152 // Wait for completion callback, and verify that the request ran as expected. |
3128 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 3153 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
3129 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3154 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3130 } | 3155 } |
3131 | 3156 |
3132 // This test verifies that the PAC script specified by the settings is | 3157 // This test verifies that the PAC script specified by the settings is |
3133 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 3158 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
3134 // however at a later time it starts to fail, we should re-configure the | 3159 // however at a later time it starts to fail, we should re-configure the |
3135 // ProxyService to stop using that PAC script. | 3160 // ProxyService to stop using that PAC script. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3173 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3198 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3174 // PAC script download completion. | 3199 // PAC script download completion. |
3175 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3200 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3176 | 3201 |
3177 // Now that the PAC script is downloaded, the request will have been sent to | 3202 // Now that the PAC script is downloaded, the request will have been sent to |
3178 // the proxy resolver. | 3203 // the proxy resolver. |
3179 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3204 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3180 factory->pending_requests()[0]->script_data()->utf16()); | 3205 factory->pending_requests()[0]->script_data()->utf16()); |
3181 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3206 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3182 | 3207 |
3183 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3208 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3184 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3209 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
3185 | 3210 |
3186 // Complete the pending request. | 3211 // Complete the pending request. |
3187 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3212 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
3188 resolver.pending_requests()[0]->CompleteNow(OK); | 3213 resolver.pending_jobs()[0]->CompleteNow(OK); |
3189 | 3214 |
3190 // Wait for completion callback, and verify that the request ran as expected. | 3215 // Wait for completion callback, and verify that the request ran as expected. |
3191 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 3216 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
3192 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3217 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3193 | 3218 |
3194 // At this point we have initialized the proxy service using a PAC script. | 3219 // At this point we have initialized the proxy service using a PAC script. |
3195 // | 3220 // |
3196 // A background task to periodically re-check the PAC script for validity will | 3221 // A background task to periodically re-check the PAC script for validity will |
3197 // have been started. We will now wait for the next download attempt to start. | 3222 // have been started. We will now wait for the next download attempt to start. |
3198 // | 3223 // |
3199 // Note that we shouldn't have to wait long here, since our test enables a | 3224 // Note that we shouldn't have to wait long here, since our test enables a |
3200 // special unit-test mode. | 3225 // special unit-test mode. |
3201 fetcher->WaitUntilFetch(); | 3226 fetcher->WaitUntilFetch(); |
3202 | 3227 |
3203 ASSERT_TRUE(factory->pending_requests().empty()); | 3228 ASSERT_TRUE(factory->pending_requests().empty()); |
3204 ASSERT_TRUE(resolver.pending_requests().empty()); | 3229 ASSERT_TRUE(resolver.pending_jobs().empty()); |
3205 | 3230 |
3206 // Make sure that our background checker is trying to download the expected | 3231 // Make sure that our background checker is trying to download the expected |
3207 // PAC script (same one as before). This time we will simulate a failure | 3232 // PAC script (same one as before). This time we will simulate a failure |
3208 // to download the script. | 3233 // to download the script. |
3209 EXPECT_TRUE(fetcher->has_pending_request()); | 3234 EXPECT_TRUE(fetcher->has_pending_request()); |
3210 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3235 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3211 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 3236 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
3212 | 3237 |
3213 base::RunLoop().RunUntilIdle(); | 3238 base::RunLoop().RunUntilIdle(); |
3214 | 3239 |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3328 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3353 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3329 // PAC script download completion. | 3354 // PAC script download completion. |
3330 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3355 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3331 | 3356 |
3332 // Now that the PAC script is downloaded, the request will have been sent to | 3357 // Now that the PAC script is downloaded, the request will have been sent to |
3333 // the proxy resolver. | 3358 // the proxy resolver. |
3334 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3359 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3335 factory->pending_requests()[0]->script_data()->utf16()); | 3360 factory->pending_requests()[0]->script_data()->utf16()); |
3336 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3361 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3337 | 3362 |
3338 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3363 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3339 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3364 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
3340 | 3365 |
3341 // Complete the pending request. | 3366 // Complete the pending request. |
3342 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3367 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
3343 resolver.pending_requests()[0]->CompleteNow(OK); | 3368 resolver.pending_jobs()[0]->CompleteNow(OK); |
3344 | 3369 |
3345 // Wait for completion callback, and verify that the request ran as expected. | 3370 // Wait for completion callback, and verify that the request ran as expected. |
3346 EXPECT_THAT(callback1.WaitForResult(), IsOk()); | 3371 EXPECT_THAT(callback1.WaitForResult(), IsOk()); |
3347 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3372 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3348 | 3373 |
3349 // At this point we have initialized the proxy service using a PAC script. | 3374 // At this point we have initialized the proxy service using a PAC script. |
3350 // Our PAC poller is set to update ONLY in response to network activity, | 3375 // Our PAC poller is set to update ONLY in response to network activity, |
3351 // (i.e. another call to ResolveProxy()). | 3376 // (i.e. another call to ResolveProxy()). |
3352 | 3377 |
3353 ASSERT_FALSE(fetcher->has_pending_request()); | 3378 ASSERT_FALSE(fetcher->has_pending_request()); |
3354 ASSERT_TRUE(factory->pending_requests().empty()); | 3379 ASSERT_TRUE(factory->pending_requests().empty()); |
3355 ASSERT_TRUE(resolver.pending_requests().empty()); | 3380 ASSERT_TRUE(resolver.pending_jobs().empty()); |
3356 | 3381 |
3357 // Start a second request. | 3382 // Start a second request. |
3358 ProxyInfo info2; | 3383 ProxyInfo info2; |
3359 TestCompletionCallback callback2; | 3384 TestCompletionCallback callback2; |
3360 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, | 3385 rv = service.ResolveProxy(GURL("http://request2"), std::string(), &info2, |
3361 callback2.callback(), nullptr, nullptr, | 3386 callback2.callback(), nullptr, nullptr, |
3362 NetLogWithSource()); | 3387 NetLogWithSource()); |
3363 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3388 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3364 | 3389 |
3365 // This request should have sent work to the resolver; complete it. | 3390 // This request should have sent work to the resolver; complete it. |
3366 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3391 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3367 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3392 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
3368 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3393 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
3369 resolver.pending_requests()[0]->CompleteNow(OK); | 3394 resolver.pending_jobs()[0]->CompleteNow(OK); |
3370 | 3395 |
3371 EXPECT_THAT(callback2.WaitForResult(), IsOk()); | 3396 EXPECT_THAT(callback2.WaitForResult(), IsOk()); |
3372 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3397 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3373 | 3398 |
3374 // In response to getting that resolve request, the poller should have | 3399 // In response to getting that resolve request, the poller should have |
3375 // started the next poll, and made it as far as to request the download. | 3400 // started the next poll, and made it as far as to request the download. |
3376 | 3401 |
3377 EXPECT_TRUE(fetcher->has_pending_request()); | 3402 EXPECT_TRUE(fetcher->has_pending_request()); |
3378 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3403 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3379 | 3404 |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3472 int rv = | 3497 int rv = |
3473 service_->ResolveProxy(url, std::string(), &info, callback.callback(), | 3498 service_->ResolveProxy(url, std::string(), &info, callback.callback(), |
3474 nullptr, nullptr, NetLogWithSource()); | 3499 nullptr, nullptr, NetLogWithSource()); |
3475 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3500 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3476 | 3501 |
3477 // First step is to download the PAC script. | 3502 // First step is to download the PAC script. |
3478 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 3503 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
3479 factory->pending_requests()[0]->script_data()->url()); | 3504 factory->pending_requests()[0]->script_data()->url()); |
3480 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3505 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3481 | 3506 |
3482 EXPECT_EQ(1u, resolver.pending_requests().size()); | 3507 EXPECT_EQ(1u, resolver.pending_jobs().size()); |
3483 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 3508 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
3484 | 3509 |
3485 // Complete the request. | 3510 // Complete the request. |
3486 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); | 3511 resolver.pending_jobs()[0]->results()->UsePacString("DIRECT"); |
3487 resolver.pending_requests()[0]->CompleteNow(OK); | 3512 resolver.pending_jobs()[0]->CompleteNow(OK); |
3488 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 3513 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
3489 EXPECT_TRUE(info.is_direct()); | 3514 EXPECT_TRUE(info.is_direct()); |
3490 } | 3515 } |
3491 | 3516 |
3492 // Changes the URL sanitization policy for the underlying ProxyService. This | 3517 // Changes the URL sanitization policy for the underlying ProxyService. This |
3493 // will affect subsequent calls to SanitizeUrl. | 3518 // will affect subsequent calls to SanitizeUrl. |
3494 void SetSanitizeUrlPolicy(ProxyService::SanitizeUrlPolicy policy) { | 3519 void SetSanitizeUrlPolicy(ProxyService::SanitizeUrlPolicy policy) { |
3495 service_->set_sanitize_url_policy(policy); | 3520 service_->set_sanitize_url_policy(policy); |
3496 } | 3521 } |
3497 | 3522 |
3498 // Makes a proxy resolution request through the ProxyService, and returns the | 3523 // Makes a proxy resolution request through the ProxyService, and returns the |
3499 // URL that was submitted to the Proxy Resolver. | 3524 // URL that was submitted to the Proxy Resolver. |
3500 GURL SanitizeUrl(const GURL& raw_url) { | 3525 GURL SanitizeUrl(const GURL& raw_url) { |
3501 // Issue a request and see what URL is sent to the proxy resolver. | 3526 // Issue a request and see what URL is sent to the proxy resolver. |
3502 ProxyInfo info; | 3527 ProxyInfo info; |
3503 TestCompletionCallback callback; | 3528 TestCompletionCallback callback; |
3504 int rv = service_->ResolveProxy(raw_url, std::string(), &info, | 3529 int rv = service_->ResolveProxy(raw_url, std::string(), &info, |
3505 callback.callback(), nullptr, nullptr, | 3530 callback.callback(), nullptr, nullptr, |
3506 NetLogWithSource()); | 3531 NetLogWithSource()); |
3507 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); | 3532 EXPECT_THAT(rv, IsError(ERR_IO_PENDING)); |
3508 | 3533 |
3509 EXPECT_EQ(1u, resolver.pending_requests().size()); | 3534 EXPECT_EQ(1u, resolver.pending_jobs().size()); |
3510 | 3535 |
3511 GURL sanitized_url = resolver.pending_requests()[0]->url(); | 3536 GURL sanitized_url = resolver.pending_jobs()[0]->url(); |
3512 | 3537 |
3513 // Complete the request. | 3538 // Complete the request. |
3514 resolver.pending_requests()[0]->results()->UsePacString("DIRECT"); | 3539 resolver.pending_jobs()[0]->results()->UsePacString("DIRECT"); |
3515 resolver.pending_requests()[0]->CompleteNow(OK); | 3540 resolver.pending_jobs()[0]->CompleteNow(OK); |
3516 EXPECT_THAT(callback.WaitForResult(), IsOk()); | 3541 EXPECT_THAT(callback.WaitForResult(), IsOk()); |
3517 EXPECT_TRUE(info.is_direct()); | 3542 EXPECT_TRUE(info.is_direct()); |
3518 | 3543 |
3519 return sanitized_url; | 3544 return sanitized_url; |
3520 } | 3545 } |
3521 | 3546 |
3522 // Changes the ProxyService's URL sanitization policy and then sanitizes | 3547 // Changes the ProxyService's URL sanitization policy and then sanitizes |
3523 // |raw_url|. | 3548 // |raw_url|. |
3524 GURL SanitizeUrl(const GURL& raw_url, | 3549 GURL SanitizeUrl(const GURL& raw_url, |
3525 ProxyService::SanitizeUrlPolicy policy) { | 3550 ProxyService::SanitizeUrlPolicy policy) { |
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3662 GURL(test.sanitized_url_unstripped), | 3687 GURL(test.sanitized_url_unstripped), |
3663 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); | 3688 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::UNSAFE)); |
3664 | 3689 |
3665 EXPECT_EQ( | 3690 EXPECT_EQ( |
3666 GURL(test.sanitized_url), | 3691 GURL(test.sanitized_url), |
3667 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); | 3692 helper.SanitizeUrl(raw_url, ProxyService::SanitizeUrlPolicy::SAFE)); |
3668 } | 3693 } |
3669 } | 3694 } |
3670 | 3695 |
3671 } // namespace net | 3696 } // namespace net |
OLD | NEW |