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