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 222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
233 int proxy_fallback_net_error() const { | 233 int proxy_fallback_net_error() const { |
234 return proxy_fallback_net_error_; | 234 return proxy_fallback_net_error_; |
235 } | 235 } |
236 | 236 |
237 private: | 237 private: |
238 bool on_proxy_fallback_called_; | 238 bool on_proxy_fallback_called_; |
239 ProxyServer proxy_server_; | 239 ProxyServer proxy_server_; |
240 int proxy_fallback_net_error_; | 240 int proxy_fallback_net_error_; |
241 }; | 241 }; |
242 | 242 |
243 using RequestMap = | 243 using JobMap = std::map<GURL, scoped_refptr<MockAsyncProxyResolver::Job>>; |
244 std::map<GURL, scoped_refptr<MockAsyncProxyResolver::Request>>; | |
245 | 244 |
246 // Given a list of requests |list| from a MockAsyncProxyResolver and a list of | 245 // Given a list of jobs |list| from a MockAsyncProxyResolver and a list of |
247 // target URLs |_urls|, asserts that the set of URLs of the requests appearing | 246 // target URLs |_urls|, asserts that the set of URLs of the jobs appearing |
248 // in |list| is exactly the set of URLs in |_urls|, and produces a RequestMap in | 247 // in |list| is exactly the set of URLs in |_urls|, and produces a JobMap in |
249 // |*map| containing the requests corresponding to those target |_urls|. | 248 // |*map| containing the jobs corresponding to those target |_urls|. |
250 // | 249 // |
251 // Note that this function must return void to allow use of gtest's ASSERT_* | 250 // Note that this function must return void to allow use of gtest's ASSERT_* |
252 // macros inside it. | 251 // macros inside it. |
253 RequestMap GetRequestsForURLs( | 252 JobMap GetJobsForURLs(const MockAsyncProxyResolver::JobsList& jobs, |
254 const MockAsyncProxyResolver::RequestsList& requests, | 253 const std::vector<GURL>& urls) { |
255 const std::vector<GURL>& urls) { | 254 JobMap map; |
256 RequestMap map; | |
257 | 255 |
258 for (const auto& it : requests) | 256 for (const auto& it : jobs) |
259 map[it->url()] = it; | 257 map[it->url()] = it; |
260 | 258 |
261 if (urls.size() != map.size()) { | 259 if (urls.size() != map.size()) { |
262 ADD_FAILURE() << "map size (" << map.size() << ") != urls size (" | 260 ADD_FAILURE() << "map size (" << map.size() << ") != urls size (" |
263 << urls.size() << ")"; | 261 << urls.size() << ")"; |
264 return map; | 262 return map; |
265 } | 263 } |
266 for (const auto& it : urls) { | 264 for (const auto& it : urls) { |
267 if (map.count(it) != 1U) { | 265 if (map.count(it) != 1U) { |
268 ADD_FAILURE() << "url not in map: " << it.spec(); | 266 ADD_FAILURE() << "url not in map: " << it.spec(); |
269 break; | 267 break; |
270 } | 268 } |
271 } | 269 } |
272 return map; | 270 return map; |
273 } | 271 } |
274 | 272 |
275 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the | 273 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the |
276 // set of pending request URLs for |resolver| is exactly the supplied list of | 274 // set of pending request URLs for |resolver| is exactly the supplied list of |
277 // URLs and returns a map from URLs to the corresponding pending requests. | 275 // URLs and returns a map from URLs to the corresponding pending jobs. |
278 RequestMap GetPendingRequestsForURLs(const MockAsyncProxyResolver& resolver, | 276 JobMap GetPendingJobsForURLs(const MockAsyncProxyResolver& resolver, |
279 const GURL& url1 = GURL(), | 277 const GURL& url1 = GURL(), |
280 const GURL& url2 = GURL(), | 278 const GURL& url2 = GURL(), |
281 const GURL& url3 = GURL()) { | 279 const GURL& url3 = GURL()) { |
282 std::vector<GURL> urls; | 280 std::vector<GURL> urls; |
283 if (!url1.is_empty()) | 281 if (!url1.is_empty()) |
284 urls.push_back(url1); | 282 urls.push_back(url1); |
285 if (!url2.is_empty()) | 283 if (!url2.is_empty()) |
286 urls.push_back(url2); | 284 urls.push_back(url2); |
287 if (!url3.is_empty()) | 285 if (!url3.is_empty()) |
288 urls.push_back(url3); | 286 urls.push_back(url3); |
289 return GetRequestsForURLs(resolver.pending_requests(), urls); | 287 return GetJobsForURLs(resolver.pending_jobs(), urls); |
290 } | 288 } |
291 | 289 |
292 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the | 290 // Given a MockAsyncProxyResolver |resolver| and some GURLs, validates that the |
293 // set of cancelled request URLs for |resolver| is exactly the supplied list of | 291 // set of cancelled request URLs for |resolver| is exactly the supplied list of |
294 // URLs and returns a map from URLs to the corresponding cancelled requests. | 292 // URLs and returns a map from URLs to the corresponding cancelled jobs. |
295 RequestMap GetCancelledRequestsForURLs(const MockAsyncProxyResolver& resolver, | 293 JobMap GetCancelledJobsForURLs(const MockAsyncProxyResolver& resolver, |
296 const GURL& url1 = GURL(), | 294 const GURL& url1 = GURL(), |
297 const GURL& url2 = GURL(), | 295 const GURL& url2 = GURL(), |
298 const GURL& url3 = GURL()) { | 296 const GURL& url3 = GURL()) { |
299 std::vector<GURL> urls; | 297 std::vector<GURL> urls; |
300 if (!url1.is_empty()) | 298 if (!url1.is_empty()) |
301 urls.push_back(url1); | 299 urls.push_back(url1); |
302 if (!url2.is_empty()) | 300 if (!url2.is_empty()) |
303 urls.push_back(url2); | 301 urls.push_back(url2); |
304 if (!url3.is_empty()) | 302 if (!url3.is_empty()) |
305 urls.push_back(url3); | 303 urls.push_back(url3); |
306 return GetRequestsForURLs(resolver.cancelled_requests(), urls); | 304 return GetJobsForURLs(resolver.cancelled_jobs(), urls); |
307 } | 305 } |
308 | 306 |
309 } // namespace | 307 } // namespace |
310 | 308 |
311 TEST_F(ProxyServiceTest, Direct) { | 309 TEST_F(ProxyServiceTest, Direct) { |
312 MockAsyncProxyResolverFactory* factory = | 310 MockAsyncProxyResolverFactory* factory = |
313 new MockAsyncProxyResolverFactory(false); | 311 new MockAsyncProxyResolverFactory(false); |
314 ProxyService service( | 312 ProxyService service( |
315 make_scoped_ptr(new MockProxyConfigService(ProxyConfig::CreateDirect())), | 313 make_scoped_ptr(new MockProxyConfigService(ProxyConfig::CreateDirect())), |
316 make_scoped_ptr(factory), NULL); | 314 make_scoped_ptr(factory), NULL); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
366 | 364 |
367 // Verify that network delegate is invoked. | 365 // Verify that network delegate is invoked. |
368 TestResolveProxyNetworkDelegate delegate; | 366 TestResolveProxyNetworkDelegate delegate; |
369 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), NULL, | 367 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), NULL, |
370 &delegate, log.bound()); | 368 &delegate, log.bound()); |
371 EXPECT_TRUE(delegate.on_resolve_proxy_called()); | 369 EXPECT_TRUE(delegate.on_resolve_proxy_called()); |
372 EXPECT_EQ(&service, delegate.proxy_service()); | 370 EXPECT_EQ(&service, delegate.proxy_service()); |
373 | 371 |
374 // Verify that the NetworkDelegate's behavior is stateless across | 372 // Verify that the NetworkDelegate's behavior is stateless across |
375 // invocations of ResolveProxy. Start by having the callback add a proxy | 373 // invocations of ResolveProxy. Start by having the callback add a proxy |
376 // and checking that subsequent requests are not affected. | 374 // and checking that subsequent jobs are not affected. |
377 delegate.set_add_proxy(true); | 375 delegate.set_add_proxy(true); |
378 | 376 |
379 // Callback should interpose: | 377 // Callback should interpose: |
380 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), NULL, | 378 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), NULL, |
381 &delegate, log.bound()); | 379 &delegate, log.bound()); |
382 EXPECT_FALSE(info.is_direct()); | 380 EXPECT_FALSE(info.is_direct()); |
383 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); | 381 EXPECT_EQ(info.proxy_server().host_port_pair().host(), "delegate_proxy.com"); |
384 delegate.set_add_proxy(false); | 382 delegate.set_add_proxy(false); |
385 | 383 |
386 // Check non-bypassed URL: | 384 // Check non-bypassed URL: |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
462 &request, NULL, log.bound()); | 460 &request, NULL, log.bound()); |
463 EXPECT_EQ(ERR_IO_PENDING, rv); | 461 EXPECT_EQ(ERR_IO_PENDING, rv); |
464 | 462 |
465 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 463 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
466 | 464 |
467 ASSERT_EQ(1u, factory->pending_requests().size()); | 465 ASSERT_EQ(1u, factory->pending_requests().size()); |
468 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 466 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
469 factory->pending_requests()[0]->script_data()->url()); | 467 factory->pending_requests()[0]->script_data()->url()); |
470 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 468 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
471 | 469 |
472 ASSERT_EQ(1u, resolver.pending_requests().size()); | 470 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
473 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 471 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
474 | 472 |
475 // Set the result in proxy resolver. | 473 // Set the result in proxy resolver. |
476 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 474 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy"); |
477 resolver.pending_requests()[0]->CompleteNow(OK); | 475 resolver.pending_jobs()[0]->CompleteNow(OK); |
478 | 476 |
479 EXPECT_EQ(OK, callback.WaitForResult()); | 477 EXPECT_EQ(OK, callback.WaitForResult()); |
480 EXPECT_FALSE(info.is_direct()); | 478 EXPECT_FALSE(info.is_direct()); |
481 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); | 479 EXPECT_EQ("foopy:80", info.proxy_server().ToURI()); |
482 EXPECT_TRUE(info.did_use_pac_script()); | 480 EXPECT_TRUE(info.did_use_pac_script()); |
483 | 481 |
484 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 482 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
485 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 483 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
486 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 484 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
487 | 485 |
(...skipping 30 matching lines...) Expand all Loading... |
518 ProxyInfo info; | 516 ProxyInfo info; |
519 TestCompletionCallback callback; | 517 TestCompletionCallback callback; |
520 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 518 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
521 NULL, NULL, BoundNetLog()); | 519 NULL, NULL, BoundNetLog()); |
522 EXPECT_EQ(ERR_IO_PENDING, rv); | 520 EXPECT_EQ(ERR_IO_PENDING, rv); |
523 | 521 |
524 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 522 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
525 factory->pending_requests()[0]->script_data()->url()); | 523 factory->pending_requests()[0]->script_data()->url()); |
526 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 524 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
527 | 525 |
528 ASSERT_EQ(1u, resolver.pending_requests().size()); | 526 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
529 // The URL should have been simplified, stripping the username/password/hash. | 527 // The URL should have been simplified, stripping the username/password/hash. |
530 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 528 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
531 resolver.pending_requests()[0]->url()); | 529 resolver.pending_jobs()[0]->url()); |
532 | 530 |
533 // We end here without ever completing the request -- destruction of | 531 // We end here without ever completing the request -- destruction of |
534 // ProxyService will cancel the outstanding request. | 532 // ProxyService will cancel the outstanding request. |
535 } | 533 } |
536 | 534 |
537 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 535 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
538 MockProxyConfigService* config_service = | 536 MockProxyConfigService* config_service = |
539 new MockProxyConfigService("http://foopy/proxy.pac"); | 537 new MockProxyConfigService("http://foopy/proxy.pac"); |
540 MockAsyncProxyResolver resolver; | 538 MockAsyncProxyResolver resolver; |
541 MockAsyncProxyResolverFactory* factory = | 539 MockAsyncProxyResolverFactory* factory = |
542 new MockAsyncProxyResolverFactory(false); | 540 new MockAsyncProxyResolverFactory(false); |
543 | 541 |
544 ProxyService service(make_scoped_ptr(config_service), | 542 ProxyService service(make_scoped_ptr(config_service), |
545 make_scoped_ptr(factory), NULL); | 543 make_scoped_ptr(factory), NULL); |
546 | 544 |
547 GURL url("http://www.google.com/"); | 545 GURL url("http://www.google.com/"); |
548 | 546 |
549 ProxyInfo info; | 547 ProxyInfo info; |
550 TestCompletionCallback callback1; | 548 TestCompletionCallback callback1; |
551 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 549 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
552 NULL, NULL, BoundNetLog()); | 550 NULL, NULL, BoundNetLog()); |
553 EXPECT_EQ(ERR_IO_PENDING, rv); | 551 EXPECT_EQ(ERR_IO_PENDING, rv); |
554 | 552 |
555 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 553 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
556 factory->pending_requests()[0]->script_data()->url()); | 554 factory->pending_requests()[0]->script_data()->url()); |
557 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 555 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
558 | 556 |
559 ASSERT_EQ(1u, resolver.pending_requests().size()); | 557 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
560 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 558 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
561 | 559 |
562 // Set the result in proxy resolver. | 560 // Set the result in proxy resolver. |
563 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 561 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy:8080"); |
564 resolver.pending_requests()[0]->CompleteNow(OK); | 562 resolver.pending_jobs()[0]->CompleteNow(OK); |
565 | 563 |
566 EXPECT_EQ(OK, callback1.WaitForResult()); | 564 EXPECT_EQ(OK, callback1.WaitForResult()); |
567 EXPECT_FALSE(info.is_direct()); | 565 EXPECT_FALSE(info.is_direct()); |
568 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); | 566 EXPECT_EQ("foopy:8080", info.proxy_server().ToURI()); |
569 EXPECT_TRUE(info.did_use_pac_script()); | 567 EXPECT_TRUE(info.did_use_pac_script()); |
570 | 568 |
571 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 569 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
572 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 570 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
573 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 571 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
574 | 572 |
(...skipping 28 matching lines...) Expand all Loading... |
603 ProxyInfo info; | 601 ProxyInfo info; |
604 TestCompletionCallback callback1; | 602 TestCompletionCallback callback1; |
605 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 603 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
606 NULL, NULL, BoundNetLog()); | 604 NULL, NULL, BoundNetLog()); |
607 EXPECT_EQ(ERR_IO_PENDING, rv); | 605 EXPECT_EQ(ERR_IO_PENDING, rv); |
608 | 606 |
609 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 607 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
610 factory->pending_requests()[0]->script_data()->url()); | 608 factory->pending_requests()[0]->script_data()->url()); |
611 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 609 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
612 | 610 |
613 ASSERT_EQ(1u, resolver.pending_requests().size()); | 611 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
614 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 612 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
615 | 613 |
616 // Simulate a failure in the PAC executor. | 614 // Simulate a failure in the PAC executor. |
617 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); | 615 resolver.pending_jobs()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); |
618 | 616 |
619 EXPECT_EQ(OK, callback1.WaitForResult()); | 617 EXPECT_EQ(OK, callback1.WaitForResult()); |
620 | 618 |
621 // Since the PAC script was non-mandatory, we should have fallen-back to | 619 // Since the PAC script was non-mandatory, we should have fallen-back to |
622 // DIRECT. | 620 // DIRECT. |
623 EXPECT_TRUE(info.is_direct()); | 621 EXPECT_TRUE(info.is_direct()); |
624 EXPECT_TRUE(info.did_use_pac_script()); | 622 EXPECT_TRUE(info.did_use_pac_script()); |
625 EXPECT_EQ(1, info.config_id()); | 623 EXPECT_EQ(1, info.config_id()); |
626 | 624 |
627 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 625 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
661 ProxyInfo info; | 659 ProxyInfo info; |
662 TestCompletionCallback callback1; | 660 TestCompletionCallback callback1; |
663 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 661 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
664 NULL, NULL, BoundNetLog()); | 662 NULL, NULL, BoundNetLog()); |
665 EXPECT_EQ(ERR_IO_PENDING, rv); | 663 EXPECT_EQ(ERR_IO_PENDING, rv); |
666 | 664 |
667 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 665 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
668 factory->pending_requests()[0]->script_data()->url()); | 666 factory->pending_requests()[0]->script_data()->url()); |
669 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 667 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
670 | 668 |
671 ASSERT_EQ(1u, resolver.pending_requests().size()); | 669 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
672 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 670 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
673 | 671 |
674 // Set the result in proxy resolver. | 672 // Set the result in proxy resolver. |
675 resolver.pending_requests()[0]->results()->UsePacString( | 673 resolver.pending_jobs()[0]->results()->UsePacString( |
676 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 674 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
677 resolver.pending_requests()[0]->CompleteNow(OK); | 675 resolver.pending_jobs()[0]->CompleteNow(OK); |
678 | 676 |
679 EXPECT_EQ(OK, callback1.WaitForResult()); | 677 EXPECT_EQ(OK, callback1.WaitForResult()); |
680 EXPECT_TRUE(info.is_direct()); | 678 EXPECT_TRUE(info.is_direct()); |
681 | 679 |
682 // Fallback 1. | 680 // Fallback 1. |
683 TestCompletionCallback callback2; | 681 TestCompletionCallback callback2; |
684 rv = service.ReconsiderProxyAfterError( | 682 rv = service.ReconsiderProxyAfterError( |
685 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 683 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
686 callback2.callback(), NULL, NULL, BoundNetLog()); | 684 callback2.callback(), NULL, NULL, BoundNetLog()); |
687 EXPECT_EQ(OK, rv); | 685 EXPECT_EQ(OK, rv); |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
733 make_scoped_ptr(factory), NULL); | 731 make_scoped_ptr(factory), NULL); |
734 | 732 |
735 // Resolve something. | 733 // Resolve something. |
736 GURL url("http://www.google.com/"); | 734 GURL url("http://www.google.com/"); |
737 ProxyInfo info; | 735 ProxyInfo info; |
738 TestCompletionCallback callback; | 736 TestCompletionCallback callback; |
739 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 737 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
740 NULL, NULL, BoundNetLog()); | 738 NULL, NULL, BoundNetLog()); |
741 ASSERT_EQ(ERR_IO_PENDING, rv); | 739 ASSERT_EQ(ERR_IO_PENDING, rv); |
742 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 740 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
743 ASSERT_EQ(1u, resolver.pending_requests().size()); | 741 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
744 | 742 |
745 // Set the result in proxy resolver. | 743 // Set the result in proxy resolver. |
746 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 744 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy"); |
747 resolver.pending_requests()[0]->CompleteNow(OK); | 745 resolver.pending_jobs()[0]->CompleteNow(OK); |
748 | 746 |
749 EXPECT_EQ(OK, callback.WaitForResult()); | 747 EXPECT_EQ(OK, callback.WaitForResult()); |
750 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 748 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
751 EXPECT_TRUE(info.did_use_pac_script()); | 749 EXPECT_TRUE(info.did_use_pac_script()); |
752 | 750 |
753 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 751 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
754 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 752 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
755 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 753 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
756 } | 754 } |
757 | 755 |
(...skipping 17 matching lines...) Expand all Loading... |
775 ProxyInfo info; | 773 ProxyInfo info; |
776 TestCompletionCallback callback1; | 774 TestCompletionCallback callback1; |
777 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 775 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
778 NULL, NULL, BoundNetLog()); | 776 NULL, NULL, BoundNetLog()); |
779 EXPECT_EQ(ERR_IO_PENDING, rv); | 777 EXPECT_EQ(ERR_IO_PENDING, rv); |
780 | 778 |
781 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 779 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
782 factory->pending_requests()[0]->script_data()->url()); | 780 factory->pending_requests()[0]->script_data()->url()); |
783 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 781 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
784 | 782 |
785 ASSERT_EQ(1u, resolver.pending_requests().size()); | 783 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
786 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 784 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
787 | 785 |
788 // Fail the first resolve request in MockAsyncProxyResolver. | 786 // Fail the first resolve request in MockAsyncProxyResolver. |
789 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 787 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); |
790 | 788 |
791 // Although the proxy resolver failed the request, ProxyService implicitly | 789 // Although the proxy resolver failed the request, ProxyService implicitly |
792 // falls-back to DIRECT. | 790 // falls-back to DIRECT. |
793 EXPECT_EQ(OK, callback1.WaitForResult()); | 791 EXPECT_EQ(OK, callback1.WaitForResult()); |
794 EXPECT_TRUE(info.is_direct()); | 792 EXPECT_TRUE(info.is_direct()); |
795 | 793 |
796 // Failed PAC executions still have proxy resolution times. | 794 // Failed PAC executions still have proxy resolution times. |
797 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 795 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
798 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 796 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
799 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 797 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
800 | 798 |
801 // The second resolve request will try to run through the proxy resolver, | 799 // The second resolve request will try to run through the proxy resolver, |
802 // regardless of whether the first request failed in it. | 800 // regardless of whether the first request failed in it. |
803 TestCompletionCallback callback2; | 801 TestCompletionCallback callback2; |
804 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, | 802 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, |
805 NULL, BoundNetLog()); | 803 NULL, BoundNetLog()); |
806 EXPECT_EQ(ERR_IO_PENDING, rv); | 804 EXPECT_EQ(ERR_IO_PENDING, rv); |
807 | 805 |
808 ASSERT_EQ(1u, resolver.pending_requests().size()); | 806 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
809 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 807 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
810 | 808 |
811 // This time we will have the resolver succeed (perhaps the PAC script has | 809 // This time we will have the resolver succeed (perhaps the PAC script has |
812 // a dependency on the current time). | 810 // a dependency on the current time). |
813 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 811 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
814 resolver.pending_requests()[0]->CompleteNow(OK); | 812 resolver.pending_jobs()[0]->CompleteNow(OK); |
815 | 813 |
816 EXPECT_EQ(OK, callback2.WaitForResult()); | 814 EXPECT_EQ(OK, callback2.WaitForResult()); |
817 EXPECT_FALSE(info.is_direct()); | 815 EXPECT_FALSE(info.is_direct()); |
818 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 816 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
819 } | 817 } |
820 | 818 |
821 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { | 819 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { |
822 // Test what happens when the ProxyResolver fails with a fatal error while | 820 // Test what happens when the ProxyResolver fails with a fatal error while |
823 // a GetProxyForURL() call is in progress. | 821 // a GetProxyForURL() call is in progress. |
824 | 822 |
(...skipping 14 matching lines...) Expand all Loading... |
839 int rv = | 837 int rv = |
840 service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback1.callback(), | 838 service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback1.callback(), |
841 nullptr, nullptr, BoundNetLog()); | 839 nullptr, nullptr, BoundNetLog()); |
842 EXPECT_EQ(ERR_IO_PENDING, rv); | 840 EXPECT_EQ(ERR_IO_PENDING, rv); |
843 | 841 |
844 ASSERT_EQ(1u, factory->pending_requests().size()); | 842 ASSERT_EQ(1u, factory->pending_requests().size()); |
845 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 843 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
846 factory->pending_requests()[0]->script_data()->url()); | 844 factory->pending_requests()[0]->script_data()->url()); |
847 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 845 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
848 | 846 |
849 ASSERT_EQ(1u, resolver.pending_requests().size()); | 847 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
850 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 848 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
851 | 849 |
852 // Fail the first resolve request in MockAsyncProxyResolver. | 850 // Fail the first resolve request in MockAsyncProxyResolver. |
853 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 851 resolver.pending_jobs()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
854 | 852 |
855 // Although the proxy resolver failed the request, ProxyService implicitly | 853 // Although the proxy resolver failed the request, ProxyService implicitly |
856 // falls-back to DIRECT. | 854 // falls-back to DIRECT. |
857 EXPECT_EQ(OK, callback1.WaitForResult()); | 855 EXPECT_EQ(OK, callback1.WaitForResult()); |
858 EXPECT_TRUE(info.is_direct()); | 856 EXPECT_TRUE(info.is_direct()); |
859 | 857 |
860 // Failed PAC executions still have proxy resolution times. | 858 // Failed PAC executions still have proxy resolution times. |
861 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 859 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
862 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 860 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
863 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 861 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
864 | 862 |
865 // With no other requests, the ProxyService waits for a new request before | 863 // With no other requests, the ProxyService waits for a new request before |
866 // initializing a new ProxyResolver. | 864 // initializing a new ProxyResolver. |
867 EXPECT_TRUE(factory->pending_requests().empty()); | 865 EXPECT_TRUE(factory->pending_requests().empty()); |
868 | 866 |
869 TestCompletionCallback callback2; | 867 TestCompletionCallback callback2; |
870 rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback2.callback(), | 868 rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback2.callback(), |
871 nullptr, nullptr, BoundNetLog()); | 869 nullptr, nullptr, BoundNetLog()); |
872 EXPECT_EQ(ERR_IO_PENDING, rv); | 870 EXPECT_EQ(ERR_IO_PENDING, rv); |
873 | 871 |
874 ASSERT_EQ(1u, factory->pending_requests().size()); | 872 ASSERT_EQ(1u, factory->pending_requests().size()); |
875 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 873 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
876 factory->pending_requests()[0]->script_data()->url()); | 874 factory->pending_requests()[0]->script_data()->url()); |
877 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 875 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
878 | 876 |
879 ASSERT_EQ(1u, resolver.pending_requests().size()); | 877 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
880 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 878 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
881 | 879 |
882 // This time we will have the resolver succeed. | 880 // This time we will have the resolver succeed. |
883 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 881 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
884 resolver.pending_requests()[0]->CompleteNow(OK); | 882 resolver.pending_jobs()[0]->CompleteNow(OK); |
885 | 883 |
886 EXPECT_EQ(OK, callback2.WaitForResult()); | 884 EXPECT_EQ(OK, callback2.WaitForResult()); |
887 EXPECT_FALSE(info.is_direct()); | 885 EXPECT_FALSE(info.is_direct()); |
888 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 886 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
889 } | 887 } |
890 | 888 |
891 TEST_F(ProxyServiceTest, | 889 TEST_F(ProxyServiceTest, |
892 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { | 890 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { |
893 // Test what happens when the ProxyResolver fails with a fatal error while | 891 // Test what happens when the ProxyResolver fails with a fatal error while |
894 // a GetProxyForURL() call is in progress. | 892 // a GetProxyForURL() call is in progress. |
(...skipping 20 matching lines...) Expand all Loading... |
915 TestCompletionCallback callback2; | 913 TestCompletionCallback callback2; |
916 rv = service.ResolveProxy(url2, net::LOAD_NORMAL, &info, callback2.callback(), | 914 rv = service.ResolveProxy(url2, net::LOAD_NORMAL, &info, callback2.callback(), |
917 nullptr, nullptr, BoundNetLog()); | 915 nullptr, nullptr, BoundNetLog()); |
918 EXPECT_EQ(ERR_IO_PENDING, rv); | 916 EXPECT_EQ(ERR_IO_PENDING, rv); |
919 | 917 |
920 ASSERT_EQ(1u, factory->pending_requests().size()); | 918 ASSERT_EQ(1u, factory->pending_requests().size()); |
921 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 919 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
922 factory->pending_requests()[0]->script_data()->url()); | 920 factory->pending_requests()[0]->script_data()->url()); |
923 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 921 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
924 | 922 |
925 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 923 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); |
926 | 924 |
927 // Fail the first resolve request in MockAsyncProxyResolver. | 925 // Fail the first resolve request in MockAsyncProxyResolver. |
928 requests[url1]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 926 jobs[url1]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
929 | 927 |
930 // Although the proxy resolver failed the request, ProxyService implicitly | 928 // Although the proxy resolver failed the request, ProxyService implicitly |
931 // falls-back to DIRECT. | 929 // falls-back to DIRECT. |
932 EXPECT_EQ(OK, callback1.WaitForResult()); | 930 EXPECT_EQ(OK, callback1.WaitForResult()); |
933 EXPECT_TRUE(info.is_direct()); | 931 EXPECT_TRUE(info.is_direct()); |
934 | 932 |
935 // Failed PAC executions still have proxy resolution times. | 933 // Failed PAC executions still have proxy resolution times. |
936 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 934 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
937 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 935 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
938 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 936 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
939 | 937 |
940 // The second request is cancelled when the proxy resolver terminates. | 938 // The second request is cancelled when the proxy resolver terminates. |
941 requests = GetCancelledRequestsForURLs(resolver, url2); | 939 jobs = GetCancelledJobsForURLs(resolver, url2); |
942 | 940 |
943 // Since a second request was in progress, the ProxyService starts | 941 // Since a second request was in progress, the ProxyService starts |
944 // initializating a new ProxyResolver. | 942 // initializating a new ProxyResolver. |
945 ASSERT_EQ(1u, factory->pending_requests().size()); | 943 ASSERT_EQ(1u, factory->pending_requests().size()); |
946 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 944 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
947 factory->pending_requests()[0]->script_data()->url()); | 945 factory->pending_requests()[0]->script_data()->url()); |
948 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 946 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
949 | 947 |
950 requests = GetPendingRequestsForURLs(resolver, url2); | 948 jobs = GetPendingJobsForURLs(resolver, url2); |
951 | 949 |
952 // This request succeeds. | 950 // This request succeeds. |
953 requests[url2]->results()->UseNamedProxy("foopy_valid:8080"); | 951 jobs[url2]->results()->UseNamedProxy("foopy_valid:8080"); |
954 requests[url2]->CompleteNow(OK); | 952 jobs[url2]->CompleteNow(OK); |
955 | 953 |
956 EXPECT_EQ(OK, callback2.WaitForResult()); | 954 EXPECT_EQ(OK, callback2.WaitForResult()); |
957 EXPECT_FALSE(info.is_direct()); | 955 EXPECT_FALSE(info.is_direct()); |
958 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 956 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
959 } | 957 } |
960 | 958 |
961 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { | 959 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { |
962 // Test what happens when the ProxyScriptResolver fails to download a | 960 // Test what happens when the ProxyScriptResolver fails to download a |
963 // mandatory PAC script. | 961 // mandatory PAC script. |
964 | 962 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1074 ProxyInfo info; | 1072 ProxyInfo info; |
1075 TestCompletionCallback callback1; | 1073 TestCompletionCallback callback1; |
1076 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1074 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1077 NULL, NULL, BoundNetLog()); | 1075 NULL, NULL, BoundNetLog()); |
1078 EXPECT_EQ(ERR_IO_PENDING, rv); | 1076 EXPECT_EQ(ERR_IO_PENDING, rv); |
1079 | 1077 |
1080 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1078 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1081 factory->pending_requests()[0]->script_data()->url()); | 1079 factory->pending_requests()[0]->script_data()->url()); |
1082 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1080 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1083 | 1081 |
1084 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1082 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1085 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1083 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1086 | 1084 |
1087 // Fail the first resolve request in MockAsyncProxyResolver. | 1085 // Fail the first resolve request in MockAsyncProxyResolver. |
1088 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1086 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); |
1089 | 1087 |
1090 // As the proxy resolver failed the request and is configured for a mandatory | 1088 // As the proxy resolver failed the request and is configured for a mandatory |
1091 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1089 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
1092 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1090 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1093 callback1.WaitForResult()); | 1091 callback1.WaitForResult()); |
1094 EXPECT_FALSE(info.is_direct()); | 1092 EXPECT_FALSE(info.is_direct()); |
1095 | 1093 |
1096 // The second resolve request will try to run through the proxy resolver, | 1094 // The second resolve request will try to run through the proxy resolver, |
1097 // regardless of whether the first request failed in it. | 1095 // regardless of whether the first request failed in it. |
1098 TestCompletionCallback callback2; | 1096 TestCompletionCallback callback2; |
1099 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, | 1097 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, |
1100 NULL, BoundNetLog()); | 1098 NULL, BoundNetLog()); |
1101 EXPECT_EQ(ERR_IO_PENDING, rv); | 1099 EXPECT_EQ(ERR_IO_PENDING, rv); |
1102 | 1100 |
1103 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1101 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1104 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1102 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1105 | 1103 |
1106 // This time we will have the resolver succeed (perhaps the PAC script has | 1104 // This time we will have the resolver succeed (perhaps the PAC script has |
1107 // a dependency on the current time). | 1105 // a dependency on the current time). |
1108 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 1106 resolver.pending_jobs()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
1109 resolver.pending_requests()[0]->CompleteNow(OK); | 1107 resolver.pending_jobs()[0]->CompleteNow(OK); |
1110 | 1108 |
1111 EXPECT_EQ(OK, callback2.WaitForResult()); | 1109 EXPECT_EQ(OK, callback2.WaitForResult()); |
1112 EXPECT_FALSE(info.is_direct()); | 1110 EXPECT_FALSE(info.is_direct()); |
1113 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 1111 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
1114 } | 1112 } |
1115 | 1113 |
1116 TEST_F(ProxyServiceTest, ProxyFallback) { | 1114 TEST_F(ProxyServiceTest, ProxyFallback) { |
1117 // Test what happens when we specify multiple proxy servers and some of them | 1115 // Test what happens when we specify multiple proxy servers and some of them |
1118 // are bad. | 1116 // are bad. |
1119 | 1117 |
(...skipping 13 matching lines...) Expand all Loading... |
1133 ProxyInfo info; | 1131 ProxyInfo info; |
1134 TestCompletionCallback callback1; | 1132 TestCompletionCallback callback1; |
1135 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1133 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1136 NULL, NULL, BoundNetLog()); | 1134 NULL, NULL, BoundNetLog()); |
1137 EXPECT_EQ(ERR_IO_PENDING, rv); | 1135 EXPECT_EQ(ERR_IO_PENDING, rv); |
1138 | 1136 |
1139 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1137 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1140 factory->pending_requests()[0]->script_data()->url()); | 1138 factory->pending_requests()[0]->script_data()->url()); |
1141 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1139 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1142 | 1140 |
1143 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1141 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1144 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1142 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1145 | 1143 |
1146 // Set the result in proxy resolver. | 1144 // Set the result in proxy resolver. |
1147 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1145 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1148 "foopy1:8080;foopy2:9090"); | 1146 "foopy1:8080;foopy2:9090"); |
1149 resolver.pending_requests()[0]->CompleteNow(OK); | 1147 resolver.pending_jobs()[0]->CompleteNow(OK); |
1150 | 1148 |
1151 // The first item is valid. | 1149 // The first item is valid. |
1152 EXPECT_EQ(OK, callback1.WaitForResult()); | 1150 EXPECT_EQ(OK, callback1.WaitForResult()); |
1153 EXPECT_FALSE(info.is_direct()); | 1151 EXPECT_FALSE(info.is_direct()); |
1154 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1152 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1155 | 1153 |
1156 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1154 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1157 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1155 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1158 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1156 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1159 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); | 1157 base::TimeTicks proxy_resolve_start_time = info.proxy_resolve_start_time(); |
(...skipping 18 matching lines...) Expand all Loading... |
1178 service.ReportSuccess(info, &test_delegate); | 1176 service.ReportSuccess(info, &test_delegate); |
1179 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); | 1177 EXPECT_EQ("foopy1:8080", test_delegate.proxy_server().ToURI()); |
1180 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, | 1178 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, |
1181 test_delegate.proxy_fallback_net_error()); | 1179 test_delegate.proxy_fallback_net_error()); |
1182 | 1180 |
1183 TestCompletionCallback callback3; | 1181 TestCompletionCallback callback3; |
1184 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback3.callback(), NULL, | 1182 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback3.callback(), NULL, |
1185 NULL, BoundNetLog()); | 1183 NULL, BoundNetLog()); |
1186 EXPECT_EQ(ERR_IO_PENDING, rv); | 1184 EXPECT_EQ(ERR_IO_PENDING, rv); |
1187 | 1185 |
1188 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1186 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1189 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1187 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1190 | 1188 |
1191 // Set the result in proxy resolver -- the second result is already known | 1189 // Set the result in proxy resolver -- the second result is already known |
1192 // to be bad, so we will not try to use it initially. | 1190 // to be bad, so we will not try to use it initially. |
1193 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1191 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1194 "foopy3:7070;foopy1:8080;foopy2:9090"); | 1192 "foopy3:7070;foopy1:8080;foopy2:9090"); |
1195 resolver.pending_requests()[0]->CompleteNow(OK); | 1193 resolver.pending_jobs()[0]->CompleteNow(OK); |
1196 | 1194 |
1197 EXPECT_EQ(OK, callback3.WaitForResult()); | 1195 EXPECT_EQ(OK, callback3.WaitForResult()); |
1198 EXPECT_FALSE(info.is_direct()); | 1196 EXPECT_FALSE(info.is_direct()); |
1199 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1197 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1200 | 1198 |
1201 // Proxy times should have been updated, so get them again. | 1199 // Proxy times should have been updated, so get them again. |
1202 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1200 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1203 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1201 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1204 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1202 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1205 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1203 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... |
1237 // Proxy times should not have been modified by fallback. | 1235 // Proxy times should not have been modified by fallback. |
1238 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); | 1236 EXPECT_EQ(proxy_resolve_start_time, info.proxy_resolve_start_time()); |
1239 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); | 1237 EXPECT_EQ(proxy_resolve_end_time, info.proxy_resolve_end_time()); |
1240 | 1238 |
1241 // Look up proxies again | 1239 // Look up proxies again |
1242 TestCompletionCallback callback7; | 1240 TestCompletionCallback callback7; |
1243 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback7.callback(), NULL, | 1241 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback7.callback(), NULL, |
1244 NULL, BoundNetLog()); | 1242 NULL, BoundNetLog()); |
1245 EXPECT_EQ(ERR_IO_PENDING, rv); | 1243 EXPECT_EQ(ERR_IO_PENDING, rv); |
1246 | 1244 |
1247 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1245 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1248 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1246 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1249 | 1247 |
1250 // This time, the first 3 results have been found to be bad, but only the | 1248 // This time, the first 3 results have been found to be bad, but only the |
1251 // first proxy has been confirmed ... | 1249 // first proxy has been confirmed ... |
1252 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1250 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1253 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); | 1251 "foopy1:8080;foopy3:7070;foopy2:9090;foopy4:9091"); |
1254 resolver.pending_requests()[0]->CompleteNow(OK); | 1252 resolver.pending_jobs()[0]->CompleteNow(OK); |
1255 | 1253 |
1256 // ... therefore, we should see the second proxy first. | 1254 // ... therefore, we should see the second proxy first. |
1257 EXPECT_EQ(OK, callback7.WaitForResult()); | 1255 EXPECT_EQ(OK, callback7.WaitForResult()); |
1258 EXPECT_FALSE(info.is_direct()); | 1256 EXPECT_FALSE(info.is_direct()); |
1259 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); | 1257 EXPECT_EQ("foopy3:7070", info.proxy_server().ToURI()); |
1260 | 1258 |
1261 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); | 1259 EXPECT_LE(proxy_resolve_end_time, info.proxy_resolve_start_time()); |
1262 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1260 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1263 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1261 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1264 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 1262 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
(...skipping 18 matching lines...) Expand all Loading... |
1283 ProxyInfo info; | 1281 ProxyInfo info; |
1284 TestCompletionCallback callback1; | 1282 TestCompletionCallback callback1; |
1285 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1283 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1286 NULL, NULL, BoundNetLog()); | 1284 NULL, NULL, BoundNetLog()); |
1287 EXPECT_EQ(ERR_IO_PENDING, rv); | 1285 EXPECT_EQ(ERR_IO_PENDING, rv); |
1288 | 1286 |
1289 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1287 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1290 factory->pending_requests()[0]->script_data()->url()); | 1288 factory->pending_requests()[0]->script_data()->url()); |
1291 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1289 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1292 | 1290 |
1293 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1291 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1294 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1292 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1295 | 1293 |
1296 // Set the result in proxy resolver. | 1294 // Set the result in proxy resolver. |
1297 resolver.pending_requests()[0]->results()->UsePacString( | 1295 resolver.pending_jobs()[0]->results()->UsePacString( |
1298 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 1296 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
1299 resolver.pending_requests()[0]->CompleteNow(OK); | 1297 resolver.pending_jobs()[0]->CompleteNow(OK); |
1300 | 1298 |
1301 // Get the first result. | 1299 // Get the first result. |
1302 EXPECT_EQ(OK, callback1.WaitForResult()); | 1300 EXPECT_EQ(OK, callback1.WaitForResult()); |
1303 EXPECT_FALSE(info.is_direct()); | 1301 EXPECT_FALSE(info.is_direct()); |
1304 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1302 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1305 | 1303 |
1306 // Fake an error on the proxy. | 1304 // Fake an error on the proxy. |
1307 TestCompletionCallback callback2; | 1305 TestCompletionCallback callback2; |
1308 rv = service.ReconsiderProxyAfterError( | 1306 rv = service.ReconsiderProxyAfterError( |
1309 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1307 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1356 ProxyInfo info; | 1354 ProxyInfo info; |
1357 TestCompletionCallback callback1; | 1355 TestCompletionCallback callback1; |
1358 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1356 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1359 NULL, NULL, BoundNetLog()); | 1357 NULL, NULL, BoundNetLog()); |
1360 EXPECT_EQ(ERR_IO_PENDING, rv); | 1358 EXPECT_EQ(ERR_IO_PENDING, rv); |
1361 | 1359 |
1362 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1360 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1363 factory->pending_requests()[0]->script_data()->url()); | 1361 factory->pending_requests()[0]->script_data()->url()); |
1364 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1362 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1365 | 1363 |
1366 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1364 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1367 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1365 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1368 | 1366 |
1369 // Set the result in proxy resolver. | 1367 // Set the result in proxy resolver. |
1370 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1368 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1371 "foopy1:8080;foopy2:9090"); | 1369 "foopy1:8080;foopy2:9090"); |
1372 resolver.pending_requests()[0]->CompleteNow(OK); | 1370 resolver.pending_jobs()[0]->CompleteNow(OK); |
1373 | 1371 |
1374 // The first item is valid. | 1372 // The first item is valid. |
1375 EXPECT_EQ(OK, callback1.WaitForResult()); | 1373 EXPECT_EQ(OK, callback1.WaitForResult()); |
1376 EXPECT_FALSE(info.is_direct()); | 1374 EXPECT_FALSE(info.is_direct()); |
1377 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1375 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1378 | 1376 |
1379 // Fake an error on the proxy, and also a new configuration on the proxy. | 1377 // Fake an error on the proxy, and also a new configuration on the proxy. |
1380 config_service->SetConfig( | 1378 config_service->SetConfig( |
1381 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 1379 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
1382 | 1380 |
1383 TestCompletionCallback callback2; | 1381 TestCompletionCallback callback2; |
1384 rv = service.ReconsiderProxyAfterError( | 1382 rv = service.ReconsiderProxyAfterError( |
1385 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1383 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1386 callback2.callback(), NULL, NULL, BoundNetLog()); | 1384 callback2.callback(), NULL, NULL, BoundNetLog()); |
1387 EXPECT_EQ(ERR_IO_PENDING, rv); | 1385 EXPECT_EQ(ERR_IO_PENDING, rv); |
1388 | 1386 |
1389 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 1387 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
1390 factory->pending_requests()[0]->script_data()->url()); | 1388 factory->pending_requests()[0]->script_data()->url()); |
1391 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1389 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1392 | 1390 |
1393 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1391 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1394 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1392 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1395 | 1393 |
1396 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1394 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1397 "foopy1:8080;foopy2:9090"); | 1395 "foopy1:8080;foopy2:9090"); |
1398 resolver.pending_requests()[0]->CompleteNow(OK); | 1396 resolver.pending_jobs()[0]->CompleteNow(OK); |
1399 | 1397 |
1400 // The first proxy is still there since the configuration changed. | 1398 // The first proxy is still there since the configuration changed. |
1401 EXPECT_EQ(OK, callback2.WaitForResult()); | 1399 EXPECT_EQ(OK, callback2.WaitForResult()); |
1402 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1400 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1403 | 1401 |
1404 // We fake another error. It should now ignore the first one. | 1402 // We fake another error. It should now ignore the first one. |
1405 TestCompletionCallback callback3; | 1403 TestCompletionCallback callback3; |
1406 rv = service.ReconsiderProxyAfterError( | 1404 rv = service.ReconsiderProxyAfterError( |
1407 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1405 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1408 callback3.callback(), NULL, NULL, BoundNetLog()); | 1406 callback3.callback(), NULL, NULL, BoundNetLog()); |
1409 EXPECT_EQ(OK, rv); | 1407 EXPECT_EQ(OK, rv); |
1410 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1408 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1411 | 1409 |
1412 // We simulate a new configuration. | 1410 // We simulate a new configuration. |
1413 config_service->SetConfig( | 1411 config_service->SetConfig( |
1414 ProxyConfig::CreateFromCustomPacURL( | 1412 ProxyConfig::CreateFromCustomPacURL( |
1415 GURL("http://foopy-new2/proxy.pac"))); | 1413 GURL("http://foopy-new2/proxy.pac"))); |
1416 | 1414 |
1417 // We fake another error. It should go back to the first proxy. | 1415 // We fake another error. It should go back to the first proxy. |
1418 TestCompletionCallback callback4; | 1416 TestCompletionCallback callback4; |
1419 rv = service.ReconsiderProxyAfterError( | 1417 rv = service.ReconsiderProxyAfterError( |
1420 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1418 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1421 callback4.callback(), NULL, NULL, BoundNetLog()); | 1419 callback4.callback(), NULL, NULL, BoundNetLog()); |
1422 EXPECT_EQ(ERR_IO_PENDING, rv); | 1420 EXPECT_EQ(ERR_IO_PENDING, rv); |
1423 | 1421 |
1424 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 1422 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
1425 factory->pending_requests()[0]->script_data()->url()); | 1423 factory->pending_requests()[0]->script_data()->url()); |
1426 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1424 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1427 | 1425 |
1428 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1426 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1429 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1427 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1430 | 1428 |
1431 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1429 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1432 "foopy1:8080;foopy2:9090"); | 1430 "foopy1:8080;foopy2:9090"); |
1433 resolver.pending_requests()[0]->CompleteNow(OK); | 1431 resolver.pending_jobs()[0]->CompleteNow(OK); |
1434 | 1432 |
1435 EXPECT_EQ(OK, callback4.WaitForResult()); | 1433 EXPECT_EQ(OK, callback4.WaitForResult()); |
1436 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1434 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1437 | 1435 |
1438 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1436 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1439 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1437 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1440 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1438 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
1441 } | 1439 } |
1442 | 1440 |
1443 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { | 1441 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { |
(...skipping 14 matching lines...) Expand all Loading... |
1458 // Get the proxy information. | 1456 // Get the proxy information. |
1459 ProxyInfo info; | 1457 ProxyInfo info; |
1460 TestCompletionCallback callback1; | 1458 TestCompletionCallback callback1; |
1461 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1459 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1462 NULL, NULL, BoundNetLog()); | 1460 NULL, NULL, BoundNetLog()); |
1463 EXPECT_EQ(ERR_IO_PENDING, rv); | 1461 EXPECT_EQ(ERR_IO_PENDING, rv); |
1464 | 1462 |
1465 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1463 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1466 factory->pending_requests()[0]->script_data()->url()); | 1464 factory->pending_requests()[0]->script_data()->url()); |
1467 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1465 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1468 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1466 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1469 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1467 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1470 | 1468 |
1471 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1469 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1472 "foopy1:8080;foopy2:9090"); | 1470 "foopy1:8080;foopy2:9090"); |
1473 resolver.pending_requests()[0]->CompleteNow(OK); | 1471 resolver.pending_jobs()[0]->CompleteNow(OK); |
1474 | 1472 |
1475 // The first item is valid. | 1473 // The first item is valid. |
1476 EXPECT_EQ(OK, callback1.WaitForResult()); | 1474 EXPECT_EQ(OK, callback1.WaitForResult()); |
1477 EXPECT_FALSE(info.is_direct()); | 1475 EXPECT_FALSE(info.is_direct()); |
1478 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1476 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1479 | 1477 |
1480 // Fake a proxy error. | 1478 // Fake a proxy error. |
1481 TestCompletionCallback callback2; | 1479 TestCompletionCallback callback2; |
1482 rv = service.ReconsiderProxyAfterError( | 1480 rv = service.ReconsiderProxyAfterError( |
1483 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1481 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1484 callback2.callback(), NULL, NULL, BoundNetLog()); | 1482 callback2.callback(), NULL, NULL, BoundNetLog()); |
1485 EXPECT_EQ(OK, rv); | 1483 EXPECT_EQ(OK, rv); |
1486 | 1484 |
1487 // The first proxy is ignored, and the second one is selected. | 1485 // The first proxy is ignored, and the second one is selected. |
1488 EXPECT_FALSE(info.is_direct()); | 1486 EXPECT_FALSE(info.is_direct()); |
1489 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1487 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1490 | 1488 |
1491 // Fake a PAC failure. | 1489 // Fake a PAC failure. |
1492 ProxyInfo info2; | 1490 ProxyInfo info2; |
1493 TestCompletionCallback callback3; | 1491 TestCompletionCallback callback3; |
1494 rv = service.ResolveProxy(url, LOAD_NORMAL, &info2, callback3.callback(), | 1492 rv = service.ResolveProxy(url, LOAD_NORMAL, &info2, callback3.callback(), |
1495 NULL, NULL, BoundNetLog()); | 1493 NULL, NULL, BoundNetLog()); |
1496 EXPECT_EQ(ERR_IO_PENDING, rv); | 1494 EXPECT_EQ(ERR_IO_PENDING, rv); |
1497 | 1495 |
1498 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1496 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1499 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1497 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1500 | 1498 |
1501 // This simulates a javascript runtime error in the PAC script. | 1499 // This simulates a javascript runtime error in the PAC script. |
1502 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1500 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); |
1503 | 1501 |
1504 // Although the resolver failed, the ProxyService will implicitly fall-back | 1502 // Although the resolver failed, the ProxyService will implicitly fall-back |
1505 // to a DIRECT connection. | 1503 // to a DIRECT connection. |
1506 EXPECT_EQ(OK, callback3.WaitForResult()); | 1504 EXPECT_EQ(OK, callback3.WaitForResult()); |
1507 EXPECT_TRUE(info2.is_direct()); | 1505 EXPECT_TRUE(info2.is_direct()); |
1508 EXPECT_FALSE(info2.is_empty()); | 1506 EXPECT_FALSE(info2.is_empty()); |
1509 | 1507 |
1510 // The PAC script will work properly next time and successfully return a | 1508 // The PAC script will work properly next time and successfully return a |
1511 // proxy list. Since we have not marked the configuration as bad, it should | 1509 // proxy list. Since we have not marked the configuration as bad, it should |
1512 // "just work" the next time we call it. | 1510 // "just work" the next time we call it. |
1513 ProxyInfo info3; | 1511 ProxyInfo info3; |
1514 TestCompletionCallback callback4; | 1512 TestCompletionCallback callback4; |
1515 rv = service.ReconsiderProxyAfterError( | 1513 rv = service.ReconsiderProxyAfterError( |
1516 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, | 1514 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, |
1517 callback4.callback(), NULL, NULL, BoundNetLog()); | 1515 callback4.callback(), NULL, NULL, BoundNetLog()); |
1518 EXPECT_EQ(ERR_IO_PENDING, rv); | 1516 EXPECT_EQ(ERR_IO_PENDING, rv); |
1519 | 1517 |
1520 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1518 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1521 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1519 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1522 | 1520 |
1523 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1521 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1524 "foopy1:8080;foopy2:9090"); | 1522 "foopy1:8080;foopy2:9090"); |
1525 resolver.pending_requests()[0]->CompleteNow(OK); | 1523 resolver.pending_jobs()[0]->CompleteNow(OK); |
1526 | 1524 |
1527 // The first proxy is not there since the it was added to the bad proxies | 1525 // The first proxy is not there since the it was added to the bad proxies |
1528 // list by the earlier ReconsiderProxyAfterError(). | 1526 // list by the earlier ReconsiderProxyAfterError(). |
1529 EXPECT_EQ(OK, callback4.WaitForResult()); | 1527 EXPECT_EQ(OK, callback4.WaitForResult()); |
1530 EXPECT_FALSE(info3.is_direct()); | 1528 EXPECT_FALSE(info3.is_direct()); |
1531 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 1529 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
1532 | 1530 |
1533 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1531 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
1534 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1532 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
1535 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1533 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
(...skipping 20 matching lines...) Expand all Loading... |
1556 // Get the proxy information. | 1554 // Get the proxy information. |
1557 ProxyInfo info; | 1555 ProxyInfo info; |
1558 TestCompletionCallback callback1; | 1556 TestCompletionCallback callback1; |
1559 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1557 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
1560 NULL, NULL, BoundNetLog()); | 1558 NULL, NULL, BoundNetLog()); |
1561 EXPECT_EQ(ERR_IO_PENDING, rv); | 1559 EXPECT_EQ(ERR_IO_PENDING, rv); |
1562 | 1560 |
1563 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1561 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1564 factory->pending_requests()[0]->script_data()->url()); | 1562 factory->pending_requests()[0]->script_data()->url()); |
1565 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1563 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1566 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1564 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1567 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1565 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1568 | 1566 |
1569 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1567 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1570 "foopy1:8080;foopy2:9090"); | 1568 "foopy1:8080;foopy2:9090"); |
1571 resolver.pending_requests()[0]->CompleteNow(OK); | 1569 resolver.pending_jobs()[0]->CompleteNow(OK); |
1572 | 1570 |
1573 // The first item is valid. | 1571 // The first item is valid. |
1574 EXPECT_EQ(OK, callback1.WaitForResult()); | 1572 EXPECT_EQ(OK, callback1.WaitForResult()); |
1575 EXPECT_FALSE(info.is_direct()); | 1573 EXPECT_FALSE(info.is_direct()); |
1576 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1574 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
1577 | 1575 |
1578 // Fake a proxy error. | 1576 // Fake a proxy error. |
1579 TestCompletionCallback callback2; | 1577 TestCompletionCallback callback2; |
1580 rv = service.ReconsiderProxyAfterError( | 1578 rv = service.ReconsiderProxyAfterError( |
1581 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1579 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
1582 callback2.callback(), NULL, NULL, BoundNetLog()); | 1580 callback2.callback(), NULL, NULL, BoundNetLog()); |
1583 EXPECT_EQ(OK, rv); | 1581 EXPECT_EQ(OK, rv); |
1584 | 1582 |
1585 // The first proxy is ignored, and the second one is selected. | 1583 // The first proxy is ignored, and the second one is selected. |
1586 EXPECT_FALSE(info.is_direct()); | 1584 EXPECT_FALSE(info.is_direct()); |
1587 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); | 1585 EXPECT_EQ("foopy2:9090", info.proxy_server().ToURI()); |
1588 | 1586 |
1589 // Fake a PAC failure. | 1587 // Fake a PAC failure. |
1590 ProxyInfo info2; | 1588 ProxyInfo info2; |
1591 TestCompletionCallback callback3; | 1589 TestCompletionCallback callback3; |
1592 rv = service.ResolveProxy(url, LOAD_NORMAL, &info2, callback3.callback(), | 1590 rv = service.ResolveProxy(url, LOAD_NORMAL, &info2, callback3.callback(), |
1593 NULL, NULL, BoundNetLog()); | 1591 NULL, NULL, BoundNetLog()); |
1594 EXPECT_EQ(ERR_IO_PENDING, rv); | 1592 EXPECT_EQ(ERR_IO_PENDING, rv); |
1595 | 1593 |
1596 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1594 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1597 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1595 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1598 | 1596 |
1599 // This simulates a javascript runtime error in the PAC script. | 1597 // This simulates a javascript runtime error in the PAC script. |
1600 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1598 resolver.pending_jobs()[0]->CompleteNow(ERR_FAILED); |
1601 | 1599 |
1602 // Although the resolver failed, the ProxyService will NOT fall-back | 1600 // Although the resolver failed, the ProxyService will NOT fall-back |
1603 // to a DIRECT connection as it is configured as mandatory. | 1601 // to a DIRECT connection as it is configured as mandatory. |
1604 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1602 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
1605 callback3.WaitForResult()); | 1603 callback3.WaitForResult()); |
1606 EXPECT_FALSE(info2.is_direct()); | 1604 EXPECT_FALSE(info2.is_direct()); |
1607 EXPECT_TRUE(info2.is_empty()); | 1605 EXPECT_TRUE(info2.is_empty()); |
1608 | 1606 |
1609 // The PAC script will work properly next time and successfully return a | 1607 // The PAC script will work properly next time and successfully return a |
1610 // proxy list. Since we have not marked the configuration as bad, it should | 1608 // proxy list. Since we have not marked the configuration as bad, it should |
1611 // "just work" the next time we call it. | 1609 // "just work" the next time we call it. |
1612 ProxyInfo info3; | 1610 ProxyInfo info3; |
1613 TestCompletionCallback callback4; | 1611 TestCompletionCallback callback4; |
1614 rv = service.ReconsiderProxyAfterError( | 1612 rv = service.ReconsiderProxyAfterError( |
1615 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, | 1613 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info3, |
1616 callback4.callback(), NULL, NULL, BoundNetLog()); | 1614 callback4.callback(), NULL, NULL, BoundNetLog()); |
1617 EXPECT_EQ(ERR_IO_PENDING, rv); | 1615 EXPECT_EQ(ERR_IO_PENDING, rv); |
1618 | 1616 |
1619 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1617 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
1620 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1618 EXPECT_EQ(url, resolver.pending_jobs()[0]->url()); |
1621 | 1619 |
1622 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1620 resolver.pending_jobs()[0]->results()->UseNamedProxy( |
1623 "foopy1:8080;foopy2:9090"); | 1621 "foopy1:8080;foopy2:9090"); |
1624 resolver.pending_requests()[0]->CompleteNow(OK); | 1622 resolver.pending_jobs()[0]->CompleteNow(OK); |
1625 | 1623 |
1626 // The first proxy is not there since the it was added to the bad proxies | 1624 // The first proxy is not there since the it was added to the bad proxies |
1627 // list by the earlier ReconsiderProxyAfterError(). | 1625 // list by the earlier ReconsiderProxyAfterError(). |
1628 EXPECT_EQ(OK, callback4.WaitForResult()); | 1626 EXPECT_EQ(OK, callback4.WaitForResult()); |
1629 EXPECT_FALSE(info3.is_direct()); | 1627 EXPECT_FALSE(info3.is_direct()); |
1630 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); | 1628 EXPECT_EQ("foopy1:8080", info3.proxy_server().ToURI()); |
1631 } | 1629 } |
1632 | 1630 |
1633 TEST_F(ProxyServiceTest, ProxyBypassList) { | 1631 TEST_F(ProxyServiceTest, ProxyBypassList) { |
1634 // Test that the proxy bypass rules are consulted. | 1632 // Test that the proxy bypass rules are consulted. |
(...skipping 256 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1891 TestCompletionCallback callback1; | 1889 TestCompletionCallback callback1; |
1892 int rv = service.ResolveProxy(url1, LOAD_NORMAL, &info1, callback1.callback(), | 1890 int rv = service.ResolveProxy(url1, LOAD_NORMAL, &info1, callback1.callback(), |
1893 NULL, NULL, BoundNetLog()); | 1891 NULL, NULL, BoundNetLog()); |
1894 EXPECT_EQ(ERR_IO_PENDING, rv); | 1892 EXPECT_EQ(ERR_IO_PENDING, rv); |
1895 | 1893 |
1896 // Successfully initialize the PAC script. | 1894 // Successfully initialize the PAC script. |
1897 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1895 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
1898 factory->pending_requests()[0]->script_data()->url()); | 1896 factory->pending_requests()[0]->script_data()->url()); |
1899 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 1897 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
1900 | 1898 |
1901 GetPendingRequestsForURLs(resolver, url1); | 1899 GetPendingJobsForURLs(resolver, url1); |
1902 | 1900 |
1903 ProxyInfo info2; | 1901 ProxyInfo info2; |
1904 TestCompletionCallback callback2; | 1902 TestCompletionCallback callback2; |
1905 ProxyService::PacRequest* request2; | 1903 ProxyService::PacRequest* request2; |
1906 rv = service.ResolveProxy(url2, LOAD_NORMAL, &info2, callback2.callback(), | 1904 rv = service.ResolveProxy(url2, LOAD_NORMAL, &info2, callback2.callback(), |
1907 &request2, NULL, BoundNetLog()); | 1905 &request2, NULL, BoundNetLog()); |
1908 EXPECT_EQ(ERR_IO_PENDING, rv); | 1906 EXPECT_EQ(ERR_IO_PENDING, rv); |
1909 | 1907 |
1910 GetPendingRequestsForURLs(resolver, url1, url2); | 1908 GetPendingJobsForURLs(resolver, url1, url2); |
1911 | 1909 |
1912 ProxyInfo info3; | 1910 ProxyInfo info3; |
1913 TestCompletionCallback callback3; | 1911 TestCompletionCallback callback3; |
1914 rv = service.ResolveProxy(url3, LOAD_NORMAL, &info3, callback3.callback(), | 1912 rv = service.ResolveProxy(url3, LOAD_NORMAL, &info3, callback3.callback(), |
1915 NULL, NULL, BoundNetLog()); | 1913 NULL, NULL, BoundNetLog()); |
1916 EXPECT_EQ(ERR_IO_PENDING, rv); | 1914 EXPECT_EQ(ERR_IO_PENDING, rv); |
1917 GetPendingRequestsForURLs(resolver, url1, url2, url3); | 1915 GetPendingJobsForURLs(resolver, url1, url2, url3); |
1918 | 1916 |
1919 // Cancel the second request | 1917 // Cancel the second request |
1920 service.CancelPacRequest(request2); | 1918 service.CancelPacRequest(request2); |
1921 | 1919 |
1922 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url3); | 1920 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url3); |
1923 | 1921 |
1924 // Complete the two un-cancelled requests. | 1922 // Complete the two un-cancelled jobs. |
1925 // We complete the last one first, just to mix it up a bit. | 1923 // We complete the last one first, just to mix it up a bit. |
1926 requests[url3]->results()->UseNamedProxy("request3:80"); | 1924 jobs[url3]->results()->UseNamedProxy("request3:80"); |
1927 requests[url3]->CompleteNow(OK); | 1925 jobs[url3]->CompleteNow(OK); |
1928 | 1926 |
1929 requests[url1]->results()->UseNamedProxy("request1:80"); | 1927 jobs[url1]->results()->UseNamedProxy("request1:80"); |
1930 requests[url1]->CompleteNow(OK); | 1928 jobs[url1]->CompleteNow(OK); |
1931 | 1929 |
1932 // Complete and verify that requests ran as expected. | 1930 // Complete and verify that jobs ran as expected. |
1933 EXPECT_EQ(OK, callback1.WaitForResult()); | 1931 EXPECT_EQ(OK, callback1.WaitForResult()); |
1934 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 1932 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
1935 | 1933 |
1936 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 1934 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
1937 GetCancelledRequestsForURLs(resolver, url2); | 1935 GetCancelledJobsForURLs(resolver, url2); |
1938 | 1936 |
1939 EXPECT_EQ(OK, callback3.WaitForResult()); | 1937 EXPECT_EQ(OK, callback3.WaitForResult()); |
1940 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1938 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
1941 } | 1939 } |
1942 | 1940 |
1943 // Test the initial PAC download for resolver that expects bytes. | 1941 // Test the initial PAC download for resolver that expects bytes. |
1944 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { | 1942 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { |
1945 const GURL url1("http://request1"); | 1943 const GURL url1("http://request1"); |
1946 const GURL url2("http://request2"); | 1944 const GURL url2("http://request2"); |
1947 const GURL url3("http://request3"); | 1945 const GURL url3("http://request3"); |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2000 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1998 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2001 // PAC script download completion. | 1999 // PAC script download completion. |
2002 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2000 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2003 | 2001 |
2004 // Now that the PAC script is downloaded, it will have been sent to the proxy | 2002 // Now that the PAC script is downloaded, it will have been sent to the proxy |
2005 // resolver. | 2003 // resolver. |
2006 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2004 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2007 factory->pending_requests()[0]->script_data()->utf16()); | 2005 factory->pending_requests()[0]->script_data()->utf16()); |
2008 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2006 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2009 | 2007 |
2010 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2, url3); | 2008 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2, url3); |
2011 | 2009 |
2012 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); | 2010 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); |
2013 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); | 2011 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); |
2014 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); | 2012 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); |
2015 | 2013 |
2016 // Complete all the requests (in some order). | 2014 // Complete all the jobs (in some order). |
2017 | 2015 |
2018 requests[url3]->results()->UseNamedProxy("request3:80"); | 2016 jobs[url3]->results()->UseNamedProxy("request3:80"); |
2019 requests[url3]->CompleteNow(OK); | 2017 jobs[url3]->CompleteNow(OK); |
2020 | 2018 |
2021 requests[url1]->results()->UseNamedProxy("request1:80"); | 2019 jobs[url1]->results()->UseNamedProxy("request1:80"); |
2022 requests[url1]->CompleteNow(OK); | 2020 jobs[url1]->CompleteNow(OK); |
2023 | 2021 |
2024 requests[url2]->results()->UseNamedProxy("request2:80"); | 2022 jobs[url2]->results()->UseNamedProxy("request2:80"); |
2025 requests[url2]->CompleteNow(OK); | 2023 jobs[url2]->CompleteNow(OK); |
2026 | 2024 |
2027 // Complete and verify that requests ran as expected. | 2025 // Complete and verify that jobs ran as expected. |
2028 EXPECT_EQ(OK, callback1.WaitForResult()); | 2026 EXPECT_EQ(OK, callback1.WaitForResult()); |
2029 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2027 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2030 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); | 2028 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); |
2031 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); | 2029 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); |
2032 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); | 2030 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); |
2033 | 2031 |
2034 EXPECT_EQ(OK, callback2.WaitForResult()); | 2032 EXPECT_EQ(OK, callback2.WaitForResult()); |
2035 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2033 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2036 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); | 2034 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); |
2037 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); | 2035 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); |
(...skipping 17 matching lines...) Expand all Loading... |
2055 MockAsyncProxyResolverFactory* factory = | 2053 MockAsyncProxyResolverFactory* factory = |
2056 new MockAsyncProxyResolverFactory(true); | 2054 new MockAsyncProxyResolverFactory(true); |
2057 | 2055 |
2058 ProxyService service(make_scoped_ptr(config_service), | 2056 ProxyService service(make_scoped_ptr(config_service), |
2059 make_scoped_ptr(factory), NULL); | 2057 make_scoped_ptr(factory), NULL); |
2060 | 2058 |
2061 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2059 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2062 service.SetProxyScriptFetchers( | 2060 service.SetProxyScriptFetchers( |
2063 fetcher, make_scoped_ptr(new DoNothingDhcpProxyScriptFetcher())); | 2061 fetcher, make_scoped_ptr(new DoNothingDhcpProxyScriptFetcher())); |
2064 | 2062 |
2065 // Start 2 requests. | 2063 // Start 2 jobs. |
2066 | 2064 |
2067 ProxyInfo info1; | 2065 ProxyInfo info1; |
2068 TestCompletionCallback callback1; | 2066 TestCompletionCallback callback1; |
2069 int rv = service.ResolveProxy(url1, LOAD_NORMAL, &info1, callback1.callback(), | 2067 int rv = service.ResolveProxy(url1, LOAD_NORMAL, &info1, callback1.callback(), |
2070 NULL, NULL, BoundNetLog()); | 2068 NULL, NULL, BoundNetLog()); |
2071 EXPECT_EQ(ERR_IO_PENDING, rv); | 2069 EXPECT_EQ(ERR_IO_PENDING, rv); |
2072 | 2070 |
2073 // The first request should have triggered download of PAC script. | 2071 // The first request should have triggered download of PAC script. |
2074 EXPECT_TRUE(fetcher->has_pending_request()); | 2072 EXPECT_TRUE(fetcher->has_pending_request()); |
2075 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2073 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
(...skipping 19 matching lines...) Expand all Loading... |
2095 EXPECT_TRUE(factory->pending_requests().empty()); | 2093 EXPECT_TRUE(factory->pending_requests().empty()); |
2096 | 2094 |
2097 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2095 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2098 | 2096 |
2099 // Now that the PAC script is downloaded, it will have been sent to the proxy | 2097 // Now that the PAC script is downloaded, it will have been sent to the proxy |
2100 // resolver. | 2098 // resolver. |
2101 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2099 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2102 factory->pending_requests()[0]->script_data()->utf16()); | 2100 factory->pending_requests()[0]->script_data()->utf16()); |
2103 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2101 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2104 | 2102 |
2105 GetPendingRequestsForURLs(resolver, url1, url2); | 2103 GetPendingJobsForURLs(resolver, url1, url2); |
2106 } | 2104 } |
2107 | 2105 |
2108 // Test cancellation of a request, while the PAC script is being fetched. | 2106 // Test cancellation of a request, while the PAC script is being fetched. |
2109 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { | 2107 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { |
2110 MockProxyConfigService* config_service = | 2108 MockProxyConfigService* config_service = |
2111 new MockProxyConfigService("http://foopy/proxy.pac"); | 2109 new MockProxyConfigService("http://foopy/proxy.pac"); |
2112 | 2110 |
2113 MockAsyncProxyResolver resolver; | 2111 MockAsyncProxyResolver resolver; |
2114 MockAsyncProxyResolverFactory* factory = | 2112 MockAsyncProxyResolverFactory* factory = |
2115 new MockAsyncProxyResolverFactory(true); | 2113 new MockAsyncProxyResolverFactory(true); |
(...skipping 29 matching lines...) Expand all Loading... |
2145 | 2143 |
2146 ProxyInfo info3; | 2144 ProxyInfo info3; |
2147 TestCompletionCallback callback3; | 2145 TestCompletionCallback callback3; |
2148 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3, | 2146 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3, |
2149 callback3.callback(), NULL, NULL, BoundNetLog()); | 2147 callback3.callback(), NULL, NULL, BoundNetLog()); |
2150 EXPECT_EQ(ERR_IO_PENDING, rv); | 2148 EXPECT_EQ(ERR_IO_PENDING, rv); |
2151 | 2149 |
2152 // Nothing has been sent to the factory yet. | 2150 // Nothing has been sent to the factory yet. |
2153 EXPECT_TRUE(factory->pending_requests().empty()); | 2151 EXPECT_TRUE(factory->pending_requests().empty()); |
2154 | 2152 |
2155 // Cancel the first 2 requests. | 2153 // Cancel the first 2 jobs. |
2156 service.CancelPacRequest(request1); | 2154 service.CancelPacRequest(request1); |
2157 service.CancelPacRequest(request2); | 2155 service.CancelPacRequest(request2); |
2158 | 2156 |
2159 // At this point the ProxyService should be waiting for the | 2157 // At this point the ProxyService should be waiting for the |
2160 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2158 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2161 // PAC script download completion. | 2159 // PAC script download completion. |
2162 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2160 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2163 | 2161 |
2164 // Now that the PAC script is downloaded, it will have been sent to the | 2162 // Now that the PAC script is downloaded, it will have been sent to the |
2165 // proxy resolver. | 2163 // proxy resolver. |
2166 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2164 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2167 factory->pending_requests()[0]->script_data()->utf16()); | 2165 factory->pending_requests()[0]->script_data()->utf16()); |
2168 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2166 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2169 | 2167 |
2170 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2168 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2171 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url()); | 2169 EXPECT_EQ(GURL("http://request3"), resolver.pending_jobs()[0]->url()); |
2172 | 2170 |
2173 // Complete all the requests. | 2171 // Complete all the jobs. |
2174 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80"); | 2172 resolver.pending_jobs()[0]->results()->UseNamedProxy("request3:80"); |
2175 resolver.pending_requests()[0]->CompleteNow(OK); | 2173 resolver.pending_jobs()[0]->CompleteNow(OK); |
2176 | 2174 |
2177 EXPECT_EQ(OK, callback3.WaitForResult()); | 2175 EXPECT_EQ(OK, callback3.WaitForResult()); |
2178 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 2176 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
2179 | 2177 |
2180 EXPECT_TRUE(resolver.cancelled_requests().empty()); | 2178 EXPECT_TRUE(resolver.cancelled_jobs().empty()); |
2181 | 2179 |
2182 EXPECT_FALSE(callback1.have_result()); // Cancelled. | 2180 EXPECT_FALSE(callback1.have_result()); // Cancelled. |
2183 EXPECT_FALSE(callback2.have_result()); // Cancelled. | 2181 EXPECT_FALSE(callback2.have_result()); // Cancelled. |
2184 | 2182 |
2185 TestNetLogEntry::List entries1; | 2183 TestNetLogEntry::List entries1; |
2186 log1.GetEntries(&entries1); | 2184 log1.GetEntries(&entries1); |
2187 | 2185 |
2188 // Check the NetLog for request 1 (which was cancelled) got filled properly. | 2186 // Check the NetLog for request 1 (which was cancelled) got filled properly. |
2189 EXPECT_EQ(4u, entries1.size()); | 2187 EXPECT_EQ(4u, entries1.size()); |
2190 EXPECT_TRUE(LogContainsBeginEvent( | 2188 EXPECT_TRUE(LogContainsBeginEvent( |
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2245 | 2243 |
2246 // Next it should be trying the custom PAC url. | 2244 // Next it should be trying the custom PAC url. |
2247 EXPECT_TRUE(fetcher->has_pending_request()); | 2245 EXPECT_TRUE(fetcher->has_pending_request()); |
2248 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2246 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2249 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2247 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2250 | 2248 |
2251 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2249 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2252 factory->pending_requests()[0]->script_data()->utf16()); | 2250 factory->pending_requests()[0]->script_data()->utf16()); |
2253 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2251 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2254 | 2252 |
2255 // Now finally, the pending requests should have been sent to the resolver | 2253 // Now finally, the pending jobs should have been sent to the resolver |
2256 // (which was initialized with custom PAC script). | 2254 // (which was initialized with custom PAC script). |
2257 | 2255 |
2258 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 2256 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); |
2259 | 2257 |
2260 // Complete the pending requests. | 2258 // Complete the pending jobs. |
2261 requests[url2]->results()->UseNamedProxy("request2:80"); | 2259 jobs[url2]->results()->UseNamedProxy("request2:80"); |
2262 requests[url2]->CompleteNow(OK); | 2260 jobs[url2]->CompleteNow(OK); |
2263 requests[url1]->results()->UseNamedProxy("request1:80"); | 2261 jobs[url1]->results()->UseNamedProxy("request1:80"); |
2264 requests[url1]->CompleteNow(OK); | 2262 jobs[url1]->CompleteNow(OK); |
2265 | 2263 |
2266 // Verify that requests ran as expected. | 2264 // Verify that jobs ran as expected. |
2267 EXPECT_EQ(OK, callback1.WaitForResult()); | 2265 EXPECT_EQ(OK, callback1.WaitForResult()); |
2268 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2266 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2269 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); | 2267 EXPECT_FALSE(info1.proxy_resolve_start_time().is_null()); |
2270 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); | 2268 EXPECT_FALSE(info1.proxy_resolve_end_time().is_null()); |
2271 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); | 2269 EXPECT_LE(info1.proxy_resolve_start_time(), info1.proxy_resolve_end_time()); |
2272 | 2270 |
2273 EXPECT_EQ(OK, callback2.WaitForResult()); | 2271 EXPECT_EQ(OK, callback2.WaitForResult()); |
2274 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2272 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2275 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); | 2273 EXPECT_FALSE(info2.proxy_resolve_start_time().is_null()); |
2276 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); | 2274 EXPECT_FALSE(info2.proxy_resolve_end_time().is_null()); |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2326 | 2324 |
2327 // Next it should be trying the custom PAC url. | 2325 // Next it should be trying the custom PAC url. |
2328 EXPECT_TRUE(fetcher->has_pending_request()); | 2326 EXPECT_TRUE(fetcher->has_pending_request()); |
2329 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2327 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2330 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2328 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2331 | 2329 |
2332 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2330 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2333 factory->pending_requests()[0]->script_data()->utf16()); | 2331 factory->pending_requests()[0]->script_data()->utf16()); |
2334 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2332 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2335 | 2333 |
2336 // Now finally, the pending requests should have been sent to the resolver | 2334 // Now finally, the pending jobs should have been sent to the resolver |
2337 // (which was initialized with custom PAC script). | 2335 // (which was initialized with custom PAC script). |
2338 | 2336 |
2339 RequestMap requests = GetPendingRequestsForURLs(resolver, url1, url2); | 2337 JobMap jobs = GetPendingJobsForURLs(resolver, url1, url2); |
2340 | 2338 |
2341 // Complete the pending requests. | 2339 // Complete the pending jobs. |
2342 requests[url2]->results()->UseNamedProxy("request2:80"); | 2340 jobs[url2]->results()->UseNamedProxy("request2:80"); |
2343 requests[url2]->CompleteNow(OK); | 2341 jobs[url2]->CompleteNow(OK); |
2344 requests[url1]->results()->UseNamedProxy("request1:80"); | 2342 jobs[url1]->results()->UseNamedProxy("request1:80"); |
2345 requests[url1]->CompleteNow(OK); | 2343 jobs[url1]->CompleteNow(OK); |
2346 | 2344 |
2347 // Verify that requests ran as expected. | 2345 // Verify that jobs ran as expected. |
2348 EXPECT_EQ(OK, callback1.WaitForResult()); | 2346 EXPECT_EQ(OK, callback1.WaitForResult()); |
2349 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2347 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2350 | 2348 |
2351 EXPECT_EQ(OK, callback2.WaitForResult()); | 2349 EXPECT_EQ(OK, callback2.WaitForResult()); |
2352 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2350 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2353 } | 2351 } |
2354 | 2352 |
2355 // Test that if all of auto-detect, a custom PAC script, and manual settings | 2353 // Test that if all of auto-detect, a custom PAC script, and manual settings |
2356 // are given, then we will try them in that order. | 2354 // are given, then we will try them in that order. |
2357 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { | 2355 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { |
2358 ProxyConfig config; | 2356 ProxyConfig config; |
2359 config.set_auto_detect(true); | 2357 config.set_auto_detect(true); |
2360 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2358 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
2361 config.proxy_rules().ParseFromString("http=foopy:80"); | 2359 config.proxy_rules().ParseFromString("http=foopy:80"); |
2362 | 2360 |
2363 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2361 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
2364 MockAsyncProxyResolverFactory* factory = | 2362 MockAsyncProxyResolverFactory* factory = |
2365 new MockAsyncProxyResolverFactory(true); | 2363 new MockAsyncProxyResolverFactory(true); |
2366 ProxyService service(make_scoped_ptr(config_service), | 2364 ProxyService service(make_scoped_ptr(config_service), |
2367 make_scoped_ptr(factory), NULL); | 2365 make_scoped_ptr(factory), NULL); |
2368 | 2366 |
2369 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2367 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
2370 service.SetProxyScriptFetchers( | 2368 service.SetProxyScriptFetchers( |
2371 fetcher, make_scoped_ptr(new DoNothingDhcpProxyScriptFetcher())); | 2369 fetcher, make_scoped_ptr(new DoNothingDhcpProxyScriptFetcher())); |
2372 | 2370 |
2373 // Start 2 requests. | 2371 // Start 2 jobs. |
2374 | 2372 |
2375 ProxyInfo info1; | 2373 ProxyInfo info1; |
2376 TestCompletionCallback callback1; | 2374 TestCompletionCallback callback1; |
2377 int rv = | 2375 int rv = |
2378 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2376 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
2379 callback1.callback(), NULL, NULL, BoundNetLog()); | 2377 callback1.callback(), NULL, NULL, BoundNetLog()); |
2380 EXPECT_EQ(ERR_IO_PENDING, rv); | 2378 EXPECT_EQ(ERR_IO_PENDING, rv); |
2381 | 2379 |
2382 ProxyInfo info2; | 2380 ProxyInfo info2; |
2383 TestCompletionCallback callback2; | 2381 TestCompletionCallback callback2; |
(...skipping 13 matching lines...) Expand all Loading... |
2397 | 2395 |
2398 // Next it should be trying the custom PAC url -- fail the download. | 2396 // Next it should be trying the custom PAC url -- fail the download. |
2399 EXPECT_TRUE(fetcher->has_pending_request()); | 2397 EXPECT_TRUE(fetcher->has_pending_request()); |
2400 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2398 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2401 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2399 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
2402 | 2400 |
2403 // Since we never managed to initialize a resolver, nothing should have been | 2401 // Since we never managed to initialize a resolver, nothing should have been |
2404 // sent to it. | 2402 // sent to it. |
2405 ASSERT_EQ(0u, factory->pending_requests().size()); | 2403 ASSERT_EQ(0u, factory->pending_requests().size()); |
2406 | 2404 |
2407 // Verify that requests ran as expected -- they should have fallen back to | 2405 // Verify that jobs ran as expected -- they should have fallen back to |
2408 // the manual proxy configuration for HTTP urls. | 2406 // the manual proxy configuration for HTTP urls. |
2409 EXPECT_EQ(OK, callback1.WaitForResult()); | 2407 EXPECT_EQ(OK, callback1.WaitForResult()); |
2410 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); | 2408 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); |
2411 | 2409 |
2412 EXPECT_EQ(OK, callback2.WaitForResult()); | 2410 EXPECT_EQ(OK, callback2.WaitForResult()); |
2413 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); | 2411 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); |
2414 } | 2412 } |
2415 | 2413 |
2416 // Test that the bypass rules are NOT applied when using autodetect. | 2414 // Test that the bypass rules are NOT applied when using autodetect. |
2417 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { | 2415 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { |
(...skipping 28 matching lines...) Expand all Loading... |
2446 | 2444 |
2447 // It should be trying to auto-detect first -- succeed the download. | 2445 // It should be trying to auto-detect first -- succeed the download. |
2448 EXPECT_TRUE(fetcher->has_pending_request()); | 2446 EXPECT_TRUE(fetcher->has_pending_request()); |
2449 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2447 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
2450 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2448 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2451 | 2449 |
2452 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2450 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2453 factory->pending_requests()[0]->script_data()->utf16()); | 2451 factory->pending_requests()[0]->script_data()->utf16()); |
2454 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2452 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2455 | 2453 |
2456 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2454 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2457 EXPECT_EQ(GURL("http://www.google.com"), | 2455 EXPECT_EQ(GURL("http://www.google.com"), resolver.pending_jobs()[0]->url()); |
2458 resolver.pending_requests()[0]->url()); | |
2459 | 2456 |
2460 // Complete the pending request. | 2457 // Complete the pending request. |
2461 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2458 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
2462 resolver.pending_requests()[0]->CompleteNow(OK); | 2459 resolver.pending_jobs()[0]->CompleteNow(OK); |
2463 | 2460 |
2464 // Verify that request ran as expected. | 2461 // Verify that request ran as expected. |
2465 EXPECT_EQ(OK, callback1.WaitForResult()); | 2462 EXPECT_EQ(OK, callback1.WaitForResult()); |
2466 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2463 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2467 | 2464 |
2468 // Start another request, it should pickup the bypass item. | 2465 // Start another request, it should pickup the bypass item. |
2469 ProxyInfo info2; | 2466 ProxyInfo info2; |
2470 TestCompletionCallback callback2; | 2467 TestCompletionCallback callback2; |
2471 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2, | 2468 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2, |
2472 callback2.callback(), NULL, NULL, BoundNetLog()); | 2469 callback2.callback(), NULL, NULL, BoundNetLog()); |
2473 EXPECT_EQ(ERR_IO_PENDING, rv); | 2470 EXPECT_EQ(ERR_IO_PENDING, rv); |
2474 | 2471 |
2475 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2472 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2476 EXPECT_EQ(GURL("http://www.google.com"), | 2473 EXPECT_EQ(GURL("http://www.google.com"), resolver.pending_jobs()[0]->url()); |
2477 resolver.pending_requests()[0]->url()); | |
2478 | 2474 |
2479 // Complete the pending request. | 2475 // Complete the pending request. |
2480 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2476 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
2481 resolver.pending_requests()[0]->CompleteNow(OK); | 2477 resolver.pending_jobs()[0]->CompleteNow(OK); |
2482 | 2478 |
2483 EXPECT_EQ(OK, callback2.WaitForResult()); | 2479 EXPECT_EQ(OK, callback2.WaitForResult()); |
2484 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2480 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2485 } | 2481 } |
2486 | 2482 |
2487 // Delete the ProxyService while InitProxyResolver has an outstanding | 2483 // Delete the ProxyService while InitProxyResolver has an outstanding |
2488 // request to the script fetcher. When run under valgrind, should not | 2484 // request to the script fetcher. When run under valgrind, should not |
2489 // have any memory errors (used to be that the ProxyScriptFetcher was | 2485 // have any memory errors (used to be that the ProxyScriptFetcher was |
2490 // being deleted prior to the InitProxyResolver). | 2486 // being deleted prior to the InitProxyResolver). |
2491 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { | 2487 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2593 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, | 2589 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, |
2594 callback1.callback(), NULL, NULL, BoundNetLog()); | 2590 callback1.callback(), NULL, NULL, BoundNetLog()); |
2595 EXPECT_EQ(ERR_IO_PENDING, rv); | 2591 EXPECT_EQ(ERR_IO_PENDING, rv); |
2596 | 2592 |
2597 // Successfully set the autodetect script. | 2593 // Successfully set the autodetect script. |
2598 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2594 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
2599 factory->pending_requests()[0]->script_data()->type()); | 2595 factory->pending_requests()[0]->script_data()->type()); |
2600 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2596 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2601 | 2597 |
2602 // Complete the pending request. | 2598 // Complete the pending request. |
2603 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2599 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2604 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2600 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
2605 resolver.pending_requests()[0]->CompleteNow(OK); | 2601 resolver.pending_jobs()[0]->CompleteNow(OK); |
2606 | 2602 |
2607 // Verify that request ran as expected. | 2603 // Verify that request ran as expected. |
2608 EXPECT_EQ(OK, callback1.WaitForResult()); | 2604 EXPECT_EQ(OK, callback1.WaitForResult()); |
2609 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2605 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2610 | 2606 |
2611 // Force the ProxyService to pull down a new proxy configuration. | 2607 // Force the ProxyService to pull down a new proxy configuration. |
2612 // (Even though the configuration isn't old/bad). | 2608 // (Even though the configuration isn't old/bad). |
2613 // | 2609 // |
2614 // This new configuration no longer has auto_detect set, so | 2610 // This new configuration no longer has auto_detect set, so |
2615 // requests should complete synchronously now as direct-connect. | 2611 // jobs should complete synchronously now as direct-connect. |
2616 config_service->SetConfig(ProxyConfig::CreateDirect()); | 2612 config_service->SetConfig(ProxyConfig::CreateDirect()); |
2617 | 2613 |
2618 // Start another request -- the effective configuration has changed. | 2614 // Start another request -- the effective configuration has changed. |
2619 ProxyInfo info2; | 2615 ProxyInfo info2; |
2620 TestCompletionCallback callback2; | 2616 TestCompletionCallback callback2; |
2621 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2, | 2617 rv = service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info2, |
2622 callback2.callback(), NULL, NULL, BoundNetLog()); | 2618 callback2.callback(), NULL, NULL, BoundNetLog()); |
2623 EXPECT_EQ(OK, rv); | 2619 EXPECT_EQ(OK, rv); |
2624 | 2620 |
2625 EXPECT_TRUE(info2.is_direct()); | 2621 EXPECT_TRUE(info2.is_direct()); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2666 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2662 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2667 // PAC script download completion. | 2663 // PAC script download completion. |
2668 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2664 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2669 | 2665 |
2670 // Now that the PAC script is downloaded, the request will have been sent to | 2666 // Now that the PAC script is downloaded, the request will have been sent to |
2671 // the proxy resolver. | 2667 // the proxy resolver. |
2672 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2668 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2673 factory->pending_requests()[0]->script_data()->utf16()); | 2669 factory->pending_requests()[0]->script_data()->utf16()); |
2674 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2670 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2675 | 2671 |
2676 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2672 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2677 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2673 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
2678 | 2674 |
2679 // Complete the pending request. | 2675 // Complete the pending request. |
2680 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2676 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
2681 resolver.pending_requests()[0]->CompleteNow(OK); | 2677 resolver.pending_jobs()[0]->CompleteNow(OK); |
2682 | 2678 |
2683 // Wait for completion callback, and verify that the request ran as expected. | 2679 // Wait for completion callback, and verify that the request ran as expected. |
2684 EXPECT_EQ(OK, callback1.WaitForResult()); | 2680 EXPECT_EQ(OK, callback1.WaitForResult()); |
2685 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2681 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2686 | 2682 |
2687 // Now simluate a change in the network. The ProxyConfigService is still | 2683 // Now simluate a change in the network. The ProxyConfigService is still |
2688 // going to return the same PAC URL as before, but this URL needs to be | 2684 // going to return the same PAC URL as before, but this URL needs to be |
2689 // refetched on the new network. | 2685 // refetched on the new network. |
2690 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); | 2686 NetworkChangeNotifier::NotifyObserversOfIPAddressChangeForTests(); |
2691 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. | 2687 base::MessageLoop::current()->RunUntilIdle(); // Notification happens async. |
(...skipping 16 matching lines...) Expand all Loading... |
2708 // Simulate the PAC script fetch as having completed (this time with | 2704 // Simulate the PAC script fetch as having completed (this time with |
2709 // different data). | 2705 // different data). |
2710 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 2706 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
2711 | 2707 |
2712 // Now that the PAC script is downloaded, the second request will have been | 2708 // Now that the PAC script is downloaded, the second request will have been |
2713 // sent to the proxy resolver. | 2709 // sent to the proxy resolver. |
2714 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2710 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
2715 factory->pending_requests()[0]->script_data()->utf16()); | 2711 factory->pending_requests()[0]->script_data()->utf16()); |
2716 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2712 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2717 | 2713 |
2718 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2714 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2719 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2715 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
2720 | 2716 |
2721 // Complete the pending second request. | 2717 // Complete the pending second request. |
2722 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2718 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
2723 resolver.pending_requests()[0]->CompleteNow(OK); | 2719 resolver.pending_jobs()[0]->CompleteNow(OK); |
2724 | 2720 |
2725 // Wait for completion callback, and verify that the request ran as expected. | 2721 // Wait for completion callback, and verify that the request ran as expected. |
2726 EXPECT_EQ(OK, callback2.WaitForResult()); | 2722 EXPECT_EQ(OK, callback2.WaitForResult()); |
2727 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2723 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2728 | 2724 |
2729 // Check that the expected events were output to the log stream. In particular | 2725 // Check that the expected events were output to the log stream. In particular |
2730 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial | 2726 // PROXY_CONFIG_CHANGED should have only been emitted once (for the initial |
2731 // setup), and NOT a second time when the IP address changed. | 2727 // setup), and NOT a second time when the IP address changed. |
2732 TestNetLogEntry::List entries; | 2728 TestNetLogEntry::List entries; |
2733 log.GetEntries(&entries); | 2729 log.GetEntries(&entries); |
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2826 // DIRECT. | 2822 // DIRECT. |
2827 | 2823 |
2828 // Start a second request. | 2824 // Start a second request. |
2829 ProxyInfo info2; | 2825 ProxyInfo info2; |
2830 TestCompletionCallback callback2; | 2826 TestCompletionCallback callback2; |
2831 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2827 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
2832 callback2.callback(), NULL, NULL, BoundNetLog()); | 2828 callback2.callback(), NULL, NULL, BoundNetLog()); |
2833 EXPECT_EQ(ERR_IO_PENDING, rv); | 2829 EXPECT_EQ(ERR_IO_PENDING, rv); |
2834 | 2830 |
2835 // Check that it was sent to the resolver. | 2831 // Check that it was sent to the resolver. |
2836 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2832 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2837 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2833 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
2838 | 2834 |
2839 // Complete the pending second request. | 2835 // Complete the pending second request. |
2840 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2836 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
2841 resolver.pending_requests()[0]->CompleteNow(OK); | 2837 resolver.pending_jobs()[0]->CompleteNow(OK); |
2842 | 2838 |
2843 // Wait for completion callback, and verify that the request ran as expected. | 2839 // Wait for completion callback, and verify that the request ran as expected. |
2844 EXPECT_EQ(OK, callback2.WaitForResult()); | 2840 EXPECT_EQ(OK, callback2.WaitForResult()); |
2845 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2841 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2846 } | 2842 } |
2847 | 2843 |
2848 // This test verifies that the PAC script specified by the settings is | 2844 // This test verifies that the PAC script specified by the settings is |
2849 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 2845 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
2850 // however at a later time its *contents* change, we will eventually | 2846 // however at a later time its *contents* change, we will eventually |
2851 // re-configure the service to use the new script. | 2847 // re-configure the service to use the new script. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2889 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2885 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
2890 // PAC script download completion. | 2886 // PAC script download completion. |
2891 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2887 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
2892 | 2888 |
2893 // Now that the PAC script is downloaded, the request will have been sent to | 2889 // Now that the PAC script is downloaded, the request will have been sent to |
2894 // the proxy resolver. | 2890 // the proxy resolver. |
2895 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2891 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
2896 factory->pending_requests()[0]->script_data()->utf16()); | 2892 factory->pending_requests()[0]->script_data()->utf16()); |
2897 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2893 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2898 | 2894 |
2899 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2895 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2900 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2896 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
2901 | 2897 |
2902 // Complete the pending request. | 2898 // Complete the pending request. |
2903 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2899 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
2904 resolver.pending_requests()[0]->CompleteNow(OK); | 2900 resolver.pending_jobs()[0]->CompleteNow(OK); |
2905 | 2901 |
2906 // Wait for completion callback, and verify that the request ran as expected. | 2902 // Wait for completion callback, and verify that the request ran as expected. |
2907 EXPECT_EQ(OK, callback1.WaitForResult()); | 2903 EXPECT_EQ(OK, callback1.WaitForResult()); |
2908 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2904 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
2909 | 2905 |
2910 // At this point we have initialized the proxy service using a PAC script. | 2906 // At this point we have initialized the proxy service using a PAC script. |
2911 // | 2907 // |
2912 // A background task to periodically re-check the PAC script for validity will | 2908 // A background task to periodically re-check the PAC script for validity will |
2913 // have been started. We will now wait for the next download attempt to start. | 2909 // have been started. We will now wait for the next download attempt to start. |
2914 // | 2910 // |
2915 // Note that we shouldn't have to wait long here, since our test enables a | 2911 // Note that we shouldn't have to wait long here, since our test enables a |
2916 // special unit-test mode. | 2912 // special unit-test mode. |
2917 fetcher->WaitUntilFetch(); | 2913 fetcher->WaitUntilFetch(); |
2918 | 2914 |
2919 ASSERT_TRUE(factory->pending_requests().empty()); | 2915 ASSERT_TRUE(factory->pending_requests().empty()); |
2920 ASSERT_TRUE(resolver.pending_requests().empty()); | 2916 ASSERT_TRUE(resolver.pending_jobs().empty()); |
2921 | 2917 |
2922 // Make sure that our background checker is trying to download the expected | 2918 // Make sure that our background checker is trying to download the expected |
2923 // PAC script (same one as before). This time we will simulate a successful | 2919 // PAC script (same one as before). This time we will simulate a successful |
2924 // download of a DIFFERENT script. | 2920 // download of a DIFFERENT script. |
2925 EXPECT_TRUE(fetcher->has_pending_request()); | 2921 EXPECT_TRUE(fetcher->has_pending_request()); |
2926 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2922 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
2927 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 2923 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
2928 | 2924 |
2929 base::MessageLoop::current()->RunUntilIdle(); | 2925 base::MessageLoop::current()->RunUntilIdle(); |
2930 | 2926 |
2931 // Now that the PAC script is downloaded, it should be used to initialize the | 2927 // Now that the PAC script is downloaded, it should be used to initialize the |
2932 // ProxyResolver. Simulate a successful parse. | 2928 // ProxyResolver. Simulate a successful parse. |
2933 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2929 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
2934 factory->pending_requests()[0]->script_data()->utf16()); | 2930 factory->pending_requests()[0]->script_data()->utf16()); |
2935 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 2931 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
2936 | 2932 |
2937 // At this point the ProxyService should have re-configured itself to use the | 2933 // At this point the ProxyService should have re-configured itself to use the |
2938 // new PAC script. | 2934 // new PAC script. |
2939 | 2935 |
2940 // Start a second request. | 2936 // Start a second request. |
2941 ProxyInfo info2; | 2937 ProxyInfo info2; |
2942 TestCompletionCallback callback2; | 2938 TestCompletionCallback callback2; |
2943 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2939 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
2944 callback2.callback(), NULL, NULL, BoundNetLog()); | 2940 callback2.callback(), NULL, NULL, BoundNetLog()); |
2945 EXPECT_EQ(ERR_IO_PENDING, rv); | 2941 EXPECT_EQ(ERR_IO_PENDING, rv); |
2946 | 2942 |
2947 // Check that it was sent to the resolver. | 2943 // Check that it was sent to the resolver. |
2948 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2944 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
2949 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2945 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
2950 | 2946 |
2951 // Complete the pending second request. | 2947 // Complete the pending second request. |
2952 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2948 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
2953 resolver.pending_requests()[0]->CompleteNow(OK); | 2949 resolver.pending_jobs()[0]->CompleteNow(OK); |
2954 | 2950 |
2955 // Wait for completion callback, and verify that the request ran as expected. | 2951 // Wait for completion callback, and verify that the request ran as expected. |
2956 EXPECT_EQ(OK, callback2.WaitForResult()); | 2952 EXPECT_EQ(OK, callback2.WaitForResult()); |
2957 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 2953 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
2958 } | 2954 } |
2959 | 2955 |
2960 // This test verifies that the PAC script specified by the settings is | 2956 // This test verifies that the PAC script specified by the settings is |
2961 // periodically polled for changes. Specifically, if the initial fetch succeeds | 2957 // periodically polled for changes. Specifically, if the initial fetch succeeds |
2962 // and so does the next poll, however the contents of the downloaded script | 2958 // and so does the next poll, however the contents of the downloaded script |
2963 // have NOT changed, then we do not bother to re-initialize the proxy resolver. | 2959 // 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... |
3001 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2997 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3002 // PAC script download completion. | 2998 // PAC script download completion. |
3003 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2999 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3004 | 3000 |
3005 // Now that the PAC script is downloaded, the request will have been sent to | 3001 // Now that the PAC script is downloaded, the request will have been sent to |
3006 // the proxy resolver. | 3002 // the proxy resolver. |
3007 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3003 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3008 factory->pending_requests()[0]->script_data()->utf16()); | 3004 factory->pending_requests()[0]->script_data()->utf16()); |
3009 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3005 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3010 | 3006 |
3011 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3007 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3012 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3008 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
3013 | 3009 |
3014 // Complete the pending request. | 3010 // Complete the pending request. |
3015 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3011 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
3016 resolver.pending_requests()[0]->CompleteNow(OK); | 3012 resolver.pending_jobs()[0]->CompleteNow(OK); |
3017 | 3013 |
3018 // Wait for completion callback, and verify that the request ran as expected. | 3014 // Wait for completion callback, and verify that the request ran as expected. |
3019 EXPECT_EQ(OK, callback1.WaitForResult()); | 3015 EXPECT_EQ(OK, callback1.WaitForResult()); |
3020 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3016 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3021 | 3017 |
3022 // At this point we have initialized the proxy service using a PAC script. | 3018 // At this point we have initialized the proxy service using a PAC script. |
3023 // | 3019 // |
3024 // A background task to periodically re-check the PAC script for validity will | 3020 // A background task to periodically re-check the PAC script for validity will |
3025 // have been started. We will now wait for the next download attempt to start. | 3021 // have been started. We will now wait for the next download attempt to start. |
3026 // | 3022 // |
3027 // Note that we shouldn't have to wait long here, since our test enables a | 3023 // Note that we shouldn't have to wait long here, since our test enables a |
3028 // special unit-test mode. | 3024 // special unit-test mode. |
3029 fetcher->WaitUntilFetch(); | 3025 fetcher->WaitUntilFetch(); |
3030 | 3026 |
3031 ASSERT_TRUE(factory->pending_requests().empty()); | 3027 ASSERT_TRUE(factory->pending_requests().empty()); |
3032 ASSERT_TRUE(resolver.pending_requests().empty()); | 3028 ASSERT_TRUE(resolver.pending_jobs().empty()); |
3033 | 3029 |
3034 // Make sure that our background checker is trying to download the expected | 3030 // Make sure that our background checker is trying to download the expected |
3035 // PAC script (same one as before). We will simulate the same response as | 3031 // PAC script (same one as before). We will simulate the same response as |
3036 // last time (i.e. the script is unchanged). | 3032 // last time (i.e. the script is unchanged). |
3037 EXPECT_TRUE(fetcher->has_pending_request()); | 3033 EXPECT_TRUE(fetcher->has_pending_request()); |
3038 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3034 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3039 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3035 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3040 | 3036 |
3041 base::MessageLoop::current()->RunUntilIdle(); | 3037 base::MessageLoop::current()->RunUntilIdle(); |
3042 | 3038 |
3043 ASSERT_TRUE(factory->pending_requests().empty()); | 3039 ASSERT_TRUE(factory->pending_requests().empty()); |
3044 ASSERT_TRUE(resolver.pending_requests().empty()); | 3040 ASSERT_TRUE(resolver.pending_jobs().empty()); |
3045 | 3041 |
3046 // At this point the ProxyService is still running the same PAC script as | 3042 // At this point the ProxyService is still running the same PAC script as |
3047 // before. | 3043 // before. |
3048 | 3044 |
3049 // Start a second request. | 3045 // Start a second request. |
3050 ProxyInfo info2; | 3046 ProxyInfo info2; |
3051 TestCompletionCallback callback2; | 3047 TestCompletionCallback callback2; |
3052 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 3048 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
3053 callback2.callback(), NULL, NULL, BoundNetLog()); | 3049 callback2.callback(), NULL, NULL, BoundNetLog()); |
3054 EXPECT_EQ(ERR_IO_PENDING, rv); | 3050 EXPECT_EQ(ERR_IO_PENDING, rv); |
3055 | 3051 |
3056 // Check that it was sent to the resolver. | 3052 // Check that it was sent to the resolver. |
3057 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3053 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3058 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3054 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
3059 | 3055 |
3060 // Complete the pending second request. | 3056 // Complete the pending second request. |
3061 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3057 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
3062 resolver.pending_requests()[0]->CompleteNow(OK); | 3058 resolver.pending_jobs()[0]->CompleteNow(OK); |
3063 | 3059 |
3064 // Wait for completion callback, and verify that the request ran as expected. | 3060 // Wait for completion callback, and verify that the request ran as expected. |
3065 EXPECT_EQ(OK, callback2.WaitForResult()); | 3061 EXPECT_EQ(OK, callback2.WaitForResult()); |
3066 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3062 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3067 } | 3063 } |
3068 | 3064 |
3069 // This test verifies that the PAC script specified by the settings is | 3065 // This test verifies that the PAC script specified by the settings is |
3070 // periodically polled for changes. Specifically, if the initial fetch succeeds, | 3066 // periodically polled for changes. Specifically, if the initial fetch succeeds, |
3071 // however at a later time it starts to fail, we should re-configure the | 3067 // however at a later time it starts to fail, we should re-configure the |
3072 // ProxyService to stop using that PAC script. | 3068 // ProxyService to stop using that PAC script. |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3110 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3106 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3111 // PAC script download completion. | 3107 // PAC script download completion. |
3112 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3108 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3113 | 3109 |
3114 // Now that the PAC script is downloaded, the request will have been sent to | 3110 // Now that the PAC script is downloaded, the request will have been sent to |
3115 // the proxy resolver. | 3111 // the proxy resolver. |
3116 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3112 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3117 factory->pending_requests()[0]->script_data()->utf16()); | 3113 factory->pending_requests()[0]->script_data()->utf16()); |
3118 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3114 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3119 | 3115 |
3120 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3116 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3121 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3117 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
3122 | 3118 |
3123 // Complete the pending request. | 3119 // Complete the pending request. |
3124 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3120 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
3125 resolver.pending_requests()[0]->CompleteNow(OK); | 3121 resolver.pending_jobs()[0]->CompleteNow(OK); |
3126 | 3122 |
3127 // Wait for completion callback, and verify that the request ran as expected. | 3123 // Wait for completion callback, and verify that the request ran as expected. |
3128 EXPECT_EQ(OK, callback1.WaitForResult()); | 3124 EXPECT_EQ(OK, callback1.WaitForResult()); |
3129 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3125 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3130 | 3126 |
3131 // At this point we have initialized the proxy service using a PAC script. | 3127 // At this point we have initialized the proxy service using a PAC script. |
3132 // | 3128 // |
3133 // A background task to periodically re-check the PAC script for validity will | 3129 // A background task to periodically re-check the PAC script for validity will |
3134 // have been started. We will now wait for the next download attempt to start. | 3130 // have been started. We will now wait for the next download attempt to start. |
3135 // | 3131 // |
3136 // Note that we shouldn't have to wait long here, since our test enables a | 3132 // Note that we shouldn't have to wait long here, since our test enables a |
3137 // special unit-test mode. | 3133 // special unit-test mode. |
3138 fetcher->WaitUntilFetch(); | 3134 fetcher->WaitUntilFetch(); |
3139 | 3135 |
3140 ASSERT_TRUE(factory->pending_requests().empty()); | 3136 ASSERT_TRUE(factory->pending_requests().empty()); |
3141 ASSERT_TRUE(resolver.pending_requests().empty()); | 3137 ASSERT_TRUE(resolver.pending_jobs().empty()); |
3142 | 3138 |
3143 // Make sure that our background checker is trying to download the expected | 3139 // Make sure that our background checker is trying to download the expected |
3144 // PAC script (same one as before). This time we will simulate a failure | 3140 // PAC script (same one as before). This time we will simulate a failure |
3145 // to download the script. | 3141 // to download the script. |
3146 EXPECT_TRUE(fetcher->has_pending_request()); | 3142 EXPECT_TRUE(fetcher->has_pending_request()); |
3147 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3143 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3148 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 3144 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
3149 | 3145 |
3150 base::MessageLoop::current()->RunUntilIdle(); | 3146 base::MessageLoop::current()->RunUntilIdle(); |
3151 | 3147 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3264 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3260 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
3265 // PAC script download completion. | 3261 // PAC script download completion. |
3266 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3262 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
3267 | 3263 |
3268 // Now that the PAC script is downloaded, the request will have been sent to | 3264 // Now that the PAC script is downloaded, the request will have been sent to |
3269 // the proxy resolver. | 3265 // the proxy resolver. |
3270 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3266 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
3271 factory->pending_requests()[0]->script_data()->utf16()); | 3267 factory->pending_requests()[0]->script_data()->utf16()); |
3272 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); | 3268 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
3273 | 3269 |
3274 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3270 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3275 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3271 EXPECT_EQ(GURL("http://request1"), resolver.pending_jobs()[0]->url()); |
3276 | 3272 |
3277 // Complete the pending request. | 3273 // Complete the pending request. |
3278 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3274 resolver.pending_jobs()[0]->results()->UseNamedProxy("request1:80"); |
3279 resolver.pending_requests()[0]->CompleteNow(OK); | 3275 resolver.pending_jobs()[0]->CompleteNow(OK); |
3280 | 3276 |
3281 // Wait for completion callback, and verify that the request ran as expected. | 3277 // Wait for completion callback, and verify that the request ran as expected. |
3282 EXPECT_EQ(OK, callback1.WaitForResult()); | 3278 EXPECT_EQ(OK, callback1.WaitForResult()); |
3283 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3279 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
3284 | 3280 |
3285 // At this point we have initialized the proxy service using a PAC script. | 3281 // At this point we have initialized the proxy service using a PAC script. |
3286 // Our PAC poller is set to update ONLY in response to network activity, | 3282 // Our PAC poller is set to update ONLY in response to network activity, |
3287 // (i.e. another call to ResolveProxy()). | 3283 // (i.e. another call to ResolveProxy()). |
3288 | 3284 |
3289 ASSERT_FALSE(fetcher->has_pending_request()); | 3285 ASSERT_FALSE(fetcher->has_pending_request()); |
3290 ASSERT_TRUE(factory->pending_requests().empty()); | 3286 ASSERT_TRUE(factory->pending_requests().empty()); |
3291 ASSERT_TRUE(resolver.pending_requests().empty()); | 3287 ASSERT_TRUE(resolver.pending_jobs().empty()); |
3292 | 3288 |
3293 // Start a second request. | 3289 // Start a second request. |
3294 ProxyInfo info2; | 3290 ProxyInfo info2; |
3295 TestCompletionCallback callback2; | 3291 TestCompletionCallback callback2; |
3296 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 3292 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
3297 callback2.callback(), NULL, NULL, BoundNetLog()); | 3293 callback2.callback(), NULL, NULL, BoundNetLog()); |
3298 EXPECT_EQ(ERR_IO_PENDING, rv); | 3294 EXPECT_EQ(ERR_IO_PENDING, rv); |
3299 | 3295 |
3300 // This request should have sent work to the resolver; complete it. | 3296 // This request should have sent work to the resolver; complete it. |
3301 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3297 ASSERT_EQ(1u, resolver.pending_jobs().size()); |
3302 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 3298 EXPECT_EQ(GURL("http://request2"), resolver.pending_jobs()[0]->url()); |
3303 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 3299 resolver.pending_jobs()[0]->results()->UseNamedProxy("request2:80"); |
3304 resolver.pending_requests()[0]->CompleteNow(OK); | 3300 resolver.pending_jobs()[0]->CompleteNow(OK); |
3305 | 3301 |
3306 EXPECT_EQ(OK, callback2.WaitForResult()); | 3302 EXPECT_EQ(OK, callback2.WaitForResult()); |
3307 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); | 3303 EXPECT_EQ("request2:80", info2.proxy_server().ToURI()); |
3308 | 3304 |
3309 // In response to getting that resolve request, the poller should have | 3305 // In response to getting that resolve request, the poller should have |
3310 // started the next poll, and made it as far as to request the download. | 3306 // started the next poll, and made it as far as to request the download. |
3311 | 3307 |
3312 EXPECT_TRUE(fetcher->has_pending_request()); | 3308 EXPECT_TRUE(fetcher->has_pending_request()); |
3313 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3309 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
3314 | 3310 |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
3376 url, LOAD_NORMAL, &info, NULL, log.bound()); | 3372 url, LOAD_NORMAL, &info, NULL, log.bound()); |
3377 EXPECT_TRUE(synchronous_success); | 3373 EXPECT_TRUE(synchronous_success); |
3378 EXPECT_FALSE(info.is_direct()); | 3374 EXPECT_FALSE(info.is_direct()); |
3379 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); | 3375 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); |
3380 | 3376 |
3381 // No request should have been queued. | 3377 // No request should have been queued. |
3382 EXPECT_EQ(0u, factory->pending_requests().size()); | 3378 EXPECT_EQ(0u, factory->pending_requests().size()); |
3383 } | 3379 } |
3384 | 3380 |
3385 } // namespace net | 3381 } // namespace net |
OLD | NEW |