| 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 <vector> | 7 #include <vector> |
| 8 | 8 |
| 9 #include "base/format_macros.h" | 9 #include "base/format_macros.h" |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 235 | 235 |
| 236 private: | 236 private: |
| 237 bool on_proxy_fallback_called_; | 237 bool on_proxy_fallback_called_; |
| 238 ProxyServer proxy_server_; | 238 ProxyServer proxy_server_; |
| 239 int proxy_fallback_net_error_; | 239 int proxy_fallback_net_error_; |
| 240 }; | 240 }; |
| 241 | 241 |
| 242 } // namespace | 242 } // namespace |
| 243 | 243 |
| 244 TEST_F(ProxyServiceTest, Direct) { | 244 TEST_F(ProxyServiceTest, Direct) { |
| 245 MockAsyncProxyResolver resolver; | 245 MockAsyncProxyResolverFactory* factory = |
| 246 ProxyService service( | 246 new MockAsyncProxyResolverFactory(false); |
| 247 new MockProxyConfigService(ProxyConfig::CreateDirect()), | 247 ProxyService service(new MockProxyConfigService(ProxyConfig::CreateDirect()), |
| 248 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | 248 make_scoped_ptr(factory), NULL); |
| 249 | 249 |
| 250 GURL url("http://www.google.com/"); | 250 GURL url("http://www.google.com/"); |
| 251 | 251 |
| 252 ProxyInfo info; | 252 ProxyInfo info; |
| 253 TestCompletionCallback callback; | 253 TestCompletionCallback callback; |
| 254 BoundTestNetLog log; | 254 BoundTestNetLog log; |
| 255 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 255 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
| 256 NULL, NULL, log.bound()); | 256 NULL, NULL, log.bound()); |
| 257 EXPECT_EQ(OK, rv); | 257 EXPECT_EQ(OK, rv); |
| 258 EXPECT_TRUE(resolver.pending_requests().empty()); | 258 EXPECT_TRUE(factory->pending_requests().empty()); |
| 259 | 259 |
| 260 EXPECT_TRUE(info.is_direct()); | 260 EXPECT_TRUE(info.is_direct()); |
| 261 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); | 261 EXPECT_TRUE(info.proxy_resolve_start_time().is_null()); |
| 262 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); | 262 EXPECT_TRUE(info.proxy_resolve_end_time().is_null()); |
| 263 | 263 |
| 264 // Check the NetLog was filled correctly. | 264 // Check the NetLog was filled correctly. |
| 265 CapturedNetLogEntry::List entries; | 265 CapturedNetLogEntry::List entries; |
| 266 log.GetEntries(&entries); | 266 log.GetEntries(&entries); |
| 267 | 267 |
| 268 EXPECT_EQ(3u, entries.size()); | 268 EXPECT_EQ(3u, entries.size()); |
| (...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 368 rv = service.ResolveProxy(bypass_url, LOAD_NORMAL, &info, callback.callback(), | 368 rv = service.ResolveProxy(bypass_url, LOAD_NORMAL, &info, callback.callback(), |
| 369 NULL, &delegate, log.bound()); | 369 NULL, &delegate, log.bound()); |
| 370 EXPECT_TRUE(info.is_direct()); | 370 EXPECT_TRUE(info.is_direct()); |
| 371 } | 371 } |
| 372 | 372 |
| 373 TEST_F(ProxyServiceTest, PAC) { | 373 TEST_F(ProxyServiceTest, PAC) { |
| 374 MockProxyConfigService* config_service = | 374 MockProxyConfigService* config_service = |
| 375 new MockProxyConfigService("http://foopy/proxy.pac"); | 375 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 376 | 376 |
| 377 MockAsyncProxyResolver resolver; | 377 MockAsyncProxyResolver resolver; |
| 378 MockAsyncProxyResolverFactory* factory = |
| 379 new MockAsyncProxyResolverFactory(false); |
| 378 | 380 |
| 379 ProxyService service( | 381 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 380 config_service, | |
| 381 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 382 | 382 |
| 383 GURL url("http://www.google.com/"); | 383 GURL url("http://www.google.com/"); |
| 384 | 384 |
| 385 ProxyInfo info; | 385 ProxyInfo info; |
| 386 TestCompletionCallback callback; | 386 TestCompletionCallback callback; |
| 387 ProxyService::PacRequest* request; | 387 ProxyService::PacRequest* request; |
| 388 BoundTestNetLog log; | 388 BoundTestNetLog log; |
| 389 | 389 |
| 390 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 390 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
| 391 &request, NULL, log.bound()); | 391 &request, NULL, log.bound()); |
| 392 EXPECT_EQ(ERR_IO_PENDING, rv); | 392 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 393 | 393 |
| 394 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); | 394 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request)); |
| 395 | 395 |
| 396 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 396 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 397 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 397 resolver.pending_set_pac_script_request()->script_data()->url()); | 398 factory->pending_requests()[0]->script_data()->url()); |
| 398 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 399 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 399 | 400 |
| 400 ASSERT_EQ(1u, resolver.pending_requests().size()); | 401 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 401 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 402 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 402 | 403 |
| 403 // Set the result in proxy resolver. | 404 // Set the result in proxy resolver. |
| 404 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 405 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); |
| 405 resolver.pending_requests()[0]->CompleteNow(OK); | 406 resolver.pending_requests()[0]->CompleteNow(OK); |
| 406 | 407 |
| 407 EXPECT_EQ(OK, callback.WaitForResult()); | 408 EXPECT_EQ(OK, callback.WaitForResult()); |
| 408 EXPECT_FALSE(info.is_direct()); | 409 EXPECT_FALSE(info.is_direct()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 428 entries, 4, NetLog::TYPE_PROXY_SERVICE)); | 429 entries, 4, NetLog::TYPE_PROXY_SERVICE)); |
| 429 } | 430 } |
| 430 | 431 |
| 431 // Test that the proxy resolver does not see the URL's username/password | 432 // Test that the proxy resolver does not see the URL's username/password |
| 432 // or its reference section. | 433 // or its reference section. |
| 433 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { | 434 TEST_F(ProxyServiceTest, PAC_NoIdentityOrHash) { |
| 434 MockProxyConfigService* config_service = | 435 MockProxyConfigService* config_service = |
| 435 new MockProxyConfigService("http://foopy/proxy.pac"); | 436 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 436 | 437 |
| 437 MockAsyncProxyResolver resolver; | 438 MockAsyncProxyResolver resolver; |
| 439 MockAsyncProxyResolverFactory* factory = |
| 440 new MockAsyncProxyResolverFactory(false); |
| 438 | 441 |
| 439 ProxyService service( | 442 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 440 config_service, | |
| 441 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 442 | 443 |
| 443 GURL url("http://username:password@www.google.com/?ref#hash#hash"); | 444 GURL url("http://username:password@www.google.com/?ref#hash#hash"); |
| 444 | 445 |
| 445 ProxyInfo info; | 446 ProxyInfo info; |
| 446 TestCompletionCallback callback; | 447 TestCompletionCallback callback; |
| 447 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 448 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
| 448 NULL, NULL, BoundNetLog()); | 449 NULL, NULL, BoundNetLog()); |
| 449 EXPECT_EQ(ERR_IO_PENDING, rv); | 450 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 450 | 451 |
| 451 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 452 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 452 resolver.pending_set_pac_script_request()->script_data()->url()); | 453 factory->pending_requests()[0]->script_data()->url()); |
| 453 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 454 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 454 | 455 |
| 455 ASSERT_EQ(1u, resolver.pending_requests().size()); | 456 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 456 // The URL should have been simplified, stripping the username/password/hash. | 457 // The URL should have been simplified, stripping the username/password/hash. |
| 457 EXPECT_EQ(GURL("http://www.google.com/?ref"), | 458 EXPECT_EQ(GURL("http://www.google.com/?ref"), |
| 458 resolver.pending_requests()[0]->url()); | 459 resolver.pending_requests()[0]->url()); |
| 459 | 460 |
| 460 // We end here without ever completing the request -- destruction of | 461 // We end here without ever completing the request -- destruction of |
| 461 // ProxyService will cancel the outstanding request. | 462 // ProxyService will cancel the outstanding request. |
| 462 } | 463 } |
| 463 | 464 |
| 464 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { | 465 TEST_F(ProxyServiceTest, PAC_FailoverWithoutDirect) { |
| 465 MockProxyConfigService* config_service = | 466 MockProxyConfigService* config_service = |
| 466 new MockProxyConfigService("http://foopy/proxy.pac"); | 467 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 467 MockAsyncProxyResolver resolver; | 468 MockAsyncProxyResolver resolver; |
| 469 MockAsyncProxyResolverFactory* factory = |
| 470 new MockAsyncProxyResolverFactory(false); |
| 468 | 471 |
| 469 ProxyService service( | 472 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 470 config_service, | |
| 471 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 472 | 473 |
| 473 GURL url("http://www.google.com/"); | 474 GURL url("http://www.google.com/"); |
| 474 | 475 |
| 475 ProxyInfo info; | 476 ProxyInfo info; |
| 476 TestCompletionCallback callback1; | 477 TestCompletionCallback callback1; |
| 477 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 478 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 478 NULL, NULL, BoundNetLog()); | 479 NULL, NULL, BoundNetLog()); |
| 479 EXPECT_EQ(ERR_IO_PENDING, rv); | 480 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 480 | 481 |
| 481 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 482 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 482 resolver.pending_set_pac_script_request()->script_data()->url()); | 483 factory->pending_requests()[0]->script_data()->url()); |
| 483 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 484 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 484 | 485 |
| 485 ASSERT_EQ(1u, resolver.pending_requests().size()); | 486 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 486 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 487 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 487 | 488 |
| 488 // Set the result in proxy resolver. | 489 // Set the result in proxy resolver. |
| 489 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); | 490 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy:8080"); |
| 490 resolver.pending_requests()[0]->CompleteNow(OK); | 491 resolver.pending_requests()[0]->CompleteNow(OK); |
| 491 | 492 |
| 492 EXPECT_EQ(OK, callback1.WaitForResult()); | 493 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 493 EXPECT_FALSE(info.is_direct()); | 494 EXPECT_FALSE(info.is_direct()); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 511 EXPECT_EQ(ERR_FAILED, rv); | 512 EXPECT_EQ(ERR_FAILED, rv); |
| 512 EXPECT_TRUE(info.is_empty()); | 513 EXPECT_TRUE(info.is_empty()); |
| 513 } | 514 } |
| 514 | 515 |
| 515 // Test that if the execution of the PAC script fails (i.e. javascript runtime | 516 // Test that if the execution of the PAC script fails (i.e. javascript runtime |
| 516 // error), and the PAC settings are non-mandatory, that we fall-back to direct. | 517 // error), and the PAC settings are non-mandatory, that we fall-back to direct. |
| 517 TEST_F(ProxyServiceTest, PAC_RuntimeError) { | 518 TEST_F(ProxyServiceTest, PAC_RuntimeError) { |
| 518 MockProxyConfigService* config_service = | 519 MockProxyConfigService* config_service = |
| 519 new MockProxyConfigService("http://foopy/proxy.pac"); | 520 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 520 MockAsyncProxyResolver resolver; | 521 MockAsyncProxyResolver resolver; |
| 522 MockAsyncProxyResolverFactory* factory = |
| 523 new MockAsyncProxyResolverFactory(false); |
| 521 | 524 |
| 522 ProxyService service( | 525 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 523 config_service, | |
| 524 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 525 | 526 |
| 526 GURL url("http://this-causes-js-error/"); | 527 GURL url("http://this-causes-js-error/"); |
| 527 | 528 |
| 528 ProxyInfo info; | 529 ProxyInfo info; |
| 529 TestCompletionCallback callback1; | 530 TestCompletionCallback callback1; |
| 530 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 531 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 531 NULL, NULL, BoundNetLog()); | 532 NULL, NULL, BoundNetLog()); |
| 532 EXPECT_EQ(ERR_IO_PENDING, rv); | 533 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 533 | 534 |
| 534 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 535 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 535 resolver.pending_set_pac_script_request()->script_data()->url()); | 536 factory->pending_requests()[0]->script_data()->url()); |
| 536 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 537 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 537 | 538 |
| 538 ASSERT_EQ(1u, resolver.pending_requests().size()); | 539 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 539 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 540 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 540 | 541 |
| 541 // Simulate a failure in the PAC executor. | 542 // Simulate a failure in the PAC executor. |
| 542 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); | 543 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_FAILED); |
| 543 | 544 |
| 544 EXPECT_EQ(OK, callback1.WaitForResult()); | 545 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 545 | 546 |
| 546 // Since the PAC script was non-mandatory, we should have fallen-back to | 547 // Since the PAC script was non-mandatory, we should have fallen-back to |
| (...skipping 21 matching lines...) Expand all Loading... |
| 568 // | 569 // |
| 569 // For which we expect it to try DIRECT, then foobar:10, then DIRECT again, | 570 // For which we expect it to try DIRECT, then foobar:10, then DIRECT again, |
| 570 // then foobar:20, and then give up and error. | 571 // then foobar:20, and then give up and error. |
| 571 // | 572 // |
| 572 // The important check of this test is to make sure that DIRECT is not somehow | 573 // The important check of this test is to make sure that DIRECT is not somehow |
| 573 // cached as being a bad proxy. | 574 // cached as being a bad proxy. |
| 574 TEST_F(ProxyServiceTest, PAC_FailoverAfterDirect) { | 575 TEST_F(ProxyServiceTest, PAC_FailoverAfterDirect) { |
| 575 MockProxyConfigService* config_service = | 576 MockProxyConfigService* config_service = |
| 576 new MockProxyConfigService("http://foopy/proxy.pac"); | 577 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 577 MockAsyncProxyResolver resolver; | 578 MockAsyncProxyResolver resolver; |
| 579 MockAsyncProxyResolverFactory* factory = |
| 580 new MockAsyncProxyResolverFactory(false); |
| 578 | 581 |
| 579 ProxyService service( | 582 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 580 config_service, | |
| 581 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 582 | 583 |
| 583 GURL url("http://www.google.com/"); | 584 GURL url("http://www.google.com/"); |
| 584 | 585 |
| 585 ProxyInfo info; | 586 ProxyInfo info; |
| 586 TestCompletionCallback callback1; | 587 TestCompletionCallback callback1; |
| 587 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 588 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 588 NULL, NULL, BoundNetLog()); | 589 NULL, NULL, BoundNetLog()); |
| 589 EXPECT_EQ(ERR_IO_PENDING, rv); | 590 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 590 | 591 |
| 591 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 592 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 592 resolver.pending_set_pac_script_request()->script_data()->url()); | 593 factory->pending_requests()[0]->script_data()->url()); |
| 593 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 594 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 594 | 595 |
| 595 ASSERT_EQ(1u, resolver.pending_requests().size()); | 596 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 596 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 597 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 597 | 598 |
| 598 // Set the result in proxy resolver. | 599 // Set the result in proxy resolver. |
| 599 resolver.pending_requests()[0]->results()->UsePacString( | 600 resolver.pending_requests()[0]->results()->UsePacString( |
| 600 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); | 601 "DIRECT ; PROXY foobar:10 ; DIRECT ; PROXY foobar:20"); |
| 601 resolver.pending_requests()[0]->CompleteNow(OK); | 602 resolver.pending_requests()[0]->CompleteNow(OK); |
| 602 | 603 |
| 603 EXPECT_EQ(OK, callback1.WaitForResult()); | 604 EXPECT_EQ(OK, callback1.WaitForResult()); |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 644 | 645 |
| 645 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { | 646 TEST_F(ProxyServiceTest, PAC_ConfigSourcePropagates) { |
| 646 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied | 647 // Test whether the ProxyConfigSource set by the ProxyConfigService is applied |
| 647 // to ProxyInfo after the proxy is resolved via a PAC script. | 648 // to ProxyInfo after the proxy is resolved via a PAC script. |
| 648 ProxyConfig config = | 649 ProxyConfig config = |
| 649 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 650 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
| 650 config.set_source(PROXY_CONFIG_SOURCE_TEST); | 651 config.set_source(PROXY_CONFIG_SOURCE_TEST); |
| 651 | 652 |
| 652 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 653 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 653 MockAsyncProxyResolver resolver; | 654 MockAsyncProxyResolver resolver; |
| 654 ProxyService service( | 655 MockAsyncProxyResolverFactory* factory = |
| 655 config_service, | 656 new MockAsyncProxyResolverFactory(false); |
| 656 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | 657 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 657 | 658 |
| 658 // Resolve something. | 659 // Resolve something. |
| 659 GURL url("http://www.google.com/"); | 660 GURL url("http://www.google.com/"); |
| 660 ProxyInfo info; | 661 ProxyInfo info; |
| 661 TestCompletionCallback callback; | 662 TestCompletionCallback callback; |
| 662 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 663 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
| 663 NULL, NULL, BoundNetLog()); | 664 NULL, NULL, BoundNetLog()); |
| 664 ASSERT_EQ(ERR_IO_PENDING, rv); | 665 ASSERT_EQ(ERR_IO_PENDING, rv); |
| 665 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 666 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 666 ASSERT_EQ(1u, resolver.pending_requests().size()); | 667 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 667 | 668 |
| 668 // Set the result in proxy resolver. | 669 // Set the result in proxy resolver. |
| 669 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); | 670 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy"); |
| 670 resolver.pending_requests()[0]->CompleteNow(OK); | 671 resolver.pending_requests()[0]->CompleteNow(OK); |
| 671 | 672 |
| 672 EXPECT_EQ(OK, callback.WaitForResult()); | 673 EXPECT_EQ(OK, callback.WaitForResult()); |
| 673 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); | 674 EXPECT_EQ(PROXY_CONFIG_SOURCE_TEST, info.config_source()); |
| 674 EXPECT_TRUE(info.did_use_pac_script()); | 675 EXPECT_TRUE(info.did_use_pac_script()); |
| 675 | 676 |
| 676 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 677 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 677 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 678 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 678 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 679 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 679 } | 680 } |
| 680 | 681 |
| 681 TEST_F(ProxyServiceTest, ProxyResolverFails) { | 682 TEST_F(ProxyServiceTest, ProxyResolverFails) { |
| 682 // Test what happens when the ProxyResolver fails. The download and setting | 683 // Test what happens when the ProxyResolver fails. The download and setting |
| 683 // of the PAC script have already succeeded, so this corresponds with a | 684 // of the PAC script have already succeeded, so this corresponds with a |
| 684 // javascript runtime error while calling FindProxyForURL(). | 685 // javascript runtime error while calling FindProxyForURL(). |
| 685 | 686 |
| 686 MockProxyConfigService* config_service = | 687 MockProxyConfigService* config_service = |
| 687 new MockProxyConfigService("http://foopy/proxy.pac"); | 688 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 688 | 689 |
| 689 MockAsyncProxyResolver resolver; | 690 MockAsyncProxyResolver resolver; |
| 691 MockAsyncProxyResolverFactory* factory = |
| 692 new MockAsyncProxyResolverFactory(false); |
| 690 | 693 |
| 691 ProxyService service( | 694 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 692 config_service, | |
| 693 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 694 | 695 |
| 695 // Start first resolve request. | 696 // Start first resolve request. |
| 696 GURL url("http://www.google.com/"); | 697 GURL url("http://www.google.com/"); |
| 697 ProxyInfo info; | 698 ProxyInfo info; |
| 698 TestCompletionCallback callback1; | 699 TestCompletionCallback callback1; |
| 699 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 700 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 700 NULL, NULL, BoundNetLog()); | 701 NULL, NULL, BoundNetLog()); |
| 701 EXPECT_EQ(ERR_IO_PENDING, rv); | 702 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 702 | 703 |
| 703 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 704 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 704 resolver.pending_set_pac_script_request()->script_data()->url()); | 705 factory->pending_requests()[0]->script_data()->url()); |
| 705 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 706 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 706 | 707 |
| 707 ASSERT_EQ(1u, resolver.pending_requests().size()); | 708 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 708 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 709 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 709 | 710 |
| 710 // Fail the first resolve request in MockAsyncProxyResolver. | 711 // Fail the first resolve request in MockAsyncProxyResolver. |
| 711 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 712 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 712 | 713 |
| 713 // Although the proxy resolver failed the request, ProxyService implicitly | 714 // Although the proxy resolver failed the request, ProxyService implicitly |
| 714 // falls-back to DIRECT. | 715 // falls-back to DIRECT. |
| 715 EXPECT_EQ(OK, callback1.WaitForResult()); | 716 EXPECT_EQ(OK, callback1.WaitForResult()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 741 } | 742 } |
| 742 | 743 |
| 743 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { | 744 TEST_F(ProxyServiceTest, ProxyResolverTerminatedDuringRequest) { |
| 744 // Test what happens when the ProxyResolver fails with a fatal error while | 745 // Test what happens when the ProxyResolver fails with a fatal error while |
| 745 // a GetProxyForURL() call is in progress. | 746 // a GetProxyForURL() call is in progress. |
| 746 | 747 |
| 747 MockProxyConfigService* config_service = | 748 MockProxyConfigService* config_service = |
| 748 new MockProxyConfigService("http://foopy/proxy.pac"); | 749 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 749 | 750 |
| 750 MockAsyncProxyResolver resolver; | 751 MockAsyncProxyResolver resolver; |
| 752 MockAsyncProxyResolverFactory* factory = |
| 753 new MockAsyncProxyResolverFactory(false); |
| 751 | 754 |
| 752 ProxyService service( | 755 ProxyService service(config_service, make_scoped_ptr(factory), nullptr); |
| 753 config_service, | |
| 754 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), nullptr); | |
| 755 | 756 |
| 756 // Start first resolve request. | 757 // Start first resolve request. |
| 757 GURL url("http://www.google.com/"); | 758 GURL url("http://www.google.com/"); |
| 758 ProxyInfo info; | 759 ProxyInfo info; |
| 759 TestCompletionCallback callback1; | 760 TestCompletionCallback callback1; |
| 760 int rv = | 761 int rv = |
| 761 service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback1.callback(), | 762 service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback1.callback(), |
| 762 nullptr, nullptr, BoundNetLog()); | 763 nullptr, nullptr, BoundNetLog()); |
| 763 EXPECT_EQ(ERR_IO_PENDING, rv); | 764 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 764 | 765 |
| 765 ASSERT_TRUE(resolver.pending_set_pac_script_request()); | 766 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 766 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 767 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 767 resolver.pending_set_pac_script_request()->script_data()->url()); | 768 factory->pending_requests()[0]->script_data()->url()); |
| 768 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 769 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 769 | 770 |
| 770 ASSERT_EQ(1u, resolver.pending_requests().size()); | 771 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 771 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 772 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 772 | 773 |
| 773 // Fail the first resolve request in MockAsyncProxyResolver. | 774 // Fail the first resolve request in MockAsyncProxyResolver. |
| 774 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 775 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
| 775 | 776 |
| 776 // Although the proxy resolver failed the request, ProxyService implicitly | 777 // Although the proxy resolver failed the request, ProxyService implicitly |
| 777 // falls-back to DIRECT. | 778 // falls-back to DIRECT. |
| 778 EXPECT_EQ(OK, callback1.WaitForResult()); | 779 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 779 EXPECT_TRUE(info.is_direct()); | 780 EXPECT_TRUE(info.is_direct()); |
| 780 | 781 |
| 781 // Failed PAC executions still have proxy resolution times. | 782 // Failed PAC executions still have proxy resolution times. |
| 782 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 783 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 783 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 784 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 784 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 785 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 785 | 786 |
| 786 // With no other requests, the ProxyService waits for a new request before | 787 // With no other requests, the ProxyService waits for a new request before |
| 787 // initializing a new ProxyResolver. | 788 // initializing a new ProxyResolver. |
| 788 EXPECT_FALSE(resolver.pending_set_pac_script_request()); | 789 EXPECT_TRUE(factory->pending_requests().empty()); |
| 789 | 790 |
| 790 TestCompletionCallback callback2; | 791 TestCompletionCallback callback2; |
| 791 rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback2.callback(), | 792 rv = service.ResolveProxy(url, net::LOAD_NORMAL, &info, callback2.callback(), |
| 792 nullptr, nullptr, BoundNetLog()); | 793 nullptr, nullptr, BoundNetLog()); |
| 793 EXPECT_EQ(ERR_IO_PENDING, rv); | 794 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 794 | 795 |
| 795 ASSERT_TRUE(resolver.pending_set_pac_script_request()); | 796 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 796 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 797 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 797 resolver.pending_set_pac_script_request()->script_data()->url()); | 798 factory->pending_requests()[0]->script_data()->url()); |
| 798 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 799 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 799 | 800 |
| 800 ASSERT_EQ(1u, resolver.pending_requests().size()); | 801 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 801 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 802 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 802 | 803 |
| 803 // This time we will have the resolver succeed. | 804 // This time we will have the resolver succeed. |
| 804 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 805 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
| 805 resolver.pending_requests()[0]->CompleteNow(OK); | 806 resolver.pending_requests()[0]->CompleteNow(OK); |
| 806 | 807 |
| 807 EXPECT_EQ(OK, callback2.WaitForResult()); | 808 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 808 EXPECT_FALSE(info.is_direct()); | 809 EXPECT_FALSE(info.is_direct()); |
| 809 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 810 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
| 810 } | 811 } |
| 811 | 812 |
| 812 TEST_F(ProxyServiceTest, | 813 TEST_F(ProxyServiceTest, |
| 813 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { | 814 ProxyResolverTerminatedDuringRequestWithConcurrentRequest) { |
| 814 // Test what happens when the ProxyResolver fails with a fatal error while | 815 // Test what happens when the ProxyResolver fails with a fatal error while |
| 815 // a GetProxyForURL() call is in progress. | 816 // a GetProxyForURL() call is in progress. |
| 816 | 817 |
| 817 MockProxyConfigService* config_service = | 818 MockProxyConfigService* config_service = |
| 818 new MockProxyConfigService("http://foopy/proxy.pac"); | 819 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 819 | 820 |
| 820 MockAsyncProxyResolver resolver; | 821 MockAsyncProxyResolver resolver; |
| 822 MockAsyncProxyResolverFactory* factory = |
| 823 new MockAsyncProxyResolverFactory(false); |
| 821 | 824 |
| 822 ProxyService service( | 825 ProxyService service(config_service, make_scoped_ptr(factory), nullptr); |
| 823 config_service, | |
| 824 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), nullptr); | |
| 825 | 826 |
| 826 // Start two resolve requests. | 827 // Start two resolve requests. |
| 827 GURL url1("http://www.google.com/"); | 828 GURL url1("http://www.google.com/"); |
| 828 GURL url2("https://www.google.com/"); | 829 GURL url2("https://www.google.com/"); |
| 829 ProxyInfo info; | 830 ProxyInfo info; |
| 830 TestCompletionCallback callback1; | 831 TestCompletionCallback callback1; |
| 831 int rv = | 832 int rv = |
| 832 service.ResolveProxy(url1, net::LOAD_NORMAL, &info, callback1.callback(), | 833 service.ResolveProxy(url1, net::LOAD_NORMAL, &info, callback1.callback(), |
| 833 nullptr, nullptr, BoundNetLog()); | 834 nullptr, nullptr, BoundNetLog()); |
| 834 EXPECT_EQ(ERR_IO_PENDING, rv); | 835 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 835 TestCompletionCallback callback2; | 836 TestCompletionCallback callback2; |
| 836 rv = service.ResolveProxy(url2, net::LOAD_NORMAL, &info, callback2.callback(), | 837 rv = service.ResolveProxy(url2, net::LOAD_NORMAL, &info, callback2.callback(), |
| 837 nullptr, nullptr, BoundNetLog()); | 838 nullptr, nullptr, BoundNetLog()); |
| 838 EXPECT_EQ(ERR_IO_PENDING, rv); | 839 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 839 | 840 |
| 840 ASSERT_TRUE(resolver.pending_set_pac_script_request()); | 841 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 841 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 842 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 842 resolver.pending_set_pac_script_request()->script_data()->url()); | 843 factory->pending_requests()[0]->script_data()->url()); |
| 843 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 844 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 844 | 845 |
| 845 ASSERT_EQ(2u, resolver.pending_requests().size()); | 846 ASSERT_EQ(2u, resolver.pending_requests().size()); |
| 846 EXPECT_EQ(url1, resolver.pending_requests()[0]->url()); | 847 EXPECT_EQ(url1, resolver.pending_requests()[0]->url()); |
| 847 EXPECT_EQ(url2, resolver.pending_requests()[1]->url()); | 848 EXPECT_EQ(url2, resolver.pending_requests()[1]->url()); |
| 848 | 849 |
| 849 // Fail the first resolve request in MockAsyncProxyResolver. | 850 // Fail the first resolve request in MockAsyncProxyResolver. |
| 850 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); | 851 resolver.pending_requests()[0]->CompleteNow(ERR_PAC_SCRIPT_TERMINATED); |
| 851 | 852 |
| 852 // Although the proxy resolver failed the request, ProxyService implicitly | 853 // Although the proxy resolver failed the request, ProxyService implicitly |
| 853 // falls-back to DIRECT. | 854 // falls-back to DIRECT. |
| 854 EXPECT_EQ(OK, callback1.WaitForResult()); | 855 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 855 EXPECT_TRUE(info.is_direct()); | 856 EXPECT_TRUE(info.is_direct()); |
| 856 | 857 |
| 857 // Failed PAC executions still have proxy resolution times. | 858 // Failed PAC executions still have proxy resolution times. |
| 858 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 859 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 859 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 860 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 860 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 861 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 861 | 862 |
| 862 // The second request is cancelled when the proxy resolver terminates. | 863 // The second request is cancelled when the proxy resolver terminates. |
| 863 ASSERT_EQ(1u, resolver.cancelled_requests().size()); | 864 ASSERT_EQ(1u, resolver.cancelled_requests().size()); |
| 864 EXPECT_EQ(url2, resolver.cancelled_requests()[0]->url()); | 865 EXPECT_EQ(url2, resolver.cancelled_requests()[0]->url()); |
| 865 | 866 |
| 866 // Since a second request was in progress, the ProxyService starts | 867 // Since a second request was in progress, the ProxyService starts |
| 867 // initializating a new ProxyResolver. | 868 // initializating a new ProxyResolver. |
| 868 ASSERT_TRUE(resolver.pending_set_pac_script_request()); | 869 ASSERT_EQ(1u, factory->pending_requests().size()); |
| 869 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 870 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 870 resolver.pending_set_pac_script_request()->script_data()->url()); | 871 factory->pending_requests()[0]->script_data()->url()); |
| 871 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 872 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 872 | 873 |
| 873 ASSERT_EQ(1u, resolver.pending_requests().size()); | 874 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 874 EXPECT_EQ(url2, resolver.pending_requests()[0]->url()); | 875 EXPECT_EQ(url2, resolver.pending_requests()[0]->url()); |
| 875 | 876 |
| 876 // This request succeeds. | 877 // This request succeeds. |
| 877 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); | 878 resolver.pending_requests()[0]->results()->UseNamedProxy("foopy_valid:8080"); |
| 878 resolver.pending_requests()[0]->CompleteNow(OK); | 879 resolver.pending_requests()[0]->CompleteNow(OK); |
| 879 | 880 |
| 880 EXPECT_EQ(OK, callback2.WaitForResult()); | 881 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 881 EXPECT_FALSE(info.is_direct()); | 882 EXPECT_FALSE(info.is_direct()); |
| 882 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); | 883 EXPECT_EQ("foopy_valid:8080", info.proxy_server().ToURI()); |
| 883 } | 884 } |
| 884 | 885 |
| 885 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { | 886 TEST_F(ProxyServiceTest, ProxyScriptFetcherFailsDownloadingMandatoryPac) { |
| 886 // Test what happens when the ProxyScriptResolver fails to download a | 887 // Test what happens when the ProxyScriptResolver fails to download a |
| 887 // mandatory PAC script. | 888 // mandatory PAC script. |
| 888 | 889 |
| 889 ProxyConfig config( | 890 ProxyConfig config( |
| 890 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 891 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 891 config.set_pac_mandatory(true); | 892 config.set_pac_mandatory(true); |
| 892 | 893 |
| 893 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 894 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 894 | 895 |
| 895 MockAsyncProxyResolver resolver; | 896 MockAsyncProxyResolverFactory* factory = |
| 897 new MockAsyncProxyResolverFactory(false); |
| 896 | 898 |
| 897 ProxyService service( | 899 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 898 config_service, | |
| 899 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 900 | 900 |
| 901 // Start first resolve request. | 901 // Start first resolve request. |
| 902 GURL url("http://www.google.com/"); | 902 GURL url("http://www.google.com/"); |
| 903 ProxyInfo info; | 903 ProxyInfo info; |
| 904 TestCompletionCallback callback1; | 904 TestCompletionCallback callback1; |
| 905 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 905 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 906 NULL, NULL, BoundNetLog()); | 906 NULL, NULL, BoundNetLog()); |
| 907 EXPECT_EQ(ERR_IO_PENDING, rv); | 907 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 908 | 908 |
| 909 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 909 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 910 resolver.pending_set_pac_script_request()->script_data()->url()); | 910 factory->pending_requests()[0]->script_data()->url()); |
| 911 resolver.pending_set_pac_script_request()->CompleteNow(ERR_FAILED); | 911 factory->pending_requests()[0]->CompleteNow(ERR_FAILED, nullptr); |
| 912 | 912 |
| 913 ASSERT_EQ(0u, resolver.pending_requests().size()); | 913 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 914 // As the proxy resolver failed the request and is configured for a mandatory | 914 // As the proxy resolver factory failed the request and is configured for a |
| 915 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 915 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. |
| 916 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 916 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
| 917 callback1.WaitForResult()); | 917 callback1.WaitForResult()); |
| 918 EXPECT_FALSE(info.is_direct()); | 918 EXPECT_FALSE(info.is_direct()); |
| 919 | 919 |
| 920 // As the proxy resolver failed the request and is configured for a mandatory | 920 // As the proxy resolver factory failed the request and is configured for a |
| 921 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 921 // mandatory PAC script, ProxyService must not implicitly fall-back to DIRECT. |
| 922 TestCompletionCallback callback2; | 922 TestCompletionCallback callback2; |
| 923 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, | 923 rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback2.callback(), NULL, |
| 924 NULL, BoundNetLog()); | 924 NULL, BoundNetLog()); |
| 925 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); | 925 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, rv); |
| 926 EXPECT_FALSE(info.is_direct()); | 926 EXPECT_FALSE(info.is_direct()); |
| 927 } | 927 } |
| 928 | 928 |
| 929 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { | 929 TEST_F(ProxyServiceTest, ProxyResolverFailsParsingJavaScriptMandatoryPac) { |
| 930 // Test what happens when the ProxyResolver fails that is configured to use a | 930 // Test what happens when the ProxyResolver fails that is configured to use a |
| 931 // mandatory PAC script. The download of the PAC script has already | 931 // mandatory PAC script. The download of the PAC script has already |
| 932 // succeeded but the PAC script contains no valid javascript. | 932 // succeeded but the PAC script contains no valid javascript. |
| 933 | 933 |
| 934 ProxyConfig config( | 934 ProxyConfig config( |
| 935 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 935 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 936 config.set_pac_mandatory(true); | 936 config.set_pac_mandatory(true); |
| 937 | 937 |
| 938 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 938 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 939 | 939 |
| 940 MockAsyncProxyResolverExpectsBytes resolver; | 940 MockAsyncProxyResolverFactory* factory = |
| 941 new MockAsyncProxyResolverFactory(true); |
| 941 | 942 |
| 942 ProxyService service( | 943 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 943 config_service, | |
| 944 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 945 | 944 |
| 946 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 945 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 947 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); | 946 DhcpProxyScriptFetcher* dhcp_fetcher = new DoNothingDhcpProxyScriptFetcher(); |
| 948 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); | 947 service.SetProxyScriptFetchers(fetcher, dhcp_fetcher); |
| 949 | 948 |
| 950 // Start resolve request. | 949 // Start resolve request. |
| 951 GURL url("http://www.google.com/"); | 950 GURL url("http://www.google.com/"); |
| 952 ProxyInfo info; | 951 ProxyInfo info; |
| 953 TestCompletionCallback callback; | 952 TestCompletionCallback callback; |
| 954 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 953 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
| 955 NULL, NULL, BoundNetLog()); | 954 NULL, NULL, BoundNetLog()); |
| 956 EXPECT_EQ(ERR_IO_PENDING, rv); | 955 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 957 | 956 |
| 958 // Check that nothing has been sent to the proxy resolver yet. | 957 // Check that nothing has been sent to the proxy resolver factory yet. |
| 959 ASSERT_EQ(0u, resolver.pending_requests().size()); | 958 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 960 | 959 |
| 961 // Downloading the PAC script succeeds. | 960 // Downloading the PAC script succeeds. |
| 962 EXPECT_TRUE(fetcher->has_pending_request()); | 961 EXPECT_TRUE(fetcher->has_pending_request()); |
| 963 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 962 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 964 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 963 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
| 965 | 964 |
| 966 EXPECT_FALSE(fetcher->has_pending_request()); | 965 EXPECT_FALSE(fetcher->has_pending_request()); |
| 967 ASSERT_EQ(0u, resolver.pending_requests().size()); | 966 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 968 | 967 |
| 969 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was | 968 // Since ProxyScriptDecider failed to identify a valid PAC and PAC was |
| 970 // mandatory for this configuration, the ProxyService must not implicitly | 969 // mandatory for this configuration, the ProxyService must not implicitly |
| 971 // fall-back to DIRECT. | 970 // fall-back to DIRECT. |
| 972 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 971 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
| 973 callback.WaitForResult()); | 972 callback.WaitForResult()); |
| 974 EXPECT_FALSE(info.is_direct()); | 973 EXPECT_FALSE(info.is_direct()); |
| 975 } | 974 } |
| 976 | 975 |
| 977 TEST_F(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { | 976 TEST_F(ProxyServiceTest, ProxyResolverFailsInJavaScriptMandatoryPac) { |
| 978 // Test what happens when the ProxyResolver fails that is configured to use a | 977 // Test what happens when the ProxyResolver fails that is configured to use a |
| 979 // mandatory PAC script. The download and setting of the PAC script have | 978 // mandatory PAC script. The download and setting of the PAC script have |
| 980 // already succeeded, so this corresponds with a javascript runtime error | 979 // already succeeded, so this corresponds with a javascript runtime error |
| 981 // while calling FindProxyForURL(). | 980 // while calling FindProxyForURL(). |
| 982 | 981 |
| 983 ProxyConfig config( | 982 ProxyConfig config( |
| 984 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 983 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 985 config.set_pac_mandatory(true); | 984 config.set_pac_mandatory(true); |
| 986 | 985 |
| 987 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 986 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 988 | 987 |
| 989 MockAsyncProxyResolver resolver; | 988 MockAsyncProxyResolver resolver; |
| 989 MockAsyncProxyResolverFactory* factory = |
| 990 new MockAsyncProxyResolverFactory(false); |
| 990 | 991 |
| 991 ProxyService service( | 992 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 992 config_service, | |
| 993 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 994 | 993 |
| 995 // Start first resolve request. | 994 // Start first resolve request. |
| 996 GURL url("http://www.google.com/"); | 995 GURL url("http://www.google.com/"); |
| 997 ProxyInfo info; | 996 ProxyInfo info; |
| 998 TestCompletionCallback callback1; | 997 TestCompletionCallback callback1; |
| 999 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 998 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 1000 NULL, NULL, BoundNetLog()); | 999 NULL, NULL, BoundNetLog()); |
| 1001 EXPECT_EQ(ERR_IO_PENDING, rv); | 1000 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1002 | 1001 |
| 1003 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1002 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1004 resolver.pending_set_pac_script_request()->script_data()->url()); | 1003 factory->pending_requests()[0]->script_data()->url()); |
| 1005 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1004 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1006 | 1005 |
| 1007 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1006 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1008 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1007 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1009 | 1008 |
| 1010 // Fail the first resolve request in MockAsyncProxyResolver. | 1009 // Fail the first resolve request in MockAsyncProxyResolver. |
| 1011 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); | 1010 resolver.pending_requests()[0]->CompleteNow(ERR_FAILED); |
| 1012 | 1011 |
| 1013 // As the proxy resolver failed the request and is configured for a mandatory | 1012 // As the proxy resolver failed the request and is configured for a mandatory |
| 1014 // PAC script, ProxyService must not implicitly fall-back to DIRECT. | 1013 // PAC script, ProxyService must not implicitly fall-back to DIRECT. |
| 1015 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, | 1014 EXPECT_EQ(ERR_MANDATORY_PROXY_CONFIGURATION_FAILED, |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1037 } | 1036 } |
| 1038 | 1037 |
| 1039 TEST_F(ProxyServiceTest, ProxyFallback) { | 1038 TEST_F(ProxyServiceTest, ProxyFallback) { |
| 1040 // Test what happens when we specify multiple proxy servers and some of them | 1039 // Test what happens when we specify multiple proxy servers and some of them |
| 1041 // are bad. | 1040 // are bad. |
| 1042 | 1041 |
| 1043 MockProxyConfigService* config_service = | 1042 MockProxyConfigService* config_service = |
| 1044 new MockProxyConfigService("http://foopy/proxy.pac"); | 1043 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1045 | 1044 |
| 1046 MockAsyncProxyResolver resolver; | 1045 MockAsyncProxyResolver resolver; |
| 1046 MockAsyncProxyResolverFactory* factory = |
| 1047 new MockAsyncProxyResolverFactory(false); |
| 1047 | 1048 |
| 1048 ProxyService service( | 1049 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1049 config_service, | |
| 1050 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 1051 | 1050 |
| 1052 GURL url("http://www.google.com/"); | 1051 GURL url("http://www.google.com/"); |
| 1053 | 1052 |
| 1054 // Get the proxy information. | 1053 // Get the proxy information. |
| 1055 ProxyInfo info; | 1054 ProxyInfo info; |
| 1056 TestCompletionCallback callback1; | 1055 TestCompletionCallback callback1; |
| 1057 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1056 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 1058 NULL, NULL, BoundNetLog()); | 1057 NULL, NULL, BoundNetLog()); |
| 1059 EXPECT_EQ(ERR_IO_PENDING, rv); | 1058 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1060 | 1059 |
| 1061 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1060 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1062 resolver.pending_set_pac_script_request()->script_data()->url()); | 1061 factory->pending_requests()[0]->script_data()->url()); |
| 1063 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1062 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1064 | 1063 |
| 1065 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1064 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1066 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1065 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1067 | 1066 |
| 1068 // Set the result in proxy resolver. | 1067 // Set the result in proxy resolver. |
| 1069 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1068 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1070 "foopy1:8080;foopy2:9090"); | 1069 "foopy1:8080;foopy2:9090"); |
| 1071 resolver.pending_requests()[0]->CompleteNow(OK); | 1070 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1072 | 1071 |
| 1073 // The first item is valid. | 1072 // The first item is valid. |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1186 // TODO(nsylvain): Test that the proxy can be retried after the delay. | 1185 // TODO(nsylvain): Test that the proxy can be retried after the delay. |
| 1187 } | 1186 } |
| 1188 | 1187 |
| 1189 // This test is similar to ProxyFallback, but this time we have an explicit | 1188 // This test is similar to ProxyFallback, but this time we have an explicit |
| 1190 // fallback choice to DIRECT. | 1189 // fallback choice to DIRECT. |
| 1191 TEST_F(ProxyServiceTest, ProxyFallbackToDirect) { | 1190 TEST_F(ProxyServiceTest, ProxyFallbackToDirect) { |
| 1192 MockProxyConfigService* config_service = | 1191 MockProxyConfigService* config_service = |
| 1193 new MockProxyConfigService("http://foopy/proxy.pac"); | 1192 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1194 | 1193 |
| 1195 MockAsyncProxyResolver resolver; | 1194 MockAsyncProxyResolver resolver; |
| 1195 MockAsyncProxyResolverFactory* factory = |
| 1196 new MockAsyncProxyResolverFactory(false); |
| 1196 | 1197 |
| 1197 ProxyService service( | 1198 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1198 config_service, | |
| 1199 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 1200 | 1199 |
| 1201 GURL url("http://www.google.com/"); | 1200 GURL url("http://www.google.com/"); |
| 1202 | 1201 |
| 1203 // Get the proxy information. | 1202 // Get the proxy information. |
| 1204 ProxyInfo info; | 1203 ProxyInfo info; |
| 1205 TestCompletionCallback callback1; | 1204 TestCompletionCallback callback1; |
| 1206 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1205 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 1207 NULL, NULL, BoundNetLog()); | 1206 NULL, NULL, BoundNetLog()); |
| 1208 EXPECT_EQ(ERR_IO_PENDING, rv); | 1207 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1209 | 1208 |
| 1210 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1209 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1211 resolver.pending_set_pac_script_request()->script_data()->url()); | 1210 factory->pending_requests()[0]->script_data()->url()); |
| 1212 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1211 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1213 | 1212 |
| 1214 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1213 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1215 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1214 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1216 | 1215 |
| 1217 // Set the result in proxy resolver. | 1216 // Set the result in proxy resolver. |
| 1218 resolver.pending_requests()[0]->results()->UsePacString( | 1217 resolver.pending_requests()[0]->results()->UsePacString( |
| 1219 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); | 1218 "PROXY foopy1:8080; PROXY foopy2:9090; DIRECT"); |
| 1220 resolver.pending_requests()[0]->CompleteNow(OK); | 1219 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1221 | 1220 |
| 1222 // Get the first result. | 1221 // Get the first result. |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1258 EXPECT_EQ(ERR_FAILED, rv); | 1257 EXPECT_EQ(ERR_FAILED, rv); |
| 1259 } | 1258 } |
| 1260 | 1259 |
| 1261 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { | 1260 TEST_F(ProxyServiceTest, ProxyFallback_NewSettings) { |
| 1262 // Test proxy failover when new settings are available. | 1261 // Test proxy failover when new settings are available. |
| 1263 | 1262 |
| 1264 MockProxyConfigService* config_service = | 1263 MockProxyConfigService* config_service = |
| 1265 new MockProxyConfigService("http://foopy/proxy.pac"); | 1264 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1266 | 1265 |
| 1267 MockAsyncProxyResolver resolver; | 1266 MockAsyncProxyResolver resolver; |
| 1267 MockAsyncProxyResolverFactory* factory = |
| 1268 new MockAsyncProxyResolverFactory(false); |
| 1268 | 1269 |
| 1269 ProxyService service( | 1270 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1270 config_service, | |
| 1271 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 1272 | 1271 |
| 1273 GURL url("http://www.google.com/"); | 1272 GURL url("http://www.google.com/"); |
| 1274 | 1273 |
| 1275 // Get the proxy information. | 1274 // Get the proxy information. |
| 1276 ProxyInfo info; | 1275 ProxyInfo info; |
| 1277 TestCompletionCallback callback1; | 1276 TestCompletionCallback callback1; |
| 1278 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1277 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 1279 NULL, NULL, BoundNetLog()); | 1278 NULL, NULL, BoundNetLog()); |
| 1280 EXPECT_EQ(ERR_IO_PENDING, rv); | 1279 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1281 | 1280 |
| 1282 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1281 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1283 resolver.pending_set_pac_script_request()->script_data()->url()); | 1282 factory->pending_requests()[0]->script_data()->url()); |
| 1284 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1283 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1285 | 1284 |
| 1286 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1285 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1287 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1286 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1288 | 1287 |
| 1289 // Set the result in proxy resolver. | 1288 // Set the result in proxy resolver. |
| 1290 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1289 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1291 "foopy1:8080;foopy2:9090"); | 1290 "foopy1:8080;foopy2:9090"); |
| 1292 resolver.pending_requests()[0]->CompleteNow(OK); | 1291 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1293 | 1292 |
| 1294 // The first item is valid. | 1293 // The first item is valid. |
| 1295 EXPECT_EQ(OK, callback1.WaitForResult()); | 1294 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1296 EXPECT_FALSE(info.is_direct()); | 1295 EXPECT_FALSE(info.is_direct()); |
| 1297 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1296 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1298 | 1297 |
| 1299 // Fake an error on the proxy, and also a new configuration on the proxy. | 1298 // Fake an error on the proxy, and also a new configuration on the proxy. |
| 1300 config_service->SetConfig( | 1299 config_service->SetConfig( |
| 1301 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); | 1300 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy-new/proxy.pac"))); |
| 1302 | 1301 |
| 1303 TestCompletionCallback callback2; | 1302 TestCompletionCallback callback2; |
| 1304 rv = service.ReconsiderProxyAfterError( | 1303 rv = service.ReconsiderProxyAfterError( |
| 1305 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1304 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
| 1306 callback2.callback(), NULL, NULL, BoundNetLog()); | 1305 callback2.callback(), NULL, NULL, BoundNetLog()); |
| 1307 EXPECT_EQ(ERR_IO_PENDING, rv); | 1306 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1308 | 1307 |
| 1309 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), | 1308 EXPECT_EQ(GURL("http://foopy-new/proxy.pac"), |
| 1310 resolver.pending_set_pac_script_request()->script_data()->url()); | 1309 factory->pending_requests()[0]->script_data()->url()); |
| 1311 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1310 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1312 | 1311 |
| 1313 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1312 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1314 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1313 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1315 | 1314 |
| 1316 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1315 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1317 "foopy1:8080;foopy2:9090"); | 1316 "foopy1:8080;foopy2:9090"); |
| 1318 resolver.pending_requests()[0]->CompleteNow(OK); | 1317 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1319 | 1318 |
| 1320 // The first proxy is still there since the configuration changed. | 1319 // The first proxy is still there since the configuration changed. |
| 1321 EXPECT_EQ(OK, callback2.WaitForResult()); | 1320 EXPECT_EQ(OK, callback2.WaitForResult()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1335 GURL("http://foopy-new2/proxy.pac"))); | 1334 GURL("http://foopy-new2/proxy.pac"))); |
| 1336 | 1335 |
| 1337 // We fake another error. It should go back to the first proxy. | 1336 // We fake another error. It should go back to the first proxy. |
| 1338 TestCompletionCallback callback4; | 1337 TestCompletionCallback callback4; |
| 1339 rv = service.ReconsiderProxyAfterError( | 1338 rv = service.ReconsiderProxyAfterError( |
| 1340 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, | 1339 url, LOAD_NORMAL, ERR_PROXY_CONNECTION_FAILED, &info, |
| 1341 callback4.callback(), NULL, NULL, BoundNetLog()); | 1340 callback4.callback(), NULL, NULL, BoundNetLog()); |
| 1342 EXPECT_EQ(ERR_IO_PENDING, rv); | 1341 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1343 | 1342 |
| 1344 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), | 1343 EXPECT_EQ(GURL("http://foopy-new2/proxy.pac"), |
| 1345 resolver.pending_set_pac_script_request()->script_data()->url()); | 1344 factory->pending_requests()[0]->script_data()->url()); |
| 1346 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1345 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1347 | 1346 |
| 1348 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1347 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1349 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1348 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1350 | 1349 |
| 1351 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1350 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1352 "foopy1:8080;foopy2:9090"); | 1351 "foopy1:8080;foopy2:9090"); |
| 1353 resolver.pending_requests()[0]->CompleteNow(OK); | 1352 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1354 | 1353 |
| 1355 EXPECT_EQ(OK, callback4.WaitForResult()); | 1354 EXPECT_EQ(OK, callback4.WaitForResult()); |
| 1356 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); | 1355 EXPECT_EQ("foopy1:8080", info.proxy_server().ToURI()); |
| 1357 | 1356 |
| 1358 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); | 1357 EXPECT_FALSE(info.proxy_resolve_start_time().is_null()); |
| 1359 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); | 1358 EXPECT_FALSE(info.proxy_resolve_end_time().is_null()); |
| 1360 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); | 1359 EXPECT_LE(info.proxy_resolve_start_time(), info.proxy_resolve_end_time()); |
| 1361 } | 1360 } |
| 1362 | 1361 |
| 1363 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { | 1362 TEST_F(ProxyServiceTest, ProxyFallback_BadConfig) { |
| 1364 // Test proxy failover when the configuration is bad. | 1363 // Test proxy failover when the configuration is bad. |
| 1365 | 1364 |
| 1366 MockProxyConfigService* config_service = | 1365 MockProxyConfigService* config_service = |
| 1367 new MockProxyConfigService("http://foopy/proxy.pac"); | 1366 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1368 | 1367 |
| 1369 MockAsyncProxyResolver resolver; | 1368 MockAsyncProxyResolver resolver; |
| 1369 MockAsyncProxyResolverFactory* factory = |
| 1370 new MockAsyncProxyResolverFactory(false); |
| 1370 | 1371 |
| 1371 ProxyService service( | 1372 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1372 config_service, | |
| 1373 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 1374 | 1373 |
| 1375 GURL url("http://www.google.com/"); | 1374 GURL url("http://www.google.com/"); |
| 1376 | 1375 |
| 1377 // Get the proxy information. | 1376 // Get the proxy information. |
| 1378 ProxyInfo info; | 1377 ProxyInfo info; |
| 1379 TestCompletionCallback callback1; | 1378 TestCompletionCallback callback1; |
| 1380 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1379 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 1381 NULL, NULL, BoundNetLog()); | 1380 NULL, NULL, BoundNetLog()); |
| 1382 EXPECT_EQ(ERR_IO_PENDING, rv); | 1381 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1383 | 1382 |
| 1384 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1383 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1385 resolver.pending_set_pac_script_request()->script_data()->url()); | 1384 factory->pending_requests()[0]->script_data()->url()); |
| 1386 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1385 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1387 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1386 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1388 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1387 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1389 | 1388 |
| 1390 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1389 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1391 "foopy1:8080;foopy2:9090"); | 1390 "foopy1:8080;foopy2:9090"); |
| 1392 resolver.pending_requests()[0]->CompleteNow(OK); | 1391 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1393 | 1392 |
| 1394 // The first item is valid. | 1393 // The first item is valid. |
| 1395 EXPECT_EQ(OK, callback1.WaitForResult()); | 1394 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1396 EXPECT_FALSE(info.is_direct()); | 1395 EXPECT_FALSE(info.is_direct()); |
| (...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1457 TEST_F(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { | 1456 TEST_F(ProxyServiceTest, ProxyFallback_BadConfigMandatory) { |
| 1458 // Test proxy failover when the configuration is bad. | 1457 // Test proxy failover when the configuration is bad. |
| 1459 | 1458 |
| 1460 ProxyConfig config( | 1459 ProxyConfig config( |
| 1461 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); | 1460 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac"))); |
| 1462 | 1461 |
| 1463 config.set_pac_mandatory(true); | 1462 config.set_pac_mandatory(true); |
| 1464 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 1463 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 1465 | 1464 |
| 1466 MockAsyncProxyResolver resolver; | 1465 MockAsyncProxyResolver resolver; |
| 1466 MockAsyncProxyResolverFactory* factory = |
| 1467 new MockAsyncProxyResolverFactory(false); |
| 1467 | 1468 |
| 1468 ProxyService service( | 1469 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1469 config_service, | |
| 1470 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 1471 | 1470 |
| 1472 GURL url("http://www.google.com/"); | 1471 GURL url("http://www.google.com/"); |
| 1473 | 1472 |
| 1474 // Get the proxy information. | 1473 // Get the proxy information. |
| 1475 ProxyInfo info; | 1474 ProxyInfo info; |
| 1476 TestCompletionCallback callback1; | 1475 TestCompletionCallback callback1; |
| 1477 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), | 1476 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback1.callback(), |
| 1478 NULL, NULL, BoundNetLog()); | 1477 NULL, NULL, BoundNetLog()); |
| 1479 EXPECT_EQ(ERR_IO_PENDING, rv); | 1478 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1480 | 1479 |
| 1481 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1480 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1482 resolver.pending_set_pac_script_request()->script_data()->url()); | 1481 factory->pending_requests()[0]->script_data()->url()); |
| 1483 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1482 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1484 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1483 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1485 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); | 1484 EXPECT_EQ(url, resolver.pending_requests()[0]->url()); |
| 1486 | 1485 |
| 1487 resolver.pending_requests()[0]->results()->UseNamedProxy( | 1486 resolver.pending_requests()[0]->results()->UseNamedProxy( |
| 1488 "foopy1:8080;foopy2:9090"); | 1487 "foopy1:8080;foopy2:9090"); |
| 1489 resolver.pending_requests()[0]->CompleteNow(OK); | 1488 resolver.pending_requests()[0]->CompleteNow(OK); |
| 1490 | 1489 |
| 1491 // The first item is valid. | 1490 // The first item is valid. |
| 1492 EXPECT_EQ(OK, callback1.WaitForResult()); | 1491 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 1493 EXPECT_FALSE(info.is_direct()); | 1492 EXPECT_FALSE(info.is_direct()); |
| (...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1741 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); | 1740 EXPECT_EQ("socks4://foopy2:1080", info.proxy_server().ToURI()); |
| 1742 } | 1741 } |
| 1743 } | 1742 } |
| 1744 | 1743 |
| 1745 // Test cancellation of an in-progress request. | 1744 // Test cancellation of an in-progress request. |
| 1746 TEST_F(ProxyServiceTest, CancelInProgressRequest) { | 1745 TEST_F(ProxyServiceTest, CancelInProgressRequest) { |
| 1747 MockProxyConfigService* config_service = | 1746 MockProxyConfigService* config_service = |
| 1748 new MockProxyConfigService("http://foopy/proxy.pac"); | 1747 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1749 | 1748 |
| 1750 MockAsyncProxyResolver resolver; | 1749 MockAsyncProxyResolver resolver; |
| 1750 MockAsyncProxyResolverFactory* factory = |
| 1751 new MockAsyncProxyResolverFactory(false); |
| 1751 | 1752 |
| 1752 ProxyService service( | 1753 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1753 config_service, | |
| 1754 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 1755 | 1754 |
| 1756 // Start 3 requests. | 1755 // Start 3 requests. |
| 1757 | 1756 |
| 1758 ProxyInfo info1; | 1757 ProxyInfo info1; |
| 1759 TestCompletionCallback callback1; | 1758 TestCompletionCallback callback1; |
| 1760 int rv = | 1759 int rv = |
| 1761 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 1760 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 1762 callback1.callback(), NULL, NULL, BoundNetLog()); | 1761 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 1763 EXPECT_EQ(ERR_IO_PENDING, rv); | 1762 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1764 | 1763 |
| 1765 // Nothing has been sent to the proxy resolver yet, since the proxy | |
| 1766 // resolver has not been configured yet. | |
| 1767 ASSERT_EQ(0u, resolver.pending_requests().size()); | |
| 1768 | |
| 1769 // Successfully initialize the PAC script. | 1764 // Successfully initialize the PAC script. |
| 1770 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 1765 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 1771 resolver.pending_set_pac_script_request()->script_data()->url()); | 1766 factory->pending_requests()[0]->script_data()->url()); |
| 1772 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1767 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1773 | 1768 |
| 1774 ASSERT_EQ(1u, resolver.pending_requests().size()); | 1769 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 1775 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 1770 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 1776 | 1771 |
| 1777 ProxyInfo info2; | 1772 ProxyInfo info2; |
| 1778 TestCompletionCallback callback2; | 1773 TestCompletionCallback callback2; |
| 1779 ProxyService::PacRequest* request2; | 1774 ProxyService::PacRequest* request2; |
| 1780 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 1775 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| 1781 callback2.callback(), &request2, NULL, | 1776 callback2.callback(), &request2, NULL, |
| 1782 BoundNetLog()); | 1777 BoundNetLog()); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1818 EXPECT_EQ(OK, callback3.WaitForResult()); | 1813 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 1819 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 1814 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
| 1820 } | 1815 } |
| 1821 | 1816 |
| 1822 // Test the initial PAC download for resolver that expects bytes. | 1817 // Test the initial PAC download for resolver that expects bytes. |
| 1823 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { | 1818 TEST_F(ProxyServiceTest, InitialPACScriptDownload) { |
| 1824 MockProxyConfigService* config_service = | 1819 MockProxyConfigService* config_service = |
| 1825 new MockProxyConfigService("http://foopy/proxy.pac"); | 1820 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1826 | 1821 |
| 1827 MockAsyncProxyResolverExpectsBytes resolver; | 1822 MockAsyncProxyResolverExpectsBytes resolver; |
| 1823 MockAsyncProxyResolverFactory* factory = |
| 1824 new MockAsyncProxyResolverFactory(true); |
| 1828 | 1825 |
| 1829 ProxyService service( | 1826 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1830 config_service, | |
| 1831 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 1832 | 1827 |
| 1833 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1828 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1834 service.SetProxyScriptFetchers(fetcher, | 1829 service.SetProxyScriptFetchers(fetcher, |
| 1835 new DoNothingDhcpProxyScriptFetcher()); | 1830 new DoNothingDhcpProxyScriptFetcher()); |
| 1836 | 1831 |
| 1837 // Start 3 requests. | 1832 // Start 3 requests. |
| 1838 | 1833 |
| 1839 ProxyInfo info1; | 1834 ProxyInfo info1; |
| 1840 TestCompletionCallback callback1; | 1835 TestCompletionCallback callback1; |
| 1841 ProxyService::PacRequest* request1; | 1836 ProxyService::PacRequest* request1; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1857 EXPECT_EQ(ERR_IO_PENDING, rv); | 1852 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1858 | 1853 |
| 1859 ProxyInfo info3; | 1854 ProxyInfo info3; |
| 1860 TestCompletionCallback callback3; | 1855 TestCompletionCallback callback3; |
| 1861 ProxyService::PacRequest* request3; | 1856 ProxyService::PacRequest* request3; |
| 1862 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3, | 1857 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3, |
| 1863 callback3.callback(), &request3, NULL, | 1858 callback3.callback(), &request3, NULL, |
| 1864 BoundNetLog()); | 1859 BoundNetLog()); |
| 1865 EXPECT_EQ(ERR_IO_PENDING, rv); | 1860 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 1866 | 1861 |
| 1867 // Nothing has been sent to the resolver yet. | 1862 // Nothing has been sent to the factory yet. |
| 1868 EXPECT_TRUE(resolver.pending_requests().empty()); | 1863 EXPECT_TRUE(factory->pending_requests().empty()); |
| 1869 | 1864 |
| 1870 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1865 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
| 1871 service.GetLoadState(request1)); | 1866 service.GetLoadState(request1)); |
| 1872 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1867 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
| 1873 service.GetLoadState(request2)); | 1868 service.GetLoadState(request2)); |
| 1874 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, | 1869 EXPECT_EQ(LOAD_STATE_DOWNLOADING_PROXY_SCRIPT, |
| 1875 service.GetLoadState(request3)); | 1870 service.GetLoadState(request3)); |
| 1876 | 1871 |
| 1877 // At this point the ProxyService should be waiting for the | 1872 // At this point the ProxyService should be waiting for the |
| 1878 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1873 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1879 // PAC script download completion. | 1874 // PAC script download completion. |
| 1880 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 1875 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1881 | 1876 |
| 1882 // Now that the PAC script is downloaded, it will have been sent to the proxy | 1877 // Now that the PAC script is downloaded, it will have been sent to the proxy |
| 1883 // resolver. | 1878 // resolver. |
| 1884 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 1879 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1885 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 1880 factory->pending_requests()[0]->script_data()->utf16()); |
| 1886 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1881 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1887 | 1882 |
| 1888 ASSERT_EQ(3u, resolver.pending_requests().size()); | 1883 ASSERT_EQ(3u, resolver.pending_requests().size()); |
| 1889 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 1884 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 1890 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); | 1885 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); |
| 1891 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[2]->url()); | 1886 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[2]->url()); |
| 1892 | 1887 |
| 1893 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); | 1888 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request1)); |
| 1894 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); | 1889 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request2)); |
| 1895 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); | 1890 EXPECT_EQ(LOAD_STATE_RESOLVING_PROXY_FOR_URL, service.GetLoadState(request3)); |
| 1896 | 1891 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 1925 EXPECT_FALSE(info3.proxy_resolve_end_time().is_null()); | 1920 EXPECT_FALSE(info3.proxy_resolve_end_time().is_null()); |
| 1926 EXPECT_LE(info3.proxy_resolve_start_time(), info3.proxy_resolve_end_time()); | 1921 EXPECT_LE(info3.proxy_resolve_start_time(), info3.proxy_resolve_end_time()); |
| 1927 } | 1922 } |
| 1928 | 1923 |
| 1929 // Test changing the ProxyScriptFetcher while PAC download is in progress. | 1924 // Test changing the ProxyScriptFetcher while PAC download is in progress. |
| 1930 TEST_F(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { | 1925 TEST_F(ProxyServiceTest, ChangeScriptFetcherWhilePACDownloadInProgress) { |
| 1931 MockProxyConfigService* config_service = | 1926 MockProxyConfigService* config_service = |
| 1932 new MockProxyConfigService("http://foopy/proxy.pac"); | 1927 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1933 | 1928 |
| 1934 MockAsyncProxyResolverExpectsBytes resolver; | 1929 MockAsyncProxyResolverExpectsBytes resolver; |
| 1930 MockAsyncProxyResolverFactory* factory = |
| 1931 new MockAsyncProxyResolverFactory(true); |
| 1935 | 1932 |
| 1936 ProxyService service( | 1933 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1937 config_service, | |
| 1938 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 1939 | 1934 |
| 1940 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1935 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 1941 service.SetProxyScriptFetchers(fetcher, | 1936 service.SetProxyScriptFetchers(fetcher, |
| 1942 new DoNothingDhcpProxyScriptFetcher()); | 1937 new DoNothingDhcpProxyScriptFetcher()); |
| 1943 | 1938 |
| 1944 // Start 2 requests. | 1939 // Start 2 requests. |
| 1945 | 1940 |
| 1946 ProxyInfo info1; | 1941 ProxyInfo info1; |
| 1947 TestCompletionCallback callback1; | 1942 TestCompletionCallback callback1; |
| 1948 int rv = | 1943 int rv = |
| (...skipping 15 matching lines...) Expand all Loading... |
| 1964 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 1959 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 1965 // PAC script download completion. | 1960 // PAC script download completion. |
| 1966 | 1961 |
| 1967 // We now change out the ProxyService's script fetcher. We should restart | 1962 // We now change out the ProxyService's script fetcher. We should restart |
| 1968 // the initialization with the new fetcher. | 1963 // the initialization with the new fetcher. |
| 1969 | 1964 |
| 1970 fetcher = new MockProxyScriptFetcher; | 1965 fetcher = new MockProxyScriptFetcher; |
| 1971 service.SetProxyScriptFetchers(fetcher, | 1966 service.SetProxyScriptFetchers(fetcher, |
| 1972 new DoNothingDhcpProxyScriptFetcher()); | 1967 new DoNothingDhcpProxyScriptFetcher()); |
| 1973 | 1968 |
| 1974 // Nothing has been sent to the resolver yet. | 1969 // Nothing has been sent to the factory yet. |
| 1975 EXPECT_TRUE(resolver.pending_requests().empty()); | 1970 EXPECT_TRUE(factory->pending_requests().empty()); |
| 1976 | 1971 |
| 1977 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 1972 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 1978 | 1973 |
| 1979 // Now that the PAC script is downloaded, it will have been sent to the proxy | 1974 // Now that the PAC script is downloaded, it will have been sent to the proxy |
| 1980 // resolver. | 1975 // resolver. |
| 1981 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 1976 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 1982 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 1977 factory->pending_requests()[0]->script_data()->utf16()); |
| 1983 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 1978 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 1984 | 1979 |
| 1985 ASSERT_EQ(2u, resolver.pending_requests().size()); | 1980 ASSERT_EQ(2u, resolver.pending_requests().size()); |
| 1986 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 1981 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 1987 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); | 1982 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); |
| 1988 } | 1983 } |
| 1989 | 1984 |
| 1990 // Test cancellation of a request, while the PAC script is being fetched. | 1985 // Test cancellation of a request, while the PAC script is being fetched. |
| 1991 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { | 1986 TEST_F(ProxyServiceTest, CancelWhilePACFetching) { |
| 1992 MockProxyConfigService* config_service = | 1987 MockProxyConfigService* config_service = |
| 1993 new MockProxyConfigService("http://foopy/proxy.pac"); | 1988 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 1994 | 1989 |
| 1995 MockAsyncProxyResolverExpectsBytes resolver; | 1990 MockAsyncProxyResolverExpectsBytes resolver; |
| 1991 MockAsyncProxyResolverFactory* factory = |
| 1992 new MockAsyncProxyResolverFactory(true); |
| 1996 | 1993 |
| 1997 ProxyService service( | 1994 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 1998 config_service, | |
| 1999 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 2000 | 1995 |
| 2001 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 1996 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2002 service.SetProxyScriptFetchers(fetcher, | 1997 service.SetProxyScriptFetchers(fetcher, |
| 2003 new DoNothingDhcpProxyScriptFetcher()); | 1998 new DoNothingDhcpProxyScriptFetcher()); |
| 2004 | 1999 |
| 2005 // Start 3 requests. | 2000 // Start 3 requests. |
| 2006 ProxyInfo info1; | 2001 ProxyInfo info1; |
| 2007 TestCompletionCallback callback1; | 2002 TestCompletionCallback callback1; |
| 2008 ProxyService::PacRequest* request1; | 2003 ProxyService::PacRequest* request1; |
| 2009 BoundTestNetLog log1; | 2004 BoundTestNetLog log1; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 2023 callback2.callback(), &request2, NULL, | 2018 callback2.callback(), &request2, NULL, |
| 2024 BoundNetLog()); | 2019 BoundNetLog()); |
| 2025 EXPECT_EQ(ERR_IO_PENDING, rv); | 2020 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2026 | 2021 |
| 2027 ProxyInfo info3; | 2022 ProxyInfo info3; |
| 2028 TestCompletionCallback callback3; | 2023 TestCompletionCallback callback3; |
| 2029 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3, | 2024 rv = service.ResolveProxy(GURL("http://request3"), LOAD_NORMAL, &info3, |
| 2030 callback3.callback(), NULL, NULL, BoundNetLog()); | 2025 callback3.callback(), NULL, NULL, BoundNetLog()); |
| 2031 EXPECT_EQ(ERR_IO_PENDING, rv); | 2026 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2032 | 2027 |
| 2033 // Nothing has been sent to the resolver yet. | 2028 // Nothing has been sent to the factory yet. |
| 2034 EXPECT_TRUE(resolver.pending_requests().empty()); | 2029 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2035 | 2030 |
| 2036 // Cancel the first 2 requests. | 2031 // Cancel the first 2 requests. |
| 2037 service.CancelPacRequest(request1); | 2032 service.CancelPacRequest(request1); |
| 2038 service.CancelPacRequest(request2); | 2033 service.CancelPacRequest(request2); |
| 2039 | 2034 |
| 2040 // At this point the ProxyService should be waiting for the | 2035 // At this point the ProxyService should be waiting for the |
| 2041 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2036 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 2042 // PAC script download completion. | 2037 // PAC script download completion. |
| 2043 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2038 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2044 | 2039 |
| 2045 // Now that the PAC script is downloaded, it will have been sent to the | 2040 // Now that the PAC script is downloaded, it will have been sent to the |
| 2046 // proxy resolver. | 2041 // proxy resolver. |
| 2047 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2042 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2048 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2043 factory->pending_requests()[0]->script_data()->utf16()); |
| 2049 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2044 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2050 | 2045 |
| 2051 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2046 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2052 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url()); | 2047 EXPECT_EQ(GURL("http://request3"), resolver.pending_requests()[0]->url()); |
| 2053 | 2048 |
| 2054 // Complete all the requests. | 2049 // Complete all the requests. |
| 2055 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80"); | 2050 resolver.pending_requests()[0]->results()->UseNamedProxy("request3:80"); |
| 2056 resolver.pending_requests()[0]->CompleteNow(OK); | 2051 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2057 | 2052 |
| 2058 EXPECT_EQ(OK, callback3.WaitForResult()); | 2053 EXPECT_EQ(OK, callback3.WaitForResult()); |
| 2059 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); | 2054 EXPECT_EQ("request3:80", info3.proxy_server().ToURI()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 2082 | 2077 |
| 2083 // Test that if auto-detect fails, we fall-back to the custom pac. | 2078 // Test that if auto-detect fails, we fall-back to the custom pac. |
| 2084 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { | 2079 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac) { |
| 2085 ProxyConfig config; | 2080 ProxyConfig config; |
| 2086 config.set_auto_detect(true); | 2081 config.set_auto_detect(true); |
| 2087 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2082 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 2088 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 2083 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
| 2089 | 2084 |
| 2090 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2085 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 2091 MockAsyncProxyResolverExpectsBytes resolver; | 2086 MockAsyncProxyResolverExpectsBytes resolver; |
| 2092 ProxyService service( | 2087 MockAsyncProxyResolverFactory* factory = |
| 2093 config_service, | 2088 new MockAsyncProxyResolverFactory(true); |
| 2094 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | 2089 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2095 | 2090 |
| 2096 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2091 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2097 service.SetProxyScriptFetchers(fetcher, | 2092 service.SetProxyScriptFetchers(fetcher, |
| 2098 new DoNothingDhcpProxyScriptFetcher()); | 2093 new DoNothingDhcpProxyScriptFetcher()); |
| 2099 | 2094 |
| 2100 // Start 2 requests. | 2095 // Start 2 requests. |
| 2101 | 2096 |
| 2102 ProxyInfo info1; | 2097 ProxyInfo info1; |
| 2103 TestCompletionCallback callback1; | 2098 TestCompletionCallback callback1; |
| 2104 int rv = | 2099 int rv = |
| 2105 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2100 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 2106 callback1.callback(), NULL, NULL, BoundNetLog()); | 2101 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2107 EXPECT_EQ(ERR_IO_PENDING, rv); | 2102 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2108 | 2103 |
| 2109 ProxyInfo info2; | 2104 ProxyInfo info2; |
| 2110 TestCompletionCallback callback2; | 2105 TestCompletionCallback callback2; |
| 2111 ProxyService::PacRequest* request2; | 2106 ProxyService::PacRequest* request2; |
| 2112 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2107 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| 2113 callback2.callback(), &request2, NULL, | 2108 callback2.callback(), &request2, NULL, |
| 2114 BoundNetLog()); | 2109 BoundNetLog()); |
| 2115 EXPECT_EQ(ERR_IO_PENDING, rv); | 2110 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2116 | 2111 |
| 2117 // Check that nothing has been sent to the proxy resolver yet. | 2112 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2118 ASSERT_EQ(0u, resolver.pending_requests().size()); | 2113 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2119 | 2114 |
| 2120 // It should be trying to auto-detect first -- FAIL the autodetect during | 2115 // It should be trying to auto-detect first -- FAIL the autodetect during |
| 2121 // the script download. | 2116 // the script download. |
| 2122 EXPECT_TRUE(fetcher->has_pending_request()); | 2117 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2123 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2118 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 2124 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2119 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| 2125 | 2120 |
| 2126 // Next it should be trying the custom PAC url. | 2121 // Next it should be trying the custom PAC url. |
| 2127 EXPECT_TRUE(fetcher->has_pending_request()); | 2122 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2128 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2123 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2129 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2124 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2130 | 2125 |
| 2131 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2126 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2132 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2127 factory->pending_requests()[0]->script_data()->utf16()); |
| 2133 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2128 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2134 | 2129 |
| 2135 // Now finally, the pending requests should have been sent to the resolver | 2130 // Now finally, the pending requests should have been sent to the resolver |
| 2136 // (which was initialized with custom PAC script). | 2131 // (which was initialized with custom PAC script). |
| 2137 | 2132 |
| 2138 ASSERT_EQ(2u, resolver.pending_requests().size()); | 2133 ASSERT_EQ(2u, resolver.pending_requests().size()); |
| 2139 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2134 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 2140 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); | 2135 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); |
| 2141 | 2136 |
| 2142 // Complete the pending requests. | 2137 // Complete the pending requests. |
| 2143 resolver.pending_requests()[1]->results()->UseNamedProxy("request2:80"); | 2138 resolver.pending_requests()[1]->results()->UseNamedProxy("request2:80"); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2162 // This is the same test as FallbackFromAutodetectToCustomPac, except | 2157 // This is the same test as FallbackFromAutodetectToCustomPac, except |
| 2163 // the auto-detect script fails parsing rather than downloading. | 2158 // the auto-detect script fails parsing rather than downloading. |
| 2164 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { | 2159 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomPac2) { |
| 2165 ProxyConfig config; | 2160 ProxyConfig config; |
| 2166 config.set_auto_detect(true); | 2161 config.set_auto_detect(true); |
| 2167 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2162 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 2168 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. | 2163 config.proxy_rules().ParseFromString("http=foopy:80"); // Won't be used. |
| 2169 | 2164 |
| 2170 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2165 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 2171 MockAsyncProxyResolverExpectsBytes resolver; | 2166 MockAsyncProxyResolverExpectsBytes resolver; |
| 2172 ProxyService service( | 2167 MockAsyncProxyResolverFactory* factory = |
| 2173 config_service, | 2168 new MockAsyncProxyResolverFactory(true); |
| 2174 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | 2169 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2175 | 2170 |
| 2176 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2171 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2177 service.SetProxyScriptFetchers(fetcher, | 2172 service.SetProxyScriptFetchers(fetcher, |
| 2178 new DoNothingDhcpProxyScriptFetcher()); | 2173 new DoNothingDhcpProxyScriptFetcher()); |
| 2179 | 2174 |
| 2180 // Start 2 requests. | 2175 // Start 2 requests. |
| 2181 | 2176 |
| 2182 ProxyInfo info1; | 2177 ProxyInfo info1; |
| 2183 TestCompletionCallback callback1; | 2178 TestCompletionCallback callback1; |
| 2184 int rv = | 2179 int rv = |
| 2185 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2180 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 2186 callback1.callback(), NULL, NULL, BoundNetLog()); | 2181 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2187 EXPECT_EQ(ERR_IO_PENDING, rv); | 2182 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2188 | 2183 |
| 2189 ProxyInfo info2; | 2184 ProxyInfo info2; |
| 2190 TestCompletionCallback callback2; | 2185 TestCompletionCallback callback2; |
| 2191 ProxyService::PacRequest* request2; | 2186 ProxyService::PacRequest* request2; |
| 2192 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2187 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| 2193 callback2.callback(), &request2, NULL, | 2188 callback2.callback(), &request2, NULL, |
| 2194 BoundNetLog()); | 2189 BoundNetLog()); |
| 2195 EXPECT_EQ(ERR_IO_PENDING, rv); | 2190 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2196 | 2191 |
| 2197 // Check that nothing has been sent to the proxy resolver yet. | 2192 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2198 ASSERT_EQ(0u, resolver.pending_requests().size()); | 2193 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2199 | 2194 |
| 2200 // It should be trying to auto-detect first -- succeed the download. | 2195 // It should be trying to auto-detect first -- succeed the download. |
| 2201 EXPECT_TRUE(fetcher->has_pending_request()); | 2196 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2202 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2197 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 2203 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); | 2198 fetcher->NotifyFetchCompletion(OK, "invalid-script-contents"); |
| 2204 | 2199 |
| 2205 // The script contents passed failed basic verification step (since didn't | 2200 // The script contents passed failed basic verification step (since didn't |
| 2206 // contain token FindProxyForURL), so it was never passed to the resolver. | 2201 // contain token FindProxyForURL), so it was never passed to the resolver. |
| 2207 | 2202 |
| 2208 // Next it should be trying the custom PAC url. | 2203 // Next it should be trying the custom PAC url. |
| 2209 EXPECT_TRUE(fetcher->has_pending_request()); | 2204 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2210 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2205 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2211 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2206 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2212 | 2207 |
| 2213 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2208 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2214 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2209 factory->pending_requests()[0]->script_data()->utf16()); |
| 2215 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2210 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2216 | 2211 |
| 2217 // Now finally, the pending requests should have been sent to the resolver | 2212 // Now finally, the pending requests should have been sent to the resolver |
| 2218 // (which was initialized with custom PAC script). | 2213 // (which was initialized with custom PAC script). |
| 2219 | 2214 |
| 2220 ASSERT_EQ(2u, resolver.pending_requests().size()); | 2215 ASSERT_EQ(2u, resolver.pending_requests().size()); |
| 2221 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2216 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 2222 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); | 2217 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[1]->url()); |
| 2223 | 2218 |
| 2224 // Complete the pending requests. | 2219 // Complete the pending requests. |
| 2225 resolver.pending_requests()[1]->results()->UseNamedProxy("request2:80"); | 2220 resolver.pending_requests()[1]->results()->UseNamedProxy("request2:80"); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2237 | 2232 |
| 2238 // Test that if all of auto-detect, a custom PAC script, and manual settings | 2233 // Test that if all of auto-detect, a custom PAC script, and manual settings |
| 2239 // are given, then we will try them in that order. | 2234 // are given, then we will try them in that order. |
| 2240 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { | 2235 TEST_F(ProxyServiceTest, FallbackFromAutodetectToCustomToManual) { |
| 2241 ProxyConfig config; | 2236 ProxyConfig config; |
| 2242 config.set_auto_detect(true); | 2237 config.set_auto_detect(true); |
| 2243 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2238 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 2244 config.proxy_rules().ParseFromString("http=foopy:80"); | 2239 config.proxy_rules().ParseFromString("http=foopy:80"); |
| 2245 | 2240 |
| 2246 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2241 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 2247 MockAsyncProxyResolverExpectsBytes resolver; | 2242 MockAsyncProxyResolverFactory* factory = |
| 2248 ProxyService service( | 2243 new MockAsyncProxyResolverFactory(true); |
| 2249 config_service, | 2244 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2250 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 2251 | 2245 |
| 2252 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2246 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2253 service.SetProxyScriptFetchers(fetcher, | 2247 service.SetProxyScriptFetchers(fetcher, |
| 2254 new DoNothingDhcpProxyScriptFetcher()); | 2248 new DoNothingDhcpProxyScriptFetcher()); |
| 2255 | 2249 |
| 2256 // Start 2 requests. | 2250 // Start 2 requests. |
| 2257 | 2251 |
| 2258 ProxyInfo info1; | 2252 ProxyInfo info1; |
| 2259 TestCompletionCallback callback1; | 2253 TestCompletionCallback callback1; |
| 2260 int rv = | 2254 int rv = |
| 2261 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2255 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 2262 callback1.callback(), NULL, NULL, BoundNetLog()); | 2256 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2263 EXPECT_EQ(ERR_IO_PENDING, rv); | 2257 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2264 | 2258 |
| 2265 ProxyInfo info2; | 2259 ProxyInfo info2; |
| 2266 TestCompletionCallback callback2; | 2260 TestCompletionCallback callback2; |
| 2267 ProxyService::PacRequest* request2; | 2261 ProxyService::PacRequest* request2; |
| 2268 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2262 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| 2269 callback2.callback(), &request2, NULL, | 2263 callback2.callback(), &request2, NULL, |
| 2270 BoundNetLog()); | 2264 BoundNetLog()); |
| 2271 EXPECT_EQ(ERR_IO_PENDING, rv); | 2265 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2272 | 2266 |
| 2273 // Check that nothing has been sent to the proxy resolver yet. | 2267 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2274 ASSERT_EQ(0u, resolver.pending_requests().size()); | 2268 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2275 | 2269 |
| 2276 // It should be trying to auto-detect first -- fail the download. | 2270 // It should be trying to auto-detect first -- fail the download. |
| 2277 EXPECT_TRUE(fetcher->has_pending_request()); | 2271 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2278 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2272 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 2279 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2273 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| 2280 | 2274 |
| 2281 // Next it should be trying the custom PAC url -- fail the download. | 2275 // Next it should be trying the custom PAC url -- fail the download. |
| 2282 EXPECT_TRUE(fetcher->has_pending_request()); | 2276 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2283 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2277 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2284 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2278 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| 2285 | 2279 |
| 2286 // Since we never managed to initialize a resolver, nothing should have been | 2280 // Since we never managed to initialize a resolver, nothing should have been |
| 2287 // sent to it. | 2281 // sent to it. |
| 2288 ASSERT_EQ(0u, resolver.pending_requests().size()); | 2282 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2289 | 2283 |
| 2290 // Verify that requests ran as expected -- they should have fallen back to | 2284 // Verify that requests ran as expected -- they should have fallen back to |
| 2291 // the manual proxy configuration for HTTP urls. | 2285 // the manual proxy configuration for HTTP urls. |
| 2292 EXPECT_EQ(OK, callback1.WaitForResult()); | 2286 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2293 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); | 2287 EXPECT_EQ("foopy:80", info1.proxy_server().ToURI()); |
| 2294 | 2288 |
| 2295 EXPECT_EQ(OK, callback2.WaitForResult()); | 2289 EXPECT_EQ(OK, callback2.WaitForResult()); |
| 2296 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); | 2290 EXPECT_EQ("foopy:80", info2.proxy_server().ToURI()); |
| 2297 } | 2291 } |
| 2298 | 2292 |
| 2299 // Test that the bypass rules are NOT applied when using autodetect. | 2293 // Test that the bypass rules are NOT applied when using autodetect. |
| 2300 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { | 2294 TEST_F(ProxyServiceTest, BypassDoesntApplyToPac) { |
| 2301 ProxyConfig config; | 2295 ProxyConfig config; |
| 2302 config.set_auto_detect(true); | 2296 config.set_auto_detect(true); |
| 2303 config.set_pac_url(GURL("http://foopy/proxy.pac")); | 2297 config.set_pac_url(GURL("http://foopy/proxy.pac")); |
| 2304 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. | 2298 config.proxy_rules().ParseFromString("http=foopy:80"); // Not used. |
| 2305 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); | 2299 config.proxy_rules().bypass_rules.ParseFromString("www.google.com"); |
| 2306 | 2300 |
| 2307 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2301 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 2308 MockAsyncProxyResolverExpectsBytes resolver; | 2302 MockAsyncProxyResolverExpectsBytes resolver; |
| 2309 ProxyService service( | 2303 MockAsyncProxyResolverFactory* factory = |
| 2310 config_service, | 2304 new MockAsyncProxyResolverFactory(true); |
| 2311 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | 2305 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2312 | 2306 |
| 2313 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2307 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2314 service.SetProxyScriptFetchers(fetcher, | 2308 service.SetProxyScriptFetchers(fetcher, |
| 2315 new DoNothingDhcpProxyScriptFetcher()); | 2309 new DoNothingDhcpProxyScriptFetcher()); |
| 2316 | 2310 |
| 2317 // Start 1 requests. | 2311 // Start 1 requests. |
| 2318 | 2312 |
| 2319 ProxyInfo info1; | 2313 ProxyInfo info1; |
| 2320 TestCompletionCallback callback1; | 2314 TestCompletionCallback callback1; |
| 2321 int rv = | 2315 int rv = |
| 2322 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, | 2316 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, |
| 2323 callback1.callback(), NULL, NULL, BoundNetLog()); | 2317 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2324 EXPECT_EQ(ERR_IO_PENDING, rv); | 2318 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2325 | 2319 |
| 2326 // Check that nothing has been sent to the proxy resolver yet. | 2320 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2327 ASSERT_EQ(0u, resolver.pending_requests().size()); | 2321 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2328 | 2322 |
| 2329 // It should be trying to auto-detect first -- succeed the download. | 2323 // It should be trying to auto-detect first -- succeed the download. |
| 2330 EXPECT_TRUE(fetcher->has_pending_request()); | 2324 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2331 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); | 2325 EXPECT_EQ(GURL("http://wpad/wpad.dat"), fetcher->pending_request_url()); |
| 2332 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2326 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2333 | 2327 |
| 2334 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2328 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2335 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2329 factory->pending_requests()[0]->script_data()->utf16()); |
| 2336 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2330 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2337 | 2331 |
| 2338 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2332 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2339 EXPECT_EQ(GURL("http://www.google.com"), | 2333 EXPECT_EQ(GURL("http://www.google.com"), |
| 2340 resolver.pending_requests()[0]->url()); | 2334 resolver.pending_requests()[0]->url()); |
| 2341 | 2335 |
| 2342 // Complete the pending request. | 2336 // Complete the pending request. |
| 2343 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2337 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 2344 resolver.pending_requests()[0]->CompleteNow(OK); | 2338 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2345 | 2339 |
| 2346 // Verify that request ran as expected. | 2340 // Verify that request ran as expected. |
| (...skipping 21 matching lines...) Expand all Loading... |
| 2368 | 2362 |
| 2369 // Delete the ProxyService while InitProxyResolver has an outstanding | 2363 // Delete the ProxyService while InitProxyResolver has an outstanding |
| 2370 // request to the script fetcher. When run under valgrind, should not | 2364 // request to the script fetcher. When run under valgrind, should not |
| 2371 // have any memory errors (used to be that the ProxyScriptFetcher was | 2365 // have any memory errors (used to be that the ProxyScriptFetcher was |
| 2372 // being deleted prior to the InitProxyResolver). | 2366 // being deleted prior to the InitProxyResolver). |
| 2373 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { | 2367 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingFetch) { |
| 2374 ProxyConfig config = | 2368 ProxyConfig config = |
| 2375 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); | 2369 ProxyConfig::CreateFromCustomPacURL(GURL("http://foopy/proxy.pac")); |
| 2376 | 2370 |
| 2377 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2371 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 2378 MockAsyncProxyResolverExpectsBytes resolver; | 2372 MockAsyncProxyResolverFactory* factory = |
| 2379 ProxyService service( | 2373 new MockAsyncProxyResolverFactory(true); |
| 2380 config_service, | 2374 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2381 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 2382 | 2375 |
| 2383 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2376 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2384 service.SetProxyScriptFetchers(fetcher, | 2377 service.SetProxyScriptFetchers(fetcher, |
| 2385 new DoNothingDhcpProxyScriptFetcher()); | 2378 new DoNothingDhcpProxyScriptFetcher()); |
| 2386 | 2379 |
| 2387 // Start 1 request. | 2380 // Start 1 request. |
| 2388 | 2381 |
| 2389 ProxyInfo info1; | 2382 ProxyInfo info1; |
| 2390 TestCompletionCallback callback1; | 2383 TestCompletionCallback callback1; |
| 2391 int rv = | 2384 int rv = |
| 2392 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, | 2385 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, |
| 2393 callback1.callback(), NULL, NULL, BoundNetLog()); | 2386 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2394 EXPECT_EQ(ERR_IO_PENDING, rv); | 2387 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2395 | 2388 |
| 2396 // Check that nothing has been sent to the proxy resolver yet. | 2389 // Check that nothing has been sent to the proxy resolver factory yet. |
| 2397 ASSERT_EQ(0u, resolver.pending_requests().size()); | 2390 ASSERT_EQ(0u, factory->pending_requests().size()); |
| 2398 | 2391 |
| 2399 // InitProxyResolver should have issued a request to the ProxyScriptFetcher | 2392 // InitProxyResolver should have issued a request to the ProxyScriptFetcher |
| 2400 // and be waiting on that to complete. | 2393 // and be waiting on that to complete. |
| 2401 EXPECT_TRUE(fetcher->has_pending_request()); | 2394 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2402 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2395 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2403 } | 2396 } |
| 2404 | 2397 |
| 2405 // Delete the ProxyService while InitProxyResolver has an outstanding | 2398 // Delete the ProxyService while InitProxyResolver has an outstanding |
| 2406 // request to the proxy resolver. When run under valgrind, should not | 2399 // request to the proxy resolver. When run under valgrind, should not |
| 2407 // have any memory errors (used to be that the ProxyResolver was | 2400 // have any memory errors (used to be that the ProxyResolver was |
| 2408 // being deleted prior to the InitProxyResolver). | 2401 // being deleted prior to the InitProxyResolver). |
| 2409 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { | 2402 TEST_F(ProxyServiceTest, DeleteWhileInitProxyResolverHasOutstandingSet) { |
| 2410 MockProxyConfigService* config_service = | 2403 MockProxyConfigService* config_service = |
| 2411 new MockProxyConfigService("http://foopy/proxy.pac"); | 2404 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2412 | 2405 |
| 2413 MockAsyncProxyResolver resolver; | 2406 MockAsyncProxyResolverFactory* factory = |
| 2407 new MockAsyncProxyResolverFactory(false); |
| 2414 | 2408 |
| 2415 ProxyService service( | 2409 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2416 config_service, | |
| 2417 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 2418 | 2410 |
| 2419 GURL url("http://www.google.com/"); | 2411 GURL url("http://www.google.com/"); |
| 2420 | 2412 |
| 2421 ProxyInfo info; | 2413 ProxyInfo info; |
| 2422 TestCompletionCallback callback; | 2414 TestCompletionCallback callback; |
| 2423 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), | 2415 int rv = service.ResolveProxy(url, LOAD_NORMAL, &info, callback.callback(), |
| 2424 NULL, NULL, BoundNetLog()); | 2416 NULL, NULL, BoundNetLog()); |
| 2425 EXPECT_EQ(ERR_IO_PENDING, rv); | 2417 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2426 | 2418 |
| 2427 EXPECT_EQ(GURL("http://foopy/proxy.pac"), | 2419 EXPECT_EQ(GURL("http://foopy/proxy.pac"), |
| 2428 resolver.pending_set_pac_script_request()->script_data()->url()); | 2420 factory->pending_requests()[0]->script_data()->url()); |
| 2429 } | 2421 } |
| 2430 | 2422 |
| 2431 TEST_F(ProxyServiceTest, ResetProxyConfigService) { | 2423 TEST_F(ProxyServiceTest, ResetProxyConfigService) { |
| 2432 ProxyConfig config1; | 2424 ProxyConfig config1; |
| 2433 config1.proxy_rules().ParseFromString("foopy1:8080"); | 2425 config1.proxy_rules().ParseFromString("foopy1:8080"); |
| 2434 config1.set_auto_detect(false); | 2426 config1.set_auto_detect(false); |
| 2435 ProxyService service(new MockProxyConfigService(config1), nullptr, NULL); | 2427 ProxyService service(new MockProxyConfigService(config1), nullptr, NULL); |
| 2436 | 2428 |
| 2437 ProxyInfo info; | 2429 ProxyInfo info; |
| 2438 TestCompletionCallback callback1; | 2430 TestCompletionCallback callback1; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 2453 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); | 2445 EXPECT_EQ("foopy2:8080", info.proxy_server().ToURI()); |
| 2454 } | 2446 } |
| 2455 | 2447 |
| 2456 // Test that when going from a configuration that required PAC to one | 2448 // Test that when going from a configuration that required PAC to one |
| 2457 // that does NOT, we unset the variable |should_use_proxy_resolver_|. | 2449 // that does NOT, we unset the variable |should_use_proxy_resolver_|. |
| 2458 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { | 2450 TEST_F(ProxyServiceTest, UpdateConfigFromPACToDirect) { |
| 2459 ProxyConfig config = ProxyConfig::CreateAutoDetect(); | 2451 ProxyConfig config = ProxyConfig::CreateAutoDetect(); |
| 2460 | 2452 |
| 2461 MockProxyConfigService* config_service = new MockProxyConfigService(config); | 2453 MockProxyConfigService* config_service = new MockProxyConfigService(config); |
| 2462 MockAsyncProxyResolver resolver; | 2454 MockAsyncProxyResolver resolver; |
| 2463 ProxyService service( | 2455 MockAsyncProxyResolverFactory* factory = |
| 2464 config_service, | 2456 new MockAsyncProxyResolverFactory(false); |
| 2465 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | 2457 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2466 | 2458 |
| 2467 // Start 1 request. | 2459 // Start 1 request. |
| 2468 | 2460 |
| 2469 ProxyInfo info1; | 2461 ProxyInfo info1; |
| 2470 TestCompletionCallback callback1; | 2462 TestCompletionCallback callback1; |
| 2471 int rv = | 2463 int rv = |
| 2472 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, | 2464 service.ResolveProxy(GURL("http://www.google.com"), LOAD_NORMAL, &info1, |
| 2473 callback1.callback(), NULL, NULL, BoundNetLog()); | 2465 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2474 EXPECT_EQ(ERR_IO_PENDING, rv); | 2466 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2475 | 2467 |
| 2476 // Check that nothing has been sent to the proxy resolver yet. | |
| 2477 ASSERT_EQ(0u, resolver.pending_requests().size()); | |
| 2478 | |
| 2479 // Successfully set the autodetect script. | 2468 // Successfully set the autodetect script. |
| 2480 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, | 2469 EXPECT_EQ(ProxyResolverScriptData::TYPE_AUTO_DETECT, |
| 2481 resolver.pending_set_pac_script_request()->script_data()->type()); | 2470 factory->pending_requests()[0]->script_data()->type()); |
| 2482 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2471 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2483 | 2472 |
| 2484 // Complete the pending request. | 2473 // Complete the pending request. |
| 2485 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2474 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2486 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2475 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 2487 resolver.pending_requests()[0]->CompleteNow(OK); | 2476 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2488 | 2477 |
| 2489 // Verify that request ran as expected. | 2478 // Verify that request ran as expected. |
| 2490 EXPECT_EQ(OK, callback1.WaitForResult()); | 2479 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2491 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2480 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 2492 | 2481 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2505 EXPECT_EQ(OK, rv); | 2494 EXPECT_EQ(OK, rv); |
| 2506 | 2495 |
| 2507 EXPECT_TRUE(info2.is_direct()); | 2496 EXPECT_TRUE(info2.is_direct()); |
| 2508 } | 2497 } |
| 2509 | 2498 |
| 2510 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { | 2499 TEST_F(ProxyServiceTest, NetworkChangeTriggersPacRefetch) { |
| 2511 MockProxyConfigService* config_service = | 2500 MockProxyConfigService* config_service = |
| 2512 new MockProxyConfigService("http://foopy/proxy.pac"); | 2501 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2513 | 2502 |
| 2514 MockAsyncProxyResolverExpectsBytes resolver; | 2503 MockAsyncProxyResolverExpectsBytes resolver; |
| 2504 MockAsyncProxyResolverFactory* factory = |
| 2505 new MockAsyncProxyResolverFactory(true); |
| 2515 | 2506 |
| 2516 TestNetLog log; | 2507 TestNetLog log; |
| 2517 | 2508 |
| 2518 ProxyService service( | 2509 ProxyService service(config_service, make_scoped_ptr(factory), &log); |
| 2519 config_service, | |
| 2520 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), &log); | |
| 2521 | 2510 |
| 2522 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2511 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2523 service.SetProxyScriptFetchers(fetcher, | 2512 service.SetProxyScriptFetchers(fetcher, |
| 2524 new DoNothingDhcpProxyScriptFetcher()); | 2513 new DoNothingDhcpProxyScriptFetcher()); |
| 2525 | 2514 |
| 2526 // Disable the "wait after IP address changes" hack, so this unit-test can | 2515 // Disable the "wait after IP address changes" hack, so this unit-test can |
| 2527 // complete quickly. | 2516 // complete quickly. |
| 2528 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); | 2517 service.set_stall_proxy_auto_config_delay(base::TimeDelta()); |
| 2529 | 2518 |
| 2530 // Start 1 request. | 2519 // Start 1 request. |
| 2531 | 2520 |
| 2532 ProxyInfo info1; | 2521 ProxyInfo info1; |
| 2533 TestCompletionCallback callback1; | 2522 TestCompletionCallback callback1; |
| 2534 int rv = | 2523 int rv = |
| 2535 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2524 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 2536 callback1.callback(), NULL, NULL, BoundNetLog()); | 2525 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2537 EXPECT_EQ(ERR_IO_PENDING, rv); | 2526 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2538 | 2527 |
| 2539 // The first request should have triggered initial download of PAC script. | 2528 // The first request should have triggered initial download of PAC script. |
| 2540 EXPECT_TRUE(fetcher->has_pending_request()); | 2529 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2541 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2530 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2542 | 2531 |
| 2543 // Nothing has been sent to the resolver yet. | 2532 // Nothing has been sent to the factory yet. |
| 2544 EXPECT_TRUE(resolver.pending_requests().empty()); | 2533 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2545 | 2534 |
| 2546 // At this point the ProxyService should be waiting for the | 2535 // At this point the ProxyService should be waiting for the |
| 2547 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2536 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 2548 // PAC script download completion. | 2537 // PAC script download completion. |
| 2549 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2538 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2550 | 2539 |
| 2551 // Now that the PAC script is downloaded, the request will have been sent to | 2540 // Now that the PAC script is downloaded, the request will have been sent to |
| 2552 // the proxy resolver. | 2541 // the proxy resolver. |
| 2553 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2542 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2554 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2543 factory->pending_requests()[0]->script_data()->utf16()); |
| 2555 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2544 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2556 | 2545 |
| 2557 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2546 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2558 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2547 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 2559 | 2548 |
| 2560 // Complete the pending request. | 2549 // Complete the pending request. |
| 2561 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2550 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 2562 resolver.pending_requests()[0]->CompleteNow(OK); | 2551 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2563 | 2552 |
| 2564 // Wait for completion callback, and verify that the request ran as expected. | 2553 // Wait for completion callback, and verify that the request ran as expected. |
| 2565 EXPECT_EQ(OK, callback1.WaitForResult()); | 2554 EXPECT_EQ(OK, callback1.WaitForResult()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 2576 TestCompletionCallback callback2; | 2565 TestCompletionCallback callback2; |
| 2577 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2566 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| 2578 callback2.callback(), NULL, NULL, BoundNetLog()); | 2567 callback2.callback(), NULL, NULL, BoundNetLog()); |
| 2579 EXPECT_EQ(ERR_IO_PENDING, rv); | 2568 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2580 | 2569 |
| 2581 // This second request should have triggered the re-download of the PAC | 2570 // This second request should have triggered the re-download of the PAC |
| 2582 // script (since we marked the network as having changed). | 2571 // script (since we marked the network as having changed). |
| 2583 EXPECT_TRUE(fetcher->has_pending_request()); | 2572 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2584 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2573 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2585 | 2574 |
| 2586 // Nothing has been sent to the resolver yet. | 2575 // Nothing has been sent to the factory yet. |
| 2587 EXPECT_TRUE(resolver.pending_requests().empty()); | 2576 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2588 | 2577 |
| 2589 // Simulate the PAC script fetch as having completed (this time with | 2578 // Simulate the PAC script fetch as having completed (this time with |
| 2590 // different data). | 2579 // different data). |
| 2591 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 2580 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
| 2592 | 2581 |
| 2593 // Now that the PAC script is downloaded, the second request will have been | 2582 // Now that the PAC script is downloaded, the second request will have been |
| 2594 // sent to the proxy resolver. | 2583 // sent to the proxy resolver. |
| 2595 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2584 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
| 2596 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2585 factory->pending_requests()[0]->script_data()->utf16()); |
| 2597 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2586 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2598 | 2587 |
| 2599 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2588 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2600 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); | 2589 EXPECT_EQ(GURL("http://request2"), resolver.pending_requests()[0]->url()); |
| 2601 | 2590 |
| 2602 // Complete the pending second request. | 2591 // Complete the pending second request. |
| 2603 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); | 2592 resolver.pending_requests()[0]->results()->UseNamedProxy("request2:80"); |
| 2604 resolver.pending_requests()[0]->CompleteNow(OK); | 2593 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2605 | 2594 |
| 2606 // Wait for completion callback, and verify that the request ran as expected. | 2595 // Wait for completion callback, and verify that the request ran as expected. |
| 2607 EXPECT_EQ(OK, callback2.WaitForResult()); | 2596 EXPECT_EQ(OK, callback2.WaitForResult()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2627 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { | 2616 TEST_F(ProxyServiceTest, PACScriptRefetchAfterFailure) { |
| 2628 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2617 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
| 2629 // runs quickly. | 2618 // runs quickly. |
| 2630 ImmediatePollPolicy poll_policy; | 2619 ImmediatePollPolicy poll_policy; |
| 2631 ProxyService::set_pac_script_poll_policy(&poll_policy); | 2620 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 2632 | 2621 |
| 2633 MockProxyConfigService* config_service = | 2622 MockProxyConfigService* config_service = |
| 2634 new MockProxyConfigService("http://foopy/proxy.pac"); | 2623 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2635 | 2624 |
| 2636 MockAsyncProxyResolverExpectsBytes resolver; | 2625 MockAsyncProxyResolverExpectsBytes resolver; |
| 2626 MockAsyncProxyResolverFactory* factory = |
| 2627 new MockAsyncProxyResolverFactory(true); |
| 2637 | 2628 |
| 2638 ProxyService service( | 2629 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2639 config_service, | |
| 2640 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 2641 | 2630 |
| 2642 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2631 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2643 service.SetProxyScriptFetchers(fetcher, | 2632 service.SetProxyScriptFetchers(fetcher, |
| 2644 new DoNothingDhcpProxyScriptFetcher()); | 2633 new DoNothingDhcpProxyScriptFetcher()); |
| 2645 | 2634 |
| 2646 // Start 1 request. | 2635 // Start 1 request. |
| 2647 | 2636 |
| 2648 ProxyInfo info1; | 2637 ProxyInfo info1; |
| 2649 TestCompletionCallback callback1; | 2638 TestCompletionCallback callback1; |
| 2650 int rv = | 2639 int rv = |
| 2651 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2640 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 2652 callback1.callback(), NULL, NULL, BoundNetLog()); | 2641 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2653 EXPECT_EQ(ERR_IO_PENDING, rv); | 2642 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2654 | 2643 |
| 2655 // The first request should have triggered initial download of PAC script. | 2644 // The first request should have triggered initial download of PAC script. |
| 2656 EXPECT_TRUE(fetcher->has_pending_request()); | 2645 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2657 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2646 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2658 | 2647 |
| 2659 // Nothing has been sent to the resolver yet. | 2648 // Nothing has been sent to the factory yet. |
| 2660 EXPECT_TRUE(resolver.pending_requests().empty()); | 2649 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2661 | 2650 |
| 2662 // At this point the ProxyService should be waiting for the | 2651 // At this point the ProxyService should be waiting for the |
| 2663 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2652 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 2664 // PAC script download completion. | 2653 // PAC script download completion. |
| 2665 // | 2654 // |
| 2666 // We simulate a failed download attempt, the proxy service should now | 2655 // We simulate a failed download attempt, the proxy service should now |
| 2667 // fall-back to DIRECT connections. | 2656 // fall-back to DIRECT connections. |
| 2668 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 2657 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| 2669 | 2658 |
| 2670 ASSERT_TRUE(resolver.pending_requests().empty()); | 2659 ASSERT_TRUE(factory->pending_requests().empty()); |
| 2671 | 2660 |
| 2672 // Wait for completion callback, and verify it used DIRECT. | 2661 // Wait for completion callback, and verify it used DIRECT. |
| 2673 EXPECT_EQ(OK, callback1.WaitForResult()); | 2662 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2674 EXPECT_TRUE(info1.is_direct()); | 2663 EXPECT_TRUE(info1.is_direct()); |
| 2675 | 2664 |
| 2676 // At this point we have initialized the proxy service using a PAC script, | 2665 // At this point we have initialized the proxy service using a PAC script, |
| 2677 // however it failed and fell-back to DIRECT. | 2666 // however it failed and fell-back to DIRECT. |
| 2678 // | 2667 // |
| 2679 // A background task to periodically re-check the PAC script for validity will | 2668 // A background task to periodically re-check the PAC script for validity will |
| 2680 // have been started. We will now wait for the next download attempt to start. | 2669 // have been started. We will now wait for the next download attempt to start. |
| 2681 // | 2670 // |
| 2682 // Note that we shouldn't have to wait long here, since our test enables a | 2671 // Note that we shouldn't have to wait long here, since our test enables a |
| 2683 // special unit-test mode. | 2672 // special unit-test mode. |
| 2684 fetcher->WaitUntilFetch(); | 2673 fetcher->WaitUntilFetch(); |
| 2685 | 2674 |
| 2686 ASSERT_TRUE(resolver.pending_requests().empty()); | 2675 ASSERT_TRUE(factory->pending_requests().empty()); |
| 2687 | 2676 |
| 2688 // Make sure that our background checker is trying to download the expected | 2677 // Make sure that our background checker is trying to download the expected |
| 2689 // PAC script (same one as before). This time we will simulate a successful | 2678 // PAC script (same one as before). This time we will simulate a successful |
| 2690 // download of the script. | 2679 // download of the script. |
| 2691 EXPECT_TRUE(fetcher->has_pending_request()); | 2680 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2692 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2681 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2693 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2682 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2694 | 2683 |
| 2695 base::MessageLoop::current()->RunUntilIdle(); | 2684 base::MessageLoop::current()->RunUntilIdle(); |
| 2696 | 2685 |
| 2697 // Now that the PAC script is downloaded, it should be used to initialize the | 2686 // Now that the PAC script is downloaded, it should be used to initialize the |
| 2698 // ProxyResolver. Simulate a successful parse. | 2687 // ProxyResolver. Simulate a successful parse. |
| 2699 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2688 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2700 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2689 factory->pending_requests()[0]->script_data()->utf16()); |
| 2701 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2690 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2702 | 2691 |
| 2703 // At this point the ProxyService should have re-configured itself to use the | 2692 // At this point the ProxyService should have re-configured itself to use the |
| 2704 // PAC script (thereby recovering from the initial fetch failure). We will | 2693 // PAC script (thereby recovering from the initial fetch failure). We will |
| 2705 // verify that the next Resolve request uses the resolver rather than | 2694 // verify that the next Resolve request uses the resolver rather than |
| 2706 // DIRECT. | 2695 // DIRECT. |
| 2707 | 2696 |
| 2708 // Start a second request. | 2697 // Start a second request. |
| 2709 ProxyInfo info2; | 2698 ProxyInfo info2; |
| 2710 TestCompletionCallback callback2; | 2699 TestCompletionCallback callback2; |
| 2711 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2700 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2732 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) { | 2721 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentChange) { |
| 2733 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2722 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
| 2734 // runs quickly. | 2723 // runs quickly. |
| 2735 ImmediatePollPolicy poll_policy; | 2724 ImmediatePollPolicy poll_policy; |
| 2736 ProxyService::set_pac_script_poll_policy(&poll_policy); | 2725 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 2737 | 2726 |
| 2738 MockProxyConfigService* config_service = | 2727 MockProxyConfigService* config_service = |
| 2739 new MockProxyConfigService("http://foopy/proxy.pac"); | 2728 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2740 | 2729 |
| 2741 MockAsyncProxyResolverExpectsBytes resolver; | 2730 MockAsyncProxyResolverExpectsBytes resolver; |
| 2731 MockAsyncProxyResolverFactory* factory = |
| 2732 new MockAsyncProxyResolverFactory(true); |
| 2742 | 2733 |
| 2743 ProxyService service( | 2734 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2744 config_service, | |
| 2745 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 2746 | 2735 |
| 2747 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2736 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2748 service.SetProxyScriptFetchers(fetcher, | 2737 service.SetProxyScriptFetchers(fetcher, |
| 2749 new DoNothingDhcpProxyScriptFetcher()); | 2738 new DoNothingDhcpProxyScriptFetcher()); |
| 2750 | 2739 |
| 2751 // Start 1 request. | 2740 // Start 1 request. |
| 2752 | 2741 |
| 2753 ProxyInfo info1; | 2742 ProxyInfo info1; |
| 2754 TestCompletionCallback callback1; | 2743 TestCompletionCallback callback1; |
| 2755 int rv = | 2744 int rv = |
| 2756 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2745 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 2757 callback1.callback(), NULL, NULL, BoundNetLog()); | 2746 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2758 EXPECT_EQ(ERR_IO_PENDING, rv); | 2747 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2759 | 2748 |
| 2760 // The first request should have triggered initial download of PAC script. | 2749 // The first request should have triggered initial download of PAC script. |
| 2761 EXPECT_TRUE(fetcher->has_pending_request()); | 2750 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2762 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2751 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2763 | 2752 |
| 2764 // Nothing has been sent to the resolver yet. | 2753 // Nothing has been sent to the factory yet. |
| 2765 EXPECT_TRUE(resolver.pending_requests().empty()); | 2754 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2766 | 2755 |
| 2767 // At this point the ProxyService should be waiting for the | 2756 // At this point the ProxyService should be waiting for the |
| 2768 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2757 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 2769 // PAC script download completion. | 2758 // PAC script download completion. |
| 2770 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2759 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2771 | 2760 |
| 2772 // Now that the PAC script is downloaded, the request will have been sent to | 2761 // Now that the PAC script is downloaded, the request will have been sent to |
| 2773 // the proxy resolver. | 2762 // the proxy resolver. |
| 2774 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2763 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2775 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2764 factory->pending_requests()[0]->script_data()->utf16()); |
| 2776 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2765 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2777 | 2766 |
| 2778 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2767 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2779 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2768 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 2780 | 2769 |
| 2781 // Complete the pending request. | 2770 // Complete the pending request. |
| 2782 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2771 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 2783 resolver.pending_requests()[0]->CompleteNow(OK); | 2772 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2784 | 2773 |
| 2785 // Wait for completion callback, and verify that the request ran as expected. | 2774 // Wait for completion callback, and verify that the request ran as expected. |
| 2786 EXPECT_EQ(OK, callback1.WaitForResult()); | 2775 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2787 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2776 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 2788 | 2777 |
| 2789 // At this point we have initialized the proxy service using a PAC script. | 2778 // At this point we have initialized the proxy service using a PAC script. |
| 2790 // | 2779 // |
| 2791 // A background task to periodically re-check the PAC script for validity will | 2780 // A background task to periodically re-check the PAC script for validity will |
| 2792 // have been started. We will now wait for the next download attempt to start. | 2781 // have been started. We will now wait for the next download attempt to start. |
| 2793 // | 2782 // |
| 2794 // Note that we shouldn't have to wait long here, since our test enables a | 2783 // Note that we shouldn't have to wait long here, since our test enables a |
| 2795 // special unit-test mode. | 2784 // special unit-test mode. |
| 2796 fetcher->WaitUntilFetch(); | 2785 fetcher->WaitUntilFetch(); |
| 2797 | 2786 |
| 2787 ASSERT_TRUE(factory->pending_requests().empty()); |
| 2798 ASSERT_TRUE(resolver.pending_requests().empty()); | 2788 ASSERT_TRUE(resolver.pending_requests().empty()); |
| 2799 | 2789 |
| 2800 // Make sure that our background checker is trying to download the expected | 2790 // Make sure that our background checker is trying to download the expected |
| 2801 // PAC script (same one as before). This time we will simulate a successful | 2791 // PAC script (same one as before). This time we will simulate a successful |
| 2802 // download of a DIFFERENT script. | 2792 // download of a DIFFERENT script. |
| 2803 EXPECT_TRUE(fetcher->has_pending_request()); | 2793 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2804 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2794 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2805 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); | 2795 fetcher->NotifyFetchCompletion(OK, kValidPacScript2); |
| 2806 | 2796 |
| 2807 base::MessageLoop::current()->RunUntilIdle(); | 2797 base::MessageLoop::current()->RunUntilIdle(); |
| 2808 | 2798 |
| 2809 // Now that the PAC script is downloaded, it should be used to initialize the | 2799 // Now that the PAC script is downloaded, it should be used to initialize the |
| 2810 // ProxyResolver. Simulate a successful parse. | 2800 // ProxyResolver. Simulate a successful parse. |
| 2811 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), | 2801 EXPECT_EQ(ASCIIToUTF16(kValidPacScript2), |
| 2812 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2802 factory->pending_requests()[0]->script_data()->utf16()); |
| 2813 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2803 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2814 | 2804 |
| 2815 // At this point the ProxyService should have re-configured itself to use the | 2805 // At this point the ProxyService should have re-configured itself to use the |
| 2816 // new PAC script. | 2806 // new PAC script. |
| 2817 | 2807 |
| 2818 // Start a second request. | 2808 // Start a second request. |
| 2819 ProxyInfo info2; | 2809 ProxyInfo info2; |
| 2820 TestCompletionCallback callback2; | 2810 TestCompletionCallback callback2; |
| 2821 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2811 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| 2822 callback2.callback(), NULL, NULL, BoundNetLog()); | 2812 callback2.callback(), NULL, NULL, BoundNetLog()); |
| 2823 EXPECT_EQ(ERR_IO_PENDING, rv); | 2813 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2842 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) { | 2832 TEST_F(ProxyServiceTest, PACScriptRefetchAfterContentUnchanged) { |
| 2843 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2833 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
| 2844 // runs quickly. | 2834 // runs quickly. |
| 2845 ImmediatePollPolicy poll_policy; | 2835 ImmediatePollPolicy poll_policy; |
| 2846 ProxyService::set_pac_script_poll_policy(&poll_policy); | 2836 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 2847 | 2837 |
| 2848 MockProxyConfigService* config_service = | 2838 MockProxyConfigService* config_service = |
| 2849 new MockProxyConfigService("http://foopy/proxy.pac"); | 2839 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2850 | 2840 |
| 2851 MockAsyncProxyResolverExpectsBytes resolver; | 2841 MockAsyncProxyResolverExpectsBytes resolver; |
| 2842 MockAsyncProxyResolverFactory* factory = |
| 2843 new MockAsyncProxyResolverFactory(true); |
| 2852 | 2844 |
| 2853 ProxyService service( | 2845 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2854 config_service, | |
| 2855 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 2856 | 2846 |
| 2857 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2847 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2858 service.SetProxyScriptFetchers(fetcher, | 2848 service.SetProxyScriptFetchers(fetcher, |
| 2859 new DoNothingDhcpProxyScriptFetcher()); | 2849 new DoNothingDhcpProxyScriptFetcher()); |
| 2860 | 2850 |
| 2861 // Start 1 request. | 2851 // Start 1 request. |
| 2862 | 2852 |
| 2863 ProxyInfo info1; | 2853 ProxyInfo info1; |
| 2864 TestCompletionCallback callback1; | 2854 TestCompletionCallback callback1; |
| 2865 int rv = | 2855 int rv = |
| 2866 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2856 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 2867 callback1.callback(), NULL, NULL, BoundNetLog()); | 2857 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2868 EXPECT_EQ(ERR_IO_PENDING, rv); | 2858 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2869 | 2859 |
| 2870 // The first request should have triggered initial download of PAC script. | 2860 // The first request should have triggered initial download of PAC script. |
| 2871 EXPECT_TRUE(fetcher->has_pending_request()); | 2861 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2872 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2862 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2873 | 2863 |
| 2874 // Nothing has been sent to the resolver yet. | 2864 // Nothing has been sent to the factory yet. |
| 2875 EXPECT_TRUE(resolver.pending_requests().empty()); | 2865 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2876 | 2866 |
| 2877 // At this point the ProxyService should be waiting for the | 2867 // At this point the ProxyService should be waiting for the |
| 2878 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2868 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 2879 // PAC script download completion. | 2869 // PAC script download completion. |
| 2880 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2870 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2881 | 2871 |
| 2882 // Now that the PAC script is downloaded, the request will have been sent to | 2872 // Now that the PAC script is downloaded, the request will have been sent to |
| 2883 // the proxy resolver. | 2873 // the proxy resolver. |
| 2884 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2874 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2885 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2875 factory->pending_requests()[0]->script_data()->utf16()); |
| 2886 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2876 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2887 | 2877 |
| 2888 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2878 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2889 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2879 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 2890 | 2880 |
| 2891 // Complete the pending request. | 2881 // Complete the pending request. |
| 2892 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2882 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 2893 resolver.pending_requests()[0]->CompleteNow(OK); | 2883 resolver.pending_requests()[0]->CompleteNow(OK); |
| 2894 | 2884 |
| 2895 // Wait for completion callback, and verify that the request ran as expected. | 2885 // Wait for completion callback, and verify that the request ran as expected. |
| 2896 EXPECT_EQ(OK, callback1.WaitForResult()); | 2886 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 2897 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2887 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 2898 | 2888 |
| 2899 // At this point we have initialized the proxy service using a PAC script. | 2889 // At this point we have initialized the proxy service using a PAC script. |
| 2900 // | 2890 // |
| 2901 // A background task to periodically re-check the PAC script for validity will | 2891 // A background task to periodically re-check the PAC script for validity will |
| 2902 // have been started. We will now wait for the next download attempt to start. | 2892 // have been started. We will now wait for the next download attempt to start. |
| 2903 // | 2893 // |
| 2904 // Note that we shouldn't have to wait long here, since our test enables a | 2894 // Note that we shouldn't have to wait long here, since our test enables a |
| 2905 // special unit-test mode. | 2895 // special unit-test mode. |
| 2906 fetcher->WaitUntilFetch(); | 2896 fetcher->WaitUntilFetch(); |
| 2907 | 2897 |
| 2898 ASSERT_TRUE(factory->pending_requests().empty()); |
| 2908 ASSERT_TRUE(resolver.pending_requests().empty()); | 2899 ASSERT_TRUE(resolver.pending_requests().empty()); |
| 2909 | 2900 |
| 2910 // Make sure that our background checker is trying to download the expected | 2901 // Make sure that our background checker is trying to download the expected |
| 2911 // PAC script (same one as before). We will simulate the same response as | 2902 // PAC script (same one as before). We will simulate the same response as |
| 2912 // last time (i.e. the script is unchanged). | 2903 // last time (i.e. the script is unchanged). |
| 2913 EXPECT_TRUE(fetcher->has_pending_request()); | 2904 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2914 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2905 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2915 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2906 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2916 | 2907 |
| 2917 base::MessageLoop::current()->RunUntilIdle(); | 2908 base::MessageLoop::current()->RunUntilIdle(); |
| 2918 | 2909 |
| 2919 ASSERT_FALSE(resolver.has_pending_set_pac_script_request()); | 2910 ASSERT_TRUE(factory->pending_requests().empty()); |
| 2911 ASSERT_TRUE(resolver.pending_requests().empty()); |
| 2920 | 2912 |
| 2921 // At this point the ProxyService is still running the same PAC script as | 2913 // At this point the ProxyService is still running the same PAC script as |
| 2922 // before. | 2914 // before. |
| 2923 | 2915 |
| 2924 // Start a second request. | 2916 // Start a second request. |
| 2925 ProxyInfo info2; | 2917 ProxyInfo info2; |
| 2926 TestCompletionCallback callback2; | 2918 TestCompletionCallback callback2; |
| 2927 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 2919 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| 2928 callback2.callback(), NULL, NULL, BoundNetLog()); | 2920 callback2.callback(), NULL, NULL, BoundNetLog()); |
| 2929 EXPECT_EQ(ERR_IO_PENDING, rv); | 2921 EXPECT_EQ(ERR_IO_PENDING, rv); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2948 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) { | 2940 TEST_F(ProxyServiceTest, PACScriptRefetchAfterSuccess) { |
| 2949 // Change the retry policy to wait a mere 1 ms before retrying, so the test | 2941 // Change the retry policy to wait a mere 1 ms before retrying, so the test |
| 2950 // runs quickly. | 2942 // runs quickly. |
| 2951 ImmediatePollPolicy poll_policy; | 2943 ImmediatePollPolicy poll_policy; |
| 2952 ProxyService::set_pac_script_poll_policy(&poll_policy); | 2944 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 2953 | 2945 |
| 2954 MockProxyConfigService* config_service = | 2946 MockProxyConfigService* config_service = |
| 2955 new MockProxyConfigService("http://foopy/proxy.pac"); | 2947 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 2956 | 2948 |
| 2957 MockAsyncProxyResolverExpectsBytes resolver; | 2949 MockAsyncProxyResolverExpectsBytes resolver; |
| 2950 MockAsyncProxyResolverFactory* factory = |
| 2951 new MockAsyncProxyResolverFactory(true); |
| 2958 | 2952 |
| 2959 ProxyService service( | 2953 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 2960 config_service, | |
| 2961 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 2962 | 2954 |
| 2963 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 2955 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 2964 service.SetProxyScriptFetchers(fetcher, | 2956 service.SetProxyScriptFetchers(fetcher, |
| 2965 new DoNothingDhcpProxyScriptFetcher()); | 2957 new DoNothingDhcpProxyScriptFetcher()); |
| 2966 | 2958 |
| 2967 // Start 1 request. | 2959 // Start 1 request. |
| 2968 | 2960 |
| 2969 ProxyInfo info1; | 2961 ProxyInfo info1; |
| 2970 TestCompletionCallback callback1; | 2962 TestCompletionCallback callback1; |
| 2971 int rv = | 2963 int rv = |
| 2972 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 2964 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 2973 callback1.callback(), NULL, NULL, BoundNetLog()); | 2965 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 2974 EXPECT_EQ(ERR_IO_PENDING, rv); | 2966 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 2975 | 2967 |
| 2976 // The first request should have triggered initial download of PAC script. | 2968 // The first request should have triggered initial download of PAC script. |
| 2977 EXPECT_TRUE(fetcher->has_pending_request()); | 2969 EXPECT_TRUE(fetcher->has_pending_request()); |
| 2978 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 2970 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 2979 | 2971 |
| 2980 // Nothing has been sent to the resolver yet. | 2972 // Nothing has been sent to the factory yet. |
| 2981 EXPECT_TRUE(resolver.pending_requests().empty()); | 2973 EXPECT_TRUE(factory->pending_requests().empty()); |
| 2982 | 2974 |
| 2983 // At this point the ProxyService should be waiting for the | 2975 // At this point the ProxyService should be waiting for the |
| 2984 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 2976 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 2985 // PAC script download completion. | 2977 // PAC script download completion. |
| 2986 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 2978 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 2987 | 2979 |
| 2988 // Now that the PAC script is downloaded, the request will have been sent to | 2980 // Now that the PAC script is downloaded, the request will have been sent to |
| 2989 // the proxy resolver. | 2981 // the proxy resolver. |
| 2990 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 2982 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 2991 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 2983 factory->pending_requests()[0]->script_data()->utf16()); |
| 2992 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 2984 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 2993 | 2985 |
| 2994 ASSERT_EQ(1u, resolver.pending_requests().size()); | 2986 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 2995 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 2987 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 2996 | 2988 |
| 2997 // Complete the pending request. | 2989 // Complete the pending request. |
| 2998 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 2990 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 2999 resolver.pending_requests()[0]->CompleteNow(OK); | 2991 resolver.pending_requests()[0]->CompleteNow(OK); |
| 3000 | 2992 |
| 3001 // Wait for completion callback, and verify that the request ran as expected. | 2993 // Wait for completion callback, and verify that the request ran as expected. |
| 3002 EXPECT_EQ(OK, callback1.WaitForResult()); | 2994 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 3003 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 2995 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 3004 | 2996 |
| 3005 // At this point we have initialized the proxy service using a PAC script. | 2997 // At this point we have initialized the proxy service using a PAC script. |
| 3006 // | 2998 // |
| 3007 // A background task to periodically re-check the PAC script for validity will | 2999 // A background task to periodically re-check the PAC script for validity will |
| 3008 // have been started. We will now wait for the next download attempt to start. | 3000 // have been started. We will now wait for the next download attempt to start. |
| 3009 // | 3001 // |
| 3010 // Note that we shouldn't have to wait long here, since our test enables a | 3002 // Note that we shouldn't have to wait long here, since our test enables a |
| 3011 // special unit-test mode. | 3003 // special unit-test mode. |
| 3012 fetcher->WaitUntilFetch(); | 3004 fetcher->WaitUntilFetch(); |
| 3013 | 3005 |
| 3006 ASSERT_TRUE(factory->pending_requests().empty()); |
| 3014 ASSERT_TRUE(resolver.pending_requests().empty()); | 3007 ASSERT_TRUE(resolver.pending_requests().empty()); |
| 3015 | 3008 |
| 3016 // Make sure that our background checker is trying to download the expected | 3009 // Make sure that our background checker is trying to download the expected |
| 3017 // PAC script (same one as before). This time we will simulate a failure | 3010 // PAC script (same one as before). This time we will simulate a failure |
| 3018 // to download the script. | 3011 // to download the script. |
| 3019 EXPECT_TRUE(fetcher->has_pending_request()); | 3012 EXPECT_TRUE(fetcher->has_pending_request()); |
| 3020 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3013 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 3021 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); | 3014 fetcher->NotifyFetchCompletion(ERR_FAILED, std::string()); |
| 3022 | 3015 |
| 3023 base::MessageLoop::current()->RunUntilIdle(); | 3016 base::MessageLoop::current()->RunUntilIdle(); |
| (...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3100 // This tests the polling of the PAC script. Specifically, it tests that | 3093 // This tests the polling of the PAC script. Specifically, it tests that |
| 3101 // polling occurs in response to user activity. | 3094 // polling occurs in response to user activity. |
| 3102 TEST_F(ProxyServiceTest, PACScriptRefetchAfterActivity) { | 3095 TEST_F(ProxyServiceTest, PACScriptRefetchAfterActivity) { |
| 3103 ImmediateAfterActivityPollPolicy poll_policy; | 3096 ImmediateAfterActivityPollPolicy poll_policy; |
| 3104 ProxyService::set_pac_script_poll_policy(&poll_policy); | 3097 ProxyService::set_pac_script_poll_policy(&poll_policy); |
| 3105 | 3098 |
| 3106 MockProxyConfigService* config_service = | 3099 MockProxyConfigService* config_service = |
| 3107 new MockProxyConfigService("http://foopy/proxy.pac"); | 3100 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 3108 | 3101 |
| 3109 MockAsyncProxyResolverExpectsBytes resolver; | 3102 MockAsyncProxyResolverExpectsBytes resolver; |
| 3103 MockAsyncProxyResolverFactory* factory = |
| 3104 new MockAsyncProxyResolverFactory(true); |
| 3110 | 3105 |
| 3111 ProxyService service( | 3106 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 3112 config_service, | |
| 3113 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 3114 | 3107 |
| 3115 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; | 3108 MockProxyScriptFetcher* fetcher = new MockProxyScriptFetcher; |
| 3116 service.SetProxyScriptFetchers(fetcher, | 3109 service.SetProxyScriptFetchers(fetcher, |
| 3117 new DoNothingDhcpProxyScriptFetcher()); | 3110 new DoNothingDhcpProxyScriptFetcher()); |
| 3118 | 3111 |
| 3119 // Start 1 request. | 3112 // Start 1 request. |
| 3120 | 3113 |
| 3121 ProxyInfo info1; | 3114 ProxyInfo info1; |
| 3122 TestCompletionCallback callback1; | 3115 TestCompletionCallback callback1; |
| 3123 int rv = | 3116 int rv = |
| 3124 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, | 3117 service.ResolveProxy(GURL("http://request1"), LOAD_NORMAL, &info1, |
| 3125 callback1.callback(), NULL, NULL, BoundNetLog()); | 3118 callback1.callback(), NULL, NULL, BoundNetLog()); |
| 3126 EXPECT_EQ(ERR_IO_PENDING, rv); | 3119 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3127 | 3120 |
| 3128 // The first request should have triggered initial download of PAC script. | 3121 // The first request should have triggered initial download of PAC script. |
| 3129 EXPECT_TRUE(fetcher->has_pending_request()); | 3122 EXPECT_TRUE(fetcher->has_pending_request()); |
| 3130 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); | 3123 EXPECT_EQ(GURL("http://foopy/proxy.pac"), fetcher->pending_request_url()); |
| 3131 | 3124 |
| 3132 // Nothing has been sent to the resolver yet. | 3125 // Nothing has been sent to the factory yet. |
| 3133 EXPECT_TRUE(resolver.pending_requests().empty()); | 3126 EXPECT_TRUE(factory->pending_requests().empty()); |
| 3134 | 3127 |
| 3135 // At this point the ProxyService should be waiting for the | 3128 // At this point the ProxyService should be waiting for the |
| 3136 // ProxyScriptFetcher to invoke its completion callback, notifying it of | 3129 // ProxyScriptFetcher to invoke its completion callback, notifying it of |
| 3137 // PAC script download completion. | 3130 // PAC script download completion. |
| 3138 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); | 3131 fetcher->NotifyFetchCompletion(OK, kValidPacScript1); |
| 3139 | 3132 |
| 3140 // Now that the PAC script is downloaded, the request will have been sent to | 3133 // Now that the PAC script is downloaded, the request will have been sent to |
| 3141 // the proxy resolver. | 3134 // the proxy resolver. |
| 3142 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), | 3135 EXPECT_EQ(ASCIIToUTF16(kValidPacScript1), |
| 3143 resolver.pending_set_pac_script_request()->script_data()->utf16()); | 3136 factory->pending_requests()[0]->script_data()->utf16()); |
| 3144 resolver.pending_set_pac_script_request()->CompleteNow(OK); | 3137 factory->pending_requests()[0]->CompleteNowWithForwarder(OK, &resolver); |
| 3145 | 3138 |
| 3146 ASSERT_EQ(1u, resolver.pending_requests().size()); | 3139 ASSERT_EQ(1u, resolver.pending_requests().size()); |
| 3147 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); | 3140 EXPECT_EQ(GURL("http://request1"), resolver.pending_requests()[0]->url()); |
| 3148 | 3141 |
| 3149 // Complete the pending request. | 3142 // Complete the pending request. |
| 3150 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); | 3143 resolver.pending_requests()[0]->results()->UseNamedProxy("request1:80"); |
| 3151 resolver.pending_requests()[0]->CompleteNow(OK); | 3144 resolver.pending_requests()[0]->CompleteNow(OK); |
| 3152 | 3145 |
| 3153 // Wait for completion callback, and verify that the request ran as expected. | 3146 // Wait for completion callback, and verify that the request ran as expected. |
| 3154 EXPECT_EQ(OK, callback1.WaitForResult()); | 3147 EXPECT_EQ(OK, callback1.WaitForResult()); |
| 3155 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); | 3148 EXPECT_EQ("request1:80", info1.proxy_server().ToURI()); |
| 3156 | 3149 |
| 3157 // At this point we have initialized the proxy service using a PAC script. | 3150 // At this point we have initialized the proxy service using a PAC script. |
| 3158 // Our PAC poller is set to update ONLY in response to network activity, | 3151 // Our PAC poller is set to update ONLY in response to network activity, |
| 3159 // (i.e. another call to ResolveProxy()). | 3152 // (i.e. another call to ResolveProxy()). |
| 3160 | 3153 |
| 3161 ASSERT_FALSE(fetcher->has_pending_request()); | 3154 ASSERT_FALSE(fetcher->has_pending_request()); |
| 3155 ASSERT_TRUE(factory->pending_requests().empty()); |
| 3162 ASSERT_TRUE(resolver.pending_requests().empty()); | 3156 ASSERT_TRUE(resolver.pending_requests().empty()); |
| 3163 | 3157 |
| 3164 // Start a second request. | 3158 // Start a second request. |
| 3165 ProxyInfo info2; | 3159 ProxyInfo info2; |
| 3166 TestCompletionCallback callback2; | 3160 TestCompletionCallback callback2; |
| 3167 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, | 3161 rv = service.ResolveProxy(GURL("http://request2"), LOAD_NORMAL, &info2, |
| 3168 callback2.callback(), NULL, NULL, BoundNetLog()); | 3162 callback2.callback(), NULL, NULL, BoundNetLog()); |
| 3169 EXPECT_EQ(ERR_IO_PENDING, rv); | 3163 EXPECT_EQ(ERR_IO_PENDING, rv); |
| 3170 | 3164 |
| 3171 // This request should have sent work to the resolver; complete it. | 3165 // This request should have sent work to the resolver; complete it. |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3198 callback3.callback(), NULL, NULL, BoundNetLog()); | 3192 callback3.callback(), NULL, NULL, BoundNetLog()); |
| 3199 EXPECT_EQ(OK, rv); | 3193 EXPECT_EQ(OK, rv); |
| 3200 EXPECT_TRUE(info3.is_direct()); | 3194 EXPECT_TRUE(info3.is_direct()); |
| 3201 } | 3195 } |
| 3202 | 3196 |
| 3203 // Test that the synchronous resolution fails when a PAC script is active. | 3197 // Test that the synchronous resolution fails when a PAC script is active. |
| 3204 TEST_F(ProxyServiceTest, SynchronousWithPAC) { | 3198 TEST_F(ProxyServiceTest, SynchronousWithPAC) { |
| 3205 MockProxyConfigService* config_service = | 3199 MockProxyConfigService* config_service = |
| 3206 new MockProxyConfigService("http://foopy/proxy.pac"); | 3200 new MockProxyConfigService("http://foopy/proxy.pac"); |
| 3207 | 3201 |
| 3208 MockAsyncProxyResolver resolver; | 3202 MockAsyncProxyResolverFactory* factory = |
| 3203 new MockAsyncProxyResolverFactory(false); |
| 3209 | 3204 |
| 3210 ProxyService service( | 3205 ProxyService service(config_service, make_scoped_ptr(factory), NULL); |
| 3211 config_service, | |
| 3212 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 3213 | 3206 |
| 3214 GURL url("http://www.google.com/"); | 3207 GURL url("http://www.google.com/"); |
| 3215 | 3208 |
| 3216 ProxyInfo info; | 3209 ProxyInfo info; |
| 3217 info.UseDirect(); | 3210 info.UseDirect(); |
| 3218 BoundTestNetLog log; | 3211 BoundTestNetLog log; |
| 3219 | 3212 |
| 3220 bool synchronous_success = service.TryResolveProxySynchronously( | 3213 bool synchronous_success = service.TryResolveProxySynchronously( |
| 3221 url, LOAD_NORMAL, &info, NULL, log.bound()); | 3214 url, LOAD_NORMAL, &info, NULL, log.bound()); |
| 3222 EXPECT_FALSE(synchronous_success); | 3215 EXPECT_FALSE(synchronous_success); |
| 3223 | 3216 |
| 3224 // No request should have been queued. | |
| 3225 EXPECT_EQ(0u, resolver.pending_requests().size()); | |
| 3226 | |
| 3227 // |info| should not have been modified. | 3217 // |info| should not have been modified. |
| 3228 EXPECT_TRUE(info.is_direct()); | 3218 EXPECT_TRUE(info.is_direct()); |
| 3229 } | 3219 } |
| 3230 | 3220 |
| 3231 // Test that synchronous results are returned correctly if a fixed proxy | 3221 // Test that synchronous results are returned correctly if a fixed proxy |
| 3232 // configuration is active. | 3222 // configuration is active. |
| 3233 TEST_F(ProxyServiceTest, SynchronousWithFixedConfiguration) { | 3223 TEST_F(ProxyServiceTest, SynchronousWithFixedConfiguration) { |
| 3234 ProxyConfig config; | 3224 ProxyConfig config; |
| 3235 config.proxy_rules().ParseFromString("foopy1:8080"); | 3225 config.proxy_rules().ParseFromString("foopy1:8080"); |
| 3236 config.set_auto_detect(false); | 3226 config.set_auto_detect(false); |
| 3237 | 3227 |
| 3238 MockAsyncProxyResolver resolver; | 3228 MockAsyncProxyResolverFactory* factory = |
| 3229 new MockAsyncProxyResolverFactory(false); |
| 3239 | 3230 |
| 3240 ProxyService service( | 3231 ProxyService service(new MockProxyConfigService(config), |
| 3241 new MockProxyConfigService(config), | 3232 make_scoped_ptr(factory), NULL); |
| 3242 make_scoped_ptr(new ForwardingProxyResolverFactory(&resolver)), NULL); | |
| 3243 | 3233 |
| 3244 GURL url("http://www.google.com/"); | 3234 GURL url("http://www.google.com/"); |
| 3245 | 3235 |
| 3246 ProxyInfo info; | 3236 ProxyInfo info; |
| 3247 BoundTestNetLog log; | 3237 BoundTestNetLog log; |
| 3248 | 3238 |
| 3249 bool synchronous_success = service.TryResolveProxySynchronously( | 3239 bool synchronous_success = service.TryResolveProxySynchronously( |
| 3250 url, LOAD_NORMAL, &info, NULL, log.bound()); | 3240 url, LOAD_NORMAL, &info, NULL, log.bound()); |
| 3251 EXPECT_TRUE(synchronous_success); | 3241 EXPECT_TRUE(synchronous_success); |
| 3252 EXPECT_FALSE(info.is_direct()); | 3242 EXPECT_FALSE(info.is_direct()); |
| 3253 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); | 3243 EXPECT_EQ("foopy1", info.proxy_server().host_port_pair().host()); |
| 3254 | 3244 |
| 3255 // No request should have been queued. | 3245 // No request should have been queued. |
| 3256 EXPECT_EQ(0u, resolver.pending_requests().size()); | 3246 EXPECT_EQ(0u, factory->pending_requests().size()); |
| 3257 } | 3247 } |
| 3258 | 3248 |
| 3259 } // namespace net | 3249 } // namespace net |
| OLD | NEW |