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