| 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 "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| (...skipping 388 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 main_intercept_job_ = job; | 399 main_intercept_job_ = job; |
| 400 } | 400 } |
| 401 | 401 |
| 402 private: | 402 private: |
| 403 mutable URLRequestJob* main_intercept_job_; | 403 mutable URLRequestJob* main_intercept_job_; |
| 404 }; | 404 }; |
| 405 | 405 |
| 406 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f | 406 // Inherit PlatformTest since we require the autorelease pool on Mac OS X.f |
| 407 class URLRequestTest : public PlatformTest { | 407 class URLRequestTest : public PlatformTest { |
| 408 public: | 408 public: |
| 409 URLRequestTest() : default_context_(new TestURLRequestContext(true)) { | 409 URLRequestTest() : default_context_(true) { |
| 410 default_context_->set_network_delegate(&default_network_delegate_); | 410 default_context_.set_network_delegate(&default_network_delegate_); |
| 411 default_context_->Init(); | 411 default_context_.Init(); |
| 412 } | 412 } |
| 413 | 413 |
| 414 static void SetUpTestCase() { | 414 static void SetUpTestCase() { |
| 415 URLRequest::AllowFileAccess(); | 415 URLRequest::AllowFileAccess(); |
| 416 } | 416 } |
| 417 | 417 |
| 418 // Adds the TestJobInterceptor to the default context. | 418 // Adds the TestJobInterceptor to the default context. |
| 419 TestJobInterceptor* AddTestInterceptor() { | 419 TestJobInterceptor* AddTestInterceptor() { |
| 420 TestJobInterceptor* interceptor = new TestJobInterceptor(); | 420 TestJobInterceptor* interceptor = new TestJobInterceptor(); |
| 421 default_context_->set_job_factory(&job_factory_); | 421 default_context_.set_job_factory(&job_factory_); |
| 422 job_factory_.AddInterceptor(interceptor); | 422 job_factory_.AddInterceptor(interceptor); |
| 423 return interceptor; | 423 return interceptor; |
| 424 } | 424 } |
| 425 | 425 |
| 426 protected: | 426 protected: |
| 427 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest | 427 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest |
| 428 scoped_refptr<TestURLRequestContext> default_context_; | |
| 429 URLRequestJobFactory job_factory_; | 428 URLRequestJobFactory job_factory_; |
| 429 TestURLRequestContext default_context_; |
| 430 }; | 430 }; |
| 431 | 431 |
| 432 class URLRequestTestHTTP : public URLRequestTest { | 432 class URLRequestTestHTTP : public URLRequestTest { |
| 433 public: | 433 public: |
| 434 URLRequestTestHTTP() | 434 URLRequestTestHTTP() |
| 435 : test_server_(FilePath(FILE_PATH_LITERAL( | 435 : test_server_(FilePath(FILE_PATH_LITERAL( |
| 436 "net/data/url_request_unittest"))) { | 436 "net/data/url_request_unittest"))) { |
| 437 } | 437 } |
| 438 | 438 |
| 439 protected: | 439 protected: |
| 440 // Requests |redirect_url|, which must return a HTTP 3xx redirect. | 440 // Requests |redirect_url|, which must return a HTTP 3xx redirect. |
| 441 // |request_method| is the method to use for the initial request. | 441 // |request_method| is the method to use for the initial request. |
| 442 // |redirect_method| is the method that is expected to be used for the second | 442 // |redirect_method| is the method that is expected to be used for the second |
| 443 // request, after redirection. | 443 // request, after redirection. |
| 444 // If |include_data| is true, data is uploaded with the request. The | 444 // If |include_data| is true, data is uploaded with the request. The |
| 445 // response body is expected to match it exactly, if and only if | 445 // response body is expected to match it exactly, if and only if |
| 446 // |request_method| == |redirect_method|. | 446 // |request_method| == |redirect_method|. |
| 447 void HTTPRedirectMethodTest(const GURL& redirect_url, | 447 void HTTPRedirectMethodTest(const GURL& redirect_url, |
| 448 const std::string& request_method, | 448 const std::string& request_method, |
| 449 const std::string& redirect_method, | 449 const std::string& redirect_method, |
| 450 bool include_data) { | 450 bool include_data) { |
| 451 static const char kData[] = "hello world"; | 451 static const char kData[] = "hello world"; |
| 452 TestDelegate d; | 452 TestDelegate d; |
| 453 TestURLRequest req(redirect_url, &d); | 453 TestURLRequest req(redirect_url, &d); |
| 454 req.set_context(default_context_); | 454 req.set_context(&default_context_); |
| 455 req.set_method(request_method); | 455 req.set_method(request_method); |
| 456 if (include_data) { | 456 if (include_data) { |
| 457 req.set_upload(CreateSimpleUploadData(kData).get()); | 457 req.set_upload(CreateSimpleUploadData(kData).get()); |
| 458 HttpRequestHeaders headers; | 458 HttpRequestHeaders headers; |
| 459 headers.SetHeader(HttpRequestHeaders::kContentLength, | 459 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 460 base::UintToString(arraysize(kData) - 1)); | 460 base::UintToString(arraysize(kData) - 1)); |
| 461 req.SetExtraRequestHeaders(headers); | 461 req.SetExtraRequestHeaders(headers); |
| 462 } | 462 } |
| 463 req.Start(); | 463 req.Start(); |
| 464 MessageLoop::current()->Run(); | 464 MessageLoop::current()->Run(); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 490 *ptr++ = marker; | 490 *ptr++ = marker; |
| 491 if (++marker > 'z') | 491 if (++marker > 'z') |
| 492 marker = 'a'; | 492 marker = 'a'; |
| 493 } | 493 } |
| 494 } | 494 } |
| 495 uploadBytes[kMsgSize] = '\0'; | 495 uploadBytes[kMsgSize] = '\0'; |
| 496 | 496 |
| 497 for (int i = 0; i < kIterations; ++i) { | 497 for (int i = 0; i < kIterations; ++i) { |
| 498 TestDelegate d; | 498 TestDelegate d; |
| 499 URLRequest r(test_server_.GetURL("echo"), &d); | 499 URLRequest r(test_server_.GetURL("echo"), &d); |
| 500 r.set_context(default_context_); | 500 r.set_context(&default_context_); |
| 501 r.set_method(method.c_str()); | 501 r.set_method(method.c_str()); |
| 502 | 502 |
| 503 r.AppendBytesToUpload(uploadBytes, kMsgSize); | 503 r.AppendBytesToUpload(uploadBytes, kMsgSize); |
| 504 | 504 |
| 505 r.Start(); | 505 r.Start(); |
| 506 EXPECT_TRUE(r.is_pending()); | 506 EXPECT_TRUE(r.is_pending()); |
| 507 | 507 |
| 508 MessageLoop::current()->Run(); | 508 MessageLoop::current()->Run(); |
| 509 | 509 |
| 510 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 510 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 547 | 547 |
| 548 // In this unit test, we're using the HTTPTestServer as a proxy server and | 548 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| 549 // issuing a CONNECT request with the magic host name "www.redirect.com". | 549 // issuing a CONNECT request with the magic host name "www.redirect.com". |
| 550 // The HTTPTestServer will return a 302 response, which we should not | 550 // The HTTPTestServer will return a 302 response, which we should not |
| 551 // follow. | 551 // follow. |
| 552 // flaky: crbug.com/96594 | 552 // flaky: crbug.com/96594 |
| 553 TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) { | 553 TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) { |
| 554 ASSERT_TRUE(test_server_.Start()); | 554 ASSERT_TRUE(test_server_.Start()); |
| 555 | 555 |
| 556 TestNetworkDelegate network_delegate; // must outlive URLRequest | 556 TestNetworkDelegate network_delegate; // must outlive URLRequest |
| 557 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 557 TestURLRequestContext context(true); |
| 558 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 558 context.SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 559 context->set_network_delegate(&network_delegate); | 559 context.set_network_delegate(&network_delegate); |
| 560 context->Init(); | 560 context.Init(); |
| 561 | 561 |
| 562 TestDelegate d; | 562 TestDelegate d; |
| 563 { | 563 { |
| 564 URLRequest r(GURL("https://www.redirect.com/"), &d); | 564 URLRequest r(GURL("https://www.redirect.com/"), &d); |
| 565 r.set_context(context); | 565 r.set_context(&context); |
| 566 r.Start(); | 566 r.Start(); |
| 567 EXPECT_TRUE(r.is_pending()); | 567 EXPECT_TRUE(r.is_pending()); |
| 568 | 568 |
| 569 MessageLoop::current()->Run(); | 569 MessageLoop::current()->Run(); |
| 570 | 570 |
| 571 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 571 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 572 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 572 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 573 EXPECT_EQ(1, d.response_started_count()); | 573 EXPECT_EQ(1, d.response_started_count()); |
| 574 // We should not have followed the redirect. | 574 // We should not have followed the redirect. |
| 575 EXPECT_EQ(0, d.received_redirect_count()); | 575 EXPECT_EQ(0, d.received_redirect_count()); |
| 576 } | 576 } |
| 577 } | 577 } |
| 578 | 578 |
| 579 // This is the same as the previous test, but checks that the network delegate | 579 // This is the same as the previous test, but checks that the network delegate |
| 580 // registers the error. | 580 // registers the error. |
| 581 // This test was disabled because it made chrome_frame_net_tests hang | 581 // This test was disabled because it made chrome_frame_net_tests hang |
| 582 // (see bug 102991). | 582 // (see bug 102991). |
| 583 TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) { | 583 TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) { |
| 584 ASSERT_TRUE(test_server_.Start()); | 584 ASSERT_TRUE(test_server_.Start()); |
| 585 | 585 |
| 586 TestNetworkDelegate network_delegate; // must outlive URLRequest | 586 TestNetworkDelegate network_delegate; // must outlive URLRequest |
| 587 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 587 TestURLRequestContext context(true); |
| 588 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 588 context.SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 589 context->set_network_delegate(&network_delegate); | 589 context.set_network_delegate(&network_delegate); |
| 590 context->Init(); | 590 context.Init(); |
| 591 | 591 |
| 592 TestDelegate d; | 592 TestDelegate d; |
| 593 { | 593 { |
| 594 URLRequest r(GURL("https://www.redirect.com/"), &d); | 594 URLRequest r(GURL("https://www.redirect.com/"), &d); |
| 595 r.set_context(context); | 595 r.set_context(&context); |
| 596 r.Start(); | 596 r.Start(); |
| 597 EXPECT_TRUE(r.is_pending()); | 597 EXPECT_TRUE(r.is_pending()); |
| 598 | 598 |
| 599 MessageLoop::current()->Run(); | 599 MessageLoop::current()->Run(); |
| 600 | 600 |
| 601 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 601 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 602 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 602 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 603 EXPECT_EQ(1, d.response_started_count()); | 603 EXPECT_EQ(1, d.response_started_count()); |
| 604 // We should not have followed the redirect. | 604 // We should not have followed the redirect. |
| 605 EXPECT_EQ(0, d.received_redirect_count()); | 605 EXPECT_EQ(0, d.received_redirect_count()); |
| 606 | 606 |
| 607 EXPECT_EQ(1, network_delegate.error_count()); | 607 EXPECT_EQ(1, network_delegate.error_count()); |
| 608 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); | 608 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); |
| 609 } | 609 } |
| 610 } | 610 } |
| 611 | 611 |
| 612 // Tests that the network delegate can block and cancel a request. | 612 // Tests that the network delegate can block and cancel a request. |
| 613 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { | 613 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { |
| 614 ASSERT_TRUE(test_server_.Start()); | 614 ASSERT_TRUE(test_server_.Start()); |
| 615 | 615 |
| 616 TestDelegate d; | 616 TestDelegate d; |
| 617 BlockingNetworkDelegate network_delegate; | 617 BlockingNetworkDelegate network_delegate; |
| 618 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); | 618 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); |
| 619 | 619 |
| 620 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 620 TestURLRequestContext context(true); |
| 621 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 621 context.SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 622 context->set_network_delegate(&network_delegate); | 622 context.set_network_delegate(&network_delegate); |
| 623 context->Init(); | 623 context.Init(); |
| 624 | 624 |
| 625 { | 625 { |
| 626 TestURLRequest r(test_server_.GetURL(""), &d); | 626 TestURLRequest r(test_server_.GetURL(""), &d); |
| 627 r.set_context(context); | 627 r.set_context(&context); |
| 628 | 628 |
| 629 r.Start(); | 629 r.Start(); |
| 630 MessageLoop::current()->Run(); | 630 MessageLoop::current()->Run(); |
| 631 | 631 |
| 632 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 632 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 633 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 633 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
| 634 EXPECT_EQ(1, network_delegate.created_requests()); | 634 EXPECT_EQ(1, network_delegate.created_requests()); |
| 635 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 635 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 636 } | 636 } |
| 637 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 637 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 638 } | 638 } |
| 639 | 639 |
| 640 // Tests that the network delegate can cancel a request synchronously. | 640 // Tests that the network delegate can cancel a request synchronously. |
| 641 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { | 641 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { |
| 642 ASSERT_TRUE(test_server_.Start()); | 642 ASSERT_TRUE(test_server_.Start()); |
| 643 | 643 |
| 644 TestDelegate d; | 644 TestDelegate d; |
| 645 BlockingNetworkDelegate network_delegate; | 645 BlockingNetworkDelegate network_delegate; |
| 646 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 646 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
| 647 | 647 |
| 648 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 648 TestURLRequestContext context(true); |
| 649 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 649 context.SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 650 context->set_network_delegate(&network_delegate); | 650 context.set_network_delegate(&network_delegate); |
| 651 context->Init(); | 651 context.Init(); |
| 652 | 652 |
| 653 { | 653 { |
| 654 TestURLRequest r(test_server_.GetURL(""), &d); | 654 TestURLRequest r(test_server_.GetURL(""), &d); |
| 655 r.set_context(context); | 655 r.set_context(&context); |
| 656 | 656 |
| 657 r.Start(); | 657 r.Start(); |
| 658 MessageLoop::current()->Run(); | 658 MessageLoop::current()->Run(); |
| 659 | 659 |
| 660 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 660 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 661 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 661 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
| 662 EXPECT_EQ(1, network_delegate.created_requests()); | 662 EXPECT_EQ(1, network_delegate.created_requests()); |
| 663 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 663 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 664 } | 664 } |
| 665 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 665 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 666 } | 666 } |
| 667 | 667 |
| 668 // Tests that the network delegate can block and redirect a request to a new | 668 // Tests that the network delegate can block and redirect a request to a new |
| 669 // URL. | 669 // URL. |
| 670 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { | 670 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { |
| 671 ASSERT_TRUE(test_server_.Start()); | 671 ASSERT_TRUE(test_server_.Start()); |
| 672 | 672 |
| 673 TestDelegate d; | 673 TestDelegate d; |
| 674 BlockingNetworkDelegate network_delegate; | 674 BlockingNetworkDelegate network_delegate; |
| 675 GURL redirect_url(test_server_.GetURL("simple.html")); | 675 GURL redirect_url(test_server_.GetURL("simple.html")); |
| 676 network_delegate.set_redirect_url(redirect_url); | 676 network_delegate.set_redirect_url(redirect_url); |
| 677 | 677 |
| 678 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 678 TestURLRequestContext context(true); |
| 679 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 679 context.SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 680 context->set_network_delegate(&network_delegate); | 680 context.set_network_delegate(&network_delegate); |
| 681 context->Init(); | 681 context.Init(); |
| 682 | 682 |
| 683 { | 683 { |
| 684 GURL original_url(test_server_.GetURL("empty.html")); | 684 GURL original_url(test_server_.GetURL("empty.html")); |
| 685 TestURLRequest r(original_url, &d); | 685 TestURLRequest r(original_url, &d); |
| 686 r.set_context(context); | 686 r.set_context(&context); |
| 687 | 687 |
| 688 r.Start(); | 688 r.Start(); |
| 689 MessageLoop::current()->Run(); | 689 MessageLoop::current()->Run(); |
| 690 | 690 |
| 691 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 691 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 692 EXPECT_EQ(0, r.status().error()); | 692 EXPECT_EQ(0, r.status().error()); |
| 693 EXPECT_EQ(redirect_url, r.url()); | 693 EXPECT_EQ(redirect_url, r.url()); |
| 694 EXPECT_EQ(original_url, r.original_url()); | 694 EXPECT_EQ(original_url, r.original_url()); |
| 695 EXPECT_EQ(2U, r.url_chain().size()); | 695 EXPECT_EQ(2U, r.url_chain().size()); |
| 696 EXPECT_EQ(1, network_delegate.created_requests()); | 696 EXPECT_EQ(1, network_delegate.created_requests()); |
| 697 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 697 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 698 } | 698 } |
| 699 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 699 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 700 } | 700 } |
| 701 | 701 |
| 702 // Tests that the network delegate can block and redirect a request to a new | 702 // Tests that the network delegate can block and redirect a request to a new |
| 703 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. | 703 // URL by setting a redirect_url and returning in OnBeforeURLRequest directly. |
| 704 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { | 704 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestSynchronously) { |
| 705 ASSERT_TRUE(test_server_.Start()); | 705 ASSERT_TRUE(test_server_.Start()); |
| 706 | 706 |
| 707 TestDelegate d; | 707 TestDelegate d; |
| 708 BlockingNetworkDelegate network_delegate; | 708 BlockingNetworkDelegate network_delegate; |
| 709 GURL redirect_url(test_server_.GetURL("simple.html")); | 709 GURL redirect_url(test_server_.GetURL("simple.html")); |
| 710 network_delegate.set_redirect_url(redirect_url); | 710 network_delegate.set_redirect_url(redirect_url); |
| 711 network_delegate.set_retval(OK); | 711 network_delegate.set_retval(OK); |
| 712 | 712 |
| 713 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 713 TestURLRequestContext context(true); |
| 714 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 714 context.SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 715 context->set_network_delegate(&network_delegate); | 715 context.set_network_delegate(&network_delegate); |
| 716 context->Init(); | 716 context.Init(); |
| 717 | 717 |
| 718 { | 718 { |
| 719 GURL original_url(test_server_.GetURL("empty.html")); | 719 GURL original_url(test_server_.GetURL("empty.html")); |
| 720 TestURLRequest r(original_url, &d); | 720 TestURLRequest r(original_url, &d); |
| 721 r.set_context(context); | 721 r.set_context(&context); |
| 722 | 722 |
| 723 r.Start(); | 723 r.Start(); |
| 724 MessageLoop::current()->Run(); | 724 MessageLoop::current()->Run(); |
| 725 | 725 |
| 726 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 726 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 727 EXPECT_EQ(0, r.status().error()); | 727 EXPECT_EQ(0, r.status().error()); |
| 728 EXPECT_EQ(redirect_url, r.url()); | 728 EXPECT_EQ(redirect_url, r.url()); |
| 729 EXPECT_EQ(original_url, r.original_url()); | 729 EXPECT_EQ(original_url, r.original_url()); |
| 730 EXPECT_EQ(2U, r.url_chain().size()); | 730 EXPECT_EQ(2U, r.url_chain().size()); |
| 731 EXPECT_EQ(1, network_delegate.created_requests()); | 731 EXPECT_EQ(1, network_delegate.created_requests()); |
| 732 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 732 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 733 } | 733 } |
| 734 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 734 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 735 } | 735 } |
| 736 | 736 |
| 737 // Tests that redirects caused by the network delegate preserve POST data. | 737 // Tests that redirects caused by the network delegate preserve POST data. |
| 738 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { | 738 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequestPost) { |
| 739 ASSERT_TRUE(test_server_.Start()); | 739 ASSERT_TRUE(test_server_.Start()); |
| 740 | 740 |
| 741 const char kData[] = "hello world"; | 741 const char kData[] = "hello world"; |
| 742 | 742 |
| 743 TestDelegate d; | 743 TestDelegate d; |
| 744 BlockingNetworkDelegate network_delegate; | 744 BlockingNetworkDelegate network_delegate; |
| 745 GURL redirect_url(test_server_.GetURL("echo")); | 745 GURL redirect_url(test_server_.GetURL("echo")); |
| 746 network_delegate.set_redirect_url(redirect_url); | 746 network_delegate.set_redirect_url(redirect_url); |
| 747 | 747 |
| 748 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 748 TestURLRequestContext context(true); |
| 749 context->set_network_delegate(&network_delegate); | 749 context.set_network_delegate(&network_delegate); |
| 750 context->Init(); | 750 context.Init(); |
| 751 | 751 |
| 752 { | 752 { |
| 753 GURL original_url(test_server_.GetURL("empty.html")); | 753 GURL original_url(test_server_.GetURL("empty.html")); |
| 754 TestURLRequest r(original_url, &d); | 754 TestURLRequest r(original_url, &d); |
| 755 r.set_context(context); | 755 r.set_context(&context); |
| 756 r.set_method("POST"); | 756 r.set_method("POST"); |
| 757 r.set_upload(CreateSimpleUploadData(kData).get()); | 757 r.set_upload(CreateSimpleUploadData(kData).get()); |
| 758 HttpRequestHeaders headers; | 758 HttpRequestHeaders headers; |
| 759 headers.SetHeader(HttpRequestHeaders::kContentLength, | 759 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 760 base::UintToString(arraysize(kData) - 1)); | 760 base::UintToString(arraysize(kData) - 1)); |
| 761 r.SetExtraRequestHeaders(headers); | 761 r.SetExtraRequestHeaders(headers); |
| 762 r.Start(); | 762 r.Start(); |
| 763 MessageLoop::current()->Run(); | 763 MessageLoop::current()->Run(); |
| 764 | 764 |
| 765 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 765 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 780 // handle the challenge, and is passing the buck along to the | 780 // handle the challenge, and is passing the buck along to the |
| 781 // URLRequest::Delegate. | 781 // URLRequest::Delegate. |
| 782 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { | 782 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncNoAction) { |
| 783 ASSERT_TRUE(test_server_.Start()); | 783 ASSERT_TRUE(test_server_.Start()); |
| 784 | 784 |
| 785 TestDelegate d; | 785 TestDelegate d; |
| 786 BlockingNetworkDelegate network_delegate; | 786 BlockingNetworkDelegate network_delegate; |
| 787 network_delegate.set_auth_retval( | 787 network_delegate.set_auth_retval( |
| 788 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); | 788 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); |
| 789 | 789 |
| 790 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 790 TestURLRequestContext context(true); |
| 791 context->set_network_delegate(&network_delegate); | 791 context.set_network_delegate(&network_delegate); |
| 792 context->Init(); | 792 context.Init(); |
| 793 | 793 |
| 794 d.set_credentials(AuthCredentials(kUser, kSecret)); | 794 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 795 | 795 |
| 796 { | 796 { |
| 797 GURL url(test_server_.GetURL("auth-basic")); | 797 GURL url(test_server_.GetURL("auth-basic")); |
| 798 TestURLRequest r(url, &d); | 798 TestURLRequest r(url, &d); |
| 799 r.set_context(context); | 799 r.set_context(&context); |
| 800 r.Start(); | 800 r.Start(); |
| 801 MessageLoop::current()->Run(); | 801 MessageLoop::current()->Run(); |
| 802 | 802 |
| 803 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 803 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 804 EXPECT_EQ(0, r.status().error()); | 804 EXPECT_EQ(0, r.status().error()); |
| 805 EXPECT_EQ(200, r.GetResponseCode()); | 805 EXPECT_EQ(200, r.GetResponseCode()); |
| 806 EXPECT_TRUE(d.auth_required_called()); | 806 EXPECT_TRUE(d.auth_required_called()); |
| 807 EXPECT_EQ(1, network_delegate.created_requests()); | 807 EXPECT_EQ(1, network_delegate.created_requests()); |
| 808 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 808 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 809 } | 809 } |
| 810 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 810 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 811 } | 811 } |
| 812 | 812 |
| 813 // Tests that the network delegate can synchronously complete OnAuthRequired | 813 // Tests that the network delegate can synchronously complete OnAuthRequired |
| 814 // by setting credentials. | 814 // by setting credentials. |
| 815 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { | 815 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncSetAuth) { |
| 816 ASSERT_TRUE(test_server_.Start()); | 816 ASSERT_TRUE(test_server_.Start()); |
| 817 | 817 |
| 818 TestDelegate d; | 818 TestDelegate d; |
| 819 BlockingNetworkDelegate network_delegate; | 819 BlockingNetworkDelegate network_delegate; |
| 820 network_delegate.set_auth_retval( | 820 network_delegate.set_auth_retval( |
| 821 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 821 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 822 | 822 |
| 823 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 823 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 824 | 824 |
| 825 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 825 TestURLRequestContext context(true); |
| 826 context->set_network_delegate(&network_delegate); | 826 context.set_network_delegate(&network_delegate); |
| 827 context->Init(); | 827 context.Init(); |
| 828 | 828 |
| 829 { | 829 { |
| 830 GURL url(test_server_.GetURL("auth-basic")); | 830 GURL url(test_server_.GetURL("auth-basic")); |
| 831 TestURLRequest r(url, &d); | 831 TestURLRequest r(url, &d); |
| 832 r.set_context(context); | 832 r.set_context(&context); |
| 833 r.Start(); | 833 r.Start(); |
| 834 MessageLoop::current()->Run(); | 834 MessageLoop::current()->Run(); |
| 835 | 835 |
| 836 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 836 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 837 EXPECT_EQ(0, r.status().error()); | 837 EXPECT_EQ(0, r.status().error()); |
| 838 EXPECT_EQ(200, r.GetResponseCode()); | 838 EXPECT_EQ(200, r.GetResponseCode()); |
| 839 EXPECT_FALSE(d.auth_required_called()); | 839 EXPECT_FALSE(d.auth_required_called()); |
| 840 EXPECT_EQ(1, network_delegate.created_requests()); | 840 EXPECT_EQ(1, network_delegate.created_requests()); |
| 841 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 841 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 842 } | 842 } |
| 843 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 843 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 844 } | 844 } |
| 845 | 845 |
| 846 // Tests that the network delegate can synchronously complete OnAuthRequired | 846 // Tests that the network delegate can synchronously complete OnAuthRequired |
| 847 // by cancelling authentication. | 847 // by cancelling authentication. |
| 848 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { | 848 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { |
| 849 ASSERT_TRUE(test_server_.Start()); | 849 ASSERT_TRUE(test_server_.Start()); |
| 850 | 850 |
| 851 TestDelegate d; | 851 TestDelegate d; |
| 852 BlockingNetworkDelegate network_delegate; | 852 BlockingNetworkDelegate network_delegate; |
| 853 network_delegate.set_auth_retval( | 853 network_delegate.set_auth_retval( |
| 854 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 854 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 855 | 855 |
| 856 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 856 TestURLRequestContext context(true); |
| 857 context->set_network_delegate(&network_delegate); | 857 context.set_network_delegate(&network_delegate); |
| 858 context->Init(); | 858 context.Init(); |
| 859 | 859 |
| 860 { | 860 { |
| 861 GURL url(test_server_.GetURL("auth-basic")); | 861 GURL url(test_server_.GetURL("auth-basic")); |
| 862 TestURLRequest r(url, &d); | 862 TestURLRequest r(url, &d); |
| 863 r.set_context(context); | 863 r.set_context(&context); |
| 864 r.Start(); | 864 r.Start(); |
| 865 MessageLoop::current()->Run(); | 865 MessageLoop::current()->Run(); |
| 866 | 866 |
| 867 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 867 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 868 EXPECT_EQ(OK, r.status().error()); | 868 EXPECT_EQ(OK, r.status().error()); |
| 869 EXPECT_EQ(401, r.GetResponseCode()); | 869 EXPECT_EQ(401, r.GetResponseCode()); |
| 870 EXPECT_FALSE(d.auth_required_called()); | 870 EXPECT_FALSE(d.auth_required_called()); |
| 871 EXPECT_EQ(1, network_delegate.created_requests()); | 871 EXPECT_EQ(1, network_delegate.created_requests()); |
| 872 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 872 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 873 } | 873 } |
| 874 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 874 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 875 } | 875 } |
| 876 | 876 |
| 877 // Tests that the network delegate can asynchronously complete OnAuthRequired | 877 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 878 // by taking no action. This indicates that the NetworkDelegate does not want | 878 // by taking no action. This indicates that the NetworkDelegate does not want |
| 879 // to handle the challenge, and is passing the buck along to the | 879 // to handle the challenge, and is passing the buck along to the |
| 880 // URLRequest::Delegate. | 880 // URLRequest::Delegate. |
| 881 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { | 881 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncNoAction) { |
| 882 ASSERT_TRUE(test_server_.Start()); | 882 ASSERT_TRUE(test_server_.Start()); |
| 883 | 883 |
| 884 TestDelegate d; | 884 TestDelegate d; |
| 885 BlockingNetworkDelegate network_delegate; | 885 BlockingNetworkDelegate network_delegate; |
| 886 network_delegate.set_auth_retval( | 886 network_delegate.set_auth_retval( |
| 887 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); | 887 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); |
| 888 network_delegate.set_auth_callback_retval( | 888 network_delegate.set_auth_callback_retval( |
| 889 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); | 889 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); |
| 890 | 890 |
| 891 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 891 TestURLRequestContext context(true); |
| 892 context->set_network_delegate(&network_delegate); | 892 context.set_network_delegate(&network_delegate); |
| 893 context->Init(); | 893 context.Init(); |
| 894 | 894 |
| 895 d.set_credentials(AuthCredentials(kUser, kSecret)); | 895 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 896 | 896 |
| 897 { | 897 { |
| 898 GURL url(test_server_.GetURL("auth-basic")); | 898 GURL url(test_server_.GetURL("auth-basic")); |
| 899 TestURLRequest r(url, &d); | 899 TestURLRequest r(url, &d); |
| 900 r.set_context(context); | 900 r.set_context(&context); |
| 901 r.Start(); | 901 r.Start(); |
| 902 MessageLoop::current()->Run(); | 902 MessageLoop::current()->Run(); |
| 903 | 903 |
| 904 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 904 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 905 EXPECT_EQ(0, r.status().error()); | 905 EXPECT_EQ(0, r.status().error()); |
| 906 EXPECT_EQ(200, r.GetResponseCode()); | 906 EXPECT_EQ(200, r.GetResponseCode()); |
| 907 EXPECT_TRUE(d.auth_required_called()); | 907 EXPECT_TRUE(d.auth_required_called()); |
| 908 EXPECT_EQ(1, network_delegate.created_requests()); | 908 EXPECT_EQ(1, network_delegate.created_requests()); |
| 909 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 909 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 910 } | 910 } |
| 911 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 911 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 912 } | 912 } |
| 913 | 913 |
| 914 // Tests that the network delegate can asynchronously complete OnAuthRequired | 914 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 915 // by setting credentials. | 915 // by setting credentials. |
| 916 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { | 916 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncSetAuth) { |
| 917 ASSERT_TRUE(test_server_.Start()); | 917 ASSERT_TRUE(test_server_.Start()); |
| 918 | 918 |
| 919 TestDelegate d; | 919 TestDelegate d; |
| 920 BlockingNetworkDelegate network_delegate; | 920 BlockingNetworkDelegate network_delegate; |
| 921 network_delegate.set_auth_retval( | 921 network_delegate.set_auth_retval( |
| 922 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); | 922 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); |
| 923 network_delegate.set_auth_callback_retval( | 923 network_delegate.set_auth_callback_retval( |
| 924 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 924 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 925 | 925 |
| 926 AuthCredentials auth_credentials(kUser, kSecret); | 926 AuthCredentials auth_credentials(kUser, kSecret); |
| 927 network_delegate.set_auth_credentials(auth_credentials); | 927 network_delegate.set_auth_credentials(auth_credentials); |
| 928 | 928 |
| 929 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 929 TestURLRequestContext context(true); |
| 930 context->set_network_delegate(&network_delegate); | 930 context.set_network_delegate(&network_delegate); |
| 931 context->Init(); | 931 context.Init(); |
| 932 | 932 |
| 933 { | 933 { |
| 934 GURL url(test_server_.GetURL("auth-basic")); | 934 GURL url(test_server_.GetURL("auth-basic")); |
| 935 TestURLRequest r(url, &d); | 935 TestURLRequest r(url, &d); |
| 936 r.set_context(context); | 936 r.set_context(&context); |
| 937 r.Start(); | 937 r.Start(); |
| 938 MessageLoop::current()->Run(); | 938 MessageLoop::current()->Run(); |
| 939 | 939 |
| 940 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 940 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 941 EXPECT_EQ(0, r.status().error()); | 941 EXPECT_EQ(0, r.status().error()); |
| 942 | 942 |
| 943 EXPECT_EQ(200, r.GetResponseCode()); | 943 EXPECT_EQ(200, r.GetResponseCode()); |
| 944 EXPECT_FALSE(d.auth_required_called()); | 944 EXPECT_FALSE(d.auth_required_called()); |
| 945 EXPECT_EQ(1, network_delegate.created_requests()); | 945 EXPECT_EQ(1, network_delegate.created_requests()); |
| 946 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 946 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 947 } | 947 } |
| 948 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 948 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 949 } | 949 } |
| 950 | 950 |
| 951 // Tests that the network delegate can asynchronously complete OnAuthRequired | 951 // Tests that the network delegate can asynchronously complete OnAuthRequired |
| 952 // by cancelling authentication. | 952 // by cancelling authentication. |
| 953 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { | 953 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredAsyncCancel) { |
| 954 ASSERT_TRUE(test_server_.Start()); | 954 ASSERT_TRUE(test_server_.Start()); |
| 955 | 955 |
| 956 TestDelegate d; | 956 TestDelegate d; |
| 957 BlockingNetworkDelegate network_delegate; | 957 BlockingNetworkDelegate network_delegate; |
| 958 network_delegate.set_auth_retval( | 958 network_delegate.set_auth_retval( |
| 959 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); | 959 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); |
| 960 network_delegate.set_auth_callback_retval( | 960 network_delegate.set_auth_callback_retval( |
| 961 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 961 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 962 | 962 |
| 963 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 963 TestURLRequestContext context(true); |
| 964 context->set_network_delegate(&network_delegate); | 964 context.set_network_delegate(&network_delegate); |
| 965 context->Init(); | 965 context.Init(); |
| 966 | 966 |
| 967 { | 967 { |
| 968 GURL url(test_server_.GetURL("auth-basic")); | 968 GURL url(test_server_.GetURL("auth-basic")); |
| 969 TestURLRequest r(url, &d); | 969 TestURLRequest r(url, &d); |
| 970 r.set_context(context); | 970 r.set_context(&context); |
| 971 r.Start(); | 971 r.Start(); |
| 972 MessageLoop::current()->Run(); | 972 MessageLoop::current()->Run(); |
| 973 | 973 |
| 974 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 974 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 975 EXPECT_EQ(OK, r.status().error()); | 975 EXPECT_EQ(OK, r.status().error()); |
| 976 EXPECT_EQ(401, r.GetResponseCode()); | 976 EXPECT_EQ(401, r.GetResponseCode()); |
| 977 EXPECT_FALSE(d.auth_required_called()); | 977 EXPECT_FALSE(d.auth_required_called()); |
| 978 EXPECT_EQ(1, network_delegate.created_requests()); | 978 EXPECT_EQ(1, network_delegate.created_requests()); |
| 979 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 979 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 980 } | 980 } |
| 981 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 981 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 982 } | 982 } |
| 983 | 983 |
| 984 // Tests that we can handle when a network request was canceled while we were | 984 // Tests that we can handle when a network request was canceled while we were |
| 985 // waiting for the network delegate. | 985 // waiting for the network delegate. |
| 986 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. | 986 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. |
| 987 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { | 987 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { |
| 988 ASSERT_TRUE(test_server_.Start()); | 988 ASSERT_TRUE(test_server_.Start()); |
| 989 | 989 |
| 990 TestDelegate d; | 990 TestDelegate d; |
| 991 BlockingNetworkDelegateWithManualCallback network_delegate; | 991 BlockingNetworkDelegateWithManualCallback network_delegate; |
| 992 network_delegate.BlockOn( | 992 network_delegate.BlockOn( |
| 993 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); | 993 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); |
| 994 | 994 |
| 995 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 995 TestURLRequestContext context(true); |
| 996 context->set_network_delegate(&network_delegate); | 996 context.set_network_delegate(&network_delegate); |
| 997 context->Init(); | 997 context.Init(); |
| 998 | 998 |
| 999 { | 999 { |
| 1000 TestURLRequest r(test_server_.GetURL(""), &d); | 1000 TestURLRequest r(test_server_.GetURL(""), &d); |
| 1001 r.set_context(context); | 1001 r.set_context(&context); |
| 1002 | 1002 |
| 1003 r.Start(); | 1003 r.Start(); |
| 1004 network_delegate.WaitForState( | 1004 network_delegate.WaitForState( |
| 1005 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); | 1005 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); |
| 1006 EXPECT_EQ(0, network_delegate.completed_requests()); | 1006 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 1007 // Cancel before callback. | 1007 // Cancel before callback. |
| 1008 r.Cancel(); | 1008 r.Cancel(); |
| 1009 // Ensure that network delegate is notified. | 1009 // Ensure that network delegate is notified. |
| 1010 EXPECT_EQ(1, network_delegate.completed_requests()); | 1010 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 1011 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 1011 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 1012 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 1012 EXPECT_EQ(ERR_ABORTED, r.status().error()); |
| 1013 EXPECT_EQ(1, network_delegate.created_requests()); | 1013 EXPECT_EQ(1, network_delegate.created_requests()); |
| 1014 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 1014 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 1015 } | 1015 } |
| 1016 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 1016 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 1017 } | 1017 } |
| 1018 | 1018 |
| 1019 // Tests that we can handle when a network request was canceled while we were | 1019 // Tests that we can handle when a network request was canceled while we were |
| 1020 // waiting for the network delegate. | 1020 // waiting for the network delegate. |
| 1021 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback. | 1021 // Part 2: Request is cancelled while waiting for OnBeforeSendHeaders callback. |
| 1022 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { | 1022 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting2) { |
| 1023 ASSERT_TRUE(test_server_.Start()); | 1023 ASSERT_TRUE(test_server_.Start()); |
| 1024 | 1024 |
| 1025 TestDelegate d; | 1025 TestDelegate d; |
| 1026 BlockingNetworkDelegateWithManualCallback network_delegate; | 1026 BlockingNetworkDelegateWithManualCallback network_delegate; |
| 1027 network_delegate.BlockOn( | 1027 network_delegate.BlockOn( |
| 1028 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); | 1028 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); |
| 1029 | 1029 |
| 1030 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1030 TestURLRequestContext context(true); |
| 1031 context->set_network_delegate(&network_delegate); | 1031 context.set_network_delegate(&network_delegate); |
| 1032 context->Init(); | 1032 context.Init(); |
| 1033 | 1033 |
| 1034 { | 1034 { |
| 1035 TestURLRequest r(test_server_.GetURL(""), &d); | 1035 TestURLRequest r(test_server_.GetURL(""), &d); |
| 1036 r.set_context(context); | 1036 r.set_context(&context); |
| 1037 | 1037 |
| 1038 r.Start(); | 1038 r.Start(); |
| 1039 network_delegate.WaitForState( | 1039 network_delegate.WaitForState( |
| 1040 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); | 1040 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); |
| 1041 EXPECT_EQ(0, network_delegate.completed_requests()); | 1041 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 1042 // Cancel before callback. | 1042 // Cancel before callback. |
| 1043 r.Cancel(); | 1043 r.Cancel(); |
| 1044 // Ensure that network delegate is notified. | 1044 // Ensure that network delegate is notified. |
| 1045 EXPECT_EQ(1, network_delegate.completed_requests()); | 1045 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 1046 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 1046 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 1047 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 1047 EXPECT_EQ(ERR_ABORTED, r.status().error()); |
| 1048 EXPECT_EQ(1, network_delegate.created_requests()); | 1048 EXPECT_EQ(1, network_delegate.created_requests()); |
| 1049 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 1049 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 1050 } | 1050 } |
| 1051 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 1051 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 1052 } | 1052 } |
| 1053 | 1053 |
| 1054 // Tests that we can handle when a network request was canceled while we were | 1054 // Tests that we can handle when a network request was canceled while we were |
| 1055 // waiting for the network delegate. | 1055 // waiting for the network delegate. |
| 1056 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. | 1056 // Part 3: Request is cancelled while waiting for OnHeadersReceived callback. |
| 1057 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { | 1057 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting3) { |
| 1058 ASSERT_TRUE(test_server_.Start()); | 1058 ASSERT_TRUE(test_server_.Start()); |
| 1059 | 1059 |
| 1060 TestDelegate d; | 1060 TestDelegate d; |
| 1061 BlockingNetworkDelegateWithManualCallback network_delegate; | 1061 BlockingNetworkDelegateWithManualCallback network_delegate; |
| 1062 network_delegate.BlockOn( | 1062 network_delegate.BlockOn( |
| 1063 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); | 1063 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); |
| 1064 | 1064 |
| 1065 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1065 TestURLRequestContext context(true); |
| 1066 context->set_network_delegate(&network_delegate); | 1066 context.set_network_delegate(&network_delegate); |
| 1067 context->Init(); | 1067 context.Init(); |
| 1068 | 1068 |
| 1069 { | 1069 { |
| 1070 TestURLRequest r(test_server_.GetURL(""), &d); | 1070 TestURLRequest r(test_server_.GetURL(""), &d); |
| 1071 r.set_context(context); | 1071 r.set_context(&context); |
| 1072 | 1072 |
| 1073 r.Start(); | 1073 r.Start(); |
| 1074 network_delegate.WaitForState( | 1074 network_delegate.WaitForState( |
| 1075 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); | 1075 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); |
| 1076 EXPECT_EQ(0, network_delegate.completed_requests()); | 1076 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 1077 // Cancel before callback. | 1077 // Cancel before callback. |
| 1078 r.Cancel(); | 1078 r.Cancel(); |
| 1079 // Ensure that network delegate is notified. | 1079 // Ensure that network delegate is notified. |
| 1080 EXPECT_EQ(1, network_delegate.completed_requests()); | 1080 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 1081 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 1081 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 1082 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 1082 EXPECT_EQ(ERR_ABORTED, r.status().error()); |
| 1083 EXPECT_EQ(1, network_delegate.created_requests()); | 1083 EXPECT_EQ(1, network_delegate.created_requests()); |
| 1084 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 1084 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 1085 } | 1085 } |
| 1086 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 1086 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 1087 } | 1087 } |
| 1088 | 1088 |
| 1089 // Tests that we can handle when a network request was canceled while we were | 1089 // Tests that we can handle when a network request was canceled while we were |
| 1090 // waiting for the network delegate. | 1090 // waiting for the network delegate. |
| 1091 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. | 1091 // Part 4: Request is cancelled while waiting for OnAuthRequired callback. |
| 1092 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { | 1092 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting4) { |
| 1093 ASSERT_TRUE(test_server_.Start()); | 1093 ASSERT_TRUE(test_server_.Start()); |
| 1094 | 1094 |
| 1095 TestDelegate d; | 1095 TestDelegate d; |
| 1096 BlockingNetworkDelegateWithManualCallback network_delegate; | 1096 BlockingNetworkDelegateWithManualCallback network_delegate; |
| 1097 network_delegate.BlockOn( | 1097 network_delegate.BlockOn( |
| 1098 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); | 1098 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); |
| 1099 | 1099 |
| 1100 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1100 TestURLRequestContext context(true); |
| 1101 context->set_network_delegate(&network_delegate); | 1101 context.set_network_delegate(&network_delegate); |
| 1102 context->Init(); | 1102 context.Init(); |
| 1103 | 1103 |
| 1104 { | 1104 { |
| 1105 TestURLRequest r(test_server_.GetURL("auth-basic"), &d); | 1105 TestURLRequest r(test_server_.GetURL("auth-basic"), &d); |
| 1106 r.set_context(context); | 1106 r.set_context(&context); |
| 1107 | 1107 |
| 1108 r.Start(); | 1108 r.Start(); |
| 1109 network_delegate.WaitForState( | 1109 network_delegate.WaitForState( |
| 1110 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); | 1110 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); |
| 1111 EXPECT_EQ(0, network_delegate.completed_requests()); | 1111 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 1112 // Cancel before callback. | 1112 // Cancel before callback. |
| 1113 r.Cancel(); | 1113 r.Cancel(); |
| 1114 // Ensure that network delegate is notified. | 1114 // Ensure that network delegate is notified. |
| 1115 EXPECT_EQ(1, network_delegate.completed_requests()); | 1115 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 1116 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 1116 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 1117 EXPECT_EQ(ERR_ABORTED, r.status().error()); | 1117 EXPECT_EQ(ERR_ABORTED, r.status().error()); |
| 1118 EXPECT_EQ(1, network_delegate.created_requests()); | 1118 EXPECT_EQ(1, network_delegate.created_requests()); |
| 1119 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 1119 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 1120 } | 1120 } |
| 1121 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 1121 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 1122 } | 1122 } |
| 1123 | 1123 |
| 1124 // In this unit test, we're using the HTTPTestServer as a proxy server and | 1124 // In this unit test, we're using the HTTPTestServer as a proxy server and |
| 1125 // issuing a CONNECT request with the magic host name "www.server-auth.com". | 1125 // issuing a CONNECT request with the magic host name "www.server-auth.com". |
| 1126 // The HTTPTestServer will return a 401 response, which we should balk at. | 1126 // The HTTPTestServer will return a 401 response, which we should balk at. |
| 1127 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 1127 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
| 1128 ASSERT_TRUE(test_server_.Start()); | 1128 ASSERT_TRUE(test_server_.Start()); |
| 1129 | 1129 |
| 1130 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1130 TestNetworkDelegate network_delegate; // must outlive URLRequest |
| 1131 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1131 TestURLRequestContext context(true); |
| 1132 context->SetProxyFromString(test_server_.host_port_pair().ToString()); | 1132 context.SetProxyFromString(test_server_.host_port_pair().ToString()); |
| 1133 context->set_network_delegate(&network_delegate); | 1133 context.set_network_delegate(&network_delegate); |
| 1134 context->Init(); | 1134 context.Init(); |
| 1135 | 1135 |
| 1136 TestDelegate d; | 1136 TestDelegate d; |
| 1137 { | 1137 { |
| 1138 URLRequest r(GURL("https://www.server-auth.com/"), &d); | 1138 URLRequest r(GURL("https://www.server-auth.com/"), &d); |
| 1139 r.set_context(context); | 1139 r.set_context(&context); |
| 1140 | 1140 |
| 1141 r.Start(); | 1141 r.Start(); |
| 1142 EXPECT_TRUE(r.is_pending()); | 1142 EXPECT_TRUE(r.is_pending()); |
| 1143 | 1143 |
| 1144 MessageLoop::current()->Run(); | 1144 MessageLoop::current()->Run(); |
| 1145 | 1145 |
| 1146 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 1146 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 1147 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 1147 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
| 1148 } | 1148 } |
| 1149 } | 1149 } |
| 1150 | 1150 |
| 1151 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 1151 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
| 1152 ASSERT_TRUE(test_server_.Start()); | 1152 ASSERT_TRUE(test_server_.Start()); |
| 1153 | 1153 |
| 1154 TestDelegate d; | 1154 TestDelegate d; |
| 1155 { | 1155 { |
| 1156 TestURLRequest r(test_server_.GetURL(""), &d); | 1156 TestURLRequest r(test_server_.GetURL(""), &d); |
| 1157 r.set_context(default_context_); | 1157 r.set_context(&default_context_); |
| 1158 | 1158 |
| 1159 r.Start(); | 1159 r.Start(); |
| 1160 EXPECT_TRUE(r.is_pending()); | 1160 EXPECT_TRUE(r.is_pending()); |
| 1161 | 1161 |
| 1162 MessageLoop::current()->Run(); | 1162 MessageLoop::current()->Run(); |
| 1163 | 1163 |
| 1164 EXPECT_EQ(1, d.response_started_count()); | 1164 EXPECT_EQ(1, d.response_started_count()); |
| 1165 EXPECT_FALSE(d.received_data_before_response()); | 1165 EXPECT_FALSE(d.received_data_before_response()); |
| 1166 EXPECT_NE(0, d.bytes_received()); | 1166 EXPECT_NE(0, d.bytes_received()); |
| 1167 EXPECT_EQ(test_server_.host_port_pair().host(), | 1167 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 1168 r.GetSocketAddress().host()); | 1168 r.GetSocketAddress().host()); |
| 1169 EXPECT_EQ(test_server_.host_port_pair().port(), | 1169 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 1170 r.GetSocketAddress().port()); | 1170 r.GetSocketAddress().port()); |
| 1171 | 1171 |
| 1172 // TODO(eroman): Add back the NetLog tests... | 1172 // TODO(eroman): Add back the NetLog tests... |
| 1173 } | 1173 } |
| 1174 } | 1174 } |
| 1175 | 1175 |
| 1176 TEST_F(URLRequestTestHTTP, GetTest) { | 1176 TEST_F(URLRequestTestHTTP, GetTest) { |
| 1177 ASSERT_TRUE(test_server_.Start()); | 1177 ASSERT_TRUE(test_server_.Start()); |
| 1178 | 1178 |
| 1179 TestDelegate d; | 1179 TestDelegate d; |
| 1180 { | 1180 { |
| 1181 TestURLRequest r(test_server_.GetURL(""), &d); | 1181 TestURLRequest r(test_server_.GetURL(""), &d); |
| 1182 r.set_context(default_context_); | 1182 r.set_context(&default_context_); |
| 1183 | 1183 |
| 1184 r.Start(); | 1184 r.Start(); |
| 1185 EXPECT_TRUE(r.is_pending()); | 1185 EXPECT_TRUE(r.is_pending()); |
| 1186 | 1186 |
| 1187 MessageLoop::current()->Run(); | 1187 MessageLoop::current()->Run(); |
| 1188 | 1188 |
| 1189 EXPECT_EQ(1, d.response_started_count()); | 1189 EXPECT_EQ(1, d.response_started_count()); |
| 1190 EXPECT_FALSE(d.received_data_before_response()); | 1190 EXPECT_FALSE(d.received_data_before_response()); |
| 1191 EXPECT_NE(0, d.bytes_received()); | 1191 EXPECT_NE(0, d.bytes_received()); |
| 1192 EXPECT_EQ(test_server_.host_port_pair().host(), | 1192 EXPECT_EQ(test_server_.host_port_pair().host(), |
| (...skipping 21 matching lines...) Expand all Loading... |
| 1214 { true, true, false, false, true }; | 1214 { true, true, false, false, true }; |
| 1215 | 1215 |
| 1216 for (int i = 0; i < num_tests ; i++) { | 1216 for (int i = 0; i < num_tests ; i++) { |
| 1217 TestDelegate d; | 1217 TestDelegate d; |
| 1218 { | 1218 { |
| 1219 std::string test_file = | 1219 std::string test_file = |
| 1220 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", | 1220 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", |
| 1221 test_parameters[i]); | 1221 test_parameters[i]); |
| 1222 | 1222 |
| 1223 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1223 TestNetworkDelegate network_delegate; // must outlive URLRequest |
| 1224 scoped_refptr<TestURLRequestContext> context( | 1224 TestURLRequestContext context(true); |
| 1225 new TestURLRequestContext(true)); | 1225 context.set_network_delegate(&network_delegate); |
| 1226 context->set_network_delegate(&network_delegate); | 1226 context.Init(); |
| 1227 context->Init(); | |
| 1228 | 1227 |
| 1229 TestURLRequest r(test_server_.GetURL(test_file), &d); | 1228 TestURLRequest r(test_server_.GetURL(test_file), &d); |
| 1230 r.set_context(context); | 1229 r.set_context(&context); |
| 1231 r.Start(); | 1230 r.Start(); |
| 1232 EXPECT_TRUE(r.is_pending()); | 1231 EXPECT_TRUE(r.is_pending()); |
| 1233 | 1232 |
| 1234 MessageLoop::current()->Run(); | 1233 MessageLoop::current()->Run(); |
| 1235 | 1234 |
| 1236 EXPECT_EQ(1, d.response_started_count()); | 1235 EXPECT_EQ(1, d.response_started_count()); |
| 1237 EXPECT_FALSE(d.received_data_before_response()); | 1236 EXPECT_FALSE(d.received_data_before_response()); |
| 1238 VLOG(1) << " Received " << d.bytes_received() << " bytes" | 1237 VLOG(1) << " Received " << d.bytes_received() << " bytes" |
| 1239 << " status = " << r.status().status() | 1238 << " status = " << r.status().status() |
| 1240 << " error = " << r.status().error(); | 1239 << " error = " << r.status().error(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 1260 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1259 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1261 ASSERT_TRUE(https_test_server.Start()); | 1260 ASSERT_TRUE(https_test_server.Start()); |
| 1262 | 1261 |
| 1263 // An https server is sent a request with an https referer, | 1262 // An https server is sent a request with an https referer, |
| 1264 // and responds with a redirect to an http url. The http | 1263 // and responds with a redirect to an http url. The http |
| 1265 // server should not be sent the referer. | 1264 // server should not be sent the referer. |
| 1266 GURL http_destination = test_server_.GetURL(""); | 1265 GURL http_destination = test_server_.GetURL(""); |
| 1267 TestDelegate d; | 1266 TestDelegate d; |
| 1268 TestURLRequest req(https_test_server.GetURL( | 1267 TestURLRequest req(https_test_server.GetURL( |
| 1269 "server-redirect?" + http_destination.spec()), &d); | 1268 "server-redirect?" + http_destination.spec()), &d); |
| 1270 req.set_context(default_context_); | 1269 req.set_context(&default_context_); |
| 1271 req.set_referrer("https://www.referrer.com/"); | 1270 req.set_referrer("https://www.referrer.com/"); |
| 1272 req.Start(); | 1271 req.Start(); |
| 1273 MessageLoop::current()->Run(); | 1272 MessageLoop::current()->Run(); |
| 1274 | 1273 |
| 1275 EXPECT_EQ(1, d.response_started_count()); | 1274 EXPECT_EQ(1, d.response_started_count()); |
| 1276 EXPECT_EQ(1, d.received_redirect_count()); | 1275 EXPECT_EQ(1, d.received_redirect_count()); |
| 1277 EXPECT_EQ(http_destination, req.url()); | 1276 EXPECT_EQ(http_destination, req.url()); |
| 1278 EXPECT_EQ(std::string(), req.referrer()); | 1277 EXPECT_EQ(std::string(), req.referrer()); |
| 1279 } | 1278 } |
| 1280 | 1279 |
| 1281 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { | 1280 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { |
| 1282 ASSERT_TRUE(test_server_.Start()); | 1281 ASSERT_TRUE(test_server_.Start()); |
| 1283 | 1282 |
| 1284 GURL destination_url = test_server_.GetURL(""); | 1283 GURL destination_url = test_server_.GetURL(""); |
| 1285 GURL middle_redirect_url = test_server_.GetURL( | 1284 GURL middle_redirect_url = test_server_.GetURL( |
| 1286 "server-redirect?" + destination_url.spec()); | 1285 "server-redirect?" + destination_url.spec()); |
| 1287 GURL original_url = test_server_.GetURL( | 1286 GURL original_url = test_server_.GetURL( |
| 1288 "server-redirect?" + middle_redirect_url.spec()); | 1287 "server-redirect?" + middle_redirect_url.spec()); |
| 1289 TestDelegate d; | 1288 TestDelegate d; |
| 1290 TestURLRequest req(original_url, &d); | 1289 TestURLRequest req(original_url, &d); |
| 1291 req.set_context(default_context_); | 1290 req.set_context(&default_context_); |
| 1292 req.Start(); | 1291 req.Start(); |
| 1293 MessageLoop::current()->Run(); | 1292 MessageLoop::current()->Run(); |
| 1294 | 1293 |
| 1295 EXPECT_EQ(1, d.response_started_count()); | 1294 EXPECT_EQ(1, d.response_started_count()); |
| 1296 EXPECT_EQ(2, d.received_redirect_count()); | 1295 EXPECT_EQ(2, d.received_redirect_count()); |
| 1297 EXPECT_EQ(destination_url, req.url()); | 1296 EXPECT_EQ(destination_url, req.url()); |
| 1298 EXPECT_EQ(original_url, req.original_url()); | 1297 EXPECT_EQ(original_url, req.original_url()); |
| 1299 ASSERT_EQ(3U, req.url_chain().size()); | 1298 ASSERT_EQ(3U, req.url_chain().size()); |
| 1300 EXPECT_EQ(original_url, req.url_chain()[0]); | 1299 EXPECT_EQ(original_url, req.url_chain()[0]); |
| 1301 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); | 1300 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); |
| 1302 EXPECT_EQ(destination_url, req.url_chain()[2]); | 1301 EXPECT_EQ(destination_url, req.url_chain()[2]); |
| 1303 } | 1302 } |
| 1304 | 1303 |
| 1305 class HTTPSRequestTest : public testing::Test { | 1304 class HTTPSRequestTest : public testing::Test { |
| 1306 public: | 1305 public: |
| 1307 HTTPSRequestTest() : default_context_(new TestURLRequestContext(true)) { | 1306 HTTPSRequestTest() : default_context_(true) { |
| 1308 default_context_->set_network_delegate(&default_network_delegate_); | 1307 default_context_.set_network_delegate(&default_network_delegate_); |
| 1309 default_context_->Init(); | 1308 default_context_.Init(); |
| 1310 } | 1309 } |
| 1311 virtual ~HTTPSRequestTest() {} | 1310 virtual ~HTTPSRequestTest() {} |
| 1312 | 1311 |
| 1313 protected: | 1312 protected: |
| 1314 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest | 1313 TestNetworkDelegate default_network_delegate_; // must outlive URLRequest |
| 1315 scoped_refptr<TestURLRequestContext> default_context_; | 1314 TestURLRequestContext default_context_; |
| 1316 }; | 1315 }; |
| 1317 | 1316 |
| 1318 // This test was disabled because it made chrome_frame_net_tests hang | 1317 // This test was disabled because it made chrome_frame_net_tests hang |
| 1319 // (see bug 102991). | 1318 // (see bug 102991). |
| 1320 TEST_F(HTTPSRequestTest, DISABLED_HTTPSGetTest) { | 1319 TEST_F(HTTPSRequestTest, DISABLED_HTTPSGetTest) { |
| 1321 TestServer test_server(TestServer::TYPE_HTTPS, | 1320 TestServer test_server(TestServer::TYPE_HTTPS, |
| 1322 TestServer::kLocalhost, | 1321 TestServer::kLocalhost, |
| 1323 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1322 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1324 ASSERT_TRUE(test_server.Start()); | 1323 ASSERT_TRUE(test_server.Start()); |
| 1325 | 1324 |
| 1326 TestDelegate d; | 1325 TestDelegate d; |
| 1327 { | 1326 { |
| 1328 TestURLRequest r(test_server.GetURL(""), &d); | 1327 TestURLRequest r(test_server.GetURL(""), &d); |
| 1329 r.set_context(default_context_); | 1328 r.set_context(&default_context_); |
| 1330 r.Start(); | 1329 r.Start(); |
| 1331 EXPECT_TRUE(r.is_pending()); | 1330 EXPECT_TRUE(r.is_pending()); |
| 1332 | 1331 |
| 1333 MessageLoop::current()->Run(); | 1332 MessageLoop::current()->Run(); |
| 1334 | 1333 |
| 1335 EXPECT_EQ(1, d.response_started_count()); | 1334 EXPECT_EQ(1, d.response_started_count()); |
| 1336 EXPECT_FALSE(d.received_data_before_response()); | 1335 EXPECT_FALSE(d.received_data_before_response()); |
| 1337 EXPECT_NE(0, d.bytes_received()); | 1336 EXPECT_NE(0, d.bytes_received()); |
| 1338 CheckSSLInfo(r.ssl_info()); | 1337 CheckSSLInfo(r.ssl_info()); |
| 1339 EXPECT_EQ(test_server.host_port_pair().host(), | 1338 EXPECT_EQ(test_server.host_port_pair().host(), |
| 1340 r.GetSocketAddress().host()); | 1339 r.GetSocketAddress().host()); |
| 1341 EXPECT_EQ(test_server.host_port_pair().port(), | 1340 EXPECT_EQ(test_server.host_port_pair().port(), |
| 1342 r.GetSocketAddress().port()); | 1341 r.GetSocketAddress().port()); |
| 1343 } | 1342 } |
| 1344 } | 1343 } |
| 1345 | 1344 |
| 1346 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { | 1345 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { |
| 1347 TestServer::HTTPSOptions https_options( | 1346 TestServer::HTTPSOptions https_options( |
| 1348 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); | 1347 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); |
| 1349 TestServer test_server(https_options, | 1348 TestServer test_server(https_options, |
| 1350 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1349 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1351 ASSERT_TRUE(test_server.Start()); | 1350 ASSERT_TRUE(test_server.Start()); |
| 1352 | 1351 |
| 1353 bool err_allowed = true; | 1352 bool err_allowed = true; |
| 1354 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 1353 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 1355 TestDelegate d; | 1354 TestDelegate d; |
| 1356 { | 1355 { |
| 1357 d.set_allow_certificate_errors(err_allowed); | 1356 d.set_allow_certificate_errors(err_allowed); |
| 1358 TestURLRequest r(test_server.GetURL(""), &d); | 1357 TestURLRequest r(test_server.GetURL(""), &d); |
| 1359 r.set_context(default_context_); | 1358 r.set_context(&default_context_); |
| 1360 | 1359 |
| 1361 r.Start(); | 1360 r.Start(); |
| 1362 EXPECT_TRUE(r.is_pending()); | 1361 EXPECT_TRUE(r.is_pending()); |
| 1363 | 1362 |
| 1364 MessageLoop::current()->Run(); | 1363 MessageLoop::current()->Run(); |
| 1365 | 1364 |
| 1366 EXPECT_EQ(1, d.response_started_count()); | 1365 EXPECT_EQ(1, d.response_started_count()); |
| 1367 EXPECT_FALSE(d.received_data_before_response()); | 1366 EXPECT_FALSE(d.received_data_before_response()); |
| 1368 EXPECT_TRUE(d.have_certificate_errors()); | 1367 EXPECT_TRUE(d.have_certificate_errors()); |
| 1369 if (err_allowed) { | 1368 if (err_allowed) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1384 ASSERT_TRUE(test_server.Start()); | 1383 ASSERT_TRUE(test_server.Start()); |
| 1385 | 1384 |
| 1386 // Iterate from false to true, just so that we do the opposite of the | 1385 // Iterate from false to true, just so that we do the opposite of the |
| 1387 // previous test in order to increase test coverage. | 1386 // previous test in order to increase test coverage. |
| 1388 bool err_allowed = false; | 1387 bool err_allowed = false; |
| 1389 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 1388 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 1390 TestDelegate d; | 1389 TestDelegate d; |
| 1391 { | 1390 { |
| 1392 d.set_allow_certificate_errors(err_allowed); | 1391 d.set_allow_certificate_errors(err_allowed); |
| 1393 TestURLRequest r(test_server.GetURL(""), &d); | 1392 TestURLRequest r(test_server.GetURL(""), &d); |
| 1394 r.set_context(default_context_); | 1393 r.set_context(&default_context_); |
| 1395 | 1394 |
| 1396 r.Start(); | 1395 r.Start(); |
| 1397 EXPECT_TRUE(r.is_pending()); | 1396 EXPECT_TRUE(r.is_pending()); |
| 1398 | 1397 |
| 1399 MessageLoop::current()->Run(); | 1398 MessageLoop::current()->Run(); |
| 1400 | 1399 |
| 1401 EXPECT_EQ(1, d.response_started_count()); | 1400 EXPECT_EQ(1, d.response_started_count()); |
| 1402 EXPECT_FALSE(d.received_data_before_response()); | 1401 EXPECT_FALSE(d.received_data_before_response()); |
| 1403 EXPECT_TRUE(d.have_certificate_errors()); | 1402 EXPECT_TRUE(d.have_certificate_errors()); |
| 1404 if (err_allowed) { | 1403 if (err_allowed) { |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1439 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24, | 1438 { { 0xf1, 0xad, 0xf6, 0xce, 0x42, 0xac, 0xe7, 0xb4, 0xf4, 0x24, |
| 1440 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } }; | 1439 0xdb, 0x1a, 0xf7, 0xa0, 0x9f, 0x09, 0xa1, 0xea, 0xf1, 0x5c } }; |
| 1441 | 1440 |
| 1442 // This is the policy OID contained in the certificates that testserver | 1441 // This is the policy OID contained in the certificates that testserver |
| 1443 // generates. | 1442 // generates. |
| 1444 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; | 1443 static const char kOCSPTestCertPolicy[] = "1.3.6.1.4.1.11129.2.4.1"; |
| 1445 | 1444 |
| 1446 class HTTPSOCSPTest : public HTTPSRequestTest { | 1445 class HTTPSOCSPTest : public HTTPSRequestTest { |
| 1447 public: | 1446 public: |
| 1448 HTTPSOCSPTest() | 1447 HTTPSOCSPTest() |
| 1449 : context_(new TestURLRequestContext(true)), | 1448 : context_(true), |
| 1450 ev_test_policy_(EVRootCAMetadata::GetInstance(), | 1449 ev_test_policy_(EVRootCAMetadata::GetInstance(), |
| 1451 kOCSPTestCertFingerprint, | 1450 kOCSPTestCertFingerprint, |
| 1452 kOCSPTestCertPolicy) { | 1451 kOCSPTestCertPolicy) { |
| 1453 } | 1452 } |
| 1454 | 1453 |
| 1455 virtual void SetUp() OVERRIDE { | 1454 virtual void SetUp() OVERRIDE { |
| 1456 SetupContext(context_); | 1455 SetupContext(&context_); |
| 1457 context_->Init(); | 1456 context_.Init(); |
| 1458 | 1457 |
| 1459 scoped_refptr<net::X509Certificate> root_cert = | 1458 scoped_refptr<net::X509Certificate> root_cert = |
| 1460 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); | 1459 ImportCertFromFile(GetTestCertsDirectory(), "ocsp-test-root.pem"); |
| 1461 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); | 1460 CHECK_NE(static_cast<X509Certificate*>(NULL), root_cert); |
| 1462 test_root_.reset(new ScopedTestRoot(root_cert)); | 1461 test_root_.reset(new ScopedTestRoot(root_cert)); |
| 1463 | 1462 |
| 1464 #if defined(USE_NSS) | 1463 #if defined(USE_NSS) |
| 1465 SetURLRequestContextForNSSHttpIO(context_.get()); | 1464 SetURLRequestContextForNSSHttpIO(&context_); |
| 1466 EnsureNSSHttpIOInit(); | 1465 EnsureNSSHttpIOInit(); |
| 1467 #endif | 1466 #endif |
| 1468 } | 1467 } |
| 1469 | 1468 |
| 1470 void DoConnection(const TestServer::HTTPSOptions& https_options, | 1469 void DoConnection(const TestServer::HTTPSOptions& https_options, |
| 1471 CertStatus* out_cert_status) { | 1470 CertStatus* out_cert_status) { |
| 1472 TestServer test_server(https_options, | 1471 TestServer test_server(https_options, |
| 1473 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1472 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1474 ASSERT_TRUE(test_server.Start()); | 1473 ASSERT_TRUE(test_server.Start()); |
| 1475 | 1474 |
| 1476 TestDelegate d; | 1475 TestDelegate d; |
| 1477 d.set_allow_certificate_errors(true); | 1476 d.set_allow_certificate_errors(true); |
| 1478 URLRequest r(test_server.GetURL(""), &d); | 1477 URLRequest r(test_server.GetURL(""), &d); |
| 1479 r.set_context(context_.get()); | 1478 r.set_context(&context_); |
| 1480 r.Start(); | 1479 r.Start(); |
| 1481 | 1480 |
| 1482 MessageLoop::current()->Run(); | 1481 MessageLoop::current()->Run(); |
| 1483 | 1482 |
| 1484 EXPECT_EQ(1, d.response_started_count()); | 1483 EXPECT_EQ(1, d.response_started_count()); |
| 1485 *out_cert_status = r.ssl_info().cert_status; | 1484 *out_cert_status = r.ssl_info().cert_status; |
| 1486 } | 1485 } |
| 1487 | 1486 |
| 1488 ~HTTPSOCSPTest() { | 1487 ~HTTPSOCSPTest() { |
| 1489 #if defined(USE_NSS) | 1488 #if defined(USE_NSS) |
| 1490 ShutdownNSSHttpIO(); | 1489 ShutdownNSSHttpIO(); |
| 1491 #endif | 1490 #endif |
| 1492 } | 1491 } |
| 1493 | 1492 |
| 1494 protected: | 1493 protected: |
| 1495 // SetupContext configures the URLRequestContext that will be used for making | 1494 // SetupContext configures the URLRequestContext that will be used for making |
| 1496 // connetions to testserver. This can be overridden in test subclasses for | 1495 // connetions to testserver. This can be overridden in test subclasses for |
| 1497 // different behaviour. | 1496 // different behaviour. |
| 1498 virtual void SetupContext(URLRequestContext* context) { | 1497 virtual void SetupContext(URLRequestContext* context) { |
| 1499 context->set_ssl_config_service( | 1498 context->set_ssl_config_service( |
| 1500 new TestSSLConfigService(true /* check for EV */, | 1499 new TestSSLConfigService(true /* check for EV */, |
| 1501 true /* online revocation checking */)); | 1500 true /* online revocation checking */)); |
| 1502 } | 1501 } |
| 1503 | 1502 |
| 1504 scoped_ptr<ScopedTestRoot> test_root_; | 1503 scoped_ptr<ScopedTestRoot> test_root_; |
| 1505 scoped_refptr<TestURLRequestContext> context_; | 1504 TestURLRequestContext context_; |
| 1506 ScopedTestEVPolicy ev_test_policy_; | 1505 ScopedTestEVPolicy ev_test_policy_; |
| 1507 }; | 1506 }; |
| 1508 | 1507 |
| 1509 static CertStatus ExpectedCertStatusForFailedOnlineRevocationCheck() { | 1508 static CertStatus ExpectedCertStatusForFailedOnlineRevocationCheck() { |
| 1510 #if defined(OS_WIN) | 1509 #if defined(OS_WIN) |
| 1511 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't | 1510 // Windows can return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION but we don't |
| 1512 // have that ability on other platforms. | 1511 // have that ability on other platforms. |
| 1513 return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; | 1512 return CERT_STATUS_UNABLE_TO_CHECK_REVOCATION; |
| 1514 #else | 1513 #else |
| 1515 return 0; | 1514 return 0; |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1732 | 1731 |
| 1733 TEST_F(HTTPSRequestTest, SSLv3Fallback) { | 1732 TEST_F(HTTPSRequestTest, SSLv3Fallback) { |
| 1734 TestServer::HTTPSOptions https_options( | 1733 TestServer::HTTPSOptions https_options( |
| 1735 TestServer::HTTPSOptions::CERT_OK); | 1734 TestServer::HTTPSOptions::CERT_OK); |
| 1736 https_options.tls_intolerant = true; | 1735 https_options.tls_intolerant = true; |
| 1737 TestServer test_server(https_options, | 1736 TestServer test_server(https_options, |
| 1738 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1737 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1739 ASSERT_TRUE(test_server.Start()); | 1738 ASSERT_TRUE(test_server.Start()); |
| 1740 | 1739 |
| 1741 TestDelegate d; | 1740 TestDelegate d; |
| 1742 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1741 TestURLRequestContext context(true); |
| 1743 context->Init(); | 1742 context.Init(); |
| 1744 d.set_allow_certificate_errors(true); | 1743 d.set_allow_certificate_errors(true); |
| 1745 URLRequest r(test_server.GetURL(""), &d); | 1744 URLRequest r(test_server.GetURL(""), &d); |
| 1746 r.set_context(context.get()); | 1745 r.set_context(&context); |
| 1747 r.Start(); | 1746 r.Start(); |
| 1748 | 1747 |
| 1749 MessageLoop::current()->Run(); | 1748 MessageLoop::current()->Run(); |
| 1750 | 1749 |
| 1751 EXPECT_EQ(1, d.response_started_count()); | 1750 EXPECT_EQ(1, d.response_started_count()); |
| 1752 EXPECT_NE(0, d.bytes_received()); | 1751 EXPECT_NE(0, d.bytes_received()); |
| 1753 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_SSL3_FALLBACK); | 1752 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_SSL3_FALLBACK); |
| 1754 } | 1753 } |
| 1755 | 1754 |
| 1756 // This tests that a load of www.google.com with a certificate error sets | 1755 // This tests that a load of www.google.com with a certificate error sets |
| 1757 // the |certificate_errors_are_fatal| flag correctly. This flag will cause | 1756 // the |certificate_errors_are_fatal| flag correctly. This flag will cause |
| 1758 // the interstitial to be fatal. | 1757 // the interstitial to be fatal. |
| 1759 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { | 1758 TEST_F(HTTPSRequestTest, HTTPSPreloadedHSTSTest) { |
| 1760 TestServer::HTTPSOptions https_options( | 1759 TestServer::HTTPSOptions https_options( |
| 1761 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); | 1760 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); |
| 1762 TestServer test_server(https_options, | 1761 TestServer test_server(https_options, |
| 1763 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1762 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1764 ASSERT_TRUE(test_server.Start()); | 1763 ASSERT_TRUE(test_server.Start()); |
| 1765 | 1764 |
| 1766 // We require that the URL be www.google.com in order to pick up the | 1765 // We require that the URL be www.google.com in order to pick up the |
| 1767 // preloaded HSTS entries in the TransportSecurityState. This means that we | 1766 // preloaded HSTS entries in the TransportSecurityState. This means that we |
| 1768 // have to use a MockHostResolver in order to direct www.google.com to the | 1767 // have to use a MockHostResolver in order to direct www.google.com to the |
| 1769 // testserver. | 1768 // testserver. |
| 1770 | 1769 |
| 1771 MockHostResolver host_resolver; | 1770 MockHostResolver host_resolver; |
| 1772 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); | 1771 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); |
| 1773 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1772 TestNetworkDelegate network_delegate; // must outlive URLRequest |
| 1774 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1773 TestURLRequestContext context(true); |
| 1775 context->set_network_delegate(&network_delegate); | 1774 context.set_network_delegate(&network_delegate); |
| 1776 context->set_host_resolver(&host_resolver); | 1775 context.set_host_resolver(&host_resolver); |
| 1777 TransportSecurityState transport_security_state; | 1776 TransportSecurityState transport_security_state; |
| 1778 context->set_transport_security_state(&transport_security_state); | 1777 context.set_transport_security_state(&transport_security_state); |
| 1779 context->Init(); | 1778 context.Init(); |
| 1780 | 1779 |
| 1781 TestDelegate d; | 1780 TestDelegate d; |
| 1782 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", | 1781 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", |
| 1783 test_server.host_port_pair().port())), | 1782 test_server.host_port_pair().port())), |
| 1784 &d); | 1783 &d); |
| 1785 r.set_context(context); | 1784 r.set_context(&context); |
| 1786 | 1785 |
| 1787 r.Start(); | 1786 r.Start(); |
| 1788 EXPECT_TRUE(r.is_pending()); | 1787 EXPECT_TRUE(r.is_pending()); |
| 1789 | 1788 |
| 1790 MessageLoop::current()->Run(); | 1789 MessageLoop::current()->Run(); |
| 1791 | 1790 |
| 1792 EXPECT_EQ(1, d.response_started_count()); | 1791 EXPECT_EQ(1, d.response_started_count()); |
| 1793 EXPECT_FALSE(d.received_data_before_response()); | 1792 EXPECT_FALSE(d.received_data_before_response()); |
| 1794 EXPECT_TRUE(d.have_certificate_errors()); | 1793 EXPECT_TRUE(d.have_certificate_errors()); |
| 1795 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 1794 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 1807 ASSERT_TRUE(test_server.Start()); | 1806 ASSERT_TRUE(test_server.Start()); |
| 1808 | 1807 |
| 1809 // We require that the URL be www.google.com in order to pick up the | 1808 // We require that the URL be www.google.com in order to pick up the |
| 1810 // preloaded and dynamic HSTS and public key pin entries in the | 1809 // preloaded and dynamic HSTS and public key pin entries in the |
| 1811 // TransportSecurityState. This means that we have to use a | 1810 // TransportSecurityState. This means that we have to use a |
| 1812 // MockHostResolver in order to direct www.google.com to the testserver. | 1811 // MockHostResolver in order to direct www.google.com to the testserver. |
| 1813 | 1812 |
| 1814 MockHostResolver host_resolver; | 1813 MockHostResolver host_resolver; |
| 1815 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); | 1814 host_resolver.rules()->AddRule("www.google.com", "127.0.0.1"); |
| 1816 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1815 TestNetworkDelegate network_delegate; // must outlive URLRequest |
| 1817 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 1816 TestURLRequestContext context(true); |
| 1818 context->set_network_delegate(&network_delegate); | 1817 context.set_network_delegate(&network_delegate); |
| 1819 context->set_host_resolver(&host_resolver); | 1818 context.set_host_resolver(&host_resolver); |
| 1820 TransportSecurityState transport_security_state; | 1819 TransportSecurityState transport_security_state; |
| 1821 TransportSecurityState::DomainState domain_state; | 1820 TransportSecurityState::DomainState domain_state; |
| 1822 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, | 1821 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, |
| 1823 &domain_state)); | 1822 &domain_state)); |
| 1824 context->set_transport_security_state(&transport_security_state); | 1823 context.set_transport_security_state(&transport_security_state); |
| 1825 context->Init(); | 1824 context.Init(); |
| 1826 | 1825 |
| 1827 TestDelegate d; | 1826 TestDelegate d; |
| 1828 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", | 1827 TestURLRequest r(GURL(StringPrintf("https://www.google.com:%d", |
| 1829 test_server.host_port_pair().port())), | 1828 test_server.host_port_pair().port())), |
| 1830 &d); | 1829 &d); |
| 1831 r.set_context(context); | 1830 r.set_context(&context); |
| 1832 | 1831 |
| 1833 r.Start(); | 1832 r.Start(); |
| 1834 EXPECT_TRUE(r.is_pending()); | 1833 EXPECT_TRUE(r.is_pending()); |
| 1835 | 1834 |
| 1836 MessageLoop::current()->Run(); | 1835 MessageLoop::current()->Run(); |
| 1837 | 1836 |
| 1838 EXPECT_EQ(1, d.response_started_count()); | 1837 EXPECT_EQ(1, d.response_started_count()); |
| 1839 EXPECT_FALSE(d.received_data_before_response()); | 1838 EXPECT_FALSE(d.received_data_before_response()); |
| 1840 EXPECT_TRUE(d.have_certificate_errors()); | 1839 EXPECT_TRUE(d.have_certificate_errors()); |
| 1841 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 1840 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1884 TEST_F(HTTPSRequestTest, ClientAuthTest) { | 1883 TEST_F(HTTPSRequestTest, ClientAuthTest) { |
| 1885 TestServer::HTTPSOptions https_options; | 1884 TestServer::HTTPSOptions https_options; |
| 1886 https_options.request_client_certificate = true; | 1885 https_options.request_client_certificate = true; |
| 1887 TestServer test_server(https_options, | 1886 TestServer test_server(https_options, |
| 1888 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1887 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1889 ASSERT_TRUE(test_server.Start()); | 1888 ASSERT_TRUE(test_server.Start()); |
| 1890 | 1889 |
| 1891 SSLClientAuthTestDelegate d; | 1890 SSLClientAuthTestDelegate d; |
| 1892 { | 1891 { |
| 1893 TestURLRequest r(test_server.GetURL(""), &d); | 1892 TestURLRequest r(test_server.GetURL(""), &d); |
| 1894 r.set_context(default_context_); | 1893 r.set_context(&default_context_); |
| 1895 | 1894 |
| 1896 r.Start(); | 1895 r.Start(); |
| 1897 EXPECT_TRUE(r.is_pending()); | 1896 EXPECT_TRUE(r.is_pending()); |
| 1898 | 1897 |
| 1899 MessageLoop::current()->Run(); | 1898 MessageLoop::current()->Run(); |
| 1900 | 1899 |
| 1901 EXPECT_EQ(1, d.on_certificate_requested_count()); | 1900 EXPECT_EQ(1, d.on_certificate_requested_count()); |
| 1902 EXPECT_FALSE(d.received_data_before_response()); | 1901 EXPECT_FALSE(d.received_data_before_response()); |
| 1903 EXPECT_EQ(0, d.bytes_received()); | 1902 EXPECT_EQ(0, d.bytes_received()); |
| 1904 | 1903 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1922 https_options.record_resume = true; | 1921 https_options.record_resume = true; |
| 1923 TestServer test_server(https_options, | 1922 TestServer test_server(https_options, |
| 1924 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1923 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1925 ASSERT_TRUE(test_server.Start()); | 1924 ASSERT_TRUE(test_server.Start()); |
| 1926 | 1925 |
| 1927 SSLClientSocket::ClearSessionCache(); | 1926 SSLClientSocket::ClearSessionCache(); |
| 1928 | 1927 |
| 1929 { | 1928 { |
| 1930 TestDelegate d; | 1929 TestDelegate d; |
| 1931 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); | 1930 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); |
| 1932 r.set_context(default_context_); | 1931 r.set_context(&default_context_); |
| 1933 | 1932 |
| 1934 r.Start(); | 1933 r.Start(); |
| 1935 EXPECT_TRUE(r.is_pending()); | 1934 EXPECT_TRUE(r.is_pending()); |
| 1936 | 1935 |
| 1937 MessageLoop::current()->Run(); | 1936 MessageLoop::current()->Run(); |
| 1938 | 1937 |
| 1939 EXPECT_EQ(1, d.response_started_count()); | 1938 EXPECT_EQ(1, d.response_started_count()); |
| 1940 } | 1939 } |
| 1941 | 1940 |
| 1942 reinterpret_cast<HttpCache*>(default_context_->http_transaction_factory())-> | 1941 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> |
| 1943 CloseAllConnections(); | 1942 CloseAllConnections(); |
| 1944 | 1943 |
| 1945 { | 1944 { |
| 1946 TestDelegate d; | 1945 TestDelegate d; |
| 1947 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); | 1946 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); |
| 1948 r.set_context(default_context_); | 1947 r.set_context(&default_context_); |
| 1949 | 1948 |
| 1950 r.Start(); | 1949 r.Start(); |
| 1951 EXPECT_TRUE(r.is_pending()); | 1950 EXPECT_TRUE(r.is_pending()); |
| 1952 | 1951 |
| 1953 MessageLoop::current()->Run(); | 1952 MessageLoop::current()->Run(); |
| 1954 | 1953 |
| 1955 // The response will look like; | 1954 // The response will look like; |
| 1956 // insert abc | 1955 // insert abc |
| 1957 // lookup abc | 1956 // lookup abc |
| 1958 // insert xyz | 1957 // insert xyz |
| (...skipping 30 matching lines...) Expand all Loading... |
| 1989 https_options.record_resume = true; | 1988 https_options.record_resume = true; |
| 1990 TestServer test_server(https_options, | 1989 TestServer test_server(https_options, |
| 1991 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1990 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 1992 ASSERT_TRUE(test_server.Start()); | 1991 ASSERT_TRUE(test_server.Start()); |
| 1993 | 1992 |
| 1994 SSLClientSocket::ClearSessionCache(); | 1993 SSLClientSocket::ClearSessionCache(); |
| 1995 | 1994 |
| 1996 { | 1995 { |
| 1997 TestDelegate d; | 1996 TestDelegate d; |
| 1998 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); | 1997 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); |
| 1999 r.set_context(default_context_); | 1998 r.set_context(&default_context_); |
| 2000 | 1999 |
| 2001 r.Start(); | 2000 r.Start(); |
| 2002 EXPECT_TRUE(r.is_pending()); | 2001 EXPECT_TRUE(r.is_pending()); |
| 2003 | 2002 |
| 2004 MessageLoop::current()->Run(); | 2003 MessageLoop::current()->Run(); |
| 2005 | 2004 |
| 2006 EXPECT_EQ(1, d.response_started_count()); | 2005 EXPECT_EQ(1, d.response_started_count()); |
| 2007 } | 2006 } |
| 2008 | 2007 |
| 2009 // Now create a new HttpCache with a different ssl_session_cache_shard value. | 2008 // Now create a new HttpCache with a different ssl_session_cache_shard value. |
| 2010 HttpNetworkSession::Params params; | 2009 HttpNetworkSession::Params params; |
| 2011 params.host_resolver = default_context_->host_resolver(); | 2010 params.host_resolver = default_context_.host_resolver(); |
| 2012 params.cert_verifier = default_context_->cert_verifier(); | 2011 params.cert_verifier = default_context_.cert_verifier(); |
| 2013 params.proxy_service = default_context_->proxy_service(); | 2012 params.proxy_service = default_context_.proxy_service(); |
| 2014 params.ssl_config_service = default_context_->ssl_config_service(); | 2013 params.ssl_config_service = default_context_.ssl_config_service(); |
| 2015 params.http_auth_handler_factory = | 2014 params.http_auth_handler_factory = |
| 2016 default_context_->http_auth_handler_factory(); | 2015 default_context_.http_auth_handler_factory(); |
| 2017 params.network_delegate = default_context_->network_delegate(); | 2016 params.network_delegate = default_context_.network_delegate(); |
| 2018 params.http_server_properties = default_context_->http_server_properties(); | 2017 params.http_server_properties = default_context_.http_server_properties(); |
| 2019 params.ssl_session_cache_shard = "alternate"; | 2018 params.ssl_session_cache_shard = "alternate"; |
| 2020 | 2019 |
| 2021 scoped_ptr<net::HttpCache> cache(new net::HttpCache( | 2020 scoped_ptr<net::HttpCache> cache(new net::HttpCache( |
| 2022 new net::HttpNetworkSession(params), | 2021 new net::HttpNetworkSession(params), |
| 2023 net::HttpCache::DefaultBackend::InMemory(0))); | 2022 net::HttpCache::DefaultBackend::InMemory(0))); |
| 2024 | 2023 |
| 2025 default_context_->set_http_transaction_factory(cache.get()); | 2024 default_context_.set_http_transaction_factory(cache.get()); |
| 2026 | 2025 |
| 2027 { | 2026 { |
| 2028 TestDelegate d; | 2027 TestDelegate d; |
| 2029 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); | 2028 TestURLRequest r(test_server.GetURL("ssl-session-cache"), &d); |
| 2030 r.set_context(default_context_); | 2029 r.set_context(&default_context_); |
| 2031 | 2030 |
| 2032 r.Start(); | 2031 r.Start(); |
| 2033 EXPECT_TRUE(r.is_pending()); | 2032 EXPECT_TRUE(r.is_pending()); |
| 2034 | 2033 |
| 2035 MessageLoop::current()->Run(); | 2034 MessageLoop::current()->Run(); |
| 2036 | 2035 |
| 2037 // The response will look like; | 2036 // The response will look like; |
| 2038 // insert abc | 2037 // insert abc |
| 2039 // insert xyz | 2038 // insert xyz |
| 2040 // | 2039 // |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2058 EXPECT_NE(session_id, parts[1]); | 2057 EXPECT_NE(session_id, parts[1]); |
| 2059 } | 2058 } |
| 2060 } | 2059 } |
| 2061 } | 2060 } |
| 2062 } | 2061 } |
| 2063 | 2062 |
| 2064 TEST_F(URLRequestTestHTTP, CancelTest) { | 2063 TEST_F(URLRequestTestHTTP, CancelTest) { |
| 2065 TestDelegate d; | 2064 TestDelegate d; |
| 2066 { | 2065 { |
| 2067 TestURLRequest r(GURL("http://www.google.com/"), &d); | 2066 TestURLRequest r(GURL("http://www.google.com/"), &d); |
| 2068 r.set_context(default_context_); | 2067 r.set_context(&default_context_); |
| 2069 | 2068 |
| 2070 r.Start(); | 2069 r.Start(); |
| 2071 EXPECT_TRUE(r.is_pending()); | 2070 EXPECT_TRUE(r.is_pending()); |
| 2072 | 2071 |
| 2073 r.Cancel(); | 2072 r.Cancel(); |
| 2074 | 2073 |
| 2075 MessageLoop::current()->Run(); | 2074 MessageLoop::current()->Run(); |
| 2076 | 2075 |
| 2077 // We expect to receive OnResponseStarted even though the request has been | 2076 // We expect to receive OnResponseStarted even though the request has been |
| 2078 // cancelled. | 2077 // cancelled. |
| 2079 EXPECT_EQ(1, d.response_started_count()); | 2078 EXPECT_EQ(1, d.response_started_count()); |
| 2080 EXPECT_EQ(0, d.bytes_received()); | 2079 EXPECT_EQ(0, d.bytes_received()); |
| 2081 EXPECT_FALSE(d.received_data_before_response()); | 2080 EXPECT_FALSE(d.received_data_before_response()); |
| 2082 } | 2081 } |
| 2083 } | 2082 } |
| 2084 | 2083 |
| 2085 TEST_F(URLRequestTestHTTP, CancelTest2) { | 2084 TEST_F(URLRequestTestHTTP, CancelTest2) { |
| 2086 ASSERT_TRUE(test_server_.Start()); | 2085 ASSERT_TRUE(test_server_.Start()); |
| 2087 | 2086 |
| 2088 TestDelegate d; | 2087 TestDelegate d; |
| 2089 { | 2088 { |
| 2090 TestURLRequest r(test_server_.GetURL(""), &d); | 2089 TestURLRequest r(test_server_.GetURL(""), &d); |
| 2091 r.set_context(default_context_); | 2090 r.set_context(&default_context_); |
| 2092 | 2091 |
| 2093 d.set_cancel_in_response_started(true); | 2092 d.set_cancel_in_response_started(true); |
| 2094 | 2093 |
| 2095 r.Start(); | 2094 r.Start(); |
| 2096 EXPECT_TRUE(r.is_pending()); | 2095 EXPECT_TRUE(r.is_pending()); |
| 2097 | 2096 |
| 2098 MessageLoop::current()->Run(); | 2097 MessageLoop::current()->Run(); |
| 2099 | 2098 |
| 2100 EXPECT_EQ(1, d.response_started_count()); | 2099 EXPECT_EQ(1, d.response_started_count()); |
| 2101 EXPECT_EQ(0, d.bytes_received()); | 2100 EXPECT_EQ(0, d.bytes_received()); |
| 2102 EXPECT_FALSE(d.received_data_before_response()); | 2101 EXPECT_FALSE(d.received_data_before_response()); |
| 2103 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 2102 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 2104 } | 2103 } |
| 2105 } | 2104 } |
| 2106 | 2105 |
| 2107 TEST_F(URLRequestTestHTTP, CancelTest3) { | 2106 TEST_F(URLRequestTestHTTP, CancelTest3) { |
| 2108 ASSERT_TRUE(test_server_.Start()); | 2107 ASSERT_TRUE(test_server_.Start()); |
| 2109 | 2108 |
| 2110 TestDelegate d; | 2109 TestDelegate d; |
| 2111 { | 2110 { |
| 2112 TestURLRequest r(test_server_.GetURL(""), &d); | 2111 TestURLRequest r(test_server_.GetURL(""), &d); |
| 2113 r.set_context(default_context_); | 2112 r.set_context(&default_context_); |
| 2114 | 2113 |
| 2115 d.set_cancel_in_received_data(true); | 2114 d.set_cancel_in_received_data(true); |
| 2116 | 2115 |
| 2117 r.Start(); | 2116 r.Start(); |
| 2118 EXPECT_TRUE(r.is_pending()); | 2117 EXPECT_TRUE(r.is_pending()); |
| 2119 | 2118 |
| 2120 MessageLoop::current()->Run(); | 2119 MessageLoop::current()->Run(); |
| 2121 | 2120 |
| 2122 EXPECT_EQ(1, d.response_started_count()); | 2121 EXPECT_EQ(1, d.response_started_count()); |
| 2123 // There is no guarantee about how much data was received | 2122 // There is no guarantee about how much data was received |
| 2124 // before the cancel was issued. It could have been 0 bytes, | 2123 // before the cancel was issued. It could have been 0 bytes, |
| 2125 // or it could have been all the bytes. | 2124 // or it could have been all the bytes. |
| 2126 // EXPECT_EQ(0, d.bytes_received()); | 2125 // EXPECT_EQ(0, d.bytes_received()); |
| 2127 EXPECT_FALSE(d.received_data_before_response()); | 2126 EXPECT_FALSE(d.received_data_before_response()); |
| 2128 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 2127 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 2129 } | 2128 } |
| 2130 } | 2129 } |
| 2131 | 2130 |
| 2132 TEST_F(URLRequestTestHTTP, CancelTest4) { | 2131 TEST_F(URLRequestTestHTTP, CancelTest4) { |
| 2133 ASSERT_TRUE(test_server_.Start()); | 2132 ASSERT_TRUE(test_server_.Start()); |
| 2134 | 2133 |
| 2135 TestDelegate d; | 2134 TestDelegate d; |
| 2136 { | 2135 { |
| 2137 TestURLRequest r(test_server_.GetURL(""), &d); | 2136 TestURLRequest r(test_server_.GetURL(""), &d); |
| 2138 r.set_context(default_context_); | 2137 r.set_context(&default_context_); |
| 2139 | 2138 |
| 2140 r.Start(); | 2139 r.Start(); |
| 2141 EXPECT_TRUE(r.is_pending()); | 2140 EXPECT_TRUE(r.is_pending()); |
| 2142 | 2141 |
| 2143 // The request will be implicitly canceled when it is destroyed. The | 2142 // The request will be implicitly canceled when it is destroyed. The |
| 2144 // test delegate must not post a quit message when this happens because | 2143 // test delegate must not post a quit message when this happens because |
| 2145 // this test doesn't actually have a message loop. The quit message would | 2144 // this test doesn't actually have a message loop. The quit message would |
| 2146 // get put on this thread's message queue and the next test would exit | 2145 // get put on this thread's message queue and the next test would exit |
| 2147 // early, causing problems. | 2146 // early, causing problems. |
| 2148 d.set_quit_on_complete(false); | 2147 d.set_quit_on_complete(false); |
| 2149 } | 2148 } |
| 2150 // expect things to just cleanup properly. | 2149 // expect things to just cleanup properly. |
| 2151 | 2150 |
| 2152 // we won't actually get a received reponse here because we've never run the | 2151 // we won't actually get a received reponse here because we've never run the |
| 2153 // message loop | 2152 // message loop |
| 2154 EXPECT_FALSE(d.received_data_before_response()); | 2153 EXPECT_FALSE(d.received_data_before_response()); |
| 2155 EXPECT_EQ(0, d.bytes_received()); | 2154 EXPECT_EQ(0, d.bytes_received()); |
| 2156 } | 2155 } |
| 2157 | 2156 |
| 2158 TEST_F(URLRequestTestHTTP, CancelTest5) { | 2157 TEST_F(URLRequestTestHTTP, CancelTest5) { |
| 2159 ASSERT_TRUE(test_server_.Start()); | 2158 ASSERT_TRUE(test_server_.Start()); |
| 2160 | 2159 |
| 2161 // populate cache | 2160 // populate cache |
| 2162 { | 2161 { |
| 2163 TestDelegate d; | 2162 TestDelegate d; |
| 2164 URLRequest r(test_server_.GetURL("cachetime"), &d); | 2163 URLRequest r(test_server_.GetURL("cachetime"), &d); |
| 2165 r.set_context(default_context_); | 2164 r.set_context(&default_context_); |
| 2166 r.Start(); | 2165 r.Start(); |
| 2167 MessageLoop::current()->Run(); | 2166 MessageLoop::current()->Run(); |
| 2168 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2167 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 2169 } | 2168 } |
| 2170 | 2169 |
| 2171 // cancel read from cache (see bug 990242) | 2170 // cancel read from cache (see bug 990242) |
| 2172 { | 2171 { |
| 2173 TestDelegate d; | 2172 TestDelegate d; |
| 2174 URLRequest r(test_server_.GetURL("cachetime"), &d); | 2173 URLRequest r(test_server_.GetURL("cachetime"), &d); |
| 2175 r.set_context(default_context_); | 2174 r.set_context(&default_context_); |
| 2176 r.Start(); | 2175 r.Start(); |
| 2177 r.Cancel(); | 2176 r.Cancel(); |
| 2178 MessageLoop::current()->Run(); | 2177 MessageLoop::current()->Run(); |
| 2179 | 2178 |
| 2180 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 2179 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
| 2181 EXPECT_EQ(1, d.response_started_count()); | 2180 EXPECT_EQ(1, d.response_started_count()); |
| 2182 EXPECT_EQ(0, d.bytes_received()); | 2181 EXPECT_EQ(0, d.bytes_received()); |
| 2183 EXPECT_FALSE(d.received_data_before_response()); | 2182 EXPECT_FALSE(d.received_data_before_response()); |
| 2184 } | 2183 } |
| 2185 } | 2184 } |
| 2186 | 2185 |
| 2187 TEST_F(URLRequestTestHTTP, PostTest) { | 2186 TEST_F(URLRequestTestHTTP, PostTest) { |
| 2188 ASSERT_TRUE(test_server_.Start()); | 2187 ASSERT_TRUE(test_server_.Start()); |
| 2189 HTTPUploadDataOperationTest("POST"); | 2188 HTTPUploadDataOperationTest("POST"); |
| 2190 } | 2189 } |
| 2191 | 2190 |
| 2192 TEST_F(URLRequestTestHTTP, PutTest) { | 2191 TEST_F(URLRequestTestHTTP, PutTest) { |
| 2193 ASSERT_TRUE(test_server_.Start()); | 2192 ASSERT_TRUE(test_server_.Start()); |
| 2194 HTTPUploadDataOperationTest("PUT"); | 2193 HTTPUploadDataOperationTest("PUT"); |
| 2195 } | 2194 } |
| 2196 | 2195 |
| 2197 TEST_F(URLRequestTestHTTP, PostEmptyTest) { | 2196 TEST_F(URLRequestTestHTTP, PostEmptyTest) { |
| 2198 ASSERT_TRUE(test_server_.Start()); | 2197 ASSERT_TRUE(test_server_.Start()); |
| 2199 | 2198 |
| 2200 TestDelegate d; | 2199 TestDelegate d; |
| 2201 { | 2200 { |
| 2202 TestURLRequest r(test_server_.GetURL("echo"), &d); | 2201 TestURLRequest r(test_server_.GetURL("echo"), &d); |
| 2203 r.set_context(default_context_); | 2202 r.set_context(&default_context_); |
| 2204 r.set_method("POST"); | 2203 r.set_method("POST"); |
| 2205 | 2204 |
| 2206 r.Start(); | 2205 r.Start(); |
| 2207 EXPECT_TRUE(r.is_pending()); | 2206 EXPECT_TRUE(r.is_pending()); |
| 2208 | 2207 |
| 2209 MessageLoop::current()->Run(); | 2208 MessageLoop::current()->Run(); |
| 2210 | 2209 |
| 2211 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 2210 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
| 2212 (int) r.status().status() << ", error: " << r.status().error(); | 2211 (int) r.status().status() << ", error: " << r.status().error(); |
| 2213 | 2212 |
| 2214 EXPECT_FALSE(d.received_data_before_response()); | 2213 EXPECT_FALSE(d.received_data_before_response()); |
| 2215 EXPECT_TRUE(d.data_received().empty()); | 2214 EXPECT_TRUE(d.data_received().empty()); |
| 2216 } | 2215 } |
| 2217 } | 2216 } |
| 2218 | 2217 |
| 2219 TEST_F(URLRequestTestHTTP, PostFileTest) { | 2218 TEST_F(URLRequestTestHTTP, PostFileTest) { |
| 2220 ASSERT_TRUE(test_server_.Start()); | 2219 ASSERT_TRUE(test_server_.Start()); |
| 2221 | 2220 |
| 2222 TestDelegate d; | 2221 TestDelegate d; |
| 2223 { | 2222 { |
| 2224 TestURLRequest r(test_server_.GetURL("echo"), &d); | 2223 TestURLRequest r(test_server_.GetURL("echo"), &d); |
| 2225 r.set_context(default_context_); | 2224 r.set_context(&default_context_); |
| 2226 r.set_method("POST"); | 2225 r.set_method("POST"); |
| 2227 | 2226 |
| 2228 FilePath dir; | 2227 FilePath dir; |
| 2229 PathService::Get(base::DIR_EXE, &dir); | 2228 PathService::Get(base::DIR_EXE, &dir); |
| 2230 file_util::SetCurrentDirectory(dir); | 2229 file_util::SetCurrentDirectory(dir); |
| 2231 | 2230 |
| 2232 scoped_refptr<UploadData> upload_data(new UploadData); | 2231 scoped_refptr<UploadData> upload_data(new UploadData); |
| 2233 | 2232 |
| 2234 FilePath path; | 2233 FilePath path; |
| 2235 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 2234 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2269 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); | 2268 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); |
| 2270 } | 2269 } |
| 2271 } | 2270 } |
| 2272 | 2271 |
| 2273 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 2272 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
| 2274 ASSERT_TRUE(test_server_.Start()); | 2273 ASSERT_TRUE(test_server_.Start()); |
| 2275 | 2274 |
| 2276 TestDelegate d; | 2275 TestDelegate d; |
| 2277 { | 2276 { |
| 2278 TestURLRequest r(test_server_.GetURL("echo"), &d); | 2277 TestURLRequest r(test_server_.GetURL("echo"), &d); |
| 2279 r.set_context(default_context_); | 2278 r.set_context(&default_context_); |
| 2280 r.EnableChunkedUpload(); | 2279 r.EnableChunkedUpload(); |
| 2281 r.set_method("POST"); | 2280 r.set_method("POST"); |
| 2282 AddChunksToUpload(&r); | 2281 AddChunksToUpload(&r); |
| 2283 r.Start(); | 2282 r.Start(); |
| 2284 EXPECT_TRUE(r.is_pending()); | 2283 EXPECT_TRUE(r.is_pending()); |
| 2285 | 2284 |
| 2286 MessageLoop::current()->Run(); | 2285 MessageLoop::current()->Run(); |
| 2287 | 2286 |
| 2288 VerifyReceivedDataMatchesChunks(&r, &d); | 2287 VerifyReceivedDataMatchesChunks(&r, &d); |
| 2289 } | 2288 } |
| 2290 } | 2289 } |
| 2291 | 2290 |
| 2292 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 2291 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
| 2293 ASSERT_TRUE(test_server_.Start()); | 2292 ASSERT_TRUE(test_server_.Start()); |
| 2294 | 2293 |
| 2295 TestDelegate d; | 2294 TestDelegate d; |
| 2296 { | 2295 { |
| 2297 TestURLRequest r(test_server_.GetURL("echo"), &d); | 2296 TestURLRequest r(test_server_.GetURL("echo"), &d); |
| 2298 r.set_context(default_context_); | 2297 r.set_context(&default_context_); |
| 2299 r.EnableChunkedUpload(); | 2298 r.EnableChunkedUpload(); |
| 2300 r.set_method("POST"); | 2299 r.set_method("POST"); |
| 2301 r.Start(); | 2300 r.Start(); |
| 2302 EXPECT_TRUE(r.is_pending()); | 2301 EXPECT_TRUE(r.is_pending()); |
| 2303 | 2302 |
| 2304 MessageLoop::current()->RunAllPending(); | 2303 MessageLoop::current()->RunAllPending(); |
| 2305 AddChunksToUpload(&r); | 2304 AddChunksToUpload(&r); |
| 2306 MessageLoop::current()->Run(); | 2305 MessageLoop::current()->Run(); |
| 2307 | 2306 |
| 2308 VerifyReceivedDataMatchesChunks(&r, &d); | 2307 VerifyReceivedDataMatchesChunks(&r, &d); |
| 2309 } | 2308 } |
| 2310 } | 2309 } |
| 2311 | 2310 |
| 2312 TEST_F(URLRequestTest, AboutBlankTest) { | 2311 TEST_F(URLRequestTest, AboutBlankTest) { |
| 2313 TestDelegate d; | 2312 TestDelegate d; |
| 2314 { | 2313 { |
| 2315 TestURLRequest r(GURL("about:blank"), &d); | 2314 TestURLRequest r(GURL("about:blank"), &d); |
| 2316 r.set_context(default_context_); | 2315 r.set_context(&default_context_); |
| 2317 | 2316 |
| 2318 r.Start(); | 2317 r.Start(); |
| 2319 EXPECT_TRUE(r.is_pending()); | 2318 EXPECT_TRUE(r.is_pending()); |
| 2320 | 2319 |
| 2321 MessageLoop::current()->Run(); | 2320 MessageLoop::current()->Run(); |
| 2322 | 2321 |
| 2323 EXPECT_TRUE(!r.is_pending()); | 2322 EXPECT_TRUE(!r.is_pending()); |
| 2324 EXPECT_FALSE(d.received_data_before_response()); | 2323 EXPECT_FALSE(d.received_data_before_response()); |
| 2325 EXPECT_EQ(d.bytes_received(), 0); | 2324 EXPECT_EQ(d.bytes_received(), 0); |
| 2326 EXPECT_EQ("", r.GetSocketAddress().host()); | 2325 EXPECT_EQ("", r.GetSocketAddress().host()); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 2346 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" | 2345 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" |
| 2347 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" | 2346 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" |
| 2348 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" | 2347 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" |
| 2349 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" | 2348 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" |
| 2350 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" | 2349 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" |
| 2351 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" | 2350 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" |
| 2352 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" | 2351 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" |
| 2353 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" | 2352 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" |
| 2354 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), | 2353 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), |
| 2355 &d); | 2354 &d); |
| 2356 r.set_context(default_context_); | 2355 r.set_context(&default_context_); |
| 2357 | 2356 |
| 2358 r.Start(); | 2357 r.Start(); |
| 2359 EXPECT_TRUE(r.is_pending()); | 2358 EXPECT_TRUE(r.is_pending()); |
| 2360 | 2359 |
| 2361 MessageLoop::current()->Run(); | 2360 MessageLoop::current()->Run(); |
| 2362 | 2361 |
| 2363 EXPECT_TRUE(!r.is_pending()); | 2362 EXPECT_TRUE(!r.is_pending()); |
| 2364 EXPECT_FALSE(d.received_data_before_response()); | 2363 EXPECT_FALSE(d.received_data_before_response()); |
| 2365 EXPECT_EQ(d.bytes_received(), 911); | 2364 EXPECT_EQ(d.bytes_received(), 911); |
| 2366 EXPECT_EQ("", r.GetSocketAddress().host()); | 2365 EXPECT_EQ("", r.GetSocketAddress().host()); |
| 2367 EXPECT_EQ(0, r.GetSocketAddress().port()); | 2366 EXPECT_EQ(0, r.GetSocketAddress().port()); |
| 2368 } | 2367 } |
| 2369 } | 2368 } |
| 2370 | 2369 |
| 2371 TEST_F(URLRequestTest, FileTest) { | 2370 TEST_F(URLRequestTest, FileTest) { |
| 2372 FilePath app_path; | 2371 FilePath app_path; |
| 2373 PathService::Get(base::FILE_EXE, &app_path); | 2372 PathService::Get(base::FILE_EXE, &app_path); |
| 2374 GURL app_url = FilePathToFileURL(app_path); | 2373 GURL app_url = FilePathToFileURL(app_path); |
| 2375 | 2374 |
| 2376 TestDelegate d; | 2375 TestDelegate d; |
| 2377 { | 2376 { |
| 2378 TestURLRequest r(app_url, &d); | 2377 TestURLRequest r(app_url, &d); |
| 2379 r.set_context(default_context_); | 2378 r.set_context(&default_context_); |
| 2380 | 2379 |
| 2381 r.Start(); | 2380 r.Start(); |
| 2382 EXPECT_TRUE(r.is_pending()); | 2381 EXPECT_TRUE(r.is_pending()); |
| 2383 | 2382 |
| 2384 MessageLoop::current()->Run(); | 2383 MessageLoop::current()->Run(); |
| 2385 | 2384 |
| 2386 int64 file_size = -1; | 2385 int64 file_size = -1; |
| 2387 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); | 2386 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); |
| 2388 | 2387 |
| 2389 EXPECT_TRUE(!r.is_pending()); | 2388 EXPECT_TRUE(!r.is_pending()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 2410 | 2409 |
| 2411 const size_t first_byte_position = 500; | 2410 const size_t first_byte_position = 500; |
| 2412 const size_t last_byte_position = buffer_size - first_byte_position; | 2411 const size_t last_byte_position = buffer_size - first_byte_position; |
| 2413 const size_t content_length = last_byte_position - first_byte_position + 1; | 2412 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 2414 std::string partial_buffer_string(buffer.get() + first_byte_position, | 2413 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 2415 buffer.get() + last_byte_position + 1); | 2414 buffer.get() + last_byte_position + 1); |
| 2416 | 2415 |
| 2417 TestDelegate d; | 2416 TestDelegate d; |
| 2418 { | 2417 { |
| 2419 TestURLRequest r(temp_url, &d); | 2418 TestURLRequest r(temp_url, &d); |
| 2420 r.set_context(default_context_); | 2419 r.set_context(&default_context_); |
| 2421 | 2420 |
| 2422 HttpRequestHeaders headers; | 2421 HttpRequestHeaders headers; |
| 2423 headers.SetHeader(HttpRequestHeaders::kRange, | 2422 headers.SetHeader(HttpRequestHeaders::kRange, |
| 2424 base::StringPrintf( | 2423 base::StringPrintf( |
| 2425 "bytes=%" PRIuS "-%" PRIuS, | 2424 "bytes=%" PRIuS "-%" PRIuS, |
| 2426 first_byte_position, last_byte_position)); | 2425 first_byte_position, last_byte_position)); |
| 2427 r.SetExtraRequestHeaders(headers); | 2426 r.SetExtraRequestHeaders(headers); |
| 2428 r.Start(); | 2427 r.Start(); |
| 2429 EXPECT_TRUE(r.is_pending()); | 2428 EXPECT_TRUE(r.is_pending()); |
| 2430 | 2429 |
| (...skipping 24 matching lines...) Expand all Loading... |
| 2455 | 2454 |
| 2456 const size_t first_byte_position = 500; | 2455 const size_t first_byte_position = 500; |
| 2457 const size_t last_byte_position = buffer_size - 1; | 2456 const size_t last_byte_position = buffer_size - 1; |
| 2458 const size_t content_length = last_byte_position - first_byte_position + 1; | 2457 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 2459 std::string partial_buffer_string(buffer.get() + first_byte_position, | 2458 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 2460 buffer.get() + last_byte_position + 1); | 2459 buffer.get() + last_byte_position + 1); |
| 2461 | 2460 |
| 2462 TestDelegate d; | 2461 TestDelegate d; |
| 2463 { | 2462 { |
| 2464 TestURLRequest r(temp_url, &d); | 2463 TestURLRequest r(temp_url, &d); |
| 2465 r.set_context(default_context_); | 2464 r.set_context(&default_context_); |
| 2466 | 2465 |
| 2467 HttpRequestHeaders headers; | 2466 HttpRequestHeaders headers; |
| 2468 headers.SetHeader(HttpRequestHeaders::kRange, | 2467 headers.SetHeader(HttpRequestHeaders::kRange, |
| 2469 base::StringPrintf("bytes=%" PRIuS "-", | 2468 base::StringPrintf("bytes=%" PRIuS "-", |
| 2470 first_byte_position)); | 2469 first_byte_position)); |
| 2471 r.SetExtraRequestHeaders(headers); | 2470 r.SetExtraRequestHeaders(headers); |
| 2472 r.Start(); | 2471 r.Start(); |
| 2473 EXPECT_TRUE(r.is_pending()); | 2472 EXPECT_TRUE(r.is_pending()); |
| 2474 | 2473 |
| 2475 MessageLoop::current()->Run(); | 2474 MessageLoop::current()->Run(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 2493 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); | 2492 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); |
| 2494 GURL temp_url = FilePathToFileURL(temp_path); | 2493 GURL temp_url = FilePathToFileURL(temp_path); |
| 2495 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 2494 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 2496 | 2495 |
| 2497 int64 file_size; | 2496 int64 file_size; |
| 2498 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 2497 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
| 2499 | 2498 |
| 2500 TestDelegate d; | 2499 TestDelegate d; |
| 2501 { | 2500 { |
| 2502 TestURLRequest r(temp_url, &d); | 2501 TestURLRequest r(temp_url, &d); |
| 2503 r.set_context(default_context_); | 2502 r.set_context(&default_context_); |
| 2504 | 2503 |
| 2505 HttpRequestHeaders headers; | 2504 HttpRequestHeaders headers; |
| 2506 headers.SetHeader(HttpRequestHeaders::kRange, | 2505 headers.SetHeader(HttpRequestHeaders::kRange, |
| 2507 "bytes=0-0,10-200,200-300"); | 2506 "bytes=0-0,10-200,200-300"); |
| 2508 r.SetExtraRequestHeaders(headers); | 2507 r.SetExtraRequestHeaders(headers); |
| 2509 r.Start(); | 2508 r.Start(); |
| 2510 EXPECT_TRUE(r.is_pending()); | 2509 EXPECT_TRUE(r.is_pending()); |
| 2511 | 2510 |
| 2512 MessageLoop::current()->Run(); | 2511 MessageLoop::current()->Run(); |
| 2513 EXPECT_TRUE(d.request_failed()); | 2512 EXPECT_TRUE(d.request_failed()); |
| 2514 } | 2513 } |
| 2515 | 2514 |
| 2516 EXPECT_TRUE(file_util::Delete(temp_path, false)); | 2515 EXPECT_TRUE(file_util::Delete(temp_path, false)); |
| 2517 } | 2516 } |
| 2518 | 2517 |
| 2519 TEST_F(URLRequestTest, InvalidUrlTest) { | 2518 TEST_F(URLRequestTest, InvalidUrlTest) { |
| 2520 TestDelegate d; | 2519 TestDelegate d; |
| 2521 { | 2520 { |
| 2522 TestURLRequest r(GURL("invalid url"), &d); | 2521 TestURLRequest r(GURL("invalid url"), &d); |
| 2523 r.set_context(default_context_); | 2522 r.set_context(&default_context_); |
| 2524 | 2523 |
| 2525 r.Start(); | 2524 r.Start(); |
| 2526 EXPECT_TRUE(r.is_pending()); | 2525 EXPECT_TRUE(r.is_pending()); |
| 2527 | 2526 |
| 2528 MessageLoop::current()->Run(); | 2527 MessageLoop::current()->Run(); |
| 2529 EXPECT_TRUE(d.request_failed()); | 2528 EXPECT_TRUE(d.request_failed()); |
| 2530 } | 2529 } |
| 2531 } | 2530 } |
| 2532 | 2531 |
| 2533 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 2532 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
| 2534 ASSERT_TRUE(test_server_.Start()); | 2533 ASSERT_TRUE(test_server_.Start()); |
| 2535 | 2534 |
| 2536 TestDelegate d; | 2535 TestDelegate d; |
| 2537 TestURLRequest req(test_server_.GetURL("files/with-headers.html"), &d); | 2536 TestURLRequest req(test_server_.GetURL("files/with-headers.html"), &d); |
| 2538 req.set_context(default_context_); | 2537 req.set_context(&default_context_); |
| 2539 req.Start(); | 2538 req.Start(); |
| 2540 MessageLoop::current()->Run(); | 2539 MessageLoop::current()->Run(); |
| 2541 | 2540 |
| 2542 const HttpResponseHeaders* headers = req.response_headers(); | 2541 const HttpResponseHeaders* headers = req.response_headers(); |
| 2543 | 2542 |
| 2544 // Simple sanity check that response_info() accesses the same data. | 2543 // Simple sanity check that response_info() accesses the same data. |
| 2545 EXPECT_EQ(headers, req.response_info().headers.get()); | 2544 EXPECT_EQ(headers, req.response_info().headers.get()); |
| 2546 | 2545 |
| 2547 std::string header; | 2546 std::string header; |
| 2548 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 2547 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2590 result = persist->Save(lnk_path.c_str(), TRUE); | 2589 result = persist->Save(lnk_path.c_str(), TRUE); |
| 2591 EXPECT_TRUE(SUCCEEDED(result)); | 2590 EXPECT_TRUE(SUCCEEDED(result)); |
| 2592 if (persist) | 2591 if (persist) |
| 2593 persist->Release(); | 2592 persist->Release(); |
| 2594 if (shell) | 2593 if (shell) |
| 2595 shell->Release(); | 2594 shell->Release(); |
| 2596 | 2595 |
| 2597 TestDelegate d; | 2596 TestDelegate d; |
| 2598 { | 2597 { |
| 2599 TestURLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d); | 2598 TestURLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d); |
| 2600 r.set_context(default_context_); | 2599 r.set_context(&default_context_); |
| 2601 | 2600 |
| 2602 r.Start(); | 2601 r.Start(); |
| 2603 EXPECT_TRUE(r.is_pending()); | 2602 EXPECT_TRUE(r.is_pending()); |
| 2604 | 2603 |
| 2605 MessageLoop::current()->Run(); | 2604 MessageLoop::current()->Run(); |
| 2606 | 2605 |
| 2607 WIN32_FILE_ATTRIBUTE_DATA data; | 2606 WIN32_FILE_ATTRIBUTE_DATA data; |
| 2608 GetFileAttributesEx(app_path.value().c_str(), | 2607 GetFileAttributesEx(app_path.value().c_str(), |
| 2609 GetFileExInfoStandard, &data); | 2608 GetFileExInfoStandard, &data); |
| 2610 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, | 2609 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, |
| (...skipping 18 matching lines...) Expand all Loading... |
| 2629 CoUninitialize(); | 2628 CoUninitialize(); |
| 2630 } | 2629 } |
| 2631 #endif // defined(OS_WIN) | 2630 #endif // defined(OS_WIN) |
| 2632 | 2631 |
| 2633 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { | 2632 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { |
| 2634 ASSERT_TRUE(test_server_.Start()); | 2633 ASSERT_TRUE(test_server_.Start()); |
| 2635 | 2634 |
| 2636 TestDelegate d; | 2635 TestDelegate d; |
| 2637 TestURLRequest req(test_server_.GetURL( | 2636 TestURLRequest req(test_server_.GetURL( |
| 2638 "files/content-type-normalization.html"), &d); | 2637 "files/content-type-normalization.html"), &d); |
| 2639 req.set_context(default_context_); | 2638 req.set_context(&default_context_); |
| 2640 req.Start(); | 2639 req.Start(); |
| 2641 MessageLoop::current()->Run(); | 2640 MessageLoop::current()->Run(); |
| 2642 | 2641 |
| 2643 std::string mime_type; | 2642 std::string mime_type; |
| 2644 req.GetMimeType(&mime_type); | 2643 req.GetMimeType(&mime_type); |
| 2645 EXPECT_EQ("text/html", mime_type); | 2644 EXPECT_EQ("text/html", mime_type); |
| 2646 | 2645 |
| 2647 std::string charset; | 2646 std::string charset; |
| 2648 req.GetCharset(&charset); | 2647 req.GetCharset(&charset); |
| 2649 EXPECT_EQ("utf-8", charset); | 2648 EXPECT_EQ("utf-8", charset); |
| 2650 req.Cancel(); | 2649 req.Cancel(); |
| 2651 } | 2650 } |
| 2652 | 2651 |
| 2653 TEST_F(URLRequestTest, FileDirCancelTest) { | 2652 TEST_F(URLRequestTest, FileDirCancelTest) { |
| 2654 // Put in mock resource provider. | 2653 // Put in mock resource provider. |
| 2655 NetModule::SetResourceProvider(TestNetResourceProvider); | 2654 NetModule::SetResourceProvider(TestNetResourceProvider); |
| 2656 | 2655 |
| 2657 TestDelegate d; | 2656 TestDelegate d; |
| 2658 { | 2657 { |
| 2659 FilePath file_path; | 2658 FilePath file_path; |
| 2660 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 2659 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
| 2661 file_path = file_path.Append(FILE_PATH_LITERAL("net")); | 2660 file_path = file_path.Append(FILE_PATH_LITERAL("net")); |
| 2662 file_path = file_path.Append(FILE_PATH_LITERAL("data")); | 2661 file_path = file_path.Append(FILE_PATH_LITERAL("data")); |
| 2663 | 2662 |
| 2664 TestURLRequest req(FilePathToFileURL(file_path), &d); | 2663 TestURLRequest req(FilePathToFileURL(file_path), &d); |
| 2665 req.set_context(default_context_); | 2664 req.set_context(&default_context_); |
| 2666 req.Start(); | 2665 req.Start(); |
| 2667 EXPECT_TRUE(req.is_pending()); | 2666 EXPECT_TRUE(req.is_pending()); |
| 2668 | 2667 |
| 2669 d.set_cancel_in_received_data_pending(true); | 2668 d.set_cancel_in_received_data_pending(true); |
| 2670 | 2669 |
| 2671 MessageLoop::current()->Run(); | 2670 MessageLoop::current()->Run(); |
| 2672 } | 2671 } |
| 2673 | 2672 |
| 2674 // Take out mock resource provider. | 2673 // Take out mock resource provider. |
| 2675 NetModule::SetResourceProvider(NULL); | 2674 NetModule::SetResourceProvider(NULL); |
| 2676 } | 2675 } |
| 2677 | 2676 |
| 2678 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { | 2677 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { |
| 2679 // There is an implicit redirect when loading a file path that matches a | 2678 // There is an implicit redirect when loading a file path that matches a |
| 2680 // directory and does not end with a slash. Ensure that following such | 2679 // directory and does not end with a slash. Ensure that following such |
| 2681 // redirects does not crash. See http://crbug.com/18686. | 2680 // redirects does not crash. See http://crbug.com/18686. |
| 2682 | 2681 |
| 2683 FilePath path; | 2682 FilePath path; |
| 2684 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 2683 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 2685 path = path.Append(FILE_PATH_LITERAL("net")); | 2684 path = path.Append(FILE_PATH_LITERAL("net")); |
| 2686 path = path.Append(FILE_PATH_LITERAL("data")); | 2685 path = path.Append(FILE_PATH_LITERAL("data")); |
| 2687 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 2686 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 2688 | 2687 |
| 2689 TestDelegate d; | 2688 TestDelegate d; |
| 2690 TestURLRequest req(FilePathToFileURL(path), &d); | 2689 TestURLRequest req(FilePathToFileURL(path), &d); |
| 2691 req.set_context(default_context_); | 2690 req.set_context(&default_context_); |
| 2692 req.Start(); | 2691 req.Start(); |
| 2693 MessageLoop::current()->Run(); | 2692 MessageLoop::current()->Run(); |
| 2694 | 2693 |
| 2695 ASSERT_EQ(1, d.received_redirect_count()); | 2694 ASSERT_EQ(1, d.received_redirect_count()); |
| 2696 ASSERT_LT(0, d.bytes_received()); | 2695 ASSERT_LT(0, d.bytes_received()); |
| 2697 ASSERT_FALSE(d.request_failed()); | 2696 ASSERT_FALSE(d.request_failed()); |
| 2698 ASSERT_TRUE(req.status().is_success()); | 2697 ASSERT_TRUE(req.status().is_success()); |
| 2699 } | 2698 } |
| 2700 | 2699 |
| 2701 #if defined(OS_WIN) | 2700 #if defined(OS_WIN) |
| 2702 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. | 2701 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. |
| 2703 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { | 2702 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { |
| 2704 TestDelegate d; | 2703 TestDelegate d; |
| 2705 TestURLRequest req(GURL("file:///"), &d); | 2704 TestURLRequest req(GURL("file:///"), &d); |
| 2706 req.set_context(default_context_); | 2705 req.set_context(&default_context_); |
| 2707 req.Start(); | 2706 req.Start(); |
| 2708 MessageLoop::current()->Run(); | 2707 MessageLoop::current()->Run(); |
| 2709 | 2708 |
| 2710 ASSERT_EQ(1, d.received_redirect_count()); | 2709 ASSERT_EQ(1, d.received_redirect_count()); |
| 2711 ASSERT_FALSE(req.status().is_success()); | 2710 ASSERT_FALSE(req.status().is_success()); |
| 2712 } | 2711 } |
| 2713 #endif | 2712 #endif |
| 2714 | 2713 |
| 2715 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 2714 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
| 2716 ASSERT_TRUE(test_server_.Start()); | 2715 ASSERT_TRUE(test_server_.Start()); |
| 2717 | 2716 |
| 2718 TestDelegate d; | 2717 TestDelegate d; |
| 2719 TestURLRequest req(test_server_.GetURL( | 2718 TestURLRequest req(test_server_.GetURL( |
| 2720 "files/redirect-to-file.html"), &d); | 2719 "files/redirect-to-file.html"), &d); |
| 2721 req.set_context(default_context_); | 2720 req.set_context(&default_context_); |
| 2722 req.Start(); | 2721 req.Start(); |
| 2723 MessageLoop::current()->Run(); | 2722 MessageLoop::current()->Run(); |
| 2724 | 2723 |
| 2725 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 2724 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 2726 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 2725 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); |
| 2727 } | 2726 } |
| 2728 | 2727 |
| 2729 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 2728 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
| 2730 ASSERT_TRUE(test_server_.Start()); | 2729 ASSERT_TRUE(test_server_.Start()); |
| 2731 | 2730 |
| 2732 TestDelegate d; | 2731 TestDelegate d; |
| 2733 TestURLRequest req(test_server_.GetURL( | 2732 TestURLRequest req(test_server_.GetURL( |
| 2734 "files/redirect-to-invalid-url.html"), &d); | 2733 "files/redirect-to-invalid-url.html"), &d); |
| 2735 req.set_context(default_context_); | 2734 req.set_context(&default_context_); |
| 2736 req.Start(); | 2735 req.Start(); |
| 2737 MessageLoop::current()->Run(); | 2736 MessageLoop::current()->Run(); |
| 2738 | 2737 |
| 2739 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 2738 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 2740 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); | 2739 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); |
| 2741 } | 2740 } |
| 2742 | 2741 |
| 2743 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 2742 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
| 2744 ASSERT_TRUE(test_server_.Start()); | 2743 ASSERT_TRUE(test_server_.Start()); |
| 2745 | 2744 |
| 2746 TestDelegate d; | 2745 TestDelegate d; |
| 2747 TestURLRequest req(test_server_.GetURL("echoheader?Referer"), &d); | 2746 TestURLRequest req(test_server_.GetURL("echoheader?Referer"), &d); |
| 2748 req.set_context(default_context_); | 2747 req.set_context(&default_context_); |
| 2749 req.set_referrer("http://user:pass@foo.com/"); | 2748 req.set_referrer("http://user:pass@foo.com/"); |
| 2750 req.Start(); | 2749 req.Start(); |
| 2751 MessageLoop::current()->Run(); | 2750 MessageLoop::current()->Run(); |
| 2752 | 2751 |
| 2753 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 2752 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
| 2754 } | 2753 } |
| 2755 | 2754 |
| 2756 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 2755 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
| 2757 ASSERT_TRUE(test_server_.Start()); | 2756 ASSERT_TRUE(test_server_.Start()); |
| 2758 | 2757 |
| 2759 TestDelegate d; | 2758 TestDelegate d; |
| 2760 { | 2759 { |
| 2761 d.set_cancel_in_received_redirect(true); | 2760 d.set_cancel_in_received_redirect(true); |
| 2762 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); | 2761 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); |
| 2763 req.set_context(default_context_); | 2762 req.set_context(&default_context_); |
| 2764 req.Start(); | 2763 req.Start(); |
| 2765 MessageLoop::current()->Run(); | 2764 MessageLoop::current()->Run(); |
| 2766 | 2765 |
| 2767 EXPECT_EQ(1, d.response_started_count()); | 2766 EXPECT_EQ(1, d.response_started_count()); |
| 2768 EXPECT_EQ(0, d.bytes_received()); | 2767 EXPECT_EQ(0, d.bytes_received()); |
| 2769 EXPECT_FALSE(d.received_data_before_response()); | 2768 EXPECT_FALSE(d.received_data_before_response()); |
| 2770 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 2769 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 2771 } | 2770 } |
| 2772 } | 2771 } |
| 2773 | 2772 |
| 2774 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 2773 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
| 2775 ASSERT_TRUE(test_server_.Start()); | 2774 ASSERT_TRUE(test_server_.Start()); |
| 2776 | 2775 |
| 2777 TestDelegate d; | 2776 TestDelegate d; |
| 2778 { | 2777 { |
| 2779 d.set_quit_on_redirect(true); | 2778 d.set_quit_on_redirect(true); |
| 2780 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); | 2779 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); |
| 2781 req.set_context(default_context_); | 2780 req.set_context(&default_context_); |
| 2782 req.Start(); | 2781 req.Start(); |
| 2783 MessageLoop::current()->Run(); | 2782 MessageLoop::current()->Run(); |
| 2784 | 2783 |
| 2785 EXPECT_EQ(1, d.received_redirect_count()); | 2784 EXPECT_EQ(1, d.received_redirect_count()); |
| 2786 | 2785 |
| 2787 req.FollowDeferredRedirect(); | 2786 req.FollowDeferredRedirect(); |
| 2788 MessageLoop::current()->Run(); | 2787 MessageLoop::current()->Run(); |
| 2789 | 2788 |
| 2790 EXPECT_EQ(1, d.response_started_count()); | 2789 EXPECT_EQ(1, d.response_started_count()); |
| 2791 EXPECT_FALSE(d.received_data_before_response()); | 2790 EXPECT_FALSE(d.received_data_before_response()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 2804 } | 2803 } |
| 2805 } | 2804 } |
| 2806 | 2805 |
| 2807 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 2806 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
| 2808 ASSERT_TRUE(test_server_.Start()); | 2807 ASSERT_TRUE(test_server_.Start()); |
| 2809 | 2808 |
| 2810 TestDelegate d; | 2809 TestDelegate d; |
| 2811 { | 2810 { |
| 2812 d.set_quit_on_redirect(true); | 2811 d.set_quit_on_redirect(true); |
| 2813 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); | 2812 TestURLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); |
| 2814 req.set_context(default_context_); | 2813 req.set_context(&default_context_); |
| 2815 req.Start(); | 2814 req.Start(); |
| 2816 MessageLoop::current()->Run(); | 2815 MessageLoop::current()->Run(); |
| 2817 | 2816 |
| 2818 EXPECT_EQ(1, d.received_redirect_count()); | 2817 EXPECT_EQ(1, d.received_redirect_count()); |
| 2819 | 2818 |
| 2820 req.Cancel(); | 2819 req.Cancel(); |
| 2821 MessageLoop::current()->Run(); | 2820 MessageLoop::current()->Run(); |
| 2822 | 2821 |
| 2823 EXPECT_EQ(1, d.response_started_count()); | 2822 EXPECT_EQ(1, d.response_started_count()); |
| 2824 EXPECT_EQ(0, d.bytes_received()); | 2823 EXPECT_EQ(0, d.bytes_received()); |
| 2825 EXPECT_FALSE(d.received_data_before_response()); | 2824 EXPECT_FALSE(d.received_data_before_response()); |
| 2826 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 2825 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 2827 } | 2826 } |
| 2828 } | 2827 } |
| 2829 | 2828 |
| 2830 TEST_F(URLRequestTestHTTP, VaryHeader) { | 2829 TEST_F(URLRequestTestHTTP, VaryHeader) { |
| 2831 ASSERT_TRUE(test_server_.Start()); | 2830 ASSERT_TRUE(test_server_.Start()); |
| 2832 | 2831 |
| 2833 // populate the cache | 2832 // populate the cache |
| 2834 { | 2833 { |
| 2835 TestDelegate d; | 2834 TestDelegate d; |
| 2836 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); | 2835 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); |
| 2837 req.set_context(default_context_); | 2836 req.set_context(&default_context_); |
| 2838 HttpRequestHeaders headers; | 2837 HttpRequestHeaders headers; |
| 2839 headers.SetHeader("foo", "1"); | 2838 headers.SetHeader("foo", "1"); |
| 2840 req.SetExtraRequestHeaders(headers); | 2839 req.SetExtraRequestHeaders(headers); |
| 2841 req.Start(); | 2840 req.Start(); |
| 2842 MessageLoop::current()->Run(); | 2841 MessageLoop::current()->Run(); |
| 2843 } | 2842 } |
| 2844 | 2843 |
| 2845 // expect a cache hit | 2844 // expect a cache hit |
| 2846 { | 2845 { |
| 2847 TestDelegate d; | 2846 TestDelegate d; |
| 2848 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); | 2847 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); |
| 2849 req.set_context(default_context_); | 2848 req.set_context(&default_context_); |
| 2850 HttpRequestHeaders headers; | 2849 HttpRequestHeaders headers; |
| 2851 headers.SetHeader("foo", "1"); | 2850 headers.SetHeader("foo", "1"); |
| 2852 req.SetExtraRequestHeaders(headers); | 2851 req.SetExtraRequestHeaders(headers); |
| 2853 req.Start(); | 2852 req.Start(); |
| 2854 MessageLoop::current()->Run(); | 2853 MessageLoop::current()->Run(); |
| 2855 | 2854 |
| 2856 EXPECT_TRUE(req.was_cached()); | 2855 EXPECT_TRUE(req.was_cached()); |
| 2857 } | 2856 } |
| 2858 | 2857 |
| 2859 // expect a cache miss | 2858 // expect a cache miss |
| 2860 { | 2859 { |
| 2861 TestDelegate d; | 2860 TestDelegate d; |
| 2862 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); | 2861 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); |
| 2863 req.set_context(default_context_); | 2862 req.set_context(&default_context_); |
| 2864 HttpRequestHeaders headers; | 2863 HttpRequestHeaders headers; |
| 2865 headers.SetHeader("foo", "2"); | 2864 headers.SetHeader("foo", "2"); |
| 2866 req.SetExtraRequestHeaders(headers); | 2865 req.SetExtraRequestHeaders(headers); |
| 2867 req.Start(); | 2866 req.Start(); |
| 2868 MessageLoop::current()->Run(); | 2867 MessageLoop::current()->Run(); |
| 2869 | 2868 |
| 2870 EXPECT_FALSE(req.was_cached()); | 2869 EXPECT_FALSE(req.was_cached()); |
| 2871 } | 2870 } |
| 2872 } | 2871 } |
| 2873 | 2872 |
| 2874 TEST_F(URLRequestTestHTTP, BasicAuth) { | 2873 TEST_F(URLRequestTestHTTP, BasicAuth) { |
| 2875 ASSERT_TRUE(test_server_.Start()); | 2874 ASSERT_TRUE(test_server_.Start()); |
| 2876 | 2875 |
| 2877 // populate the cache | 2876 // populate the cache |
| 2878 { | 2877 { |
| 2879 TestDelegate d; | 2878 TestDelegate d; |
| 2880 d.set_credentials(AuthCredentials(kUser, kSecret)); | 2879 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 2881 | 2880 |
| 2882 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 2881 URLRequest r(test_server_.GetURL("auth-basic"), &d); |
| 2883 r.set_context(default_context_); | 2882 r.set_context(&default_context_); |
| 2884 r.Start(); | 2883 r.Start(); |
| 2885 | 2884 |
| 2886 MessageLoop::current()->Run(); | 2885 MessageLoop::current()->Run(); |
| 2887 | 2886 |
| 2888 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 2887 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 2889 } | 2888 } |
| 2890 | 2889 |
| 2891 // repeat request with end-to-end validation. since auth-basic results in a | 2890 // repeat request with end-to-end validation. since auth-basic results in a |
| 2892 // cachable page, we expect this test to result in a 304. in which case, the | 2891 // cachable page, we expect this test to result in a 304. in which case, the |
| 2893 // response should be fetched from the cache. | 2892 // response should be fetched from the cache. |
| 2894 { | 2893 { |
| 2895 TestDelegate d; | 2894 TestDelegate d; |
| 2896 d.set_credentials(AuthCredentials(kUser, kSecret)); | 2895 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 2897 | 2896 |
| 2898 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 2897 URLRequest r(test_server_.GetURL("auth-basic"), &d); |
| 2899 r.set_context(default_context_); | 2898 r.set_context(&default_context_); |
| 2900 r.set_load_flags(LOAD_VALIDATE_CACHE); | 2899 r.set_load_flags(LOAD_VALIDATE_CACHE); |
| 2901 r.Start(); | 2900 r.Start(); |
| 2902 | 2901 |
| 2903 MessageLoop::current()->Run(); | 2902 MessageLoop::current()->Run(); |
| 2904 | 2903 |
| 2905 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 2904 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 2906 | 2905 |
| 2907 // Should be the same cached document. | 2906 // Should be the same cached document. |
| 2908 EXPECT_TRUE(r.was_cached()); | 2907 EXPECT_TRUE(r.was_cached()); |
| 2909 } | 2908 } |
| 2910 } | 2909 } |
| 2911 | 2910 |
| 2912 // Check that Set-Cookie headers in 401 responses are respected. | 2911 // Check that Set-Cookie headers in 401 responses are respected. |
| 2913 // http://crbug.com/6450 | 2912 // http://crbug.com/6450 |
| 2914 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { | 2913 TEST_F(URLRequestTestHTTP, BasicAuthWithCookies) { |
| 2915 ASSERT_TRUE(test_server_.Start()); | 2914 ASSERT_TRUE(test_server_.Start()); |
| 2916 | 2915 |
| 2917 GURL url_requiring_auth = | 2916 GURL url_requiring_auth = |
| 2918 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); | 2917 test_server_.GetURL("auth-basic?set-cookie-if-challenged"); |
| 2919 | 2918 |
| 2920 // Request a page that will give a 401 containing a Set-Cookie header. | 2919 // Request a page that will give a 401 containing a Set-Cookie header. |
| 2921 // Verify that when the transaction is restarted, it includes the new cookie. | 2920 // Verify that when the transaction is restarted, it includes the new cookie. |
| 2922 { | 2921 { |
| 2923 TestNetworkDelegate network_delegate; // must outlive URLRequest | 2922 TestNetworkDelegate network_delegate; // must outlive URLRequest |
| 2924 scoped_refptr<TestURLRequestContext> context( | 2923 TestURLRequestContext context(true); |
| 2925 new TestURLRequestContext(true)); | 2924 context.set_network_delegate(&network_delegate); |
| 2926 context->set_network_delegate(&network_delegate); | 2925 context.Init(); |
| 2927 context->Init(); | |
| 2928 | 2926 |
| 2929 TestDelegate d; | 2927 TestDelegate d; |
| 2930 d.set_credentials(AuthCredentials(kUser, kSecret)); | 2928 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 2931 | 2929 |
| 2932 URLRequest r(url_requiring_auth, &d); | 2930 URLRequest r(url_requiring_auth, &d); |
| 2933 r.set_context(context); | 2931 r.set_context(&context); |
| 2934 r.Start(); | 2932 r.Start(); |
| 2935 | 2933 |
| 2936 MessageLoop::current()->Run(); | 2934 MessageLoop::current()->Run(); |
| 2937 | 2935 |
| 2938 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 2936 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 2939 | 2937 |
| 2940 // Make sure we sent the cookie in the restarted transaction. | 2938 // Make sure we sent the cookie in the restarted transaction. |
| 2941 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 2939 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 2942 != std::string::npos); | 2940 != std::string::npos); |
| 2943 } | 2941 } |
| 2944 } | 2942 } |
| 2945 | 2943 |
| 2946 TEST_F(URLRequestTest, DelayedCookieCallback) { | 2944 TEST_F(URLRequestTest, DelayedCookieCallback) { |
| 2947 LocalHttpTestServer test_server; | 2945 LocalHttpTestServer test_server; |
| 2948 ASSERT_TRUE(test_server.Start()); | 2946 ASSERT_TRUE(test_server.Start()); |
| 2949 | 2947 |
| 2950 scoped_refptr<URLRequestContext> context(new TestURLRequestContext()); | 2948 TestURLRequestContext context; |
| 2951 scoped_refptr<DelayedCookieMonster> delayed_cm = | 2949 scoped_refptr<DelayedCookieMonster> delayed_cm = |
| 2952 new DelayedCookieMonster(); | 2950 new DelayedCookieMonster(); |
| 2953 scoped_refptr<CookieStore> cookie_store = delayed_cm; | 2951 scoped_refptr<CookieStore> cookie_store = delayed_cm; |
| 2954 context->set_cookie_store(delayed_cm); | 2952 context.set_cookie_store(delayed_cm); |
| 2955 | 2953 |
| 2956 // Set up a cookie. | 2954 // Set up a cookie. |
| 2957 { | 2955 { |
| 2958 TestNetworkDelegate network_delegate; | 2956 TestNetworkDelegate network_delegate; |
| 2959 context->set_network_delegate(&network_delegate); | 2957 context.set_network_delegate(&network_delegate); |
| 2960 TestDelegate d; | 2958 TestDelegate d; |
| 2961 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 2959 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
| 2962 req.set_context(context); | 2960 req.set_context(&context); |
| 2963 req.Start(); | 2961 req.Start(); |
| 2964 MessageLoop::current()->Run(); | 2962 MessageLoop::current()->Run(); |
| 2965 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2963 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2966 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2964 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2967 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2965 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2968 } | 2966 } |
| 2969 | 2967 |
| 2970 // Verify that the cookie is set. | 2968 // Verify that the cookie is set. |
| 2971 { | 2969 { |
| 2972 TestNetworkDelegate network_delegate; | 2970 TestNetworkDelegate network_delegate; |
| 2973 context->set_network_delegate(&network_delegate); | 2971 context.set_network_delegate(&network_delegate); |
| 2974 TestDelegate d; | 2972 TestDelegate d; |
| 2975 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 2973 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 2976 req.set_context(context); | 2974 req.set_context(&context); |
| 2977 req.Start(); | 2975 req.Start(); |
| 2978 MessageLoop::current()->Run(); | 2976 MessageLoop::current()->Run(); |
| 2979 | 2977 |
| 2980 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2978 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2981 != std::string::npos); | 2979 != std::string::npos); |
| 2982 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2980 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2983 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2981 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2984 } | 2982 } |
| 2985 } | 2983 } |
| 2986 | 2984 |
| 2987 TEST_F(URLRequestTest, DoNotSendCookies) { | 2985 TEST_F(URLRequestTest, DoNotSendCookies) { |
| 2988 LocalHttpTestServer test_server; | 2986 LocalHttpTestServer test_server; |
| 2989 ASSERT_TRUE(test_server.Start()); | 2987 ASSERT_TRUE(test_server.Start()); |
| 2990 | 2988 |
| 2991 // Set up a cookie. | 2989 // Set up a cookie. |
| 2992 { | 2990 { |
| 2993 TestNetworkDelegate network_delegate; | 2991 TestNetworkDelegate network_delegate; |
| 2994 default_context_->set_network_delegate(&network_delegate); | 2992 default_context_.set_network_delegate(&network_delegate); |
| 2995 TestDelegate d; | 2993 TestDelegate d; |
| 2996 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 2994 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
| 2997 req.set_context(default_context_); | 2995 req.set_context(&default_context_); |
| 2998 req.Start(); | 2996 req.Start(); |
| 2999 MessageLoop::current()->Run(); | 2997 MessageLoop::current()->Run(); |
| 3000 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2998 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3001 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2999 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3002 } | 3000 } |
| 3003 | 3001 |
| 3004 // Verify that the cookie is set. | 3002 // Verify that the cookie is set. |
| 3005 { | 3003 { |
| 3006 TestNetworkDelegate network_delegate; | 3004 TestNetworkDelegate network_delegate; |
| 3007 default_context_->set_network_delegate(&network_delegate); | 3005 default_context_.set_network_delegate(&network_delegate); |
| 3008 TestDelegate d; | 3006 TestDelegate d; |
| 3009 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3007 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3010 req.set_context(default_context_); | 3008 req.set_context(&default_context_); |
| 3011 req.Start(); | 3009 req.Start(); |
| 3012 MessageLoop::current()->Run(); | 3010 MessageLoop::current()->Run(); |
| 3013 | 3011 |
| 3014 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 3012 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 3015 != std::string::npos); | 3013 != std::string::npos); |
| 3016 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3014 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3017 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3015 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3018 } | 3016 } |
| 3019 | 3017 |
| 3020 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 3018 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
| 3021 { | 3019 { |
| 3022 TestNetworkDelegate network_delegate; | 3020 TestNetworkDelegate network_delegate; |
| 3023 default_context_->set_network_delegate(&network_delegate); | 3021 default_context_.set_network_delegate(&network_delegate); |
| 3024 TestDelegate d; | 3022 TestDelegate d; |
| 3025 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3023 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3026 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); | 3024 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); |
| 3027 req.set_context(default_context_); | 3025 req.set_context(&default_context_); |
| 3028 req.Start(); | 3026 req.Start(); |
| 3029 MessageLoop::current()->Run(); | 3027 MessageLoop::current()->Run(); |
| 3030 | 3028 |
| 3031 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 3029 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 3032 == std::string::npos); | 3030 == std::string::npos); |
| 3033 | 3031 |
| 3034 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 3032 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
| 3035 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3033 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3036 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3034 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3037 } | 3035 } |
| 3038 | 3036 |
| 3039 default_context_->set_network_delegate(&default_network_delegate_); | 3037 default_context_.set_network_delegate(&default_network_delegate_); |
| 3040 } | 3038 } |
| 3041 | 3039 |
| 3042 TEST_F(URLRequestTest, DoNotSaveCookies) { | 3040 TEST_F(URLRequestTest, DoNotSaveCookies) { |
| 3043 LocalHttpTestServer test_server; | 3041 LocalHttpTestServer test_server; |
| 3044 ASSERT_TRUE(test_server.Start()); | 3042 ASSERT_TRUE(test_server.Start()); |
| 3045 | 3043 |
| 3046 // Set up a cookie. | 3044 // Set up a cookie. |
| 3047 { | 3045 { |
| 3048 TestNetworkDelegate network_delegate; | 3046 TestNetworkDelegate network_delegate; |
| 3049 default_context_->set_network_delegate(&network_delegate); | 3047 default_context_.set_network_delegate(&network_delegate); |
| 3050 TestDelegate d; | 3048 TestDelegate d; |
| 3051 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); | 3049 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); |
| 3052 req.set_context(default_context_); | 3050 req.set_context(&default_context_); |
| 3053 req.Start(); | 3051 req.Start(); |
| 3054 MessageLoop::current()->Run(); | 3052 MessageLoop::current()->Run(); |
| 3055 | 3053 |
| 3056 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3054 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3057 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3055 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3058 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 3056 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 3059 } | 3057 } |
| 3060 | 3058 |
| 3061 // Try to set-up another cookie and update the previous cookie. | 3059 // Try to set-up another cookie and update the previous cookie. |
| 3062 { | 3060 { |
| 3063 TestNetworkDelegate network_delegate; | 3061 TestNetworkDelegate network_delegate; |
| 3064 default_context_->set_network_delegate(&network_delegate); | 3062 default_context_.set_network_delegate(&network_delegate); |
| 3065 TestDelegate d; | 3063 TestDelegate d; |
| 3066 URLRequest req(test_server.GetURL( | 3064 URLRequest req(test_server.GetURL( |
| 3067 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 3065 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
| 3068 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); | 3066 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); |
| 3069 req.set_context(default_context_); | 3067 req.set_context(&default_context_); |
| 3070 req.Start(); | 3068 req.Start(); |
| 3071 | 3069 |
| 3072 MessageLoop::current()->Run(); | 3070 MessageLoop::current()->Run(); |
| 3073 | 3071 |
| 3074 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 3072 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
| 3075 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3073 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3076 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3074 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3077 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 3075 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 3078 } | 3076 } |
| 3079 | 3077 |
| 3080 // Verify the cookies weren't saved or updated. | 3078 // Verify the cookies weren't saved or updated. |
| 3081 { | 3079 { |
| 3082 TestNetworkDelegate network_delegate; | 3080 TestNetworkDelegate network_delegate; |
| 3083 default_context_->set_network_delegate(&network_delegate); | 3081 default_context_.set_network_delegate(&network_delegate); |
| 3084 TestDelegate d; | 3082 TestDelegate d; |
| 3085 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3083 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3086 req.set_context(default_context_); | 3084 req.set_context(&default_context_); |
| 3087 req.Start(); | 3085 req.Start(); |
| 3088 MessageLoop::current()->Run(); | 3086 MessageLoop::current()->Run(); |
| 3089 | 3087 |
| 3090 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 3088 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 3091 == std::string::npos); | 3089 == std::string::npos); |
| 3092 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 3090 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 3093 != std::string::npos); | 3091 != std::string::npos); |
| 3094 | 3092 |
| 3095 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3093 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3096 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3094 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3097 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 3095 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 3098 } | 3096 } |
| 3099 | 3097 |
| 3100 default_context_->set_network_delegate(&default_network_delegate_); | 3098 default_context_.set_network_delegate(&default_network_delegate_); |
| 3101 } | 3099 } |
| 3102 | 3100 |
| 3103 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 3101 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
| 3104 LocalHttpTestServer test_server; | 3102 LocalHttpTestServer test_server; |
| 3105 ASSERT_TRUE(test_server.Start()); | 3103 ASSERT_TRUE(test_server.Start()); |
| 3106 | 3104 |
| 3107 // Set up a cookie. | 3105 // Set up a cookie. |
| 3108 { | 3106 { |
| 3109 TestNetworkDelegate network_delegate; | 3107 TestNetworkDelegate network_delegate; |
| 3110 default_context_->set_network_delegate(&network_delegate); | 3108 default_context_.set_network_delegate(&network_delegate); |
| 3111 TestDelegate d; | 3109 TestDelegate d; |
| 3112 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 3110 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
| 3113 req.set_context(default_context_); | 3111 req.set_context(&default_context_); |
| 3114 req.Start(); | 3112 req.Start(); |
| 3115 MessageLoop::current()->Run(); | 3113 MessageLoop::current()->Run(); |
| 3116 | 3114 |
| 3117 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3115 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3118 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3116 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3119 } | 3117 } |
| 3120 | 3118 |
| 3121 // Verify that the cookie is set. | 3119 // Verify that the cookie is set. |
| 3122 { | 3120 { |
| 3123 TestNetworkDelegate network_delegate; | 3121 TestNetworkDelegate network_delegate; |
| 3124 default_context_->set_network_delegate(&network_delegate); | 3122 default_context_.set_network_delegate(&network_delegate); |
| 3125 TestDelegate d; | 3123 TestDelegate d; |
| 3126 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3124 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3127 req.set_context(default_context_); | 3125 req.set_context(&default_context_); |
| 3128 req.Start(); | 3126 req.Start(); |
| 3129 MessageLoop::current()->Run(); | 3127 MessageLoop::current()->Run(); |
| 3130 | 3128 |
| 3131 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 3129 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 3132 != std::string::npos); | 3130 != std::string::npos); |
| 3133 | 3131 |
| 3134 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3132 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3135 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3133 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3136 } | 3134 } |
| 3137 | 3135 |
| 3138 // Verify that the cookie isn't sent. | 3136 // Verify that the cookie isn't sent. |
| 3139 { | 3137 { |
| 3140 TestNetworkDelegate network_delegate; | 3138 TestNetworkDelegate network_delegate; |
| 3141 default_context_->set_network_delegate(&network_delegate); | 3139 default_context_.set_network_delegate(&network_delegate); |
| 3142 TestDelegate d; | 3140 TestDelegate d; |
| 3143 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 3141 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 3144 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3142 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3145 req.set_context(default_context_); | 3143 req.set_context(&default_context_); |
| 3146 req.Start(); | 3144 req.Start(); |
| 3147 MessageLoop::current()->Run(); | 3145 MessageLoop::current()->Run(); |
| 3148 | 3146 |
| 3149 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 3147 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 3150 == std::string::npos); | 3148 == std::string::npos); |
| 3151 | 3149 |
| 3152 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 3150 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 3153 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3151 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3154 } | 3152 } |
| 3155 | 3153 |
| 3156 default_context_->set_network_delegate(&default_network_delegate_); | 3154 default_context_.set_network_delegate(&default_network_delegate_); |
| 3157 } | 3155 } |
| 3158 | 3156 |
| 3159 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 3157 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
| 3160 LocalHttpTestServer test_server; | 3158 LocalHttpTestServer test_server; |
| 3161 ASSERT_TRUE(test_server.Start()); | 3159 ASSERT_TRUE(test_server.Start()); |
| 3162 | 3160 |
| 3163 // Set up a cookie. | 3161 // Set up a cookie. |
| 3164 { | 3162 { |
| 3165 TestNetworkDelegate network_delegate; | 3163 TestNetworkDelegate network_delegate; |
| 3166 default_context_->set_network_delegate(&network_delegate); | 3164 default_context_.set_network_delegate(&network_delegate); |
| 3167 TestDelegate d; | 3165 TestDelegate d; |
| 3168 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); | 3166 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); |
| 3169 req.set_context(default_context_); | 3167 req.set_context(&default_context_); |
| 3170 req.Start(); | 3168 req.Start(); |
| 3171 MessageLoop::current()->Run(); | 3169 MessageLoop::current()->Run(); |
| 3172 | 3170 |
| 3173 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3171 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3174 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3172 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3175 } | 3173 } |
| 3176 | 3174 |
| 3177 // Try to set-up another cookie and update the previous cookie. | 3175 // Try to set-up another cookie and update the previous cookie. |
| 3178 { | 3176 { |
| 3179 TestNetworkDelegate network_delegate; | 3177 TestNetworkDelegate network_delegate; |
| 3180 default_context_->set_network_delegate(&network_delegate); | 3178 default_context_.set_network_delegate(&network_delegate); |
| 3181 TestDelegate d; | 3179 TestDelegate d; |
| 3182 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 3180 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 3183 URLRequest req(test_server.GetURL( | 3181 URLRequest req(test_server.GetURL( |
| 3184 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 3182 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
| 3185 req.set_context(default_context_); | 3183 req.set_context(&default_context_); |
| 3186 req.Start(); | 3184 req.Start(); |
| 3187 | 3185 |
| 3188 MessageLoop::current()->Run(); | 3186 MessageLoop::current()->Run(); |
| 3189 | 3187 |
| 3190 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3188 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3191 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 3189 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 3192 } | 3190 } |
| 3193 | 3191 |
| 3194 | 3192 |
| 3195 // Verify the cookies weren't saved or updated. | 3193 // Verify the cookies weren't saved or updated. |
| 3196 { | 3194 { |
| 3197 TestNetworkDelegate network_delegate; | 3195 TestNetworkDelegate network_delegate; |
| 3198 default_context_->set_network_delegate(&network_delegate); | 3196 default_context_.set_network_delegate(&network_delegate); |
| 3199 TestDelegate d; | 3197 TestDelegate d; |
| 3200 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3198 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3201 req.set_context(default_context_); | 3199 req.set_context(&default_context_); |
| 3202 req.Start(); | 3200 req.Start(); |
| 3203 MessageLoop::current()->Run(); | 3201 MessageLoop::current()->Run(); |
| 3204 | 3202 |
| 3205 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 3203 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 3206 == std::string::npos); | 3204 == std::string::npos); |
| 3207 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 3205 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 3208 != std::string::npos); | 3206 != std::string::npos); |
| 3209 | 3207 |
| 3210 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3208 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3211 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3209 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3212 } | 3210 } |
| 3213 | 3211 |
| 3214 default_context_->set_network_delegate(&default_network_delegate_); | 3212 default_context_.set_network_delegate(&default_network_delegate_); |
| 3215 } | 3213 } |
| 3216 | 3214 |
| 3217 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 3215 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
| 3218 LocalHttpTestServer test_server; | 3216 LocalHttpTestServer test_server; |
| 3219 ASSERT_TRUE(test_server.Start()); | 3217 ASSERT_TRUE(test_server.Start()); |
| 3220 | 3218 |
| 3221 // Set up an empty cookie. | 3219 // Set up an empty cookie. |
| 3222 { | 3220 { |
| 3223 TestNetworkDelegate network_delegate; | 3221 TestNetworkDelegate network_delegate; |
| 3224 default_context_->set_network_delegate(&network_delegate); | 3222 default_context_.set_network_delegate(&network_delegate); |
| 3225 TestDelegate d; | 3223 TestDelegate d; |
| 3226 URLRequest req(test_server.GetURL("set-cookie"), &d); | 3224 URLRequest req(test_server.GetURL("set-cookie"), &d); |
| 3227 req.set_context(default_context_); | 3225 req.set_context(&default_context_); |
| 3228 req.Start(); | 3226 req.Start(); |
| 3229 MessageLoop::current()->Run(); | 3227 MessageLoop::current()->Run(); |
| 3230 | 3228 |
| 3231 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3229 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3232 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3230 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3233 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 3231 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 3234 } | 3232 } |
| 3235 | 3233 |
| 3236 default_context_->set_network_delegate(&default_network_delegate_); | 3234 default_context_.set_network_delegate(&default_network_delegate_); |
| 3237 } | 3235 } |
| 3238 | 3236 |
| 3239 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 3237 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
| 3240 LocalHttpTestServer test_server; | 3238 LocalHttpTestServer test_server; |
| 3241 ASSERT_TRUE(test_server.Start()); | 3239 ASSERT_TRUE(test_server.Start()); |
| 3242 | 3240 |
| 3243 // Set up a cookie. | 3241 // Set up a cookie. |
| 3244 { | 3242 { |
| 3245 TestNetworkDelegate network_delegate; | 3243 TestNetworkDelegate network_delegate; |
| 3246 default_context_->set_network_delegate(&network_delegate); | 3244 default_context_.set_network_delegate(&network_delegate); |
| 3247 TestDelegate d; | 3245 TestDelegate d; |
| 3248 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 3246 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); |
| 3249 req.set_context(default_context_); | 3247 req.set_context(&default_context_); |
| 3250 req.Start(); | 3248 req.Start(); |
| 3251 MessageLoop::current()->Run(); | 3249 MessageLoop::current()->Run(); |
| 3252 | 3250 |
| 3253 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3251 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3254 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3252 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3255 } | 3253 } |
| 3256 | 3254 |
| 3257 // Verify that the cookie is set. | 3255 // Verify that the cookie is set. |
| 3258 { | 3256 { |
| 3259 TestNetworkDelegate network_delegate; | 3257 TestNetworkDelegate network_delegate; |
| 3260 default_context_->set_network_delegate(&network_delegate); | 3258 default_context_.set_network_delegate(&network_delegate); |
| 3261 TestDelegate d; | 3259 TestDelegate d; |
| 3262 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3260 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3263 req.set_context(default_context_); | 3261 req.set_context(&default_context_); |
| 3264 req.Start(); | 3262 req.Start(); |
| 3265 MessageLoop::current()->Run(); | 3263 MessageLoop::current()->Run(); |
| 3266 | 3264 |
| 3267 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 3265 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 3268 != std::string::npos); | 3266 != std::string::npos); |
| 3269 | 3267 |
| 3270 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3268 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3271 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3269 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3272 } | 3270 } |
| 3273 | 3271 |
| 3274 // Verify that the cookie isn't sent. | 3272 // Verify that the cookie isn't sent. |
| 3275 { | 3273 { |
| 3276 TestNetworkDelegate network_delegate; | 3274 TestNetworkDelegate network_delegate; |
| 3277 default_context_->set_network_delegate(&network_delegate); | 3275 default_context_.set_network_delegate(&network_delegate); |
| 3278 TestDelegate d; | 3276 TestDelegate d; |
| 3279 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 3277 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 3280 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3278 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3281 req.set_context(default_context_); | 3279 req.set_context(&default_context_); |
| 3282 req.Start(); | 3280 req.Start(); |
| 3283 MessageLoop::current()->Run(); | 3281 MessageLoop::current()->Run(); |
| 3284 | 3282 |
| 3285 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 3283 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 3286 == std::string::npos); | 3284 == std::string::npos); |
| 3287 | 3285 |
| 3288 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 3286 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 3289 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3287 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3290 } | 3288 } |
| 3291 | 3289 |
| 3292 default_context_->set_network_delegate(&default_network_delegate_); | 3290 default_context_.set_network_delegate(&default_network_delegate_); |
| 3293 } | 3291 } |
| 3294 | 3292 |
| 3295 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 3293 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
| 3296 LocalHttpTestServer test_server; | 3294 LocalHttpTestServer test_server; |
| 3297 ASSERT_TRUE(test_server.Start()); | 3295 ASSERT_TRUE(test_server.Start()); |
| 3298 | 3296 |
| 3299 // Set up a cookie. | 3297 // Set up a cookie. |
| 3300 { | 3298 { |
| 3301 TestNetworkDelegate network_delegate; | 3299 TestNetworkDelegate network_delegate; |
| 3302 default_context_->set_network_delegate(&network_delegate); | 3300 default_context_.set_network_delegate(&network_delegate); |
| 3303 TestDelegate d; | 3301 TestDelegate d; |
| 3304 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); | 3302 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); |
| 3305 req.set_context(default_context_); | 3303 req.set_context(&default_context_); |
| 3306 req.Start(); | 3304 req.Start(); |
| 3307 MessageLoop::current()->Run(); | 3305 MessageLoop::current()->Run(); |
| 3308 | 3306 |
| 3309 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3307 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3310 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3308 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3311 } | 3309 } |
| 3312 | 3310 |
| 3313 // Try to set-up another cookie and update the previous cookie. | 3311 // Try to set-up another cookie and update the previous cookie. |
| 3314 { | 3312 { |
| 3315 TestNetworkDelegate network_delegate; | 3313 TestNetworkDelegate network_delegate; |
| 3316 default_context_->set_network_delegate(&network_delegate); | 3314 default_context_.set_network_delegate(&network_delegate); |
| 3317 TestDelegate d; | 3315 TestDelegate d; |
| 3318 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 3316 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 3319 URLRequest req(test_server.GetURL( | 3317 URLRequest req(test_server.GetURL( |
| 3320 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 3318 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); |
| 3321 req.set_context(default_context_); | 3319 req.set_context(&default_context_); |
| 3322 req.Start(); | 3320 req.Start(); |
| 3323 | 3321 |
| 3324 MessageLoop::current()->Run(); | 3322 MessageLoop::current()->Run(); |
| 3325 | 3323 |
| 3326 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3324 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3327 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 3325 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 3328 } | 3326 } |
| 3329 | 3327 |
| 3330 // Verify the cookies weren't saved or updated. | 3328 // Verify the cookies weren't saved or updated. |
| 3331 { | 3329 { |
| 3332 TestNetworkDelegate network_delegate; | 3330 TestNetworkDelegate network_delegate; |
| 3333 default_context_->set_network_delegate(&network_delegate); | 3331 default_context_.set_network_delegate(&network_delegate); |
| 3334 TestDelegate d; | 3332 TestDelegate d; |
| 3335 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3333 TestURLRequest req(test_server.GetURL("echoheader?Cookie"), &d); |
| 3336 req.set_context(default_context_); | 3334 req.set_context(&default_context_); |
| 3337 req.Start(); | 3335 req.Start(); |
| 3338 MessageLoop::current()->Run(); | 3336 MessageLoop::current()->Run(); |
| 3339 | 3337 |
| 3340 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 3338 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 3341 == std::string::npos); | 3339 == std::string::npos); |
| 3342 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 3340 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 3343 != std::string::npos); | 3341 != std::string::npos); |
| 3344 | 3342 |
| 3345 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3343 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3346 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3344 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3347 } | 3345 } |
| 3348 | 3346 |
| 3349 default_context_->set_network_delegate(&default_network_delegate_); | 3347 default_context_.set_network_delegate(&default_network_delegate_); |
| 3350 } | 3348 } |
| 3351 | 3349 |
| 3352 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { | 3350 void CheckCookiePolicyCallback(bool* was_run, const CookieList& cookies) { |
| 3353 EXPECT_EQ(1U, cookies.size()); | 3351 EXPECT_EQ(1U, cookies.size()); |
| 3354 EXPECT_FALSE(cookies[0].IsPersistent()); | 3352 EXPECT_FALSE(cookies[0].IsPersistent()); |
| 3355 *was_run = true; | 3353 *was_run = true; |
| 3356 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); | 3354 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); |
| 3357 } | 3355 } |
| 3358 | 3356 |
| 3359 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 3357 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
| 3360 LocalHttpTestServer test_server; | 3358 LocalHttpTestServer test_server; |
| 3361 ASSERT_TRUE(test_server.Start()); | 3359 ASSERT_TRUE(test_server.Start()); |
| 3362 | 3360 |
| 3363 // Set up a cookie. | 3361 // Set up a cookie. |
| 3364 { | 3362 { |
| 3365 TestNetworkDelegate network_delegate; | 3363 TestNetworkDelegate network_delegate; |
| 3366 default_context_->set_network_delegate(&network_delegate); | 3364 default_context_.set_network_delegate(&network_delegate); |
| 3367 TestDelegate d; | 3365 TestDelegate d; |
| 3368 network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION); | 3366 network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION); |
| 3369 URLRequest req(test_server.GetURL( | 3367 URLRequest req(test_server.GetURL( |
| 3370 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); | 3368 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); |
| 3371 req.set_context(default_context_); | 3369 req.set_context(&default_context_); |
| 3372 req.Start(); // Triggers an asynchronous cookie policy check. | 3370 req.Start(); // Triggers an asynchronous cookie policy check. |
| 3373 | 3371 |
| 3374 MessageLoop::current()->Run(); | 3372 MessageLoop::current()->Run(); |
| 3375 | 3373 |
| 3376 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3374 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3377 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3375 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3378 } | 3376 } |
| 3379 default_context_->set_network_delegate(&default_network_delegate_); | 3377 default_context_.set_network_delegate(&default_network_delegate_); |
| 3380 | 3378 |
| 3381 // Now, check the cookie store. | 3379 // Now, check the cookie store. |
| 3382 bool was_run = false; | 3380 bool was_run = false; |
| 3383 default_context_->cookie_store()->GetCookieMonster()->GetAllCookiesAsync( | 3381 default_context_.cookie_store()->GetCookieMonster()->GetAllCookiesAsync( |
| 3384 base::Bind(&CheckCookiePolicyCallback, &was_run)); | 3382 base::Bind(&CheckCookiePolicyCallback, &was_run)); |
| 3385 MessageLoop::current()->RunAllPending(); | 3383 MessageLoop::current()->RunAllPending(); |
| 3386 DCHECK(was_run); | 3384 DCHECK(was_run); |
| 3387 } | 3385 } |
| 3388 | 3386 |
| 3389 // In this test, we do a POST which the server will 302 redirect. | 3387 // In this test, we do a POST which the server will 302 redirect. |
| 3390 // The subsequent transaction should use GET, and should not send the | 3388 // The subsequent transaction should use GET, and should not send the |
| 3391 // Content-Type header. | 3389 // Content-Type header. |
| 3392 // http://code.google.com/p/chromium/issues/detail?id=843 | 3390 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 3393 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 3391 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
| 3394 ASSERT_TRUE(test_server_.Start()); | 3392 ASSERT_TRUE(test_server_.Start()); |
| 3395 | 3393 |
| 3396 const char kData[] = "hello world"; | 3394 const char kData[] = "hello world"; |
| 3397 | 3395 |
| 3398 TestDelegate d; | 3396 TestDelegate d; |
| 3399 TestURLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); | 3397 TestURLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); |
| 3400 req.set_context(default_context_); | 3398 req.set_context(&default_context_); |
| 3401 req.set_method("POST"); | 3399 req.set_method("POST"); |
| 3402 req.set_upload(CreateSimpleUploadData(kData)); | 3400 req.set_upload(CreateSimpleUploadData(kData)); |
| 3403 | 3401 |
| 3404 // Set headers (some of which are specific to the POST). | 3402 // Set headers (some of which are specific to the POST). |
| 3405 HttpRequestHeaders headers; | 3403 HttpRequestHeaders headers; |
| 3406 headers.AddHeadersFromString( | 3404 headers.AddHeadersFromString( |
| 3407 "Content-Type: multipart/form-data; " | 3405 "Content-Type: multipart/form-data; " |
| 3408 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 3406 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
| 3409 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 3407 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
| 3410 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 3408 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
| (...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3477 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 3475 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 3478 } | 3476 } |
| 3479 | 3477 |
| 3480 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 3478 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
| 3481 ASSERT_TRUE(test_server_.Start()); | 3479 ASSERT_TRUE(test_server_.Start()); |
| 3482 | 3480 |
| 3483 const char kData[] = "hello world"; | 3481 const char kData[] = "hello world"; |
| 3484 | 3482 |
| 3485 TestDelegate d; | 3483 TestDelegate d; |
| 3486 TestURLRequest req(test_server_.GetURL("empty.html"), &d); | 3484 TestURLRequest req(test_server_.GetURL("empty.html"), &d); |
| 3487 req.set_context(default_context_); | 3485 req.set_context(&default_context_); |
| 3488 req.set_method("POST"); | 3486 req.set_method("POST"); |
| 3489 req.set_upload(CreateSimpleUploadData(kData).get()); | 3487 req.set_upload(CreateSimpleUploadData(kData).get()); |
| 3490 HttpRequestHeaders headers; | 3488 HttpRequestHeaders headers; |
| 3491 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3489 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 3492 base::UintToString(arraysize(kData) - 1)); | 3490 base::UintToString(arraysize(kData) - 1)); |
| 3493 req.SetExtraRequestHeaders(headers); | 3491 req.SetExtraRequestHeaders(headers); |
| 3494 | 3492 |
| 3495 URLRequestRedirectJob* job = | 3493 URLRequestRedirectJob* job = |
| 3496 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); | 3494 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); |
| 3497 AddTestInterceptor()->set_main_intercept_job(job); | 3495 AddTestInterceptor()->set_main_intercept_job(job); |
| 3498 | 3496 |
| 3499 req.Start(); | 3497 req.Start(); |
| 3500 MessageLoop::current()->Run(); | 3498 MessageLoop::current()->Run(); |
| 3501 EXPECT_EQ("GET", req.method()); | 3499 EXPECT_EQ("GET", req.method()); |
| 3502 } | 3500 } |
| 3503 | 3501 |
| 3504 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 3502 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
| 3505 ASSERT_TRUE(test_server_.Start()); | 3503 ASSERT_TRUE(test_server_.Start()); |
| 3506 | 3504 |
| 3507 const char kData[] = "hello world"; | 3505 const char kData[] = "hello world"; |
| 3508 | 3506 |
| 3509 TestDelegate d; | 3507 TestDelegate d; |
| 3510 TestURLRequest req(test_server_.GetURL("empty.html"), &d); | 3508 TestURLRequest req(test_server_.GetURL("empty.html"), &d); |
| 3511 req.set_context(default_context_); | 3509 req.set_context(&default_context_); |
| 3512 req.set_method("POST"); | 3510 req.set_method("POST"); |
| 3513 req.set_upload(CreateSimpleUploadData(kData).get()); | 3511 req.set_upload(CreateSimpleUploadData(kData).get()); |
| 3514 HttpRequestHeaders headers; | 3512 HttpRequestHeaders headers; |
| 3515 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3513 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 3516 base::UintToString(arraysize(kData) - 1)); | 3514 base::UintToString(arraysize(kData) - 1)); |
| 3517 req.SetExtraRequestHeaders(headers); | 3515 req.SetExtraRequestHeaders(headers); |
| 3518 | 3516 |
| 3519 URLRequestRedirectJob* job = | 3517 URLRequestRedirectJob* job = |
| 3520 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); | 3518 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); |
| 3521 job->set_redirect_code( | 3519 job->set_redirect_code( |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3721 TEST_F(URLRequestTest, Intercept) { | 3719 TEST_F(URLRequestTest, Intercept) { |
| 3722 TestInterceptor interceptor; | 3720 TestInterceptor interceptor; |
| 3723 | 3721 |
| 3724 // intercept the main request and respond with a simple response | 3722 // intercept the main request and respond with a simple response |
| 3725 interceptor.intercept_main_request_ = true; | 3723 interceptor.intercept_main_request_ = true; |
| 3726 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 3724 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
| 3727 interceptor.main_data_ = TestInterceptor::ok_data(); | 3725 interceptor.main_data_ = TestInterceptor::ok_data(); |
| 3728 | 3726 |
| 3729 TestDelegate d; | 3727 TestDelegate d; |
| 3730 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3728 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3731 req.set_context(default_context_); | 3729 req.set_context(&default_context_); |
| 3732 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); | 3730 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); |
| 3733 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); | 3731 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); |
| 3734 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); | 3732 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); |
| 3735 req.SetUserData(NULL, user_data0); | 3733 req.SetUserData(NULL, user_data0); |
| 3736 req.SetUserData(&user_data1, user_data1); | 3734 req.SetUserData(&user_data1, user_data1); |
| 3737 req.SetUserData(&user_data2, user_data2); | 3735 req.SetUserData(&user_data2, user_data2); |
| 3738 req.set_method("GET"); | 3736 req.set_method("GET"); |
| 3739 req.Start(); | 3737 req.Start(); |
| 3740 MessageLoop::current()->Run(); | 3738 MessageLoop::current()->Run(); |
| 3741 | 3739 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 3763 interceptor.main_headers_ = TestInterceptor::redirect_headers(); | 3761 interceptor.main_headers_ = TestInterceptor::redirect_headers(); |
| 3764 interceptor.main_data_ = TestInterceptor::redirect_data(); | 3762 interceptor.main_data_ = TestInterceptor::redirect_data(); |
| 3765 | 3763 |
| 3766 // intercept that redirect and respond a final OK response | 3764 // intercept that redirect and respond a final OK response |
| 3767 interceptor.intercept_redirect_ = true; | 3765 interceptor.intercept_redirect_ = true; |
| 3768 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); | 3766 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); |
| 3769 interceptor.redirect_data_ = TestInterceptor::ok_data(); | 3767 interceptor.redirect_data_ = TestInterceptor::ok_data(); |
| 3770 | 3768 |
| 3771 TestDelegate d; | 3769 TestDelegate d; |
| 3772 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3770 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3773 req.set_context(default_context_); | 3771 req.set_context(&default_context_); |
| 3774 req.set_method("GET"); | 3772 req.set_method("GET"); |
| 3775 req.Start(); | 3773 req.Start(); |
| 3776 MessageLoop::current()->Run(); | 3774 MessageLoop::current()->Run(); |
| 3777 | 3775 |
| 3778 // Check the interceptor got called as expected | 3776 // Check the interceptor got called as expected |
| 3779 EXPECT_TRUE(interceptor.did_intercept_main_); | 3777 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 3780 EXPECT_TRUE(interceptor.did_intercept_redirect_); | 3778 EXPECT_TRUE(interceptor.did_intercept_redirect_); |
| 3781 | 3779 |
| 3782 // Check we got one good response | 3780 // Check we got one good response |
| 3783 EXPECT_TRUE(req.status().is_success()); | 3781 EXPECT_TRUE(req.status().is_success()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3797 interceptor.main_headers_ = TestInterceptor::error_headers(); | 3795 interceptor.main_headers_ = TestInterceptor::error_headers(); |
| 3798 interceptor.main_data_ = TestInterceptor::error_data(); | 3796 interceptor.main_data_ = TestInterceptor::error_data(); |
| 3799 | 3797 |
| 3800 // intercept that error and respond with an OK response | 3798 // intercept that error and respond with an OK response |
| 3801 interceptor.intercept_final_response_ = true; | 3799 interceptor.intercept_final_response_ = true; |
| 3802 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3800 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 3803 interceptor.final_data_ = TestInterceptor::ok_data(); | 3801 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 3804 | 3802 |
| 3805 TestDelegate d; | 3803 TestDelegate d; |
| 3806 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3804 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3807 req.set_context(default_context_); | 3805 req.set_context(&default_context_); |
| 3808 req.set_method("GET"); | 3806 req.set_method("GET"); |
| 3809 req.Start(); | 3807 req.Start(); |
| 3810 MessageLoop::current()->Run(); | 3808 MessageLoop::current()->Run(); |
| 3811 | 3809 |
| 3812 // Check the interceptor got called as expected | 3810 // Check the interceptor got called as expected |
| 3813 EXPECT_TRUE(interceptor.did_intercept_main_); | 3811 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 3814 EXPECT_TRUE(interceptor.did_intercept_final_); | 3812 EXPECT_TRUE(interceptor.did_intercept_final_); |
| 3815 | 3813 |
| 3816 // Check we got one good response | 3814 // Check we got one good response |
| 3817 EXPECT_TRUE(req.status().is_success()); | 3815 EXPECT_TRUE(req.status().is_success()); |
| 3818 EXPECT_EQ(200, req.response_headers()->response_code()); | 3816 EXPECT_EQ(200, req.response_headers()->response_code()); |
| 3819 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 3817 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 3820 EXPECT_EQ(1, d.response_started_count()); | 3818 EXPECT_EQ(1, d.response_started_count()); |
| 3821 EXPECT_EQ(0, d.received_redirect_count()); | 3819 EXPECT_EQ(0, d.received_redirect_count()); |
| 3822 } | 3820 } |
| 3823 | 3821 |
| 3824 TEST_F(URLRequestTest, InterceptNetworkError) { | 3822 TEST_F(URLRequestTest, InterceptNetworkError) { |
| 3825 TestInterceptor interceptor; | 3823 TestInterceptor interceptor; |
| 3826 | 3824 |
| 3827 // intercept the main request to simulate a network error | 3825 // intercept the main request to simulate a network error |
| 3828 interceptor.simulate_main_network_error_ = true; | 3826 interceptor.simulate_main_network_error_ = true; |
| 3829 | 3827 |
| 3830 // intercept that error and respond with an OK response | 3828 // intercept that error and respond with an OK response |
| 3831 interceptor.intercept_final_response_ = true; | 3829 interceptor.intercept_final_response_ = true; |
| 3832 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3830 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 3833 interceptor.final_data_ = TestInterceptor::ok_data(); | 3831 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 3834 | 3832 |
| 3835 TestDelegate d; | 3833 TestDelegate d; |
| 3836 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3834 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3837 req.set_context(default_context_); | 3835 req.set_context(&default_context_); |
| 3838 req.set_method("GET"); | 3836 req.set_method("GET"); |
| 3839 req.Start(); | 3837 req.Start(); |
| 3840 MessageLoop::current()->Run(); | 3838 MessageLoop::current()->Run(); |
| 3841 | 3839 |
| 3842 // Check the interceptor got called as expected | 3840 // Check the interceptor got called as expected |
| 3843 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 3841 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
| 3844 EXPECT_TRUE(interceptor.did_intercept_final_); | 3842 EXPECT_TRUE(interceptor.did_intercept_final_); |
| 3845 | 3843 |
| 3846 // Check we received one good response | 3844 // Check we received one good response |
| 3847 EXPECT_TRUE(req.status().is_success()); | 3845 EXPECT_TRUE(req.status().is_success()); |
| 3848 EXPECT_EQ(200, req.response_headers()->response_code()); | 3846 EXPECT_EQ(200, req.response_headers()->response_code()); |
| 3849 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 3847 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
| 3850 EXPECT_EQ(1, d.response_started_count()); | 3848 EXPECT_EQ(1, d.response_started_count()); |
| 3851 EXPECT_EQ(0, d.received_redirect_count()); | 3849 EXPECT_EQ(0, d.received_redirect_count()); |
| 3852 } | 3850 } |
| 3853 | 3851 |
| 3854 TEST_F(URLRequestTest, InterceptRestartRequired) { | 3852 TEST_F(URLRequestTest, InterceptRestartRequired) { |
| 3855 TestInterceptor interceptor; | 3853 TestInterceptor interceptor; |
| 3856 | 3854 |
| 3857 // restart the main request | 3855 // restart the main request |
| 3858 interceptor.restart_main_request_ = true; | 3856 interceptor.restart_main_request_ = true; |
| 3859 | 3857 |
| 3860 // then intercept the new main request and respond with an OK response | 3858 // then intercept the new main request and respond with an OK response |
| 3861 interceptor.intercept_main_request_ = true; | 3859 interceptor.intercept_main_request_ = true; |
| 3862 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 3860 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
| 3863 interceptor.main_data_ = TestInterceptor::ok_data(); | 3861 interceptor.main_data_ = TestInterceptor::ok_data(); |
| 3864 | 3862 |
| 3865 TestDelegate d; | 3863 TestDelegate d; |
| 3866 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3864 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3867 req.set_context(default_context_); | 3865 req.set_context(&default_context_); |
| 3868 req.set_method("GET"); | 3866 req.set_method("GET"); |
| 3869 req.Start(); | 3867 req.Start(); |
| 3870 MessageLoop::current()->Run(); | 3868 MessageLoop::current()->Run(); |
| 3871 | 3869 |
| 3872 // Check the interceptor got called as expected | 3870 // Check the interceptor got called as expected |
| 3873 EXPECT_TRUE(interceptor.did_restart_main_); | 3871 EXPECT_TRUE(interceptor.did_restart_main_); |
| 3874 EXPECT_TRUE(interceptor.did_intercept_main_); | 3872 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 3875 | 3873 |
| 3876 // Check we received one good response | 3874 // Check we received one good response |
| 3877 EXPECT_TRUE(req.status().is_success()); | 3875 EXPECT_TRUE(req.status().is_success()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3889 // intercept the main request and cancel from within the restarted job | 3887 // intercept the main request and cancel from within the restarted job |
| 3890 interceptor.cancel_main_request_ = true; | 3888 interceptor.cancel_main_request_ = true; |
| 3891 | 3889 |
| 3892 // setup to intercept final response and override it with an OK response | 3890 // setup to intercept final response and override it with an OK response |
| 3893 interceptor.intercept_final_response_ = true; | 3891 interceptor.intercept_final_response_ = true; |
| 3894 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3892 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 3895 interceptor.final_data_ = TestInterceptor::ok_data(); | 3893 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 3896 | 3894 |
| 3897 TestDelegate d; | 3895 TestDelegate d; |
| 3898 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3896 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3899 req.set_context(default_context_); | 3897 req.set_context(&default_context_); |
| 3900 req.set_method("GET"); | 3898 req.set_method("GET"); |
| 3901 req.Start(); | 3899 req.Start(); |
| 3902 MessageLoop::current()->Run(); | 3900 MessageLoop::current()->Run(); |
| 3903 | 3901 |
| 3904 // Check the interceptor got called as expected | 3902 // Check the interceptor got called as expected |
| 3905 EXPECT_TRUE(interceptor.did_cancel_main_); | 3903 EXPECT_TRUE(interceptor.did_cancel_main_); |
| 3906 EXPECT_FALSE(interceptor.did_intercept_final_); | 3904 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 3907 | 3905 |
| 3908 // Check we see a canceled request | 3906 // Check we see a canceled request |
| 3909 EXPECT_FALSE(req.status().is_success()); | 3907 EXPECT_FALSE(req.status().is_success()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3921 // intercept the redirect and cancel from within that job | 3919 // intercept the redirect and cancel from within that job |
| 3922 interceptor.cancel_redirect_request_ = true; | 3920 interceptor.cancel_redirect_request_ = true; |
| 3923 | 3921 |
| 3924 // setup to intercept final response and override it with an OK response | 3922 // setup to intercept final response and override it with an OK response |
| 3925 interceptor.intercept_final_response_ = true; | 3923 interceptor.intercept_final_response_ = true; |
| 3926 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3924 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 3927 interceptor.final_data_ = TestInterceptor::ok_data(); | 3925 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 3928 | 3926 |
| 3929 TestDelegate d; | 3927 TestDelegate d; |
| 3930 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3928 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3931 req.set_context(default_context_); | 3929 req.set_context(&default_context_); |
| 3932 req.set_method("GET"); | 3930 req.set_method("GET"); |
| 3933 req.Start(); | 3931 req.Start(); |
| 3934 MessageLoop::current()->Run(); | 3932 MessageLoop::current()->Run(); |
| 3935 | 3933 |
| 3936 // Check the interceptor got called as expected | 3934 // Check the interceptor got called as expected |
| 3937 EXPECT_TRUE(interceptor.did_intercept_main_); | 3935 EXPECT_TRUE(interceptor.did_intercept_main_); |
| 3938 EXPECT_TRUE(interceptor.did_cancel_redirect_); | 3936 EXPECT_TRUE(interceptor.did_cancel_redirect_); |
| 3939 EXPECT_FALSE(interceptor.did_intercept_final_); | 3937 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 3940 | 3938 |
| 3941 // Check we see a canceled request | 3939 // Check we see a canceled request |
| 3942 EXPECT_FALSE(req.status().is_success()); | 3940 EXPECT_FALSE(req.status().is_success()); |
| 3943 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 3941 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 3944 } | 3942 } |
| 3945 | 3943 |
| 3946 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { | 3944 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { |
| 3947 TestInterceptor interceptor; | 3945 TestInterceptor interceptor; |
| 3948 | 3946 |
| 3949 // intercept the main request to simulate a network error | 3947 // intercept the main request to simulate a network error |
| 3950 interceptor.simulate_main_network_error_ = true; | 3948 interceptor.simulate_main_network_error_ = true; |
| 3951 | 3949 |
| 3952 // setup to intercept final response and cancel from within that job | 3950 // setup to intercept final response and cancel from within that job |
| 3953 interceptor.cancel_final_request_ = true; | 3951 interceptor.cancel_final_request_ = true; |
| 3954 | 3952 |
| 3955 TestDelegate d; | 3953 TestDelegate d; |
| 3956 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3954 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3957 req.set_context(default_context_); | 3955 req.set_context(&default_context_); |
| 3958 req.set_method("GET"); | 3956 req.set_method("GET"); |
| 3959 req.Start(); | 3957 req.Start(); |
| 3960 MessageLoop::current()->Run(); | 3958 MessageLoop::current()->Run(); |
| 3961 | 3959 |
| 3962 // Check the interceptor got called as expected | 3960 // Check the interceptor got called as expected |
| 3963 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 3961 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
| 3964 EXPECT_TRUE(interceptor.did_cancel_final_); | 3962 EXPECT_TRUE(interceptor.did_cancel_final_); |
| 3965 | 3963 |
| 3966 // Check we see a canceled request | 3964 // Check we see a canceled request |
| 3967 EXPECT_FALSE(req.status().is_success()); | 3965 EXPECT_FALSE(req.status().is_success()); |
| 3968 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 3966 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 3969 } | 3967 } |
| 3970 | 3968 |
| 3971 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { | 3969 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { |
| 3972 TestInterceptor interceptor; | 3970 TestInterceptor interceptor; |
| 3973 | 3971 |
| 3974 // intercept the main request and cancel then restart from within that job | 3972 // intercept the main request and cancel then restart from within that job |
| 3975 interceptor.cancel_then_restart_main_request_ = true; | 3973 interceptor.cancel_then_restart_main_request_ = true; |
| 3976 | 3974 |
| 3977 // setup to intercept final response and override it with an OK response | 3975 // setup to intercept final response and override it with an OK response |
| 3978 interceptor.intercept_final_response_ = true; | 3976 interceptor.intercept_final_response_ = true; |
| 3979 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3977 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
| 3980 interceptor.final_data_ = TestInterceptor::ok_data(); | 3978 interceptor.final_data_ = TestInterceptor::ok_data(); |
| 3981 | 3979 |
| 3982 TestDelegate d; | 3980 TestDelegate d; |
| 3983 TestURLRequest req(GURL("http://test_intercept/foo"), &d); | 3981 TestURLRequest req(GURL("http://test_intercept/foo"), &d); |
| 3984 req.set_context(default_context_); | 3982 req.set_context(&default_context_); |
| 3985 req.set_method("GET"); | 3983 req.set_method("GET"); |
| 3986 req.Start(); | 3984 req.Start(); |
| 3987 MessageLoop::current()->Run(); | 3985 MessageLoop::current()->Run(); |
| 3988 | 3986 |
| 3989 // Check the interceptor got called as expected | 3987 // Check the interceptor got called as expected |
| 3990 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); | 3988 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); |
| 3991 EXPECT_FALSE(interceptor.did_intercept_final_); | 3989 EXPECT_FALSE(interceptor.did_intercept_final_); |
| 3992 | 3990 |
| 3993 // Check we see a canceled request | 3991 // Check we see a canceled request |
| 3994 EXPECT_FALSE(req.status().is_success()); | 3992 EXPECT_FALSE(req.status().is_success()); |
| 3995 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 3993 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
| 3996 } | 3994 } |
| 3997 | 3995 |
| 3998 // Check that two different URL requests have different identifiers. | 3996 // Check that two different URL requests have different identifiers. |
| 3999 TEST_F(URLRequestTest, Identifiers) { | 3997 TEST_F(URLRequestTest, Identifiers) { |
| 4000 TestDelegate d; | 3998 TestDelegate d; |
| 4001 TestURLRequest req(GURL("http://example.com"), &d); | 3999 TestURLRequest req(GURL("http://example.com"), &d); |
| 4002 TestURLRequest other_req(GURL("http://example.com"), &d); | 4000 TestURLRequest other_req(GURL("http://example.com"), &d); |
| 4003 | 4001 |
| 4004 ASSERT_NE(req.identifier(), other_req.identifier()); | 4002 ASSERT_NE(req.identifier(), other_req.identifier()); |
| 4005 } | 4003 } |
| 4006 | 4004 |
| 4007 // Check that a failure to connect to the proxy is reported to the network | 4005 // Check that a failure to connect to the proxy is reported to the network |
| 4008 // delegate. | 4006 // delegate. |
| 4009 TEST_F(URLRequestTest, NetworkDelegateProxyError) { | 4007 TEST_F(URLRequestTest, NetworkDelegateProxyError) { |
| 4010 MockHostResolver host_resolver; | 4008 MockHostResolver host_resolver; |
| 4011 host_resolver.rules()->AddSimulatedFailure("*"); | 4009 host_resolver.rules()->AddSimulatedFailure("*"); |
| 4012 | 4010 |
| 4013 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4011 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 4014 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 4012 TestURLRequestContext context(true); |
| 4015 context->set_network_delegate(&network_delegate); | 4013 context.set_network_delegate(&network_delegate); |
| 4016 context->SetProxyFromString("myproxy:70"); | 4014 context.SetProxyFromString("myproxy:70"); |
| 4017 context->set_host_resolver(&host_resolver); | 4015 context.set_host_resolver(&host_resolver); |
| 4018 context->Init(); | 4016 context.Init(); |
| 4019 | 4017 |
| 4020 TestDelegate d; | 4018 TestDelegate d; |
| 4021 TestURLRequest req(GURL("http://example.com"), &d); | 4019 TestURLRequest req(GURL("http://example.com"), &d); |
| 4022 req.set_context(context); | 4020 req.set_context(&context); |
| 4023 req.set_method("GET"); | 4021 req.set_method("GET"); |
| 4024 | 4022 |
| 4025 req.Start(); | 4023 req.Start(); |
| 4026 MessageLoop::current()->Run(); | 4024 MessageLoop::current()->Run(); |
| 4027 | 4025 |
| 4028 // Check we see a failed request. | 4026 // Check we see a failed request. |
| 4029 EXPECT_FALSE(req.status().is_success()); | 4027 EXPECT_FALSE(req.status().is_success()); |
| 4030 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 4028 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
| 4031 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); | 4029 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); |
| 4032 | 4030 |
| 4033 EXPECT_EQ(1, network_delegate.error_count()); | 4031 EXPECT_EQ(1, network_delegate.error_count()); |
| 4034 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); | 4032 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); |
| 4035 EXPECT_EQ(1, network_delegate.completed_requests()); | 4033 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 4036 } | 4034 } |
| 4037 | 4035 |
| 4038 // Check that it is impossible to change the referrer in the extra headers of | 4036 // Check that it is impossible to change the referrer in the extra headers of |
| 4039 // an URLRequest. | 4037 // an URLRequest. |
| 4040 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 4038 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
| 4041 LocalHttpTestServer test_server; | 4039 LocalHttpTestServer test_server; |
| 4042 ASSERT_TRUE(test_server.Start()); | 4040 ASSERT_TRUE(test_server.Start()); |
| 4043 | 4041 |
| 4044 // If extra headers contain referer and the request contains a referer, | 4042 // If extra headers contain referer and the request contains a referer, |
| 4045 // only the latter shall be respected. | 4043 // only the latter shall be respected. |
| 4046 { | 4044 { |
| 4047 TestDelegate d; | 4045 TestDelegate d; |
| 4048 TestURLRequest req(test_server.GetURL("echoheader?Referer"), &d); | 4046 TestURLRequest req(test_server.GetURL("echoheader?Referer"), &d); |
| 4049 req.set_referrer("http://foo.com/"); | 4047 req.set_referrer("http://foo.com/"); |
| 4050 req.set_context(default_context_); | 4048 req.set_context(&default_context_); |
| 4051 | 4049 |
| 4052 HttpRequestHeaders headers; | 4050 HttpRequestHeaders headers; |
| 4053 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 4051 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 4054 req.SetExtraRequestHeaders(headers); | 4052 req.SetExtraRequestHeaders(headers); |
| 4055 | 4053 |
| 4056 req.Start(); | 4054 req.Start(); |
| 4057 MessageLoop::current()->Run(); | 4055 MessageLoop::current()->Run(); |
| 4058 | 4056 |
| 4059 EXPECT_EQ("http://foo.com/", d.data_received()); | 4057 EXPECT_EQ("http://foo.com/", d.data_received()); |
| 4060 } | 4058 } |
| 4061 | 4059 |
| 4062 // If extra headers contain a referer but the request does not, no referer | 4060 // If extra headers contain a referer but the request does not, no referer |
| 4063 // shall be sent in the header. | 4061 // shall be sent in the header. |
| 4064 { | 4062 { |
| 4065 TestDelegate d; | 4063 TestDelegate d; |
| 4066 TestURLRequest req(test_server.GetURL("echoheader?Referer"), &d); | 4064 TestURLRequest req(test_server.GetURL("echoheader?Referer"), &d); |
| 4067 req.set_context(default_context_); | 4065 req.set_context(&default_context_); |
| 4068 | 4066 |
| 4069 HttpRequestHeaders headers; | 4067 HttpRequestHeaders headers; |
| 4070 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 4068 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 4071 req.SetExtraRequestHeaders(headers); | 4069 req.SetExtraRequestHeaders(headers); |
| 4072 req.set_load_flags(LOAD_VALIDATE_CACHE); | 4070 req.set_load_flags(LOAD_VALIDATE_CACHE); |
| 4073 | 4071 |
| 4074 req.Start(); | 4072 req.Start(); |
| 4075 MessageLoop::current()->Run(); | 4073 MessageLoop::current()->Run(); |
| 4076 | 4074 |
| 4077 EXPECT_EQ("None", d.data_received()); | 4075 EXPECT_EQ("None", d.data_received()); |
| 4078 } | 4076 } |
| 4079 } | 4077 } |
| 4080 | 4078 |
| 4081 // Make sure that net::NetworkDelegate::NotifyCompleted is called if | 4079 // Make sure that net::NetworkDelegate::NotifyCompleted is called if |
| 4082 // content is empty. | 4080 // content is empty. |
| 4083 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { | 4081 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { |
| 4084 TestDelegate d; | 4082 TestDelegate d; |
| 4085 TestURLRequest req(GURL("data:,"), &d); | 4083 TestURLRequest req(GURL("data:,"), &d); |
| 4086 req.set_context(new TestURLRequestContext()); | 4084 req.set_context(new TestURLRequestContext()); |
| 4087 req.set_context(default_context_); | 4085 req.set_context(&default_context_); |
| 4088 req.Start(); | 4086 req.Start(); |
| 4089 MessageLoop::current()->Run(); | 4087 MessageLoop::current()->Run(); |
| 4090 EXPECT_EQ("", d.data_received()); | 4088 EXPECT_EQ("", d.data_received()); |
| 4091 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 4089 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
| 4092 } | 4090 } |
| 4093 | 4091 |
| 4094 class URLRequestTestFTP : public URLRequestTest { | 4092 class URLRequestTestFTP : public URLRequestTest { |
| 4095 public: | 4093 public: |
| 4096 URLRequestTestFTP() | 4094 URLRequestTestFTP() |
| 4097 : test_server_(TestServer::TYPE_FTP, TestServer::kLocalhost, FilePath()) { | 4095 : test_server_(TestServer::TYPE_FTP, TestServer::kLocalhost, FilePath()) { |
| 4098 } | 4096 } |
| 4099 | 4097 |
| 4100 protected: | 4098 protected: |
| 4101 TestServer test_server_; | 4099 TestServer test_server_; |
| 4102 }; | 4100 }; |
| 4103 | 4101 |
| 4104 // Flaky, see http://crbug.com/25045. | 4102 // Flaky, see http://crbug.com/25045. |
| 4105 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { | 4103 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { |
| 4106 ASSERT_TRUE(test_server_.Start()); | 4104 ASSERT_TRUE(test_server_.Start()); |
| 4107 | 4105 |
| 4108 TestDelegate d; | 4106 TestDelegate d; |
| 4109 { | 4107 { |
| 4110 TestURLRequest r(test_server_.GetURL("/"), &d); | 4108 TestURLRequest r(test_server_.GetURL("/"), &d); |
| 4111 r.set_context(default_context_); | 4109 r.set_context(&default_context_); |
| 4112 r.Start(); | 4110 r.Start(); |
| 4113 EXPECT_TRUE(r.is_pending()); | 4111 EXPECT_TRUE(r.is_pending()); |
| 4114 | 4112 |
| 4115 MessageLoop::current()->Run(); | 4113 MessageLoop::current()->Run(); |
| 4116 | 4114 |
| 4117 EXPECT_FALSE(r.is_pending()); | 4115 EXPECT_FALSE(r.is_pending()); |
| 4118 EXPECT_EQ(1, d.response_started_count()); | 4116 EXPECT_EQ(1, d.response_started_count()); |
| 4119 EXPECT_FALSE(d.received_data_before_response()); | 4117 EXPECT_FALSE(d.received_data_before_response()); |
| 4120 EXPECT_LT(0, d.bytes_received()); | 4118 EXPECT_LT(0, d.bytes_received()); |
| 4121 EXPECT_EQ(test_server_.host_port_pair().host(), | 4119 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 4122 r.GetSocketAddress().host()); | 4120 r.GetSocketAddress().host()); |
| 4123 EXPECT_EQ(test_server_.host_port_pair().port(), | 4121 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 4124 r.GetSocketAddress().port()); | 4122 r.GetSocketAddress().port()); |
| 4125 } | 4123 } |
| 4126 } | 4124 } |
| 4127 | 4125 |
| 4128 // Flaky, see http://crbug.com/25045. | 4126 // Flaky, see http://crbug.com/25045. |
| 4129 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { | 4127 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { |
| 4130 ASSERT_TRUE(test_server_.Start()); | 4128 ASSERT_TRUE(test_server_.Start()); |
| 4131 | 4129 |
| 4132 FilePath app_path; | 4130 FilePath app_path; |
| 4133 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4131 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 4134 app_path = app_path.AppendASCII("LICENSE"); | 4132 app_path = app_path.AppendASCII("LICENSE"); |
| 4135 TestDelegate d; | 4133 TestDelegate d; |
| 4136 { | 4134 { |
| 4137 TestURLRequest r(test_server_.GetURL("/LICENSE"), &d); | 4135 TestURLRequest r(test_server_.GetURL("/LICENSE"), &d); |
| 4138 r.set_context(default_context_); | 4136 r.set_context(&default_context_); |
| 4139 r.Start(); | 4137 r.Start(); |
| 4140 EXPECT_TRUE(r.is_pending()); | 4138 EXPECT_TRUE(r.is_pending()); |
| 4141 | 4139 |
| 4142 MessageLoop::current()->Run(); | 4140 MessageLoop::current()->Run(); |
| 4143 | 4141 |
| 4144 int64 file_size = 0; | 4142 int64 file_size = 0; |
| 4145 file_util::GetFileSize(app_path, &file_size); | 4143 file_util::GetFileSize(app_path, &file_size); |
| 4146 | 4144 |
| 4147 EXPECT_FALSE(r.is_pending()); | 4145 EXPECT_FALSE(r.is_pending()); |
| 4148 EXPECT_EQ(1, d.response_started_count()); | 4146 EXPECT_EQ(1, d.response_started_count()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4160 ASSERT_TRUE(test_server_.Start()); | 4158 ASSERT_TRUE(test_server_.Start()); |
| 4161 | 4159 |
| 4162 FilePath app_path; | 4160 FilePath app_path; |
| 4163 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4161 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 4164 app_path = app_path.AppendASCII("LICENSE"); | 4162 app_path = app_path.AppendASCII("LICENSE"); |
| 4165 TestDelegate d; | 4163 TestDelegate d; |
| 4166 { | 4164 { |
| 4167 TestURLRequest r( | 4165 TestURLRequest r( |
| 4168 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 4166 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), |
| 4169 &d); | 4167 &d); |
| 4170 r.set_context(default_context_); | 4168 r.set_context(&default_context_); |
| 4171 r.Start(); | 4169 r.Start(); |
| 4172 EXPECT_TRUE(r.is_pending()); | 4170 EXPECT_TRUE(r.is_pending()); |
| 4173 | 4171 |
| 4174 MessageLoop::current()->Run(); | 4172 MessageLoop::current()->Run(); |
| 4175 | 4173 |
| 4176 int64 file_size = 0; | 4174 int64 file_size = 0; |
| 4177 file_util::GetFileSize(app_path, &file_size); | 4175 file_util::GetFileSize(app_path, &file_size); |
| 4178 | 4176 |
| 4179 EXPECT_FALSE(r.is_pending()); | 4177 EXPECT_FALSE(r.is_pending()); |
| 4180 EXPECT_EQ(test_server_.host_port_pair().host(), | 4178 EXPECT_EQ(test_server_.host_port_pair().host(), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4194 FilePath app_path; | 4192 FilePath app_path; |
| 4195 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4193 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 4196 app_path = app_path.AppendASCII("LICENSE"); | 4194 app_path = app_path.AppendASCII("LICENSE"); |
| 4197 TestDelegate d; | 4195 TestDelegate d; |
| 4198 { | 4196 { |
| 4199 TestURLRequest r( | 4197 TestURLRequest r( |
| 4200 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4198 test_server_.GetURLWithUserAndPassword("/LICENSE", |
| 4201 "chrome", | 4199 "chrome", |
| 4202 "wrong_password"), | 4200 "wrong_password"), |
| 4203 &d); | 4201 &d); |
| 4204 r.set_context(default_context_); | 4202 r.set_context(&default_context_); |
| 4205 r.Start(); | 4203 r.Start(); |
| 4206 EXPECT_TRUE(r.is_pending()); | 4204 EXPECT_TRUE(r.is_pending()); |
| 4207 | 4205 |
| 4208 MessageLoop::current()->Run(); | 4206 MessageLoop::current()->Run(); |
| 4209 | 4207 |
| 4210 int64 file_size = 0; | 4208 int64 file_size = 0; |
| 4211 file_util::GetFileSize(app_path, &file_size); | 4209 file_util::GetFileSize(app_path, &file_size); |
| 4212 | 4210 |
| 4213 EXPECT_FALSE(r.is_pending()); | 4211 EXPECT_FALSE(r.is_pending()); |
| 4214 EXPECT_EQ(1, d.response_started_count()); | 4212 EXPECT_EQ(1, d.response_started_count()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4227 TestDelegate d; | 4225 TestDelegate d; |
| 4228 // Set correct login credentials. The delegate will be asked for them when | 4226 // Set correct login credentials. The delegate will be asked for them when |
| 4229 // the initial login with wrong credentials will fail. | 4227 // the initial login with wrong credentials will fail. |
| 4230 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 4228 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 4231 { | 4229 { |
| 4232 TestURLRequest r( | 4230 TestURLRequest r( |
| 4233 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4231 test_server_.GetURLWithUserAndPassword("/LICENSE", |
| 4234 "chrome", | 4232 "chrome", |
| 4235 "wrong_password"), | 4233 "wrong_password"), |
| 4236 &d); | 4234 &d); |
| 4237 r.set_context(default_context_); | 4235 r.set_context(&default_context_); |
| 4238 r.Start(); | 4236 r.Start(); |
| 4239 EXPECT_TRUE(r.is_pending()); | 4237 EXPECT_TRUE(r.is_pending()); |
| 4240 | 4238 |
| 4241 MessageLoop::current()->Run(); | 4239 MessageLoop::current()->Run(); |
| 4242 | 4240 |
| 4243 int64 file_size = 0; | 4241 int64 file_size = 0; |
| 4244 file_util::GetFileSize(app_path, &file_size); | 4242 file_util::GetFileSize(app_path, &file_size); |
| 4245 | 4243 |
| 4246 EXPECT_FALSE(r.is_pending()); | 4244 EXPECT_FALSE(r.is_pending()); |
| 4247 EXPECT_EQ(1, d.response_started_count()); | 4245 EXPECT_EQ(1, d.response_started_count()); |
| 4248 EXPECT_FALSE(d.received_data_before_response()); | 4246 EXPECT_FALSE(d.received_data_before_response()); |
| 4249 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 4247 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 4250 } | 4248 } |
| 4251 } | 4249 } |
| 4252 | 4250 |
| 4253 // Flaky, see http://crbug.com/25045. | 4251 // Flaky, see http://crbug.com/25045. |
| 4254 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { | 4252 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { |
| 4255 ASSERT_TRUE(test_server_.Start()); | 4253 ASSERT_TRUE(test_server_.Start()); |
| 4256 | 4254 |
| 4257 FilePath app_path; | 4255 FilePath app_path; |
| 4258 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4256 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 4259 app_path = app_path.AppendASCII("LICENSE"); | 4257 app_path = app_path.AppendASCII("LICENSE"); |
| 4260 TestDelegate d; | 4258 TestDelegate d; |
| 4261 { | 4259 { |
| 4262 TestURLRequest r( | 4260 TestURLRequest r( |
| 4263 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4261 test_server_.GetURLWithUserAndPassword("/LICENSE", |
| 4264 "wrong_user", | 4262 "wrong_user", |
| 4265 "chrome"), | 4263 "chrome"), |
| 4266 &d); | 4264 &d); |
| 4267 r.set_context(default_context_); | 4265 r.set_context(&default_context_); |
| 4268 r.Start(); | 4266 r.Start(); |
| 4269 EXPECT_TRUE(r.is_pending()); | 4267 EXPECT_TRUE(r.is_pending()); |
| 4270 | 4268 |
| 4271 MessageLoop::current()->Run(); | 4269 MessageLoop::current()->Run(); |
| 4272 | 4270 |
| 4273 int64 file_size = 0; | 4271 int64 file_size = 0; |
| 4274 file_util::GetFileSize(app_path, &file_size); | 4272 file_util::GetFileSize(app_path, &file_size); |
| 4275 | 4273 |
| 4276 EXPECT_FALSE(r.is_pending()); | 4274 EXPECT_FALSE(r.is_pending()); |
| 4277 EXPECT_EQ(1, d.response_started_count()); | 4275 EXPECT_EQ(1, d.response_started_count()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4290 TestDelegate d; | 4288 TestDelegate d; |
| 4291 // Set correct login credentials. The delegate will be asked for them when | 4289 // Set correct login credentials. The delegate will be asked for them when |
| 4292 // the initial login with wrong credentials will fail. | 4290 // the initial login with wrong credentials will fail. |
| 4293 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 4291 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 4294 { | 4292 { |
| 4295 TestURLRequest r( | 4293 TestURLRequest r( |
| 4296 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4294 test_server_.GetURLWithUserAndPassword("/LICENSE", |
| 4297 "wrong_user", | 4295 "wrong_user", |
| 4298 "chrome"), | 4296 "chrome"), |
| 4299 &d); | 4297 &d); |
| 4300 r.set_context(default_context_); | 4298 r.set_context(&default_context_); |
| 4301 r.Start(); | 4299 r.Start(); |
| 4302 EXPECT_TRUE(r.is_pending()); | 4300 EXPECT_TRUE(r.is_pending()); |
| 4303 | 4301 |
| 4304 MessageLoop::current()->Run(); | 4302 MessageLoop::current()->Run(); |
| 4305 | 4303 |
| 4306 int64 file_size = 0; | 4304 int64 file_size = 0; |
| 4307 file_util::GetFileSize(app_path, &file_size); | 4305 file_util::GetFileSize(app_path, &file_size); |
| 4308 | 4306 |
| 4309 EXPECT_FALSE(r.is_pending()); | 4307 EXPECT_FALSE(r.is_pending()); |
| 4310 EXPECT_EQ(1, d.response_started_count()); | 4308 EXPECT_EQ(1, d.response_started_count()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 4322 app_path = app_path.AppendASCII("LICENSE"); | 4320 app_path = app_path.AppendASCII("LICENSE"); |
| 4323 | 4321 |
| 4324 scoped_ptr<TestDelegate> d(new TestDelegate); | 4322 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 4325 { | 4323 { |
| 4326 // Pass correct login identity in the URL. | 4324 // Pass correct login identity in the URL. |
| 4327 TestURLRequest r( | 4325 TestURLRequest r( |
| 4328 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4326 test_server_.GetURLWithUserAndPassword("/LICENSE", |
| 4329 "chrome", | 4327 "chrome", |
| 4330 "chrome"), | 4328 "chrome"), |
| 4331 d.get()); | 4329 d.get()); |
| 4332 r.set_context(default_context_); | 4330 r.set_context(&default_context_); |
| 4333 r.Start(); | 4331 r.Start(); |
| 4334 EXPECT_TRUE(r.is_pending()); | 4332 EXPECT_TRUE(r.is_pending()); |
| 4335 | 4333 |
| 4336 MessageLoop::current()->Run(); | 4334 MessageLoop::current()->Run(); |
| 4337 | 4335 |
| 4338 int64 file_size = 0; | 4336 int64 file_size = 0; |
| 4339 file_util::GetFileSize(app_path, &file_size); | 4337 file_util::GetFileSize(app_path, &file_size); |
| 4340 | 4338 |
| 4341 EXPECT_FALSE(r.is_pending()); | 4339 EXPECT_FALSE(r.is_pending()); |
| 4342 EXPECT_EQ(1, d->response_started_count()); | 4340 EXPECT_EQ(1, d->response_started_count()); |
| 4343 EXPECT_FALSE(d->received_data_before_response()); | 4341 EXPECT_FALSE(d->received_data_before_response()); |
| 4344 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4342 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 4345 } | 4343 } |
| 4346 | 4344 |
| 4347 d.reset(new TestDelegate); | 4345 d.reset(new TestDelegate); |
| 4348 { | 4346 { |
| 4349 // This request should use cached identity from previous request. | 4347 // This request should use cached identity from previous request. |
| 4350 TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); | 4348 TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); |
| 4351 r.set_context(default_context_); | 4349 r.set_context(&default_context_); |
| 4352 r.Start(); | 4350 r.Start(); |
| 4353 EXPECT_TRUE(r.is_pending()); | 4351 EXPECT_TRUE(r.is_pending()); |
| 4354 | 4352 |
| 4355 MessageLoop::current()->Run(); | 4353 MessageLoop::current()->Run(); |
| 4356 | 4354 |
| 4357 int64 file_size = 0; | 4355 int64 file_size = 0; |
| 4358 file_util::GetFileSize(app_path, &file_size); | 4356 file_util::GetFileSize(app_path, &file_size); |
| 4359 | 4357 |
| 4360 EXPECT_FALSE(r.is_pending()); | 4358 EXPECT_FALSE(r.is_pending()); |
| 4361 EXPECT_EQ(1, d->response_started_count()); | 4359 EXPECT_EQ(1, d->response_started_count()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4375 scoped_ptr<TestDelegate> d(new TestDelegate); | 4373 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 4376 // Set correct login credentials. The delegate will be asked for them when | 4374 // Set correct login credentials. The delegate will be asked for them when |
| 4377 // the initial login with wrong credentials will fail. | 4375 // the initial login with wrong credentials will fail. |
| 4378 d->set_credentials(AuthCredentials(kChrome, kChrome)); | 4376 d->set_credentials(AuthCredentials(kChrome, kChrome)); |
| 4379 { | 4377 { |
| 4380 TestURLRequest r( | 4378 TestURLRequest r( |
| 4381 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4379 test_server_.GetURLWithUserAndPassword("/LICENSE", |
| 4382 "chrome", | 4380 "chrome", |
| 4383 "wrong_password"), | 4381 "wrong_password"), |
| 4384 d.get()); | 4382 d.get()); |
| 4385 r.set_context(default_context_); | 4383 r.set_context(&default_context_); |
| 4386 r.Start(); | 4384 r.Start(); |
| 4387 EXPECT_TRUE(r.is_pending()); | 4385 EXPECT_TRUE(r.is_pending()); |
| 4388 | 4386 |
| 4389 MessageLoop::current()->Run(); | 4387 MessageLoop::current()->Run(); |
| 4390 | 4388 |
| 4391 int64 file_size = 0; | 4389 int64 file_size = 0; |
| 4392 file_util::GetFileSize(app_path, &file_size); | 4390 file_util::GetFileSize(app_path, &file_size); |
| 4393 | 4391 |
| 4394 EXPECT_FALSE(r.is_pending()); | 4392 EXPECT_FALSE(r.is_pending()); |
| 4395 EXPECT_EQ(1, d->response_started_count()); | 4393 EXPECT_EQ(1, d->response_started_count()); |
| 4396 EXPECT_FALSE(d->received_data_before_response()); | 4394 EXPECT_FALSE(d->received_data_before_response()); |
| 4397 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4395 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 4398 } | 4396 } |
| 4399 | 4397 |
| 4400 // Use a new delegate without explicit credentials. The cached ones should be | 4398 // Use a new delegate without explicit credentials. The cached ones should be |
| 4401 // used. | 4399 // used. |
| 4402 d.reset(new TestDelegate); | 4400 d.reset(new TestDelegate); |
| 4403 { | 4401 { |
| 4404 // Don't pass wrong credentials in the URL, they would override valid cached | 4402 // Don't pass wrong credentials in the URL, they would override valid cached |
| 4405 // ones. | 4403 // ones. |
| 4406 TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); | 4404 TestURLRequest r(test_server_.GetURL("/LICENSE"), d.get()); |
| 4407 r.set_context(default_context_); | 4405 r.set_context(&default_context_); |
| 4408 r.Start(); | 4406 r.Start(); |
| 4409 EXPECT_TRUE(r.is_pending()); | 4407 EXPECT_TRUE(r.is_pending()); |
| 4410 | 4408 |
| 4411 MessageLoop::current()->Run(); | 4409 MessageLoop::current()->Run(); |
| 4412 | 4410 |
| 4413 int64 file_size = 0; | 4411 int64 file_size = 0; |
| 4414 file_util::GetFileSize(app_path, &file_size); | 4412 file_util::GetFileSize(app_path, &file_size); |
| 4415 | 4413 |
| 4416 EXPECT_FALSE(r.is_pending()); | 4414 EXPECT_FALSE(r.is_pending()); |
| 4417 EXPECT_EQ(1, d->response_started_count()); | 4415 EXPECT_EQ(1, d->response_started_count()); |
| 4418 EXPECT_FALSE(d->received_data_before_response()); | 4416 EXPECT_FALSE(d->received_data_before_response()); |
| 4419 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4417 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 4420 } | 4418 } |
| 4421 } | 4419 } |
| 4422 | 4420 |
| 4423 // Check that default A-L header is sent. | 4421 // Check that default A-L header is sent. |
| 4424 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 4422 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
| 4425 ASSERT_TRUE(test_server_.Start()); | 4423 ASSERT_TRUE(test_server_.Start()); |
| 4426 | 4424 |
| 4427 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4425 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 4428 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 4426 TestURLRequestContext context(true); |
| 4429 context->set_network_delegate(&network_delegate); | 4427 context.set_network_delegate(&network_delegate); |
| 4430 context->set_accept_language("en"); | 4428 context.set_accept_language("en"); |
| 4431 context->Init(); | 4429 context.Init(); |
| 4432 | 4430 |
| 4433 TestDelegate d; | 4431 TestDelegate d; |
| 4434 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 4432 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); |
| 4435 req.set_context(context); | 4433 req.set_context(&context); |
| 4436 req.Start(); | 4434 req.Start(); |
| 4437 MessageLoop::current()->Run(); | 4435 MessageLoop::current()->Run(); |
| 4438 EXPECT_EQ("en", d.data_received()); | 4436 EXPECT_EQ("en", d.data_received()); |
| 4439 } | 4437 } |
| 4440 | 4438 |
| 4441 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 4439 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
| 4442 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 4440 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
| 4443 ASSERT_TRUE(test_server_.Start()); | 4441 ASSERT_TRUE(test_server_.Start()); |
| 4444 | 4442 |
| 4445 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4443 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 4446 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 4444 TestURLRequestContext context(true); |
| 4447 context->set_network_delegate(&network_delegate); | 4445 context.set_network_delegate(&network_delegate); |
| 4448 context->Init(); | 4446 context.Init(); |
| 4449 // We override the language after initialization because empty entries | 4447 // We override the language after initialization because empty entries |
| 4450 // get overridden by Init(). | 4448 // get overridden by Init(). |
| 4451 context->set_accept_language(""); | 4449 context.set_accept_language(""); |
| 4452 | 4450 |
| 4453 TestDelegate d; | 4451 TestDelegate d; |
| 4454 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 4452 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); |
| 4455 req.set_context(context); | 4453 req.set_context(&context); |
| 4456 req.Start(); | 4454 req.Start(); |
| 4457 MessageLoop::current()->Run(); | 4455 MessageLoop::current()->Run(); |
| 4458 EXPECT_EQ("None", d.data_received()); | 4456 EXPECT_EQ("None", d.data_received()); |
| 4459 } | 4457 } |
| 4460 | 4458 |
| 4461 // Check that if request overrides the A-L header, the default is not appended. | 4459 // Check that if request overrides the A-L header, the default is not appended. |
| 4462 // See http://crbug.com/20894 | 4460 // See http://crbug.com/20894 |
| 4463 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 4461 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
| 4464 ASSERT_TRUE(test_server_.Start()); | 4462 ASSERT_TRUE(test_server_.Start()); |
| 4465 | 4463 |
| 4466 TestDelegate d; | 4464 TestDelegate d; |
| 4467 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 4465 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); |
| 4468 req.set_context(default_context_); | 4466 req.set_context(&default_context_); |
| 4469 HttpRequestHeaders headers; | 4467 HttpRequestHeaders headers; |
| 4470 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); | 4468 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); |
| 4471 req.SetExtraRequestHeaders(headers); | 4469 req.SetExtraRequestHeaders(headers); |
| 4472 req.Start(); | 4470 req.Start(); |
| 4473 MessageLoop::current()->Run(); | 4471 MessageLoop::current()->Run(); |
| 4474 EXPECT_EQ(std::string("ru"), d.data_received()); | 4472 EXPECT_EQ(std::string("ru"), d.data_received()); |
| 4475 } | 4473 } |
| 4476 | 4474 |
| 4477 // Check that default A-E header is sent. | 4475 // Check that default A-E header is sent. |
| 4478 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { | 4476 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { |
| 4479 ASSERT_TRUE(test_server_.Start()); | 4477 ASSERT_TRUE(test_server_.Start()); |
| 4480 | 4478 |
| 4481 TestDelegate d; | 4479 TestDelegate d; |
| 4482 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); | 4480 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); |
| 4483 req.set_context(default_context_); | 4481 req.set_context(&default_context_); |
| 4484 HttpRequestHeaders headers; | 4482 HttpRequestHeaders headers; |
| 4485 req.SetExtraRequestHeaders(headers); | 4483 req.SetExtraRequestHeaders(headers); |
| 4486 req.Start(); | 4484 req.Start(); |
| 4487 MessageLoop::current()->Run(); | 4485 MessageLoop::current()->Run(); |
| 4488 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); | 4486 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); |
| 4489 } | 4487 } |
| 4490 | 4488 |
| 4491 // Check that if request overrides the A-E header, the default is not appended. | 4489 // Check that if request overrides the A-E header, the default is not appended. |
| 4492 // See http://crbug.com/47381 | 4490 // See http://crbug.com/47381 |
| 4493 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { | 4491 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { |
| 4494 ASSERT_TRUE(test_server_.Start()); | 4492 ASSERT_TRUE(test_server_.Start()); |
| 4495 | 4493 |
| 4496 TestDelegate d; | 4494 TestDelegate d; |
| 4497 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); | 4495 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); |
| 4498 req.set_context(default_context_); | 4496 req.set_context(&default_context_); |
| 4499 HttpRequestHeaders headers; | 4497 HttpRequestHeaders headers; |
| 4500 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); | 4498 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); |
| 4501 req.SetExtraRequestHeaders(headers); | 4499 req.SetExtraRequestHeaders(headers); |
| 4502 req.Start(); | 4500 req.Start(); |
| 4503 MessageLoop::current()->Run(); | 4501 MessageLoop::current()->Run(); |
| 4504 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); | 4502 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); |
| 4505 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 4503 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
| 4506 } | 4504 } |
| 4507 | 4505 |
| 4508 // Check that default A-C header is sent. | 4506 // Check that default A-C header is sent. |
| 4509 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { | 4507 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { |
| 4510 ASSERT_TRUE(test_server_.Start()); | 4508 ASSERT_TRUE(test_server_.Start()); |
| 4511 | 4509 |
| 4512 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4510 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 4513 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 4511 TestURLRequestContext context(true); |
| 4514 context->set_network_delegate(&network_delegate); | 4512 context.set_network_delegate(&network_delegate); |
| 4515 context->set_accept_charset("en"); | 4513 context.set_accept_charset("en"); |
| 4516 context->Init(); | 4514 context.Init(); |
| 4517 | 4515 |
| 4518 TestDelegate d; | 4516 TestDelegate d; |
| 4519 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 4517 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); |
| 4520 req.set_context(context); | 4518 req.set_context(&context); |
| 4521 req.Start(); | 4519 req.Start(); |
| 4522 MessageLoop::current()->Run(); | 4520 MessageLoop::current()->Run(); |
| 4523 EXPECT_EQ("en", d.data_received()); | 4521 EXPECT_EQ("en", d.data_received()); |
| 4524 } | 4522 } |
| 4525 | 4523 |
| 4526 // Check that an empty A-C header is not sent. http://crbug.com/77365. | 4524 // Check that an empty A-C header is not sent. http://crbug.com/77365. |
| 4527 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { | 4525 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { |
| 4528 ASSERT_TRUE(test_server_.Start()); | 4526 ASSERT_TRUE(test_server_.Start()); |
| 4529 | 4527 |
| 4530 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4528 TestNetworkDelegate network_delegate; // must outlive URLRequests |
| 4531 scoped_refptr<TestURLRequestContext> context(new TestURLRequestContext(true)); | 4529 TestURLRequestContext context(true); |
| 4532 context->set_network_delegate(&network_delegate); | 4530 context.set_network_delegate(&network_delegate); |
| 4533 context->Init(); | 4531 context.Init(); |
| 4534 // We override the accepted charset after initialization because empty | 4532 // We override the accepted charset after initialization because empty |
| 4535 // entries get overridden otherwise. | 4533 // entries get overridden otherwise. |
| 4536 context->set_accept_charset(""); | 4534 context.set_accept_charset(""); |
| 4537 | 4535 |
| 4538 TestDelegate d; | 4536 TestDelegate d; |
| 4539 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 4537 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); |
| 4540 req.set_context(context); | 4538 req.set_context(&context); |
| 4541 req.Start(); | 4539 req.Start(); |
| 4542 MessageLoop::current()->Run(); | 4540 MessageLoop::current()->Run(); |
| 4543 EXPECT_EQ("None", d.data_received()); | 4541 EXPECT_EQ("None", d.data_received()); |
| 4544 } | 4542 } |
| 4545 | 4543 |
| 4546 // Check that if request overrides the A-C header, the default is not appended. | 4544 // Check that if request overrides the A-C header, the default is not appended. |
| 4547 // See http://crbug.com/20894 | 4545 // See http://crbug.com/20894 |
| 4548 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { | 4546 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { |
| 4549 ASSERT_TRUE(test_server_.Start()); | 4547 ASSERT_TRUE(test_server_.Start()); |
| 4550 | 4548 |
| 4551 TestDelegate d; | 4549 TestDelegate d; |
| 4552 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 4550 TestURLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); |
| 4553 req.set_context(default_context_); | 4551 req.set_context(&default_context_); |
| 4554 HttpRequestHeaders headers; | 4552 HttpRequestHeaders headers; |
| 4555 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 4553 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
| 4556 req.SetExtraRequestHeaders(headers); | 4554 req.SetExtraRequestHeaders(headers); |
| 4557 req.Start(); | 4555 req.Start(); |
| 4558 MessageLoop::current()->Run(); | 4556 MessageLoop::current()->Run(); |
| 4559 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 4557 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
| 4560 } | 4558 } |
| 4561 | 4559 |
| 4562 // Check that default User-Agent header is sent. | 4560 // Check that default User-Agent header is sent. |
| 4563 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { | 4561 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { |
| 4564 ASSERT_TRUE(test_server_.Start()); | 4562 ASSERT_TRUE(test_server_.Start()); |
| 4565 | 4563 |
| 4566 TestDelegate d; | 4564 TestDelegate d; |
| 4567 TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); | 4565 TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); |
| 4568 req.set_context(default_context_); | 4566 req.set_context(&default_context_); |
| 4569 req.Start(); | 4567 req.Start(); |
| 4570 MessageLoop::current()->Run(); | 4568 MessageLoop::current()->Run(); |
| 4571 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); | 4569 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); |
| 4572 } | 4570 } |
| 4573 | 4571 |
| 4574 // Check that if request overrides the User-Agent header, | 4572 // Check that if request overrides the User-Agent header, |
| 4575 // the default is not appended. | 4573 // the default is not appended. |
| 4576 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { | 4574 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { |
| 4577 ASSERT_TRUE(test_server_.Start()); | 4575 ASSERT_TRUE(test_server_.Start()); |
| 4578 | 4576 |
| 4579 TestDelegate d; | 4577 TestDelegate d; |
| 4580 TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); | 4578 TestURLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); |
| 4581 req.set_context(default_context_); | 4579 req.set_context(&default_context_); |
| 4582 HttpRequestHeaders headers; | 4580 HttpRequestHeaders headers; |
| 4583 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 4581 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 4584 req.SetExtraRequestHeaders(headers); | 4582 req.SetExtraRequestHeaders(headers); |
| 4585 req.Start(); | 4583 req.Start(); |
| 4586 MessageLoop::current()->Run(); | 4584 MessageLoop::current()->Run(); |
| 4587 // If the net tests are being run with ChromeFrame then we need to allow for | 4585 // If the net tests are being run with ChromeFrame then we need to allow for |
| 4588 // the 'chromeframe' suffix which is added to the user agent before the | 4586 // the 'chromeframe' suffix which is added to the user agent before the |
| 4589 // closing parentheses. | 4587 // closing parentheses. |
| 4590 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 4588 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 4591 } | 4589 } |
| 4592 | 4590 |
| 4593 } // namespace net | 4591 } // namespace net |
| OLD | NEW |