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