Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(600)

Side by Side Diff: net/url_request/url_request_unittest.cc

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

Powered by Google App Engine
This is Rietveld 408576698