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 441 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
452 // request, after redirection. | 452 // request, after redirection. |
453 // If |include_data| is true, data is uploaded with the request. The | 453 // If |include_data| is true, data is uploaded with the request. The |
454 // response body is expected to match it exactly, if and only if | 454 // response body is expected to match it exactly, if and only if |
455 // |request_method| == |redirect_method|. | 455 // |request_method| == |redirect_method|. |
456 void HTTPRedirectMethodTest(const GURL& redirect_url, | 456 void HTTPRedirectMethodTest(const GURL& redirect_url, |
457 const std::string& request_method, | 457 const std::string& request_method, |
458 const std::string& redirect_method, | 458 const std::string& redirect_method, |
459 bool include_data) { | 459 bool include_data) { |
460 static const char kData[] = "hello world"; | 460 static const char kData[] = "hello world"; |
461 TestDelegate d; | 461 TestDelegate d; |
462 URLRequest req(redirect_url, &d); | 462 URLRequest req(redirect_url, &d, &default_context_); |
463 req.set_context(&default_context_); | |
464 req.set_method(request_method); | 463 req.set_method(request_method); |
465 if (include_data) { | 464 if (include_data) { |
466 req.set_upload(CreateSimpleUploadData(kData).get()); | 465 req.set_upload(CreateSimpleUploadData(kData).get()); |
467 HttpRequestHeaders headers; | 466 HttpRequestHeaders headers; |
468 headers.SetHeader(HttpRequestHeaders::kContentLength, | 467 headers.SetHeader(HttpRequestHeaders::kContentLength, |
469 base::UintToString(arraysize(kData) - 1)); | 468 base::UintToString(arraysize(kData) - 1)); |
470 req.SetExtraRequestHeaders(headers); | 469 req.SetExtraRequestHeaders(headers); |
471 } | 470 } |
472 req.Start(); | 471 req.Start(); |
473 MessageLoop::current()->Run(); | 472 MessageLoop::current()->Run(); |
(...skipping 24 matching lines...) Expand all Loading... | |
498 ptr--; | 497 ptr--; |
499 *ptr++ = marker; | 498 *ptr++ = marker; |
500 if (++marker > 'z') | 499 if (++marker > 'z') |
501 marker = 'a'; | 500 marker = 'a'; |
502 } | 501 } |
503 } | 502 } |
504 uploadBytes[kMsgSize] = '\0'; | 503 uploadBytes[kMsgSize] = '\0'; |
505 | 504 |
506 for (int i = 0; i < kIterations; ++i) { | 505 for (int i = 0; i < kIterations; ++i) { |
507 TestDelegate d; | 506 TestDelegate d; |
508 URLRequest r(test_server_.GetURL("echo"), &d); | 507 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
509 r.set_context(&default_context_); | |
510 r.set_method(method.c_str()); | 508 r.set_method(method.c_str()); |
511 | 509 |
512 r.AppendBytesToUpload(uploadBytes, kMsgSize); | 510 r.AppendBytesToUpload(uploadBytes, kMsgSize); |
513 | 511 |
514 r.Start(); | 512 r.Start(); |
515 EXPECT_TRUE(r.is_pending()); | 513 EXPECT_TRUE(r.is_pending()); |
516 | 514 |
517 MessageLoop::current()->Run(); | 515 MessageLoop::current()->Run(); |
518 | 516 |
519 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 517 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
(...skipping 28 matching lines...) Expand all Loading... | |
548 | 546 |
549 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received())); | 547 ASSERT_EQ(strlen(expected_data), static_cast<size_t>(d->bytes_received())); |
550 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data, | 548 EXPECT_EQ(0, memcmp(d->data_received().c_str(), expected_data, |
551 strlen(expected_data))); | 549 strlen(expected_data))); |
552 } | 550 } |
553 | 551 |
554 bool DoManyCookiesRequest(int num_cookies){ | 552 bool DoManyCookiesRequest(int num_cookies){ |
555 TestDelegate d; | 553 TestDelegate d; |
556 URLRequest r(test_server_.GetURL("set-many-cookies?" + | 554 URLRequest r(test_server_.GetURL("set-many-cookies?" + |
557 base::IntToString(num_cookies)), | 555 base::IntToString(num_cookies)), |
558 &d); | 556 &d, |
559 r.set_context(&default_context_); | 557 &default_context_); |
560 | 558 |
561 r.Start(); | 559 r.Start(); |
562 EXPECT_TRUE(r.is_pending()); | 560 EXPECT_TRUE(r.is_pending()); |
563 | 561 |
564 MessageLoop::current()->Run(); | 562 MessageLoop::current()->Run(); |
565 | 563 |
566 bool is_success = r.status().is_success(); | 564 bool is_success = r.status().is_success(); |
567 | 565 |
568 if (!is_success){ | 566 if (!is_success){ |
569 // Requests handled by ChromeFrame send a less precise error message, | 567 // Requests handled by ChromeFrame send a less precise error message, |
(...skipping 20 matching lines...) Expand all Loading... | |
590 TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) { | 588 TEST_F(URLRequestTestHTTP, FLAKY_ProxyTunnelRedirectTest) { |
591 ASSERT_TRUE(test_server_.Start()); | 589 ASSERT_TRUE(test_server_.Start()); |
592 | 590 |
593 TestNetworkDelegate network_delegate; // must outlive URLRequest | 591 TestNetworkDelegate network_delegate; // must outlive URLRequest |
594 TestURLRequestContextWithProxy context( | 592 TestURLRequestContextWithProxy context( |
595 test_server_.host_port_pair().ToString(), | 593 test_server_.host_port_pair().ToString(), |
596 &network_delegate); | 594 &network_delegate); |
597 | 595 |
598 TestDelegate d; | 596 TestDelegate d; |
599 { | 597 { |
600 URLRequest r(GURL("https://www.redirect.com/"), &d); | 598 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); |
601 r.set_context(&context); | |
602 r.Start(); | 599 r.Start(); |
603 EXPECT_TRUE(r.is_pending()); | 600 EXPECT_TRUE(r.is_pending()); |
604 | 601 |
605 MessageLoop::current()->Run(); | 602 MessageLoop::current()->Run(); |
606 | 603 |
607 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 604 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
608 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 605 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
609 EXPECT_EQ(1, d.response_started_count()); | 606 EXPECT_EQ(1, d.response_started_count()); |
610 // We should not have followed the redirect. | 607 // We should not have followed the redirect. |
611 EXPECT_EQ(0, d.received_redirect_count()); | 608 EXPECT_EQ(0, d.received_redirect_count()); |
612 } | 609 } |
613 } | 610 } |
614 | 611 |
615 // This is the same as the previous test, but checks that the network delegate | 612 // This is the same as the previous test, but checks that the network delegate |
616 // registers the error. | 613 // registers the error. |
617 // This test was disabled because it made chrome_frame_net_tests hang | 614 // This test was disabled because it made chrome_frame_net_tests hang |
618 // (see bug 102991). | 615 // (see bug 102991). |
619 TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) { | 616 TEST_F(URLRequestTestHTTP, DISABLED_NetworkDelegateTunnelConnectionFailed) { |
620 ASSERT_TRUE(test_server_.Start()); | 617 ASSERT_TRUE(test_server_.Start()); |
621 | 618 |
622 TestNetworkDelegate network_delegate; // must outlive URLRequest | 619 TestNetworkDelegate network_delegate; // must outlive URLRequest |
623 TestURLRequestContextWithProxy context( | 620 TestURLRequestContextWithProxy context( |
624 test_server_.host_port_pair().ToString(), | 621 test_server_.host_port_pair().ToString(), |
625 &network_delegate); | 622 &network_delegate); |
626 | 623 |
627 TestDelegate d; | 624 TestDelegate d; |
628 { | 625 { |
629 URLRequest r(GURL("https://www.redirect.com/"), &d); | 626 URLRequest r(GURL("https://www.redirect.com/"), &d, &context); |
630 r.set_context(&context); | |
631 r.Start(); | 627 r.Start(); |
632 EXPECT_TRUE(r.is_pending()); | 628 EXPECT_TRUE(r.is_pending()); |
633 | 629 |
634 MessageLoop::current()->Run(); | 630 MessageLoop::current()->Run(); |
635 | 631 |
636 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 632 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
637 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 633 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
638 EXPECT_EQ(1, d.response_started_count()); | 634 EXPECT_EQ(1, d.response_started_count()); |
639 // We should not have followed the redirect. | 635 // We should not have followed the redirect. |
640 EXPECT_EQ(0, d.received_redirect_count()); | 636 EXPECT_EQ(0, d.received_redirect_count()); |
641 | 637 |
642 EXPECT_EQ(1, network_delegate.error_count()); | 638 EXPECT_EQ(1, network_delegate.error_count()); |
643 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); | 639 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, network_delegate.last_error()); |
644 } | 640 } |
645 } | 641 } |
646 | 642 |
647 // Tests that the network delegate can block and cancel a request. | 643 // Tests that the network delegate can block and cancel a request. |
648 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { | 644 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequest) { |
649 ASSERT_TRUE(test_server_.Start()); | 645 ASSERT_TRUE(test_server_.Start()); |
650 | 646 |
651 TestDelegate d; | 647 TestDelegate d; |
652 BlockingNetworkDelegate network_delegate; | 648 BlockingNetworkDelegate network_delegate; |
653 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); | 649 network_delegate.set_callback_retval(ERR_EMPTY_RESPONSE); |
654 | 650 |
655 TestURLRequestContextWithProxy context( | 651 TestURLRequestContextWithProxy context( |
656 test_server_.host_port_pair().ToString(), | 652 test_server_.host_port_pair().ToString(), |
657 &network_delegate); | 653 &network_delegate); |
658 | 654 |
659 { | 655 { |
660 URLRequest r(test_server_.GetURL(""), &d); | 656 URLRequest r(test_server_.GetURL(""), &d, &context); |
661 r.set_context(&context); | |
662 | 657 |
663 r.Start(); | 658 r.Start(); |
664 MessageLoop::current()->Run(); | 659 MessageLoop::current()->Run(); |
665 | 660 |
666 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 661 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
667 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 662 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
668 EXPECT_EQ(1, network_delegate.created_requests()); | 663 EXPECT_EQ(1, network_delegate.created_requests()); |
669 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 664 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
670 } | 665 } |
671 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 666 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
672 } | 667 } |
673 | 668 |
674 // Tests that the network delegate can cancel a request synchronously. | 669 // Tests that the network delegate can cancel a request synchronously. |
675 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { | 670 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelRequestSynchronously) { |
676 ASSERT_TRUE(test_server_.Start()); | 671 ASSERT_TRUE(test_server_.Start()); |
677 | 672 |
678 TestDelegate d; | 673 TestDelegate d; |
679 BlockingNetworkDelegate network_delegate; | 674 BlockingNetworkDelegate network_delegate; |
680 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 675 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
681 | 676 |
682 TestURLRequestContextWithProxy context( | 677 TestURLRequestContextWithProxy context( |
683 test_server_.host_port_pair().ToString(), | 678 test_server_.host_port_pair().ToString(), |
684 &network_delegate); | 679 &network_delegate); |
685 | 680 |
686 { | 681 { |
687 URLRequest r(test_server_.GetURL(""), &d); | 682 URLRequest r(test_server_.GetURL(""), &d, &context); |
688 r.set_context(&context); | |
689 | 683 |
690 r.Start(); | 684 r.Start(); |
691 MessageLoop::current()->Run(); | 685 MessageLoop::current()->Run(); |
692 | 686 |
693 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 687 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
694 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); | 688 EXPECT_EQ(ERR_EMPTY_RESPONSE, r.status().error()); |
695 EXPECT_EQ(1, network_delegate.created_requests()); | 689 EXPECT_EQ(1, network_delegate.created_requests()); |
696 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 690 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
697 } | 691 } |
698 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 692 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
699 } | 693 } |
700 | 694 |
701 // Tests that the network delegate can block and redirect a request to a new | 695 // Tests that the network delegate can block and redirect a request to a new |
702 // URL. | 696 // URL. |
703 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { | 697 TEST_F(URLRequestTestHTTP, NetworkDelegateRedirectRequest) { |
704 ASSERT_TRUE(test_server_.Start()); | 698 ASSERT_TRUE(test_server_.Start()); |
705 | 699 |
706 TestDelegate d; | 700 TestDelegate d; |
707 BlockingNetworkDelegate network_delegate; | 701 BlockingNetworkDelegate network_delegate; |
708 GURL redirect_url(test_server_.GetURL("simple.html")); | 702 GURL redirect_url(test_server_.GetURL("simple.html")); |
709 network_delegate.set_redirect_url(redirect_url); | 703 network_delegate.set_redirect_url(redirect_url); |
710 | 704 |
711 TestURLRequestContextWithProxy context( | 705 TestURLRequestContextWithProxy context( |
712 test_server_.host_port_pair().ToString(), | 706 test_server_.host_port_pair().ToString(), |
713 &network_delegate); | 707 &network_delegate); |
714 | 708 |
715 { | 709 { |
716 GURL original_url(test_server_.GetURL("empty.html")); | 710 GURL original_url(test_server_.GetURL("empty.html")); |
717 URLRequest r(original_url, &d); | 711 URLRequest r(original_url, &d, &context); |
718 r.set_context(&context); | |
719 | 712 |
720 r.Start(); | 713 r.Start(); |
721 MessageLoop::current()->Run(); | 714 MessageLoop::current()->Run(); |
722 | 715 |
723 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 716 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
724 EXPECT_EQ(0, r.status().error()); | 717 EXPECT_EQ(0, r.status().error()); |
725 EXPECT_EQ(redirect_url, r.url()); | 718 EXPECT_EQ(redirect_url, r.url()); |
726 EXPECT_EQ(original_url, r.original_url()); | 719 EXPECT_EQ(original_url, r.original_url()); |
727 EXPECT_EQ(2U, r.url_chain().size()); | 720 EXPECT_EQ(2U, r.url_chain().size()); |
728 EXPECT_EQ(1, network_delegate.created_requests()); | 721 EXPECT_EQ(1, network_delegate.created_requests()); |
(...skipping 12 matching lines...) Expand all Loading... | |
741 GURL redirect_url(test_server_.GetURL("simple.html")); | 734 GURL redirect_url(test_server_.GetURL("simple.html")); |
742 network_delegate.set_redirect_url(redirect_url); | 735 network_delegate.set_redirect_url(redirect_url); |
743 network_delegate.set_retval(OK); | 736 network_delegate.set_retval(OK); |
744 | 737 |
745 TestURLRequestContextWithProxy context( | 738 TestURLRequestContextWithProxy context( |
746 test_server_.host_port_pair().ToString(), | 739 test_server_.host_port_pair().ToString(), |
747 &network_delegate); | 740 &network_delegate); |
748 | 741 |
749 { | 742 { |
750 GURL original_url(test_server_.GetURL("empty.html")); | 743 GURL original_url(test_server_.GetURL("empty.html")); |
751 URLRequest r(original_url, &d); | 744 URLRequest r(original_url, &d, &context); |
752 r.set_context(&context); | |
753 | 745 |
754 r.Start(); | 746 r.Start(); |
755 MessageLoop::current()->Run(); | 747 MessageLoop::current()->Run(); |
756 | 748 |
757 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 749 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
758 EXPECT_EQ(0, r.status().error()); | 750 EXPECT_EQ(0, r.status().error()); |
759 EXPECT_EQ(redirect_url, r.url()); | 751 EXPECT_EQ(redirect_url, r.url()); |
760 EXPECT_EQ(original_url, r.original_url()); | 752 EXPECT_EQ(original_url, r.original_url()); |
761 EXPECT_EQ(2U, r.url_chain().size()); | 753 EXPECT_EQ(2U, r.url_chain().size()); |
762 EXPECT_EQ(1, network_delegate.created_requests()); | 754 EXPECT_EQ(1, network_delegate.created_requests()); |
(...skipping 12 matching lines...) Expand all Loading... | |
775 BlockingNetworkDelegate network_delegate; | 767 BlockingNetworkDelegate network_delegate; |
776 GURL redirect_url(test_server_.GetURL("echo")); | 768 GURL redirect_url(test_server_.GetURL("echo")); |
777 network_delegate.set_redirect_url(redirect_url); | 769 network_delegate.set_redirect_url(redirect_url); |
778 | 770 |
779 TestURLRequestContext context(true); | 771 TestURLRequestContext context(true); |
780 context.set_network_delegate(&network_delegate); | 772 context.set_network_delegate(&network_delegate); |
781 context.Init(); | 773 context.Init(); |
782 | 774 |
783 { | 775 { |
784 GURL original_url(test_server_.GetURL("empty.html")); | 776 GURL original_url(test_server_.GetURL("empty.html")); |
785 URLRequest r(original_url, &d); | 777 URLRequest r(original_url, &d, &context); |
786 r.set_context(&context); | |
787 r.set_method("POST"); | 778 r.set_method("POST"); |
788 r.set_upload(CreateSimpleUploadData(kData).get()); | 779 r.set_upload(CreateSimpleUploadData(kData).get()); |
789 HttpRequestHeaders headers; | 780 HttpRequestHeaders headers; |
790 headers.SetHeader(HttpRequestHeaders::kContentLength, | 781 headers.SetHeader(HttpRequestHeaders::kContentLength, |
791 base::UintToString(arraysize(kData) - 1)); | 782 base::UintToString(arraysize(kData) - 1)); |
792 r.SetExtraRequestHeaders(headers); | 783 r.SetExtraRequestHeaders(headers); |
793 r.Start(); | 784 r.Start(); |
794 MessageLoop::current()->Run(); | 785 MessageLoop::current()->Run(); |
795 | 786 |
796 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 787 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
(...skipping 22 matching lines...) Expand all Loading... | |
819 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); | 810 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); |
820 | 811 |
821 TestURLRequestContext context(true); | 812 TestURLRequestContext context(true); |
822 context.set_network_delegate(&network_delegate); | 813 context.set_network_delegate(&network_delegate); |
823 context.Init(); | 814 context.Init(); |
824 | 815 |
825 d.set_credentials(AuthCredentials(kUser, kSecret)); | 816 d.set_credentials(AuthCredentials(kUser, kSecret)); |
826 | 817 |
827 { | 818 { |
828 GURL url(test_server_.GetURL("auth-basic")); | 819 GURL url(test_server_.GetURL("auth-basic")); |
829 URLRequest r(url, &d); | 820 URLRequest r(url, &d, &context); |
830 r.set_context(&context); | |
831 r.Start(); | 821 r.Start(); |
832 MessageLoop::current()->Run(); | 822 MessageLoop::current()->Run(); |
833 | 823 |
834 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 824 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
835 EXPECT_EQ(0, r.status().error()); | 825 EXPECT_EQ(0, r.status().error()); |
836 EXPECT_EQ(200, r.GetResponseCode()); | 826 EXPECT_EQ(200, r.GetResponseCode()); |
837 EXPECT_TRUE(d.auth_required_called()); | 827 EXPECT_TRUE(d.auth_required_called()); |
838 EXPECT_EQ(1, network_delegate.created_requests()); | 828 EXPECT_EQ(1, network_delegate.created_requests()); |
839 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 829 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
840 } | 830 } |
(...skipping 11 matching lines...) Expand all Loading... | |
852 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 842 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
853 | 843 |
854 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 844 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
855 | 845 |
856 TestURLRequestContext context(true); | 846 TestURLRequestContext context(true); |
857 context.set_network_delegate(&network_delegate); | 847 context.set_network_delegate(&network_delegate); |
858 context.Init(); | 848 context.Init(); |
859 | 849 |
860 { | 850 { |
861 GURL url(test_server_.GetURL("auth-basic")); | 851 GURL url(test_server_.GetURL("auth-basic")); |
862 URLRequest r(url, &d); | 852 URLRequest r(url, &d, &context); |
863 r.set_context(&context); | |
864 r.Start(); | 853 r.Start(); |
865 MessageLoop::current()->Run(); | 854 MessageLoop::current()->Run(); |
866 | 855 |
867 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 856 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
868 EXPECT_EQ(0, r.status().error()); | 857 EXPECT_EQ(0, r.status().error()); |
869 EXPECT_EQ(200, r.GetResponseCode()); | 858 EXPECT_EQ(200, r.GetResponseCode()); |
870 EXPECT_FALSE(d.auth_required_called()); | 859 EXPECT_FALSE(d.auth_required_called()); |
871 EXPECT_EQ(1, network_delegate.created_requests()); | 860 EXPECT_EQ(1, network_delegate.created_requests()); |
872 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 861 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
873 } | 862 } |
874 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 863 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
875 } | 864 } |
876 | 865 |
877 // Tests that the network delegate can synchronously complete OnAuthRequired | 866 // Tests that the network delegate can synchronously complete OnAuthRequired |
878 // by cancelling authentication. | 867 // by cancelling authentication. |
879 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { | 868 TEST_F(URLRequestTestHTTP, NetworkDelegateOnAuthRequiredSyncCancel) { |
880 ASSERT_TRUE(test_server_.Start()); | 869 ASSERT_TRUE(test_server_.Start()); |
881 | 870 |
882 TestDelegate d; | 871 TestDelegate d; |
883 BlockingNetworkDelegate network_delegate; | 872 BlockingNetworkDelegate network_delegate; |
884 network_delegate.set_auth_retval( | 873 network_delegate.set_auth_retval( |
885 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 874 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
886 | 875 |
887 TestURLRequestContext context(true); | 876 TestURLRequestContext context(true); |
888 context.set_network_delegate(&network_delegate); | 877 context.set_network_delegate(&network_delegate); |
889 context.Init(); | 878 context.Init(); |
890 | 879 |
891 { | 880 { |
892 GURL url(test_server_.GetURL("auth-basic")); | 881 GURL url(test_server_.GetURL("auth-basic")); |
893 URLRequest r(url, &d); | 882 URLRequest r(url, &d, &context); |
894 r.set_context(&context); | |
895 r.Start(); | 883 r.Start(); |
896 MessageLoop::current()->Run(); | 884 MessageLoop::current()->Run(); |
897 | 885 |
898 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 886 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
899 EXPECT_EQ(OK, r.status().error()); | 887 EXPECT_EQ(OK, r.status().error()); |
900 EXPECT_EQ(401, r.GetResponseCode()); | 888 EXPECT_EQ(401, r.GetResponseCode()); |
901 EXPECT_FALSE(d.auth_required_called()); | 889 EXPECT_FALSE(d.auth_required_called()); |
902 EXPECT_EQ(1, network_delegate.created_requests()); | 890 EXPECT_EQ(1, network_delegate.created_requests()); |
903 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 891 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
904 } | 892 } |
(...skipping 15 matching lines...) Expand all Loading... | |
920 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); | 908 NetworkDelegate::AUTH_REQUIRED_RESPONSE_NO_ACTION); |
921 | 909 |
922 TestURLRequestContext context(true); | 910 TestURLRequestContext context(true); |
923 context.set_network_delegate(&network_delegate); | 911 context.set_network_delegate(&network_delegate); |
924 context.Init(); | 912 context.Init(); |
925 | 913 |
926 d.set_credentials(AuthCredentials(kUser, kSecret)); | 914 d.set_credentials(AuthCredentials(kUser, kSecret)); |
927 | 915 |
928 { | 916 { |
929 GURL url(test_server_.GetURL("auth-basic")); | 917 GURL url(test_server_.GetURL("auth-basic")); |
930 URLRequest r(url, &d); | 918 URLRequest r(url, &d, &context); |
931 r.set_context(&context); | |
932 r.Start(); | 919 r.Start(); |
933 MessageLoop::current()->Run(); | 920 MessageLoop::current()->Run(); |
934 | 921 |
935 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 922 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
936 EXPECT_EQ(0, r.status().error()); | 923 EXPECT_EQ(0, r.status().error()); |
937 EXPECT_EQ(200, r.GetResponseCode()); | 924 EXPECT_EQ(200, r.GetResponseCode()); |
938 EXPECT_TRUE(d.auth_required_called()); | 925 EXPECT_TRUE(d.auth_required_called()); |
939 EXPECT_EQ(1, network_delegate.created_requests()); | 926 EXPECT_EQ(1, network_delegate.created_requests()); |
940 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 927 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
941 } | 928 } |
(...skipping 14 matching lines...) Expand all Loading... | |
956 | 943 |
957 AuthCredentials auth_credentials(kUser, kSecret); | 944 AuthCredentials auth_credentials(kUser, kSecret); |
958 network_delegate.set_auth_credentials(auth_credentials); | 945 network_delegate.set_auth_credentials(auth_credentials); |
959 | 946 |
960 TestURLRequestContext context(true); | 947 TestURLRequestContext context(true); |
961 context.set_network_delegate(&network_delegate); | 948 context.set_network_delegate(&network_delegate); |
962 context.Init(); | 949 context.Init(); |
963 | 950 |
964 { | 951 { |
965 GURL url(test_server_.GetURL("auth-basic")); | 952 GURL url(test_server_.GetURL("auth-basic")); |
966 URLRequest r(url, &d); | 953 URLRequest r(url, &d, &context); |
967 r.set_context(&context); | |
968 r.Start(); | 954 r.Start(); |
969 MessageLoop::current()->Run(); | 955 MessageLoop::current()->Run(); |
970 | 956 |
971 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 957 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
972 EXPECT_EQ(0, r.status().error()); | 958 EXPECT_EQ(0, r.status().error()); |
973 | 959 |
974 EXPECT_EQ(200, r.GetResponseCode()); | 960 EXPECT_EQ(200, r.GetResponseCode()); |
975 EXPECT_FALSE(d.auth_required_called()); | 961 EXPECT_FALSE(d.auth_required_called()); |
976 EXPECT_EQ(1, network_delegate.created_requests()); | 962 EXPECT_EQ(1, network_delegate.created_requests()); |
977 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 963 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
(...skipping 12 matching lines...) Expand all Loading... | |
990 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); | 976 NetworkDelegate::AUTH_REQUIRED_RESPONSE_IO_PENDING); |
991 network_delegate.set_auth_callback_retval( | 977 network_delegate.set_auth_callback_retval( |
992 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 978 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
993 | 979 |
994 TestURLRequestContext context(true); | 980 TestURLRequestContext context(true); |
995 context.set_network_delegate(&network_delegate); | 981 context.set_network_delegate(&network_delegate); |
996 context.Init(); | 982 context.Init(); |
997 | 983 |
998 { | 984 { |
999 GURL url(test_server_.GetURL("auth-basic")); | 985 GURL url(test_server_.GetURL("auth-basic")); |
1000 URLRequest r(url, &d); | 986 URLRequest r(url, &d, &context); |
1001 r.set_context(&context); | |
1002 r.Start(); | 987 r.Start(); |
1003 MessageLoop::current()->Run(); | 988 MessageLoop::current()->Run(); |
1004 | 989 |
1005 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 990 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
1006 EXPECT_EQ(OK, r.status().error()); | 991 EXPECT_EQ(OK, r.status().error()); |
1007 EXPECT_EQ(401, r.GetResponseCode()); | 992 EXPECT_EQ(401, r.GetResponseCode()); |
1008 EXPECT_FALSE(d.auth_required_called()); | 993 EXPECT_FALSE(d.auth_required_called()); |
1009 EXPECT_EQ(1, network_delegate.created_requests()); | 994 EXPECT_EQ(1, network_delegate.created_requests()); |
1010 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 995 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
1011 } | 996 } |
1012 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 997 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
1013 } | 998 } |
1014 | 999 |
1015 // Tests that we can handle when a network request was canceled while we were | 1000 // Tests that we can handle when a network request was canceled while we were |
1016 // waiting for the network delegate. | 1001 // waiting for the network delegate. |
1017 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. | 1002 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. |
1018 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { | 1003 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { |
1019 ASSERT_TRUE(test_server_.Start()); | 1004 ASSERT_TRUE(test_server_.Start()); |
1020 | 1005 |
1021 TestDelegate d; | 1006 TestDelegate d; |
1022 BlockingNetworkDelegateWithManualCallback network_delegate; | 1007 BlockingNetworkDelegateWithManualCallback network_delegate; |
1023 network_delegate.BlockOn( | 1008 network_delegate.BlockOn( |
1024 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); | 1009 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); |
1025 | 1010 |
1026 TestURLRequestContext context(true); | 1011 TestURLRequestContext context(true); |
1027 context.set_network_delegate(&network_delegate); | 1012 context.set_network_delegate(&network_delegate); |
1028 context.Init(); | 1013 context.Init(); |
1029 | 1014 |
1030 { | 1015 { |
1031 URLRequest r(test_server_.GetURL(""), &d); | 1016 URLRequest r(test_server_.GetURL(""), &d, &context); |
1032 r.set_context(&context); | |
1033 | 1017 |
1034 r.Start(); | 1018 r.Start(); |
1035 network_delegate.WaitForState( | 1019 network_delegate.WaitForState( |
1036 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); | 1020 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_URL_REQUEST); |
1037 EXPECT_EQ(0, network_delegate.completed_requests()); | 1021 EXPECT_EQ(0, network_delegate.completed_requests()); |
1038 // Cancel before callback. | 1022 // Cancel before callback. |
1039 r.Cancel(); | 1023 r.Cancel(); |
1040 // Ensure that network delegate is notified. | 1024 // Ensure that network delegate is notified. |
1041 EXPECT_EQ(1, network_delegate.completed_requests()); | 1025 EXPECT_EQ(1, network_delegate.completed_requests()); |
1042 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 1026 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
(...skipping 13 matching lines...) Expand all Loading... | |
1056 TestDelegate d; | 1040 TestDelegate d; |
1057 BlockingNetworkDelegateWithManualCallback network_delegate; | 1041 BlockingNetworkDelegateWithManualCallback network_delegate; |
1058 network_delegate.BlockOn( | 1042 network_delegate.BlockOn( |
1059 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); | 1043 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); |
1060 | 1044 |
1061 TestURLRequestContext context(true); | 1045 TestURLRequestContext context(true); |
1062 context.set_network_delegate(&network_delegate); | 1046 context.set_network_delegate(&network_delegate); |
1063 context.Init(); | 1047 context.Init(); |
1064 | 1048 |
1065 { | 1049 { |
1066 URLRequest r(test_server_.GetURL(""), &d); | 1050 URLRequest r(test_server_.GetURL(""), &d, &context); |
1067 r.set_context(&context); | |
1068 | 1051 |
1069 r.Start(); | 1052 r.Start(); |
1070 network_delegate.WaitForState( | 1053 network_delegate.WaitForState( |
1071 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); | 1054 BlockingNetworkDelegateWithManualCallback::ON_BEFORE_SEND_HEADERS); |
1072 EXPECT_EQ(0, network_delegate.completed_requests()); | 1055 EXPECT_EQ(0, network_delegate.completed_requests()); |
1073 // Cancel before callback. | 1056 // Cancel before callback. |
1074 r.Cancel(); | 1057 r.Cancel(); |
1075 // Ensure that network delegate is notified. | 1058 // Ensure that network delegate is notified. |
1076 EXPECT_EQ(1, network_delegate.completed_requests()); | 1059 EXPECT_EQ(1, network_delegate.completed_requests()); |
1077 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 1060 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
(...skipping 13 matching lines...) Expand all Loading... | |
1091 TestDelegate d; | 1074 TestDelegate d; |
1092 BlockingNetworkDelegateWithManualCallback network_delegate; | 1075 BlockingNetworkDelegateWithManualCallback network_delegate; |
1093 network_delegate.BlockOn( | 1076 network_delegate.BlockOn( |
1094 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); | 1077 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); |
1095 | 1078 |
1096 TestURLRequestContext context(true); | 1079 TestURLRequestContext context(true); |
1097 context.set_network_delegate(&network_delegate); | 1080 context.set_network_delegate(&network_delegate); |
1098 context.Init(); | 1081 context.Init(); |
1099 | 1082 |
1100 { | 1083 { |
1101 URLRequest r(test_server_.GetURL(""), &d); | 1084 URLRequest r(test_server_.GetURL(""), &d, &context); |
1102 r.set_context(&context); | |
1103 | 1085 |
1104 r.Start(); | 1086 r.Start(); |
1105 network_delegate.WaitForState( | 1087 network_delegate.WaitForState( |
1106 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); | 1088 BlockingNetworkDelegateWithManualCallback::ON_HEADERS_RECEIVED); |
1107 EXPECT_EQ(0, network_delegate.completed_requests()); | 1089 EXPECT_EQ(0, network_delegate.completed_requests()); |
1108 // Cancel before callback. | 1090 // Cancel before callback. |
1109 r.Cancel(); | 1091 r.Cancel(); |
1110 // Ensure that network delegate is notified. | 1092 // Ensure that network delegate is notified. |
1111 EXPECT_EQ(1, network_delegate.completed_requests()); | 1093 EXPECT_EQ(1, network_delegate.completed_requests()); |
1112 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 1094 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
(...skipping 13 matching lines...) Expand all Loading... | |
1126 TestDelegate d; | 1108 TestDelegate d; |
1127 BlockingNetworkDelegateWithManualCallback network_delegate; | 1109 BlockingNetworkDelegateWithManualCallback network_delegate; |
1128 network_delegate.BlockOn( | 1110 network_delegate.BlockOn( |
1129 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); | 1111 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); |
1130 | 1112 |
1131 TestURLRequestContext context(true); | 1113 TestURLRequestContext context(true); |
1132 context.set_network_delegate(&network_delegate); | 1114 context.set_network_delegate(&network_delegate); |
1133 context.Init(); | 1115 context.Init(); |
1134 | 1116 |
1135 { | 1117 { |
1136 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 1118 URLRequest r(test_server_.GetURL("auth-basic"), &d, &context); |
1137 r.set_context(&context); | |
1138 | 1119 |
1139 r.Start(); | 1120 r.Start(); |
1140 network_delegate.WaitForState( | 1121 network_delegate.WaitForState( |
1141 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); | 1122 BlockingNetworkDelegateWithManualCallback::ON_AUTH_REQUIRED); |
1142 EXPECT_EQ(0, network_delegate.completed_requests()); | 1123 EXPECT_EQ(0, network_delegate.completed_requests()); |
1143 // Cancel before callback. | 1124 // Cancel before callback. |
1144 r.Cancel(); | 1125 r.Cancel(); |
1145 // Ensure that network delegate is notified. | 1126 // Ensure that network delegate is notified. |
1146 EXPECT_EQ(1, network_delegate.completed_requests()); | 1127 EXPECT_EQ(1, network_delegate.completed_requests()); |
1147 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 1128 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
(...skipping 10 matching lines...) Expand all Loading... | |
1158 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { | 1139 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { |
1159 ASSERT_TRUE(test_server_.Start()); | 1140 ASSERT_TRUE(test_server_.Start()); |
1160 | 1141 |
1161 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1142 TestNetworkDelegate network_delegate; // must outlive URLRequest |
1162 TestURLRequestContextWithProxy context( | 1143 TestURLRequestContextWithProxy context( |
1163 test_server_.host_port_pair().ToString(), | 1144 test_server_.host_port_pair().ToString(), |
1164 &network_delegate); | 1145 &network_delegate); |
1165 | 1146 |
1166 TestDelegate d; | 1147 TestDelegate d; |
1167 { | 1148 { |
1168 URLRequest r(GURL("https://www.server-auth.com/"), &d); | 1149 URLRequest r(GURL("https://www.server-auth.com/"), &d, &context); |
1169 r.set_context(&context); | |
1170 | 1150 |
1171 r.Start(); | 1151 r.Start(); |
1172 EXPECT_TRUE(r.is_pending()); | 1152 EXPECT_TRUE(r.is_pending()); |
1173 | 1153 |
1174 MessageLoop::current()->Run(); | 1154 MessageLoop::current()->Run(); |
1175 | 1155 |
1176 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 1156 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
1177 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); | 1157 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r.status().error()); |
1178 } | 1158 } |
1179 } | 1159 } |
1180 | 1160 |
1181 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 1161 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
1182 ASSERT_TRUE(test_server_.Start()); | 1162 ASSERT_TRUE(test_server_.Start()); |
1183 | 1163 |
1184 TestDelegate d; | 1164 TestDelegate d; |
1185 { | 1165 { |
1186 URLRequest r(test_server_.GetURL(""), &d); | 1166 URLRequest r(test_server_.GetURL(""), &d, &default_context_); |
1187 r.set_context(&default_context_); | |
1188 | 1167 |
1189 r.Start(); | 1168 r.Start(); |
1190 EXPECT_TRUE(r.is_pending()); | 1169 EXPECT_TRUE(r.is_pending()); |
1191 | 1170 |
1192 MessageLoop::current()->Run(); | 1171 MessageLoop::current()->Run(); |
1193 | 1172 |
1194 EXPECT_EQ(1, d.response_started_count()); | 1173 EXPECT_EQ(1, d.response_started_count()); |
1195 EXPECT_FALSE(d.received_data_before_response()); | 1174 EXPECT_FALSE(d.received_data_before_response()); |
1196 EXPECT_NE(0, d.bytes_received()); | 1175 EXPECT_NE(0, d.bytes_received()); |
1197 EXPECT_EQ(test_server_.host_port_pair().host(), | 1176 EXPECT_EQ(test_server_.host_port_pair().host(), |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1237 upper_bound = num_cookies; | 1216 upper_bound = num_cookies; |
1238 } | 1217 } |
1239 // Success: the test did not crash. | 1218 // Success: the test did not crash. |
1240 } | 1219 } |
1241 | 1220 |
1242 TEST_F(URLRequestTestHTTP, GetTest) { | 1221 TEST_F(URLRequestTestHTTP, GetTest) { |
1243 ASSERT_TRUE(test_server_.Start()); | 1222 ASSERT_TRUE(test_server_.Start()); |
1244 | 1223 |
1245 TestDelegate d; | 1224 TestDelegate d; |
1246 { | 1225 { |
1247 URLRequest r(test_server_.GetURL(""), &d); | 1226 URLRequest r(test_server_.GetURL(""), &d, &default_context_); |
1248 r.set_context(&default_context_); | |
1249 | 1227 |
1250 r.Start(); | 1228 r.Start(); |
1251 EXPECT_TRUE(r.is_pending()); | 1229 EXPECT_TRUE(r.is_pending()); |
1252 | 1230 |
1253 MessageLoop::current()->Run(); | 1231 MessageLoop::current()->Run(); |
1254 | 1232 |
1255 EXPECT_EQ(1, d.response_started_count()); | 1233 EXPECT_EQ(1, d.response_started_count()); |
1256 EXPECT_FALSE(d.received_data_before_response()); | 1234 EXPECT_FALSE(d.received_data_before_response()); |
1257 EXPECT_NE(0, d.bytes_received()); | 1235 EXPECT_NE(0, d.bytes_received()); |
1258 EXPECT_EQ(test_server_.host_port_pair().host(), | 1236 EXPECT_EQ(test_server_.host_port_pair().host(), |
(...skipping 25 matching lines...) Expand all Loading... | |
1284 { | 1262 { |
1285 std::string test_file = | 1263 std::string test_file = |
1286 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", | 1264 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", |
1287 test_parameters[i]); | 1265 test_parameters[i]); |
1288 | 1266 |
1289 TestNetworkDelegate network_delegate; // must outlive URLRequest | 1267 TestNetworkDelegate network_delegate; // must outlive URLRequest |
1290 TestURLRequestContext context(true); | 1268 TestURLRequestContext context(true); |
1291 context.set_network_delegate(&network_delegate); | 1269 context.set_network_delegate(&network_delegate); |
1292 context.Init(); | 1270 context.Init(); |
1293 | 1271 |
1294 URLRequest r(test_server_.GetURL(test_file), &d); | 1272 URLRequest r(test_server_.GetURL(test_file), &d, &context); |
1295 r.set_context(&context); | |
1296 r.Start(); | 1273 r.Start(); |
1297 EXPECT_TRUE(r.is_pending()); | 1274 EXPECT_TRUE(r.is_pending()); |
1298 | 1275 |
1299 MessageLoop::current()->Run(); | 1276 MessageLoop::current()->Run(); |
1300 | 1277 |
1301 EXPECT_EQ(1, d.response_started_count()); | 1278 EXPECT_EQ(1, d.response_started_count()); |
1302 EXPECT_FALSE(d.received_data_before_response()); | 1279 EXPECT_FALSE(d.received_data_before_response()); |
1303 VLOG(1) << " Received " << d.bytes_received() << " bytes" | 1280 VLOG(1) << " Received " << d.bytes_received() << " bytes" |
1304 << " status = " << r.status().status() | 1281 << " status = " << r.status().status() |
1305 << " error = " << r.status().error(); | 1282 << " error = " << r.status().error(); |
(...skipping 18 matching lines...) Expand all Loading... | |
1324 TestServer::kLocalhost, | 1301 TestServer::kLocalhost, |
1325 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1302 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1326 ASSERT_TRUE(https_test_server.Start()); | 1303 ASSERT_TRUE(https_test_server.Start()); |
1327 | 1304 |
1328 // An https server is sent a request with an https referer, | 1305 // An https server is sent a request with an https referer, |
1329 // and responds with a redirect to an http url. The http | 1306 // and responds with a redirect to an http url. The http |
1330 // server should not be sent the referer. | 1307 // server should not be sent the referer. |
1331 GURL http_destination = test_server_.GetURL(""); | 1308 GURL http_destination = test_server_.GetURL(""); |
1332 TestDelegate d; | 1309 TestDelegate d; |
1333 URLRequest req(https_test_server.GetURL( | 1310 URLRequest req(https_test_server.GetURL( |
1334 "server-redirect?" + http_destination.spec()), &d); | 1311 "server-redirect?" + http_destination.spec()), &d, &default_context_); |
1335 req.set_context(&default_context_); | |
1336 req.set_referrer("https://www.referrer.com/"); | 1312 req.set_referrer("https://www.referrer.com/"); |
1337 req.Start(); | 1313 req.Start(); |
1338 MessageLoop::current()->Run(); | 1314 MessageLoop::current()->Run(); |
1339 | 1315 |
1340 EXPECT_EQ(1, d.response_started_count()); | 1316 EXPECT_EQ(1, d.response_started_count()); |
1341 EXPECT_EQ(1, d.received_redirect_count()); | 1317 EXPECT_EQ(1, d.received_redirect_count()); |
1342 EXPECT_EQ(http_destination, req.url()); | 1318 EXPECT_EQ(http_destination, req.url()); |
1343 EXPECT_EQ(std::string(), req.referrer()); | 1319 EXPECT_EQ(std::string(), req.referrer()); |
1344 } | 1320 } |
1345 | 1321 |
1346 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { | 1322 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { |
1347 ASSERT_TRUE(test_server_.Start()); | 1323 ASSERT_TRUE(test_server_.Start()); |
1348 | 1324 |
1349 GURL destination_url = test_server_.GetURL(""); | 1325 GURL destination_url = test_server_.GetURL(""); |
1350 GURL middle_redirect_url = test_server_.GetURL( | 1326 GURL middle_redirect_url = test_server_.GetURL( |
1351 "server-redirect?" + destination_url.spec()); | 1327 "server-redirect?" + destination_url.spec()); |
1352 GURL original_url = test_server_.GetURL( | 1328 GURL original_url = test_server_.GetURL( |
1353 "server-redirect?" + middle_redirect_url.spec()); | 1329 "server-redirect?" + middle_redirect_url.spec()); |
1354 TestDelegate d; | 1330 TestDelegate d; |
1355 URLRequest req(original_url, &d); | 1331 URLRequest req(original_url, &d, &default_context_); |
1356 req.set_context(&default_context_); | |
1357 req.Start(); | 1332 req.Start(); |
1358 MessageLoop::current()->Run(); | 1333 MessageLoop::current()->Run(); |
1359 | 1334 |
1360 EXPECT_EQ(1, d.response_started_count()); | 1335 EXPECT_EQ(1, d.response_started_count()); |
1361 EXPECT_EQ(2, d.received_redirect_count()); | 1336 EXPECT_EQ(2, d.received_redirect_count()); |
1362 EXPECT_EQ(destination_url, req.url()); | 1337 EXPECT_EQ(destination_url, req.url()); |
1363 EXPECT_EQ(original_url, req.original_url()); | 1338 EXPECT_EQ(original_url, req.original_url()); |
1364 ASSERT_EQ(3U, req.url_chain().size()); | 1339 ASSERT_EQ(3U, req.url_chain().size()); |
1365 EXPECT_EQ(original_url, req.url_chain()[0]); | 1340 EXPECT_EQ(original_url, req.url_chain()[0]); |
1366 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); | 1341 EXPECT_EQ(middle_redirect_url, req.url_chain()[1]); |
(...skipping 16 matching lines...) Expand all Loading... | |
1383 // This test was disabled because it made chrome_frame_net_tests hang | 1358 // This test was disabled because it made chrome_frame_net_tests hang |
1384 // (see bug 102991). | 1359 // (see bug 102991). |
1385 TEST_F(HTTPSRequestTest, DISABLED_HTTPSGetTest) { | 1360 TEST_F(HTTPSRequestTest, DISABLED_HTTPSGetTest) { |
1386 TestServer test_server(TestServer::TYPE_HTTPS, | 1361 TestServer test_server(TestServer::TYPE_HTTPS, |
1387 TestServer::kLocalhost, | 1362 TestServer::kLocalhost, |
1388 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1363 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1389 ASSERT_TRUE(test_server.Start()); | 1364 ASSERT_TRUE(test_server.Start()); |
1390 | 1365 |
1391 TestDelegate d; | 1366 TestDelegate d; |
1392 { | 1367 { |
1393 URLRequest r(test_server.GetURL(""), &d); | 1368 URLRequest r(test_server.GetURL(""), &d, &default_context_); |
1394 r.set_context(&default_context_); | |
1395 r.Start(); | 1369 r.Start(); |
1396 EXPECT_TRUE(r.is_pending()); | 1370 EXPECT_TRUE(r.is_pending()); |
1397 | 1371 |
1398 MessageLoop::current()->Run(); | 1372 MessageLoop::current()->Run(); |
1399 | 1373 |
1400 EXPECT_EQ(1, d.response_started_count()); | 1374 EXPECT_EQ(1, d.response_started_count()); |
1401 EXPECT_FALSE(d.received_data_before_response()); | 1375 EXPECT_FALSE(d.received_data_before_response()); |
1402 EXPECT_NE(0, d.bytes_received()); | 1376 EXPECT_NE(0, d.bytes_received()); |
1403 CheckSSLInfo(r.ssl_info()); | 1377 CheckSSLInfo(r.ssl_info()); |
1404 EXPECT_EQ(test_server.host_port_pair().host(), | 1378 EXPECT_EQ(test_server.host_port_pair().host(), |
1405 r.GetSocketAddress().host()); | 1379 r.GetSocketAddress().host()); |
1406 EXPECT_EQ(test_server.host_port_pair().port(), | 1380 EXPECT_EQ(test_server.host_port_pair().port(), |
1407 r.GetSocketAddress().port()); | 1381 r.GetSocketAddress().port()); |
1408 } | 1382 } |
1409 } | 1383 } |
1410 | 1384 |
1411 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { | 1385 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { |
1412 TestServer::HTTPSOptions https_options( | 1386 TestServer::HTTPSOptions https_options( |
1413 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); | 1387 TestServer::HTTPSOptions::CERT_MISMATCHED_NAME); |
1414 TestServer test_server(https_options, | 1388 TestServer test_server(https_options, |
1415 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1389 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1416 ASSERT_TRUE(test_server.Start()); | 1390 ASSERT_TRUE(test_server.Start()); |
1417 | 1391 |
1418 bool err_allowed = true; | 1392 bool err_allowed = true; |
1419 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 1393 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
1420 TestDelegate d; | 1394 TestDelegate d; |
1421 { | 1395 { |
1422 d.set_allow_certificate_errors(err_allowed); | 1396 d.set_allow_certificate_errors(err_allowed); |
1423 URLRequest r(test_server.GetURL(""), &d); | 1397 URLRequest r(test_server.GetURL(""), &d, &default_context_); |
1424 r.set_context(&default_context_); | |
1425 | 1398 |
1426 r.Start(); | 1399 r.Start(); |
1427 EXPECT_TRUE(r.is_pending()); | 1400 EXPECT_TRUE(r.is_pending()); |
1428 | 1401 |
1429 MessageLoop::current()->Run(); | 1402 MessageLoop::current()->Run(); |
1430 | 1403 |
1431 EXPECT_EQ(1, d.response_started_count()); | 1404 EXPECT_EQ(1, d.response_started_count()); |
1432 EXPECT_FALSE(d.received_data_before_response()); | 1405 EXPECT_FALSE(d.received_data_before_response()); |
1433 EXPECT_TRUE(d.have_certificate_errors()); | 1406 EXPECT_TRUE(d.have_certificate_errors()); |
1434 if (err_allowed) { | 1407 if (err_allowed) { |
(...skipping 13 matching lines...) Expand all Loading... | |
1448 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1421 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1449 ASSERT_TRUE(test_server.Start()); | 1422 ASSERT_TRUE(test_server.Start()); |
1450 | 1423 |
1451 // Iterate from false to true, just so that we do the opposite of the | 1424 // Iterate from false to true, just so that we do the opposite of the |
1452 // previous test in order to increase test coverage. | 1425 // previous test in order to increase test coverage. |
1453 bool err_allowed = false; | 1426 bool err_allowed = false; |
1454 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 1427 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
1455 TestDelegate d; | 1428 TestDelegate d; |
1456 { | 1429 { |
1457 d.set_allow_certificate_errors(err_allowed); | 1430 d.set_allow_certificate_errors(err_allowed); |
1458 URLRequest r(test_server.GetURL(""), &d); | 1431 URLRequest r(test_server.GetURL(""), &d, &default_context_); |
1459 r.set_context(&default_context_); | |
1460 | 1432 |
1461 r.Start(); | 1433 r.Start(); |
1462 EXPECT_TRUE(r.is_pending()); | 1434 EXPECT_TRUE(r.is_pending()); |
1463 | 1435 |
1464 MessageLoop::current()->Run(); | 1436 MessageLoop::current()->Run(); |
1465 | 1437 |
1466 EXPECT_EQ(1, d.response_started_count()); | 1438 EXPECT_EQ(1, d.response_started_count()); |
1467 EXPECT_FALSE(d.received_data_before_response()); | 1439 EXPECT_FALSE(d.received_data_before_response()); |
1468 EXPECT_TRUE(d.have_certificate_errors()); | 1440 EXPECT_TRUE(d.have_certificate_errors()); |
1469 if (err_allowed) { | 1441 if (err_allowed) { |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1533 } | 1505 } |
1534 | 1506 |
1535 void DoConnection(const TestServer::HTTPSOptions& https_options, | 1507 void DoConnection(const TestServer::HTTPSOptions& https_options, |
1536 CertStatus* out_cert_status) { | 1508 CertStatus* out_cert_status) { |
1537 TestServer test_server(https_options, | 1509 TestServer test_server(https_options, |
1538 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1510 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1539 ASSERT_TRUE(test_server.Start()); | 1511 ASSERT_TRUE(test_server.Start()); |
1540 | 1512 |
1541 TestDelegate d; | 1513 TestDelegate d; |
1542 d.set_allow_certificate_errors(true); | 1514 d.set_allow_certificate_errors(true); |
1543 URLRequest r(test_server.GetURL(""), &d); | 1515 URLRequest r(test_server.GetURL(""), &d, &context_); |
1544 r.set_context(&context_); | |
1545 r.Start(); | 1516 r.Start(); |
1546 | 1517 |
1547 MessageLoop::current()->Run(); | 1518 MessageLoop::current()->Run(); |
1548 | 1519 |
1549 EXPECT_EQ(1, d.response_started_count()); | 1520 EXPECT_EQ(1, d.response_started_count()); |
1550 *out_cert_status = r.ssl_info().cert_status; | 1521 *out_cert_status = r.ssl_info().cert_status; |
1551 } | 1522 } |
1552 | 1523 |
1553 ~HTTPSOCSPTest() { | 1524 ~HTTPSOCSPTest() { |
1554 #if defined(USE_NSS) | 1525 #if defined(USE_NSS) |
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1800 TestServer::HTTPSOptions::CERT_OK); | 1771 TestServer::HTTPSOptions::CERT_OK); |
1801 https_options.tls_intolerant = TestServer::HTTPSOptions::TLS_INTOLERANT_ALL; | 1772 https_options.tls_intolerant = TestServer::HTTPSOptions::TLS_INTOLERANT_ALL; |
1802 TestServer test_server(https_options, | 1773 TestServer test_server(https_options, |
1803 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1774 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1804 ASSERT_TRUE(test_server.Start()); | 1775 ASSERT_TRUE(test_server.Start()); |
1805 | 1776 |
1806 TestDelegate d; | 1777 TestDelegate d; |
1807 TestURLRequestContext context(true); | 1778 TestURLRequestContext context(true); |
1808 context.Init(); | 1779 context.Init(); |
1809 d.set_allow_certificate_errors(true); | 1780 d.set_allow_certificate_errors(true); |
1810 URLRequest r(test_server.GetURL(""), &d); | 1781 URLRequest r(test_server.GetURL(""), &d, &context); |
1811 r.set_context(&context); | |
1812 r.Start(); | 1782 r.Start(); |
1813 | 1783 |
1814 MessageLoop::current()->Run(); | 1784 MessageLoop::current()->Run(); |
1815 | 1785 |
1816 EXPECT_EQ(1, d.response_started_count()); | 1786 EXPECT_EQ(1, d.response_started_count()); |
1817 EXPECT_NE(0, d.bytes_received()); | 1787 EXPECT_NE(0, d.bytes_received()); |
1818 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), | 1788 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_SSL3), |
1819 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); | 1789 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); |
1820 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); | 1790 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); |
1821 } | 1791 } |
(...skipping 14 matching lines...) Expand all Loading... | |
1836 https_options.tls_intolerant = | 1806 https_options.tls_intolerant = |
1837 TestServer::HTTPSOptions::TLS_INTOLERANT_TLS1_1; | 1807 TestServer::HTTPSOptions::TLS_INTOLERANT_TLS1_1; |
1838 TestServer test_server(https_options, | 1808 TestServer test_server(https_options, |
1839 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1809 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1840 ASSERT_TRUE(test_server.Start()); | 1810 ASSERT_TRUE(test_server.Start()); |
1841 | 1811 |
1842 TestDelegate d; | 1812 TestDelegate d; |
1843 TestURLRequestContext context(true); | 1813 TestURLRequestContext context(true); |
1844 context.Init(); | 1814 context.Init(); |
1845 d.set_allow_certificate_errors(true); | 1815 d.set_allow_certificate_errors(true); |
1846 URLRequest r(test_server.GetURL(""), &d); | 1816 URLRequest r(test_server.GetURL(""), &d, &context); |
1847 r.set_context(&context); | |
1848 r.Start(); | 1817 r.Start(); |
1849 | 1818 |
1850 MessageLoop::current()->Run(); | 1819 MessageLoop::current()->Run(); |
1851 | 1820 |
1852 EXPECT_EQ(1, d.response_started_count()); | 1821 EXPECT_EQ(1, d.response_started_count()); |
1853 EXPECT_NE(0, d.bytes_received()); | 1822 EXPECT_NE(0, d.bytes_received()); |
1854 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1), | 1823 EXPECT_EQ(static_cast<int>(SSL_CONNECTION_VERSION_TLS1), |
1855 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); | 1824 SSLConnectionStatusToVersion(r.ssl_info().connection_status)); |
1856 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); | 1825 EXPECT_TRUE(r.ssl_info().connection_status & SSL_CONNECTION_VERSION_FALLBACK); |
1857 } | 1826 } |
(...skipping 19 matching lines...) Expand all Loading... | |
1877 TestURLRequestContext context(true); | 1846 TestURLRequestContext context(true); |
1878 context.set_network_delegate(&network_delegate); | 1847 context.set_network_delegate(&network_delegate); |
1879 context.set_host_resolver(&host_resolver); | 1848 context.set_host_resolver(&host_resolver); |
1880 TransportSecurityState transport_security_state; | 1849 TransportSecurityState transport_security_state; |
1881 context.set_transport_security_state(&transport_security_state); | 1850 context.set_transport_security_state(&transport_security_state); |
1882 context.Init(); | 1851 context.Init(); |
1883 | 1852 |
1884 TestDelegate d; | 1853 TestDelegate d; |
1885 URLRequest r(GURL(StringPrintf("https://www.google.com:%d", | 1854 URLRequest r(GURL(StringPrintf("https://www.google.com:%d", |
1886 test_server.host_port_pair().port())), | 1855 test_server.host_port_pair().port())), |
1887 &d); | 1856 &d, |
1888 r.set_context(&context); | 1857 &context); |
1889 | 1858 |
1890 r.Start(); | 1859 r.Start(); |
1891 EXPECT_TRUE(r.is_pending()); | 1860 EXPECT_TRUE(r.is_pending()); |
1892 | 1861 |
1893 MessageLoop::current()->Run(); | 1862 MessageLoop::current()->Run(); |
1894 | 1863 |
1895 EXPECT_EQ(1, d.response_started_count()); | 1864 EXPECT_EQ(1, d.response_started_count()); |
1896 EXPECT_FALSE(d.received_data_before_response()); | 1865 EXPECT_FALSE(d.received_data_before_response()); |
1897 EXPECT_TRUE(d.have_certificate_errors()); | 1866 EXPECT_TRUE(d.have_certificate_errors()); |
1898 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 1867 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
(...skipping 24 matching lines...) Expand all Loading... | |
1923 TransportSecurityState transport_security_state; | 1892 TransportSecurityState transport_security_state; |
1924 TransportSecurityState::DomainState domain_state; | 1893 TransportSecurityState::DomainState domain_state; |
1925 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, | 1894 EXPECT_TRUE(transport_security_state.GetDomainState("www.google.com", true, |
1926 &domain_state)); | 1895 &domain_state)); |
1927 context.set_transport_security_state(&transport_security_state); | 1896 context.set_transport_security_state(&transport_security_state); |
1928 context.Init(); | 1897 context.Init(); |
1929 | 1898 |
1930 TestDelegate d; | 1899 TestDelegate d; |
1931 URLRequest r(GURL(StringPrintf("https://www.google.com:%d", | 1900 URLRequest r(GURL(StringPrintf("https://www.google.com:%d", |
1932 test_server.host_port_pair().port())), | 1901 test_server.host_port_pair().port())), |
1933 &d); | 1902 &d, |
1934 r.set_context(&context); | 1903 &context); |
1935 | 1904 |
1936 r.Start(); | 1905 r.Start(); |
1937 EXPECT_TRUE(r.is_pending()); | 1906 EXPECT_TRUE(r.is_pending()); |
1938 | 1907 |
1939 MessageLoop::current()->Run(); | 1908 MessageLoop::current()->Run(); |
1940 | 1909 |
1941 EXPECT_EQ(1, d.response_started_count()); | 1910 EXPECT_EQ(1, d.response_started_count()); |
1942 EXPECT_FALSE(d.received_data_before_response()); | 1911 EXPECT_FALSE(d.received_data_before_response()); |
1943 EXPECT_TRUE(d.have_certificate_errors()); | 1912 EXPECT_TRUE(d.have_certificate_errors()); |
1944 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 1913 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1986 // HTTP request. | 1955 // HTTP request. |
1987 TEST_F(HTTPSRequestTest, ClientAuthTest) { | 1956 TEST_F(HTTPSRequestTest, ClientAuthTest) { |
1988 TestServer::HTTPSOptions https_options; | 1957 TestServer::HTTPSOptions https_options; |
1989 https_options.request_client_certificate = true; | 1958 https_options.request_client_certificate = true; |
1990 TestServer test_server(https_options, | 1959 TestServer test_server(https_options, |
1991 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1960 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
1992 ASSERT_TRUE(test_server.Start()); | 1961 ASSERT_TRUE(test_server.Start()); |
1993 | 1962 |
1994 SSLClientAuthTestDelegate d; | 1963 SSLClientAuthTestDelegate d; |
1995 { | 1964 { |
1996 URLRequest r(test_server.GetURL(""), &d); | 1965 URLRequest r(test_server.GetURL(""), &d, &default_context_); |
1997 r.set_context(&default_context_); | |
1998 | 1966 |
1999 r.Start(); | 1967 r.Start(); |
2000 EXPECT_TRUE(r.is_pending()); | 1968 EXPECT_TRUE(r.is_pending()); |
2001 | 1969 |
2002 MessageLoop::current()->Run(); | 1970 MessageLoop::current()->Run(); |
2003 | 1971 |
2004 EXPECT_EQ(1, d.on_certificate_requested_count()); | 1972 EXPECT_EQ(1, d.on_certificate_requested_count()); |
2005 EXPECT_FALSE(d.received_data_before_response()); | 1973 EXPECT_FALSE(d.received_data_before_response()); |
2006 EXPECT_EQ(0, d.bytes_received()); | 1974 EXPECT_EQ(0, d.bytes_received()); |
2007 | 1975 |
(...skipping 16 matching lines...) Expand all Loading... | |
2024 TestServer::HTTPSOptions https_options; | 1992 TestServer::HTTPSOptions https_options; |
2025 https_options.record_resume = true; | 1993 https_options.record_resume = true; |
2026 TestServer test_server(https_options, | 1994 TestServer test_server(https_options, |
2027 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 1995 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
2028 ASSERT_TRUE(test_server.Start()); | 1996 ASSERT_TRUE(test_server.Start()); |
2029 | 1997 |
2030 SSLClientSocket::ClearSessionCache(); | 1998 SSLClientSocket::ClearSessionCache(); |
2031 | 1999 |
2032 { | 2000 { |
2033 TestDelegate d; | 2001 TestDelegate d; |
2034 URLRequest r(test_server.GetURL("ssl-session-cache"), &d); | 2002 URLRequest r( |
2035 r.set_context(&default_context_); | 2003 test_server.GetURL("ssl-session-cache"), &d, &default_context_); |
2036 | 2004 |
2037 r.Start(); | 2005 r.Start(); |
2038 EXPECT_TRUE(r.is_pending()); | 2006 EXPECT_TRUE(r.is_pending()); |
2039 | 2007 |
2040 MessageLoop::current()->Run(); | 2008 MessageLoop::current()->Run(); |
2041 | 2009 |
2042 EXPECT_EQ(1, d.response_started_count()); | 2010 EXPECT_EQ(1, d.response_started_count()); |
2043 } | 2011 } |
2044 | 2012 |
2045 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 2013 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> |
2046 CloseAllConnections(); | 2014 CloseAllConnections(); |
2047 | 2015 |
2048 { | 2016 { |
2049 TestDelegate d; | 2017 TestDelegate d; |
2050 URLRequest r(test_server.GetURL("ssl-session-cache"), &d); | 2018 URLRequest r( |
2051 r.set_context(&default_context_); | 2019 test_server.GetURL("ssl-session-cache"), &d, &default_context_); |
2052 | 2020 |
2053 r.Start(); | 2021 r.Start(); |
2054 EXPECT_TRUE(r.is_pending()); | 2022 EXPECT_TRUE(r.is_pending()); |
2055 | 2023 |
2056 MessageLoop::current()->Run(); | 2024 MessageLoop::current()->Run(); |
2057 | 2025 |
2058 // The response will look like; | 2026 // The response will look like; |
2059 // insert abc | 2027 // insert abc |
2060 // lookup abc | 2028 // lookup abc |
2061 // insert xyz | 2029 // insert xyz |
(...skipping 29 matching lines...) Expand all Loading... | |
2091 TestServer::HTTPSOptions https_options; | 2059 TestServer::HTTPSOptions https_options; |
2092 https_options.record_resume = true; | 2060 https_options.record_resume = true; |
2093 TestServer test_server(https_options, | 2061 TestServer test_server(https_options, |
2094 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 2062 FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
2095 ASSERT_TRUE(test_server.Start()); | 2063 ASSERT_TRUE(test_server.Start()); |
2096 | 2064 |
2097 SSLClientSocket::ClearSessionCache(); | 2065 SSLClientSocket::ClearSessionCache(); |
2098 | 2066 |
2099 { | 2067 { |
2100 TestDelegate d; | 2068 TestDelegate d; |
2101 URLRequest r(test_server.GetURL("ssl-session-cache"), &d); | 2069 URLRequest r( |
2102 r.set_context(&default_context_); | 2070 test_server.GetURL("ssl-session-cache"), &d, &default_context_); |
2103 | 2071 |
2104 r.Start(); | 2072 r.Start(); |
2105 EXPECT_TRUE(r.is_pending()); | 2073 EXPECT_TRUE(r.is_pending()); |
2106 | 2074 |
2107 MessageLoop::current()->Run(); | 2075 MessageLoop::current()->Run(); |
2108 | 2076 |
2109 EXPECT_EQ(1, d.response_started_count()); | 2077 EXPECT_EQ(1, d.response_started_count()); |
2110 } | 2078 } |
2111 | 2079 |
2112 // Now create a new HttpCache with a different ssl_session_cache_shard value. | 2080 // Now create a new HttpCache with a different ssl_session_cache_shard value. |
2113 HttpNetworkSession::Params params; | 2081 HttpNetworkSession::Params params; |
2114 params.host_resolver = default_context_.host_resolver(); | 2082 params.host_resolver = default_context_.host_resolver(); |
2115 params.cert_verifier = default_context_.cert_verifier(); | 2083 params.cert_verifier = default_context_.cert_verifier(); |
2116 params.proxy_service = default_context_.proxy_service(); | 2084 params.proxy_service = default_context_.proxy_service(); |
2117 params.ssl_config_service = default_context_.ssl_config_service(); | 2085 params.ssl_config_service = default_context_.ssl_config_service(); |
2118 params.http_auth_handler_factory = | 2086 params.http_auth_handler_factory = |
2119 default_context_.http_auth_handler_factory(); | 2087 default_context_.http_auth_handler_factory(); |
2120 params.network_delegate = default_context_.network_delegate(); | 2088 params.network_delegate = default_context_.network_delegate(); |
2121 params.http_server_properties = default_context_.http_server_properties(); | 2089 params.http_server_properties = default_context_.http_server_properties(); |
2122 params.ssl_session_cache_shard = "alternate"; | 2090 params.ssl_session_cache_shard = "alternate"; |
2123 | 2091 |
2124 scoped_ptr<net::HttpCache> cache(new net::HttpCache( | 2092 scoped_ptr<net::HttpCache> cache(new net::HttpCache( |
2125 new net::HttpNetworkSession(params), | 2093 new net::HttpNetworkSession(params), |
2126 net::HttpCache::DefaultBackend::InMemory(0))); | 2094 net::HttpCache::DefaultBackend::InMemory(0))); |
2127 | 2095 |
2128 default_context_.set_http_transaction_factory(cache.get()); | 2096 default_context_.set_http_transaction_factory(cache.get()); |
2129 | 2097 |
2130 { | 2098 { |
2131 TestDelegate d; | 2099 TestDelegate d; |
2132 URLRequest r(test_server.GetURL("ssl-session-cache"), &d); | 2100 URLRequest r( |
2133 r.set_context(&default_context_); | 2101 test_server.GetURL("ssl-session-cache"), &d, &default_context_); |
2134 | 2102 |
2135 r.Start(); | 2103 r.Start(); |
2136 EXPECT_TRUE(r.is_pending()); | 2104 EXPECT_TRUE(r.is_pending()); |
2137 | 2105 |
2138 MessageLoop::current()->Run(); | 2106 MessageLoop::current()->Run(); |
2139 | 2107 |
2140 // The response will look like; | 2108 // The response will look like; |
2141 // insert abc | 2109 // insert abc |
2142 // insert xyz | 2110 // insert xyz |
2143 // | 2111 // |
(...skipping 16 matching lines...) Expand all Loading... | |
2160 } else { | 2128 } else { |
2161 EXPECT_NE(session_id, parts[1]); | 2129 EXPECT_NE(session_id, parts[1]); |
2162 } | 2130 } |
2163 } | 2131 } |
2164 } | 2132 } |
2165 } | 2133 } |
2166 | 2134 |
2167 TEST_F(URLRequestTestHTTP, CancelTest) { | 2135 TEST_F(URLRequestTestHTTP, CancelTest) { |
2168 TestDelegate d; | 2136 TestDelegate d; |
2169 { | 2137 { |
2170 URLRequest r(GURL("http://www.google.com/"), &d); | 2138 URLRequest r(GURL("http://www.google.com/"), &d, &default_context_); |
2171 r.set_context(&default_context_); | |
2172 | 2139 |
2173 r.Start(); | 2140 r.Start(); |
2174 EXPECT_TRUE(r.is_pending()); | 2141 EXPECT_TRUE(r.is_pending()); |
2175 | 2142 |
2176 r.Cancel(); | 2143 r.Cancel(); |
2177 | 2144 |
2178 MessageLoop::current()->Run(); | 2145 MessageLoop::current()->Run(); |
2179 | 2146 |
2180 // We expect to receive OnResponseStarted even though the request has been | 2147 // We expect to receive OnResponseStarted even though the request has been |
2181 // cancelled. | 2148 // cancelled. |
2182 EXPECT_EQ(1, d.response_started_count()); | 2149 EXPECT_EQ(1, d.response_started_count()); |
2183 EXPECT_EQ(0, d.bytes_received()); | 2150 EXPECT_EQ(0, d.bytes_received()); |
2184 EXPECT_FALSE(d.received_data_before_response()); | 2151 EXPECT_FALSE(d.received_data_before_response()); |
2185 } | 2152 } |
2186 } | 2153 } |
2187 | 2154 |
2188 TEST_F(URLRequestTestHTTP, CancelTest2) { | 2155 TEST_F(URLRequestTestHTTP, CancelTest2) { |
2189 ASSERT_TRUE(test_server_.Start()); | 2156 ASSERT_TRUE(test_server_.Start()); |
2190 | 2157 |
2191 TestDelegate d; | 2158 TestDelegate d; |
2192 { | 2159 { |
2193 URLRequest r(test_server_.GetURL(""), &d); | 2160 URLRequest r(test_server_.GetURL(""), &d, &default_context_); |
2194 r.set_context(&default_context_); | |
2195 | 2161 |
2196 d.set_cancel_in_response_started(true); | 2162 d.set_cancel_in_response_started(true); |
2197 | 2163 |
2198 r.Start(); | 2164 r.Start(); |
2199 EXPECT_TRUE(r.is_pending()); | 2165 EXPECT_TRUE(r.is_pending()); |
2200 | 2166 |
2201 MessageLoop::current()->Run(); | 2167 MessageLoop::current()->Run(); |
2202 | 2168 |
2203 EXPECT_EQ(1, d.response_started_count()); | 2169 EXPECT_EQ(1, d.response_started_count()); |
2204 EXPECT_EQ(0, d.bytes_received()); | 2170 EXPECT_EQ(0, d.bytes_received()); |
2205 EXPECT_FALSE(d.received_data_before_response()); | 2171 EXPECT_FALSE(d.received_data_before_response()); |
2206 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 2172 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
2207 } | 2173 } |
2208 } | 2174 } |
2209 | 2175 |
2210 TEST_F(URLRequestTestHTTP, CancelTest3) { | 2176 TEST_F(URLRequestTestHTTP, CancelTest3) { |
2211 ASSERT_TRUE(test_server_.Start()); | 2177 ASSERT_TRUE(test_server_.Start()); |
2212 | 2178 |
2213 TestDelegate d; | 2179 TestDelegate d; |
2214 { | 2180 { |
2215 URLRequest r(test_server_.GetURL(""), &d); | 2181 URLRequest r(test_server_.GetURL(""), &d, &default_context_); |
2216 r.set_context(&default_context_); | |
2217 | 2182 |
2218 d.set_cancel_in_received_data(true); | 2183 d.set_cancel_in_received_data(true); |
2219 | 2184 |
2220 r.Start(); | 2185 r.Start(); |
2221 EXPECT_TRUE(r.is_pending()); | 2186 EXPECT_TRUE(r.is_pending()); |
2222 | 2187 |
2223 MessageLoop::current()->Run(); | 2188 MessageLoop::current()->Run(); |
2224 | 2189 |
2225 EXPECT_EQ(1, d.response_started_count()); | 2190 EXPECT_EQ(1, d.response_started_count()); |
2226 // There is no guarantee about how much data was received | 2191 // There is no guarantee about how much data was received |
2227 // before the cancel was issued. It could have been 0 bytes, | 2192 // before the cancel was issued. It could have been 0 bytes, |
2228 // or it could have been all the bytes. | 2193 // or it could have been all the bytes. |
2229 // EXPECT_EQ(0, d.bytes_received()); | 2194 // EXPECT_EQ(0, d.bytes_received()); |
2230 EXPECT_FALSE(d.received_data_before_response()); | 2195 EXPECT_FALSE(d.received_data_before_response()); |
2231 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 2196 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
2232 } | 2197 } |
2233 } | 2198 } |
2234 | 2199 |
2235 TEST_F(URLRequestTestHTTP, CancelTest4) { | 2200 TEST_F(URLRequestTestHTTP, CancelTest4) { |
2236 ASSERT_TRUE(test_server_.Start()); | 2201 ASSERT_TRUE(test_server_.Start()); |
2237 | 2202 |
2238 TestDelegate d; | 2203 TestDelegate d; |
2239 { | 2204 { |
2240 URLRequest r(test_server_.GetURL(""), &d); | 2205 URLRequest r(test_server_.GetURL(""), &d, &default_context_); |
2241 r.set_context(&default_context_); | |
2242 | 2206 |
2243 r.Start(); | 2207 r.Start(); |
2244 EXPECT_TRUE(r.is_pending()); | 2208 EXPECT_TRUE(r.is_pending()); |
2245 | 2209 |
2246 // The request will be implicitly canceled when it is destroyed. The | 2210 // The request will be implicitly canceled when it is destroyed. The |
2247 // test delegate must not post a quit message when this happens because | 2211 // test delegate must not post a quit message when this happens because |
2248 // this test doesn't actually have a message loop. The quit message would | 2212 // this test doesn't actually have a message loop. The quit message would |
2249 // get put on this thread's message queue and the next test would exit | 2213 // get put on this thread's message queue and the next test would exit |
2250 // early, causing problems. | 2214 // early, causing problems. |
2251 d.set_quit_on_complete(false); | 2215 d.set_quit_on_complete(false); |
2252 } | 2216 } |
2253 // expect things to just cleanup properly. | 2217 // expect things to just cleanup properly. |
2254 | 2218 |
2255 // we won't actually get a received reponse here because we've never run the | 2219 // we won't actually get a received reponse here because we've never run the |
2256 // message loop | 2220 // message loop |
2257 EXPECT_FALSE(d.received_data_before_response()); | 2221 EXPECT_FALSE(d.received_data_before_response()); |
2258 EXPECT_EQ(0, d.bytes_received()); | 2222 EXPECT_EQ(0, d.bytes_received()); |
2259 } | 2223 } |
2260 | 2224 |
2261 TEST_F(URLRequestTestHTTP, CancelTest5) { | 2225 TEST_F(URLRequestTestHTTP, CancelTest5) { |
2262 ASSERT_TRUE(test_server_.Start()); | 2226 ASSERT_TRUE(test_server_.Start()); |
2263 | 2227 |
2264 // populate cache | 2228 // populate cache |
2265 { | 2229 { |
2266 TestDelegate d; | 2230 TestDelegate d; |
2267 URLRequest r(test_server_.GetURL("cachetime"), &d); | 2231 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); |
2268 r.set_context(&default_context_); | |
2269 r.Start(); | 2232 r.Start(); |
2270 MessageLoop::current()->Run(); | 2233 MessageLoop::current()->Run(); |
2271 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2234 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
2272 } | 2235 } |
2273 | 2236 |
2274 // cancel read from cache (see bug 990242) | 2237 // cancel read from cache (see bug 990242) |
2275 { | 2238 { |
2276 TestDelegate d; | 2239 TestDelegate d; |
2277 URLRequest r(test_server_.GetURL("cachetime"), &d); | 2240 URLRequest r(test_server_.GetURL("cachetime"), &d, &default_context_); |
2278 r.set_context(&default_context_); | |
2279 r.Start(); | 2241 r.Start(); |
2280 r.Cancel(); | 2242 r.Cancel(); |
2281 MessageLoop::current()->Run(); | 2243 MessageLoop::current()->Run(); |
2282 | 2244 |
2283 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); | 2245 EXPECT_EQ(URLRequestStatus::CANCELED, r.status().status()); |
2284 EXPECT_EQ(1, d.response_started_count()); | 2246 EXPECT_EQ(1, d.response_started_count()); |
2285 EXPECT_EQ(0, d.bytes_received()); | 2247 EXPECT_EQ(0, d.bytes_received()); |
2286 EXPECT_FALSE(d.received_data_before_response()); | 2248 EXPECT_FALSE(d.received_data_before_response()); |
2287 } | 2249 } |
2288 } | 2250 } |
2289 | 2251 |
2290 TEST_F(URLRequestTestHTTP, PostTest) { | 2252 TEST_F(URLRequestTestHTTP, PostTest) { |
2291 ASSERT_TRUE(test_server_.Start()); | 2253 ASSERT_TRUE(test_server_.Start()); |
2292 HTTPUploadDataOperationTest("POST"); | 2254 HTTPUploadDataOperationTest("POST"); |
2293 } | 2255 } |
2294 | 2256 |
2295 TEST_F(URLRequestTestHTTP, PutTest) { | 2257 TEST_F(URLRequestTestHTTP, PutTest) { |
2296 ASSERT_TRUE(test_server_.Start()); | 2258 ASSERT_TRUE(test_server_.Start()); |
2297 HTTPUploadDataOperationTest("PUT"); | 2259 HTTPUploadDataOperationTest("PUT"); |
2298 } | 2260 } |
2299 | 2261 |
2300 TEST_F(URLRequestTestHTTP, PostEmptyTest) { | 2262 TEST_F(URLRequestTestHTTP, PostEmptyTest) { |
2301 ASSERT_TRUE(test_server_.Start()); | 2263 ASSERT_TRUE(test_server_.Start()); |
2302 | 2264 |
2303 TestDelegate d; | 2265 TestDelegate d; |
2304 { | 2266 { |
2305 URLRequest r(test_server_.GetURL("echo"), &d); | 2267 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
2306 r.set_context(&default_context_); | |
2307 r.set_method("POST"); | 2268 r.set_method("POST"); |
2308 | 2269 |
2309 r.Start(); | 2270 r.Start(); |
2310 EXPECT_TRUE(r.is_pending()); | 2271 EXPECT_TRUE(r.is_pending()); |
2311 | 2272 |
2312 MessageLoop::current()->Run(); | 2273 MessageLoop::current()->Run(); |
2313 | 2274 |
2314 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << | 2275 ASSERT_EQ(1, d.response_started_count()) << "request failed: " << |
2315 (int) r.status().status() << ", error: " << r.status().error(); | 2276 (int) r.status().status() << ", error: " << r.status().error(); |
2316 | 2277 |
2317 EXPECT_FALSE(d.received_data_before_response()); | 2278 EXPECT_FALSE(d.received_data_before_response()); |
2318 EXPECT_TRUE(d.data_received().empty()); | 2279 EXPECT_TRUE(d.data_received().empty()); |
2319 } | 2280 } |
2320 } | 2281 } |
2321 | 2282 |
2322 TEST_F(URLRequestTestHTTP, PostFileTest) { | 2283 TEST_F(URLRequestTestHTTP, PostFileTest) { |
2323 ASSERT_TRUE(test_server_.Start()); | 2284 ASSERT_TRUE(test_server_.Start()); |
2324 | 2285 |
2325 TestDelegate d; | 2286 TestDelegate d; |
2326 { | 2287 { |
2327 URLRequest r(test_server_.GetURL("echo"), &d); | 2288 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
2328 r.set_context(&default_context_); | |
2329 r.set_method("POST"); | 2289 r.set_method("POST"); |
2330 | 2290 |
2331 FilePath dir; | 2291 FilePath dir; |
2332 PathService::Get(base::DIR_EXE, &dir); | 2292 PathService::Get(base::DIR_EXE, &dir); |
2333 file_util::SetCurrentDirectory(dir); | 2293 file_util::SetCurrentDirectory(dir); |
2334 | 2294 |
2335 scoped_refptr<UploadData> upload_data(new UploadData); | 2295 scoped_refptr<UploadData> upload_data(new UploadData); |
2336 | 2296 |
2337 FilePath path; | 2297 FilePath path; |
2338 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 2298 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2371 ASSERT_EQ(size, d.bytes_received()); | 2331 ASSERT_EQ(size, d.bytes_received()); |
2372 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); | 2332 EXPECT_EQ(0, memcmp(d.data_received().c_str(), buf.get(), size)); |
2373 } | 2333 } |
2374 } | 2334 } |
2375 | 2335 |
2376 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 2336 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
2377 ASSERT_TRUE(test_server_.Start()); | 2337 ASSERT_TRUE(test_server_.Start()); |
2378 | 2338 |
2379 TestDelegate d; | 2339 TestDelegate d; |
2380 { | 2340 { |
2381 URLRequest r(test_server_.GetURL("echo"), &d); | 2341 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
2382 r.set_context(&default_context_); | |
2383 r.EnableChunkedUpload(); | 2342 r.EnableChunkedUpload(); |
2384 r.set_method("POST"); | 2343 r.set_method("POST"); |
2385 AddChunksToUpload(&r); | 2344 AddChunksToUpload(&r); |
2386 r.Start(); | 2345 r.Start(); |
2387 EXPECT_TRUE(r.is_pending()); | 2346 EXPECT_TRUE(r.is_pending()); |
2388 | 2347 |
2389 MessageLoop::current()->Run(); | 2348 MessageLoop::current()->Run(); |
2390 | 2349 |
2391 VerifyReceivedDataMatchesChunks(&r, &d); | 2350 VerifyReceivedDataMatchesChunks(&r, &d); |
2392 } | 2351 } |
2393 } | 2352 } |
2394 | 2353 |
2395 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 2354 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
2396 ASSERT_TRUE(test_server_.Start()); | 2355 ASSERT_TRUE(test_server_.Start()); |
2397 | 2356 |
2398 TestDelegate d; | 2357 TestDelegate d; |
2399 { | 2358 { |
2400 URLRequest r(test_server_.GetURL("echo"), &d); | 2359 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
2401 r.set_context(&default_context_); | |
2402 r.EnableChunkedUpload(); | 2360 r.EnableChunkedUpload(); |
2403 r.set_method("POST"); | 2361 r.set_method("POST"); |
2404 r.Start(); | 2362 r.Start(); |
2405 EXPECT_TRUE(r.is_pending()); | 2363 EXPECT_TRUE(r.is_pending()); |
2406 | 2364 |
2407 MessageLoop::current()->RunAllPending(); | 2365 MessageLoop::current()->RunAllPending(); |
2408 AddChunksToUpload(&r); | 2366 AddChunksToUpload(&r); |
2409 MessageLoop::current()->Run(); | 2367 MessageLoop::current()->Run(); |
2410 | 2368 |
2411 VerifyReceivedDataMatchesChunks(&r, &d); | 2369 VerifyReceivedDataMatchesChunks(&r, &d); |
2412 } | 2370 } |
2413 } | 2371 } |
2414 | 2372 |
2415 TEST_F(URLRequestTest, AboutBlankTest) { | 2373 TEST_F(URLRequestTest, AboutBlankTest) { |
2416 TestDelegate d; | 2374 TestDelegate d; |
2417 { | 2375 { |
2418 URLRequest r(GURL("about:blank"), &d); | 2376 URLRequest r(GURL("about:blank"), &d, &default_context_); |
2419 r.set_context(&default_context_); | |
2420 | 2377 |
2421 r.Start(); | 2378 r.Start(); |
2422 EXPECT_TRUE(r.is_pending()); | 2379 EXPECT_TRUE(r.is_pending()); |
2423 | 2380 |
2424 MessageLoop::current()->Run(); | 2381 MessageLoop::current()->Run(); |
2425 | 2382 |
2426 EXPECT_TRUE(!r.is_pending()); | 2383 EXPECT_TRUE(!r.is_pending()); |
2427 EXPECT_FALSE(d.received_data_before_response()); | 2384 EXPECT_FALSE(d.received_data_before_response()); |
2428 EXPECT_EQ(d.bytes_received(), 0); | 2385 EXPECT_EQ(d.bytes_received(), 0); |
2429 EXPECT_EQ("", r.GetSocketAddress().host()); | 2386 EXPECT_EQ("", r.GetSocketAddress().host()); |
(...skipping 18 matching lines...) Expand all Loading... | |
2448 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" | 2405 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" |
2449 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" | 2406 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" |
2450 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" | 2407 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" |
2451 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" | 2408 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" |
2452 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" | 2409 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" |
2453 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" | 2410 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" |
2454 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" | 2411 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" |
2455 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" | 2412 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" |
2456 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" | 2413 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" |
2457 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), | 2414 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), |
2458 &d); | 2415 &d, |
2459 r.set_context(&default_context_); | 2416 &default_context_); |
2460 | 2417 |
2461 r.Start(); | 2418 r.Start(); |
2462 EXPECT_TRUE(r.is_pending()); | 2419 EXPECT_TRUE(r.is_pending()); |
2463 | 2420 |
2464 MessageLoop::current()->Run(); | 2421 MessageLoop::current()->Run(); |
2465 | 2422 |
2466 EXPECT_TRUE(!r.is_pending()); | 2423 EXPECT_TRUE(!r.is_pending()); |
2467 EXPECT_FALSE(d.received_data_before_response()); | 2424 EXPECT_FALSE(d.received_data_before_response()); |
2468 EXPECT_EQ(d.bytes_received(), 911); | 2425 EXPECT_EQ(d.bytes_received(), 911); |
2469 EXPECT_EQ("", r.GetSocketAddress().host()); | 2426 EXPECT_EQ("", r.GetSocketAddress().host()); |
2470 EXPECT_EQ(0, r.GetSocketAddress().port()); | 2427 EXPECT_EQ(0, r.GetSocketAddress().port()); |
2471 } | 2428 } |
2472 } | 2429 } |
2473 | 2430 |
2474 TEST_F(URLRequestTest, FileTest) { | 2431 TEST_F(URLRequestTest, FileTest) { |
2475 FilePath app_path; | 2432 FilePath app_path; |
2476 PathService::Get(base::FILE_EXE, &app_path); | 2433 PathService::Get(base::FILE_EXE, &app_path); |
2477 GURL app_url = FilePathToFileURL(app_path); | 2434 GURL app_url = FilePathToFileURL(app_path); |
2478 | 2435 |
2479 TestDelegate d; | 2436 TestDelegate d; |
2480 { | 2437 { |
2481 URLRequest r(app_url, &d); | 2438 URLRequest r(app_url, &d, &default_context_); |
2482 r.set_context(&default_context_); | |
2483 | 2439 |
2484 r.Start(); | 2440 r.Start(); |
2485 EXPECT_TRUE(r.is_pending()); | 2441 EXPECT_TRUE(r.is_pending()); |
2486 | 2442 |
2487 MessageLoop::current()->Run(); | 2443 MessageLoop::current()->Run(); |
2488 | 2444 |
2489 int64 file_size = -1; | 2445 int64 file_size = -1; |
2490 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); | 2446 EXPECT_TRUE(file_util::GetFileSize(app_path, &file_size)); |
2491 | 2447 |
2492 EXPECT_TRUE(!r.is_pending()); | 2448 EXPECT_TRUE(!r.is_pending()); |
(...skipping 19 matching lines...) Expand all Loading... | |
2512 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 2468 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
2513 | 2469 |
2514 const size_t first_byte_position = 500; | 2470 const size_t first_byte_position = 500; |
2515 const size_t last_byte_position = buffer_size - first_byte_position; | 2471 const size_t last_byte_position = buffer_size - first_byte_position; |
2516 const size_t content_length = last_byte_position - first_byte_position + 1; | 2472 const size_t content_length = last_byte_position - first_byte_position + 1; |
2517 std::string partial_buffer_string(buffer.get() + first_byte_position, | 2473 std::string partial_buffer_string(buffer.get() + first_byte_position, |
2518 buffer.get() + last_byte_position + 1); | 2474 buffer.get() + last_byte_position + 1); |
2519 | 2475 |
2520 TestDelegate d; | 2476 TestDelegate d; |
2521 { | 2477 { |
2522 URLRequest r(temp_url, &d); | 2478 URLRequest r(temp_url, &d, &default_context_); |
2523 r.set_context(&default_context_); | |
2524 | 2479 |
2525 HttpRequestHeaders headers; | 2480 HttpRequestHeaders headers; |
2526 headers.SetHeader(HttpRequestHeaders::kRange, | 2481 headers.SetHeader(HttpRequestHeaders::kRange, |
2527 base::StringPrintf( | 2482 base::StringPrintf( |
2528 "bytes=%" PRIuS "-%" PRIuS, | 2483 "bytes=%" PRIuS "-%" PRIuS, |
2529 first_byte_position, last_byte_position)); | 2484 first_byte_position, last_byte_position)); |
2530 r.SetExtraRequestHeaders(headers); | 2485 r.SetExtraRequestHeaders(headers); |
2531 r.Start(); | 2486 r.Start(); |
2532 EXPECT_TRUE(r.is_pending()); | 2487 EXPECT_TRUE(r.is_pending()); |
2533 | 2488 |
(...skipping 23 matching lines...) Expand all Loading... | |
2557 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 2512 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
2558 | 2513 |
2559 const size_t first_byte_position = 500; | 2514 const size_t first_byte_position = 500; |
2560 const size_t last_byte_position = buffer_size - 1; | 2515 const size_t last_byte_position = buffer_size - 1; |
2561 const size_t content_length = last_byte_position - first_byte_position + 1; | 2516 const size_t content_length = last_byte_position - first_byte_position + 1; |
2562 std::string partial_buffer_string(buffer.get() + first_byte_position, | 2517 std::string partial_buffer_string(buffer.get() + first_byte_position, |
2563 buffer.get() + last_byte_position + 1); | 2518 buffer.get() + last_byte_position + 1); |
2564 | 2519 |
2565 TestDelegate d; | 2520 TestDelegate d; |
2566 { | 2521 { |
2567 URLRequest r(temp_url, &d); | 2522 URLRequest r(temp_url, &d, &default_context_); |
2568 r.set_context(&default_context_); | |
2569 | 2523 |
2570 HttpRequestHeaders headers; | 2524 HttpRequestHeaders headers; |
2571 headers.SetHeader(HttpRequestHeaders::kRange, | 2525 headers.SetHeader(HttpRequestHeaders::kRange, |
2572 base::StringPrintf("bytes=%" PRIuS "-", | 2526 base::StringPrintf("bytes=%" PRIuS "-", |
2573 first_byte_position)); | 2527 first_byte_position)); |
2574 r.SetExtraRequestHeaders(headers); | 2528 r.SetExtraRequestHeaders(headers); |
2575 r.Start(); | 2529 r.Start(); |
2576 EXPECT_TRUE(r.is_pending()); | 2530 EXPECT_TRUE(r.is_pending()); |
2577 | 2531 |
2578 MessageLoop::current()->Run(); | 2532 MessageLoop::current()->Run(); |
(...skipping 16 matching lines...) Expand all Loading... | |
2595 FilePath temp_path; | 2549 FilePath temp_path; |
2596 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); | 2550 EXPECT_TRUE(file_util::CreateTemporaryFile(&temp_path)); |
2597 GURL temp_url = FilePathToFileURL(temp_path); | 2551 GURL temp_url = FilePathToFileURL(temp_path); |
2598 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); | 2552 EXPECT_TRUE(file_util::WriteFile(temp_path, buffer.get(), buffer_size)); |
2599 | 2553 |
2600 int64 file_size; | 2554 int64 file_size; |
2601 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); | 2555 EXPECT_TRUE(file_util::GetFileSize(temp_path, &file_size)); |
2602 | 2556 |
2603 TestDelegate d; | 2557 TestDelegate d; |
2604 { | 2558 { |
2605 URLRequest r(temp_url, &d); | 2559 URLRequest r(temp_url, &d, &default_context_); |
2606 r.set_context(&default_context_); | |
2607 | 2560 |
2608 HttpRequestHeaders headers; | 2561 HttpRequestHeaders headers; |
2609 headers.SetHeader(HttpRequestHeaders::kRange, | 2562 headers.SetHeader(HttpRequestHeaders::kRange, |
2610 "bytes=0-0,10-200,200-300"); | 2563 "bytes=0-0,10-200,200-300"); |
2611 r.SetExtraRequestHeaders(headers); | 2564 r.SetExtraRequestHeaders(headers); |
2612 r.Start(); | 2565 r.Start(); |
2613 EXPECT_TRUE(r.is_pending()); | 2566 EXPECT_TRUE(r.is_pending()); |
2614 | 2567 |
2615 MessageLoop::current()->Run(); | 2568 MessageLoop::current()->Run(); |
2616 EXPECT_TRUE(d.request_failed()); | 2569 EXPECT_TRUE(d.request_failed()); |
2617 } | 2570 } |
2618 | 2571 |
2619 EXPECT_TRUE(file_util::Delete(temp_path, false)); | 2572 EXPECT_TRUE(file_util::Delete(temp_path, false)); |
2620 } | 2573 } |
2621 | 2574 |
2622 TEST_F(URLRequestTest, InvalidUrlTest) { | 2575 TEST_F(URLRequestTest, InvalidUrlTest) { |
2623 TestDelegate d; | 2576 TestDelegate d; |
2624 { | 2577 { |
2625 URLRequest r(GURL("invalid url"), &d); | 2578 URLRequest r(GURL("invalid url"), &d, &default_context_); |
2626 r.set_context(&default_context_); | |
2627 | 2579 |
2628 r.Start(); | 2580 r.Start(); |
2629 EXPECT_TRUE(r.is_pending()); | 2581 EXPECT_TRUE(r.is_pending()); |
2630 | 2582 |
2631 MessageLoop::current()->Run(); | 2583 MessageLoop::current()->Run(); |
2632 EXPECT_TRUE(d.request_failed()); | 2584 EXPECT_TRUE(d.request_failed()); |
2633 } | 2585 } |
2634 } | 2586 } |
2635 | 2587 |
2636 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 2588 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
2637 ASSERT_TRUE(test_server_.Start()); | 2589 ASSERT_TRUE(test_server_.Start()); |
2638 | 2590 |
2639 TestDelegate d; | 2591 TestDelegate d; |
2640 URLRequest req(test_server_.GetURL("files/with-headers.html"), &d); | 2592 URLRequest req( |
2641 req.set_context(&default_context_); | 2593 test_server_.GetURL("files/with-headers.html"), &d, &default_context_); |
2642 req.Start(); | 2594 req.Start(); |
2643 MessageLoop::current()->Run(); | 2595 MessageLoop::current()->Run(); |
2644 | 2596 |
2645 const HttpResponseHeaders* headers = req.response_headers(); | 2597 const HttpResponseHeaders* headers = req.response_headers(); |
2646 | 2598 |
2647 // Simple sanity check that response_info() accesses the same data. | 2599 // Simple sanity check that response_info() accesses the same data. |
2648 EXPECT_EQ(headers, req.response_info().headers.get()); | 2600 EXPECT_EQ(headers, req.response_info().headers.get()); |
2649 | 2601 |
2650 std::string header; | 2602 std::string header; |
2651 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 2603 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2692 EXPECT_TRUE(SUCCEEDED(result)); | 2644 EXPECT_TRUE(SUCCEEDED(result)); |
2693 result = persist->Save(lnk_path.c_str(), TRUE); | 2645 result = persist->Save(lnk_path.c_str(), TRUE); |
2694 EXPECT_TRUE(SUCCEEDED(result)); | 2646 EXPECT_TRUE(SUCCEEDED(result)); |
2695 if (persist) | 2647 if (persist) |
2696 persist->Release(); | 2648 persist->Release(); |
2697 if (shell) | 2649 if (shell) |
2698 shell->Release(); | 2650 shell->Release(); |
2699 | 2651 |
2700 TestDelegate d; | 2652 TestDelegate d; |
2701 { | 2653 { |
2702 URLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d); | 2654 URLRequest r(FilePathToFileURL(FilePath(lnk_path)), &d, &default_context_); |
2703 r.set_context(&default_context_); | |
2704 | 2655 |
2705 r.Start(); | 2656 r.Start(); |
2706 EXPECT_TRUE(r.is_pending()); | 2657 EXPECT_TRUE(r.is_pending()); |
2707 | 2658 |
2708 MessageLoop::current()->Run(); | 2659 MessageLoop::current()->Run(); |
2709 | 2660 |
2710 WIN32_FILE_ATTRIBUTE_DATA data; | 2661 WIN32_FILE_ATTRIBUTE_DATA data; |
2711 GetFileAttributesEx(app_path.value().c_str(), | 2662 GetFileAttributesEx(app_path.value().c_str(), |
2712 GetFileExInfoStandard, &data); | 2663 GetFileExInfoStandard, &data); |
2713 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, | 2664 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, |
(...skipping 17 matching lines...) Expand all Loading... | |
2731 DeleteFile(lnk_path.c_str()); | 2682 DeleteFile(lnk_path.c_str()); |
2732 CoUninitialize(); | 2683 CoUninitialize(); |
2733 } | 2684 } |
2734 #endif // defined(OS_WIN) | 2685 #endif // defined(OS_WIN) |
2735 | 2686 |
2736 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { | 2687 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { |
2737 ASSERT_TRUE(test_server_.Start()); | 2688 ASSERT_TRUE(test_server_.Start()); |
2738 | 2689 |
2739 TestDelegate d; | 2690 TestDelegate d; |
2740 URLRequest req(test_server_.GetURL( | 2691 URLRequest req(test_server_.GetURL( |
2741 "files/content-type-normalization.html"), &d); | 2692 "files/content-type-normalization.html"), &d, &default_context_); |
2742 req.set_context(&default_context_); | |
2743 req.Start(); | 2693 req.Start(); |
2744 MessageLoop::current()->Run(); | 2694 MessageLoop::current()->Run(); |
2745 | 2695 |
2746 std::string mime_type; | 2696 std::string mime_type; |
2747 req.GetMimeType(&mime_type); | 2697 req.GetMimeType(&mime_type); |
2748 EXPECT_EQ("text/html", mime_type); | 2698 EXPECT_EQ("text/html", mime_type); |
2749 | 2699 |
2750 std::string charset; | 2700 std::string charset; |
2751 req.GetCharset(&charset); | 2701 req.GetCharset(&charset); |
2752 EXPECT_EQ("utf-8", charset); | 2702 EXPECT_EQ("utf-8", charset); |
2753 req.Cancel(); | 2703 req.Cancel(); |
2754 } | 2704 } |
2755 | 2705 |
2756 TEST_F(URLRequestTest, FileDirCancelTest) { | 2706 TEST_F(URLRequestTest, FileDirCancelTest) { |
2757 // Put in mock resource provider. | 2707 // Put in mock resource provider. |
2758 NetModule::SetResourceProvider(TestNetResourceProvider); | 2708 NetModule::SetResourceProvider(TestNetResourceProvider); |
2759 | 2709 |
2760 TestDelegate d; | 2710 TestDelegate d; |
2761 { | 2711 { |
2762 FilePath file_path; | 2712 FilePath file_path; |
2763 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 2713 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
2764 file_path = file_path.Append(FILE_PATH_LITERAL("net")); | 2714 file_path = file_path.Append(FILE_PATH_LITERAL("net")); |
2765 file_path = file_path.Append(FILE_PATH_LITERAL("data")); | 2715 file_path = file_path.Append(FILE_PATH_LITERAL("data")); |
2766 | 2716 |
2767 URLRequest req(FilePathToFileURL(file_path), &d); | 2717 URLRequest req(FilePathToFileURL(file_path), &d, &default_context_); |
2768 req.set_context(&default_context_); | |
2769 req.Start(); | 2718 req.Start(); |
2770 EXPECT_TRUE(req.is_pending()); | 2719 EXPECT_TRUE(req.is_pending()); |
2771 | 2720 |
2772 d.set_cancel_in_received_data_pending(true); | 2721 d.set_cancel_in_received_data_pending(true); |
2773 | 2722 |
2774 MessageLoop::current()->Run(); | 2723 MessageLoop::current()->Run(); |
2775 } | 2724 } |
2776 | 2725 |
2777 // Take out mock resource provider. | 2726 // Take out mock resource provider. |
2778 NetModule::SetResourceProvider(NULL); | 2727 NetModule::SetResourceProvider(NULL); |
2779 } | 2728 } |
2780 | 2729 |
2781 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { | 2730 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { |
2782 // There is an implicit redirect when loading a file path that matches a | 2731 // There is an implicit redirect when loading a file path that matches a |
2783 // directory and does not end with a slash. Ensure that following such | 2732 // directory and does not end with a slash. Ensure that following such |
2784 // redirects does not crash. See http://crbug.com/18686. | 2733 // redirects does not crash. See http://crbug.com/18686. |
2785 | 2734 |
2786 FilePath path; | 2735 FilePath path; |
2787 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 2736 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
2788 path = path.Append(FILE_PATH_LITERAL("net")); | 2737 path = path.Append(FILE_PATH_LITERAL("net")); |
2789 path = path.Append(FILE_PATH_LITERAL("data")); | 2738 path = path.Append(FILE_PATH_LITERAL("data")); |
2790 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 2739 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
2791 | 2740 |
2792 TestDelegate d; | 2741 TestDelegate d; |
2793 URLRequest req(FilePathToFileURL(path), &d); | 2742 URLRequest req(FilePathToFileURL(path), &d, &default_context_); |
2794 req.set_context(&default_context_); | |
2795 req.Start(); | 2743 req.Start(); |
2796 MessageLoop::current()->Run(); | 2744 MessageLoop::current()->Run(); |
2797 | 2745 |
2798 ASSERT_EQ(1, d.received_redirect_count()); | 2746 ASSERT_EQ(1, d.received_redirect_count()); |
2799 ASSERT_LT(0, d.bytes_received()); | 2747 ASSERT_LT(0, d.bytes_received()); |
2800 ASSERT_FALSE(d.request_failed()); | 2748 ASSERT_FALSE(d.request_failed()); |
2801 ASSERT_TRUE(req.status().is_success()); | 2749 ASSERT_TRUE(req.status().is_success()); |
2802 } | 2750 } |
2803 | 2751 |
2804 #if defined(OS_WIN) | 2752 #if defined(OS_WIN) |
2805 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. | 2753 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. |
2806 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { | 2754 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { |
2807 TestDelegate d; | 2755 TestDelegate d; |
2808 URLRequest req(GURL("file:///"), &d); | 2756 URLRequest req(GURL("file:///"), &d, &default_context_); |
2809 req.set_context(&default_context_); | |
2810 req.Start(); | 2757 req.Start(); |
2811 MessageLoop::current()->Run(); | 2758 MessageLoop::current()->Run(); |
2812 | 2759 |
2813 ASSERT_EQ(1, d.received_redirect_count()); | 2760 ASSERT_EQ(1, d.received_redirect_count()); |
2814 ASSERT_FALSE(req.status().is_success()); | 2761 ASSERT_FALSE(req.status().is_success()); |
2815 } | 2762 } |
2816 #endif | 2763 #endif |
2817 | 2764 |
2818 TEST_F(URLRequestTestHTTP, RestrictRedirects) { | 2765 TEST_F(URLRequestTestHTTP, RestrictRedirects) { |
2819 ASSERT_TRUE(test_server_.Start()); | 2766 ASSERT_TRUE(test_server_.Start()); |
2820 | 2767 |
2821 TestDelegate d; | 2768 TestDelegate d; |
2822 URLRequest req(test_server_.GetURL( | 2769 URLRequest req(test_server_.GetURL( |
2823 "files/redirect-to-file.html"), &d); | 2770 "files/redirect-to-file.html"), &d, &default_context_); |
2824 req.set_context(&default_context_); | |
2825 req.Start(); | 2771 req.Start(); |
2826 MessageLoop::current()->Run(); | 2772 MessageLoop::current()->Run(); |
2827 | 2773 |
2828 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 2774 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
2829 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); | 2775 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req.status().error()); |
2830 } | 2776 } |
2831 | 2777 |
2832 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 2778 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
2833 ASSERT_TRUE(test_server_.Start()); | 2779 ASSERT_TRUE(test_server_.Start()); |
2834 | 2780 |
2835 TestDelegate d; | 2781 TestDelegate d; |
2836 URLRequest req(test_server_.GetURL( | 2782 URLRequest req(test_server_.GetURL( |
2837 "files/redirect-to-invalid-url.html"), &d); | 2783 "files/redirect-to-invalid-url.html"), &d, &default_context_); |
2838 req.set_context(&default_context_); | |
2839 req.Start(); | 2784 req.Start(); |
2840 MessageLoop::current()->Run(); | 2785 MessageLoop::current()->Run(); |
2841 | 2786 |
2842 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 2787 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
2843 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); | 2788 EXPECT_EQ(ERR_INVALID_URL, req.status().error()); |
2844 } | 2789 } |
2845 | 2790 |
2846 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 2791 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
2847 ASSERT_TRUE(test_server_.Start()); | 2792 ASSERT_TRUE(test_server_.Start()); |
2848 | 2793 |
2849 TestDelegate d; | 2794 TestDelegate d; |
2850 URLRequest req(test_server_.GetURL("echoheader?Referer"), &d); | 2795 URLRequest req( |
2851 req.set_context(&default_context_); | 2796 test_server_.GetURL("echoheader?Referer"), &d, &default_context_); |
2852 req.set_referrer("http://user:pass@foo.com/"); | 2797 req.set_referrer("http://user:pass@foo.com/"); |
2853 req.Start(); | 2798 req.Start(); |
2854 MessageLoop::current()->Run(); | 2799 MessageLoop::current()->Run(); |
2855 | 2800 |
2856 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 2801 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
2857 } | 2802 } |
2858 | 2803 |
2859 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 2804 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
2860 ASSERT_TRUE(test_server_.Start()); | 2805 ASSERT_TRUE(test_server_.Start()); |
2861 | 2806 |
2862 TestDelegate d; | 2807 TestDelegate d; |
2863 { | 2808 { |
2864 d.set_cancel_in_received_redirect(true); | 2809 d.set_cancel_in_received_redirect(true); |
2865 URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); | 2810 URLRequest req( |
2866 req.set_context(&default_context_); | 2811 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); |
2867 req.Start(); | 2812 req.Start(); |
2868 MessageLoop::current()->Run(); | 2813 MessageLoop::current()->Run(); |
2869 | 2814 |
2870 EXPECT_EQ(1, d.response_started_count()); | 2815 EXPECT_EQ(1, d.response_started_count()); |
2871 EXPECT_EQ(0, d.bytes_received()); | 2816 EXPECT_EQ(0, d.bytes_received()); |
2872 EXPECT_FALSE(d.received_data_before_response()); | 2817 EXPECT_FALSE(d.received_data_before_response()); |
2873 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 2818 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
2874 } | 2819 } |
2875 } | 2820 } |
2876 | 2821 |
2877 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 2822 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
2878 ASSERT_TRUE(test_server_.Start()); | 2823 ASSERT_TRUE(test_server_.Start()); |
2879 | 2824 |
2880 TestDelegate d; | 2825 TestDelegate d; |
2881 { | 2826 { |
2882 d.set_quit_on_redirect(true); | 2827 d.set_quit_on_redirect(true); |
2883 URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); | 2828 URLRequest req( |
2884 req.set_context(&default_context_); | 2829 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); |
2885 req.Start(); | 2830 req.Start(); |
2886 MessageLoop::current()->Run(); | 2831 MessageLoop::current()->Run(); |
2887 | 2832 |
2888 EXPECT_EQ(1, d.received_redirect_count()); | 2833 EXPECT_EQ(1, d.received_redirect_count()); |
2889 | 2834 |
2890 req.FollowDeferredRedirect(); | 2835 req.FollowDeferredRedirect(); |
2891 MessageLoop::current()->Run(); | 2836 MessageLoop::current()->Run(); |
2892 | 2837 |
2893 EXPECT_EQ(1, d.response_started_count()); | 2838 EXPECT_EQ(1, d.response_started_count()); |
2894 EXPECT_FALSE(d.received_data_before_response()); | 2839 EXPECT_FALSE(d.received_data_before_response()); |
(...skipping 11 matching lines...) Expand all Loading... | |
2906 EXPECT_EQ(contents, d.data_received()); | 2851 EXPECT_EQ(contents, d.data_received()); |
2907 } | 2852 } |
2908 } | 2853 } |
2909 | 2854 |
2910 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 2855 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
2911 ASSERT_TRUE(test_server_.Start()); | 2856 ASSERT_TRUE(test_server_.Start()); |
2912 | 2857 |
2913 TestDelegate d; | 2858 TestDelegate d; |
2914 { | 2859 { |
2915 d.set_quit_on_redirect(true); | 2860 d.set_quit_on_redirect(true); |
2916 URLRequest req(test_server_.GetURL("files/redirect-test.html"), &d); | 2861 URLRequest req( |
2917 req.set_context(&default_context_); | 2862 test_server_.GetURL("files/redirect-test.html"), &d, &default_context_); |
2918 req.Start(); | 2863 req.Start(); |
2919 MessageLoop::current()->Run(); | 2864 MessageLoop::current()->Run(); |
2920 | 2865 |
2921 EXPECT_EQ(1, d.received_redirect_count()); | 2866 EXPECT_EQ(1, d.received_redirect_count()); |
2922 | 2867 |
2923 req.Cancel(); | 2868 req.Cancel(); |
2924 MessageLoop::current()->Run(); | 2869 MessageLoop::current()->Run(); |
2925 | 2870 |
2926 EXPECT_EQ(1, d.response_started_count()); | 2871 EXPECT_EQ(1, d.response_started_count()); |
2927 EXPECT_EQ(0, d.bytes_received()); | 2872 EXPECT_EQ(0, d.bytes_received()); |
2928 EXPECT_FALSE(d.received_data_before_response()); | 2873 EXPECT_FALSE(d.received_data_before_response()); |
2929 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 2874 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
2930 } | 2875 } |
2931 } | 2876 } |
2932 | 2877 |
2933 TEST_F(URLRequestTestHTTP, VaryHeader) { | 2878 TEST_F(URLRequestTestHTTP, VaryHeader) { |
2934 ASSERT_TRUE(test_server_.Start()); | 2879 ASSERT_TRUE(test_server_.Start()); |
2935 | 2880 |
2936 // populate the cache | 2881 // populate the cache |
2937 { | 2882 { |
2938 TestDelegate d; | 2883 TestDelegate d; |
2939 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); | 2884 URLRequest req( |
2940 req.set_context(&default_context_); | 2885 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); |
2941 HttpRequestHeaders headers; | 2886 HttpRequestHeaders headers; |
2942 headers.SetHeader("foo", "1"); | 2887 headers.SetHeader("foo", "1"); |
2943 req.SetExtraRequestHeaders(headers); | 2888 req.SetExtraRequestHeaders(headers); |
2944 req.Start(); | 2889 req.Start(); |
2945 MessageLoop::current()->Run(); | 2890 MessageLoop::current()->Run(); |
2946 } | 2891 } |
2947 | 2892 |
2948 // expect a cache hit | 2893 // expect a cache hit |
2949 { | 2894 { |
2950 TestDelegate d; | 2895 TestDelegate d; |
2951 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); | 2896 URLRequest req( |
2952 req.set_context(&default_context_); | 2897 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); |
2953 HttpRequestHeaders headers; | 2898 HttpRequestHeaders headers; |
2954 headers.SetHeader("foo", "1"); | 2899 headers.SetHeader("foo", "1"); |
2955 req.SetExtraRequestHeaders(headers); | 2900 req.SetExtraRequestHeaders(headers); |
2956 req.Start(); | 2901 req.Start(); |
2957 MessageLoop::current()->Run(); | 2902 MessageLoop::current()->Run(); |
2958 | 2903 |
2959 EXPECT_TRUE(req.was_cached()); | 2904 EXPECT_TRUE(req.was_cached()); |
2960 } | 2905 } |
2961 | 2906 |
2962 // expect a cache miss | 2907 // expect a cache miss |
2963 { | 2908 { |
2964 TestDelegate d; | 2909 TestDelegate d; |
2965 URLRequest req(test_server_.GetURL("echoheadercache?foo"), &d); | 2910 URLRequest req( |
2966 req.set_context(&default_context_); | 2911 test_server_.GetURL("echoheadercache?foo"), &d, &default_context_); |
2967 HttpRequestHeaders headers; | 2912 HttpRequestHeaders headers; |
2968 headers.SetHeader("foo", "2"); | 2913 headers.SetHeader("foo", "2"); |
2969 req.SetExtraRequestHeaders(headers); | 2914 req.SetExtraRequestHeaders(headers); |
2970 req.Start(); | 2915 req.Start(); |
2971 MessageLoop::current()->Run(); | 2916 MessageLoop::current()->Run(); |
2972 | 2917 |
2973 EXPECT_FALSE(req.was_cached()); | 2918 EXPECT_FALSE(req.was_cached()); |
2974 } | 2919 } |
2975 } | 2920 } |
2976 | 2921 |
2977 TEST_F(URLRequestTestHTTP, BasicAuth) { | 2922 TEST_F(URLRequestTestHTTP, BasicAuth) { |
2978 ASSERT_TRUE(test_server_.Start()); | 2923 ASSERT_TRUE(test_server_.Start()); |
2979 | 2924 |
2980 // populate the cache | 2925 // populate the cache |
2981 { | 2926 { |
2982 TestDelegate d; | 2927 TestDelegate d; |
2983 d.set_credentials(AuthCredentials(kUser, kSecret)); | 2928 d.set_credentials(AuthCredentials(kUser, kSecret)); |
2984 | 2929 |
2985 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 2930 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); |
2986 r.set_context(&default_context_); | |
2987 r.Start(); | 2931 r.Start(); |
2988 | 2932 |
2989 MessageLoop::current()->Run(); | 2933 MessageLoop::current()->Run(); |
2990 | 2934 |
2991 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 2935 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
2992 } | 2936 } |
2993 | 2937 |
2994 // repeat request with end-to-end validation. since auth-basic results in a | 2938 // repeat request with end-to-end validation. since auth-basic results in a |
2995 // cachable page, we expect this test to result in a 304. in which case, the | 2939 // cachable page, we expect this test to result in a 304. in which case, the |
2996 // response should be fetched from the cache. | 2940 // response should be fetched from the cache. |
2997 { | 2941 { |
2998 TestDelegate d; | 2942 TestDelegate d; |
2999 d.set_credentials(AuthCredentials(kUser, kSecret)); | 2943 d.set_credentials(AuthCredentials(kUser, kSecret)); |
3000 | 2944 |
3001 URLRequest r(test_server_.GetURL("auth-basic"), &d); | 2945 URLRequest r(test_server_.GetURL("auth-basic"), &d, &default_context_); |
3002 r.set_context(&default_context_); | |
3003 r.set_load_flags(LOAD_VALIDATE_CACHE); | 2946 r.set_load_flags(LOAD_VALIDATE_CACHE); |
3004 r.Start(); | 2947 r.Start(); |
3005 | 2948 |
3006 MessageLoop::current()->Run(); | 2949 MessageLoop::current()->Run(); |
3007 | 2950 |
3008 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 2951 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
3009 | 2952 |
3010 // Should be the same cached document. | 2953 // Should be the same cached document. |
3011 EXPECT_TRUE(r.was_cached()); | 2954 EXPECT_TRUE(r.was_cached()); |
3012 } | 2955 } |
(...skipping 11 matching lines...) Expand all Loading... | |
3024 // Verify that when the transaction is restarted, it includes the new cookie. | 2967 // Verify that when the transaction is restarted, it includes the new cookie. |
3025 { | 2968 { |
3026 TestNetworkDelegate network_delegate; // must outlive URLRequest | 2969 TestNetworkDelegate network_delegate; // must outlive URLRequest |
3027 TestURLRequestContext context(true); | 2970 TestURLRequestContext context(true); |
3028 context.set_network_delegate(&network_delegate); | 2971 context.set_network_delegate(&network_delegate); |
3029 context.Init(); | 2972 context.Init(); |
3030 | 2973 |
3031 TestDelegate d; | 2974 TestDelegate d; |
3032 d.set_credentials(AuthCredentials(kUser, kSecret)); | 2975 d.set_credentials(AuthCredentials(kUser, kSecret)); |
3033 | 2976 |
3034 URLRequest r(url_requiring_auth, &d); | 2977 URLRequest r(url_requiring_auth, &d, &context); |
3035 r.set_context(&context); | |
3036 r.Start(); | 2978 r.Start(); |
3037 | 2979 |
3038 MessageLoop::current()->Run(); | 2980 MessageLoop::current()->Run(); |
3039 | 2981 |
3040 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 2982 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
3041 | 2983 |
3042 // Make sure we sent the cookie in the restarted transaction. | 2984 // Make sure we sent the cookie in the restarted transaction. |
3043 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 2985 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
3044 != std::string::npos); | 2986 != std::string::npos); |
3045 } | 2987 } |
3046 | 2988 |
3047 // Same test as above, except this time the restart is initiated earlier | 2989 // Same test as above, except this time the restart is initiated earlier |
3048 // (without user intervention since identity is embedded in the URL). | 2990 // (without user intervention since identity is embedded in the URL). |
3049 { | 2991 { |
3050 TestNetworkDelegate network_delegate; // must outlive URLRequest | 2992 TestNetworkDelegate network_delegate; // must outlive URLRequest |
3051 TestURLRequestContext context(true); | 2993 TestURLRequestContext context(true); |
3052 context.set_network_delegate(&network_delegate); | 2994 context.set_network_delegate(&network_delegate); |
3053 context.Init(); | 2995 context.Init(); |
3054 | 2996 |
3055 TestDelegate d; | 2997 TestDelegate d; |
3056 | 2998 |
3057 GURL::Replacements replacements; | 2999 GURL::Replacements replacements; |
3058 std::string username("user2"); | 3000 std::string username("user2"); |
3059 std::string password("secret"); | 3001 std::string password("secret"); |
3060 replacements.SetUsernameStr(username); | 3002 replacements.SetUsernameStr(username); |
3061 replacements.SetPasswordStr(password); | 3003 replacements.SetPasswordStr(password); |
3062 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 3004 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
3063 | 3005 |
3064 URLRequest r(url_with_identity, &d); | 3006 URLRequest r(url_with_identity, &d, &context); |
3065 r.set_context(&context); | |
3066 r.Start(); | 3007 r.Start(); |
3067 | 3008 |
3068 MessageLoop::current()->Run(); | 3009 MessageLoop::current()->Run(); |
3069 | 3010 |
3070 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 3011 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
3071 | 3012 |
3072 // Make sure we sent the cookie in the restarted transaction. | 3013 // Make sure we sent the cookie in the restarted transaction. |
3073 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 3014 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
3074 != std::string::npos); | 3015 != std::string::npos); |
3075 } | 3016 } |
3076 } | 3017 } |
3077 | 3018 |
3078 TEST_F(URLRequestTest, DelayedCookieCallback) { | 3019 TEST_F(URLRequestTest, DelayedCookieCallback) { |
3079 LocalHttpTestServer test_server; | 3020 LocalHttpTestServer test_server; |
3080 ASSERT_TRUE(test_server.Start()); | 3021 ASSERT_TRUE(test_server.Start()); |
3081 | 3022 |
3082 TestURLRequestContext context; | 3023 TestURLRequestContext context; |
3083 scoped_refptr<DelayedCookieMonster> delayed_cm = | 3024 scoped_refptr<DelayedCookieMonster> delayed_cm = |
3084 new DelayedCookieMonster(); | 3025 new DelayedCookieMonster(); |
3085 scoped_refptr<CookieStore> cookie_store = delayed_cm; | 3026 scoped_refptr<CookieStore> cookie_store = delayed_cm; |
3086 context.set_cookie_store(delayed_cm); | 3027 context.set_cookie_store(delayed_cm); |
3087 | 3028 |
3088 // Set up a cookie. | 3029 // Set up a cookie. |
3089 { | 3030 { |
3090 TestNetworkDelegate network_delegate; | 3031 TestNetworkDelegate network_delegate; |
3091 context.set_network_delegate(&network_delegate); | 3032 context.set_network_delegate(&network_delegate); |
3092 TestDelegate d; | 3033 TestDelegate d; |
3093 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 3034 URLRequest req( |
3094 req.set_context(&context); | 3035 test_server.GetURL("set-cookie?CookieToNotSend=1"), &d, &context); |
3095 req.Start(); | 3036 req.Start(); |
3096 MessageLoop::current()->Run(); | 3037 MessageLoop::current()->Run(); |
3097 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3038 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3098 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3039 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3099 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 3040 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
3100 } | 3041 } |
3101 | 3042 |
3102 // Verify that the cookie is set. | 3043 // Verify that the cookie is set. |
3103 { | 3044 { |
3104 TestNetworkDelegate network_delegate; | 3045 TestNetworkDelegate network_delegate; |
3105 context.set_network_delegate(&network_delegate); | 3046 context.set_network_delegate(&network_delegate); |
3106 TestDelegate d; | 3047 TestDelegate d; |
3107 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3048 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d, &context); |
3108 req.set_context(&context); | |
3109 req.Start(); | 3049 req.Start(); |
3110 MessageLoop::current()->Run(); | 3050 MessageLoop::current()->Run(); |
3111 | 3051 |
3112 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 3052 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
3113 != std::string::npos); | 3053 != std::string::npos); |
3114 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3054 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3115 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3055 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3116 } | 3056 } |
3117 } | 3057 } |
3118 | 3058 |
3119 TEST_F(URLRequestTest, DoNotSendCookies) { | 3059 TEST_F(URLRequestTest, DoNotSendCookies) { |
3120 LocalHttpTestServer test_server; | 3060 LocalHttpTestServer test_server; |
3121 ASSERT_TRUE(test_server.Start()); | 3061 ASSERT_TRUE(test_server.Start()); |
3122 | 3062 |
3123 // Set up a cookie. | 3063 // Set up a cookie. |
3124 { | 3064 { |
3125 TestNetworkDelegate network_delegate; | 3065 TestNetworkDelegate network_delegate; |
3126 default_context_.set_network_delegate(&network_delegate); | 3066 default_context_.set_network_delegate(&network_delegate); |
3127 TestDelegate d; | 3067 TestDelegate d; |
3128 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 3068 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
3129 req.set_context(&default_context_); | 3069 &d, |
3070 &default_context_); | |
3130 req.Start(); | 3071 req.Start(); |
3131 MessageLoop::current()->Run(); | 3072 MessageLoop::current()->Run(); |
3132 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3073 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3133 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3074 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3134 } | 3075 } |
3135 | 3076 |
3136 // Verify that the cookie is set. | 3077 // Verify that the cookie is set. |
3137 { | 3078 { |
3138 TestNetworkDelegate network_delegate; | 3079 TestNetworkDelegate network_delegate; |
3139 default_context_.set_network_delegate(&network_delegate); | 3080 default_context_.set_network_delegate(&network_delegate); |
3140 TestDelegate d; | 3081 TestDelegate d; |
3141 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3082 URLRequest req( |
3142 req.set_context(&default_context_); | 3083 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
3143 req.Start(); | 3084 req.Start(); |
3144 MessageLoop::current()->Run(); | 3085 MessageLoop::current()->Run(); |
3145 | 3086 |
3146 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 3087 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
3147 != std::string::npos); | 3088 != std::string::npos); |
3148 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3089 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3149 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3090 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3150 } | 3091 } |
3151 | 3092 |
3152 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 3093 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
3153 { | 3094 { |
3154 TestNetworkDelegate network_delegate; | 3095 TestNetworkDelegate network_delegate; |
3155 default_context_.set_network_delegate(&network_delegate); | 3096 default_context_.set_network_delegate(&network_delegate); |
3156 TestDelegate d; | 3097 TestDelegate d; |
3157 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3098 URLRequest req( |
3099 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); | |
3158 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); | 3100 req.set_load_flags(LOAD_DO_NOT_SEND_COOKIES); |
3159 req.set_context(&default_context_); | |
3160 req.Start(); | 3101 req.Start(); |
3161 MessageLoop::current()->Run(); | 3102 MessageLoop::current()->Run(); |
3162 | 3103 |
3163 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 3104 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
3164 == std::string::npos); | 3105 == std::string::npos); |
3165 | 3106 |
3166 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 3107 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
3167 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3108 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3168 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3109 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3169 } | 3110 } |
3170 } | 3111 } |
3171 | 3112 |
3172 TEST_F(URLRequestTest, DoNotSaveCookies) { | 3113 TEST_F(URLRequestTest, DoNotSaveCookies) { |
3173 LocalHttpTestServer test_server; | 3114 LocalHttpTestServer test_server; |
3174 ASSERT_TRUE(test_server.Start()); | 3115 ASSERT_TRUE(test_server.Start()); |
3175 | 3116 |
3176 // Set up a cookie. | 3117 // Set up a cookie. |
3177 { | 3118 { |
3178 TestNetworkDelegate network_delegate; | 3119 TestNetworkDelegate network_delegate; |
3179 default_context_.set_network_delegate(&network_delegate); | 3120 default_context_.set_network_delegate(&network_delegate); |
3180 TestDelegate d; | 3121 TestDelegate d; |
3181 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); | 3122 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
3182 req.set_context(&default_context_); | 3123 &d, |
3124 &default_context_); | |
3183 req.Start(); | 3125 req.Start(); |
3184 MessageLoop::current()->Run(); | 3126 MessageLoop::current()->Run(); |
3185 | 3127 |
3186 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3128 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3187 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3129 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3188 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 3130 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
3189 } | 3131 } |
3190 | 3132 |
3191 // Try to set-up another cookie and update the previous cookie. | 3133 // Try to set-up another cookie and update the previous cookie. |
3192 { | 3134 { |
3193 TestNetworkDelegate network_delegate; | 3135 TestNetworkDelegate network_delegate; |
3194 default_context_.set_network_delegate(&network_delegate); | 3136 default_context_.set_network_delegate(&network_delegate); |
3195 TestDelegate d; | 3137 TestDelegate d; |
3196 URLRequest req(test_server.GetURL( | 3138 URLRequest req( |
3197 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 3139 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
3140 &d, | |
3141 &default_context_); | |
3198 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); | 3142 req.set_load_flags(LOAD_DO_NOT_SAVE_COOKIES); |
3199 req.set_context(&default_context_); | |
3200 req.Start(); | 3143 req.Start(); |
3201 | 3144 |
3202 MessageLoop::current()->Run(); | 3145 MessageLoop::current()->Run(); |
3203 | 3146 |
3204 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 3147 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
3205 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3148 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3206 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3149 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3207 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 3150 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
3208 } | 3151 } |
3209 | 3152 |
3210 // Verify the cookies weren't saved or updated. | 3153 // Verify the cookies weren't saved or updated. |
3211 { | 3154 { |
3212 TestNetworkDelegate network_delegate; | 3155 TestNetworkDelegate network_delegate; |
3213 default_context_.set_network_delegate(&network_delegate); | 3156 default_context_.set_network_delegate(&network_delegate); |
3214 TestDelegate d; | 3157 TestDelegate d; |
3215 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3158 URLRequest req( |
3216 req.set_context(&default_context_); | 3159 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
3217 req.Start(); | 3160 req.Start(); |
3218 MessageLoop::current()->Run(); | 3161 MessageLoop::current()->Run(); |
3219 | 3162 |
3220 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 3163 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
3221 == std::string::npos); | 3164 == std::string::npos); |
3222 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 3165 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
3223 != std::string::npos); | 3166 != std::string::npos); |
3224 | 3167 |
3225 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3168 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3226 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3169 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3227 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 3170 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
3228 } | 3171 } |
3229 } | 3172 } |
3230 | 3173 |
3231 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 3174 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
3232 LocalHttpTestServer test_server; | 3175 LocalHttpTestServer test_server; |
3233 ASSERT_TRUE(test_server.Start()); | 3176 ASSERT_TRUE(test_server.Start()); |
3234 | 3177 |
3235 // Set up a cookie. | 3178 // Set up a cookie. |
3236 { | 3179 { |
3237 TestNetworkDelegate network_delegate; | 3180 TestNetworkDelegate network_delegate; |
3238 default_context_.set_network_delegate(&network_delegate); | 3181 default_context_.set_network_delegate(&network_delegate); |
3239 TestDelegate d; | 3182 TestDelegate d; |
3240 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 3183 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
3241 req.set_context(&default_context_); | 3184 &d, |
3185 &default_context_); | |
3242 req.Start(); | 3186 req.Start(); |
3243 MessageLoop::current()->Run(); | 3187 MessageLoop::current()->Run(); |
3244 | 3188 |
3245 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3189 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3246 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3190 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3247 } | 3191 } |
3248 | 3192 |
3249 // Verify that the cookie is set. | 3193 // Verify that the cookie is set. |
3250 { | 3194 { |
3251 TestNetworkDelegate network_delegate; | 3195 TestNetworkDelegate network_delegate; |
3252 default_context_.set_network_delegate(&network_delegate); | 3196 default_context_.set_network_delegate(&network_delegate); |
3253 TestDelegate d; | 3197 TestDelegate d; |
3254 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3198 URLRequest req( |
3255 req.set_context(&default_context_); | 3199 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
3256 req.Start(); | 3200 req.Start(); |
3257 MessageLoop::current()->Run(); | 3201 MessageLoop::current()->Run(); |
3258 | 3202 |
3259 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 3203 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
3260 != std::string::npos); | 3204 != std::string::npos); |
3261 | 3205 |
3262 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3206 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3263 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3207 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3264 } | 3208 } |
3265 | 3209 |
3266 // Verify that the cookie isn't sent. | 3210 // Verify that the cookie isn't sent. |
3267 { | 3211 { |
3268 TestNetworkDelegate network_delegate; | 3212 TestNetworkDelegate network_delegate; |
3269 default_context_.set_network_delegate(&network_delegate); | 3213 default_context_.set_network_delegate(&network_delegate); |
3270 TestDelegate d; | 3214 TestDelegate d; |
3271 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 3215 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
3272 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3216 URLRequest req( |
3273 req.set_context(&default_context_); | 3217 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
3274 req.Start(); | 3218 req.Start(); |
3275 MessageLoop::current()->Run(); | 3219 MessageLoop::current()->Run(); |
3276 | 3220 |
3277 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 3221 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
3278 == std::string::npos); | 3222 == std::string::npos); |
3279 | 3223 |
3280 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 3224 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
3281 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3225 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3282 } | 3226 } |
3283 } | 3227 } |
3284 | 3228 |
3285 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 3229 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
3286 LocalHttpTestServer test_server; | 3230 LocalHttpTestServer test_server; |
3287 ASSERT_TRUE(test_server.Start()); | 3231 ASSERT_TRUE(test_server.Start()); |
3288 | 3232 |
3289 // Set up a cookie. | 3233 // Set up a cookie. |
3290 { | 3234 { |
3291 TestNetworkDelegate network_delegate; | 3235 TestNetworkDelegate network_delegate; |
3292 default_context_.set_network_delegate(&network_delegate); | 3236 default_context_.set_network_delegate(&network_delegate); |
3293 TestDelegate d; | 3237 TestDelegate d; |
3294 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); | 3238 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
3295 req.set_context(&default_context_); | 3239 &d, |
3240 &default_context_); | |
3296 req.Start(); | 3241 req.Start(); |
3297 MessageLoop::current()->Run(); | 3242 MessageLoop::current()->Run(); |
3298 | 3243 |
3299 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3244 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3300 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3245 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3301 } | 3246 } |
3302 | 3247 |
3303 // Try to set-up another cookie and update the previous cookie. | 3248 // Try to set-up another cookie and update the previous cookie. |
3304 { | 3249 { |
3305 TestNetworkDelegate network_delegate; | 3250 TestNetworkDelegate network_delegate; |
3306 default_context_.set_network_delegate(&network_delegate); | 3251 default_context_.set_network_delegate(&network_delegate); |
3307 TestDelegate d; | 3252 TestDelegate d; |
3308 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 3253 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
3309 URLRequest req(test_server.GetURL( | 3254 URLRequest req( |
3310 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 3255 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
3311 req.set_context(&default_context_); | 3256 &d, |
3257 &default_context_); | |
3312 req.Start(); | 3258 req.Start(); |
3313 | 3259 |
3314 MessageLoop::current()->Run(); | 3260 MessageLoop::current()->Run(); |
3315 | 3261 |
3316 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3262 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3317 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 3263 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
3318 } | 3264 } |
3319 | 3265 |
3320 // Verify the cookies weren't saved or updated. | 3266 // Verify the cookies weren't saved or updated. |
3321 { | 3267 { |
3322 TestNetworkDelegate network_delegate; | 3268 TestNetworkDelegate network_delegate; |
3323 default_context_.set_network_delegate(&network_delegate); | 3269 default_context_.set_network_delegate(&network_delegate); |
3324 TestDelegate d; | 3270 TestDelegate d; |
3325 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3271 URLRequest req( |
3326 req.set_context(&default_context_); | 3272 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
3327 req.Start(); | 3273 req.Start(); |
3328 MessageLoop::current()->Run(); | 3274 MessageLoop::current()->Run(); |
3329 | 3275 |
3330 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 3276 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
3331 == std::string::npos); | 3277 == std::string::npos); |
3332 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 3278 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
3333 != std::string::npos); | 3279 != std::string::npos); |
3334 | 3280 |
3335 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3281 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3336 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3282 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3337 } | 3283 } |
3338 } | 3284 } |
3339 | 3285 |
3340 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 3286 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
3341 LocalHttpTestServer test_server; | 3287 LocalHttpTestServer test_server; |
3342 ASSERT_TRUE(test_server.Start()); | 3288 ASSERT_TRUE(test_server.Start()); |
3343 | 3289 |
3344 // Set up an empty cookie. | 3290 // Set up an empty cookie. |
3345 { | 3291 { |
3346 TestNetworkDelegate network_delegate; | 3292 TestNetworkDelegate network_delegate; |
3347 default_context_.set_network_delegate(&network_delegate); | 3293 default_context_.set_network_delegate(&network_delegate); |
3348 TestDelegate d; | 3294 TestDelegate d; |
3349 URLRequest req(test_server.GetURL("set-cookie"), &d); | 3295 URLRequest req(test_server.GetURL("set-cookie"), &d, &default_context_); |
3350 req.set_context(&default_context_); | |
3351 req.Start(); | 3296 req.Start(); |
3352 MessageLoop::current()->Run(); | 3297 MessageLoop::current()->Run(); |
3353 | 3298 |
3354 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3299 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3355 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3300 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3356 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 3301 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
3357 } | 3302 } |
3358 } | 3303 } |
3359 | 3304 |
3360 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 3305 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
3361 LocalHttpTestServer test_server; | 3306 LocalHttpTestServer test_server; |
3362 ASSERT_TRUE(test_server.Start()); | 3307 ASSERT_TRUE(test_server.Start()); |
3363 | 3308 |
3364 // Set up a cookie. | 3309 // Set up a cookie. |
3365 { | 3310 { |
3366 TestNetworkDelegate network_delegate; | 3311 TestNetworkDelegate network_delegate; |
3367 default_context_.set_network_delegate(&network_delegate); | 3312 default_context_.set_network_delegate(&network_delegate); |
3368 TestDelegate d; | 3313 TestDelegate d; |
3369 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), &d); | 3314 URLRequest req(test_server.GetURL("set-cookie?CookieToNotSend=1"), |
3370 req.set_context(&default_context_); | 3315 &d, |
3316 &default_context_); | |
3371 req.Start(); | 3317 req.Start(); |
3372 MessageLoop::current()->Run(); | 3318 MessageLoop::current()->Run(); |
3373 | 3319 |
3374 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3320 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3375 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3321 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3376 } | 3322 } |
3377 | 3323 |
3378 // Verify that the cookie is set. | 3324 // Verify that the cookie is set. |
3379 { | 3325 { |
3380 TestNetworkDelegate network_delegate; | 3326 TestNetworkDelegate network_delegate; |
3381 default_context_.set_network_delegate(&network_delegate); | 3327 default_context_.set_network_delegate(&network_delegate); |
3382 TestDelegate d; | 3328 TestDelegate d; |
3383 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3329 URLRequest req( |
3384 req.set_context(&default_context_); | 3330 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
3385 req.Start(); | 3331 req.Start(); |
3386 MessageLoop::current()->Run(); | 3332 MessageLoop::current()->Run(); |
3387 | 3333 |
3388 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 3334 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
3389 != std::string::npos); | 3335 != std::string::npos); |
3390 | 3336 |
3391 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3337 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3392 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3338 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3393 } | 3339 } |
3394 | 3340 |
3395 // Verify that the cookie isn't sent. | 3341 // Verify that the cookie isn't sent. |
3396 { | 3342 { |
3397 TestNetworkDelegate network_delegate; | 3343 TestNetworkDelegate network_delegate; |
3398 default_context_.set_network_delegate(&network_delegate); | 3344 default_context_.set_network_delegate(&network_delegate); |
3399 TestDelegate d; | 3345 TestDelegate d; |
3400 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 3346 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
3401 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3347 URLRequest req( |
3402 req.set_context(&default_context_); | 3348 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
3403 req.Start(); | 3349 req.Start(); |
3404 MessageLoop::current()->Run(); | 3350 MessageLoop::current()->Run(); |
3405 | 3351 |
3406 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 3352 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
3407 == std::string::npos); | 3353 == std::string::npos); |
3408 | 3354 |
3409 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 3355 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
3410 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3356 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3411 } | 3357 } |
3412 } | 3358 } |
3413 | 3359 |
3414 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 3360 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
3415 LocalHttpTestServer test_server; | 3361 LocalHttpTestServer test_server; |
3416 ASSERT_TRUE(test_server.Start()); | 3362 ASSERT_TRUE(test_server.Start()); |
3417 | 3363 |
3418 // Set up a cookie. | 3364 // Set up a cookie. |
3419 { | 3365 { |
3420 TestNetworkDelegate network_delegate; | 3366 TestNetworkDelegate network_delegate; |
3421 default_context_.set_network_delegate(&network_delegate); | 3367 default_context_.set_network_delegate(&network_delegate); |
3422 TestDelegate d; | 3368 TestDelegate d; |
3423 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), &d); | 3369 URLRequest req(test_server.GetURL("set-cookie?CookieToNotUpdate=2"), |
3424 req.set_context(&default_context_); | 3370 &d, |
3371 &default_context_); | |
3425 req.Start(); | 3372 req.Start(); |
3426 MessageLoop::current()->Run(); | 3373 MessageLoop::current()->Run(); |
3427 | 3374 |
3428 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3375 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3429 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3376 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3430 } | 3377 } |
3431 | 3378 |
3432 // Try to set-up another cookie and update the previous cookie. | 3379 // Try to set-up another cookie and update the previous cookie. |
3433 { | 3380 { |
3434 TestNetworkDelegate network_delegate; | 3381 TestNetworkDelegate network_delegate; |
3435 default_context_.set_network_delegate(&network_delegate); | 3382 default_context_.set_network_delegate(&network_delegate); |
3436 TestDelegate d; | 3383 TestDelegate d; |
3437 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 3384 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
3438 URLRequest req(test_server.GetURL( | 3385 URLRequest req( |
3439 "set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), &d); | 3386 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
3440 req.set_context(&default_context_); | 3387 &d, |
3388 &default_context_); | |
3441 req.Start(); | 3389 req.Start(); |
3442 | 3390 |
3443 MessageLoop::current()->Run(); | 3391 MessageLoop::current()->Run(); |
3444 | 3392 |
3445 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3393 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3446 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 3394 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
3447 } | 3395 } |
3448 | 3396 |
3449 // Verify the cookies weren't saved or updated. | 3397 // Verify the cookies weren't saved or updated. |
3450 { | 3398 { |
3451 TestNetworkDelegate network_delegate; | 3399 TestNetworkDelegate network_delegate; |
3452 default_context_.set_network_delegate(&network_delegate); | 3400 default_context_.set_network_delegate(&network_delegate); |
3453 TestDelegate d; | 3401 TestDelegate d; |
3454 URLRequest req(test_server.GetURL("echoheader?Cookie"), &d); | 3402 URLRequest req( |
3455 req.set_context(&default_context_); | 3403 test_server.GetURL("echoheader?Cookie"), &d, &default_context_); |
3456 req.Start(); | 3404 req.Start(); |
3457 MessageLoop::current()->Run(); | 3405 MessageLoop::current()->Run(); |
3458 | 3406 |
3459 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 3407 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
3460 == std::string::npos); | 3408 == std::string::npos); |
3461 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 3409 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
3462 != std::string::npos); | 3410 != std::string::npos); |
3463 | 3411 |
3464 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3412 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3465 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3413 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
(...skipping 10 matching lines...) Expand all Loading... | |
3476 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { | 3424 TEST_F(URLRequestTest, CookiePolicy_ForceSession) { |
3477 LocalHttpTestServer test_server; | 3425 LocalHttpTestServer test_server; |
3478 ASSERT_TRUE(test_server.Start()); | 3426 ASSERT_TRUE(test_server.Start()); |
3479 | 3427 |
3480 // Set up a cookie. | 3428 // Set up a cookie. |
3481 { | 3429 { |
3482 TestNetworkDelegate network_delegate; | 3430 TestNetworkDelegate network_delegate; |
3483 default_context_.set_network_delegate(&network_delegate); | 3431 default_context_.set_network_delegate(&network_delegate); |
3484 TestDelegate d; | 3432 TestDelegate d; |
3485 network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION); | 3433 network_delegate.set_cookie_options(TestNetworkDelegate::FORCE_SESSION); |
3486 URLRequest req(test_server.GetURL( | 3434 URLRequest req( |
3487 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), &d); | 3435 test_server.GetURL( |
3488 req.set_context(&default_context_); | 3436 "set-cookie?A=1;expires=\"Fri, 05 Feb 2010 23:42:01 GMT\""), |
3437 &d, | |
3438 &default_context_); | |
3489 req.Start(); // Triggers an asynchronous cookie policy check. | 3439 req.Start(); // Triggers an asynchronous cookie policy check. |
3490 | 3440 |
3491 MessageLoop::current()->Run(); | 3441 MessageLoop::current()->Run(); |
3492 | 3442 |
3493 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3443 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
3494 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3444 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
3495 } | 3445 } |
3496 default_context_.set_network_delegate(&default_network_delegate_); | 3446 default_context_.set_network_delegate(&default_network_delegate_); |
3497 | 3447 |
3498 // Now, check the cookie store. | 3448 // Now, check the cookie store. |
3499 bool was_run = false; | 3449 bool was_run = false; |
3500 default_context_.cookie_store()->GetCookieMonster()->GetAllCookiesAsync( | 3450 default_context_.cookie_store()->GetCookieMonster()->GetAllCookiesAsync( |
3501 base::Bind(&CheckCookiePolicyCallback, &was_run)); | 3451 base::Bind(&CheckCookiePolicyCallback, &was_run)); |
3502 MessageLoop::current()->RunAllPending(); | 3452 MessageLoop::current()->RunAllPending(); |
3503 DCHECK(was_run); | 3453 DCHECK(was_run); |
3504 } | 3454 } |
3505 | 3455 |
3506 // In this test, we do a POST which the server will 302 redirect. | 3456 // In this test, we do a POST which the server will 302 redirect. |
3507 // The subsequent transaction should use GET, and should not send the | 3457 // The subsequent transaction should use GET, and should not send the |
3508 // Content-Type header. | 3458 // Content-Type header. |
3509 // http://code.google.com/p/chromium/issues/detail?id=843 | 3459 // http://code.google.com/p/chromium/issues/detail?id=843 |
3510 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 3460 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
3511 ASSERT_TRUE(test_server_.Start()); | 3461 ASSERT_TRUE(test_server_.Start()); |
3512 | 3462 |
3513 const char kData[] = "hello world"; | 3463 const char kData[] = "hello world"; |
3514 | 3464 |
3515 TestDelegate d; | 3465 TestDelegate d; |
3516 URLRequest req(test_server_.GetURL("files/redirect-to-echoall"), &d); | 3466 URLRequest req( |
3517 req.set_context(&default_context_); | 3467 test_server_.GetURL("files/redirect-to-echoall"), &d, &default_context_); |
3518 req.set_method("POST"); | 3468 req.set_method("POST"); |
3519 req.set_upload(CreateSimpleUploadData(kData)); | 3469 req.set_upload(CreateSimpleUploadData(kData)); |
3520 | 3470 |
3521 // Set headers (some of which are specific to the POST). | 3471 // Set headers (some of which are specific to the POST). |
3522 HttpRequestHeaders headers; | 3472 HttpRequestHeaders headers; |
3523 headers.AddHeadersFromString( | 3473 headers.AddHeadersFromString( |
3524 "Content-Type: multipart/form-data; " | 3474 "Content-Type: multipart/form-data; " |
3525 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 3475 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
3526 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 3476 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
3527 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 3477 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3593 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 3543 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
3594 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 3544 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
3595 } | 3545 } |
3596 | 3546 |
3597 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 3547 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
3598 ASSERT_TRUE(test_server_.Start()); | 3548 ASSERT_TRUE(test_server_.Start()); |
3599 | 3549 |
3600 const char kData[] = "hello world"; | 3550 const char kData[] = "hello world"; |
3601 | 3551 |
3602 TestDelegate d; | 3552 TestDelegate d; |
3603 URLRequest req(test_server_.GetURL("empty.html"), &d); | 3553 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
3604 req.set_context(&default_context_); | |
3605 req.set_method("POST"); | 3554 req.set_method("POST"); |
3606 req.set_upload(CreateSimpleUploadData(kData).get()); | 3555 req.set_upload(CreateSimpleUploadData(kData).get()); |
3607 HttpRequestHeaders headers; | 3556 HttpRequestHeaders headers; |
3608 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3557 headers.SetHeader(HttpRequestHeaders::kContentLength, |
3609 base::UintToString(arraysize(kData) - 1)); | 3558 base::UintToString(arraysize(kData) - 1)); |
3610 req.SetExtraRequestHeaders(headers); | 3559 req.SetExtraRequestHeaders(headers); |
3611 | 3560 |
3612 URLRequestRedirectJob* job = | 3561 URLRequestRedirectJob* job = |
3613 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); | 3562 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); |
3614 AddTestInterceptor()->set_main_intercept_job(job); | 3563 AddTestInterceptor()->set_main_intercept_job(job); |
3615 | 3564 |
3616 req.Start(); | 3565 req.Start(); |
3617 MessageLoop::current()->Run(); | 3566 MessageLoop::current()->Run(); |
3618 EXPECT_EQ("GET", req.method()); | 3567 EXPECT_EQ("GET", req.method()); |
3619 } | 3568 } |
3620 | 3569 |
3621 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 3570 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
3622 ASSERT_TRUE(test_server_.Start()); | 3571 ASSERT_TRUE(test_server_.Start()); |
3623 | 3572 |
3624 const char kData[] = "hello world"; | 3573 const char kData[] = "hello world"; |
3625 | 3574 |
3626 TestDelegate d; | 3575 TestDelegate d; |
3627 URLRequest req(test_server_.GetURL("empty.html"), &d); | 3576 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
3628 req.set_context(&default_context_); | |
3629 req.set_method("POST"); | 3577 req.set_method("POST"); |
3630 req.set_upload(CreateSimpleUploadData(kData).get()); | 3578 req.set_upload(CreateSimpleUploadData(kData).get()); |
3631 HttpRequestHeaders headers; | 3579 HttpRequestHeaders headers; |
3632 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3580 headers.SetHeader(HttpRequestHeaders::kContentLength, |
3633 base::UintToString(arraysize(kData) - 1)); | 3581 base::UintToString(arraysize(kData) - 1)); |
3634 req.SetExtraRequestHeaders(headers); | 3582 req.SetExtraRequestHeaders(headers); |
3635 | 3583 |
3636 URLRequestRedirectJob* job = | 3584 URLRequestRedirectJob* job = |
3637 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); | 3585 new URLRequestRedirectJob(&req, test_server_.GetURL("echo")); |
3638 job->set_redirect_code( | 3586 job->set_redirect_code( |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3837 | 3785 |
3838 TEST_F(URLRequestTest, Intercept) { | 3786 TEST_F(URLRequestTest, Intercept) { |
3839 TestInterceptor interceptor; | 3787 TestInterceptor interceptor; |
3840 | 3788 |
3841 // intercept the main request and respond with a simple response | 3789 // intercept the main request and respond with a simple response |
3842 interceptor.intercept_main_request_ = true; | 3790 interceptor.intercept_main_request_ = true; |
3843 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 3791 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
3844 interceptor.main_data_ = TestInterceptor::ok_data(); | 3792 interceptor.main_data_ = TestInterceptor::ok_data(); |
3845 | 3793 |
3846 TestDelegate d; | 3794 TestDelegate d; |
3847 URLRequest req(GURL("http://test_intercept/foo"), &d); | 3795 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
3848 req.set_context(&default_context_); | |
3849 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); | 3796 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); |
3850 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); | 3797 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); |
3851 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); | 3798 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); |
3852 req.SetUserData(NULL, user_data0); | 3799 req.SetUserData(NULL, user_data0); |
3853 req.SetUserData(&user_data1, user_data1); | 3800 req.SetUserData(&user_data1, user_data1); |
3854 req.SetUserData(&user_data2, user_data2); | 3801 req.SetUserData(&user_data2, user_data2); |
3855 req.set_method("GET"); | 3802 req.set_method("GET"); |
3856 req.Start(); | 3803 req.Start(); |
3857 MessageLoop::current()->Run(); | 3804 MessageLoop::current()->Run(); |
3858 | 3805 |
(...skipping 20 matching lines...) Expand all Loading... | |
3879 interceptor.intercept_main_request_ = true; | 3826 interceptor.intercept_main_request_ = true; |
3880 interceptor.main_headers_ = TestInterceptor::redirect_headers(); | 3827 interceptor.main_headers_ = TestInterceptor::redirect_headers(); |
3881 interceptor.main_data_ = TestInterceptor::redirect_data(); | 3828 interceptor.main_data_ = TestInterceptor::redirect_data(); |
3882 | 3829 |
3883 // intercept that redirect and respond a final OK response | 3830 // intercept that redirect and respond a final OK response |
3884 interceptor.intercept_redirect_ = true; | 3831 interceptor.intercept_redirect_ = true; |
3885 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); | 3832 interceptor.redirect_headers_ = TestInterceptor::ok_headers(); |
3886 interceptor.redirect_data_ = TestInterceptor::ok_data(); | 3833 interceptor.redirect_data_ = TestInterceptor::ok_data(); |
3887 | 3834 |
3888 TestDelegate d; | 3835 TestDelegate d; |
3889 URLRequest req(GURL("http://test_intercept/foo"), &d); | 3836 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
3890 req.set_context(&default_context_); | |
3891 req.set_method("GET"); | 3837 req.set_method("GET"); |
3892 req.Start(); | 3838 req.Start(); |
3893 MessageLoop::current()->Run(); | 3839 MessageLoop::current()->Run(); |
3894 | 3840 |
3895 // Check the interceptor got called as expected | 3841 // Check the interceptor got called as expected |
3896 EXPECT_TRUE(interceptor.did_intercept_main_); | 3842 EXPECT_TRUE(interceptor.did_intercept_main_); |
3897 EXPECT_TRUE(interceptor.did_intercept_redirect_); | 3843 EXPECT_TRUE(interceptor.did_intercept_redirect_); |
3898 | 3844 |
3899 // Check we got one good response | 3845 // Check we got one good response |
3900 EXPECT_TRUE(req.status().is_success()); | 3846 EXPECT_TRUE(req.status().is_success()); |
(...skipping 12 matching lines...) Expand all Loading... | |
3913 interceptor.intercept_main_request_ = true; | 3859 interceptor.intercept_main_request_ = true; |
3914 interceptor.main_headers_ = TestInterceptor::error_headers(); | 3860 interceptor.main_headers_ = TestInterceptor::error_headers(); |
3915 interceptor.main_data_ = TestInterceptor::error_data(); | 3861 interceptor.main_data_ = TestInterceptor::error_data(); |
3916 | 3862 |
3917 // intercept that error and respond with an OK response | 3863 // intercept that error and respond with an OK response |
3918 interceptor.intercept_final_response_ = true; | 3864 interceptor.intercept_final_response_ = true; |
3919 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3865 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
3920 interceptor.final_data_ = TestInterceptor::ok_data(); | 3866 interceptor.final_data_ = TestInterceptor::ok_data(); |
3921 | 3867 |
3922 TestDelegate d; | 3868 TestDelegate d; |
3923 URLRequest req(GURL("http://test_intercept/foo"), &d); | 3869 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
3924 req.set_context(&default_context_); | |
3925 req.set_method("GET"); | 3870 req.set_method("GET"); |
3926 req.Start(); | 3871 req.Start(); |
3927 MessageLoop::current()->Run(); | 3872 MessageLoop::current()->Run(); |
3928 | 3873 |
3929 // Check the interceptor got called as expected | 3874 // Check the interceptor got called as expected |
3930 EXPECT_TRUE(interceptor.did_intercept_main_); | 3875 EXPECT_TRUE(interceptor.did_intercept_main_); |
3931 EXPECT_TRUE(interceptor.did_intercept_final_); | 3876 EXPECT_TRUE(interceptor.did_intercept_final_); |
3932 | 3877 |
3933 // Check we got one good response | 3878 // Check we got one good response |
3934 EXPECT_TRUE(req.status().is_success()); | 3879 EXPECT_TRUE(req.status().is_success()); |
3935 EXPECT_EQ(200, req.response_headers()->response_code()); | 3880 EXPECT_EQ(200, req.response_headers()->response_code()); |
3936 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 3881 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
3937 EXPECT_EQ(1, d.response_started_count()); | 3882 EXPECT_EQ(1, d.response_started_count()); |
3938 EXPECT_EQ(0, d.received_redirect_count()); | 3883 EXPECT_EQ(0, d.received_redirect_count()); |
3939 } | 3884 } |
3940 | 3885 |
3941 TEST_F(URLRequestTest, InterceptNetworkError) { | 3886 TEST_F(URLRequestTest, InterceptNetworkError) { |
3942 TestInterceptor interceptor; | 3887 TestInterceptor interceptor; |
3943 | 3888 |
3944 // intercept the main request to simulate a network error | 3889 // intercept the main request to simulate a network error |
3945 interceptor.simulate_main_network_error_ = true; | 3890 interceptor.simulate_main_network_error_ = true; |
3946 | 3891 |
3947 // intercept that error and respond with an OK response | 3892 // intercept that error and respond with an OK response |
3948 interceptor.intercept_final_response_ = true; | 3893 interceptor.intercept_final_response_ = true; |
3949 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3894 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
3950 interceptor.final_data_ = TestInterceptor::ok_data(); | 3895 interceptor.final_data_ = TestInterceptor::ok_data(); |
3951 | 3896 |
3952 TestDelegate d; | 3897 TestDelegate d; |
3953 URLRequest req(GURL("http://test_intercept/foo"), &d); | 3898 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
3954 req.set_context(&default_context_); | |
3955 req.set_method("GET"); | 3899 req.set_method("GET"); |
3956 req.Start(); | 3900 req.Start(); |
3957 MessageLoop::current()->Run(); | 3901 MessageLoop::current()->Run(); |
3958 | 3902 |
3959 // Check the interceptor got called as expected | 3903 // Check the interceptor got called as expected |
3960 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 3904 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
3961 EXPECT_TRUE(interceptor.did_intercept_final_); | 3905 EXPECT_TRUE(interceptor.did_intercept_final_); |
3962 | 3906 |
3963 // Check we received one good response | 3907 // Check we received one good response |
3964 EXPECT_TRUE(req.status().is_success()); | 3908 EXPECT_TRUE(req.status().is_success()); |
3965 EXPECT_EQ(200, req.response_headers()->response_code()); | 3909 EXPECT_EQ(200, req.response_headers()->response_code()); |
3966 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); | 3910 EXPECT_EQ(TestInterceptor::ok_data(), d.data_received()); |
3967 EXPECT_EQ(1, d.response_started_count()); | 3911 EXPECT_EQ(1, d.response_started_count()); |
3968 EXPECT_EQ(0, d.received_redirect_count()); | 3912 EXPECT_EQ(0, d.received_redirect_count()); |
3969 } | 3913 } |
3970 | 3914 |
3971 TEST_F(URLRequestTest, InterceptRestartRequired) { | 3915 TEST_F(URLRequestTest, InterceptRestartRequired) { |
3972 TestInterceptor interceptor; | 3916 TestInterceptor interceptor; |
3973 | 3917 |
3974 // restart the main request | 3918 // restart the main request |
3975 interceptor.restart_main_request_ = true; | 3919 interceptor.restart_main_request_ = true; |
3976 | 3920 |
3977 // then intercept the new main request and respond with an OK response | 3921 // then intercept the new main request and respond with an OK response |
3978 interceptor.intercept_main_request_ = true; | 3922 interceptor.intercept_main_request_ = true; |
3979 interceptor.main_headers_ = TestInterceptor::ok_headers(); | 3923 interceptor.main_headers_ = TestInterceptor::ok_headers(); |
3980 interceptor.main_data_ = TestInterceptor::ok_data(); | 3924 interceptor.main_data_ = TestInterceptor::ok_data(); |
3981 | 3925 |
3982 TestDelegate d; | 3926 TestDelegate d; |
3983 URLRequest req(GURL("http://test_intercept/foo"), &d); | 3927 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
3984 req.set_context(&default_context_); | |
3985 req.set_method("GET"); | 3928 req.set_method("GET"); |
3986 req.Start(); | 3929 req.Start(); |
3987 MessageLoop::current()->Run(); | 3930 MessageLoop::current()->Run(); |
3988 | 3931 |
3989 // Check the interceptor got called as expected | 3932 // Check the interceptor got called as expected |
3990 EXPECT_TRUE(interceptor.did_restart_main_); | 3933 EXPECT_TRUE(interceptor.did_restart_main_); |
3991 EXPECT_TRUE(interceptor.did_intercept_main_); | 3934 EXPECT_TRUE(interceptor.did_intercept_main_); |
3992 | 3935 |
3993 // Check we received one good response | 3936 // Check we received one good response |
3994 EXPECT_TRUE(req.status().is_success()); | 3937 EXPECT_TRUE(req.status().is_success()); |
(...skipping 10 matching lines...) Expand all Loading... | |
4005 | 3948 |
4006 // intercept the main request and cancel from within the restarted job | 3949 // intercept the main request and cancel from within the restarted job |
4007 interceptor.cancel_main_request_ = true; | 3950 interceptor.cancel_main_request_ = true; |
4008 | 3951 |
4009 // setup to intercept final response and override it with an OK response | 3952 // setup to intercept final response and override it with an OK response |
4010 interceptor.intercept_final_response_ = true; | 3953 interceptor.intercept_final_response_ = true; |
4011 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3954 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
4012 interceptor.final_data_ = TestInterceptor::ok_data(); | 3955 interceptor.final_data_ = TestInterceptor::ok_data(); |
4013 | 3956 |
4014 TestDelegate d; | 3957 TestDelegate d; |
4015 URLRequest req(GURL("http://test_intercept/foo"), &d); | 3958 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
4016 req.set_context(&default_context_); | |
4017 req.set_method("GET"); | 3959 req.set_method("GET"); |
4018 req.Start(); | 3960 req.Start(); |
4019 MessageLoop::current()->Run(); | 3961 MessageLoop::current()->Run(); |
4020 | 3962 |
4021 // Check the interceptor got called as expected | 3963 // Check the interceptor got called as expected |
4022 EXPECT_TRUE(interceptor.did_cancel_main_); | 3964 EXPECT_TRUE(interceptor.did_cancel_main_); |
4023 EXPECT_FALSE(interceptor.did_intercept_final_); | 3965 EXPECT_FALSE(interceptor.did_intercept_final_); |
4024 | 3966 |
4025 // Check we see a canceled request | 3967 // Check we see a canceled request |
4026 EXPECT_FALSE(req.status().is_success()); | 3968 EXPECT_FALSE(req.status().is_success()); |
(...skipping 10 matching lines...) Expand all Loading... | |
4037 | 3979 |
4038 // intercept the redirect and cancel from within that job | 3980 // intercept the redirect and cancel from within that job |
4039 interceptor.cancel_redirect_request_ = true; | 3981 interceptor.cancel_redirect_request_ = true; |
4040 | 3982 |
4041 // setup to intercept final response and override it with an OK response | 3983 // setup to intercept final response and override it with an OK response |
4042 interceptor.intercept_final_response_ = true; | 3984 interceptor.intercept_final_response_ = true; |
4043 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 3985 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
4044 interceptor.final_data_ = TestInterceptor::ok_data(); | 3986 interceptor.final_data_ = TestInterceptor::ok_data(); |
4045 | 3987 |
4046 TestDelegate d; | 3988 TestDelegate d; |
4047 URLRequest req(GURL("http://test_intercept/foo"), &d); | 3989 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
4048 req.set_context(&default_context_); | |
4049 req.set_method("GET"); | 3990 req.set_method("GET"); |
4050 req.Start(); | 3991 req.Start(); |
4051 MessageLoop::current()->Run(); | 3992 MessageLoop::current()->Run(); |
4052 | 3993 |
4053 // Check the interceptor got called as expected | 3994 // Check the interceptor got called as expected |
4054 EXPECT_TRUE(interceptor.did_intercept_main_); | 3995 EXPECT_TRUE(interceptor.did_intercept_main_); |
4055 EXPECT_TRUE(interceptor.did_cancel_redirect_); | 3996 EXPECT_TRUE(interceptor.did_cancel_redirect_); |
4056 EXPECT_FALSE(interceptor.did_intercept_final_); | 3997 EXPECT_FALSE(interceptor.did_intercept_final_); |
4057 | 3998 |
4058 // Check we see a canceled request | 3999 // Check we see a canceled request |
4059 EXPECT_FALSE(req.status().is_success()); | 4000 EXPECT_FALSE(req.status().is_success()); |
4060 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 4001 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
4061 } | 4002 } |
4062 | 4003 |
4063 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { | 4004 TEST_F(URLRequestTest, InterceptRespectsCancelFinal) { |
4064 TestInterceptor interceptor; | 4005 TestInterceptor interceptor; |
4065 | 4006 |
4066 // intercept the main request to simulate a network error | 4007 // intercept the main request to simulate a network error |
4067 interceptor.simulate_main_network_error_ = true; | 4008 interceptor.simulate_main_network_error_ = true; |
4068 | 4009 |
4069 // setup to intercept final response and cancel from within that job | 4010 // setup to intercept final response and cancel from within that job |
4070 interceptor.cancel_final_request_ = true; | 4011 interceptor.cancel_final_request_ = true; |
4071 | 4012 |
4072 TestDelegate d; | 4013 TestDelegate d; |
4073 URLRequest req(GURL("http://test_intercept/foo"), &d); | 4014 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
4074 req.set_context(&default_context_); | |
4075 req.set_method("GET"); | 4015 req.set_method("GET"); |
4076 req.Start(); | 4016 req.Start(); |
4077 MessageLoop::current()->Run(); | 4017 MessageLoop::current()->Run(); |
4078 | 4018 |
4079 // Check the interceptor got called as expected | 4019 // Check the interceptor got called as expected |
4080 EXPECT_TRUE(interceptor.did_simulate_error_main_); | 4020 EXPECT_TRUE(interceptor.did_simulate_error_main_); |
4081 EXPECT_TRUE(interceptor.did_cancel_final_); | 4021 EXPECT_TRUE(interceptor.did_cancel_final_); |
4082 | 4022 |
4083 // Check we see a canceled request | 4023 // Check we see a canceled request |
4084 EXPECT_FALSE(req.status().is_success()); | 4024 EXPECT_FALSE(req.status().is_success()); |
4085 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 4025 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
4086 } | 4026 } |
4087 | 4027 |
4088 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { | 4028 TEST_F(URLRequestTest, InterceptRespectsCancelInRestart) { |
4089 TestInterceptor interceptor; | 4029 TestInterceptor interceptor; |
4090 | 4030 |
4091 // intercept the main request and cancel then restart from within that job | 4031 // intercept the main request and cancel then restart from within that job |
4092 interceptor.cancel_then_restart_main_request_ = true; | 4032 interceptor.cancel_then_restart_main_request_ = true; |
4093 | 4033 |
4094 // setup to intercept final response and override it with an OK response | 4034 // setup to intercept final response and override it with an OK response |
4095 interceptor.intercept_final_response_ = true; | 4035 interceptor.intercept_final_response_ = true; |
4096 interceptor.final_headers_ = TestInterceptor::ok_headers(); | 4036 interceptor.final_headers_ = TestInterceptor::ok_headers(); |
4097 interceptor.final_data_ = TestInterceptor::ok_data(); | 4037 interceptor.final_data_ = TestInterceptor::ok_data(); |
4098 | 4038 |
4099 TestDelegate d; | 4039 TestDelegate d; |
4100 URLRequest req(GURL("http://test_intercept/foo"), &d); | 4040 URLRequest req(GURL("http://test_intercept/foo"), &d, &default_context_); |
4101 req.set_context(&default_context_); | |
4102 req.set_method("GET"); | 4041 req.set_method("GET"); |
4103 req.Start(); | 4042 req.Start(); |
4104 MessageLoop::current()->Run(); | 4043 MessageLoop::current()->Run(); |
4105 | 4044 |
4106 // Check the interceptor got called as expected | 4045 // Check the interceptor got called as expected |
4107 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); | 4046 EXPECT_TRUE(interceptor.did_cancel_then_restart_main_); |
4108 EXPECT_FALSE(interceptor.did_intercept_final_); | 4047 EXPECT_FALSE(interceptor.did_intercept_final_); |
4109 | 4048 |
4110 // Check we see a canceled request | 4049 // Check we see a canceled request |
4111 EXPECT_FALSE(req.status().is_success()); | 4050 EXPECT_FALSE(req.status().is_success()); |
4112 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); | 4051 EXPECT_EQ(URLRequestStatus::CANCELED, req.status().status()); |
4113 } | 4052 } |
4114 | 4053 |
4115 // Check that two different URL requests have different identifiers. | 4054 // Check that two different URL requests have different identifiers. |
4116 TEST_F(URLRequestTest, Identifiers) { | 4055 TEST_F(URLRequestTest, Identifiers) { |
4117 TestDelegate d; | 4056 TestDelegate d; |
4118 TestURLRequest req(GURL("http://example.com"), &d); | 4057 TestURLRequestContext context; |
4119 TestURLRequest other_req(GURL("http://example.com"), &d); | 4058 TestURLRequest req(GURL("http://example.com"), &d, &context); |
4059 TestURLRequest other_req(GURL("http://example.com"), &d, &context); | |
mmenke
2012/06/20 18:33:50
nit: Can just use default_context_ here, rather t
shalev
2012/06/20 20:13:12
Done.
shalev
2012/06/20 21:29:08
Actually, this test seems to fail when using defau
| |
4120 | 4060 |
4121 ASSERT_NE(req.identifier(), other_req.identifier()); | 4061 ASSERT_NE(req.identifier(), other_req.identifier()); |
4122 } | 4062 } |
4123 | 4063 |
4124 // Check that a failure to connect to the proxy is reported to the network | 4064 // Check that a failure to connect to the proxy is reported to the network |
4125 // delegate. | 4065 // delegate. |
4126 TEST_F(URLRequestTest, NetworkDelegateProxyError) { | 4066 TEST_F(URLRequestTest, NetworkDelegateProxyError) { |
4127 MockHostResolver host_resolver; | 4067 MockHostResolver host_resolver; |
4128 host_resolver.rules()->AddSimulatedFailure("*"); | 4068 host_resolver.rules()->AddSimulatedFailure("*"); |
4129 | 4069 |
4130 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4070 TestNetworkDelegate network_delegate; // must outlive URLRequests |
4131 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); | 4071 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); |
4132 | 4072 |
4133 TestDelegate d; | 4073 TestDelegate d; |
4134 URLRequest req(GURL("http://example.com"), &d); | 4074 URLRequest req(GURL("http://example.com"), &d, &context); |
4135 req.set_context(&context); | |
4136 req.set_method("GET"); | 4075 req.set_method("GET"); |
4137 | 4076 |
4138 req.Start(); | 4077 req.Start(); |
4139 MessageLoop::current()->Run(); | 4078 MessageLoop::current()->Run(); |
4140 | 4079 |
4141 // Check we see a failed request. | 4080 // Check we see a failed request. |
4142 EXPECT_FALSE(req.status().is_success()); | 4081 EXPECT_FALSE(req.status().is_success()); |
4143 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); | 4082 EXPECT_EQ(URLRequestStatus::FAILED, req.status().status()); |
4144 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); | 4083 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req.status().error()); |
4145 | 4084 |
4146 EXPECT_EQ(1, network_delegate.error_count()); | 4085 EXPECT_EQ(1, network_delegate.error_count()); |
4147 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); | 4086 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); |
4148 EXPECT_EQ(1, network_delegate.completed_requests()); | 4087 EXPECT_EQ(1, network_delegate.completed_requests()); |
4149 } | 4088 } |
4150 | 4089 |
4151 // Check that it is impossible to change the referrer in the extra headers of | 4090 // Check that it is impossible to change the referrer in the extra headers of |
4152 // an URLRequest. | 4091 // an URLRequest. |
4153 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 4092 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
4154 LocalHttpTestServer test_server; | 4093 LocalHttpTestServer test_server; |
4155 ASSERT_TRUE(test_server.Start()); | 4094 ASSERT_TRUE(test_server.Start()); |
4156 | 4095 |
4157 // If extra headers contain referer and the request contains a referer, | 4096 // If extra headers contain referer and the request contains a referer, |
4158 // only the latter shall be respected. | 4097 // only the latter shall be respected. |
4159 { | 4098 { |
4160 TestDelegate d; | 4099 TestDelegate d; |
4161 URLRequest req(test_server.GetURL("echoheader?Referer"), &d); | 4100 URLRequest req( |
4101 test_server.GetURL("echoheader?Referer"), &d, &default_context_); | |
4162 req.set_referrer("http://foo.com/"); | 4102 req.set_referrer("http://foo.com/"); |
4163 req.set_context(&default_context_); | |
4164 | 4103 |
4165 HttpRequestHeaders headers; | 4104 HttpRequestHeaders headers; |
4166 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 4105 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
4167 req.SetExtraRequestHeaders(headers); | 4106 req.SetExtraRequestHeaders(headers); |
4168 | 4107 |
4169 req.Start(); | 4108 req.Start(); |
4170 MessageLoop::current()->Run(); | 4109 MessageLoop::current()->Run(); |
4171 | 4110 |
4172 EXPECT_EQ("http://foo.com/", d.data_received()); | 4111 EXPECT_EQ("http://foo.com/", d.data_received()); |
4173 } | 4112 } |
4174 | 4113 |
4175 // If extra headers contain a referer but the request does not, no referer | 4114 // If extra headers contain a referer but the request does not, no referer |
4176 // shall be sent in the header. | 4115 // shall be sent in the header. |
4177 { | 4116 { |
4178 TestDelegate d; | 4117 TestDelegate d; |
4179 URLRequest req(test_server.GetURL("echoheader?Referer"), &d); | 4118 URLRequest req( |
4180 req.set_context(&default_context_); | 4119 test_server.GetURL("echoheader?Referer"), &d, &default_context_); |
4181 | 4120 |
4182 HttpRequestHeaders headers; | 4121 HttpRequestHeaders headers; |
4183 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 4122 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
4184 req.SetExtraRequestHeaders(headers); | 4123 req.SetExtraRequestHeaders(headers); |
4185 req.set_load_flags(LOAD_VALIDATE_CACHE); | 4124 req.set_load_flags(LOAD_VALIDATE_CACHE); |
4186 | 4125 |
4187 req.Start(); | 4126 req.Start(); |
4188 MessageLoop::current()->Run(); | 4127 MessageLoop::current()->Run(); |
4189 | 4128 |
4190 EXPECT_EQ("None", d.data_received()); | 4129 EXPECT_EQ("None", d.data_received()); |
4191 } | 4130 } |
4192 } | 4131 } |
4193 | 4132 |
4194 // Make sure that net::NetworkDelegate::NotifyCompleted is called if | 4133 // Make sure that net::NetworkDelegate::NotifyCompleted is called if |
4195 // content is empty. | 4134 // content is empty. |
4196 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { | 4135 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { |
4197 TestDelegate d; | 4136 TestDelegate d; |
4198 URLRequest req(GURL("data:,"), &d); | 4137 URLRequest req(GURL("data:,"), &d, &default_context_); |
4199 req.set_context(&default_context_); | |
4200 req.Start(); | 4138 req.Start(); |
4201 MessageLoop::current()->Run(); | 4139 MessageLoop::current()->Run(); |
4202 EXPECT_EQ("", d.data_received()); | 4140 EXPECT_EQ("", d.data_received()); |
4203 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 4141 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
4204 } | 4142 } |
4205 | 4143 |
4206 class URLRequestTestFTP : public URLRequestTest { | 4144 class URLRequestTestFTP : public URLRequestTest { |
4207 public: | 4145 public: |
4208 URLRequestTestFTP() | 4146 URLRequestTestFTP() |
4209 : test_server_(TestServer::TYPE_FTP, TestServer::kLocalhost, FilePath()) { | 4147 : test_server_(TestServer::TYPE_FTP, TestServer::kLocalhost, FilePath()) { |
4210 } | 4148 } |
4211 | 4149 |
4212 protected: | 4150 protected: |
4213 TestServer test_server_; | 4151 TestServer test_server_; |
4214 }; | 4152 }; |
4215 | 4153 |
4216 // Flaky, see http://crbug.com/25045. | 4154 // Flaky, see http://crbug.com/25045. |
4217 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { | 4155 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { |
4218 ASSERT_TRUE(test_server_.Start()); | 4156 ASSERT_TRUE(test_server_.Start()); |
4219 | 4157 |
4220 TestDelegate d; | 4158 TestDelegate d; |
4221 { | 4159 { |
4222 URLRequest r(test_server_.GetURL("/"), &d); | 4160 URLRequest r(test_server_.GetURL("/"), &d, &default_context_); |
4223 r.set_context(&default_context_); | |
4224 r.Start(); | 4161 r.Start(); |
4225 EXPECT_TRUE(r.is_pending()); | 4162 EXPECT_TRUE(r.is_pending()); |
4226 | 4163 |
4227 MessageLoop::current()->Run(); | 4164 MessageLoop::current()->Run(); |
4228 | 4165 |
4229 EXPECT_FALSE(r.is_pending()); | 4166 EXPECT_FALSE(r.is_pending()); |
4230 EXPECT_EQ(1, d.response_started_count()); | 4167 EXPECT_EQ(1, d.response_started_count()); |
4231 EXPECT_FALSE(d.received_data_before_response()); | 4168 EXPECT_FALSE(d.received_data_before_response()); |
4232 EXPECT_LT(0, d.bytes_received()); | 4169 EXPECT_LT(0, d.bytes_received()); |
4233 EXPECT_EQ(test_server_.host_port_pair().host(), | 4170 EXPECT_EQ(test_server_.host_port_pair().host(), |
4234 r.GetSocketAddress().host()); | 4171 r.GetSocketAddress().host()); |
4235 EXPECT_EQ(test_server_.host_port_pair().port(), | 4172 EXPECT_EQ(test_server_.host_port_pair().port(), |
4236 r.GetSocketAddress().port()); | 4173 r.GetSocketAddress().port()); |
4237 } | 4174 } |
4238 } | 4175 } |
4239 | 4176 |
4240 // Flaky, see http://crbug.com/25045. | 4177 // Flaky, see http://crbug.com/25045. |
4241 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { | 4178 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { |
4242 ASSERT_TRUE(test_server_.Start()); | 4179 ASSERT_TRUE(test_server_.Start()); |
4243 | 4180 |
4244 FilePath app_path; | 4181 FilePath app_path; |
4245 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4182 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
4246 app_path = app_path.AppendASCII("LICENSE"); | 4183 app_path = app_path.AppendASCII("LICENSE"); |
4247 TestDelegate d; | 4184 TestDelegate d; |
4248 { | 4185 { |
4249 URLRequest r(test_server_.GetURL("/LICENSE"), &d); | 4186 URLRequest r(test_server_.GetURL("/LICENSE"), &d, &default_context_); |
4250 r.set_context(&default_context_); | |
4251 r.Start(); | 4187 r.Start(); |
4252 EXPECT_TRUE(r.is_pending()); | 4188 EXPECT_TRUE(r.is_pending()); |
4253 | 4189 |
4254 MessageLoop::current()->Run(); | 4190 MessageLoop::current()->Run(); |
4255 | 4191 |
4256 int64 file_size = 0; | 4192 int64 file_size = 0; |
4257 file_util::GetFileSize(app_path, &file_size); | 4193 file_util::GetFileSize(app_path, &file_size); |
4258 | 4194 |
4259 EXPECT_FALSE(r.is_pending()); | 4195 EXPECT_FALSE(r.is_pending()); |
4260 EXPECT_EQ(1, d.response_started_count()); | 4196 EXPECT_EQ(1, d.response_started_count()); |
(...skipping 10 matching lines...) Expand all Loading... | |
4271 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { | 4207 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { |
4272 ASSERT_TRUE(test_server_.Start()); | 4208 ASSERT_TRUE(test_server_.Start()); |
4273 | 4209 |
4274 FilePath app_path; | 4210 FilePath app_path; |
4275 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4211 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
4276 app_path = app_path.AppendASCII("LICENSE"); | 4212 app_path = app_path.AppendASCII("LICENSE"); |
4277 TestDelegate d; | 4213 TestDelegate d; |
4278 { | 4214 { |
4279 URLRequest r( | 4215 URLRequest r( |
4280 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 4216 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), |
4281 &d); | 4217 &d, |
4282 r.set_context(&default_context_); | 4218 &default_context_); |
4283 r.Start(); | 4219 r.Start(); |
4284 EXPECT_TRUE(r.is_pending()); | 4220 EXPECT_TRUE(r.is_pending()); |
4285 | 4221 |
4286 MessageLoop::current()->Run(); | 4222 MessageLoop::current()->Run(); |
4287 | 4223 |
4288 int64 file_size = 0; | 4224 int64 file_size = 0; |
4289 file_util::GetFileSize(app_path, &file_size); | 4225 file_util::GetFileSize(app_path, &file_size); |
4290 | 4226 |
4291 EXPECT_FALSE(r.is_pending()); | 4227 EXPECT_FALSE(r.is_pending()); |
4292 EXPECT_EQ(test_server_.host_port_pair().host(), | 4228 EXPECT_EQ(test_server_.host_port_pair().host(), |
(...skipping 12 matching lines...) Expand all Loading... | |
4305 | 4241 |
4306 FilePath app_path; | 4242 FilePath app_path; |
4307 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4243 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
4308 app_path = app_path.AppendASCII("LICENSE"); | 4244 app_path = app_path.AppendASCII("LICENSE"); |
4309 TestDelegate d; | 4245 TestDelegate d; |
4310 { | 4246 { |
4311 URLRequest r( | 4247 URLRequest r( |
4312 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4248 test_server_.GetURLWithUserAndPassword("/LICENSE", |
4313 "chrome", | 4249 "chrome", |
4314 "wrong_password"), | 4250 "wrong_password"), |
4315 &d); | 4251 &d, |
4316 r.set_context(&default_context_); | 4252 &default_context_); |
4317 r.Start(); | 4253 r.Start(); |
4318 EXPECT_TRUE(r.is_pending()); | 4254 EXPECT_TRUE(r.is_pending()); |
4319 | 4255 |
4320 MessageLoop::current()->Run(); | 4256 MessageLoop::current()->Run(); |
4321 | 4257 |
4322 int64 file_size = 0; | 4258 int64 file_size = 0; |
4323 file_util::GetFileSize(app_path, &file_size); | 4259 file_util::GetFileSize(app_path, &file_size); |
4324 | 4260 |
4325 EXPECT_FALSE(r.is_pending()); | 4261 EXPECT_FALSE(r.is_pending()); |
4326 EXPECT_EQ(1, d.response_started_count()); | 4262 EXPECT_EQ(1, d.response_started_count()); |
(...skipping 11 matching lines...) Expand all Loading... | |
4338 app_path = app_path.AppendASCII("LICENSE"); | 4274 app_path = app_path.AppendASCII("LICENSE"); |
4339 TestDelegate d; | 4275 TestDelegate d; |
4340 // Set correct login credentials. The delegate will be asked for them when | 4276 // Set correct login credentials. The delegate will be asked for them when |
4341 // the initial login with wrong credentials will fail. | 4277 // the initial login with wrong credentials will fail. |
4342 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 4278 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
4343 { | 4279 { |
4344 URLRequest r( | 4280 URLRequest r( |
4345 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4281 test_server_.GetURLWithUserAndPassword("/LICENSE", |
4346 "chrome", | 4282 "chrome", |
4347 "wrong_password"), | 4283 "wrong_password"), |
4348 &d); | 4284 &d, |
4349 r.set_context(&default_context_); | 4285 &default_context_); |
4350 r.Start(); | 4286 r.Start(); |
4351 EXPECT_TRUE(r.is_pending()); | 4287 EXPECT_TRUE(r.is_pending()); |
4352 | 4288 |
4353 MessageLoop::current()->Run(); | 4289 MessageLoop::current()->Run(); |
4354 | 4290 |
4355 int64 file_size = 0; | 4291 int64 file_size = 0; |
4356 file_util::GetFileSize(app_path, &file_size); | 4292 file_util::GetFileSize(app_path, &file_size); |
4357 | 4293 |
4358 EXPECT_FALSE(r.is_pending()); | 4294 EXPECT_FALSE(r.is_pending()); |
4359 EXPECT_EQ(1, d.response_started_count()); | 4295 EXPECT_EQ(1, d.response_started_count()); |
4360 EXPECT_FALSE(d.received_data_before_response()); | 4296 EXPECT_FALSE(d.received_data_before_response()); |
4361 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 4297 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
4362 } | 4298 } |
4363 } | 4299 } |
4364 | 4300 |
4365 // Flaky, see http://crbug.com/25045. | 4301 // Flaky, see http://crbug.com/25045. |
4366 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { | 4302 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { |
4367 ASSERT_TRUE(test_server_.Start()); | 4303 ASSERT_TRUE(test_server_.Start()); |
4368 | 4304 |
4369 FilePath app_path; | 4305 FilePath app_path; |
4370 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4306 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
4371 app_path = app_path.AppendASCII("LICENSE"); | 4307 app_path = app_path.AppendASCII("LICENSE"); |
4372 TestDelegate d; | 4308 TestDelegate d; |
4373 { | 4309 { |
4374 URLRequest r( | 4310 URLRequest r( |
4375 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4311 test_server_.GetURLWithUserAndPassword("/LICENSE", |
4376 "wrong_user", | 4312 "wrong_user", |
4377 "chrome"), | 4313 "chrome"), |
4378 &d); | 4314 &d, |
4379 r.set_context(&default_context_); | 4315 &default_context_); |
4380 r.Start(); | 4316 r.Start(); |
4381 EXPECT_TRUE(r.is_pending()); | 4317 EXPECT_TRUE(r.is_pending()); |
4382 | 4318 |
4383 MessageLoop::current()->Run(); | 4319 MessageLoop::current()->Run(); |
4384 | 4320 |
4385 int64 file_size = 0; | 4321 int64 file_size = 0; |
4386 file_util::GetFileSize(app_path, &file_size); | 4322 file_util::GetFileSize(app_path, &file_size); |
4387 | 4323 |
4388 EXPECT_FALSE(r.is_pending()); | 4324 EXPECT_FALSE(r.is_pending()); |
4389 EXPECT_EQ(1, d.response_started_count()); | 4325 EXPECT_EQ(1, d.response_started_count()); |
(...skipping 11 matching lines...) Expand all Loading... | |
4401 app_path = app_path.AppendASCII("LICENSE"); | 4337 app_path = app_path.AppendASCII("LICENSE"); |
4402 TestDelegate d; | 4338 TestDelegate d; |
4403 // Set correct login credentials. The delegate will be asked for them when | 4339 // Set correct login credentials. The delegate will be asked for them when |
4404 // the initial login with wrong credentials will fail. | 4340 // the initial login with wrong credentials will fail. |
4405 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 4341 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
4406 { | 4342 { |
4407 URLRequest r( | 4343 URLRequest r( |
4408 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4344 test_server_.GetURLWithUserAndPassword("/LICENSE", |
4409 "wrong_user", | 4345 "wrong_user", |
4410 "chrome"), | 4346 "chrome"), |
4411 &d); | 4347 &d, |
4412 r.set_context(&default_context_); | 4348 &default_context_); |
4413 r.Start(); | 4349 r.Start(); |
4414 EXPECT_TRUE(r.is_pending()); | 4350 EXPECT_TRUE(r.is_pending()); |
4415 | 4351 |
4416 MessageLoop::current()->Run(); | 4352 MessageLoop::current()->Run(); |
4417 | 4353 |
4418 int64 file_size = 0; | 4354 int64 file_size = 0; |
4419 file_util::GetFileSize(app_path, &file_size); | 4355 file_util::GetFileSize(app_path, &file_size); |
4420 | 4356 |
4421 EXPECT_FALSE(r.is_pending()); | 4357 EXPECT_FALSE(r.is_pending()); |
4422 EXPECT_EQ(1, d.response_started_count()); | 4358 EXPECT_EQ(1, d.response_started_count()); |
(...skipping 10 matching lines...) Expand all Loading... | |
4433 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 4369 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
4434 app_path = app_path.AppendASCII("LICENSE"); | 4370 app_path = app_path.AppendASCII("LICENSE"); |
4435 | 4371 |
4436 scoped_ptr<TestDelegate> d(new TestDelegate); | 4372 scoped_ptr<TestDelegate> d(new TestDelegate); |
4437 { | 4373 { |
4438 // Pass correct login identity in the URL. | 4374 // Pass correct login identity in the URL. |
4439 URLRequest r( | 4375 URLRequest r( |
4440 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4376 test_server_.GetURLWithUserAndPassword("/LICENSE", |
4441 "chrome", | 4377 "chrome", |
4442 "chrome"), | 4378 "chrome"), |
4443 d.get()); | 4379 d.get(), |
4444 r.set_context(&default_context_); | 4380 &default_context_); |
4445 r.Start(); | 4381 r.Start(); |
4446 EXPECT_TRUE(r.is_pending()); | 4382 EXPECT_TRUE(r.is_pending()); |
4447 | 4383 |
4448 MessageLoop::current()->Run(); | 4384 MessageLoop::current()->Run(); |
4449 | 4385 |
4450 int64 file_size = 0; | 4386 int64 file_size = 0; |
4451 file_util::GetFileSize(app_path, &file_size); | 4387 file_util::GetFileSize(app_path, &file_size); |
4452 | 4388 |
4453 EXPECT_FALSE(r.is_pending()); | 4389 EXPECT_FALSE(r.is_pending()); |
4454 EXPECT_EQ(1, d->response_started_count()); | 4390 EXPECT_EQ(1, d->response_started_count()); |
4455 EXPECT_FALSE(d->received_data_before_response()); | 4391 EXPECT_FALSE(d->received_data_before_response()); |
4456 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4392 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
4457 } | 4393 } |
4458 | 4394 |
4459 d.reset(new TestDelegate); | 4395 d.reset(new TestDelegate); |
4460 { | 4396 { |
4461 // This request should use cached identity from previous request. | 4397 // This request should use cached identity from previous request. |
4462 URLRequest r(test_server_.GetURL("/LICENSE"), d.get()); | 4398 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); |
4463 r.set_context(&default_context_); | |
4464 r.Start(); | 4399 r.Start(); |
4465 EXPECT_TRUE(r.is_pending()); | 4400 EXPECT_TRUE(r.is_pending()); |
4466 | 4401 |
4467 MessageLoop::current()->Run(); | 4402 MessageLoop::current()->Run(); |
4468 | 4403 |
4469 int64 file_size = 0; | 4404 int64 file_size = 0; |
4470 file_util::GetFileSize(app_path, &file_size); | 4405 file_util::GetFileSize(app_path, &file_size); |
4471 | 4406 |
4472 EXPECT_FALSE(r.is_pending()); | 4407 EXPECT_FALSE(r.is_pending()); |
4473 EXPECT_EQ(1, d->response_started_count()); | 4408 EXPECT_EQ(1, d->response_started_count()); |
(...skipping 12 matching lines...) Expand all Loading... | |
4486 | 4421 |
4487 scoped_ptr<TestDelegate> d(new TestDelegate); | 4422 scoped_ptr<TestDelegate> d(new TestDelegate); |
4488 // Set correct login credentials. The delegate will be asked for them when | 4423 // Set correct login credentials. The delegate will be asked for them when |
4489 // the initial login with wrong credentials will fail. | 4424 // the initial login with wrong credentials will fail. |
4490 d->set_credentials(AuthCredentials(kChrome, kChrome)); | 4425 d->set_credentials(AuthCredentials(kChrome, kChrome)); |
4491 { | 4426 { |
4492 URLRequest r( | 4427 URLRequest r( |
4493 test_server_.GetURLWithUserAndPassword("/LICENSE", | 4428 test_server_.GetURLWithUserAndPassword("/LICENSE", |
4494 "chrome", | 4429 "chrome", |
4495 "wrong_password"), | 4430 "wrong_password"), |
4496 d.get()); | 4431 d.get(), |
4497 r.set_context(&default_context_); | 4432 &default_context_); |
4498 r.Start(); | 4433 r.Start(); |
4499 EXPECT_TRUE(r.is_pending()); | 4434 EXPECT_TRUE(r.is_pending()); |
4500 | 4435 |
4501 MessageLoop::current()->Run(); | 4436 MessageLoop::current()->Run(); |
4502 | 4437 |
4503 int64 file_size = 0; | 4438 int64 file_size = 0; |
4504 file_util::GetFileSize(app_path, &file_size); | 4439 file_util::GetFileSize(app_path, &file_size); |
4505 | 4440 |
4506 EXPECT_FALSE(r.is_pending()); | 4441 EXPECT_FALSE(r.is_pending()); |
4507 EXPECT_EQ(1, d->response_started_count()); | 4442 EXPECT_EQ(1, d->response_started_count()); |
4508 EXPECT_FALSE(d->received_data_before_response()); | 4443 EXPECT_FALSE(d->received_data_before_response()); |
4509 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4444 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
4510 } | 4445 } |
4511 | 4446 |
4512 // Use a new delegate without explicit credentials. The cached ones should be | 4447 // Use a new delegate without explicit credentials. The cached ones should be |
4513 // used. | 4448 // used. |
4514 d.reset(new TestDelegate); | 4449 d.reset(new TestDelegate); |
4515 { | 4450 { |
4516 // Don't pass wrong credentials in the URL, they would override valid cached | 4451 // Don't pass wrong credentials in the URL, they would override valid cached |
4517 // ones. | 4452 // ones. |
4518 URLRequest r(test_server_.GetURL("/LICENSE"), d.get()); | 4453 URLRequest r(test_server_.GetURL("/LICENSE"), d.get(), &default_context_); |
4519 r.set_context(&default_context_); | |
4520 r.Start(); | 4454 r.Start(); |
4521 EXPECT_TRUE(r.is_pending()); | 4455 EXPECT_TRUE(r.is_pending()); |
4522 | 4456 |
4523 MessageLoop::current()->Run(); | 4457 MessageLoop::current()->Run(); |
4524 | 4458 |
4525 int64 file_size = 0; | 4459 int64 file_size = 0; |
4526 file_util::GetFileSize(app_path, &file_size); | 4460 file_util::GetFileSize(app_path, &file_size); |
4527 | 4461 |
4528 EXPECT_FALSE(r.is_pending()); | 4462 EXPECT_FALSE(r.is_pending()); |
4529 EXPECT_EQ(1, d->response_started_count()); | 4463 EXPECT_EQ(1, d->response_started_count()); |
4530 EXPECT_FALSE(d->received_data_before_response()); | 4464 EXPECT_FALSE(d->received_data_before_response()); |
4531 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 4465 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
4532 } | 4466 } |
4533 } | 4467 } |
4534 | 4468 |
4535 // Check that default A-L header is sent. | 4469 // Check that default A-L header is sent. |
4536 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { | 4470 TEST_F(URLRequestTestHTTP, DefaultAcceptLanguage) { |
4537 ASSERT_TRUE(test_server_.Start()); | 4471 ASSERT_TRUE(test_server_.Start()); |
4538 | 4472 |
4539 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4473 TestNetworkDelegate network_delegate; // must outlive URLRequests |
4540 TestURLRequestContext context(true); | 4474 TestURLRequestContext context(true); |
4541 context.set_network_delegate(&network_delegate); | 4475 context.set_network_delegate(&network_delegate); |
4542 context.set_accept_language("en"); | 4476 context.set_accept_language("en"); |
4543 context.Init(); | 4477 context.Init(); |
4544 | 4478 |
4545 TestDelegate d; | 4479 TestDelegate d; |
4546 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 4480 URLRequest req( |
4547 req.set_context(&context); | 4481 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); |
4548 req.Start(); | 4482 req.Start(); |
4549 MessageLoop::current()->Run(); | 4483 MessageLoop::current()->Run(); |
4550 EXPECT_EQ("en", d.data_received()); | 4484 EXPECT_EQ("en", d.data_received()); |
4551 } | 4485 } |
4552 | 4486 |
4553 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 4487 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
4554 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 4488 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
4555 ASSERT_TRUE(test_server_.Start()); | 4489 ASSERT_TRUE(test_server_.Start()); |
4556 | 4490 |
4557 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4491 TestNetworkDelegate network_delegate; // must outlive URLRequests |
4558 TestURLRequestContext context(true); | 4492 TestURLRequestContext context(true); |
4559 context.set_network_delegate(&network_delegate); | 4493 context.set_network_delegate(&network_delegate); |
4560 context.Init(); | 4494 context.Init(); |
4561 // We override the language after initialization because empty entries | 4495 // We override the language after initialization because empty entries |
4562 // get overridden by Init(). | 4496 // get overridden by Init(). |
4563 context.set_accept_language(""); | 4497 context.set_accept_language(""); |
4564 | 4498 |
4565 TestDelegate d; | 4499 TestDelegate d; |
4566 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 4500 URLRequest req( |
4567 req.set_context(&context); | 4501 test_server_.GetURL("echoheader?Accept-Language"), &d, &context); |
4568 req.Start(); | 4502 req.Start(); |
4569 MessageLoop::current()->Run(); | 4503 MessageLoop::current()->Run(); |
4570 EXPECT_EQ("None", d.data_received()); | 4504 EXPECT_EQ("None", d.data_received()); |
4571 } | 4505 } |
4572 | 4506 |
4573 // Check that if request overrides the A-L header, the default is not appended. | 4507 // Check that if request overrides the A-L header, the default is not appended. |
4574 // See http://crbug.com/20894 | 4508 // See http://crbug.com/20894 |
4575 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 4509 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
4576 ASSERT_TRUE(test_server_.Start()); | 4510 ASSERT_TRUE(test_server_.Start()); |
4577 | 4511 |
4578 TestDelegate d; | 4512 TestDelegate d; |
4579 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), &d); | 4513 URLRequest req(test_server_.GetURL("echoheader?Accept-Language"), |
4580 req.set_context(&default_context_); | 4514 &d, |
4515 &default_context_); | |
4581 HttpRequestHeaders headers; | 4516 HttpRequestHeaders headers; |
4582 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); | 4517 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); |
4583 req.SetExtraRequestHeaders(headers); | 4518 req.SetExtraRequestHeaders(headers); |
4584 req.Start(); | 4519 req.Start(); |
4585 MessageLoop::current()->Run(); | 4520 MessageLoop::current()->Run(); |
4586 EXPECT_EQ(std::string("ru"), d.data_received()); | 4521 EXPECT_EQ(std::string("ru"), d.data_received()); |
4587 } | 4522 } |
4588 | 4523 |
4589 // Check that default A-E header is sent. | 4524 // Check that default A-E header is sent. |
4590 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { | 4525 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { |
4591 ASSERT_TRUE(test_server_.Start()); | 4526 ASSERT_TRUE(test_server_.Start()); |
4592 | 4527 |
4593 TestDelegate d; | 4528 TestDelegate d; |
4594 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); | 4529 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), |
4595 req.set_context(&default_context_); | 4530 &d, |
4531 &default_context_); | |
4596 HttpRequestHeaders headers; | 4532 HttpRequestHeaders headers; |
4597 req.SetExtraRequestHeaders(headers); | 4533 req.SetExtraRequestHeaders(headers); |
4598 req.Start(); | 4534 req.Start(); |
4599 MessageLoop::current()->Run(); | 4535 MessageLoop::current()->Run(); |
4600 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); | 4536 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); |
4601 } | 4537 } |
4602 | 4538 |
4603 // Check that if request overrides the A-E header, the default is not appended. | 4539 // Check that if request overrides the A-E header, the default is not appended. |
4604 // See http://crbug.com/47381 | 4540 // See http://crbug.com/47381 |
4605 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { | 4541 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { |
4606 ASSERT_TRUE(test_server_.Start()); | 4542 ASSERT_TRUE(test_server_.Start()); |
4607 | 4543 |
4608 TestDelegate d; | 4544 TestDelegate d; |
4609 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), &d); | 4545 URLRequest req(test_server_.GetURL("echoheader?Accept-Encoding"), |
4610 req.set_context(&default_context_); | 4546 &d, |
4547 &default_context_); | |
4611 HttpRequestHeaders headers; | 4548 HttpRequestHeaders headers; |
4612 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); | 4549 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); |
4613 req.SetExtraRequestHeaders(headers); | 4550 req.SetExtraRequestHeaders(headers); |
4614 req.Start(); | 4551 req.Start(); |
4615 MessageLoop::current()->Run(); | 4552 MessageLoop::current()->Run(); |
4616 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); | 4553 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); |
4617 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 4554 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
4618 } | 4555 } |
4619 | 4556 |
4620 // Check that default A-C header is sent. | 4557 // Check that default A-C header is sent. |
4621 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { | 4558 TEST_F(URLRequestTestHTTP, DefaultAcceptCharset) { |
4622 ASSERT_TRUE(test_server_.Start()); | 4559 ASSERT_TRUE(test_server_.Start()); |
4623 | 4560 |
4624 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4561 TestNetworkDelegate network_delegate; // must outlive URLRequests |
4625 TestURLRequestContext context(true); | 4562 TestURLRequestContext context(true); |
4626 context.set_network_delegate(&network_delegate); | 4563 context.set_network_delegate(&network_delegate); |
4627 context.set_accept_charset("en"); | 4564 context.set_accept_charset("en"); |
4628 context.Init(); | 4565 context.Init(); |
4629 | 4566 |
4630 TestDelegate d; | 4567 TestDelegate d; |
4631 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 4568 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
4632 req.set_context(&context); | 4569 &d, |
4570 &context); | |
4633 req.Start(); | 4571 req.Start(); |
4634 MessageLoop::current()->Run(); | 4572 MessageLoop::current()->Run(); |
4635 EXPECT_EQ("en", d.data_received()); | 4573 EXPECT_EQ("en", d.data_received()); |
4636 } | 4574 } |
4637 | 4575 |
4638 // Check that an empty A-C header is not sent. http://crbug.com/77365. | 4576 // Check that an empty A-C header is not sent. http://crbug.com/77365. |
4639 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { | 4577 TEST_F(URLRequestTestHTTP, EmptyAcceptCharset) { |
4640 ASSERT_TRUE(test_server_.Start()); | 4578 ASSERT_TRUE(test_server_.Start()); |
4641 | 4579 |
4642 TestNetworkDelegate network_delegate; // must outlive URLRequests | 4580 TestNetworkDelegate network_delegate; // must outlive URLRequests |
4643 TestURLRequestContext context(true); | 4581 TestURLRequestContext context(true); |
4644 context.set_network_delegate(&network_delegate); | 4582 context.set_network_delegate(&network_delegate); |
4645 context.Init(); | 4583 context.Init(); |
4646 // We override the accepted charset after initialization because empty | 4584 // We override the accepted charset after initialization because empty |
4647 // entries get overridden otherwise. | 4585 // entries get overridden otherwise. |
4648 context.set_accept_charset(""); | 4586 context.set_accept_charset(""); |
4649 | 4587 |
4650 TestDelegate d; | 4588 TestDelegate d; |
4651 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 4589 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
4652 req.set_context(&context); | 4590 &d, |
4591 &context); | |
4653 req.Start(); | 4592 req.Start(); |
4654 MessageLoop::current()->Run(); | 4593 MessageLoop::current()->Run(); |
4655 EXPECT_EQ("None", d.data_received()); | 4594 EXPECT_EQ("None", d.data_received()); |
4656 } | 4595 } |
4657 | 4596 |
4658 // Check that if request overrides the A-C header, the default is not appended. | 4597 // Check that if request overrides the A-C header, the default is not appended. |
4659 // See http://crbug.com/20894 | 4598 // See http://crbug.com/20894 |
4660 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { | 4599 TEST_F(URLRequestTestHTTP, OverrideAcceptCharset) { |
4661 ASSERT_TRUE(test_server_.Start()); | 4600 ASSERT_TRUE(test_server_.Start()); |
4662 | 4601 |
4663 TestDelegate d; | 4602 TestDelegate d; |
4664 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), &d); | 4603 URLRequest req(test_server_.GetURL("echoheader?Accept-Charset"), |
4665 req.set_context(&default_context_); | 4604 &d, |
4605 &default_context_); | |
4666 HttpRequestHeaders headers; | 4606 HttpRequestHeaders headers; |
4667 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 4607 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
4668 req.SetExtraRequestHeaders(headers); | 4608 req.SetExtraRequestHeaders(headers); |
4669 req.Start(); | 4609 req.Start(); |
4670 MessageLoop::current()->Run(); | 4610 MessageLoop::current()->Run(); |
4671 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 4611 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
4672 } | 4612 } |
4673 | 4613 |
4674 // Check that default User-Agent header is sent. | 4614 // Check that default User-Agent header is sent. |
4675 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { | 4615 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { |
4676 ASSERT_TRUE(test_server_.Start()); | 4616 ASSERT_TRUE(test_server_.Start()); |
4677 | 4617 |
4678 TestDelegate d; | 4618 TestDelegate d; |
4679 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); | 4619 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), |
4680 req.set_context(&default_context_); | 4620 &d, |
4621 &default_context_); | |
4681 req.Start(); | 4622 req.Start(); |
4682 MessageLoop::current()->Run(); | 4623 MessageLoop::current()->Run(); |
4683 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); | 4624 EXPECT_EQ(req.context()->GetUserAgent(req.url()), d.data_received()); |
4684 } | 4625 } |
4685 | 4626 |
4686 // Check that if request overrides the User-Agent header, | 4627 // Check that if request overrides the User-Agent header, |
4687 // the default is not appended. | 4628 // the default is not appended. |
4688 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { | 4629 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { |
4689 ASSERT_TRUE(test_server_.Start()); | 4630 ASSERT_TRUE(test_server_.Start()); |
4690 | 4631 |
4691 TestDelegate d; | 4632 TestDelegate d; |
4692 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), &d); | 4633 URLRequest req(test_server_.GetURL("echoheader?User-Agent"), |
4693 req.set_context(&default_context_); | 4634 &d, |
4635 &default_context_); | |
4694 HttpRequestHeaders headers; | 4636 HttpRequestHeaders headers; |
4695 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 4637 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
4696 req.SetExtraRequestHeaders(headers); | 4638 req.SetExtraRequestHeaders(headers); |
4697 req.Start(); | 4639 req.Start(); |
4698 MessageLoop::current()->Run(); | 4640 MessageLoop::current()->Run(); |
4699 // If the net tests are being run with ChromeFrame then we need to allow for | 4641 // If the net tests are being run with ChromeFrame then we need to allow for |
4700 // the 'chromeframe' suffix which is added to the user agent before the | 4642 // the 'chromeframe' suffix which is added to the user agent before the |
4701 // closing parentheses. | 4643 // closing parentheses. |
4702 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 4644 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
4703 } | 4645 } |
4704 | 4646 |
4705 } // namespace net | 4647 } // namespace net |
OLD | NEW |