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

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

Issue 1003953008: Remove prerender cookie store, part 4. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@prerender-revert-cookie-store-3
Patch Set: Created 5 years, 9 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 644 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. 655 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest.
656 URLRequestJobFactoryImpl* job_factory_impl_; 656 URLRequestJobFactoryImpl* job_factory_impl_;
657 scoped_ptr<URLRequestJobFactory> job_factory_; 657 scoped_ptr<URLRequestJobFactory> job_factory_;
658 TestURLRequestContext default_context_; 658 TestURLRequestContext default_context_;
659 }; 659 };
660 660
661 TEST_F(URLRequestTest, AboutBlankTest) { 661 TEST_F(URLRequestTest, AboutBlankTest) {
662 TestDelegate d; 662 TestDelegate d;
663 { 663 {
664 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 664 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
665 GURL("about:blank"), DEFAULT_PRIORITY, &d, NULL)); 665 GURL("about:blank"), DEFAULT_PRIORITY, &d));
666 666
667 r->Start(); 667 r->Start();
668 EXPECT_TRUE(r->is_pending()); 668 EXPECT_TRUE(r->is_pending());
669 669
670 base::RunLoop().Run(); 670 base::RunLoop().Run();
671 671
672 EXPECT_TRUE(!r->is_pending()); 672 EXPECT_TRUE(!r->is_pending());
673 EXPECT_FALSE(d.received_data_before_response()); 673 EXPECT_FALSE(d.received_data_before_response());
674 EXPECT_EQ(d.bytes_received(), 0); 674 EXPECT_EQ(d.bytes_received(), 0);
675 EXPECT_EQ("", r->GetSocketAddress().host()); 675 EXPECT_EQ("", r->GetSocketAddress().host());
676 EXPECT_EQ(0, r->GetSocketAddress().port()); 676 EXPECT_EQ(0, r->GetSocketAddress().port());
677 677
678 HttpRequestHeaders headers; 678 HttpRequestHeaders headers;
679 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); 679 EXPECT_FALSE(r->GetFullRequestHeaders(&headers));
680 } 680 }
681 } 681 }
682 682
683 TEST_F(URLRequestTest, DataURLImageTest) { 683 TEST_F(URLRequestTest, DataURLImageTest) {
684 TestDelegate d; 684 TestDelegate d;
685 { 685 {
686 // Use our nice little Chrome logo. 686 // Use our nice little Chrome logo.
687 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 687 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
688 GURL( 688 GURL(
689 "data:image/png;base64," 689 "data:image/png;base64,"
690 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAADVklEQVQ4jX2TfUwUBBjG3" 690 "iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/"
691 "w1y+HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD" 691 "9hAAADVklEQVQ4jX2TfUwUBBjG3"
692 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/P827vnucRmYN0gyF01GI5MpCVdW0gO7t" 692 "w1y+"
693 "vNC+vqSEtbZefk5NuLv1jdJ46p/zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9" 693 "HGcd9dxhXR8T4awOccJGgOSWclHImznLkTlSw0DDQXkrmgYgbUYnlQTqQxIEVxitD"
694 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/MWq12UctI1" 694 "5UMCATRA1CEEg+Qjw3bWDxIauJv/5oumqs39/"
695 "dWWm99ypqSYmRUBdKem8MkrO/kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z" 695 "P827vnucRmYN0gyF01GI5MpCVdW0gO7t"
696 "wbtlLTVMZ3BW+TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW" 696 "vNC+vqSEtbZefk5NuLv1jdJ46p/"
697 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW" 697 "zw0HeH4+PHr3h7c1mjoV2t5rKzMx1+fg9bAgK6zHq9"
698 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTb" 698 "cU5z+LpA3xOtx34+vTeT21onRuzssC3zxbbSwC13d/pFuC7CkIMDxQpF7r/"
699 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5" 699 "MWq12UctI1"
700 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV" 700 "dWWm99ypqSYmRUBdKem8MkrO/"
701 "Md6q5c8GdosynKmSeRuGzpjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq" 701 "kgaTt1O7YzlpzE5GIVd0WYUqt57yWf2McHTObYPbVD+Z"
702 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7F" 702 "wbtlLTVMZ3BW+"
703 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB" 703 "TnLyXLaWtmEq6WJVbT3HBh3Svj2HQQcm43XwmtoYM6vVKleh0uoWvnzW"
704 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJM" 704 "3v3MpidruPTQPf0bia7sJOtBM0ufTWNvus/"
705 "nlm2O34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm" 705 "nkDFHF9ZS+uYVjRUasMeHUmyLYtcklTvzW"
706 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV5En" 706 "GFZnNOXczThvpKIzjcahSqIzkvDLayDq6D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4Ioy"
707 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), 707 "hTb"
708 DEFAULT_PRIORITY, &d, NULL)); 708 "xXX1T5xsV9tm9r4TQwHLiZw/pdDZJea8TKmsmR/K0uLh/"
709 "GwnCHghTja6lPhphezPfO5/5"
710 "MrVvMzNaI3+ERHfrFzPKQukrQGI4d/3EFD/"
711 "3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gV"
712 "Md6q5c8GdosynKmSeRuGzpjyl1/"
713 "9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq"
714 "/uxxZKzNiZFGD0wRC3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/"
715 "sYH7DAbwlgC4J+R2Z7F"
716 "Ux1qLnV7MGF40smVSoJ/jvHRfYhQeUJd/"
717 "SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufB"
718 "JbsysjjW4kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+"
719 "TGaJM"
720 "nlm2O34uI4b9tflqp1+QEFGzoW/"
721 "ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfm"
722 "moRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/"
723 "G6W9iLiIyCoReV5En"
724 "hORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="),
725 DEFAULT_PRIORITY, &d));
709 726
710 r->Start(); 727 r->Start();
711 EXPECT_TRUE(r->is_pending()); 728 EXPECT_TRUE(r->is_pending());
712 729
713 base::RunLoop().Run(); 730 base::RunLoop().Run();
714 731
715 EXPECT_TRUE(!r->is_pending()); 732 EXPECT_TRUE(!r->is_pending());
716 EXPECT_FALSE(d.received_data_before_response()); 733 EXPECT_FALSE(d.received_data_before_response());
717 EXPECT_EQ(d.bytes_received(), 911); 734 EXPECT_EQ(d.bytes_received(), 911);
718 EXPECT_EQ("", r->GetSocketAddress().host()); 735 EXPECT_EQ("", r->GetSocketAddress().host());
719 EXPECT_EQ(0, r->GetSocketAddress().port()); 736 EXPECT_EQ(0, r->GetSocketAddress().port());
720 737
721 HttpRequestHeaders headers; 738 HttpRequestHeaders headers;
722 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); 739 EXPECT_FALSE(r->GetFullRequestHeaders(&headers));
723 } 740 }
724 } 741 }
725 742
726 #if !defined(DISABLE_FILE_SUPPORT) 743 #if !defined(DISABLE_FILE_SUPPORT)
727 TEST_F(URLRequestTest, FileTest) { 744 TEST_F(URLRequestTest, FileTest) {
728 base::FilePath app_path; 745 base::FilePath app_path;
729 PathService::Get(base::FILE_EXE, &app_path); 746 PathService::Get(base::FILE_EXE, &app_path);
730 GURL app_url = FilePathToFileURL(app_path); 747 GURL app_url = FilePathToFileURL(app_path);
731 748
732 TestDelegate d; 749 TestDelegate d;
733 { 750 {
734 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 751 scoped_ptr<URLRequest> r(
735 app_url, DEFAULT_PRIORITY, &d, NULL)); 752 default_context_.CreateRequest(app_url, DEFAULT_PRIORITY, &d));
736 753
737 r->Start(); 754 r->Start();
738 EXPECT_TRUE(r->is_pending()); 755 EXPECT_TRUE(r->is_pending());
739 756
740 base::RunLoop().Run(); 757 base::RunLoop().Run();
741 758
742 int64 file_size = -1; 759 int64 file_size = -1;
743 EXPECT_TRUE(base::GetFileSize(app_path, &file_size)); 760 EXPECT_TRUE(base::GetFileSize(app_path, &file_size));
744 761
745 EXPECT_TRUE(!r->is_pending()); 762 EXPECT_TRUE(!r->is_pending());
746 EXPECT_EQ(1, d.response_started_count()); 763 EXPECT_EQ(1, d.response_started_count());
747 EXPECT_FALSE(d.received_data_before_response()); 764 EXPECT_FALSE(d.received_data_before_response());
748 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 765 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
749 EXPECT_EQ("", r->GetSocketAddress().host()); 766 EXPECT_EQ("", r->GetSocketAddress().host());
750 EXPECT_EQ(0, r->GetSocketAddress().port()); 767 EXPECT_EQ(0, r->GetSocketAddress().port());
751 768
752 HttpRequestHeaders headers; 769 HttpRequestHeaders headers;
753 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); 770 EXPECT_FALSE(r->GetFullRequestHeaders(&headers));
754 } 771 }
755 } 772 }
756 773
757 TEST_F(URLRequestTest, FileTestCancel) { 774 TEST_F(URLRequestTest, FileTestCancel) {
758 base::FilePath app_path; 775 base::FilePath app_path;
759 PathService::Get(base::FILE_EXE, &app_path); 776 PathService::Get(base::FILE_EXE, &app_path);
760 GURL app_url = FilePathToFileURL(app_path); 777 GURL app_url = FilePathToFileURL(app_path);
761 778
762 TestDelegate d; 779 TestDelegate d;
763 { 780 {
764 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 781 scoped_ptr<URLRequest> r(
765 app_url, DEFAULT_PRIORITY, &d, NULL)); 782 default_context_.CreateRequest(app_url, DEFAULT_PRIORITY, &d));
766 783
767 r->Start(); 784 r->Start();
768 EXPECT_TRUE(r->is_pending()); 785 EXPECT_TRUE(r->is_pending());
769 r->Cancel(); 786 r->Cancel();
770 } 787 }
771 // Async cancellation should be safe even when URLRequest has been already 788 // Async cancellation should be safe even when URLRequest has been already
772 // destroyed. 789 // destroyed.
773 base::RunLoop().RunUntilIdle(); 790 base::RunLoop().RunUntilIdle();
774 } 791 }
775 792
(...skipping 11 matching lines...) Expand all
787 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 804 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
788 805
789 const size_t first_byte_position = 500; 806 const size_t first_byte_position = 500;
790 const size_t last_byte_position = buffer_size - first_byte_position; 807 const size_t last_byte_position = buffer_size - first_byte_position;
791 const size_t content_length = last_byte_position - first_byte_position + 1; 808 const size_t content_length = last_byte_position - first_byte_position + 1;
792 std::string partial_buffer_string(buffer.get() + first_byte_position, 809 std::string partial_buffer_string(buffer.get() + first_byte_position,
793 buffer.get() + last_byte_position + 1); 810 buffer.get() + last_byte_position + 1);
794 811
795 TestDelegate d; 812 TestDelegate d;
796 { 813 {
797 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 814 scoped_ptr<URLRequest> r(
798 temp_url, DEFAULT_PRIORITY, &d, NULL)); 815 default_context_.CreateRequest(temp_url, DEFAULT_PRIORITY, &d));
799 816
800 HttpRequestHeaders headers; 817 HttpRequestHeaders headers;
801 headers.SetHeader( 818 headers.SetHeader(
802 HttpRequestHeaders::kRange, 819 HttpRequestHeaders::kRange,
803 HttpByteRange::Bounded( 820 HttpByteRange::Bounded(
804 first_byte_position, last_byte_position).GetHeaderValue()); 821 first_byte_position, last_byte_position).GetHeaderValue());
805 r->SetExtraRequestHeaders(headers); 822 r->SetExtraRequestHeaders(headers);
806 r->Start(); 823 r->Start();
807 EXPECT_TRUE(r->is_pending()); 824 EXPECT_TRUE(r->is_pending());
808 825
(...skipping 23 matching lines...) Expand all
832 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 849 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
833 850
834 const size_t first_byte_position = 500; 851 const size_t first_byte_position = 500;
835 const size_t last_byte_position = buffer_size - 1; 852 const size_t last_byte_position = buffer_size - 1;
836 const size_t content_length = last_byte_position - first_byte_position + 1; 853 const size_t content_length = last_byte_position - first_byte_position + 1;
837 std::string partial_buffer_string(buffer.get() + first_byte_position, 854 std::string partial_buffer_string(buffer.get() + first_byte_position,
838 buffer.get() + last_byte_position + 1); 855 buffer.get() + last_byte_position + 1);
839 856
840 TestDelegate d; 857 TestDelegate d;
841 { 858 {
842 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 859 scoped_ptr<URLRequest> r(
843 temp_url, DEFAULT_PRIORITY, &d, NULL)); 860 default_context_.CreateRequest(temp_url, DEFAULT_PRIORITY, &d));
844 861
845 HttpRequestHeaders headers; 862 HttpRequestHeaders headers;
846 headers.SetHeader(HttpRequestHeaders::kRange, 863 headers.SetHeader(HttpRequestHeaders::kRange,
847 HttpByteRange::RightUnbounded( 864 HttpByteRange::RightUnbounded(
848 first_byte_position).GetHeaderValue()); 865 first_byte_position).GetHeaderValue());
849 r->SetExtraRequestHeaders(headers); 866 r->SetExtraRequestHeaders(headers);
850 r->Start(); 867 r->Start();
851 EXPECT_TRUE(r->is_pending()); 868 EXPECT_TRUE(r->is_pending());
852 869
853 base::RunLoop().Run(); 870 base::RunLoop().Run();
(...skipping 16 matching lines...) Expand all
870 base::FilePath temp_path; 887 base::FilePath temp_path;
871 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); 888 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path));
872 GURL temp_url = FilePathToFileURL(temp_path); 889 GURL temp_url = FilePathToFileURL(temp_path);
873 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); 890 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size));
874 891
875 int64 file_size; 892 int64 file_size;
876 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); 893 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size));
877 894
878 TestDelegate d; 895 TestDelegate d;
879 { 896 {
880 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 897 scoped_ptr<URLRequest> r(
881 temp_url, DEFAULT_PRIORITY, &d, NULL)); 898 default_context_.CreateRequest(temp_url, DEFAULT_PRIORITY, &d));
882 899
883 HttpRequestHeaders headers; 900 HttpRequestHeaders headers;
884 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); 901 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300");
885 r->SetExtraRequestHeaders(headers); 902 r->SetExtraRequestHeaders(headers);
886 r->Start(); 903 r->Start();
887 EXPECT_TRUE(r->is_pending()); 904 EXPECT_TRUE(r->is_pending());
888 905
889 base::RunLoop().Run(); 906 base::RunLoop().Run();
890 EXPECT_TRUE(d.request_failed()); 907 EXPECT_TRUE(d.request_failed());
891 } 908 }
892 909
893 EXPECT_TRUE(base::DeleteFile(temp_path, false)); 910 EXPECT_TRUE(base::DeleteFile(temp_path, false));
894 } 911 }
895 912
896 TEST_F(URLRequestTest, AllowFileURLs) { 913 TEST_F(URLRequestTest, AllowFileURLs) {
897 base::ScopedTempDir temp_dir; 914 base::ScopedTempDir temp_dir;
898 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 915 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
899 base::FilePath test_file; 916 base::FilePath test_file;
900 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file)); 917 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.path(), &test_file));
901 std::string test_data("monkey"); 918 std::string test_data("monkey");
902 base::WriteFile(test_file, test_data.data(), test_data.size()); 919 base::WriteFile(test_file, test_data.data(), test_data.size());
903 GURL test_file_url = FilePathToFileURL(test_file); 920 GURL test_file_url = FilePathToFileURL(test_file);
904 921
905 { 922 {
906 TestDelegate d; 923 TestDelegate d;
907 TestNetworkDelegate network_delegate; 924 TestNetworkDelegate network_delegate;
908 network_delegate.set_can_access_files(true); 925 network_delegate.set_can_access_files(true);
909 default_context_.set_network_delegate(&network_delegate); 926 default_context_.set_network_delegate(&network_delegate);
910 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 927 scoped_ptr<URLRequest> r(
911 test_file_url, DEFAULT_PRIORITY, &d, NULL)); 928 default_context_.CreateRequest(test_file_url, DEFAULT_PRIORITY, &d));
912 r->Start(); 929 r->Start();
913 base::RunLoop().Run(); 930 base::RunLoop().Run();
914 EXPECT_FALSE(d.request_failed()); 931 EXPECT_FALSE(d.request_failed());
915 EXPECT_EQ(test_data, d.data_received()); 932 EXPECT_EQ(test_data, d.data_received());
916 } 933 }
917 934
918 { 935 {
919 TestDelegate d; 936 TestDelegate d;
920 TestNetworkDelegate network_delegate; 937 TestNetworkDelegate network_delegate;
921 network_delegate.set_can_access_files(false); 938 network_delegate.set_can_access_files(false);
922 default_context_.set_network_delegate(&network_delegate); 939 default_context_.set_network_delegate(&network_delegate);
923 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 940 scoped_ptr<URLRequest> r(
924 test_file_url, DEFAULT_PRIORITY, &d, NULL)); 941 default_context_.CreateRequest(test_file_url, DEFAULT_PRIORITY, &d));
925 r->Start(); 942 r->Start();
926 base::RunLoop().Run(); 943 base::RunLoop().Run();
927 EXPECT_TRUE(d.request_failed()); 944 EXPECT_TRUE(d.request_failed());
928 EXPECT_EQ("", d.data_received()); 945 EXPECT_EQ("", d.data_received());
929 } 946 }
930 } 947 }
931 948
932 949
933 TEST_F(URLRequestTest, FileDirCancelTest) { 950 TEST_F(URLRequestTest, FileDirCancelTest) {
934 // Put in mock resource provider. 951 // Put in mock resource provider.
935 NetModule::SetResourceProvider(TestNetResourceProvider); 952 NetModule::SetResourceProvider(TestNetResourceProvider);
936 953
937 TestDelegate d; 954 TestDelegate d;
938 { 955 {
939 base::FilePath file_path; 956 base::FilePath file_path;
940 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); 957 PathService::Get(base::DIR_SOURCE_ROOT, &file_path);
941 file_path = file_path.Append(FILE_PATH_LITERAL("net")); 958 file_path = file_path.Append(FILE_PATH_LITERAL("net"));
942 file_path = file_path.Append(FILE_PATH_LITERAL("data")); 959 file_path = file_path.Append(FILE_PATH_LITERAL("data"));
943 960
944 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 961 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
945 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d, NULL)); 962 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d));
946 req->Start(); 963 req->Start();
947 EXPECT_TRUE(req->is_pending()); 964 EXPECT_TRUE(req->is_pending());
948 965
949 d.set_cancel_in_received_data_pending(true); 966 d.set_cancel_in_received_data_pending(true);
950 967
951 base::RunLoop().Run(); 968 base::RunLoop().Run();
952 } 969 }
953 970
954 // Take out mock resource provider. 971 // Take out mock resource provider.
955 NetModule::SetResourceProvider(NULL); 972 NetModule::SetResourceProvider(NULL);
956 } 973 }
957 974
958 TEST_F(URLRequestTest, FileDirOutputSanity) { 975 TEST_F(URLRequestTest, FileDirOutputSanity) {
959 // Verify the general sanity of the the output of the file: 976 // Verify the general sanity of the the output of the file:
960 // directory lister by checking for the output of a known existing 977 // directory lister by checking for the output of a known existing
961 // file. 978 // file.
962 const char sentinel_name[] = "filedir-sentinel"; 979 const char sentinel_name[] = "filedir-sentinel";
963 980
964 base::FilePath path; 981 base::FilePath path;
965 PathService::Get(base::DIR_SOURCE_ROOT, &path); 982 PathService::Get(base::DIR_SOURCE_ROOT, &path);
966 path = path.Append(FILE_PATH_LITERAL("net")); 983 path = path.Append(FILE_PATH_LITERAL("net"));
967 path = path.Append(FILE_PATH_LITERAL("data")); 984 path = path.Append(FILE_PATH_LITERAL("data"));
968 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 985 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
969 986
970 TestDelegate d; 987 TestDelegate d;
971 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 988 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
972 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, NULL)); 989 FilePathToFileURL(path), DEFAULT_PRIORITY, &d));
973 req->Start(); 990 req->Start();
974 base::RunLoop().Run(); 991 base::RunLoop().Run();
975 992
976 // Generate entry for the sentinel file. 993 // Generate entry for the sentinel file.
977 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); 994 base::FilePath sentinel_path = path.AppendASCII(sentinel_name);
978 base::File::Info info; 995 base::File::Info info;
979 EXPECT_TRUE(base::GetFileInfo(sentinel_path, &info)); 996 EXPECT_TRUE(base::GetFileInfo(sentinel_path, &info));
980 EXPECT_GT(info.size, 0); 997 EXPECT_GT(info.size, 0);
981 std::string sentinel_output = GetDirectoryListingEntry( 998 std::string sentinel_output = GetDirectoryListingEntry(
982 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)), 999 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)),
(...skipping 16 matching lines...) Expand all
999 // redirects does not crash. See http://crbug.com/18686. 1016 // redirects does not crash. See http://crbug.com/18686.
1000 1017
1001 base::FilePath path; 1018 base::FilePath path;
1002 PathService::Get(base::DIR_SOURCE_ROOT, &path); 1019 PathService::Get(base::DIR_SOURCE_ROOT, &path);
1003 path = path.Append(FILE_PATH_LITERAL("net")); 1020 path = path.Append(FILE_PATH_LITERAL("net"));
1004 path = path.Append(FILE_PATH_LITERAL("data")); 1021 path = path.Append(FILE_PATH_LITERAL("data"));
1005 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 1022 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
1006 1023
1007 TestDelegate d; 1024 TestDelegate d;
1008 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 1025 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
1009 FilePathToFileURL(path), DEFAULT_PRIORITY, &d, NULL)); 1026 FilePathToFileURL(path), DEFAULT_PRIORITY, &d));
1010 req->Start(); 1027 req->Start();
1011 base::RunLoop().Run(); 1028 base::RunLoop().Run();
1012 1029
1013 ASSERT_EQ(1, d.received_redirect_count()); 1030 ASSERT_EQ(1, d.received_redirect_count());
1014 ASSERT_LT(0, d.bytes_received()); 1031 ASSERT_LT(0, d.bytes_received());
1015 ASSERT_FALSE(d.request_failed()); 1032 ASSERT_FALSE(d.request_failed());
1016 ASSERT_TRUE(req->status().is_success()); 1033 ASSERT_TRUE(req->status().is_success());
1017 } 1034 }
1018 1035
1019 #if defined(OS_WIN) 1036 #if defined(OS_WIN)
1020 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. 1037 // Don't accept the url "file:///" on windows. See http://crbug.com/1474.
1021 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { 1038 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) {
1022 TestDelegate d; 1039 TestDelegate d;
1023 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 1040 scoped_ptr<URLRequest> req(
1024 GURL("file:///"), DEFAULT_PRIORITY, &d, NULL)); 1041 default_context_.CreateRequest(GURL("file:///"), DEFAULT_PRIORITY, &d));
1025 req->Start(); 1042 req->Start();
1026 base::RunLoop().Run(); 1043 base::RunLoop().Run();
1027 1044
1028 ASSERT_EQ(1, d.received_redirect_count()); 1045 ASSERT_EQ(1, d.received_redirect_count());
1029 ASSERT_FALSE(req->status().is_success()); 1046 ASSERT_FALSE(req->status().is_success());
1030 } 1047 }
1031 #endif // defined(OS_WIN) 1048 #endif // defined(OS_WIN)
1032 1049
1033 #endif // !defined(DISABLE_FILE_SUPPORT) 1050 #endif // !defined(DISABLE_FILE_SUPPORT)
1034 1051
1035 TEST_F(URLRequestTest, InvalidUrlTest) { 1052 TEST_F(URLRequestTest, InvalidUrlTest) {
1036 TestDelegate d; 1053 TestDelegate d;
1037 { 1054 {
1038 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 1055 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
1039 GURL("invalid url"), DEFAULT_PRIORITY, &d, NULL)); 1056 GURL("invalid url"), DEFAULT_PRIORITY, &d));
1040 1057
1041 r->Start(); 1058 r->Start();
1042 EXPECT_TRUE(r->is_pending()); 1059 EXPECT_TRUE(r->is_pending());
1043 1060
1044 base::RunLoop().Run(); 1061 base::RunLoop().Run();
1045 EXPECT_TRUE(d.request_failed()); 1062 EXPECT_TRUE(d.request_failed());
1046 } 1063 }
1047 } 1064 }
1048 1065
1049 TEST_F(URLRequestTest, InvalidReferrerTest) { 1066 TEST_F(URLRequestTest, InvalidReferrerTest) {
1050 TestURLRequestContext context; 1067 TestURLRequestContext context;
1051 TestNetworkDelegate network_delegate; 1068 TestNetworkDelegate network_delegate;
1052 network_delegate.set_cancel_request_with_policy_violating_referrer(true); 1069 network_delegate.set_cancel_request_with_policy_violating_referrer(true);
1053 context.set_network_delegate(&network_delegate); 1070 context.set_network_delegate(&network_delegate);
1054 TestDelegate d; 1071 TestDelegate d;
1055 scoped_ptr<URLRequest> req(context.CreateRequest( 1072 scoped_ptr<URLRequest> req(
1056 GURL("http://localhost/"), DEFAULT_PRIORITY, &d, NULL)); 1073 context.CreateRequest(GURL("http://localhost/"), DEFAULT_PRIORITY, &d));
1057 req->SetReferrer("https://somewhere.com/"); 1074 req->SetReferrer("https://somewhere.com/");
1058 1075
1059 req->Start(); 1076 req->Start();
1060 base::RunLoop().Run(); 1077 base::RunLoop().Run();
1061 EXPECT_TRUE(d.request_failed()); 1078 EXPECT_TRUE(d.request_failed());
1062 } 1079 }
1063 1080
1064 #if defined(OS_WIN) 1081 #if defined(OS_WIN)
1065 TEST_F(URLRequestTest, ResolveShortcutTest) { 1082 TEST_F(URLRequestTest, ResolveShortcutTest) {
1066 base::FilePath app_path; 1083 base::FilePath app_path;
(...skipping 15 matching lines...) Expand all
1082 base::win::ScopedComPtr<IPersistFile> persist; 1099 base::win::ScopedComPtr<IPersistFile> persist;
1083 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); 1100 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive())));
1084 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); 1101 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str())));
1085 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); 1102 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest")));
1086 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); 1103 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE)));
1087 } 1104 }
1088 1105
1089 TestDelegate d; 1106 TestDelegate d;
1090 { 1107 {
1091 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 1108 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
1092 FilePathToFileURL(base::FilePath(lnk_path)), DEFAULT_PRIORITY, &d, 1109 FilePathToFileURL(base::FilePath(lnk_path)), DEFAULT_PRIORITY, &d));
1093 NULL));
1094 1110
1095 r->Start(); 1111 r->Start();
1096 EXPECT_TRUE(r->is_pending()); 1112 EXPECT_TRUE(r->is_pending());
1097 1113
1098 base::RunLoop().Run(); 1114 base::RunLoop().Run();
1099 1115
1100 WIN32_FILE_ATTRIBUTE_DATA data; 1116 WIN32_FILE_ATTRIBUTE_DATA data;
1101 GetFileAttributesEx(app_path.value().c_str(), 1117 GetFileAttributesEx(app_path.value().c_str(),
1102 GetFileExInfoStandard, &data); 1118 GetFileExInfoStandard, &data);
1103 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, 1119 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ,
(...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after
1467 MockURLRequestInterceptor* interceptor_; 1483 MockURLRequestInterceptor* interceptor_;
1468 }; 1484 };
1469 1485
1470 TEST_F(URLRequestInterceptorTest, Intercept) { 1486 TEST_F(URLRequestInterceptorTest, Intercept) {
1471 // Intercept the main request and respond with a simple response. 1487 // Intercept the main request and respond with a simple response.
1472 interceptor()->set_intercept_main_request(true); 1488 interceptor()->set_intercept_main_request(true);
1473 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers()); 1489 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers());
1474 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data()); 1490 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data());
1475 TestDelegate d; 1491 TestDelegate d;
1476 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1492 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1477 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1493 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1478 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); 1494 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data();
1479 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); 1495 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data();
1480 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); 1496 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data();
1481 req->SetUserData(nullptr, user_data0); 1497 req->SetUserData(nullptr, user_data0);
1482 req->SetUserData(&user_data1, user_data1); 1498 req->SetUserData(&user_data1, user_data1);
1483 req->SetUserData(&user_data2, user_data2); 1499 req->SetUserData(&user_data2, user_data2);
1484 req->set_method("GET"); 1500 req->set_method("GET");
1485 req->Start(); 1501 req->Start();
1486 base::RunLoop().Run(); 1502 base::RunLoop().Run();
1487 1503
(...skipping 17 matching lines...) Expand all
1505 MockURLRequestInterceptor::redirect_headers()); 1521 MockURLRequestInterceptor::redirect_headers());
1506 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data()); 1522 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data());
1507 1523
1508 // Intercept that redirect and respond with a final OK response. 1524 // Intercept that redirect and respond with a final OK response.
1509 interceptor()->set_intercept_redirect(true); 1525 interceptor()->set_intercept_redirect(true);
1510 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers()); 1526 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers());
1511 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data()); 1527 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data());
1512 1528
1513 TestDelegate d; 1529 TestDelegate d;
1514 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1530 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1515 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1531 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1516 req->set_method("GET"); 1532 req->set_method("GET");
1517 req->Start(); 1533 req->Start();
1518 base::RunLoop().Run(); 1534 base::RunLoop().Run();
1519 1535
1520 // Check that the interceptor got called as expected. 1536 // Check that the interceptor got called as expected.
1521 EXPECT_TRUE(interceptor()->did_intercept_main()); 1537 EXPECT_TRUE(interceptor()->did_intercept_main());
1522 EXPECT_TRUE(interceptor()->did_intercept_redirect()); 1538 EXPECT_TRUE(interceptor()->did_intercept_redirect());
1523 1539
1524 // Check that we got one good response. 1540 // Check that we got one good response.
1525 EXPECT_TRUE(req->status().is_success()); 1541 EXPECT_TRUE(req->status().is_success());
(...skipping 11 matching lines...) Expand all
1537 interceptor()->set_main_headers(MockURLRequestInterceptor::error_headers()); 1553 interceptor()->set_main_headers(MockURLRequestInterceptor::error_headers());
1538 interceptor()->set_main_data(MockURLRequestInterceptor::error_data()); 1554 interceptor()->set_main_data(MockURLRequestInterceptor::error_data());
1539 1555
1540 // Intercept that error and respond with an OK response. 1556 // Intercept that error and respond with an OK response.
1541 interceptor()->set_intercept_final_response(true); 1557 interceptor()->set_intercept_final_response(true);
1542 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 1558 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1543 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 1559 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1544 1560
1545 TestDelegate d; 1561 TestDelegate d;
1546 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1562 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1547 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1563 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1548 req->set_method("GET"); 1564 req->set_method("GET");
1549 req->Start(); 1565 req->Start();
1550 base::RunLoop().Run(); 1566 base::RunLoop().Run();
1551 1567
1552 // Check that the interceptor got called as expected. 1568 // Check that the interceptor got called as expected.
1553 EXPECT_TRUE(interceptor()->did_intercept_main()); 1569 EXPECT_TRUE(interceptor()->did_intercept_main());
1554 EXPECT_TRUE(interceptor()->did_intercept_final()); 1570 EXPECT_TRUE(interceptor()->did_intercept_final());
1555 1571
1556 // Check that we got one good response. 1572 // Check that we got one good response.
1557 EXPECT_TRUE(req->status().is_success()); 1573 EXPECT_TRUE(req->status().is_success());
1558 EXPECT_EQ(200, req->response_headers()->response_code()); 1574 EXPECT_EQ(200, req->response_headers()->response_code());
1559 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 1575 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1560 EXPECT_EQ(1, d.response_started_count()); 1576 EXPECT_EQ(1, d.response_started_count());
1561 EXPECT_EQ(0, d.received_redirect_count()); 1577 EXPECT_EQ(0, d.received_redirect_count());
1562 } 1578 }
1563 1579
1564 TEST_F(URLRequestInterceptorTest, InterceptNetworkError) { 1580 TEST_F(URLRequestInterceptorTest, InterceptNetworkError) {
1565 // Intercept the main request to simulate a network error. 1581 // Intercept the main request to simulate a network error.
1566 interceptor()->set_simulate_main_network_error(true); 1582 interceptor()->set_simulate_main_network_error(true);
1567 1583
1568 // Intercept that error and respond with an OK response. 1584 // Intercept that error and respond with an OK response.
1569 interceptor()->set_intercept_final_response(true); 1585 interceptor()->set_intercept_final_response(true);
1570 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 1586 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1571 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 1587 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1572 1588
1573 TestDelegate d; 1589 TestDelegate d;
1574 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1590 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1575 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1591 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1576 req->set_method("GET"); 1592 req->set_method("GET");
1577 req->Start(); 1593 req->Start();
1578 base::RunLoop().Run(); 1594 base::RunLoop().Run();
1579 1595
1580 // Check that the interceptor got called as expected. 1596 // Check that the interceptor got called as expected.
1581 EXPECT_TRUE(interceptor()->did_simulate_error_main()); 1597 EXPECT_TRUE(interceptor()->did_simulate_error_main());
1582 EXPECT_TRUE(interceptor()->did_intercept_final()); 1598 EXPECT_TRUE(interceptor()->did_intercept_final());
1583 1599
1584 // Check that we received one good response. 1600 // Check that we received one good response.
1585 EXPECT_TRUE(req->status().is_success()); 1601 EXPECT_TRUE(req->status().is_success());
1586 EXPECT_EQ(200, req->response_headers()->response_code()); 1602 EXPECT_EQ(200, req->response_headers()->response_code());
1587 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 1603 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1588 EXPECT_EQ(1, d.response_started_count()); 1604 EXPECT_EQ(1, d.response_started_count());
1589 EXPECT_EQ(0, d.received_redirect_count()); 1605 EXPECT_EQ(0, d.received_redirect_count());
1590 } 1606 }
1591 1607
1592 TEST_F(URLRequestInterceptorTest, InterceptRestartRequired) { 1608 TEST_F(URLRequestInterceptorTest, InterceptRestartRequired) {
1593 // Restart the main request. 1609 // Restart the main request.
1594 interceptor()->set_restart_main_request(true); 1610 interceptor()->set_restart_main_request(true);
1595 1611
1596 // then intercept the new main request and respond with an OK response 1612 // then intercept the new main request and respond with an OK response
1597 interceptor()->set_intercept_main_request(true); 1613 interceptor()->set_intercept_main_request(true);
1598 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers()); 1614 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers());
1599 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data()); 1615 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data());
1600 1616
1601 TestDelegate d; 1617 TestDelegate d;
1602 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1618 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1603 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1619 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1604 req->set_method("GET"); 1620 req->set_method("GET");
1605 req->Start(); 1621 req->Start();
1606 base::RunLoop().Run(); 1622 base::RunLoop().Run();
1607 1623
1608 // Check that the interceptor got called as expected. 1624 // Check that the interceptor got called as expected.
1609 EXPECT_TRUE(interceptor()->did_restart_main()); 1625 EXPECT_TRUE(interceptor()->did_restart_main());
1610 EXPECT_TRUE(interceptor()->did_intercept_main()); 1626 EXPECT_TRUE(interceptor()->did_intercept_main());
1611 1627
1612 // Check that we received one good response. 1628 // Check that we received one good response.
1613 EXPECT_TRUE(req->status().is_success()); 1629 EXPECT_TRUE(req->status().is_success());
1614 if (req->status().is_success()) 1630 if (req->status().is_success())
1615 EXPECT_EQ(200, req->response_headers()->response_code()); 1631 EXPECT_EQ(200, req->response_headers()->response_code());
1616 1632
1617 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 1633 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
1618 EXPECT_EQ(1, d.response_started_count()); 1634 EXPECT_EQ(1, d.response_started_count());
1619 EXPECT_EQ(0, d.received_redirect_count()); 1635 EXPECT_EQ(0, d.received_redirect_count());
1620 } 1636 }
1621 1637
1622 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelMain) { 1638 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelMain) {
1623 // Intercept the main request and cancel from within the restarted job. 1639 // Intercept the main request and cancel from within the restarted job.
1624 interceptor()->set_cancel_main_request(true); 1640 interceptor()->set_cancel_main_request(true);
1625 1641
1626 // Set up to intercept the final response and override it with an OK response. 1642 // Set up to intercept the final response and override it with an OK response.
1627 interceptor()->set_intercept_final_response(true); 1643 interceptor()->set_intercept_final_response(true);
1628 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 1644 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1629 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 1645 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1630 1646
1631 TestDelegate d; 1647 TestDelegate d;
1632 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1648 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1633 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1649 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1634 req->set_method("GET"); 1650 req->set_method("GET");
1635 req->Start(); 1651 req->Start();
1636 base::RunLoop().Run(); 1652 base::RunLoop().Run();
1637 1653
1638 // Check that the interceptor got called as expected. 1654 // Check that the interceptor got called as expected.
1639 EXPECT_TRUE(interceptor()->did_cancel_main()); 1655 EXPECT_TRUE(interceptor()->did_cancel_main());
1640 EXPECT_FALSE(interceptor()->did_intercept_final()); 1656 EXPECT_FALSE(interceptor()->did_intercept_final());
1641 1657
1642 // Check that we see a canceled request. 1658 // Check that we see a canceled request.
1643 EXPECT_FALSE(req->status().is_success()); 1659 EXPECT_FALSE(req->status().is_success());
(...skipping 10 matching lines...) Expand all
1654 // Intercept the redirect and cancel from within that job. 1670 // Intercept the redirect and cancel from within that job.
1655 interceptor()->set_cancel_redirect_request(true); 1671 interceptor()->set_cancel_redirect_request(true);
1656 1672
1657 // Set up to intercept the final response and override it with an OK response. 1673 // Set up to intercept the final response and override it with an OK response.
1658 interceptor()->set_intercept_final_response(true); 1674 interceptor()->set_intercept_final_response(true);
1659 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 1675 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1660 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 1676 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1661 1677
1662 TestDelegate d; 1678 TestDelegate d;
1663 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1679 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1664 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1680 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1665 req->set_method("GET"); 1681 req->set_method("GET");
1666 req->Start(); 1682 req->Start();
1667 base::RunLoop().Run(); 1683 base::RunLoop().Run();
1668 1684
1669 // Check that the interceptor got called as expected. 1685 // Check that the interceptor got called as expected.
1670 EXPECT_TRUE(interceptor()->did_intercept_main()); 1686 EXPECT_TRUE(interceptor()->did_intercept_main());
1671 EXPECT_TRUE(interceptor()->did_cancel_redirect()); 1687 EXPECT_TRUE(interceptor()->did_cancel_redirect());
1672 EXPECT_FALSE(interceptor()->did_intercept_final()); 1688 EXPECT_FALSE(interceptor()->did_intercept_final());
1673 1689
1674 // Check that we see a canceled request. 1690 // Check that we see a canceled request.
1675 EXPECT_FALSE(req->status().is_success()); 1691 EXPECT_FALSE(req->status().is_success());
1676 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 1692 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1677 } 1693 }
1678 1694
1679 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) { 1695 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) {
1680 // Intercept the main request to simulate a network error. 1696 // Intercept the main request to simulate a network error.
1681 interceptor()->set_simulate_main_network_error(true); 1697 interceptor()->set_simulate_main_network_error(true);
1682 1698
1683 // Set up to intercept final the response and cancel from within that job. 1699 // Set up to intercept final the response and cancel from within that job.
1684 interceptor()->set_cancel_final_request(true); 1700 interceptor()->set_cancel_final_request(true);
1685 1701
1686 TestDelegate d; 1702 TestDelegate d;
1687 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1703 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1688 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1704 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1689 req->set_method("GET"); 1705 req->set_method("GET");
1690 req->Start(); 1706 req->Start();
1691 base::RunLoop().Run(); 1707 base::RunLoop().Run();
1692 1708
1693 // Check that the interceptor got called as expected. 1709 // Check that the interceptor got called as expected.
1694 EXPECT_TRUE(interceptor()->did_simulate_error_main()); 1710 EXPECT_TRUE(interceptor()->did_simulate_error_main());
1695 EXPECT_TRUE(interceptor()->did_cancel_final()); 1711 EXPECT_TRUE(interceptor()->did_cancel_final());
1696 1712
1697 // Check that we see a canceled request. 1713 // Check that we see a canceled request.
1698 EXPECT_FALSE(req->status().is_success()); 1714 EXPECT_FALSE(req->status().is_success());
1699 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 1715 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
1700 } 1716 }
1701 1717
1702 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelInRestart) { 1718 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelInRestart) {
1703 // Intercept the main request and cancel then restart from within that job. 1719 // Intercept the main request and cancel then restart from within that job.
1704 interceptor()->set_cancel_then_restart_main_request(true); 1720 interceptor()->set_cancel_then_restart_main_request(true);
1705 1721
1706 // Set up to intercept the final response and override it with an OK response. 1722 // Set up to intercept the final response and override it with an OK response.
1707 interceptor()->set_intercept_final_response(true); 1723 interceptor()->set_intercept_final_response(true);
1708 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 1724 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
1709 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 1725 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
1710 1726
1711 TestDelegate d; 1727 TestDelegate d;
1712 scoped_ptr<URLRequest> req(default_context().CreateRequest( 1728 scoped_ptr<URLRequest> req(default_context().CreateRequest(
1713 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1729 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1714 req->set_method("GET"); 1730 req->set_method("GET");
1715 req->Start(); 1731 req->Start();
1716 base::RunLoop().Run(); 1732 base::RunLoop().Run();
1717 1733
1718 // Check that the interceptor got called as expected. 1734 // Check that the interceptor got called as expected.
1719 EXPECT_TRUE(interceptor()->did_cancel_then_restart_main()); 1735 EXPECT_TRUE(interceptor()->did_cancel_then_restart_main());
1720 EXPECT_FALSE(interceptor()->did_intercept_final()); 1736 EXPECT_FALSE(interceptor()->did_intercept_final());
1721 1737
1722 // Check that we see a canceled request. 1738 // Check that we see a canceled request.
1723 EXPECT_FALSE(req->status().is_success()); 1739 EXPECT_FALSE(req->status().is_success());
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
1775 } 1791 }
1776 1792
1777 LoadTimingInfo RunURLRequestInterceptorLoadTimingTest( 1793 LoadTimingInfo RunURLRequestInterceptorLoadTimingTest(
1778 const LoadTimingInfo& job_load_timing, 1794 const LoadTimingInfo& job_load_timing,
1779 const URLRequestContext& context, 1795 const URLRequestContext& context,
1780 MockURLRequestInterceptor* interceptor) { 1796 MockURLRequestInterceptor* interceptor) {
1781 interceptor->set_intercept_main_request(true); 1797 interceptor->set_intercept_main_request(true);
1782 interceptor->set_main_request_load_timing_info(job_load_timing); 1798 interceptor->set_main_request_load_timing_info(job_load_timing);
1783 TestDelegate d; 1799 TestDelegate d;
1784 scoped_ptr<URLRequest> req(context.CreateRequest( 1800 scoped_ptr<URLRequest> req(context.CreateRequest(
1785 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, nullptr)); 1801 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
1786 req->Start(); 1802 req->Start();
1787 base::RunLoop().Run(); 1803 base::RunLoop().Run();
1788 1804
1789 LoadTimingInfo resulting_load_timing; 1805 LoadTimingInfo resulting_load_timing;
1790 req->GetLoadTimingInfo(&resulting_load_timing); 1806 req->GetLoadTimingInfo(&resulting_load_timing);
1791 1807
1792 // None of these should be modified by the URLRequest. 1808 // None of these should be modified by the URLRequest.
1793 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); 1809 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused);
1794 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); 1810 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id);
1795 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); 1811 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start);
(...skipping 195 matching lines...) Expand 10 before | Expand all | Expand 10 after
1991 2007
1992 // Other times should have been left null. 2008 // Other times should have been left null.
1993 TestLoadTimingNotReusedWithProxy(load_timing_result, 2009 TestLoadTimingNotReusedWithProxy(load_timing_result,
1994 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); 2010 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY);
1995 } 2011 }
1996 2012
1997 // Check that two different URL requests have different identifiers. 2013 // Check that two different URL requests have different identifiers.
1998 TEST_F(URLRequestTest, Identifiers) { 2014 TEST_F(URLRequestTest, Identifiers) {
1999 TestDelegate d; 2015 TestDelegate d;
2000 TestURLRequestContext context; 2016 TestURLRequestContext context;
2001 scoped_ptr<URLRequest> req(context.CreateRequest( 2017 scoped_ptr<URLRequest> req(
2002 GURL("http://example.com"), DEFAULT_PRIORITY, &d, NULL)); 2018 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d));
2003 scoped_ptr<URLRequest> other_req(context.CreateRequest( 2019 scoped_ptr<URLRequest> other_req(
2004 GURL("http://example.com"), DEFAULT_PRIORITY, &d, NULL)); 2020 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d));
2005 2021
2006 ASSERT_NE(req->identifier(), other_req->identifier()); 2022 ASSERT_NE(req->identifier(), other_req->identifier());
2007 } 2023 }
2008 2024
2009 // Check that a failure to connect to the proxy is reported to the network 2025 // Check that a failure to connect to the proxy is reported to the network
2010 // delegate. 2026 // delegate.
2011 TEST_F(URLRequestTest, NetworkDelegateProxyError) { 2027 TEST_F(URLRequestTest, NetworkDelegateProxyError) {
2012 MockHostResolver host_resolver; 2028 MockHostResolver host_resolver;
2013 host_resolver.rules()->AddSimulatedFailure("*"); 2029 host_resolver.rules()->AddSimulatedFailure("*");
2014 2030
2015 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 2031 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
2016 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); 2032 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate);
2017 2033
2018 TestDelegate d; 2034 TestDelegate d;
2019 scoped_ptr<URLRequest> req(context.CreateRequest( 2035 scoped_ptr<URLRequest> req(
2020 GURL("http://example.com"), DEFAULT_PRIORITY, &d, NULL)); 2036 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d));
2021 req->set_method("GET"); 2037 req->set_method("GET");
2022 2038
2023 req->Start(); 2039 req->Start();
2024 base::RunLoop().Run(); 2040 base::RunLoop().Run();
2025 2041
2026 // Check we see a failed request. 2042 // Check we see a failed request.
2027 EXPECT_FALSE(req->status().is_success()); 2043 EXPECT_FALSE(req->status().is_success());
2028 // The proxy server is not set before failure. 2044 // The proxy server is not set before failure.
2029 EXPECT_TRUE(req->proxy_server().IsEmpty()); 2045 EXPECT_TRUE(req->proxy_server().IsEmpty());
2030 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 2046 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
2031 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req->status().error()); 2047 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, req->status().error());
2032 2048
2033 EXPECT_EQ(1, network_delegate.error_count()); 2049 EXPECT_EQ(1, network_delegate.error_count());
2034 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error()); 2050 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, network_delegate.last_error());
2035 EXPECT_EQ(1, network_delegate.completed_requests()); 2051 EXPECT_EQ(1, network_delegate.completed_requests());
2036 } 2052 }
2037 2053
2038 // Make sure that NetworkDelegate::NotifyCompleted is called if 2054 // Make sure that NetworkDelegate::NotifyCompleted is called if
2039 // content is empty. 2055 // content is empty.
2040 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { 2056 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) {
2041 TestDelegate d; 2057 TestDelegate d;
2042 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2058 scoped_ptr<URLRequest> req(
2043 GURL("data:,"), DEFAULT_PRIORITY, &d, NULL)); 2059 default_context_.CreateRequest(GURL("data:,"), DEFAULT_PRIORITY, &d));
2044 req->Start(); 2060 req->Start();
2045 base::RunLoop().Run(); 2061 base::RunLoop().Run();
2046 EXPECT_EQ("", d.data_received()); 2062 EXPECT_EQ("", d.data_received());
2047 EXPECT_EQ(1, default_network_delegate_.completed_requests()); 2063 EXPECT_EQ(1, default_network_delegate_.completed_requests());
2048 } 2064 }
2049 2065
2050 // Make sure that SetPriority actually sets the URLRequest's priority 2066 // Make sure that SetPriority actually sets the URLRequest's priority
2051 // correctly, both before and after start. 2067 // correctly, both before and after start.
2052 TEST_F(URLRequestTest, SetPriorityBasic) { 2068 TEST_F(URLRequestTest, SetPriorityBasic) {
2053 TestDelegate d; 2069 TestDelegate d;
2054 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2070 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2055 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); 2071 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
2056 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); 2072 EXPECT_EQ(DEFAULT_PRIORITY, req->priority());
2057 2073
2058 req->SetPriority(LOW); 2074 req->SetPriority(LOW);
2059 EXPECT_EQ(LOW, req->priority()); 2075 EXPECT_EQ(LOW, req->priority());
2060 2076
2061 req->Start(); 2077 req->Start();
2062 EXPECT_EQ(LOW, req->priority()); 2078 EXPECT_EQ(LOW, req->priority());
2063 2079
2064 req->SetPriority(MEDIUM); 2080 req->SetPriority(MEDIUM);
2065 EXPECT_EQ(MEDIUM, req->priority()); 2081 EXPECT_EQ(MEDIUM, req->priority());
2066 } 2082 }
2067 2083
2068 // Make sure that URLRequest calls SetPriority on a job before calling 2084 // Make sure that URLRequest calls SetPriority on a job before calling
2069 // Start on it. 2085 // Start on it.
2070 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { 2086 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) {
2071 TestDelegate d; 2087 TestDelegate d;
2072 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2088 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2073 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); 2089 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
2074 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); 2090 EXPECT_EQ(DEFAULT_PRIORITY, req->priority());
2075 2091
2076 scoped_refptr<URLRequestTestJob> job = 2092 scoped_refptr<URLRequestTestJob> job =
2077 new URLRequestTestJob(req.get(), &default_network_delegate_); 2093 new URLRequestTestJob(req.get(), &default_network_delegate_);
2078 AddTestInterceptor()->set_main_intercept_job(job.get()); 2094 AddTestInterceptor()->set_main_intercept_job(job.get());
2079 EXPECT_EQ(DEFAULT_PRIORITY, job->priority()); 2095 EXPECT_EQ(DEFAULT_PRIORITY, job->priority());
2080 2096
2081 req->SetPriority(LOW); 2097 req->SetPriority(LOW);
2082 2098
2083 req->Start(); 2099 req->Start();
2084 EXPECT_EQ(LOW, job->priority()); 2100 EXPECT_EQ(LOW, job->priority());
2085 } 2101 }
2086 2102
2087 // Make sure that URLRequest passes on its priority updates to its 2103 // Make sure that URLRequest passes on its priority updates to its
2088 // job. 2104 // job.
2089 TEST_F(URLRequestTest, SetJobPriority) { 2105 TEST_F(URLRequestTest, SetJobPriority) {
2090 TestDelegate d; 2106 TestDelegate d;
2091 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2107 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2092 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, NULL)); 2108 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d));
2093 2109
2094 scoped_refptr<URLRequestTestJob> job = 2110 scoped_refptr<URLRequestTestJob> job =
2095 new URLRequestTestJob(req.get(), &default_network_delegate_); 2111 new URLRequestTestJob(req.get(), &default_network_delegate_);
2096 AddTestInterceptor()->set_main_intercept_job(job.get()); 2112 AddTestInterceptor()->set_main_intercept_job(job.get());
2097 2113
2098 req->SetPriority(LOW); 2114 req->SetPriority(LOW);
2099 req->Start(); 2115 req->Start();
2100 EXPECT_EQ(LOW, job->priority()); 2116 EXPECT_EQ(LOW, job->priority());
2101 2117
2102 req->SetPriority(MEDIUM); 2118 req->SetPriority(MEDIUM);
2103 EXPECT_EQ(MEDIUM, req->priority()); 2119 EXPECT_EQ(MEDIUM, req->priority());
2104 EXPECT_EQ(MEDIUM, job->priority()); 2120 EXPECT_EQ(MEDIUM, job->priority());
2105 } 2121 }
2106 2122
2107 // Setting the IGNORE_LIMITS load flag should be okay if the priority 2123 // Setting the IGNORE_LIMITS load flag should be okay if the priority
2108 // is MAXIMUM_PRIORITY. 2124 // is MAXIMUM_PRIORITY.
2109 TEST_F(URLRequestTest, PriorityIgnoreLimits) { 2125 TEST_F(URLRequestTest, PriorityIgnoreLimits) {
2110 TestDelegate d; 2126 TestDelegate d;
2111 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2127 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2112 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d, NULL)); 2128 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d));
2113 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); 2129 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
2114 2130
2115 scoped_refptr<URLRequestTestJob> job = 2131 scoped_refptr<URLRequestTestJob> job =
2116 new URLRequestTestJob(req.get(), &default_network_delegate_); 2132 new URLRequestTestJob(req.get(), &default_network_delegate_);
2117 AddTestInterceptor()->set_main_intercept_job(job.get()); 2133 AddTestInterceptor()->set_main_intercept_job(job.get());
2118 2134
2119 req->SetLoadFlags(LOAD_IGNORE_LIMITS); 2135 req->SetLoadFlags(LOAD_IGNORE_LIMITS);
2120 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); 2136 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority());
2121 2137
2122 req->SetPriority(MAXIMUM_PRIORITY); 2138 req->SetPriority(MAXIMUM_PRIORITY);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
2155 scoped_refptr<CookieStore> cookie_store = delayed_cm; 2171 scoped_refptr<CookieStore> cookie_store = delayed_cm;
2156 context.set_cookie_store(delayed_cm.get()); 2172 context.set_cookie_store(delayed_cm.get());
2157 2173
2158 // Set up a cookie. 2174 // Set up a cookie.
2159 { 2175 {
2160 TestNetworkDelegate network_delegate; 2176 TestNetworkDelegate network_delegate;
2161 context.set_network_delegate(&network_delegate); 2177 context.set_network_delegate(&network_delegate);
2162 TestDelegate d; 2178 TestDelegate d;
2163 scoped_ptr<URLRequest> req(context.CreateRequest( 2179 scoped_ptr<URLRequest> req(context.CreateRequest(
2164 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, 2180 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY,
2165 &d, NULL)); 2181 &d));
2166 req->Start(); 2182 req->Start();
2167 base::RunLoop().Run(); 2183 base::RunLoop().Run();
2168 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2184 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2169 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2185 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2170 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2186 EXPECT_EQ(1, network_delegate.set_cookie_count());
2171 } 2187 }
2172 2188
2173 // Verify that the cookie is set. 2189 // Verify that the cookie is set.
2174 { 2190 {
2175 TestNetworkDelegate network_delegate; 2191 TestNetworkDelegate network_delegate;
2176 context.set_network_delegate(&network_delegate); 2192 context.set_network_delegate(&network_delegate);
2177 TestDelegate d; 2193 TestDelegate d;
2178 scoped_ptr<URLRequest> req(context.CreateRequest( 2194 scoped_ptr<URLRequest> req(context.CreateRequest(
2179 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2195 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2180 req->Start(); 2196 req->Start();
2181 base::RunLoop().Run(); 2197 base::RunLoop().Run();
2182 2198
2183 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2199 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2184 != std::string::npos); 2200 != std::string::npos);
2185 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2201 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2186 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2202 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2187 } 2203 }
2188 } 2204 }
2189 2205
2190 TEST_F(URLRequestTest, DoNotSendCookies) { 2206 TEST_F(URLRequestTest, DoNotSendCookies) {
2191 LocalHttpTestServer test_server; 2207 LocalHttpTestServer test_server;
2192 ASSERT_TRUE(test_server.Start()); 2208 ASSERT_TRUE(test_server.Start());
2193 2209
2194 // Set up a cookie. 2210 // Set up a cookie.
2195 { 2211 {
2196 TestNetworkDelegate network_delegate; 2212 TestNetworkDelegate network_delegate;
2197 default_context_.set_network_delegate(&network_delegate); 2213 default_context_.set_network_delegate(&network_delegate);
2198 TestDelegate d; 2214 TestDelegate d;
2199 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2215 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2200 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, 2216 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY,
2201 &d, NULL)); 2217 &d));
2202 req->Start(); 2218 req->Start();
2203 base::RunLoop().Run(); 2219 base::RunLoop().Run();
2204 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2220 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2205 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2221 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2206 } 2222 }
2207 2223
2208 // Verify that the cookie is set. 2224 // Verify that the cookie is set.
2209 { 2225 {
2210 TestNetworkDelegate network_delegate; 2226 TestNetworkDelegate network_delegate;
2211 default_context_.set_network_delegate(&network_delegate); 2227 default_context_.set_network_delegate(&network_delegate);
2212 TestDelegate d; 2228 TestDelegate d;
2213 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2229 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2214 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2230 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2215 req->Start(); 2231 req->Start();
2216 base::RunLoop().Run(); 2232 base::RunLoop().Run();
2217 2233
2218 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2234 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2219 != std::string::npos); 2235 != std::string::npos);
2220 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2236 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2221 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2237 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2222 } 2238 }
2223 2239
2224 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. 2240 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set.
2225 { 2241 {
2226 TestNetworkDelegate network_delegate; 2242 TestNetworkDelegate network_delegate;
2227 default_context_.set_network_delegate(&network_delegate); 2243 default_context_.set_network_delegate(&network_delegate);
2228 TestDelegate d; 2244 TestDelegate d;
2229 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2245 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2230 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2246 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2231 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); 2247 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES);
2232 req->Start(); 2248 req->Start();
2233 base::RunLoop().Run(); 2249 base::RunLoop().Run();
2234 2250
2235 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2251 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2236 == std::string::npos); 2252 == std::string::npos);
2237 2253
2238 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. 2254 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies.
2239 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2255 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2240 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2256 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2241 } 2257 }
2242 } 2258 }
2243 2259
2244 TEST_F(URLRequestTest, DoNotSaveCookies) { 2260 TEST_F(URLRequestTest, DoNotSaveCookies) {
2245 LocalHttpTestServer test_server; 2261 LocalHttpTestServer test_server;
2246 ASSERT_TRUE(test_server.Start()); 2262 ASSERT_TRUE(test_server.Start());
2247 2263
2248 // Set up a cookie. 2264 // Set up a cookie.
2249 { 2265 {
2250 TestNetworkDelegate network_delegate; 2266 TestNetworkDelegate network_delegate;
2251 default_context_.set_network_delegate(&network_delegate); 2267 default_context_.set_network_delegate(&network_delegate);
2252 TestDelegate d; 2268 TestDelegate d;
2253 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2269 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2254 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, 2270 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY,
2255 &d, NULL)); 2271 &d));
2256 req->Start(); 2272 req->Start();
2257 base::RunLoop().Run(); 2273 base::RunLoop().Run();
2258 2274
2259 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2275 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2260 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2276 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2261 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2277 EXPECT_EQ(1, network_delegate.set_cookie_count());
2262 } 2278 }
2263 2279
2264 // Try to set-up another cookie and update the previous cookie. 2280 // Try to set-up another cookie and update the previous cookie.
2265 { 2281 {
2266 TestNetworkDelegate network_delegate; 2282 TestNetworkDelegate network_delegate;
2267 default_context_.set_network_delegate(&network_delegate); 2283 default_context_.set_network_delegate(&network_delegate);
2268 TestDelegate d; 2284 TestDelegate d;
2269 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2285 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2270 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2286 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2271 DEFAULT_PRIORITY, &d, NULL)); 2287 DEFAULT_PRIORITY, &d));
2272 req->SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES); 2288 req->SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES);
2273 req->Start(); 2289 req->Start();
2274 2290
2275 base::RunLoop().Run(); 2291 base::RunLoop().Run();
2276 2292
2277 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. 2293 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie.
2278 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2294 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2279 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2295 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2280 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2296 EXPECT_EQ(0, network_delegate.set_cookie_count());
2281 } 2297 }
2282 2298
2283 // Verify the cookies weren't saved or updated. 2299 // Verify the cookies weren't saved or updated.
2284 { 2300 {
2285 TestNetworkDelegate network_delegate; 2301 TestNetworkDelegate network_delegate;
2286 default_context_.set_network_delegate(&network_delegate); 2302 default_context_.set_network_delegate(&network_delegate);
2287 TestDelegate d; 2303 TestDelegate d;
2288 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2304 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2289 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2305 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2290 req->Start(); 2306 req->Start();
2291 base::RunLoop().Run(); 2307 base::RunLoop().Run();
2292 2308
2293 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2309 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2294 == std::string::npos); 2310 == std::string::npos);
2295 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2311 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2296 != std::string::npos); 2312 != std::string::npos);
2297 2313
2298 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2314 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2299 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2315 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2300 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2316 EXPECT_EQ(0, network_delegate.set_cookie_count());
2301 } 2317 }
2302 } 2318 }
2303 2319
2304 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { 2320 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) {
2305 LocalHttpTestServer test_server; 2321 LocalHttpTestServer test_server;
2306 ASSERT_TRUE(test_server.Start()); 2322 ASSERT_TRUE(test_server.Start());
2307 2323
2308 // Set up a cookie. 2324 // Set up a cookie.
2309 { 2325 {
2310 TestNetworkDelegate network_delegate; 2326 TestNetworkDelegate network_delegate;
2311 default_context_.set_network_delegate(&network_delegate); 2327 default_context_.set_network_delegate(&network_delegate);
2312 TestDelegate d; 2328 TestDelegate d;
2313 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2329 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2314 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, 2330 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY,
2315 &d, NULL)); 2331 &d));
2316 req->Start(); 2332 req->Start();
2317 base::RunLoop().Run(); 2333 base::RunLoop().Run();
2318 2334
2319 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2335 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2320 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2336 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2321 } 2337 }
2322 2338
2323 // Verify that the cookie is set. 2339 // Verify that the cookie is set.
2324 { 2340 {
2325 TestNetworkDelegate network_delegate; 2341 TestNetworkDelegate network_delegate;
2326 default_context_.set_network_delegate(&network_delegate); 2342 default_context_.set_network_delegate(&network_delegate);
2327 TestDelegate d; 2343 TestDelegate d;
2328 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2344 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2329 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2345 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2330 req->Start(); 2346 req->Start();
2331 base::RunLoop().Run(); 2347 base::RunLoop().Run();
2332 2348
2333 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2349 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2334 != std::string::npos); 2350 != std::string::npos);
2335 2351
2336 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2352 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2337 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2353 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2338 } 2354 }
2339 2355
2340 // Verify that the cookie isn't sent. 2356 // Verify that the cookie isn't sent.
2341 { 2357 {
2342 TestNetworkDelegate network_delegate; 2358 TestNetworkDelegate network_delegate;
2343 default_context_.set_network_delegate(&network_delegate); 2359 default_context_.set_network_delegate(&network_delegate);
2344 TestDelegate d; 2360 TestDelegate d;
2345 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2361 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2346 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2362 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2347 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2363 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2348 req->Start(); 2364 req->Start();
2349 base::RunLoop().Run(); 2365 base::RunLoop().Run();
2350 2366
2351 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2367 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2352 == std::string::npos); 2368 == std::string::npos);
2353 2369
2354 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2370 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
2355 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2371 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2356 } 2372 }
2357 } 2373 }
2358 2374
2359 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { 2375 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) {
2360 LocalHttpTestServer test_server; 2376 LocalHttpTestServer test_server;
2361 ASSERT_TRUE(test_server.Start()); 2377 ASSERT_TRUE(test_server.Start());
2362 2378
2363 // Set up a cookie. 2379 // Set up a cookie.
2364 { 2380 {
2365 TestNetworkDelegate network_delegate; 2381 TestNetworkDelegate network_delegate;
2366 default_context_.set_network_delegate(&network_delegate); 2382 default_context_.set_network_delegate(&network_delegate);
2367 TestDelegate d; 2383 TestDelegate d;
2368 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2384 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2369 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, 2385 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY,
2370 &d, NULL)); 2386 &d));
2371 req->Start(); 2387 req->Start();
2372 base::RunLoop().Run(); 2388 base::RunLoop().Run();
2373 2389
2374 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2390 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2375 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2391 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2376 } 2392 }
2377 2393
2378 // Try to set-up another cookie and update the previous cookie. 2394 // Try to set-up another cookie and update the previous cookie.
2379 { 2395 {
2380 TestNetworkDelegate network_delegate; 2396 TestNetworkDelegate network_delegate;
2381 default_context_.set_network_delegate(&network_delegate); 2397 default_context_.set_network_delegate(&network_delegate);
2382 TestDelegate d; 2398 TestDelegate d;
2383 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); 2399 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
2384 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2400 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2385 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2401 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2386 DEFAULT_PRIORITY, &d, NULL)); 2402 DEFAULT_PRIORITY, &d));
2387 req->Start(); 2403 req->Start();
2388 2404
2389 base::RunLoop().Run(); 2405 base::RunLoop().Run();
2390 2406
2391 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2407 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2392 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 2408 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
2393 } 2409 }
2394 2410
2395 // Verify the cookies weren't saved or updated. 2411 // Verify the cookies weren't saved or updated.
2396 { 2412 {
2397 TestNetworkDelegate network_delegate; 2413 TestNetworkDelegate network_delegate;
2398 default_context_.set_network_delegate(&network_delegate); 2414 default_context_.set_network_delegate(&network_delegate);
2399 TestDelegate d; 2415 TestDelegate d;
2400 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2416 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2401 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2417 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2402 req->Start(); 2418 req->Start();
2403 base::RunLoop().Run(); 2419 base::RunLoop().Run();
2404 2420
2405 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2421 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2406 == std::string::npos); 2422 == std::string::npos);
2407 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2423 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2408 != std::string::npos); 2424 != std::string::npos);
2409 2425
2410 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2426 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2411 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2427 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2412 } 2428 }
2413 } 2429 }
2414 2430
2415 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { 2431 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) {
2416 LocalHttpTestServer test_server; 2432 LocalHttpTestServer test_server;
2417 ASSERT_TRUE(test_server.Start()); 2433 ASSERT_TRUE(test_server.Start());
2418 2434
2419 // Set up an empty cookie. 2435 // Set up an empty cookie.
2420 { 2436 {
2421 TestNetworkDelegate network_delegate; 2437 TestNetworkDelegate network_delegate;
2422 default_context_.set_network_delegate(&network_delegate); 2438 default_context_.set_network_delegate(&network_delegate);
2423 TestDelegate d; 2439 TestDelegate d;
2424 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2440 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2425 test_server.GetURL("set-cookie"), DEFAULT_PRIORITY, &d, NULL)); 2441 test_server.GetURL("set-cookie"), DEFAULT_PRIORITY, &d));
2426 req->Start(); 2442 req->Start();
2427 base::RunLoop().Run(); 2443 base::RunLoop().Run();
2428 2444
2429 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2445 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2430 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2446 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2431 EXPECT_EQ(0, network_delegate.set_cookie_count()); 2447 EXPECT_EQ(0, network_delegate.set_cookie_count());
2432 } 2448 }
2433 } 2449 }
2434 2450
2435 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { 2451 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) {
2436 LocalHttpTestServer test_server; 2452 LocalHttpTestServer test_server;
2437 ASSERT_TRUE(test_server.Start()); 2453 ASSERT_TRUE(test_server.Start());
2438 2454
2439 // Set up a cookie. 2455 // Set up a cookie.
2440 { 2456 {
2441 TestNetworkDelegate network_delegate; 2457 TestNetworkDelegate network_delegate;
2442 default_context_.set_network_delegate(&network_delegate); 2458 default_context_.set_network_delegate(&network_delegate);
2443 TestDelegate d; 2459 TestDelegate d;
2444 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2460 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2445 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, 2461 test_server.GetURL("set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY,
2446 &d, NULL)); 2462 &d));
2447 req->Start(); 2463 req->Start();
2448 base::RunLoop().Run(); 2464 base::RunLoop().Run();
2449 2465
2450 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2466 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2451 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2467 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2452 } 2468 }
2453 2469
2454 // Verify that the cookie is set. 2470 // Verify that the cookie is set.
2455 { 2471 {
2456 TestNetworkDelegate network_delegate; 2472 TestNetworkDelegate network_delegate;
2457 default_context_.set_network_delegate(&network_delegate); 2473 default_context_.set_network_delegate(&network_delegate);
2458 TestDelegate d; 2474 TestDelegate d;
2459 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2475 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2460 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2476 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2461 req->Start(); 2477 req->Start();
2462 base::RunLoop().Run(); 2478 base::RunLoop().Run();
2463 2479
2464 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") 2480 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1")
2465 != std::string::npos); 2481 != std::string::npos);
2466 2482
2467 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2483 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2468 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2484 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2469 } 2485 }
2470 2486
2471 // Verify that the cookie isn't sent. 2487 // Verify that the cookie isn't sent.
2472 { 2488 {
2473 TestNetworkDelegate network_delegate; 2489 TestNetworkDelegate network_delegate;
2474 default_context_.set_network_delegate(&network_delegate); 2490 default_context_.set_network_delegate(&network_delegate);
2475 TestDelegate d; 2491 TestDelegate d;
2476 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); 2492 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES);
2477 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2493 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2478 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2494 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2479 req->Start(); 2495 req->Start();
2480 base::RunLoop().Run(); 2496 base::RunLoop().Run();
2481 2497
2482 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") 2498 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1")
2483 == std::string::npos); 2499 == std::string::npos);
2484 2500
2485 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); 2501 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count());
2486 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2502 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2487 } 2503 }
2488 } 2504 }
2489 2505
2490 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { 2506 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) {
2491 LocalHttpTestServer test_server; 2507 LocalHttpTestServer test_server;
2492 ASSERT_TRUE(test_server.Start()); 2508 ASSERT_TRUE(test_server.Start());
2493 2509
2494 // Set up a cookie. 2510 // Set up a cookie.
2495 { 2511 {
2496 TestNetworkDelegate network_delegate; 2512 TestNetworkDelegate network_delegate;
2497 default_context_.set_network_delegate(&network_delegate); 2513 default_context_.set_network_delegate(&network_delegate);
2498 TestDelegate d; 2514 TestDelegate d;
2499 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2515 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2500 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, 2516 test_server.GetURL("set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY,
2501 &d, NULL)); 2517 &d));
2502 req->Start(); 2518 req->Start();
2503 base::RunLoop().Run(); 2519 base::RunLoop().Run();
2504 2520
2505 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2521 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2506 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2522 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2507 } 2523 }
2508 2524
2509 // Try to set-up another cookie and update the previous cookie. 2525 // Try to set-up another cookie and update the previous cookie.
2510 { 2526 {
2511 TestNetworkDelegate network_delegate; 2527 TestNetworkDelegate network_delegate;
2512 default_context_.set_network_delegate(&network_delegate); 2528 default_context_.set_network_delegate(&network_delegate);
2513 TestDelegate d; 2529 TestDelegate d;
2514 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); 2530 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE);
2515 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2531 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2516 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), 2532 test_server.GetURL("set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"),
2517 DEFAULT_PRIORITY, &d, NULL)); 2533 DEFAULT_PRIORITY, &d));
2518 req->Start(); 2534 req->Start();
2519 2535
2520 base::RunLoop().Run(); 2536 base::RunLoop().Run();
2521 2537
2522 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2538 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2523 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); 2539 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count());
2524 } 2540 }
2525 2541
2526 // Verify the cookies weren't saved or updated. 2542 // Verify the cookies weren't saved or updated.
2527 { 2543 {
2528 TestNetworkDelegate network_delegate; 2544 TestNetworkDelegate network_delegate;
2529 default_context_.set_network_delegate(&network_delegate); 2545 default_context_.set_network_delegate(&network_delegate);
2530 TestDelegate d; 2546 TestDelegate d;
2531 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2547 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2532 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2548 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2533 req->Start(); 2549 req->Start();
2534 base::RunLoop().Run(); 2550 base::RunLoop().Run();
2535 2551
2536 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") 2552 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1")
2537 == std::string::npos); 2553 == std::string::npos);
2538 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") 2554 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2")
2539 != std::string::npos); 2555 != std::string::npos);
2540 2556
2541 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2557 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2542 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2558 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2543 } 2559 }
2544 } 2560 }
2545 2561
2546 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) { 2562 TEST_F(URLRequestTest, FirstPartyOnlyCookiesEnabled) {
2547 LocalHttpTestServer test_server; 2563 LocalHttpTestServer test_server;
2548 ASSERT_TRUE(test_server.Start()); 2564 ASSERT_TRUE(test_server.Start());
2549 2565
2550 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where 2566 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where
2551 // LocalHttpTestServer points). 2567 // LocalHttpTestServer points).
2552 { 2568 {
2553 TestNetworkDelegate network_delegate; 2569 TestNetworkDelegate network_delegate;
2554 network_delegate.set_first_party_only_cookies_enabled(true); 2570 network_delegate.set_first_party_only_cookies_enabled(true);
2555 default_context_.set_network_delegate(&network_delegate); 2571 default_context_.set_network_delegate(&network_delegate);
2556 2572
2557 TestDelegate d; 2573 TestDelegate d;
2558 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2574 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2559 test_server.GetURL( 2575 test_server.GetURL(
2560 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), 2576 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"),
2561 DEFAULT_PRIORITY, &d, NULL)); 2577 DEFAULT_PRIORITY, &d));
2562 req->Start(); 2578 req->Start();
2563 base::RunLoop().Run(); 2579 base::RunLoop().Run();
2564 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2580 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2565 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2581 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2566 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2582 EXPECT_EQ(1, network_delegate.set_cookie_count());
2567 } 2583 }
2568 2584
2569 // Verify that the cookie is sent for first-party requests. 2585 // Verify that the cookie is sent for first-party requests.
2570 { 2586 {
2571 TestNetworkDelegate network_delegate; 2587 TestNetworkDelegate network_delegate;
2572 network_delegate.set_first_party_only_cookies_enabled(true); 2588 network_delegate.set_first_party_only_cookies_enabled(true);
2573 default_context_.set_network_delegate(&network_delegate); 2589 default_context_.set_network_delegate(&network_delegate);
2574 TestDelegate d; 2590 TestDelegate d;
2575 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2591 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2576 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2592 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2577 req->set_first_party_for_cookies(test_server.GetURL("")); 2593 req->set_first_party_for_cookies(test_server.GetURL(""));
2578 req->Start(); 2594 req->Start();
2579 base::RunLoop().Run(); 2595 base::RunLoop().Run();
2580 2596
2581 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != 2597 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2582 std::string::npos); 2598 std::string::npos);
2583 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2599 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2584 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2600 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2585 } 2601 }
2586 2602
2587 // Verify that the cookie is not-sent for non-first-party requests. 2603 // Verify that the cookie is not-sent for non-first-party requests.
2588 { 2604 {
2589 TestNetworkDelegate network_delegate; 2605 TestNetworkDelegate network_delegate;
2590 network_delegate.set_first_party_only_cookies_enabled(true); 2606 network_delegate.set_first_party_only_cookies_enabled(true);
2591 default_context_.set_network_delegate(&network_delegate); 2607 default_context_.set_network_delegate(&network_delegate);
2592 TestDelegate d; 2608 TestDelegate d;
2593 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2609 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2594 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2610 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2595 req->set_first_party_for_cookies(GURL("http://third-party.test/")); 2611 req->set_first_party_for_cookies(GURL("http://third-party.test/"));
2596 req->Start(); 2612 req->Start();
2597 base::RunLoop().Run(); 2613 base::RunLoop().Run();
2598 2614
2599 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") == 2615 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") ==
2600 std::string::npos); 2616 std::string::npos);
2601 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2617 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2602 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2618 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2603 } 2619 }
2604 } 2620 }
2605 2621
2606 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) { 2622 TEST_F(URLRequestTest, FirstPartyOnlyCookiesDisabled) {
2607 LocalHttpTestServer test_server; 2623 LocalHttpTestServer test_server;
2608 ASSERT_TRUE(test_server.Start()); 2624 ASSERT_TRUE(test_server.Start());
2609 2625
2610 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where 2626 // Set up a 'First-Party-Only' cookie (on '127.0.0.1', as that's where
2611 // LocalHttpTestServer points). 2627 // LocalHttpTestServer points).
2612 { 2628 {
2613 TestNetworkDelegate network_delegate; 2629 TestNetworkDelegate network_delegate;
2614 network_delegate.set_first_party_only_cookies_enabled(false); 2630 network_delegate.set_first_party_only_cookies_enabled(false);
2615 default_context_.set_network_delegate(&network_delegate); 2631 default_context_.set_network_delegate(&network_delegate);
2616 2632
2617 TestDelegate d; 2633 TestDelegate d;
2618 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2634 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2619 test_server.GetURL( 2635 test_server.GetURL(
2620 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"), 2636 "set-cookie?FirstPartyCookieToSet=1;First-Party-Only"),
2621 DEFAULT_PRIORITY, &d, NULL)); 2637 DEFAULT_PRIORITY, &d));
2622 req->Start(); 2638 req->Start();
2623 base::RunLoop().Run(); 2639 base::RunLoop().Run();
2624 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2640 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2625 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2641 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2626 EXPECT_EQ(1, network_delegate.set_cookie_count()); 2642 EXPECT_EQ(1, network_delegate.set_cookie_count());
2627 } 2643 }
2628 2644
2629 // Verify that the cookie is sent for first-party requests. 2645 // Verify that the cookie is sent for first-party requests.
2630 { 2646 {
2631 TestNetworkDelegate network_delegate; 2647 TestNetworkDelegate network_delegate;
2632 network_delegate.set_first_party_only_cookies_enabled(false); 2648 network_delegate.set_first_party_only_cookies_enabled(false);
2633 default_context_.set_network_delegate(&network_delegate); 2649 default_context_.set_network_delegate(&network_delegate);
2634 TestDelegate d; 2650 TestDelegate d;
2635 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2651 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2636 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2652 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2637 req->set_first_party_for_cookies(test_server.GetURL("")); 2653 req->set_first_party_for_cookies(test_server.GetURL(""));
2638 req->Start(); 2654 req->Start();
2639 base::RunLoop().Run(); 2655 base::RunLoop().Run();
2640 2656
2641 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != 2657 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2642 std::string::npos); 2658 std::string::npos);
2643 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2659 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2644 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2660 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2645 } 2661 }
2646 2662
2647 // Verify that the cookie is also sent for non-first-party requests. 2663 // Verify that the cookie is also sent for non-first-party requests.
2648 { 2664 {
2649 TestNetworkDelegate network_delegate; 2665 TestNetworkDelegate network_delegate;
2650 network_delegate.set_first_party_only_cookies_enabled(false); 2666 network_delegate.set_first_party_only_cookies_enabled(false);
2651 default_context_.set_network_delegate(&network_delegate); 2667 default_context_.set_network_delegate(&network_delegate);
2652 TestDelegate d; 2668 TestDelegate d;
2653 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2669 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2654 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2670 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2655 req->set_first_party_for_cookies(GURL("http://third-party.test/")); 2671 req->set_first_party_for_cookies(GURL("http://third-party.test/"));
2656 req->Start(); 2672 req->Start();
2657 base::RunLoop().Run(); 2673 base::RunLoop().Run();
2658 2674
2659 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") != 2675 EXPECT_TRUE(d.data_received().find("FirstPartyCookieToSet=1") !=
2660 std::string::npos); 2676 std::string::npos);
2661 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); 2677 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count());
2662 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); 2678 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count());
2663 } 2679 }
2664 } 2680 }
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
2713 ASSERT_TRUE(test_server.Start()); 2729 ASSERT_TRUE(test_server.Start());
2714 2730
2715 // Set up an expired cookie. 2731 // Set up an expired cookie.
2716 { 2732 {
2717 TestNetworkDelegate network_delegate; 2733 TestNetworkDelegate network_delegate;
2718 default_context_.set_network_delegate(&network_delegate); 2734 default_context_.set_network_delegate(&network_delegate);
2719 TestDelegate d; 2735 TestDelegate d;
2720 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2736 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2721 test_server.GetURL( 2737 test_server.GetURL(
2722 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), 2738 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"),
2723 DEFAULT_PRIORITY, &d, NULL)); 2739 DEFAULT_PRIORITY, &d));
2724 req->Start(); 2740 req->Start();
2725 base::RunLoop().Run(); 2741 base::RunLoop().Run();
2726 } 2742 }
2727 // Verify that the cookie is not set. 2743 // Verify that the cookie is not set.
2728 { 2744 {
2729 TestNetworkDelegate network_delegate; 2745 TestNetworkDelegate network_delegate;
2730 default_context_.set_network_delegate(&network_delegate); 2746 default_context_.set_network_delegate(&network_delegate);
2731 TestDelegate d; 2747 TestDelegate d;
2732 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2748 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2733 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2749 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2734 req->Start(); 2750 req->Start();
2735 base::RunLoop().Run(); 2751 base::RunLoop().Run();
2736 2752
2737 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); 2753 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos);
2738 } 2754 }
2739 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. 2755 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier.
2740 { 2756 {
2741 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); 2757 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC");
2742 default_context_.set_network_delegate(&network_delegate); 2758 default_context_.set_network_delegate(&network_delegate);
2743 TestDelegate d; 2759 TestDelegate d;
2744 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2760 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2745 test_server.GetURL( 2761 test_server.GetURL(
2746 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), 2762 "set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"),
2747 DEFAULT_PRIORITY, &d, NULL)); 2763 DEFAULT_PRIORITY, &d));
2748 req->Start(); 2764 req->Start();
2749 base::RunLoop().Run(); 2765 base::RunLoop().Run();
2750 } 2766 }
2751 // Verify that the cookie is set. 2767 // Verify that the cookie is set.
2752 { 2768 {
2753 TestNetworkDelegate network_delegate; 2769 TestNetworkDelegate network_delegate;
2754 default_context_.set_network_delegate(&network_delegate); 2770 default_context_.set_network_delegate(&network_delegate);
2755 TestDelegate d; 2771 TestDelegate d;
2756 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2772 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2757 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d, NULL)); 2773 test_server.GetURL("echoheader?Cookie"), DEFAULT_PRIORITY, &d));
2758 req->Start(); 2774 req->Start();
2759 base::RunLoop().Run(); 2775 base::RunLoop().Run();
2760 2776
2761 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); 2777 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos);
2762 } 2778 }
2763 } 2779 }
2764 2780
2765 2781
2766 // Check that it is impossible to change the referrer in the extra headers of 2782 // Check that it is impossible to change the referrer in the extra headers of
2767 // an URLRequest. 2783 // an URLRequest.
2768 TEST_F(URLRequestTest, DoNotOverrideReferrer) { 2784 TEST_F(URLRequestTest, DoNotOverrideReferrer) {
2769 LocalHttpTestServer test_server; 2785 LocalHttpTestServer test_server;
2770 ASSERT_TRUE(test_server.Start()); 2786 ASSERT_TRUE(test_server.Start());
2771 2787
2772 // If extra headers contain referer and the request contains a referer, 2788 // If extra headers contain referer and the request contains a referer,
2773 // only the latter shall be respected. 2789 // only the latter shall be respected.
2774 { 2790 {
2775 TestDelegate d; 2791 TestDelegate d;
2776 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2792 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2777 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); 2793 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d));
2778 req->SetReferrer("http://foo.com/"); 2794 req->SetReferrer("http://foo.com/");
2779 2795
2780 HttpRequestHeaders headers; 2796 HttpRequestHeaders headers;
2781 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); 2797 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
2782 req->SetExtraRequestHeaders(headers); 2798 req->SetExtraRequestHeaders(headers);
2783 2799
2784 req->Start(); 2800 req->Start();
2785 base::RunLoop().Run(); 2801 base::RunLoop().Run();
2786 2802
2787 EXPECT_EQ("http://foo.com/", d.data_received()); 2803 EXPECT_EQ("http://foo.com/", d.data_received());
2788 } 2804 }
2789 2805
2790 // If extra headers contain a referer but the request does not, no referer 2806 // If extra headers contain a referer but the request does not, no referer
2791 // shall be sent in the header. 2807 // shall be sent in the header.
2792 { 2808 {
2793 TestDelegate d; 2809 TestDelegate d;
2794 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2810 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
2795 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); 2811 test_server.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d));
2796 2812
2797 HttpRequestHeaders headers; 2813 HttpRequestHeaders headers;
2798 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); 2814 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/");
2799 req->SetExtraRequestHeaders(headers); 2815 req->SetExtraRequestHeaders(headers);
2800 req->SetLoadFlags(LOAD_VALIDATE_CACHE); 2816 req->SetLoadFlags(LOAD_VALIDATE_CACHE);
2801 2817
2802 req->Start(); 2818 req->Start();
2803 base::RunLoop().Run(); 2819 base::RunLoop().Run();
2804 2820
2805 EXPECT_EQ("None", d.data_received()); 2821 EXPECT_EQ("None", d.data_received());
(...skipping 14 matching lines...) Expand all
2820 // request, after redirection. 2836 // request, after redirection.
2821 // If |include_data| is true, data is uploaded with the request. The 2837 // If |include_data| is true, data is uploaded with the request. The
2822 // response body is expected to match it exactly, if and only if 2838 // response body is expected to match it exactly, if and only if
2823 // |request_method| == |redirect_method|. 2839 // |request_method| == |redirect_method|.
2824 void HTTPRedirectMethodTest(const GURL& redirect_url, 2840 void HTTPRedirectMethodTest(const GURL& redirect_url,
2825 const std::string& request_method, 2841 const std::string& request_method,
2826 const std::string& redirect_method, 2842 const std::string& redirect_method,
2827 bool include_data) { 2843 bool include_data) {
2828 static const char kData[] = "hello world"; 2844 static const char kData[] = "hello world";
2829 TestDelegate d; 2845 TestDelegate d;
2830 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 2846 scoped_ptr<URLRequest> req(
2831 redirect_url, DEFAULT_PRIORITY, &d, NULL)); 2847 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d));
2832 req->set_method(request_method); 2848 req->set_method(request_method);
2833 if (include_data) { 2849 if (include_data) {
2834 req->set_upload(CreateSimpleUploadData(kData)); 2850 req->set_upload(CreateSimpleUploadData(kData));
2835 HttpRequestHeaders headers; 2851 HttpRequestHeaders headers;
2836 headers.SetHeader(HttpRequestHeaders::kContentLength, 2852 headers.SetHeader(HttpRequestHeaders::kContentLength,
2837 base::UintToString(arraysize(kData) - 1)); 2853 base::UintToString(arraysize(kData) - 1));
2838 req->SetExtraRequestHeaders(headers); 2854 req->SetExtraRequestHeaders(headers);
2839 } 2855 }
2840 req->Start(); 2856 req->Start();
2841 base::RunLoop().Run(); 2857 base::RunLoop().Run();
(...skipping 25 matching lines...) Expand all
2867 *ptr++ = marker; 2883 *ptr++ = marker;
2868 if (++marker > 'z') 2884 if (++marker > 'z')
2869 marker = 'a'; 2885 marker = 'a';
2870 } 2886 }
2871 } 2887 }
2872 uploadBytes[kMsgSize] = '\0'; 2888 uploadBytes[kMsgSize] = '\0';
2873 2889
2874 for (int i = 0; i < kIterations; ++i) { 2890 for (int i = 0; i < kIterations; ++i) {
2875 TestDelegate d; 2891 TestDelegate d;
2876 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 2892 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
2877 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); 2893 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d));
2878 r->set_method(method.c_str()); 2894 r->set_method(method.c_str());
2879 2895
2880 r->set_upload(CreateSimpleUploadData(uploadBytes)); 2896 r->set_upload(CreateSimpleUploadData(uploadBytes));
2881 2897
2882 r->Start(); 2898 r->Start();
2883 EXPECT_TRUE(r->is_pending()); 2899 EXPECT_TRUE(r->is_pending());
2884 2900
2885 base::RunLoop().Run(); 2901 base::RunLoop().Run();
2886 2902
2887 ASSERT_EQ(1, d.response_started_count()) 2903 ASSERT_EQ(1, d.response_started_count())
(...skipping 27 matching lines...) Expand all
2915 EXPECT_FALSE(d->received_data_before_response()); 2931 EXPECT_FALSE(d->received_data_before_response());
2916 2932
2917 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received())); 2933 EXPECT_EQ(expected_data.size(), static_cast<size_t>(d->bytes_received()));
2918 EXPECT_EQ(expected_data, d->data_received()); 2934 EXPECT_EQ(expected_data, d->data_received());
2919 } 2935 }
2920 2936
2921 bool DoManyCookiesRequest(int num_cookies) { 2937 bool DoManyCookiesRequest(int num_cookies) {
2922 TestDelegate d; 2938 TestDelegate d;
2923 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 2939 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
2924 test_server_.GetURL("set-many-cookies?" + 2940 test_server_.GetURL("set-many-cookies?" +
2925 base::IntToString(num_cookies)), 2941 base::IntToString(num_cookies)),
2926 DEFAULT_PRIORITY, &d, NULL)); 2942 DEFAULT_PRIORITY, &d));
2927 2943
2928 r->Start(); 2944 r->Start();
2929 EXPECT_TRUE(r->is_pending()); 2945 EXPECT_TRUE(r->is_pending());
2930 2946
2931 base::RunLoop().Run(); 2947 base::RunLoop().Run();
2932 2948
2933 bool is_success = r->status().is_success(); 2949 bool is_success = r->status().is_success();
2934 2950
2935 if (!is_success) { 2951 if (!is_success) {
2936 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG); 2952 EXPECT_TRUE(r->status().error() == ERR_RESPONSE_HEADERS_TOO_BIG);
(...skipping 21 matching lines...) Expand all
2958 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) { 2974 TEST_F(URLRequestTestHTTP, ProxyTunnelRedirectTest) {
2959 ASSERT_TRUE(test_server_.Start()); 2975 ASSERT_TRUE(test_server_.Start());
2960 2976
2961 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 2977 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
2962 TestURLRequestContextWithProxy context( 2978 TestURLRequestContextWithProxy context(
2963 test_server_.host_port_pair().ToString(), &network_delegate); 2979 test_server_.host_port_pair().ToString(), &network_delegate);
2964 2980
2965 TestDelegate d; 2981 TestDelegate d;
2966 { 2982 {
2967 scoped_ptr<URLRequest> r(context.CreateRequest( 2983 scoped_ptr<URLRequest> r(context.CreateRequest(
2968 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, NULL)); 2984 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d));
2969 r->Start(); 2985 r->Start();
2970 EXPECT_TRUE(r->is_pending()); 2986 EXPECT_TRUE(r->is_pending());
2971 2987
2972 base::RunLoop().Run(); 2988 base::RunLoop().Run();
2973 2989
2974 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 2990 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
2975 // The proxy server is not set before failure. 2991 // The proxy server is not set before failure.
2976 EXPECT_TRUE(r->proxy_server().IsEmpty()); 2992 EXPECT_TRUE(r->proxy_server().IsEmpty());
2977 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); 2993 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error());
2978 EXPECT_EQ(1, d.response_started_count()); 2994 EXPECT_EQ(1, d.response_started_count());
2979 // We should not have followed the redirect. 2995 // We should not have followed the redirect.
2980 EXPECT_EQ(0, d.received_redirect_count()); 2996 EXPECT_EQ(0, d.received_redirect_count());
2981 } 2997 }
2982 } 2998 }
2983 2999
2984 // This is the same as the previous test, but checks that the network delegate 3000 // This is the same as the previous test, but checks that the network delegate
2985 // registers the error. 3001 // registers the error.
2986 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { 3002 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) {
2987 ASSERT_TRUE(test_server_.Start()); 3003 ASSERT_TRUE(test_server_.Start());
2988 3004
2989 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3005 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
2990 TestURLRequestContextWithProxy context( 3006 TestURLRequestContextWithProxy context(
2991 test_server_.host_port_pair().ToString(), &network_delegate); 3007 test_server_.host_port_pair().ToString(), &network_delegate);
2992 3008
2993 TestDelegate d; 3009 TestDelegate d;
2994 { 3010 {
2995 scoped_ptr<URLRequest> r(context.CreateRequest( 3011 scoped_ptr<URLRequest> r(context.CreateRequest(
2996 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, NULL)); 3012 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d));
2997 r->Start(); 3013 r->Start();
2998 EXPECT_TRUE(r->is_pending()); 3014 EXPECT_TRUE(r->is_pending());
2999 3015
3000 base::RunLoop().Run(); 3016 base::RunLoop().Run();
3001 3017
3002 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 3018 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3003 // The proxy server is not set before failure. 3019 // The proxy server is not set before failure.
3004 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3020 EXPECT_TRUE(r->proxy_server().IsEmpty());
3005 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); 3021 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error());
3006 EXPECT_EQ(1, d.response_started_count()); 3022 EXPECT_EQ(1, d.response_started_count());
(...skipping 23 matching lines...) Expand all
3030 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | 3046 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST |
3031 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | 3047 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS |
3032 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 3048 BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
3033 3049
3034 TestURLRequestContext context(true); 3050 TestURLRequestContext context(true);
3035 context.set_network_delegate(&network_delegate); 3051 context.set_network_delegate(&network_delegate);
3036 context.Init(); 3052 context.Init();
3037 3053
3038 { 3054 {
3039 scoped_ptr<URLRequest> r(context.CreateRequest( 3055 scoped_ptr<URLRequest> r(context.CreateRequest(
3040 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL)); 3056 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d));
3041 3057
3042 r->Start(); 3058 r->Start();
3043 for (size_t i = 0; i < blocking_stages_length; ++i) { 3059 for (size_t i = 0; i < blocking_stages_length; ++i) {
3044 base::RunLoop().Run(); 3060 base::RunLoop().Run();
3045 EXPECT_EQ(blocking_stages[i], 3061 EXPECT_EQ(blocking_stages[i],
3046 network_delegate.stage_blocked_for_callback()); 3062 network_delegate.stage_blocked_for_callback());
3047 network_delegate.DoCallback(OK); 3063 network_delegate.DoCallback(OK);
3048 } 3064 }
3049 base::RunLoop().Run(); 3065 base::RunLoop().Run();
3050 EXPECT_EQ(200, r->GetResponseCode()); 3066 EXPECT_EQ(200, r->GetResponseCode());
(...skipping 12 matching lines...) Expand all
3063 BlockingNetworkDelegate network_delegate( 3079 BlockingNetworkDelegate network_delegate(
3064 BlockingNetworkDelegate::AUTO_CALLBACK); 3080 BlockingNetworkDelegate::AUTO_CALLBACK);
3065 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 3081 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
3066 network_delegate.set_retval(ERR_EMPTY_RESPONSE); 3082 network_delegate.set_retval(ERR_EMPTY_RESPONSE);
3067 3083
3068 TestURLRequestContextWithProxy context( 3084 TestURLRequestContextWithProxy context(
3069 test_server_.host_port_pair().ToString(), &network_delegate); 3085 test_server_.host_port_pair().ToString(), &network_delegate);
3070 3086
3071 { 3087 {
3072 scoped_ptr<URLRequest> r(context.CreateRequest( 3088 scoped_ptr<URLRequest> r(context.CreateRequest(
3073 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 3089 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
3074 3090
3075 r->Start(); 3091 r->Start();
3076 base::RunLoop().Run(); 3092 base::RunLoop().Run();
3077 3093
3078 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 3094 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3079 // The proxy server is not set before cancellation. 3095 // The proxy server is not set before cancellation.
3080 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3096 EXPECT_TRUE(r->proxy_server().IsEmpty());
3081 EXPECT_EQ(ERR_EMPTY_RESPONSE, r->status().error()); 3097 EXPECT_EQ(ERR_EMPTY_RESPONSE, r->status().error());
3082 EXPECT_EQ(1, network_delegate.created_requests()); 3098 EXPECT_EQ(1, network_delegate.created_requests());
3083 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3099 EXPECT_EQ(0, network_delegate.destroyed_requests());
(...skipping 11 matching lines...) Expand all
3095 TestDelegate d; 3111 TestDelegate d;
3096 BlockingNetworkDelegate network_delegate(block_mode); 3112 BlockingNetworkDelegate network_delegate(block_mode);
3097 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); 3113 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT);
3098 network_delegate.set_block_on(stage); 3114 network_delegate.set_block_on(stage);
3099 3115
3100 TestURLRequestContext context(true); 3116 TestURLRequestContext context(true);
3101 context.set_network_delegate(&network_delegate); 3117 context.set_network_delegate(&network_delegate);
3102 context.Init(); 3118 context.Init();
3103 3119
3104 { 3120 {
3105 scoped_ptr<URLRequest> r(context.CreateRequest( 3121 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3106 url, DEFAULT_PRIORITY, &d, NULL));
3107 3122
3108 r->Start(); 3123 r->Start();
3109 base::RunLoop().Run(); 3124 base::RunLoop().Run();
3110 3125
3111 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 3126 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3112 // The proxy server is not set before cancellation. 3127 // The proxy server is not set before cancellation.
3113 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3128 EXPECT_TRUE(r->proxy_server().IsEmpty());
3114 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r->status().error()); 3129 EXPECT_EQ(ERR_BLOCKED_BY_CLIENT, r->status().error());
3115 EXPECT_EQ(1, network_delegate.created_requests()); 3130 EXPECT_EQ(1, network_delegate.created_requests());
3116 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3131 EXPECT_EQ(0, network_delegate.destroyed_requests());
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
3174 BlockingNetworkDelegate::AUTO_CALLBACK); 3189 BlockingNetworkDelegate::AUTO_CALLBACK);
3175 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 3190 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
3176 GURL redirect_url(test_server_.GetURL("simple.html")); 3191 GURL redirect_url(test_server_.GetURL("simple.html"));
3177 network_delegate.set_redirect_url(redirect_url); 3192 network_delegate.set_redirect_url(redirect_url);
3178 3193
3179 TestURLRequestContextWithProxy context( 3194 TestURLRequestContextWithProxy context(
3180 test_server_.host_port_pair().ToString(), &network_delegate); 3195 test_server_.host_port_pair().ToString(), &network_delegate);
3181 3196
3182 { 3197 {
3183 GURL original_url(test_server_.GetURL("empty.html")); 3198 GURL original_url(test_server_.GetURL("empty.html"));
3184 scoped_ptr<URLRequest> r(context.CreateRequest( 3199 scoped_ptr<URLRequest> r(
3185 original_url, DEFAULT_PRIORITY, &d, NULL)); 3200 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3186 3201
3187 // Quit after hitting the redirect, so can check the headers. 3202 // Quit after hitting the redirect, so can check the headers.
3188 d.set_quit_on_redirect(true); 3203 d.set_quit_on_redirect(true);
3189 r->Start(); 3204 r->Start();
3190 base::RunLoop().Run(); 3205 base::RunLoop().Run();
3191 3206
3192 // Check headers from URLRequestJob. 3207 // Check headers from URLRequestJob.
3193 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3208 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3194 EXPECT_EQ(307, r->GetResponseCode()); 3209 EXPECT_EQ(307, r->GetResponseCode());
3195 EXPECT_EQ(307, r->response_headers()->response_code()); 3210 EXPECT_EQ(307, r->response_headers()->response_code());
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
3228 BlockingNetworkDelegate network_delegate( 3243 BlockingNetworkDelegate network_delegate(
3229 BlockingNetworkDelegate::SYNCHRONOUS); 3244 BlockingNetworkDelegate::SYNCHRONOUS);
3230 GURL redirect_url(test_server_.GetURL("simple.html")); 3245 GURL redirect_url(test_server_.GetURL("simple.html"));
3231 network_delegate.set_redirect_url(redirect_url); 3246 network_delegate.set_redirect_url(redirect_url);
3232 3247
3233 TestURLRequestContextWithProxy context( 3248 TestURLRequestContextWithProxy context(
3234 test_server_.host_port_pair().ToString(), &network_delegate); 3249 test_server_.host_port_pair().ToString(), &network_delegate);
3235 3250
3236 { 3251 {
3237 GURL original_url(test_server_.GetURL("empty.html")); 3252 GURL original_url(test_server_.GetURL("empty.html"));
3238 scoped_ptr<URLRequest> r(context.CreateRequest( 3253 scoped_ptr<URLRequest> r(
3239 original_url, DEFAULT_PRIORITY, &d, NULL)); 3254 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3240 3255
3241 // Quit after hitting the redirect, so can check the headers. 3256 // Quit after hitting the redirect, so can check the headers.
3242 d.set_quit_on_redirect(true); 3257 d.set_quit_on_redirect(true);
3243 r->Start(); 3258 r->Start();
3244 base::RunLoop().Run(); 3259 base::RunLoop().Run();
3245 3260
3246 // Check headers from URLRequestJob. 3261 // Check headers from URLRequestJob.
3247 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3262 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3248 EXPECT_EQ(307, r->GetResponseCode()); 3263 EXPECT_EQ(307, r->GetResponseCode());
3249 EXPECT_EQ(307, r->response_headers()->response_code()); 3264 EXPECT_EQ(307, r->response_headers()->response_code());
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3285 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 3300 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
3286 GURL redirect_url(test_server_.GetURL("echo")); 3301 GURL redirect_url(test_server_.GetURL("echo"));
3287 network_delegate.set_redirect_url(redirect_url); 3302 network_delegate.set_redirect_url(redirect_url);
3288 3303
3289 TestURLRequestContext context(true); 3304 TestURLRequestContext context(true);
3290 context.set_network_delegate(&network_delegate); 3305 context.set_network_delegate(&network_delegate);
3291 context.Init(); 3306 context.Init();
3292 3307
3293 { 3308 {
3294 GURL original_url(test_server_.GetURL("empty.html")); 3309 GURL original_url(test_server_.GetURL("empty.html"));
3295 scoped_ptr<URLRequest> r(context.CreateRequest( 3310 scoped_ptr<URLRequest> r(
3296 original_url, DEFAULT_PRIORITY, &d, NULL)); 3311 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3297 r->set_method("POST"); 3312 r->set_method("POST");
3298 r->set_upload(CreateSimpleUploadData(kData)); 3313 r->set_upload(CreateSimpleUploadData(kData));
3299 HttpRequestHeaders headers; 3314 HttpRequestHeaders headers;
3300 headers.SetHeader(HttpRequestHeaders::kContentLength, 3315 headers.SetHeader(HttpRequestHeaders::kContentLength,
3301 base::UintToString(arraysize(kData) - 1)); 3316 base::UintToString(arraysize(kData) - 1));
3302 r->SetExtraRequestHeaders(headers); 3317 r->SetExtraRequestHeaders(headers);
3303 3318
3304 // Quit after hitting the redirect, so can check the headers. 3319 // Quit after hitting the redirect, so can check the headers.
3305 d.set_quit_on_redirect(true); 3320 d.set_quit_on_redirect(true);
3306 r->Start(); 3321 r->Start();
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
3342 BlockingNetworkDelegate::AUTO_CALLBACK); 3357 BlockingNetworkDelegate::AUTO_CALLBACK);
3343 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 3358 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
3344 GURL redirect_url(test_server_.GetURL("simple.html")); 3359 GURL redirect_url(test_server_.GetURL("simple.html"));
3345 network_delegate.set_redirect_on_headers_received_url(redirect_url); 3360 network_delegate.set_redirect_on_headers_received_url(redirect_url);
3346 3361
3347 TestURLRequestContextWithProxy context( 3362 TestURLRequestContextWithProxy context(
3348 test_server_.host_port_pair().ToString(), &network_delegate); 3363 test_server_.host_port_pair().ToString(), &network_delegate);
3349 3364
3350 { 3365 {
3351 GURL original_url(test_server_.GetURL("empty.html")); 3366 GURL original_url(test_server_.GetURL("empty.html"));
3352 scoped_ptr<URLRequest> r(context.CreateRequest( 3367 scoped_ptr<URLRequest> r(
3353 original_url, DEFAULT_PRIORITY, &d, NULL)); 3368 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
3354 3369
3355 r->Start(); 3370 r->Start();
3356 base::RunLoop().Run(); 3371 base::RunLoop().Run();
3357 3372
3358 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3373 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3359 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair())); 3374 EXPECT_TRUE(r->proxy_server().Equals(test_server_.host_port_pair()));
3360 EXPECT_EQ( 3375 EXPECT_EQ(
3361 2, network_delegate.observed_before_proxy_headers_sent_callbacks()); 3376 2, network_delegate.observed_before_proxy_headers_sent_callbacks());
3362 EXPECT_TRUE( 3377 EXPECT_TRUE(
3363 network_delegate.last_observed_proxy().Equals( 3378 network_delegate.last_observed_proxy().Equals(
(...skipping 21 matching lines...) Expand all
3385 BlockingNetworkDelegate::SYNCHRONOUS); 3400 BlockingNetworkDelegate::SYNCHRONOUS);
3386 3401
3387 TestURLRequestContext context(true); 3402 TestURLRequestContext context(true);
3388 context.set_network_delegate(&network_delegate); 3403 context.set_network_delegate(&network_delegate);
3389 context.Init(); 3404 context.Init();
3390 3405
3391 d.set_credentials(AuthCredentials(kUser, kSecret)); 3406 d.set_credentials(AuthCredentials(kUser, kSecret));
3392 3407
3393 { 3408 {
3394 GURL url(test_server_.GetURL("auth-basic")); 3409 GURL url(test_server_.GetURL("auth-basic"));
3395 scoped_ptr<URLRequest> r(context.CreateRequest( 3410 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3396 url, DEFAULT_PRIORITY, &d, NULL));
3397 r->Start(); 3411 r->Start();
3398 3412
3399 base::RunLoop().Run(); 3413 base::RunLoop().Run();
3400 3414
3401 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3415 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3402 EXPECT_EQ(0, r->status().error()); 3416 EXPECT_EQ(0, r->status().error());
3403 EXPECT_EQ(200, r->GetResponseCode()); 3417 EXPECT_EQ(200, r->GetResponseCode());
3404 EXPECT_TRUE(d.auth_required_called()); 3418 EXPECT_TRUE(d.auth_required_called());
3405 EXPECT_EQ(1, network_delegate.created_requests()); 3419 EXPECT_EQ(1, network_delegate.created_requests());
3406 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3420 EXPECT_EQ(0, network_delegate.destroyed_requests());
(...skipping 10 matching lines...) Expand all
3417 BlockingNetworkDelegate::SYNCHRONOUS); 3431 BlockingNetworkDelegate::SYNCHRONOUS);
3418 3432
3419 TestURLRequestContext context(true); 3433 TestURLRequestContext context(true);
3420 context.set_network_delegate(&network_delegate); 3434 context.set_network_delegate(&network_delegate);
3421 context.Init(); 3435 context.Init();
3422 3436
3423 d.set_credentials(AuthCredentials(kUser, kSecret)); 3437 d.set_credentials(AuthCredentials(kUser, kSecret));
3424 3438
3425 { 3439 {
3426 GURL url(test_server_.GetURL("auth-basic")); 3440 GURL url(test_server_.GetURL("auth-basic"));
3427 scoped_ptr<URLRequest> r(context.CreateRequest( 3441 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3428 url, DEFAULT_PRIORITY, &d, NULL));
3429 r->Start(); 3442 r->Start();
3430 3443
3431 { 3444 {
3432 HttpRequestHeaders headers; 3445 HttpRequestHeaders headers;
3433 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); 3446 EXPECT_TRUE(r->GetFullRequestHeaders(&headers));
3434 EXPECT_FALSE(headers.HasHeader("Authorization")); 3447 EXPECT_FALSE(headers.HasHeader("Authorization"));
3435 } 3448 }
3436 3449
3437 base::RunLoop().Run(); 3450 base::RunLoop().Run();
3438 3451
(...skipping 20 matching lines...) Expand all
3459 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 3472 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
3460 3473
3461 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); 3474 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret));
3462 3475
3463 TestURLRequestContext context(true); 3476 TestURLRequestContext context(true);
3464 context.set_network_delegate(&network_delegate); 3477 context.set_network_delegate(&network_delegate);
3465 context.Init(); 3478 context.Init();
3466 3479
3467 { 3480 {
3468 GURL url(test_server_.GetURL("auth-basic")); 3481 GURL url(test_server_.GetURL("auth-basic"));
3469 scoped_ptr<URLRequest> r(context.CreateRequest( 3482 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3470 url, DEFAULT_PRIORITY, &d, NULL));
3471 r->Start(); 3483 r->Start();
3472 base::RunLoop().Run(); 3484 base::RunLoop().Run();
3473 3485
3474 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3486 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3475 EXPECT_EQ(0, r->status().error()); 3487 EXPECT_EQ(0, r->status().error());
3476 EXPECT_EQ(200, r->GetResponseCode()); 3488 EXPECT_EQ(200, r->GetResponseCode());
3477 EXPECT_FALSE(d.auth_required_called()); 3489 EXPECT_FALSE(d.auth_required_called());
3478 EXPECT_EQ(1, network_delegate.created_requests()); 3490 EXPECT_EQ(1, network_delegate.created_requests());
3479 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3491 EXPECT_EQ(0, network_delegate.destroyed_requests());
3480 } 3492 }
(...skipping 14 matching lines...) Expand all
3495 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); 3507 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH);
3496 3508
3497 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); 3509 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret));
3498 3510
3499 TestURLRequestContext context(true); 3511 TestURLRequestContext context(true);
3500 context.set_network_delegate(&network_delegate); 3512 context.set_network_delegate(&network_delegate);
3501 context.Init(); 3513 context.Init();
3502 3514
3503 { 3515 {
3504 GURL url(test_server_.GetURL("auth-basic")); 3516 GURL url(test_server_.GetURL("auth-basic"));
3505 scoped_ptr<URLRequest> r(context.CreateRequest( 3517 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3506 url, DEFAULT_PRIORITY, &d, NULL));
3507 r->Start(); 3518 r->Start();
3508 base::RunLoop().Run(); 3519 base::RunLoop().Run();
3509 3520
3510 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3521 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3511 EXPECT_EQ(0, r->status().error()); 3522 EXPECT_EQ(0, r->status().error());
3512 EXPECT_EQ(200, r->GetResponseCode()); 3523 EXPECT_EQ(200, r->GetResponseCode());
3513 EXPECT_FALSE(d.auth_required_called()); 3524 EXPECT_FALSE(d.auth_required_called());
3514 EXPECT_EQ(1, network_delegate.created_requests()); 3525 EXPECT_EQ(1, network_delegate.created_requests());
3515 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3526 EXPECT_EQ(0, network_delegate.destroyed_requests());
3516 3527
(...skipping 17 matching lines...) Expand all
3534 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3545 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3535 network_delegate.set_auth_retval( 3546 network_delegate.set_auth_retval(
3536 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); 3547 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
3537 3548
3538 TestURLRequestContext context(true); 3549 TestURLRequestContext context(true);
3539 context.set_network_delegate(&network_delegate); 3550 context.set_network_delegate(&network_delegate);
3540 context.Init(); 3551 context.Init();
3541 3552
3542 { 3553 {
3543 GURL url(test_server_.GetURL("auth-basic")); 3554 GURL url(test_server_.GetURL("auth-basic"));
3544 scoped_ptr<URLRequest> r(context.CreateRequest( 3555 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3545 url, DEFAULT_PRIORITY, &d, NULL));
3546 r->Start(); 3556 r->Start();
3547 base::RunLoop().Run(); 3557 base::RunLoop().Run();
3548 3558
3549 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3559 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3550 EXPECT_EQ(OK, r->status().error()); 3560 EXPECT_EQ(OK, r->status().error());
3551 EXPECT_EQ(401, r->GetResponseCode()); 3561 EXPECT_EQ(401, r->GetResponseCode());
3552 EXPECT_FALSE(d.auth_required_called()); 3562 EXPECT_FALSE(d.auth_required_called());
3553 EXPECT_EQ(1, network_delegate.created_requests()); 3563 EXPECT_EQ(1, network_delegate.created_requests());
3554 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3564 EXPECT_EQ(0, network_delegate.destroyed_requests());
3555 } 3565 }
(...skipping 13 matching lines...) Expand all
3569 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3579 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3570 3580
3571 TestURLRequestContext context(true); 3581 TestURLRequestContext context(true);
3572 context.set_network_delegate(&network_delegate); 3582 context.set_network_delegate(&network_delegate);
3573 context.Init(); 3583 context.Init();
3574 3584
3575 d.set_credentials(AuthCredentials(kUser, kSecret)); 3585 d.set_credentials(AuthCredentials(kUser, kSecret));
3576 3586
3577 { 3587 {
3578 GURL url(test_server_.GetURL("auth-basic")); 3588 GURL url(test_server_.GetURL("auth-basic"));
3579 scoped_ptr<URLRequest> r(context.CreateRequest( 3589 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3580 url, DEFAULT_PRIORITY, &d, NULL));
3581 r->Start(); 3590 r->Start();
3582 base::RunLoop().Run(); 3591 base::RunLoop().Run();
3583 3592
3584 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3593 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3585 EXPECT_EQ(0, r->status().error()); 3594 EXPECT_EQ(0, r->status().error());
3586 EXPECT_EQ(200, r->GetResponseCode()); 3595 EXPECT_EQ(200, r->GetResponseCode());
3587 EXPECT_TRUE(d.auth_required_called()); 3596 EXPECT_TRUE(d.auth_required_called());
3588 EXPECT_EQ(1, network_delegate.created_requests()); 3597 EXPECT_EQ(1, network_delegate.created_requests());
3589 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3598 EXPECT_EQ(0, network_delegate.destroyed_requests());
3590 } 3599 }
(...skipping 14 matching lines...) Expand all
3605 3614
3606 AuthCredentials auth_credentials(kUser, kSecret); 3615 AuthCredentials auth_credentials(kUser, kSecret);
3607 network_delegate.set_auth_credentials(auth_credentials); 3616 network_delegate.set_auth_credentials(auth_credentials);
3608 3617
3609 TestURLRequestContext context(true); 3618 TestURLRequestContext context(true);
3610 context.set_network_delegate(&network_delegate); 3619 context.set_network_delegate(&network_delegate);
3611 context.Init(); 3620 context.Init();
3612 3621
3613 { 3622 {
3614 GURL url(test_server_.GetURL("auth-basic")); 3623 GURL url(test_server_.GetURL("auth-basic"));
3615 scoped_ptr<URLRequest> r(context.CreateRequest( 3624 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3616 url, DEFAULT_PRIORITY, &d, NULL));
3617 r->Start(); 3625 r->Start();
3618 base::RunLoop().Run(); 3626 base::RunLoop().Run();
3619 3627
3620 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3628 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3621 EXPECT_EQ(0, r->status().error()); 3629 EXPECT_EQ(0, r->status().error());
3622 3630
3623 EXPECT_EQ(200, r->GetResponseCode()); 3631 EXPECT_EQ(200, r->GetResponseCode());
3624 EXPECT_FALSE(d.auth_required_called()); 3632 EXPECT_FALSE(d.auth_required_called());
3625 EXPECT_EQ(1, network_delegate.created_requests()); 3633 EXPECT_EQ(1, network_delegate.created_requests());
3626 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3634 EXPECT_EQ(0, network_delegate.destroyed_requests());
(...skipping 12 matching lines...) Expand all
3639 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3647 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3640 network_delegate.set_auth_retval( 3648 network_delegate.set_auth_retval(
3641 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); 3649 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH);
3642 3650
3643 TestURLRequestContext context(true); 3651 TestURLRequestContext context(true);
3644 context.set_network_delegate(&network_delegate); 3652 context.set_network_delegate(&network_delegate);
3645 context.Init(); 3653 context.Init();
3646 3654
3647 { 3655 {
3648 GURL url(test_server_.GetURL("auth-basic")); 3656 GURL url(test_server_.GetURL("auth-basic"));
3649 scoped_ptr<URLRequest> r(context.CreateRequest( 3657 scoped_ptr<URLRequest> r(context.CreateRequest(url, DEFAULT_PRIORITY, &d));
3650 url, DEFAULT_PRIORITY, &d, NULL));
3651 r->Start(); 3658 r->Start();
3652 base::RunLoop().Run(); 3659 base::RunLoop().Run();
3653 3660
3654 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 3661 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
3655 EXPECT_EQ(OK, r->status().error()); 3662 EXPECT_EQ(OK, r->status().error());
3656 EXPECT_EQ(401, r->GetResponseCode()); 3663 EXPECT_EQ(401, r->GetResponseCode());
3657 EXPECT_FALSE(d.auth_required_called()); 3664 EXPECT_FALSE(d.auth_required_called());
3658 EXPECT_EQ(1, network_delegate.created_requests()); 3665 EXPECT_EQ(1, network_delegate.created_requests());
3659 EXPECT_EQ(0, network_delegate.destroyed_requests()); 3666 EXPECT_EQ(0, network_delegate.destroyed_requests());
3660 } 3667 }
(...skipping 10 matching lines...) Expand all
3671 BlockingNetworkDelegate network_delegate( 3678 BlockingNetworkDelegate network_delegate(
3672 BlockingNetworkDelegate::USER_CALLBACK); 3679 BlockingNetworkDelegate::USER_CALLBACK);
3673 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); 3680 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST);
3674 3681
3675 TestURLRequestContext context(true); 3682 TestURLRequestContext context(true);
3676 context.set_network_delegate(&network_delegate); 3683 context.set_network_delegate(&network_delegate);
3677 context.Init(); 3684 context.Init();
3678 3685
3679 { 3686 {
3680 scoped_ptr<URLRequest> r(context.CreateRequest( 3687 scoped_ptr<URLRequest> r(context.CreateRequest(
3681 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 3688 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
3682 3689
3683 r->Start(); 3690 r->Start();
3684 base::RunLoop().Run(); 3691 base::RunLoop().Run();
3685 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, 3692 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST,
3686 network_delegate.stage_blocked_for_callback()); 3693 network_delegate.stage_blocked_for_callback());
3687 EXPECT_EQ(0, network_delegate.completed_requests()); 3694 EXPECT_EQ(0, network_delegate.completed_requests());
3688 // Cancel before callback. 3695 // Cancel before callback.
3689 r->Cancel(); 3696 r->Cancel();
3690 // Ensure that network delegate is notified. 3697 // Ensure that network delegate is notified.
3691 EXPECT_EQ(1, network_delegate.completed_requests()); 3698 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 16 matching lines...) Expand all
3708 BlockingNetworkDelegate::USER_CALLBACK); 3715 BlockingNetworkDelegate::USER_CALLBACK);
3709 network_delegate.set_block_on( 3716 network_delegate.set_block_on(
3710 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); 3717 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS);
3711 3718
3712 TestURLRequestContext context(true); 3719 TestURLRequestContext context(true);
3713 context.set_network_delegate(&network_delegate); 3720 context.set_network_delegate(&network_delegate);
3714 context.Init(); 3721 context.Init();
3715 3722
3716 { 3723 {
3717 scoped_ptr<URLRequest> r(context.CreateRequest( 3724 scoped_ptr<URLRequest> r(context.CreateRequest(
3718 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 3725 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
3719 3726
3720 r->Start(); 3727 r->Start();
3721 base::RunLoop().Run(); 3728 base::RunLoop().Run();
3722 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, 3729 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS,
3723 network_delegate.stage_blocked_for_callback()); 3730 network_delegate.stage_blocked_for_callback());
3724 EXPECT_EQ(0, network_delegate.completed_requests()); 3731 EXPECT_EQ(0, network_delegate.completed_requests());
3725 // Cancel before callback. 3732 // Cancel before callback.
3726 r->Cancel(); 3733 r->Cancel();
3727 // Ensure that network delegate is notified. 3734 // Ensure that network delegate is notified.
3728 EXPECT_EQ(1, network_delegate.completed_requests()); 3735 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 15 matching lines...) Expand all
3744 BlockingNetworkDelegate network_delegate( 3751 BlockingNetworkDelegate network_delegate(
3745 BlockingNetworkDelegate::USER_CALLBACK); 3752 BlockingNetworkDelegate::USER_CALLBACK);
3746 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); 3753 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED);
3747 3754
3748 TestURLRequestContext context(true); 3755 TestURLRequestContext context(true);
3749 context.set_network_delegate(&network_delegate); 3756 context.set_network_delegate(&network_delegate);
3750 context.Init(); 3757 context.Init();
3751 3758
3752 { 3759 {
3753 scoped_ptr<URLRequest> r(context.CreateRequest( 3760 scoped_ptr<URLRequest> r(context.CreateRequest(
3754 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 3761 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
3755 3762
3756 r->Start(); 3763 r->Start();
3757 base::RunLoop().Run(); 3764 base::RunLoop().Run();
3758 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, 3765 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED,
3759 network_delegate.stage_blocked_for_callback()); 3766 network_delegate.stage_blocked_for_callback());
3760 EXPECT_EQ(0, network_delegate.completed_requests()); 3767 EXPECT_EQ(0, network_delegate.completed_requests());
3761 // Cancel before callback. 3768 // Cancel before callback.
3762 r->Cancel(); 3769 r->Cancel();
3763 // Ensure that network delegate is notified. 3770 // Ensure that network delegate is notified.
3764 EXPECT_EQ(1, network_delegate.completed_requests()); 3771 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 15 matching lines...) Expand all
3780 BlockingNetworkDelegate network_delegate( 3787 BlockingNetworkDelegate network_delegate(
3781 BlockingNetworkDelegate::USER_CALLBACK); 3788 BlockingNetworkDelegate::USER_CALLBACK);
3782 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); 3789 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED);
3783 3790
3784 TestURLRequestContext context(true); 3791 TestURLRequestContext context(true);
3785 context.set_network_delegate(&network_delegate); 3792 context.set_network_delegate(&network_delegate);
3786 context.Init(); 3793 context.Init();
3787 3794
3788 { 3795 {
3789 scoped_ptr<URLRequest> r(context.CreateRequest( 3796 scoped_ptr<URLRequest> r(context.CreateRequest(
3790 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); 3797 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d));
3791 3798
3792 r->Start(); 3799 r->Start();
3793 base::RunLoop().Run(); 3800 base::RunLoop().Run();
3794 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, 3801 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED,
3795 network_delegate.stage_blocked_for_callback()); 3802 network_delegate.stage_blocked_for_callback());
3796 EXPECT_EQ(0, network_delegate.completed_requests()); 3803 EXPECT_EQ(0, network_delegate.completed_requests());
3797 // Cancel before callback. 3804 // Cancel before callback.
3798 r->Cancel(); 3805 r->Cancel();
3799 // Ensure that network delegate is notified. 3806 // Ensure that network delegate is notified.
3800 EXPECT_EQ(1, network_delegate.completed_requests()); 3807 EXPECT_EQ(1, network_delegate.completed_requests());
(...skipping 11 matching lines...) Expand all
3812 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) { 3819 TEST_F(URLRequestTestHTTP, UnexpectedServerAuthTest) {
3813 ASSERT_TRUE(test_server_.Start()); 3820 ASSERT_TRUE(test_server_.Start());
3814 3821
3815 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 3822 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
3816 TestURLRequestContextWithProxy context( 3823 TestURLRequestContextWithProxy context(
3817 test_server_.host_port_pair().ToString(), &network_delegate); 3824 test_server_.host_port_pair().ToString(), &network_delegate);
3818 3825
3819 TestDelegate d; 3826 TestDelegate d;
3820 { 3827 {
3821 scoped_ptr<URLRequest> r(context.CreateRequest( 3828 scoped_ptr<URLRequest> r(context.CreateRequest(
3822 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d, NULL)); 3829 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d));
3823 3830
3824 r->Start(); 3831 r->Start();
3825 EXPECT_TRUE(r->is_pending()); 3832 EXPECT_TRUE(r->is_pending());
3826 3833
3827 base::RunLoop().Run(); 3834 base::RunLoop().Run();
3828 3835
3829 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 3836 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
3830 // The proxy server is not set before failure. 3837 // The proxy server is not set before failure.
3831 EXPECT_TRUE(r->proxy_server().IsEmpty()); 3838 EXPECT_TRUE(r->proxy_server().IsEmpty());
3832 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error()); 3839 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, r->status().error());
3833 } 3840 }
3834 } 3841 }
3835 3842
3836 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { 3843 TEST_F(URLRequestTestHTTP, GetTest_NoCache) {
3837 ASSERT_TRUE(test_server_.Start()); 3844 ASSERT_TRUE(test_server_.Start());
3838 3845
3839 TestDelegate d; 3846 TestDelegate d;
3840 { 3847 {
3841 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 3848 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
3842 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 3849 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
3843 3850
3844 r->Start(); 3851 r->Start();
3845 EXPECT_TRUE(r->is_pending()); 3852 EXPECT_TRUE(r->is_pending());
3846 3853
3847 base::RunLoop().Run(); 3854 base::RunLoop().Run();
3848 3855
3849 EXPECT_EQ(1, d.response_started_count()); 3856 EXPECT_EQ(1, d.response_started_count());
3850 EXPECT_FALSE(d.received_data_before_response()); 3857 EXPECT_FALSE(d.received_data_before_response());
3851 EXPECT_NE(0, d.bytes_received()); 3858 EXPECT_NE(0, d.bytes_received());
3852 EXPECT_EQ(test_server_.host_port_pair().host(), 3859 EXPECT_EQ(test_server_.host_port_pair().host(),
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
3899 } 3906 }
3900 // Success: the test did not crash. 3907 // Success: the test did not crash.
3901 } 3908 }
3902 3909
3903 TEST_F(URLRequestTestHTTP, GetTest) { 3910 TEST_F(URLRequestTestHTTP, GetTest) {
3904 ASSERT_TRUE(test_server_.Start()); 3911 ASSERT_TRUE(test_server_.Start());
3905 3912
3906 TestDelegate d; 3913 TestDelegate d;
3907 { 3914 {
3908 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 3915 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
3909 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 3916 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
3910 3917
3911 r->Start(); 3918 r->Start();
3912 EXPECT_TRUE(r->is_pending()); 3919 EXPECT_TRUE(r->is_pending());
3913 3920
3914 base::RunLoop().Run(); 3921 base::RunLoop().Run();
3915 3922
3916 EXPECT_EQ(1, d.response_started_count()); 3923 EXPECT_EQ(1, d.response_started_count());
3917 EXPECT_FALSE(d.received_data_before_response()); 3924 EXPECT_FALSE(d.received_data_before_response());
3918 EXPECT_NE(0, d.bytes_received()); 3925 EXPECT_NE(0, d.bytes_received());
3919 EXPECT_EQ(test_server_.host_port_pair().host(), 3926 EXPECT_EQ(test_server_.host_port_pair().host(),
3920 r->GetSocketAddress().host()); 3927 r->GetSocketAddress().host());
3921 EXPECT_EQ(test_server_.host_port_pair().port(), 3928 EXPECT_EQ(test_server_.host_port_pair().port(),
3922 r->GetSocketAddress().port()); 3929 r->GetSocketAddress().port());
3923 } 3930 }
3924 } 3931 }
3925 3932
3926 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { 3933 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) {
3927 ASSERT_TRUE(test_server_.Start()); 3934 ASSERT_TRUE(test_server_.Start());
3928 3935
3929 TestDelegate d; 3936 TestDelegate d;
3930 { 3937 {
3931 GURL test_url(test_server_.GetURL(std::string())); 3938 GURL test_url(test_server_.GetURL(std::string()));
3932 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 3939 scoped_ptr<URLRequest> r(
3933 test_url, DEFAULT_PRIORITY, &d, NULL)); 3940 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d));
3934 3941
3935 HttpRequestHeaders headers; 3942 HttpRequestHeaders headers;
3936 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); 3943 EXPECT_FALSE(r->GetFullRequestHeaders(&headers));
3937 3944
3938 r->Start(); 3945 r->Start();
3939 EXPECT_TRUE(r->is_pending()); 3946 EXPECT_TRUE(r->is_pending());
3940 3947
3941 base::RunLoop().Run(); 3948 base::RunLoop().Run();
3942 3949
3943 EXPECT_EQ(1, d.response_started_count()); 3950 EXPECT_EQ(1, d.response_started_count());
3944 EXPECT_FALSE(d.received_data_before_response()); 3951 EXPECT_FALSE(d.received_data_before_response());
3945 EXPECT_NE(0, d.bytes_received()); 3952 EXPECT_NE(0, d.bytes_received());
3946 EXPECT_EQ(test_server_.host_port_pair().host(), 3953 EXPECT_EQ(test_server_.host_port_pair().host(),
3947 r->GetSocketAddress().host()); 3954 r->GetSocketAddress().host());
3948 EXPECT_EQ(test_server_.host_port_pair().port(), 3955 EXPECT_EQ(test_server_.host_port_pair().port(),
3949 r->GetSocketAddress().port()); 3956 r->GetSocketAddress().port());
3950 3957
3951 EXPECT_TRUE(d.have_full_request_headers()); 3958 EXPECT_TRUE(d.have_full_request_headers());
3952 CheckFullRequestHeaders(d.full_request_headers(), test_url); 3959 CheckFullRequestHeaders(d.full_request_headers(), test_url);
3953 } 3960 }
3954 } 3961 }
3955 3962
3956 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { 3963 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) {
3957 ASSERT_TRUE(test_server_.Start()); 3964 ASSERT_TRUE(test_server_.Start());
3958 3965
3959 TestDelegate d; 3966 TestDelegate d;
3960 { 3967 {
3961 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 3968 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
3962 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 3969 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
3963 3970
3964 r->Start(); 3971 r->Start();
3965 EXPECT_TRUE(r->is_pending()); 3972 EXPECT_TRUE(r->is_pending());
3966 3973
3967 base::RunLoop().Run(); 3974 base::RunLoop().Run();
3968 3975
3969 LoadTimingInfo load_timing_info; 3976 LoadTimingInfo load_timing_info;
3970 r->GetLoadTimingInfo(&load_timing_info); 3977 r->GetLoadTimingInfo(&load_timing_info);
3971 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 3978 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
3972 3979
(...skipping 30 matching lines...) Expand all
4003 std::string test_file = 4010 std::string test_file =
4004 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c", 4011 base::StringPrintf("compressedfiles/BullRunSpeech.txt?%c",
4005 test_parameters[i]); 4012 test_parameters[i]);
4006 4013
4007 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 4014 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
4008 TestURLRequestContext context(true); 4015 TestURLRequestContext context(true);
4009 context.set_network_delegate(&network_delegate); 4016 context.set_network_delegate(&network_delegate);
4010 context.Init(); 4017 context.Init();
4011 4018
4012 scoped_ptr<URLRequest> r(context.CreateRequest( 4019 scoped_ptr<URLRequest> r(context.CreateRequest(
4013 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d, NULL)); 4020 test_server_.GetURL(test_file), DEFAULT_PRIORITY, &d));
4014 r->Start(); 4021 r->Start();
4015 EXPECT_TRUE(r->is_pending()); 4022 EXPECT_TRUE(r->is_pending());
4016 4023
4017 base::RunLoop().Run(); 4024 base::RunLoop().Run();
4018 4025
4019 EXPECT_EQ(1, d.response_started_count()); 4026 EXPECT_EQ(1, d.response_started_count());
4020 EXPECT_FALSE(d.received_data_before_response()); 4027 EXPECT_FALSE(d.received_data_before_response());
4021 VLOG(1) << " Received " << d.bytes_received() << " bytes" 4028 VLOG(1) << " Received " << d.bytes_received() << " bytes"
4022 << " status = " << r->status().status() 4029 << " status = " << r->status().status()
4023 << " error = " << r->status().error(); 4030 << " error = " << r->status().error();
4024 if (test_expect_success[i]) { 4031 if (test_expect_success[i]) {
4025 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()) 4032 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status())
4026 << " Parameter = \"" << test_file << "\""; 4033 << " Parameter = \"" << test_file << "\"";
4027 } else { 4034 } else {
4028 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 4035 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
4029 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error()) 4036 EXPECT_EQ(ERR_CONTENT_LENGTH_MISMATCH, r->status().error())
4030 << " Parameter = \"" << test_file << "\""; 4037 << " Parameter = \"" << test_file << "\"";
4031 } 4038 }
4032 } 4039 }
4033 } 4040 }
4034 } 4041 }
4035 4042
4036 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { 4043 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) {
4037 ASSERT_TRUE(test_server_.Start()); 4044 ASSERT_TRUE(test_server_.Start());
4038 4045
4039 GURL destination_url = test_server_.GetURL(std::string()); 4046 GURL destination_url = test_server_.GetURL(std::string());
4040 GURL original_url = 4047 GURL original_url =
4041 test_server_.GetURL("server-redirect?" + destination_url.spec()); 4048 test_server_.GetURL("server-redirect?" + destination_url.spec());
4042 TestDelegate d; 4049 TestDelegate d;
4043 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 4050 scoped_ptr<URLRequest> req(
4044 original_url, DEFAULT_PRIORITY, &d, NULL)); 4051 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
4045 req->Start(); 4052 req->Start();
4046 base::RunLoop().Run(); 4053 base::RunLoop().Run();
4047 4054
4048 EXPECT_EQ(1, d.response_started_count()); 4055 EXPECT_EQ(1, d.response_started_count());
4049 EXPECT_EQ(1, d.received_redirect_count()); 4056 EXPECT_EQ(1, d.received_redirect_count());
4050 EXPECT_EQ(destination_url, req->url()); 4057 EXPECT_EQ(destination_url, req->url());
4051 EXPECT_EQ(original_url, req->original_url()); 4058 EXPECT_EQ(original_url, req->original_url());
4052 ASSERT_EQ(2U, req->url_chain().size()); 4059 ASSERT_EQ(2U, req->url_chain().size());
4053 EXPECT_EQ(original_url, req->url_chain()[0]); 4060 EXPECT_EQ(original_url, req->url_chain()[0]);
4054 EXPECT_EQ(destination_url, req->url_chain()[1]); 4061 EXPECT_EQ(destination_url, req->url_chain()[1]);
(...skipping 19 matching lines...) Expand all
4074 4081
4075 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { 4082 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) {
4076 ASSERT_TRUE(test_server_.Start()); 4083 ASSERT_TRUE(test_server_.Start());
4077 4084
4078 GURL destination_url = test_server_.GetURL(std::string()); 4085 GURL destination_url = test_server_.GetURL(std::string());
4079 GURL middle_redirect_url = 4086 GURL middle_redirect_url =
4080 test_server_.GetURL("server-redirect?" + destination_url.spec()); 4087 test_server_.GetURL("server-redirect?" + destination_url.spec());
4081 GURL original_url = test_server_.GetURL( 4088 GURL original_url = test_server_.GetURL(
4082 "server-redirect?" + middle_redirect_url.spec()); 4089 "server-redirect?" + middle_redirect_url.spec());
4083 TestDelegate d; 4090 TestDelegate d;
4084 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 4091 scoped_ptr<URLRequest> req(
4085 original_url, DEFAULT_PRIORITY, &d, NULL)); 4092 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
4086 req->Start(); 4093 req->Start();
4087 base::RunLoop().Run(); 4094 base::RunLoop().Run();
4088 4095
4089 EXPECT_EQ(1, d.response_started_count()); 4096 EXPECT_EQ(1, d.response_started_count());
4090 EXPECT_EQ(2, d.received_redirect_count()); 4097 EXPECT_EQ(2, d.received_redirect_count());
4091 EXPECT_EQ(destination_url, req->url()); 4098 EXPECT_EQ(destination_url, req->url());
4092 EXPECT_EQ(original_url, req->original_url()); 4099 EXPECT_EQ(original_url, req->original_url());
4093 ASSERT_EQ(3U, req->url_chain().size()); 4100 ASSERT_EQ(3U, req->url_chain().size());
4094 EXPECT_EQ(original_url, req->url_chain()[0]); 4101 EXPECT_EQ(original_url, req->url_chain()[0]);
4095 EXPECT_EQ(middle_redirect_url, req->url_chain()[1]); 4102 EXPECT_EQ(middle_redirect_url, req->url_chain()[1]);
(...skipping 309 matching lines...) Expand 10 before | Expand all | Expand 10 after
4405 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) { 4412 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) {
4406 ASSERT_TRUE(test_server_.Start()); 4413 ASSERT_TRUE(test_server_.Start());
4407 4414
4408 TestDelegate request_delegate; 4415 TestDelegate request_delegate;
4409 TestURLRequestContext context(true); 4416 TestURLRequestContext context(true);
4410 context.set_network_delegate(NULL); 4417 context.set_network_delegate(NULL);
4411 context.set_net_log(&net_log_); 4418 context.set_net_log(&net_log_);
4412 context.Init(); 4419 context.Init();
4413 4420
4414 { 4421 {
4415 scoped_ptr<URLRequest> r(context.CreateRequest( 4422 scoped_ptr<URLRequest> r(
4416 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &request_delegate, 4423 context.CreateRequest(test_server_.GetURL("empty.html"),
4417 NULL)); 4424 DEFAULT_PRIORITY, &request_delegate));
4418 LoadStateWithParam load_state = r->GetLoadState(); 4425 LoadStateWithParam load_state = r->GetLoadState();
4419 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4426 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4420 EXPECT_EQ(base::string16(), load_state.param); 4427 EXPECT_EQ(base::string16(), load_state.param);
4421 4428
4422 AsyncDelegateLogger::Run( 4429 AsyncDelegateLogger::Run(
4423 r.get(), 4430 r.get(),
4424 LOAD_STATE_WAITING_FOR_DELEGATE, 4431 LOAD_STATE_WAITING_FOR_DELEGATE,
4425 LOAD_STATE_WAITING_FOR_DELEGATE, 4432 LOAD_STATE_WAITING_FOR_DELEGATE,
4426 LOAD_STATE_IDLE, 4433 LOAD_STATE_IDLE,
4427 base::Bind(&URLRequest::Start, base::Unretained(r.get()))); 4434 base::Bind(&URLRequest::Start, base::Unretained(r.get())));
(...skipping 24 matching lines...) Expand all
4452 ASSERT_TRUE(test_server_.Start()); 4459 ASSERT_TRUE(test_server_.Start());
4453 4460
4454 TestDelegate request_delegate; 4461 TestDelegate request_delegate;
4455 AsyncLoggingNetworkDelegate network_delegate; 4462 AsyncLoggingNetworkDelegate network_delegate;
4456 TestURLRequestContext context(true); 4463 TestURLRequestContext context(true);
4457 context.set_network_delegate(&network_delegate); 4464 context.set_network_delegate(&network_delegate);
4458 context.set_net_log(&net_log_); 4465 context.set_net_log(&net_log_);
4459 context.Init(); 4466 context.Init();
4460 4467
4461 { 4468 {
4462 scoped_ptr<URLRequest> r(context.CreateRequest( 4469 scoped_ptr<URLRequest> r(
4463 test_server_.GetURL("simple.html"), DEFAULT_PRIORITY, &request_delegate, 4470 context.CreateRequest(test_server_.GetURL("simple.html"),
4464 NULL)); 4471 DEFAULT_PRIORITY, &request_delegate));
4465 LoadStateWithParam load_state = r->GetLoadState(); 4472 LoadStateWithParam load_state = r->GetLoadState();
4466 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4473 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4467 EXPECT_EQ(base::string16(), load_state.param); 4474 EXPECT_EQ(base::string16(), load_state.param);
4468 4475
4469 r->Start(); 4476 r->Start();
4470 base::RunLoop().Run(); 4477 base::RunLoop().Run();
4471 4478
4472 EXPECT_EQ(200, r->GetResponseCode()); 4479 EXPECT_EQ(200, r->GetResponseCode());
4473 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4480 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4474 EXPECT_EQ(1, network_delegate.created_requests()); 4481 EXPECT_EQ(1, network_delegate.created_requests());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
4511 TestDelegate request_delegate; 4518 TestDelegate request_delegate;
4512 AsyncLoggingNetworkDelegate network_delegate; 4519 AsyncLoggingNetworkDelegate network_delegate;
4513 TestURLRequestContext context(true); 4520 TestURLRequestContext context(true);
4514 context.set_network_delegate(&network_delegate); 4521 context.set_network_delegate(&network_delegate);
4515 context.set_net_log(&net_log_); 4522 context.set_net_log(&net_log_);
4516 context.Init(); 4523 context.Init();
4517 4524
4518 { 4525 {
4519 scoped_ptr<URLRequest> r(context.CreateRequest( 4526 scoped_ptr<URLRequest> r(context.CreateRequest(
4520 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, 4527 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY,
4521 &request_delegate, NULL)); 4528 &request_delegate));
4522 LoadStateWithParam load_state = r->GetLoadState(); 4529 LoadStateWithParam load_state = r->GetLoadState();
4523 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4530 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4524 EXPECT_EQ(base::string16(), load_state.param); 4531 EXPECT_EQ(base::string16(), load_state.param);
4525 4532
4526 r->Start(); 4533 r->Start();
4527 base::RunLoop().Run(); 4534 base::RunLoop().Run();
4528 4535
4529 EXPECT_EQ(200, r->GetResponseCode()); 4536 EXPECT_EQ(200, r->GetResponseCode());
4530 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4537 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4531 EXPECT_EQ(2, network_delegate.created_requests()); 4538 EXPECT_EQ(2, network_delegate.created_requests());
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
4591 ASSERT_TRUE(test_server_.Start()); 4598 ASSERT_TRUE(test_server_.Start());
4592 4599
4593 TestDelegate request_delegate; 4600 TestDelegate request_delegate;
4594 AsyncLoggingNetworkDelegate network_delegate; 4601 AsyncLoggingNetworkDelegate network_delegate;
4595 TestURLRequestContext context(true); 4602 TestURLRequestContext context(true);
4596 context.set_network_delegate(&network_delegate); 4603 context.set_network_delegate(&network_delegate);
4597 context.set_net_log(&net_log_); 4604 context.set_net_log(&net_log_);
4598 context.Init(); 4605 context.Init();
4599 4606
4600 { 4607 {
4601 scoped_ptr<URLRequest> r(context.CreateRequest( 4608 scoped_ptr<URLRequest> r(
4602 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &request_delegate, 4609 context.CreateRequest(test_server_.GetURL("auth-basic"),
4603 NULL)); 4610 DEFAULT_PRIORITY, &request_delegate));
4604 LoadStateWithParam load_state = r->GetLoadState(); 4611 LoadStateWithParam load_state = r->GetLoadState();
4605 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); 4612 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state);
4606 EXPECT_EQ(base::string16(), load_state.param); 4613 EXPECT_EQ(base::string16(), load_state.param);
4607 4614
4608 r->Start(); 4615 r->Start();
4609 base::RunLoop().Run(); 4616 base::RunLoop().Run();
4610 4617
4611 EXPECT_EQ(200, r->GetResponseCode()); 4618 EXPECT_EQ(200, r->GetResponseCode());
4612 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4619 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4613 EXPECT_EQ(1, network_delegate.created_requests()); 4620 EXPECT_EQ(1, network_delegate.created_requests());
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4657 context.Init(); 4664 context.Init();
4658 4665
4659 { 4666 {
4660 // A chunked response with delays between chunks is used to make sure that 4667 // A chunked response with delays between chunks is used to make sure that
4661 // attempts by the URLRequest delegate to log information while reading the 4668 // attempts by the URLRequest delegate to log information while reading the
4662 // body are ignored. Since they are ignored, this test is robust against 4669 // body are ignored. Since they are ignored, this test is robust against
4663 // the possibility of multiple reads being combined in the unlikely event 4670 // the possibility of multiple reads being combined in the unlikely event
4664 // that it occurs. 4671 // that it occurs.
4665 scoped_ptr<URLRequest> r(context.CreateRequest( 4672 scoped_ptr<URLRequest> r(context.CreateRequest(
4666 test_server_.GetURL("chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY, 4673 test_server_.GetURL("chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY,
4667 &request_delegate, NULL)); 4674 &request_delegate));
4668 LoadStateWithParam load_state = r->GetLoadState(); 4675 LoadStateWithParam load_state = r->GetLoadState();
4669 r->Start(); 4676 r->Start();
4670 base::RunLoop().Run(); 4677 base::RunLoop().Run();
4671 4678
4672 EXPECT_EQ(200, r->GetResponseCode()); 4679 EXPECT_EQ(200, r->GetResponseCode());
4673 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4680 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4674 } 4681 }
4675 4682
4676 CapturingNetLog::CapturedEntryList entries; 4683 CapturingNetLog::CapturedEntryList entries;
4677 net_log_.GetEntries(&entries); 4684 net_log_.GetEntries(&entries);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
4710 AsyncLoggingUrlRequestDelegate request_delegate( 4717 AsyncLoggingUrlRequestDelegate request_delegate(
4711 AsyncLoggingUrlRequestDelegate::NO_CANCEL); 4718 AsyncLoggingUrlRequestDelegate::NO_CANCEL);
4712 TestURLRequestContext context(true); 4719 TestURLRequestContext context(true);
4713 context.set_network_delegate(NULL); 4720 context.set_network_delegate(NULL);
4714 context.set_net_log(&net_log_); 4721 context.set_net_log(&net_log_);
4715 context.Init(); 4722 context.Init();
4716 4723
4717 { 4724 {
4718 scoped_ptr<URLRequest> r(context.CreateRequest( 4725 scoped_ptr<URLRequest> r(context.CreateRequest(
4719 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, 4726 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY,
4720 &request_delegate, NULL)); 4727 &request_delegate));
4721 LoadStateWithParam load_state = r->GetLoadState(); 4728 LoadStateWithParam load_state = r->GetLoadState();
4722 r->Start(); 4729 r->Start();
4723 base::RunLoop().Run(); 4730 base::RunLoop().Run();
4724 4731
4725 EXPECT_EQ(200, r->GetResponseCode()); 4732 EXPECT_EQ(200, r->GetResponseCode());
4726 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 4733 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
4727 } 4734 }
4728 4735
4729 CapturingNetLog::CapturedEntryList entries; 4736 CapturingNetLog::CapturedEntryList entries;
4730 net_log_.GetEntries(&entries); 4737 net_log_.GetEntries(&entries);
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
4774 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); 4781 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]);
4775 TestURLRequestContext context(true); 4782 TestURLRequestContext context(true);
4776 CapturingNetLog net_log; 4783 CapturingNetLog net_log;
4777 context.set_network_delegate(NULL); 4784 context.set_network_delegate(NULL);
4778 context.set_net_log(&net_log); 4785 context.set_net_log(&net_log);
4779 context.Init(); 4786 context.Init();
4780 4787
4781 { 4788 {
4782 scoped_ptr<URLRequest> r(context.CreateRequest( 4789 scoped_ptr<URLRequest> r(context.CreateRequest(
4783 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY, 4790 test_server_.GetURL("server-redirect?simple.html"), DEFAULT_PRIORITY,
4784 &request_delegate, NULL)); 4791 &request_delegate));
4785 LoadStateWithParam load_state = r->GetLoadState(); 4792 LoadStateWithParam load_state = r->GetLoadState();
4786 r->Start(); 4793 r->Start();
4787 base::RunLoop().Run(); 4794 base::RunLoop().Run();
4788 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 4795 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
4789 } 4796 }
4790 4797
4791 CapturingNetLog::CapturedEntryList entries; 4798 CapturingNetLog::CapturedEntryList entries;
4792 net_log.GetEntries(&entries); 4799 net_log.GetEntries(&entries);
4793 4800
4794 // Delegate info is always logged in both OnReceivedRedirect and 4801 // Delegate info is always logged in both OnReceivedRedirect and
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
4840 } // namespace 4847 } // namespace
4841 4848
4842 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { 4849 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) {
4843 ASSERT_TRUE(test_server_.Start()); 4850 ASSERT_TRUE(test_server_.Start());
4844 4851
4845 GURL destination_url = test_server_.GetURL( 4852 GURL destination_url = test_server_.GetURL(
4846 "echoheader?" + std::string(kExtraHeader)); 4853 "echoheader?" + std::string(kExtraHeader));
4847 GURL original_url = test_server_.GetURL( 4854 GURL original_url = test_server_.GetURL(
4848 "server-redirect?" + destination_url.spec()); 4855 "server-redirect?" + destination_url.spec());
4849 RedirectWithAdditionalHeadersDelegate d; 4856 RedirectWithAdditionalHeadersDelegate d;
4850 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 4857 scoped_ptr<URLRequest> req(
4851 original_url, DEFAULT_PRIORITY, &d, NULL)); 4858 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
4852 req->Start(); 4859 req->Start();
4853 base::RunLoop().Run(); 4860 base::RunLoop().Run();
4854 4861
4855 std::string value; 4862 std::string value;
4856 const HttpRequestHeaders& headers = req->extra_request_headers(); 4863 const HttpRequestHeaders& headers = req->extra_request_headers();
4857 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); 4864 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value));
4858 EXPECT_EQ(kExtraValue, value); 4865 EXPECT_EQ(kExtraValue, value);
4859 EXPECT_FALSE(req->is_pending()); 4866 EXPECT_FALSE(req->is_pending());
4860 EXPECT_FALSE(req->is_redirecting()); 4867 EXPECT_FALSE(req->is_redirecting());
4861 EXPECT_EQ(kExtraValue, d.data_received()); 4868 EXPECT_EQ(kExtraValue, d.data_received());
(...skipping 15 matching lines...) Expand all
4877 } // namespace 4884 } // namespace
4878 4885
4879 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { 4886 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) {
4880 ASSERT_TRUE(test_server_.Start()); 4887 ASSERT_TRUE(test_server_.Start());
4881 4888
4882 GURL destination_url = test_server_.GetURL( 4889 GURL destination_url = test_server_.GetURL(
4883 "echoheader?" + std::string(kExtraHeaderToRemove)); 4890 "echoheader?" + std::string(kExtraHeaderToRemove));
4884 GURL original_url = test_server_.GetURL( 4891 GURL original_url = test_server_.GetURL(
4885 "server-redirect?" + destination_url.spec()); 4892 "server-redirect?" + destination_url.spec());
4886 RedirectWithHeaderRemovalDelegate d; 4893 RedirectWithHeaderRemovalDelegate d;
4887 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 4894 scoped_ptr<URLRequest> req(
4888 original_url, DEFAULT_PRIORITY, &d, NULL)); 4895 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
4889 req->SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); 4896 req->SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false);
4890 req->Start(); 4897 req->Start();
4891 base::RunLoop().Run(); 4898 base::RunLoop().Run();
4892 4899
4893 std::string value; 4900 std::string value;
4894 const HttpRequestHeaders& headers = req->extra_request_headers(); 4901 const HttpRequestHeaders& headers = req->extra_request_headers();
4895 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); 4902 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value));
4896 EXPECT_FALSE(req->is_pending()); 4903 EXPECT_FALSE(req->is_pending());
4897 EXPECT_FALSE(req->is_redirecting()); 4904 EXPECT_FALSE(req->is_redirecting());
4898 EXPECT_EQ("None", d.data_received()); 4905 EXPECT_EQ("None", d.data_received());
4899 } 4906 }
4900 4907
4901 TEST_F(URLRequestTestHTTP, CancelTest) { 4908 TEST_F(URLRequestTestHTTP, CancelTest) {
4902 TestDelegate d; 4909 TestDelegate d;
4903 { 4910 {
4904 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 4911 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4905 GURL("http://www.google.com/"), DEFAULT_PRIORITY, &d, NULL)); 4912 GURL("http://www.google.com/"), DEFAULT_PRIORITY, &d));
4906 4913
4907 r->Start(); 4914 r->Start();
4908 EXPECT_TRUE(r->is_pending()); 4915 EXPECT_TRUE(r->is_pending());
4909 4916
4910 r->Cancel(); 4917 r->Cancel();
4911 4918
4912 base::RunLoop().Run(); 4919 base::RunLoop().Run();
4913 4920
4914 // We expect to receive OnResponseStarted even though the request has been 4921 // We expect to receive OnResponseStarted even though the request has been
4915 // cancelled. 4922 // cancelled.
4916 EXPECT_EQ(1, d.response_started_count()); 4923 EXPECT_EQ(1, d.response_started_count());
4917 EXPECT_EQ(0, d.bytes_received()); 4924 EXPECT_EQ(0, d.bytes_received());
4918 EXPECT_FALSE(d.received_data_before_response()); 4925 EXPECT_FALSE(d.received_data_before_response());
4919 } 4926 }
4920 } 4927 }
4921 4928
4922 TEST_F(URLRequestTestHTTP, CancelTest2) { 4929 TEST_F(URLRequestTestHTTP, CancelTest2) {
4923 ASSERT_TRUE(test_server_.Start()); 4930 ASSERT_TRUE(test_server_.Start());
4924 4931
4925 TestDelegate d; 4932 TestDelegate d;
4926 { 4933 {
4927 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 4934 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4928 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 4935 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
4929 4936
4930 d.set_cancel_in_response_started(true); 4937 d.set_cancel_in_response_started(true);
4931 4938
4932 r->Start(); 4939 r->Start();
4933 EXPECT_TRUE(r->is_pending()); 4940 EXPECT_TRUE(r->is_pending());
4934 4941
4935 base::RunLoop().Run(); 4942 base::RunLoop().Run();
4936 4943
4937 EXPECT_EQ(1, d.response_started_count()); 4944 EXPECT_EQ(1, d.response_started_count());
4938 EXPECT_EQ(0, d.bytes_received()); 4945 EXPECT_EQ(0, d.bytes_received());
4939 EXPECT_FALSE(d.received_data_before_response()); 4946 EXPECT_FALSE(d.received_data_before_response());
4940 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 4947 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
4941 } 4948 }
4942 } 4949 }
4943 4950
4944 TEST_F(URLRequestTestHTTP, CancelTest3) { 4951 TEST_F(URLRequestTestHTTP, CancelTest3) {
4945 ASSERT_TRUE(test_server_.Start()); 4952 ASSERT_TRUE(test_server_.Start());
4946 4953
4947 TestDelegate d; 4954 TestDelegate d;
4948 { 4955 {
4949 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 4956 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4950 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 4957 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
4951 4958
4952 d.set_cancel_in_received_data(true); 4959 d.set_cancel_in_received_data(true);
4953 4960
4954 r->Start(); 4961 r->Start();
4955 EXPECT_TRUE(r->is_pending()); 4962 EXPECT_TRUE(r->is_pending());
4956 4963
4957 base::RunLoop().Run(); 4964 base::RunLoop().Run();
4958 4965
4959 EXPECT_EQ(1, d.response_started_count()); 4966 EXPECT_EQ(1, d.response_started_count());
4960 // There is no guarantee about how much data was received 4967 // There is no guarantee about how much data was received
4961 // before the cancel was issued. It could have been 0 bytes, 4968 // before the cancel was issued. It could have been 0 bytes,
4962 // or it could have been all the bytes. 4969 // or it could have been all the bytes.
4963 // EXPECT_EQ(0, d.bytes_received()); 4970 // EXPECT_EQ(0, d.bytes_received());
4964 EXPECT_FALSE(d.received_data_before_response()); 4971 EXPECT_FALSE(d.received_data_before_response());
4965 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 4972 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
4966 } 4973 }
4967 } 4974 }
4968 4975
4969 TEST_F(URLRequestTestHTTP, CancelTest4) { 4976 TEST_F(URLRequestTestHTTP, CancelTest4) {
4970 ASSERT_TRUE(test_server_.Start()); 4977 ASSERT_TRUE(test_server_.Start());
4971 4978
4972 TestDelegate d; 4979 TestDelegate d;
4973 { 4980 {
4974 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 4981 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
4975 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 4982 test_server_.GetURL(std::string()), DEFAULT_PRIORITY, &d));
4976 4983
4977 r->Start(); 4984 r->Start();
4978 EXPECT_TRUE(r->is_pending()); 4985 EXPECT_TRUE(r->is_pending());
4979 4986
4980 // The request will be implicitly canceled when it is destroyed. The 4987 // The request will be implicitly canceled when it is destroyed. The
4981 // test delegate must not post a quit message when this happens because 4988 // test delegate must not post a quit message when this happens because
4982 // this test doesn't actually have a message loop. The quit message would 4989 // this test doesn't actually have a message loop. The quit message would
4983 // get put on this thread's message queue and the next test would exit 4990 // get put on this thread's message queue and the next test would exit
4984 // early, causing problems. 4991 // early, causing problems.
4985 d.set_quit_on_complete(false); 4992 d.set_quit_on_complete(false);
4986 } 4993 }
4987 // expect things to just cleanup properly. 4994 // expect things to just cleanup properly.
4988 4995
4989 // we won't actually get a received reponse here because we've never run the 4996 // we won't actually get a received reponse here because we've never run the
4990 // message loop 4997 // message loop
4991 EXPECT_FALSE(d.received_data_before_response()); 4998 EXPECT_FALSE(d.received_data_before_response());
4992 EXPECT_EQ(0, d.bytes_received()); 4999 EXPECT_EQ(0, d.bytes_received());
4993 } 5000 }
4994 5001
4995 TEST_F(URLRequestTestHTTP, CancelTest5) { 5002 TEST_F(URLRequestTestHTTP, CancelTest5) {
4996 ASSERT_TRUE(test_server_.Start()); 5003 ASSERT_TRUE(test_server_.Start());
4997 5004
4998 // populate cache 5005 // populate cache
4999 { 5006 {
5000 TestDelegate d; 5007 TestDelegate d;
5001 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5008 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5002 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d, NULL)); 5009 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d));
5003 r->Start(); 5010 r->Start();
5004 base::RunLoop().Run(); 5011 base::RunLoop().Run();
5005 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5012 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5006 } 5013 }
5007 5014
5008 // cancel read from cache (see bug 990242) 5015 // cancel read from cache (see bug 990242)
5009 { 5016 {
5010 TestDelegate d; 5017 TestDelegate d;
5011 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5018 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5012 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d, NULL)); 5019 test_server_.GetURL("cachetime"), DEFAULT_PRIORITY, &d));
5013 r->Start(); 5020 r->Start();
5014 r->Cancel(); 5021 r->Cancel();
5015 base::RunLoop().Run(); 5022 base::RunLoop().Run();
5016 5023
5017 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status()); 5024 EXPECT_EQ(URLRequestStatus::CANCELED, r->status().status());
5018 EXPECT_EQ(1, d.response_started_count()); 5025 EXPECT_EQ(1, d.response_started_count());
5019 EXPECT_EQ(0, d.bytes_received()); 5026 EXPECT_EQ(0, d.bytes_received());
5020 EXPECT_FALSE(d.received_data_before_response()); 5027 EXPECT_FALSE(d.received_data_before_response());
5021 } 5028 }
5022 } 5029 }
5023 5030
5024 TEST_F(URLRequestTestHTTP, PostTest) { 5031 TEST_F(URLRequestTestHTTP, PostTest) {
5025 ASSERT_TRUE(test_server_.Start()); 5032 ASSERT_TRUE(test_server_.Start());
5026 HTTPUploadDataOperationTest("POST"); 5033 HTTPUploadDataOperationTest("POST");
5027 } 5034 }
5028 5035
5029 TEST_F(URLRequestTestHTTP, PutTest) { 5036 TEST_F(URLRequestTestHTTP, PutTest) {
5030 ASSERT_TRUE(test_server_.Start()); 5037 ASSERT_TRUE(test_server_.Start());
5031 HTTPUploadDataOperationTest("PUT"); 5038 HTTPUploadDataOperationTest("PUT");
5032 } 5039 }
5033 5040
5034 TEST_F(URLRequestTestHTTP, PostEmptyTest) { 5041 TEST_F(URLRequestTestHTTP, PostEmptyTest) {
5035 ASSERT_TRUE(test_server_.Start()); 5042 ASSERT_TRUE(test_server_.Start());
5036 5043
5037 TestDelegate d; 5044 TestDelegate d;
5038 { 5045 {
5039 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5046 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5040 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); 5047 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d));
5041 r->set_method("POST"); 5048 r->set_method("POST");
5042 5049
5043 r->Start(); 5050 r->Start();
5044 EXPECT_TRUE(r->is_pending()); 5051 EXPECT_TRUE(r->is_pending());
5045 5052
5046 base::RunLoop().Run(); 5053 base::RunLoop().Run();
5047 5054
5048 ASSERT_EQ(1, d.response_started_count()) 5055 ASSERT_EQ(1, d.response_started_count())
5049 << "request failed: " << r->status().status() 5056 << "request failed: " << r->status().status()
5050 << ", error: " << r->status().error(); 5057 << ", error: " << r->status().error();
5051 5058
5052 EXPECT_FALSE(d.received_data_before_response()); 5059 EXPECT_FALSE(d.received_data_before_response());
5053 EXPECT_TRUE(d.data_received().empty()); 5060 EXPECT_TRUE(d.data_received().empty());
5054 } 5061 }
5055 } 5062 }
5056 5063
5057 TEST_F(URLRequestTestHTTP, PostFileTest) { 5064 TEST_F(URLRequestTestHTTP, PostFileTest) {
5058 ASSERT_TRUE(test_server_.Start()); 5065 ASSERT_TRUE(test_server_.Start());
5059 5066
5060 TestDelegate d; 5067 TestDelegate d;
5061 { 5068 {
5062 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5069 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5063 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); 5070 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d));
5064 r->set_method("POST"); 5071 r->set_method("POST");
5065 5072
5066 base::FilePath dir; 5073 base::FilePath dir;
5067 PathService::Get(base::DIR_EXE, &dir); 5074 PathService::Get(base::DIR_EXE, &dir);
5068 base::SetCurrentDirectory(dir); 5075 base::SetCurrentDirectory(dir);
5069 5076
5070 ScopedVector<UploadElementReader> element_readers; 5077 ScopedVector<UploadElementReader> element_readers;
5071 5078
5072 base::FilePath path; 5079 base::FilePath path;
5073 PathService::Get(base::DIR_SOURCE_ROOT, &path); 5080 PathService::Get(base::DIR_SOURCE_ROOT, &path);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
5107 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); 5114 EXPECT_EQ(std::string(&buf[0], size), d.data_received());
5108 } 5115 }
5109 } 5116 }
5110 5117
5111 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { 5118 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) {
5112 ASSERT_TRUE(test_server_.Start()); 5119 ASSERT_TRUE(test_server_.Start());
5113 5120
5114 TestDelegate d; 5121 TestDelegate d;
5115 { 5122 {
5116 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5123 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5117 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); 5124 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d));
5118 r->set_method("POST"); 5125 r->set_method("POST");
5119 5126
5120 ScopedVector<UploadElementReader> element_readers; 5127 ScopedVector<UploadElementReader> element_readers;
5121 5128
5122 element_readers.push_back(new UploadFileElementReader( 5129 element_readers.push_back(new UploadFileElementReader(
5123 base::MessageLoopProxy::current().get(), 5130 base::MessageLoopProxy::current().get(),
5124 base::FilePath(FILE_PATH_LITERAL( 5131 base::FilePath(FILE_PATH_LITERAL(
5125 "c:\\path\\to\\non\\existant\\file.randomness.12345")), 5132 "c:\\path\\to\\non\\existant\\file.randomness.12345")),
5126 0, 5133 0,
5127 kuint64max, 5134 kuint64max,
(...skipping 13 matching lines...) Expand all
5141 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error()); 5148 EXPECT_EQ(ERR_FILE_NOT_FOUND, r->status().error());
5142 } 5149 }
5143 } 5150 }
5144 5151
5145 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { 5152 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) {
5146 ASSERT_TRUE(test_server_.Start()); 5153 ASSERT_TRUE(test_server_.Start());
5147 5154
5148 TestDelegate d; 5155 TestDelegate d;
5149 { 5156 {
5150 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5157 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5151 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); 5158 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d));
5152 r->EnableChunkedUpload(); 5159 r->EnableChunkedUpload();
5153 r->set_method("POST"); 5160 r->set_method("POST");
5154 AddChunksToUpload(r.get()); 5161 AddChunksToUpload(r.get());
5155 r->Start(); 5162 r->Start();
5156 EXPECT_TRUE(r->is_pending()); 5163 EXPECT_TRUE(r->is_pending());
5157 5164
5158 base::RunLoop().Run(); 5165 base::RunLoop().Run();
5159 5166
5160 VerifyReceivedDataMatchesChunks(r.get(), &d); 5167 VerifyReceivedDataMatchesChunks(r.get(), &d);
5161 } 5168 }
5162 } 5169 }
5163 5170
5164 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { 5171 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) {
5165 ASSERT_TRUE(test_server_.Start()); 5172 ASSERT_TRUE(test_server_.Start());
5166 5173
5167 TestDelegate d; 5174 TestDelegate d;
5168 { 5175 {
5169 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5176 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5170 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); 5177 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d));
5171 r->EnableChunkedUpload(); 5178 r->EnableChunkedUpload();
5172 r->set_method("POST"); 5179 r->set_method("POST");
5173 r->Start(); 5180 r->Start();
5174 EXPECT_TRUE(r->is_pending()); 5181 EXPECT_TRUE(r->is_pending());
5175 AddChunksToUpload(r.get()); 5182 AddChunksToUpload(r.get());
5176 base::RunLoop().Run(); 5183 base::RunLoop().Run();
5177 5184
5178 VerifyReceivedDataMatchesChunks(r.get(), &d); 5185 VerifyReceivedDataMatchesChunks(r.get(), &d);
5179 } 5186 }
5180 } 5187 }
5181 5188
5182 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { 5189 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) {
5183 ASSERT_TRUE(test_server_.Start()); 5190 ASSERT_TRUE(test_server_.Start());
5184 5191
5185 TestDelegate d; 5192 TestDelegate d;
5186 { 5193 {
5187 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5194 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5188 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d, NULL)); 5195 test_server_.GetURL("echo"), DEFAULT_PRIORITY, &d));
5189 r->EnableChunkedUpload(); 5196 r->EnableChunkedUpload();
5190 r->set_method("POST"); 5197 r->set_method("POST");
5191 r->Start(); 5198 r->Start();
5192 EXPECT_TRUE(r->is_pending()); 5199 EXPECT_TRUE(r->is_pending());
5193 5200
5194 base::RunLoop().RunUntilIdle(); 5201 base::RunLoop().RunUntilIdle();
5195 AddChunksToUpload(r.get()); 5202 AddChunksToUpload(r.get());
5196 base::RunLoop().Run(); 5203 base::RunLoop().Run();
5197 5204
5198 VerifyReceivedDataMatchesChunks(r.get(), &d); 5205 VerifyReceivedDataMatchesChunks(r.get(), &d);
5199 } 5206 }
5200 } 5207 }
5201 5208
5202 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { 5209 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) {
5203 ASSERT_TRUE(test_server_.Start()); 5210 ASSERT_TRUE(test_server_.Start());
5204 5211
5205 TestDelegate d; 5212 TestDelegate d;
5206 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5213 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5207 test_server_.GetURL("files/with-headers.html"), DEFAULT_PRIORITY, &d, 5214 test_server_.GetURL("files/with-headers.html"), DEFAULT_PRIORITY, &d));
5208 NULL));
5209 req->Start(); 5215 req->Start();
5210 base::RunLoop().Run(); 5216 base::RunLoop().Run();
5211 5217
5212 const HttpResponseHeaders* headers = req->response_headers(); 5218 const HttpResponseHeaders* headers = req->response_headers();
5213 5219
5214 // Simple sanity check that response_info() accesses the same data. 5220 // Simple sanity check that response_info() accesses the same data.
5215 EXPECT_EQ(headers, req->response_info().headers.get()); 5221 EXPECT_EQ(headers, req->response_info().headers.get());
5216 5222
5217 std::string header; 5223 std::string header;
5218 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); 5224 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header));
(...skipping 13 matching lines...) Expand all
5232 TEST_F(URLRequestTestHTTP, ProcessSTS) { 5238 TEST_F(URLRequestTestHTTP, ProcessSTS) {
5233 SpawnedTestServer::SSLOptions ssl_options; 5239 SpawnedTestServer::SSLOptions ssl_options;
5234 SpawnedTestServer https_test_server( 5240 SpawnedTestServer https_test_server(
5235 SpawnedTestServer::TYPE_HTTPS, 5241 SpawnedTestServer::TYPE_HTTPS,
5236 ssl_options, 5242 ssl_options,
5237 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5243 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5238 ASSERT_TRUE(https_test_server.Start()); 5244 ASSERT_TRUE(https_test_server.Start());
5239 5245
5240 TestDelegate d; 5246 TestDelegate d;
5241 scoped_ptr<URLRequest> request(default_context_.CreateRequest( 5247 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5242 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, &d, 5248 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY,
5243 NULL)); 5249 &d));
5244 request->Start(); 5250 request->Start();
5245 base::RunLoop().Run(); 5251 base::RunLoop().Run();
5246 5252
5247 TransportSecurityState* security_state = 5253 TransportSecurityState* security_state =
5248 default_context_.transport_security_state(); 5254 default_context_.transport_security_state();
5249 TransportSecurityState::DomainState domain_state; 5255 TransportSecurityState::DomainState domain_state;
5250 EXPECT_TRUE(security_state->GetDynamicDomainState( 5256 EXPECT_TRUE(security_state->GetDynamicDomainState(
5251 SpawnedTestServer::kLocalhost, &domain_state)); 5257 SpawnedTestServer::kLocalhost, &domain_state));
5252 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 5258 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
5253 domain_state.sts.upgrade_mode); 5259 domain_state.sts.upgrade_mode);
(...skipping 20 matching lines...) Expand all
5274 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { 5280 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) {
5275 SpawnedTestServer::SSLOptions ssl_options; 5281 SpawnedTestServer::SSLOptions ssl_options;
5276 SpawnedTestServer https_test_server( 5282 SpawnedTestServer https_test_server(
5277 SpawnedTestServer::TYPE_HTTPS, 5283 SpawnedTestServer::TYPE_HTTPS,
5278 ssl_options, 5284 ssl_options,
5279 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5285 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5280 ASSERT_TRUE(https_test_server.Start()); 5286 ASSERT_TRUE(https_test_server.Start());
5281 5287
5282 TestDelegate d; 5288 TestDelegate d;
5283 scoped_ptr<URLRequest> request(default_context_.CreateRequest( 5289 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5284 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, &d, 5290 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY,
5285 NULL)); 5291 &d));
5286 request->Start(); 5292 request->Start();
5287 base::RunLoop().Run(); 5293 base::RunLoop().Run();
5288 5294
5289 TransportSecurityState* security_state = 5295 TransportSecurityState* security_state =
5290 default_context_.transport_security_state(); 5296 default_context_.transport_security_state();
5291 TransportSecurityState::DomainState domain_state; 5297 TransportSecurityState::DomainState domain_state;
5292 EXPECT_TRUE(security_state->GetDynamicDomainState( 5298 EXPECT_TRUE(security_state->GetDynamicDomainState(
5293 SpawnedTestServer::kLocalhost, &domain_state)); 5299 SpawnedTestServer::kLocalhost, &domain_state));
5294 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, 5300 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT,
5295 domain_state.sts.upgrade_mode); 5301 domain_state.sts.upgrade_mode);
5296 EXPECT_FALSE(domain_state.sts.include_subdomains); 5302 EXPECT_FALSE(domain_state.sts.include_subdomains);
5297 EXPECT_FALSE(domain_state.pkp.include_subdomains); 5303 EXPECT_FALSE(domain_state.pkp.include_subdomains);
5298 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 5304 EXPECT_TRUE(domain_state.HasPublicKeyPins());
5299 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); 5305 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry);
5300 } 5306 }
5301 5307
5302 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { 5308 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) {
5303 SpawnedTestServer::SSLOptions ssl_options; 5309 SpawnedTestServer::SSLOptions ssl_options;
5304 SpawnedTestServer https_test_server( 5310 SpawnedTestServer https_test_server(
5305 SpawnedTestServer::TYPE_HTTPS, 5311 SpawnedTestServer::TYPE_HTTPS,
5306 ssl_options, 5312 ssl_options,
5307 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5313 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5308 ASSERT_TRUE(https_test_server.Start()); 5314 ASSERT_TRUE(https_test_server.Start());
5309 5315
5310 TestDelegate d; 5316 TestDelegate d;
5311 scoped_ptr<URLRequest> request(default_context_.CreateRequest( 5317 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5312 https_test_server.GetURL("files/hsts-multiple-headers.html"), 5318 https_test_server.GetURL("files/hsts-multiple-headers.html"),
5313 DEFAULT_PRIORITY, &d, NULL)); 5319 DEFAULT_PRIORITY, &d));
5314 request->Start(); 5320 request->Start();
5315 base::RunLoop().Run(); 5321 base::RunLoop().Run();
5316 5322
5317 // We should have set parameters from the first header, not the second. 5323 // We should have set parameters from the first header, not the second.
5318 TransportSecurityState* security_state = 5324 TransportSecurityState* security_state =
5319 default_context_.transport_security_state(); 5325 default_context_.transport_security_state();
5320 TransportSecurityState::DomainState domain_state; 5326 TransportSecurityState::DomainState domain_state;
5321 EXPECT_TRUE(security_state->GetDynamicDomainState( 5327 EXPECT_TRUE(security_state->GetDynamicDomainState(
5322 SpawnedTestServer::kLocalhost, &domain_state)); 5328 SpawnedTestServer::kLocalhost, &domain_state));
5323 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 5329 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
5324 domain_state.sts.upgrade_mode); 5330 domain_state.sts.upgrade_mode);
5325 EXPECT_FALSE(domain_state.sts.include_subdomains); 5331 EXPECT_FALSE(domain_state.sts.include_subdomains);
5326 EXPECT_FALSE(domain_state.pkp.include_subdomains); 5332 EXPECT_FALSE(domain_state.pkp.include_subdomains);
5327 } 5333 }
5328 5334
5329 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { 5335 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) {
5330 SpawnedTestServer::SSLOptions ssl_options; 5336 SpawnedTestServer::SSLOptions ssl_options;
5331 SpawnedTestServer https_test_server( 5337 SpawnedTestServer https_test_server(
5332 SpawnedTestServer::TYPE_HTTPS, 5338 SpawnedTestServer::TYPE_HTTPS,
5333 ssl_options, 5339 ssl_options,
5334 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5340 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5335 ASSERT_TRUE(https_test_server.Start()); 5341 ASSERT_TRUE(https_test_server.Start());
5336 5342
5337 TestDelegate d; 5343 TestDelegate d;
5338 scoped_ptr<URLRequest> request(default_context_.CreateRequest( 5344 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5339 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), 5345 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"),
5340 DEFAULT_PRIORITY, &d, NULL)); 5346 DEFAULT_PRIORITY, &d));
5341 request->Start(); 5347 request->Start();
5342 base::RunLoop().Run(); 5348 base::RunLoop().Run();
5343 5349
5344 // We should have set parameters from the first header, not the second. 5350 // We should have set parameters from the first header, not the second.
5345 TransportSecurityState* security_state = 5351 TransportSecurityState* security_state =
5346 default_context_.transport_security_state(); 5352 default_context_.transport_security_state();
5347 TransportSecurityState::DomainState domain_state; 5353 TransportSecurityState::DomainState domain_state;
5348 EXPECT_TRUE(security_state->GetDynamicDomainState( 5354 EXPECT_TRUE(security_state->GetDynamicDomainState(
5349 SpawnedTestServer::kLocalhost, &domain_state)); 5355 SpawnedTestServer::kLocalhost, &domain_state));
5350 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 5356 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
(...skipping 18 matching lines...) Expand all
5369 SpawnedTestServer::SSLOptions ssl_options; 5375 SpawnedTestServer::SSLOptions ssl_options;
5370 SpawnedTestServer https_test_server( 5376 SpawnedTestServer https_test_server(
5371 SpawnedTestServer::TYPE_HTTPS, 5377 SpawnedTestServer::TYPE_HTTPS,
5372 ssl_options, 5378 ssl_options,
5373 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); 5379 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest")));
5374 ASSERT_TRUE(https_test_server.Start()); 5380 ASSERT_TRUE(https_test_server.Start());
5375 5381
5376 TestDelegate d; 5382 TestDelegate d;
5377 scoped_ptr<URLRequest> request(default_context_.CreateRequest( 5383 scoped_ptr<URLRequest> request(default_context_.CreateRequest(
5378 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), 5384 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"),
5379 DEFAULT_PRIORITY, &d, NULL)); 5385 DEFAULT_PRIORITY, &d));
5380 request->Start(); 5386 request->Start();
5381 base::RunLoop().Run(); 5387 base::RunLoop().Run();
5382 5388
5383 TransportSecurityState* security_state = 5389 TransportSecurityState* security_state =
5384 default_context_.transport_security_state(); 5390 default_context_.transport_security_state();
5385 TransportSecurityState::DomainState domain_state; 5391 TransportSecurityState::DomainState domain_state;
5386 EXPECT_TRUE(security_state->GetDynamicDomainState( 5392 EXPECT_TRUE(security_state->GetDynamicDomainState(
5387 SpawnedTestServer::kLocalhost, &domain_state)); 5393 SpawnedTestServer::kLocalhost, &domain_state));
5388 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, 5394 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS,
5389 domain_state.sts.upgrade_mode); 5395 domain_state.sts.upgrade_mode);
5390 #if defined(OS_ANDROID) 5396 #if defined(OS_ANDROID)
5391 // Android's CertVerifyProc does not (yet) handle pins. 5397 // Android's CertVerifyProc does not (yet) handle pins.
5392 #else 5398 #else
5393 EXPECT_TRUE(domain_state.HasPublicKeyPins()); 5399 EXPECT_TRUE(domain_state.HasPublicKeyPins());
5394 #endif 5400 #endif
5395 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); 5401 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry);
5396 5402
5397 EXPECT_TRUE(domain_state.sts.include_subdomains); 5403 EXPECT_TRUE(domain_state.sts.include_subdomains);
5398 EXPECT_FALSE(domain_state.pkp.include_subdomains); 5404 EXPECT_FALSE(domain_state.pkp.include_subdomains);
5399 } 5405 }
5400 5406
5401 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { 5407 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) {
5402 ASSERT_TRUE(test_server_.Start()); 5408 ASSERT_TRUE(test_server_.Start());
5403 5409
5404 TestDelegate d; 5410 TestDelegate d;
5405 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5411 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5406 test_server_.GetURL("files/content-type-normalization.html"), 5412 test_server_.GetURL("files/content-type-normalization.html"),
5407 DEFAULT_PRIORITY, &d, NULL)); 5413 DEFAULT_PRIORITY, &d));
5408 req->Start(); 5414 req->Start();
5409 base::RunLoop().Run(); 5415 base::RunLoop().Run();
5410 5416
5411 std::string mime_type; 5417 std::string mime_type;
5412 req->GetMimeType(&mime_type); 5418 req->GetMimeType(&mime_type);
5413 EXPECT_EQ("text/html", mime_type); 5419 EXPECT_EQ("text/html", mime_type);
5414 5420
5415 std::string charset; 5421 std::string charset;
5416 req->GetCharset(&charset); 5422 req->GetCharset(&charset);
5417 EXPECT_EQ("utf-8", charset); 5423 EXPECT_EQ("utf-8", charset);
(...skipping 19 matching lines...) Expand all
5437 5443
5438 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). 5444 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget().
5439 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url)); 5445 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url));
5440 } 5446 }
5441 5447
5442 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { 5448 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) {
5443 ASSERT_TRUE(test_server_.Start()); 5449 ASSERT_TRUE(test_server_.Start());
5444 5450
5445 TestDelegate d; 5451 TestDelegate d;
5446 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5452 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5447 test_server_.GetURL("files/redirect-to-file.html"), DEFAULT_PRIORITY, &d, 5453 test_server_.GetURL("files/redirect-to-file.html"), DEFAULT_PRIORITY,
5448 NULL)); 5454 &d));
5449 req->Start(); 5455 req->Start();
5450 base::RunLoop().Run(); 5456 base::RunLoop().Run();
5451 5457
5452 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 5458 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
5453 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error()); 5459 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error());
5454 } 5460 }
5455 #endif // !defined(DISABLE_FILE_SUPPORT) 5461 #endif // !defined(DISABLE_FILE_SUPPORT)
5456 5462
5457 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { 5463 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) {
5458 ASSERT_TRUE(test_server_.Start()); 5464 ASSERT_TRUE(test_server_.Start());
5459 5465
5460 TestDelegate d; 5466 TestDelegate d;
5461 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5467 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5462 test_server_.GetURL("files/redirect-to-data.html"), DEFAULT_PRIORITY, &d, 5468 test_server_.GetURL("files/redirect-to-data.html"), DEFAULT_PRIORITY,
5463 NULL)); 5469 &d));
5464 req->Start(); 5470 req->Start();
5465 base::MessageLoop::current()->Run(); 5471 base::MessageLoop::current()->Run();
5466 5472
5467 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 5473 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
5468 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error()); 5474 EXPECT_EQ(ERR_UNSAFE_REDIRECT, req->status().error());
5469 } 5475 }
5470 5476
5471 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { 5477 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) {
5472 ASSERT_TRUE(test_server_.Start()); 5478 ASSERT_TRUE(test_server_.Start());
5473 5479
5474 TestDelegate d; 5480 TestDelegate d;
5475 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5481 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5476 test_server_.GetURL("files/redirect-to-invalid-url.html"), 5482 test_server_.GetURL("files/redirect-to-invalid-url.html"),
5477 DEFAULT_PRIORITY, &d, NULL)); 5483 DEFAULT_PRIORITY, &d));
5478 req->Start(); 5484 req->Start();
5479 base::RunLoop().Run(); 5485 base::RunLoop().Run();
5480 5486
5481 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 5487 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
5482 EXPECT_EQ(ERR_INVALID_URL, req->status().error()); 5488 EXPECT_EQ(ERR_INVALID_URL, req->status().error());
5483 } 5489 }
5484 5490
5485 // Make sure redirects are cached, despite not reading their bodies. 5491 // Make sure redirects are cached, despite not reading their bodies.
5486 TEST_F(URLRequestTestHTTP, CacheRedirect) { 5492 TEST_F(URLRequestTestHTTP, CacheRedirect) {
5487 ASSERT_TRUE(test_server_.Start()); 5493 ASSERT_TRUE(test_server_.Start());
5488 GURL redirect_url = 5494 GURL redirect_url =
5489 test_server_.GetURL("files/redirect302-to-echo-cacheable"); 5495 test_server_.GetURL("files/redirect302-to-echo-cacheable");
5490 5496
5491 { 5497 {
5492 TestDelegate d; 5498 TestDelegate d;
5493 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5499 scoped_ptr<URLRequest> req(
5494 redirect_url, DEFAULT_PRIORITY, &d, NULL)); 5500 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d));
5495 req->Start(); 5501 req->Start();
5496 base::RunLoop().Run(); 5502 base::RunLoop().Run();
5497 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 5503 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5498 EXPECT_EQ(1, d.received_redirect_count()); 5504 EXPECT_EQ(1, d.received_redirect_count());
5499 EXPECT_EQ(test_server_.GetURL("echo"), req->url()); 5505 EXPECT_EQ(test_server_.GetURL("echo"), req->url());
5500 } 5506 }
5501 5507
5502 { 5508 {
5503 TestDelegate d; 5509 TestDelegate d;
5504 d.set_quit_on_redirect(true); 5510 d.set_quit_on_redirect(true);
5505 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5511 scoped_ptr<URLRequest> req(
5506 redirect_url, DEFAULT_PRIORITY, &d, NULL)); 5512 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d));
5507 req->Start(); 5513 req->Start();
5508 base::RunLoop().Run(); 5514 base::RunLoop().Run();
5509 5515
5510 EXPECT_EQ(1, d.received_redirect_count()); 5516 EXPECT_EQ(1, d.received_redirect_count());
5511 EXPECT_EQ(0, d.response_started_count()); 5517 EXPECT_EQ(0, d.response_started_count());
5512 EXPECT_TRUE(req->was_cached()); 5518 EXPECT_TRUE(req->was_cached());
5513 5519
5514 req->FollowDeferredRedirect(); 5520 req->FollowDeferredRedirect();
5515 base::RunLoop().Run(); 5521 base::RunLoop().Run();
5516 EXPECT_EQ(1, d.received_redirect_count()); 5522 EXPECT_EQ(1, d.received_redirect_count());
(...skipping 10 matching lines...) Expand all
5527 // URL that is normally cached. 5533 // URL that is normally cached.
5528 GURL initial_url = test_server_.GetURL("cachetime"); 5534 GURL initial_url = test_server_.GetURL("cachetime");
5529 5535
5530 { 5536 {
5531 // Set up the TestNetworkDelegate tp force a redirect. 5537 // Set up the TestNetworkDelegate tp force a redirect.
5532 GURL redirect_to_url = test_server_.GetURL("echo"); 5538 GURL redirect_to_url = test_server_.GetURL("echo");
5533 default_network_delegate_.set_redirect_on_headers_received_url( 5539 default_network_delegate_.set_redirect_on_headers_received_url(
5534 redirect_to_url); 5540 redirect_to_url);
5535 5541
5536 TestDelegate d; 5542 TestDelegate d;
5537 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5543 scoped_ptr<URLRequest> req(
5538 initial_url, DEFAULT_PRIORITY, &d, NULL)); 5544 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d));
5539 req->Start(); 5545 req->Start();
5540 base::RunLoop().Run(); 5546 base::RunLoop().Run();
5541 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 5547 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5542 EXPECT_EQ(1, d.received_redirect_count()); 5548 EXPECT_EQ(1, d.received_redirect_count());
5543 EXPECT_EQ(redirect_to_url, req->url()); 5549 EXPECT_EQ(redirect_to_url, req->url());
5544 } 5550 }
5545 5551
5546 { 5552 {
5547 TestDelegate d; 5553 TestDelegate d;
5548 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5554 scoped_ptr<URLRequest> req(
5549 initial_url, DEFAULT_PRIORITY, &d, NULL)); 5555 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d));
5550 req->Start(); 5556 req->Start();
5551 base::RunLoop().Run(); 5557 base::RunLoop().Run();
5552 5558
5553 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 5559 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5554 EXPECT_FALSE(req->was_cached()); 5560 EXPECT_FALSE(req->was_cached());
5555 EXPECT_EQ(0, d.received_redirect_count()); 5561 EXPECT_EQ(0, d.received_redirect_count());
5556 EXPECT_EQ(initial_url, req->url()); 5562 EXPECT_EQ(initial_url, req->url());
5557 } 5563 }
5558 } 5564 }
5559 5565
5560 // Tests that redirection to an unsafe URL is allowed when it has been marked as 5566 // Tests that redirection to an unsafe URL is allowed when it has been marked as
5561 // safe. 5567 // safe.
5562 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { 5568 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) {
5563 ASSERT_TRUE(test_server_.Start()); 5569 ASSERT_TRUE(test_server_.Start());
5564 5570
5565 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); 5571 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url");
5566 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 5572 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
5567 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 5573 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
5568 5574
5569 TestDelegate d; 5575 TestDelegate d;
5570 { 5576 {
5571 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5577 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5572 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d, NULL)); 5578 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d));
5573 5579
5574 r->Start(); 5580 r->Start();
5575 base::RunLoop().Run(); 5581 base::RunLoop().Run();
5576 5582
5577 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5583 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5578 5584
5579 EXPECT_EQ(2U, r->url_chain().size()); 5585 EXPECT_EQ(2U, r->url_chain().size());
5580 EXPECT_EQ(OK, r->status().error()); 5586 EXPECT_EQ(OK, r->status().error());
5581 EXPECT_EQ(unsafe_url, r->url()); 5587 EXPECT_EQ(unsafe_url, r->url());
5582 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); 5588 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received());
5583 } 5589 }
5584 } 5590 }
5585 5591
5586 // Tests that a redirect to a different unsafe URL is blocked, even after adding 5592 // Tests that a redirect to a different unsafe URL is blocked, even after adding
5587 // some other URL to the whitelist. 5593 // some other URL to the whitelist.
5588 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { 5594 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) {
5589 ASSERT_TRUE(test_server_.Start()); 5595 ASSERT_TRUE(test_server_.Start());
5590 5596
5591 GURL unsafe_url("data:text/html,something"); 5597 GURL unsafe_url("data:text/html,something");
5592 GURL different_unsafe_url("data:text/html,something-else"); 5598 GURL different_unsafe_url("data:text/html,something-else");
5593 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 5599 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
5594 default_network_delegate_.set_allowed_unsafe_redirect_url( 5600 default_network_delegate_.set_allowed_unsafe_redirect_url(
5595 different_unsafe_url); 5601 different_unsafe_url);
5596 5602
5597 TestDelegate d; 5603 TestDelegate d;
5598 { 5604 {
5599 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5605 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
5600 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d, NULL)); 5606 test_server_.GetURL("whatever"), DEFAULT_PRIORITY, &d));
5601 5607
5602 r->Start(); 5608 r->Start();
5603 base::RunLoop().Run(); 5609 base::RunLoop().Run();
5604 5610
5605 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 5611 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
5606 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r->status().error()); 5612 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r->status().error());
5607 } 5613 }
5608 } 5614 }
5609 5615
5610 // Redirects from an URL with fragment to an unsafe URL with fragment should 5616 // Redirects from an URL with fragment to an unsafe URL with fragment should
5611 // be allowed, and the reference fragment of the target URL should be preserved. 5617 // be allowed, and the reference fragment of the target URL should be preserved.
5612 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { 5618 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) {
5613 ASSERT_TRUE(test_server_.Start()); 5619 ASSERT_TRUE(test_server_.Start());
5614 5620
5615 GURL original_url(test_server_.GetURL("original#fragment1")); 5621 GURL original_url(test_server_.GetURL("original#fragment1"));
5616 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); 5622 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2");
5617 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); 5623 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2");
5618 5624
5619 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); 5625 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url);
5620 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 5626 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
5621 5627
5622 TestDelegate d; 5628 TestDelegate d;
5623 { 5629 {
5624 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5630 scoped_ptr<URLRequest> r(
5625 original_url, DEFAULT_PRIORITY, &d, NULL)); 5631 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
5626 5632
5627 r->Start(); 5633 r->Start();
5628 base::RunLoop().Run(); 5634 base::RunLoop().Run();
5629 5635
5630 EXPECT_EQ(2U, r->url_chain().size()); 5636 EXPECT_EQ(2U, r->url_chain().size());
5631 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5637 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5632 EXPECT_EQ(OK, r->status().error()); 5638 EXPECT_EQ(OK, r->status().error());
5633 EXPECT_EQ(original_url, r->original_url()); 5639 EXPECT_EQ(original_url, r->original_url());
5634 EXPECT_EQ(expected_url, r->url()); 5640 EXPECT_EQ(expected_url, r->url());
5635 } 5641 }
5636 } 5642 }
5637 5643
5638 // When a delegate has specified a safe redirect URL, but it does not match the 5644 // When a delegate has specified a safe redirect URL, but it does not match the
5639 // redirect target, then do not prevent the reference fragment from being added. 5645 // redirect target, then do not prevent the reference fragment from being added.
5640 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { 5646 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) {
5641 ASSERT_TRUE(test_server_.Start()); 5647 ASSERT_TRUE(test_server_.Start());
5642 5648
5643 GURL original_url(test_server_.GetURL("original#expected-fragment")); 5649 GURL original_url(test_server_.GetURL("original#expected-fragment"));
5644 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); 5650 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url");
5645 GURL redirect_url(test_server_.GetURL("target")); 5651 GURL redirect_url(test_server_.GetURL("target"));
5646 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment")); 5652 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment"));
5647 5653
5648 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); 5654 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url);
5649 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); 5655 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url);
5650 5656
5651 TestDelegate d; 5657 TestDelegate d;
5652 { 5658 {
5653 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5659 scoped_ptr<URLRequest> r(
5654 original_url, DEFAULT_PRIORITY, &d, NULL)); 5660 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
5655 5661
5656 r->Start(); 5662 r->Start();
5657 base::RunLoop().Run(); 5663 base::RunLoop().Run();
5658 5664
5659 EXPECT_EQ(2U, r->url_chain().size()); 5665 EXPECT_EQ(2U, r->url_chain().size());
5660 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5666 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5661 EXPECT_EQ(OK, r->status().error()); 5667 EXPECT_EQ(OK, r->status().error());
5662 EXPECT_EQ(original_url, r->original_url()); 5668 EXPECT_EQ(original_url, r->original_url());
5663 EXPECT_EQ(expected_redirect_url, r->url()); 5669 EXPECT_EQ(expected_redirect_url, r->url());
5664 } 5670 }
5665 } 5671 }
5666 5672
5667 // When a delegate has specified a safe redirect URL, assume that the redirect 5673 // When a delegate has specified a safe redirect URL, assume that the redirect
5668 // URL should not be changed. In particular, the reference fragment should not 5674 // URL should not be changed. In particular, the reference fragment should not
5669 // be modified. 5675 // be modified.
5670 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { 5676 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) {
5671 ASSERT_TRUE(test_server_.Start()); 5677 ASSERT_TRUE(test_server_.Start());
5672 5678
5673 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); 5679 GURL original_url(test_server_.GetURL("original#should-not-be-appended"));
5674 GURL redirect_url("data:text/html,expect-no-reference-fragment"); 5680 GURL redirect_url("data:text/html,expect-no-reference-fragment");
5675 5681
5676 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); 5682 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url);
5677 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); 5683 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url);
5678 5684
5679 TestDelegate d; 5685 TestDelegate d;
5680 { 5686 {
5681 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5687 scoped_ptr<URLRequest> r(
5682 original_url, DEFAULT_PRIORITY, &d, NULL)); 5688 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
5683 5689
5684 r->Start(); 5690 r->Start();
5685 base::RunLoop().Run(); 5691 base::RunLoop().Run();
5686 5692
5687 EXPECT_EQ(2U, r->url_chain().size()); 5693 EXPECT_EQ(2U, r->url_chain().size());
5688 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5694 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5689 EXPECT_EQ(OK, r->status().error()); 5695 EXPECT_EQ(OK, r->status().error());
5690 EXPECT_EQ(original_url, r->original_url()); 5696 EXPECT_EQ(original_url, r->original_url());
5691 EXPECT_EQ(redirect_url, r->url()); 5697 EXPECT_EQ(redirect_url, r->url());
5692 } 5698 }
5693 } 5699 }
5694 5700
5695 // When a URLRequestRedirectJob is created, the redirection must be followed and 5701 // When a URLRequestRedirectJob is created, the redirection must be followed and
5696 // the reference fragment of the target URL must not be modified. 5702 // the reference fragment of the target URL must not be modified.
5697 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { 5703 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) {
5698 ASSERT_TRUE(test_server_.Start()); 5704 ASSERT_TRUE(test_server_.Start());
5699 5705
5700 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); 5706 GURL original_url(test_server_.GetURL("original#should-not-be-appended"));
5701 GURL redirect_url(test_server_.GetURL("echo")); 5707 GURL redirect_url(test_server_.GetURL("echo"));
5702 5708
5703 TestDelegate d; 5709 TestDelegate d;
5704 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 5710 scoped_ptr<URLRequest> r(
5705 original_url, DEFAULT_PRIORITY, &d, NULL)); 5711 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
5706 5712
5707 URLRequestRedirectJob* job = new URLRequestRedirectJob( 5713 URLRequestRedirectJob* job = new URLRequestRedirectJob(
5708 r.get(), &default_network_delegate_, redirect_url, 5714 r.get(), &default_network_delegate_, redirect_url,
5709 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); 5715 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason");
5710 AddTestInterceptor()->set_main_intercept_job(job); 5716 AddTestInterceptor()->set_main_intercept_job(job);
5711 5717
5712 r->Start(); 5718 r->Start();
5713 base::RunLoop().Run(); 5719 base::RunLoop().Run();
5714 5720
5715 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 5721 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
5716 EXPECT_EQ(OK, r->status().error()); 5722 EXPECT_EQ(OK, r->status().error());
5717 EXPECT_EQ(original_url, r->original_url()); 5723 EXPECT_EQ(original_url, r->original_url());
5718 EXPECT_EQ(redirect_url, r->url()); 5724 EXPECT_EQ(redirect_url, r->url());
5719 } 5725 }
5720 5726
5721 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { 5727 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) {
5722 ASSERT_TRUE(test_server_.Start()); 5728 ASSERT_TRUE(test_server_.Start());
5723 5729
5724 TestDelegate d; 5730 TestDelegate d;
5725 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5731 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5726 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); 5732 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d));
5727 req->SetReferrer("http://user:pass@foo.com/"); 5733 req->SetReferrer("http://user:pass@foo.com/");
5728 req->Start(); 5734 req->Start();
5729 base::RunLoop().Run(); 5735 base::RunLoop().Run();
5730 5736
5731 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); 5737 EXPECT_EQ(std::string("http://foo.com/"), d.data_received());
5732 } 5738 }
5733 5739
5734 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { 5740 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) {
5735 ASSERT_TRUE(test_server_.Start()); 5741 ASSERT_TRUE(test_server_.Start());
5736 5742
5737 TestDelegate d; 5743 TestDelegate d;
5738 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5744 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5739 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); 5745 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d));
5740 req->SetReferrer("http://foo.com/test#fragment"); 5746 req->SetReferrer("http://foo.com/test#fragment");
5741 req->Start(); 5747 req->Start();
5742 base::RunLoop().Run(); 5748 base::RunLoop().Run();
5743 5749
5744 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); 5750 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received());
5745 } 5751 }
5746 5752
5747 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { 5753 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) {
5748 ASSERT_TRUE(test_server_.Start()); 5754 ASSERT_TRUE(test_server_.Start());
5749 5755
5750 TestDelegate d; 5756 TestDelegate d;
5751 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5757 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5752 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d, NULL)); 5758 test_server_.GetURL("echoheader?Referer"), DEFAULT_PRIORITY, &d));
5753 req->SetReferrer("http://foo.com/test#fragment"); 5759 req->SetReferrer("http://foo.com/test#fragment");
5754 req->SetReferrer(""); 5760 req->SetReferrer("");
5755 req->Start(); 5761 req->Start();
5756 base::RunLoop().Run(); 5762 base::RunLoop().Run();
5757 5763
5758 EXPECT_EQ(std::string("None"), d.data_received()); 5764 EXPECT_EQ(std::string("None"), d.data_received());
5759 } 5765 }
5760 5766
5761 // Defer network start and then resume, checking that the request was a success 5767 // Defer network start and then resume, checking that the request was a success
5762 // and bytes were received. 5768 // and bytes were received.
5763 TEST_F(URLRequestTestHTTP, DeferredBeforeNetworkStart) { 5769 TEST_F(URLRequestTestHTTP, DeferredBeforeNetworkStart) {
5764 ASSERT_TRUE(test_server_.Start()); 5770 ASSERT_TRUE(test_server_.Start());
5765 5771
5766 TestDelegate d; 5772 TestDelegate d;
5767 { 5773 {
5768 d.set_quit_on_network_start(true); 5774 d.set_quit_on_network_start(true);
5769 GURL test_url(test_server_.GetURL("echo")); 5775 GURL test_url(test_server_.GetURL("echo"));
5770 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5776 scoped_ptr<URLRequest> req(
5771 test_url, DEFAULT_PRIORITY, &d, NULL)); 5777 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d));
5772 5778
5773 req->Start(); 5779 req->Start();
5774 base::RunLoop().Run(); 5780 base::RunLoop().Run();
5775 5781
5776 EXPECT_EQ(1, d.received_before_network_start_count()); 5782 EXPECT_EQ(1, d.received_before_network_start_count());
5777 EXPECT_EQ(0, d.response_started_count()); 5783 EXPECT_EQ(0, d.response_started_count());
5778 5784
5779 req->ResumeNetworkStart(); 5785 req->ResumeNetworkStart();
5780 base::RunLoop().Run(); 5786 base::RunLoop().Run();
5781 5787
5782 EXPECT_EQ(1, d.response_started_count()); 5788 EXPECT_EQ(1, d.response_started_count());
5783 EXPECT_NE(0, d.bytes_received()); 5789 EXPECT_NE(0, d.bytes_received());
5784 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); 5790 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status());
5785 } 5791 }
5786 } 5792 }
5787 5793
5788 // Check that OnBeforeNetworkStart is only called once even if there is a 5794 // Check that OnBeforeNetworkStart is only called once even if there is a
5789 // redirect. 5795 // redirect.
5790 TEST_F(URLRequestTestHTTP, BeforeNetworkStartCalledOnce) { 5796 TEST_F(URLRequestTestHTTP, BeforeNetworkStartCalledOnce) {
5791 ASSERT_TRUE(test_server_.Start()); 5797 ASSERT_TRUE(test_server_.Start());
5792 5798
5793 TestDelegate d; 5799 TestDelegate d;
5794 { 5800 {
5795 d.set_quit_on_redirect(true); 5801 d.set_quit_on_redirect(true);
5796 d.set_quit_on_network_start(true); 5802 d.set_quit_on_network_start(true);
5797 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5803 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5798 test_server_.GetURL("server-redirect?echo"), DEFAULT_PRIORITY, &d, 5804 test_server_.GetURL("server-redirect?echo"), DEFAULT_PRIORITY, &d));
5799 NULL));
5800 5805
5801 req->Start(); 5806 req->Start();
5802 base::RunLoop().Run(); 5807 base::RunLoop().Run();
5803 5808
5804 EXPECT_EQ(1, d.received_before_network_start_count()); 5809 EXPECT_EQ(1, d.received_before_network_start_count());
5805 EXPECT_EQ(0, d.response_started_count()); 5810 EXPECT_EQ(0, d.response_started_count());
5806 EXPECT_EQ(0, d.received_redirect_count()); 5811 EXPECT_EQ(0, d.received_redirect_count());
5807 5812
5808 req->ResumeNetworkStart(); 5813 req->ResumeNetworkStart();
5809 base::RunLoop().Run(); 5814 base::RunLoop().Run();
(...skipping 13 matching lines...) Expand all
5823 } 5828 }
5824 5829
5825 // Cancel the request after learning that the request would use the network. 5830 // Cancel the request after learning that the request would use the network.
5826 TEST_F(URLRequestTestHTTP, CancelOnBeforeNetworkStart) { 5831 TEST_F(URLRequestTestHTTP, CancelOnBeforeNetworkStart) {
5827 ASSERT_TRUE(test_server_.Start()); 5832 ASSERT_TRUE(test_server_.Start());
5828 5833
5829 TestDelegate d; 5834 TestDelegate d;
5830 { 5835 {
5831 d.set_quit_on_network_start(true); 5836 d.set_quit_on_network_start(true);
5832 GURL test_url(test_server_.GetURL("echo")); 5837 GURL test_url(test_server_.GetURL("echo"));
5833 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5838 scoped_ptr<URLRequest> req(
5834 test_url, DEFAULT_PRIORITY, &d, NULL)); 5839 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d));
5835 5840
5836 req->Start(); 5841 req->Start();
5837 base::RunLoop().Run(); 5842 base::RunLoop().Run();
5838 5843
5839 EXPECT_EQ(1, d.received_before_network_start_count()); 5844 EXPECT_EQ(1, d.received_before_network_start_count());
5840 EXPECT_EQ(0, d.response_started_count()); 5845 EXPECT_EQ(0, d.response_started_count());
5841 5846
5842 req->Cancel(); 5847 req->Cancel();
5843 base::RunLoop().Run(); 5848 base::RunLoop().Run();
5844 5849
5845 EXPECT_EQ(1, d.response_started_count()); 5850 EXPECT_EQ(1, d.response_started_count());
5846 EXPECT_EQ(0, d.bytes_received()); 5851 EXPECT_EQ(0, d.bytes_received());
5847 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 5852 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
5848 } 5853 }
5849 } 5854 }
5850 5855
5851 TEST_F(URLRequestTestHTTP, CancelRedirect) { 5856 TEST_F(URLRequestTestHTTP, CancelRedirect) {
5852 ASSERT_TRUE(test_server_.Start()); 5857 ASSERT_TRUE(test_server_.Start());
5853 5858
5854 TestDelegate d; 5859 TestDelegate d;
5855 { 5860 {
5856 d.set_cancel_in_received_redirect(true); 5861 d.set_cancel_in_received_redirect(true);
5857 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5862 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5858 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d, 5863 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d));
5859 NULL));
5860 req->Start(); 5864 req->Start();
5861 base::RunLoop().Run(); 5865 base::RunLoop().Run();
5862 5866
5863 EXPECT_EQ(1, d.response_started_count()); 5867 EXPECT_EQ(1, d.response_started_count());
5864 EXPECT_EQ(0, d.bytes_received()); 5868 EXPECT_EQ(0, d.bytes_received());
5865 EXPECT_FALSE(d.received_data_before_response()); 5869 EXPECT_FALSE(d.received_data_before_response());
5866 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 5870 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
5867 } 5871 }
5868 } 5872 }
5869 5873
5870 TEST_F(URLRequestTestHTTP, DeferredRedirect) { 5874 TEST_F(URLRequestTestHTTP, DeferredRedirect) {
5871 ASSERT_TRUE(test_server_.Start()); 5875 ASSERT_TRUE(test_server_.Start());
5872 5876
5873 TestDelegate d; 5877 TestDelegate d;
5874 { 5878 {
5875 d.set_quit_on_redirect(true); 5879 d.set_quit_on_redirect(true);
5876 GURL test_url(test_server_.GetURL("files/redirect-test.html")); 5880 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
5877 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5881 scoped_ptr<URLRequest> req(
5878 test_url, DEFAULT_PRIORITY, &d, NULL)); 5882 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d));
5879 5883
5880 req->Start(); 5884 req->Start();
5881 base::RunLoop().Run(); 5885 base::RunLoop().Run();
5882 5886
5883 EXPECT_EQ(1, d.received_redirect_count()); 5887 EXPECT_EQ(1, d.received_redirect_count());
5884 5888
5885 req->FollowDeferredRedirect(); 5889 req->FollowDeferredRedirect();
5886 base::RunLoop().Run(); 5890 base::RunLoop().Run();
5887 5891
5888 EXPECT_EQ(1, d.response_started_count()); 5892 EXPECT_EQ(1, d.response_started_count());
(...skipping 13 matching lines...) Expand all
5902 } 5906 }
5903 } 5907 }
5904 5908
5905 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { 5909 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) {
5906 ASSERT_TRUE(test_server_.Start()); 5910 ASSERT_TRUE(test_server_.Start());
5907 5911
5908 TestDelegate d; 5912 TestDelegate d;
5909 { 5913 {
5910 d.set_quit_on_redirect(true); 5914 d.set_quit_on_redirect(true);
5911 GURL test_url(test_server_.GetURL("files/redirect-test.html")); 5915 GURL test_url(test_server_.GetURL("files/redirect-test.html"));
5912 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5916 scoped_ptr<URLRequest> req(
5913 test_url, DEFAULT_PRIORITY, &d, NULL)); 5917 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d));
5914 5918
5915 EXPECT_FALSE(d.have_full_request_headers()); 5919 EXPECT_FALSE(d.have_full_request_headers());
5916 5920
5917 req->Start(); 5921 req->Start();
5918 base::RunLoop().Run(); 5922 base::RunLoop().Run();
5919 5923
5920 EXPECT_EQ(1, d.received_redirect_count()); 5924 EXPECT_EQ(1, d.received_redirect_count());
5921 EXPECT_TRUE(d.have_full_request_headers()); 5925 EXPECT_TRUE(d.have_full_request_headers());
5922 CheckFullRequestHeaders(d.full_request_headers(), test_url); 5926 CheckFullRequestHeaders(d.full_request_headers(), test_url);
5923 d.ClearFullRequestHeaders(); 5927 d.ClearFullRequestHeaders();
(...skipping 21 matching lines...) Expand all
5945 } 5949 }
5946 } 5950 }
5947 5951
5948 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { 5952 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) {
5949 ASSERT_TRUE(test_server_.Start()); 5953 ASSERT_TRUE(test_server_.Start());
5950 5954
5951 TestDelegate d; 5955 TestDelegate d;
5952 { 5956 {
5953 d.set_quit_on_redirect(true); 5957 d.set_quit_on_redirect(true);
5954 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5958 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5955 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d, 5959 test_server_.GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d));
5956 NULL));
5957 req->Start(); 5960 req->Start();
5958 base::RunLoop().Run(); 5961 base::RunLoop().Run();
5959 5962
5960 EXPECT_EQ(1, d.received_redirect_count()); 5963 EXPECT_EQ(1, d.received_redirect_count());
5961 5964
5962 req->Cancel(); 5965 req->Cancel();
5963 base::RunLoop().Run(); 5966 base::RunLoop().Run();
5964 5967
5965 EXPECT_EQ(1, d.response_started_count()); 5968 EXPECT_EQ(1, d.response_started_count());
5966 EXPECT_EQ(0, d.bytes_received()); 5969 EXPECT_EQ(0, d.bytes_received());
5967 EXPECT_FALSE(d.received_data_before_response()); 5970 EXPECT_FALSE(d.received_data_before_response());
5968 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status()); 5971 EXPECT_EQ(URLRequestStatus::CANCELED, req->status().status());
5969 } 5972 }
5970 } 5973 }
5971 5974
5972 TEST_F(URLRequestTestHTTP, VaryHeader) { 5975 TEST_F(URLRequestTestHTTP, VaryHeader) {
5973 ASSERT_TRUE(test_server_.Start()); 5976 ASSERT_TRUE(test_server_.Start());
5974 5977
5975 // Populate the cache. 5978 // Populate the cache.
5976 { 5979 {
5977 TestDelegate d; 5980 TestDelegate d;
5978 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5981 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5979 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d, 5982 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d));
5980 NULL));
5981 HttpRequestHeaders headers; 5983 HttpRequestHeaders headers;
5982 headers.SetHeader("foo", "1"); 5984 headers.SetHeader("foo", "1");
5983 req->SetExtraRequestHeaders(headers); 5985 req->SetExtraRequestHeaders(headers);
5984 req->Start(); 5986 req->Start();
5985 base::RunLoop().Run(); 5987 base::RunLoop().Run();
5986 5988
5987 LoadTimingInfo load_timing_info; 5989 LoadTimingInfo load_timing_info;
5988 req->GetLoadTimingInfo(&load_timing_info); 5990 req->GetLoadTimingInfo(&load_timing_info);
5989 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 5991 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
5990 } 5992 }
5991 5993
5992 // Expect a cache hit. 5994 // Expect a cache hit.
5993 { 5995 {
5994 TestDelegate d; 5996 TestDelegate d;
5995 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 5997 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
5996 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d, 5998 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d));
5997 NULL));
5998 HttpRequestHeaders headers; 5999 HttpRequestHeaders headers;
5999 headers.SetHeader("foo", "1"); 6000 headers.SetHeader("foo", "1");
6000 req->SetExtraRequestHeaders(headers); 6001 req->SetExtraRequestHeaders(headers);
6001 req->Start(); 6002 req->Start();
6002 base::RunLoop().Run(); 6003 base::RunLoop().Run();
6003 6004
6004 EXPECT_TRUE(req->was_cached()); 6005 EXPECT_TRUE(req->was_cached());
6005 6006
6006 LoadTimingInfo load_timing_info; 6007 LoadTimingInfo load_timing_info;
6007 req->GetLoadTimingInfo(&load_timing_info); 6008 req->GetLoadTimingInfo(&load_timing_info);
6008 TestLoadTimingCacheHitNoNetwork(load_timing_info); 6009 TestLoadTimingCacheHitNoNetwork(load_timing_info);
6009 } 6010 }
6010 6011
6011 // Expect a cache miss. 6012 // Expect a cache miss.
6012 { 6013 {
6013 TestDelegate d; 6014 TestDelegate d;
6014 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6015 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6015 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d, 6016 test_server_.GetURL("echoheadercache?foo"), DEFAULT_PRIORITY, &d));
6016 NULL));
6017 HttpRequestHeaders headers; 6017 HttpRequestHeaders headers;
6018 headers.SetHeader("foo", "2"); 6018 headers.SetHeader("foo", "2");
6019 req->SetExtraRequestHeaders(headers); 6019 req->SetExtraRequestHeaders(headers);
6020 req->Start(); 6020 req->Start();
6021 base::RunLoop().Run(); 6021 base::RunLoop().Run();
6022 6022
6023 EXPECT_FALSE(req->was_cached()); 6023 EXPECT_FALSE(req->was_cached());
6024 6024
6025 LoadTimingInfo load_timing_info; 6025 LoadTimingInfo load_timing_info;
6026 req->GetLoadTimingInfo(&load_timing_info); 6026 req->GetLoadTimingInfo(&load_timing_info);
6027 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 6027 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
6028 } 6028 }
6029 } 6029 }
6030 6030
6031 TEST_F(URLRequestTestHTTP, BasicAuth) { 6031 TEST_F(URLRequestTestHTTP, BasicAuth) {
6032 ASSERT_TRUE(test_server_.Start()); 6032 ASSERT_TRUE(test_server_.Start());
6033 6033
6034 // populate the cache 6034 // populate the cache
6035 { 6035 {
6036 TestDelegate d; 6036 TestDelegate d;
6037 d.set_credentials(AuthCredentials(kUser, kSecret)); 6037 d.set_credentials(AuthCredentials(kUser, kSecret));
6038 6038
6039 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 6039 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6040 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); 6040 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d));
6041 r->Start(); 6041 r->Start();
6042 6042
6043 base::RunLoop().Run(); 6043 base::RunLoop().Run();
6044 6044
6045 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 6045 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
6046 } 6046 }
6047 6047
6048 // repeat request with end-to-end validation. since auth-basic results in a 6048 // repeat request with end-to-end validation. since auth-basic results in a
6049 // cachable page, we expect this test to result in a 304. in which case, the 6049 // cachable page, we expect this test to result in a 304. in which case, the
6050 // response should be fetched from the cache. 6050 // response should be fetched from the cache.
6051 { 6051 {
6052 TestDelegate d; 6052 TestDelegate d;
6053 d.set_credentials(AuthCredentials(kUser, kSecret)); 6053 d.set_credentials(AuthCredentials(kUser, kSecret));
6054 6054
6055 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 6055 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6056 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); 6056 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d));
6057 r->SetLoadFlags(LOAD_VALIDATE_CACHE); 6057 r->SetLoadFlags(LOAD_VALIDATE_CACHE);
6058 r->Start(); 6058 r->Start();
6059 6059
6060 base::RunLoop().Run(); 6060 base::RunLoop().Run();
6061 6061
6062 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 6062 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
6063 6063
6064 // Should be the same cached document. 6064 // Should be the same cached document.
6065 EXPECT_TRUE(r->was_cached()); 6065 EXPECT_TRUE(r->was_cached());
6066 } 6066 }
(...skipping 11 matching lines...) Expand all
6078 // Verify that when the transaction is restarted, it includes the new cookie. 6078 // Verify that when the transaction is restarted, it includes the new cookie.
6079 { 6079 {
6080 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 6080 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
6081 TestURLRequestContext context(true); 6081 TestURLRequestContext context(true);
6082 context.set_network_delegate(&network_delegate); 6082 context.set_network_delegate(&network_delegate);
6083 context.Init(); 6083 context.Init();
6084 6084
6085 TestDelegate d; 6085 TestDelegate d;
6086 d.set_credentials(AuthCredentials(kUser, kSecret)); 6086 d.set_credentials(AuthCredentials(kUser, kSecret));
6087 6087
6088 scoped_ptr<URLRequest> r(context.CreateRequest( 6088 scoped_ptr<URLRequest> r(
6089 url_requiring_auth, DEFAULT_PRIORITY, &d, NULL)); 6089 context.CreateRequest(url_requiring_auth, DEFAULT_PRIORITY, &d));
6090 r->Start(); 6090 r->Start();
6091 6091
6092 base::RunLoop().Run(); 6092 base::RunLoop().Run();
6093 6093
6094 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 6094 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
6095 6095
6096 // Make sure we sent the cookie in the restarted transaction. 6096 // Make sure we sent the cookie in the restarted transaction.
6097 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") 6097 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
6098 != std::string::npos); 6098 != std::string::npos);
6099 } 6099 }
6100 6100
6101 // Same test as above, except this time the restart is initiated earlier 6101 // Same test as above, except this time the restart is initiated earlier
6102 // (without user intervention since identity is embedded in the URL). 6102 // (without user intervention since identity is embedded in the URL).
6103 { 6103 {
6104 TestNetworkDelegate network_delegate; // Must outlive URLRequest. 6104 TestNetworkDelegate network_delegate; // Must outlive URLRequest.
6105 TestURLRequestContext context(true); 6105 TestURLRequestContext context(true);
6106 context.set_network_delegate(&network_delegate); 6106 context.set_network_delegate(&network_delegate);
6107 context.Init(); 6107 context.Init();
6108 6108
6109 TestDelegate d; 6109 TestDelegate d;
6110 6110
6111 GURL::Replacements replacements; 6111 GURL::Replacements replacements;
6112 replacements.SetUsernameStr("user2"); 6112 replacements.SetUsernameStr("user2");
6113 replacements.SetPasswordStr("secret"); 6113 replacements.SetPasswordStr("secret");
6114 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); 6114 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements);
6115 6115
6116 scoped_ptr<URLRequest> r(context.CreateRequest( 6116 scoped_ptr<URLRequest> r(
6117 url_with_identity, DEFAULT_PRIORITY, &d, NULL)); 6117 context.CreateRequest(url_with_identity, DEFAULT_PRIORITY, &d));
6118 r->Start(); 6118 r->Start();
6119 6119
6120 base::RunLoop().Run(); 6120 base::RunLoop().Run();
6121 6121
6122 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); 6122 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos);
6123 6123
6124 // Make sure we sent the cookie in the restarted transaction. 6124 // Make sure we sent the cookie in the restarted transaction.
6125 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") 6125 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true")
6126 != std::string::npos); 6126 != std::string::npos);
6127 } 6127 }
6128 } 6128 }
6129 6129
6130 // Tests that load timing works as expected with auth and the cache. 6130 // Tests that load timing works as expected with auth and the cache.
6131 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { 6131 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) {
6132 ASSERT_TRUE(test_server_.Start()); 6132 ASSERT_TRUE(test_server_.Start());
6133 6133
6134 // populate the cache 6134 // populate the cache
6135 { 6135 {
6136 TestDelegate d; 6136 TestDelegate d;
6137 d.set_credentials(AuthCredentials(kUser, kSecret)); 6137 d.set_credentials(AuthCredentials(kUser, kSecret));
6138 6138
6139 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 6139 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6140 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); 6140 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d));
6141 r->Start(); 6141 r->Start();
6142 6142
6143 base::RunLoop().Run(); 6143 base::RunLoop().Run();
6144 6144
6145 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 6145 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
6146 6146
6147 LoadTimingInfo load_timing_info_before_auth; 6147 LoadTimingInfo load_timing_info_before_auth;
6148 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( 6148 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth(
6149 &load_timing_info_before_auth)); 6149 &load_timing_info_before_auth));
6150 TestLoadTimingNotReused(load_timing_info_before_auth, 6150 TestLoadTimingNotReused(load_timing_info_before_auth,
(...skipping 11 matching lines...) Expand all
6162 } 6162 }
6163 6163
6164 // Repeat request with end-to-end validation. Since auth-basic results in a 6164 // Repeat request with end-to-end validation. Since auth-basic results in a
6165 // cachable page, we expect this test to result in a 304. In which case, the 6165 // cachable page, we expect this test to result in a 304. In which case, the
6166 // response should be fetched from the cache. 6166 // response should be fetched from the cache.
6167 { 6167 {
6168 TestDelegate d; 6168 TestDelegate d;
6169 d.set_credentials(AuthCredentials(kUser, kSecret)); 6169 d.set_credentials(AuthCredentials(kUser, kSecret));
6170 6170
6171 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 6171 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
6172 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d, NULL)); 6172 test_server_.GetURL("auth-basic"), DEFAULT_PRIORITY, &d));
6173 r->SetLoadFlags(LOAD_VALIDATE_CACHE); 6173 r->SetLoadFlags(LOAD_VALIDATE_CACHE);
6174 r->Start(); 6174 r->Start();
6175 6175
6176 base::RunLoop().Run(); 6176 base::RunLoop().Run();
6177 6177
6178 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); 6178 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos);
6179 6179
6180 // Should be the same cached document. 6180 // Should be the same cached document.
6181 EXPECT_TRUE(r->was_cached()); 6181 EXPECT_TRUE(r->was_cached());
6182 6182
6183 // Since there was a request that went over the wire, the load timing 6183 // Since there was a request that went over the wire, the load timing
6184 // information should include connection times. 6184 // information should include connection times.
6185 LoadTimingInfo load_timing_info; 6185 LoadTimingInfo load_timing_info;
6186 r->GetLoadTimingInfo(&load_timing_info); 6186 r->GetLoadTimingInfo(&load_timing_info);
6187 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); 6187 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES);
6188 } 6188 }
6189 } 6189 }
6190 6190
6191 // In this test, we do a POST which the server will 302 redirect. 6191 // In this test, we do a POST which the server will 302 redirect.
6192 // The subsequent transaction should use GET, and should not send the 6192 // The subsequent transaction should use GET, and should not send the
6193 // Content-Type header. 6193 // Content-Type header.
6194 // http://code.google.com/p/chromium/issues/detail?id=843 6194 // http://code.google.com/p/chromium/issues/detail?id=843
6195 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { 6195 TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
6196 ASSERT_TRUE(test_server_.Start()); 6196 ASSERT_TRUE(test_server_.Start());
6197 6197
6198 const char kData[] = "hello world"; 6198 const char kData[] = "hello world";
6199 6199
6200 TestDelegate d; 6200 TestDelegate d;
6201 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6201 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6202 test_server_.GetURL("files/redirect-to-echoall"), DEFAULT_PRIORITY, &d, 6202 test_server_.GetURL("files/redirect-to-echoall"), DEFAULT_PRIORITY, &d));
6203 NULL));
6204 req->set_method("POST"); 6203 req->set_method("POST");
6205 req->set_upload(CreateSimpleUploadData(kData)); 6204 req->set_upload(CreateSimpleUploadData(kData));
6206 6205
6207 // Set headers (some of which are specific to the POST). 6206 // Set headers (some of which are specific to the POST).
6208 HttpRequestHeaders headers; 6207 HttpRequestHeaders headers;
6209 headers.AddHeadersFromString( 6208 headers.AddHeadersFromString(
6210 "Content-Type: multipart/form-data; " 6209 "Content-Type: multipart/form-data; "
6211 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" 6210 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n"
6212 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," 6211 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,"
6213 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" 6212 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n"
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
6292 6291
6293 // Make sure that 308 responses without bodies are not treated as redirects. 6292 // Make sure that 308 responses without bodies are not treated as redirects.
6294 // Certain legacy apis that pre-date the response code expect this behavior 6293 // Certain legacy apis that pre-date the response code expect this behavior
6295 // (Like Google Drive). 6294 // (Like Google Drive).
6296 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { 6295 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) {
6297 ASSERT_TRUE(test_server_.Start()); 6296 ASSERT_TRUE(test_server_.Start());
6298 6297
6299 TestDelegate d; 6298 TestDelegate d;
6300 const GURL url = test_server_.GetURL("files/308-without-location-header"); 6299 const GURL url = test_server_.GetURL("files/308-without-location-header");
6301 6300
6302 scoped_ptr<URLRequest> request(default_context_.CreateRequest( 6301 scoped_ptr<URLRequest> request(
6303 url, DEFAULT_PRIORITY, &d, NULL)); 6302 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
6304 6303
6305 request->Start(); 6304 request->Start();
6306 base::RunLoop().Run(); 6305 base::RunLoop().Run();
6307 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status()); 6306 EXPECT_EQ(URLRequestStatus::SUCCESS, request->status().status());
6308 EXPECT_EQ(OK, request->status().error()); 6307 EXPECT_EQ(OK, request->status().error());
6309 EXPECT_EQ(0, d.received_redirect_count()); 6308 EXPECT_EQ(0, d.received_redirect_count());
6310 EXPECT_EQ(308, request->response_headers()->response_code()); 6309 EXPECT_EQ(308, request->response_headers()->response_code());
6311 EXPECT_EQ("This is not a redirect.", d.data_received()); 6310 EXPECT_EQ("This is not a redirect.", d.data_received());
6312 } 6311 }
6313 6312
6314 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { 6313 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) {
6315 ASSERT_TRUE(test_server_.Start()); 6314 ASSERT_TRUE(test_server_.Start());
6316 6315
6317 GURL original_url(test_server_.GetURL("files/redirect302-to-echo#fragment")); 6316 GURL original_url(test_server_.GetURL("files/redirect302-to-echo#fragment"));
6318 GURL expected_url(test_server_.GetURL("echo#fragment")); 6317 GURL expected_url(test_server_.GetURL("echo#fragment"));
6319 6318
6320 TestDelegate d; 6319 TestDelegate d;
6321 { 6320 {
6322 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 6321 scoped_ptr<URLRequest> r(
6323 original_url, DEFAULT_PRIORITY, &d, NULL)); 6322 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d));
6324 6323
6325 r->Start(); 6324 r->Start();
6326 base::RunLoop().Run(); 6325 base::RunLoop().Run();
6327 6326
6328 EXPECT_EQ(2U, r->url_chain().size()); 6327 EXPECT_EQ(2U, r->url_chain().size());
6329 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 6328 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
6330 EXPECT_EQ(OK, r->status().error()); 6329 EXPECT_EQ(OK, r->status().error());
6331 EXPECT_EQ(original_url, r->original_url()); 6330 EXPECT_EQ(original_url, r->original_url());
6332 EXPECT_EQ(expected_url, r->url()); 6331 EXPECT_EQ(expected_url, r->url());
6333 } 6332 }
6334 } 6333 }
6335 6334
6336 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) { 6335 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) {
6337 ASSERT_TRUE(test_server_.Start()); 6336 ASSERT_TRUE(test_server_.Start());
6338 6337
6339 GURL url(test_server_.GetURL("files/redirect302-to-echo")); 6338 GURL url(test_server_.GetURL("files/redirect302-to-echo"));
6340 GURL first_party_url("http://example.com"); 6339 GURL first_party_url("http://example.com");
6341 6340
6342 TestDelegate d; 6341 TestDelegate d;
6343 { 6342 {
6344 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 6343 scoped_ptr<URLRequest> r(
6345 url, DEFAULT_PRIORITY, &d, NULL)); 6344 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
6346 r->set_first_party_for_cookies(first_party_url); 6345 r->set_first_party_for_cookies(first_party_url);
6347 6346
6348 r->Start(); 6347 r->Start();
6349 base::RunLoop().Run(); 6348 base::RunLoop().Run();
6350 6349
6351 EXPECT_EQ(2U, r->url_chain().size()); 6350 EXPECT_EQ(2U, r->url_chain().size());
6352 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 6351 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
6353 EXPECT_EQ(OK, r->status().error()); 6352 EXPECT_EQ(OK, r->status().error());
6354 EXPECT_EQ(first_party_url, r->first_party_for_cookies()); 6353 EXPECT_EQ(first_party_url, r->first_party_for_cookies());
6355 } 6354 }
6356 } 6355 }
6357 6356
6358 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) { 6357 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) {
6359 ASSERT_TRUE(test_server_.Start()); 6358 ASSERT_TRUE(test_server_.Start());
6360 6359
6361 GURL url(test_server_.GetURL("files/redirect302-to-echo")); 6360 GURL url(test_server_.GetURL("files/redirect302-to-echo"));
6362 GURL original_first_party_url("http://example.com"); 6361 GURL original_first_party_url("http://example.com");
6363 GURL expected_first_party_url(test_server_.GetURL("echo")); 6362 GURL expected_first_party_url(test_server_.GetURL("echo"));
6364 6363
6365 TestDelegate d; 6364 TestDelegate d;
6366 { 6365 {
6367 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 6366 scoped_ptr<URLRequest> r(
6368 url, DEFAULT_PRIORITY, &d, NULL)); 6367 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
6369 r->set_first_party_for_cookies(original_first_party_url); 6368 r->set_first_party_for_cookies(original_first_party_url);
6370 r->set_first_party_url_policy( 6369 r->set_first_party_url_policy(
6371 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); 6370 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT);
6372 6371
6373 r->Start(); 6372 r->Start();
6374 base::RunLoop().Run(); 6373 base::RunLoop().Run();
6375 6374
6376 EXPECT_EQ(2U, r->url_chain().size()); 6375 EXPECT_EQ(2U, r->url_chain().size());
6377 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status()); 6376 EXPECT_EQ(URLRequestStatus::SUCCESS, r->status().status());
6378 EXPECT_EQ(OK, r->status().error()); 6377 EXPECT_EQ(OK, r->status().error());
6379 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies()); 6378 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies());
6380 } 6379 }
6381 } 6380 }
6382 6381
6383 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { 6382 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
6384 ASSERT_TRUE(test_server_.Start()); 6383 ASSERT_TRUE(test_server_.Start());
6385 6384
6386 const char kData[] = "hello world"; 6385 const char kData[] = "hello world";
6387 6386
6388 TestDelegate d; 6387 TestDelegate d;
6389 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6388 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6390 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL)); 6389 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d));
6391 req->set_method("POST"); 6390 req->set_method("POST");
6392 req->set_upload(CreateSimpleUploadData(kData)); 6391 req->set_upload(CreateSimpleUploadData(kData));
6393 HttpRequestHeaders headers; 6392 HttpRequestHeaders headers;
6394 headers.SetHeader(HttpRequestHeaders::kContentLength, 6393 headers.SetHeader(HttpRequestHeaders::kContentLength,
6395 base::UintToString(arraysize(kData) - 1)); 6394 base::UintToString(arraysize(kData) - 1));
6396 req->SetExtraRequestHeaders(headers); 6395 req->SetExtraRequestHeaders(headers);
6397 6396
6398 URLRequestRedirectJob* job = new URLRequestRedirectJob( 6397 URLRequestRedirectJob* job = new URLRequestRedirectJob(
6399 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), 6398 req.get(), &default_network_delegate_, test_server_.GetURL("echo"),
6400 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); 6399 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason");
6401 AddTestInterceptor()->set_main_intercept_job(job); 6400 AddTestInterceptor()->set_main_intercept_job(job);
6402 6401
6403 req->Start(); 6402 req->Start();
6404 base::RunLoop().Run(); 6403 base::RunLoop().Run();
6405 EXPECT_EQ("GET", req->method()); 6404 EXPECT_EQ("GET", req->method());
6406 } 6405 }
6407 6406
6408 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { 6407 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) {
6409 ASSERT_TRUE(test_server_.Start()); 6408 ASSERT_TRUE(test_server_.Start());
6410 6409
6411 const char kData[] = "hello world"; 6410 const char kData[] = "hello world";
6412 6411
6413 TestDelegate d; 6412 TestDelegate d;
6414 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6413 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6415 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL)); 6414 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d));
6416 req->set_method("POST"); 6415 req->set_method("POST");
6417 req->set_upload(CreateSimpleUploadData(kData)); 6416 req->set_upload(CreateSimpleUploadData(kData));
6418 HttpRequestHeaders headers; 6417 HttpRequestHeaders headers;
6419 headers.SetHeader(HttpRequestHeaders::kContentLength, 6418 headers.SetHeader(HttpRequestHeaders::kContentLength,
6420 base::UintToString(arraysize(kData) - 1)); 6419 base::UintToString(arraysize(kData) - 1));
6421 req->SetExtraRequestHeaders(headers); 6420 req->SetExtraRequestHeaders(headers);
6422 6421
6423 URLRequestRedirectJob* job = new URLRequestRedirectJob( 6422 URLRequestRedirectJob* job = new URLRequestRedirectJob(
6424 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), 6423 req.get(), &default_network_delegate_, test_server_.GetURL("echo"),
6425 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, 6424 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT,
(...skipping 12 matching lines...) Expand all
6438 6437
6439 StaticHttpUserAgentSettings settings("en", std::string()); 6438 StaticHttpUserAgentSettings settings("en", std::string());
6440 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 6439 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
6441 TestURLRequestContext context(true); 6440 TestURLRequestContext context(true);
6442 context.set_network_delegate(&network_delegate); 6441 context.set_network_delegate(&network_delegate);
6443 context.set_http_user_agent_settings(&settings); 6442 context.set_http_user_agent_settings(&settings);
6444 context.Init(); 6443 context.Init();
6445 6444
6446 TestDelegate d; 6445 TestDelegate d;
6447 scoped_ptr<URLRequest> req(context.CreateRequest( 6446 scoped_ptr<URLRequest> req(context.CreateRequest(
6448 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d, 6447 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d));
6449 NULL));
6450 req->Start(); 6448 req->Start();
6451 base::RunLoop().Run(); 6449 base::RunLoop().Run();
6452 EXPECT_EQ("en", d.data_received()); 6450 EXPECT_EQ("en", d.data_received());
6453 } 6451 }
6454 6452
6455 // Check that an empty A-L header is not sent. http://crbug.com/77365. 6453 // Check that an empty A-L header is not sent. http://crbug.com/77365.
6456 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { 6454 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) {
6457 ASSERT_TRUE(test_server_.Start()); 6455 ASSERT_TRUE(test_server_.Start());
6458 6456
6459 std::string empty_string; // Avoid most vexing parse on line below. 6457 std::string empty_string; // Avoid most vexing parse on line below.
6460 StaticHttpUserAgentSettings settings(empty_string, empty_string); 6458 StaticHttpUserAgentSettings settings(empty_string, empty_string);
6461 TestNetworkDelegate network_delegate; // Must outlive URLRequests. 6459 TestNetworkDelegate network_delegate; // Must outlive URLRequests.
6462 TestURLRequestContext context(true); 6460 TestURLRequestContext context(true);
6463 context.set_network_delegate(&network_delegate); 6461 context.set_network_delegate(&network_delegate);
6464 context.Init(); 6462 context.Init();
6465 // We override the language after initialization because empty entries 6463 // We override the language after initialization because empty entries
6466 // get overridden by Init(). 6464 // get overridden by Init().
6467 context.set_http_user_agent_settings(&settings); 6465 context.set_http_user_agent_settings(&settings);
6468 6466
6469 TestDelegate d; 6467 TestDelegate d;
6470 scoped_ptr<URLRequest> req(context.CreateRequest( 6468 scoped_ptr<URLRequest> req(context.CreateRequest(
6471 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d, 6469 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d));
6472 NULL));
6473 req->Start(); 6470 req->Start();
6474 base::RunLoop().Run(); 6471 base::RunLoop().Run();
6475 EXPECT_EQ("None", d.data_received()); 6472 EXPECT_EQ("None", d.data_received());
6476 } 6473 }
6477 6474
6478 // Check that if request overrides the A-L header, the default is not appended. 6475 // Check that if request overrides the A-L header, the default is not appended.
6479 // See http://crbug.com/20894 6476 // See http://crbug.com/20894
6480 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { 6477 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) {
6481 ASSERT_TRUE(test_server_.Start()); 6478 ASSERT_TRUE(test_server_.Start());
6482 6479
6483 TestDelegate d; 6480 TestDelegate d;
6484 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6481 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6485 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d, 6482 test_server_.GetURL("echoheader?Accept-Language"), DEFAULT_PRIORITY, &d));
6486 NULL));
6487 HttpRequestHeaders headers; 6483 HttpRequestHeaders headers;
6488 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); 6484 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru");
6489 req->SetExtraRequestHeaders(headers); 6485 req->SetExtraRequestHeaders(headers);
6490 req->Start(); 6486 req->Start();
6491 base::RunLoop().Run(); 6487 base::RunLoop().Run();
6492 EXPECT_EQ(std::string("ru"), d.data_received()); 6488 EXPECT_EQ(std::string("ru"), d.data_received());
6493 } 6489 }
6494 6490
6495 // Check that default A-E header is sent. 6491 // Check that default A-E header is sent.
6496 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { 6492 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) {
6497 ASSERT_TRUE(test_server_.Start()); 6493 ASSERT_TRUE(test_server_.Start());
6498 6494
6499 TestDelegate d; 6495 TestDelegate d;
6500 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6496 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6501 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d, 6497 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d));
6502 NULL));
6503 HttpRequestHeaders headers; 6498 HttpRequestHeaders headers;
6504 req->SetExtraRequestHeaders(headers); 6499 req->SetExtraRequestHeaders(headers);
6505 req->Start(); 6500 req->Start();
6506 base::RunLoop().Run(); 6501 base::RunLoop().Run();
6507 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); 6502 EXPECT_TRUE(ContainsString(d.data_received(), "gzip"));
6508 } 6503 }
6509 6504
6510 // Check that if request overrides the A-E header, the default is not appended. 6505 // Check that if request overrides the A-E header, the default is not appended.
6511 // See http://crbug.com/47381 6506 // See http://crbug.com/47381
6512 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { 6507 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) {
6513 ASSERT_TRUE(test_server_.Start()); 6508 ASSERT_TRUE(test_server_.Start());
6514 6509
6515 TestDelegate d; 6510 TestDelegate d;
6516 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6511 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6517 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d, 6512 test_server_.GetURL("echoheader?Accept-Encoding"), DEFAULT_PRIORITY, &d));
6518 NULL));
6519 HttpRequestHeaders headers; 6513 HttpRequestHeaders headers;
6520 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); 6514 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity");
6521 req->SetExtraRequestHeaders(headers); 6515 req->SetExtraRequestHeaders(headers);
6522 req->Start(); 6516 req->Start();
6523 base::RunLoop().Run(); 6517 base::RunLoop().Run();
6524 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); 6518 EXPECT_FALSE(ContainsString(d.data_received(), "gzip"));
6525 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); 6519 EXPECT_TRUE(ContainsString(d.data_received(), "identity"));
6526 } 6520 }
6527 6521
6528 // Check that setting the A-C header sends the proper header. 6522 // Check that setting the A-C header sends the proper header.
6529 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { 6523 TEST_F(URLRequestTestHTTP, SetAcceptCharset) {
6530 ASSERT_TRUE(test_server_.Start()); 6524 ASSERT_TRUE(test_server_.Start());
6531 6525
6532 TestDelegate d; 6526 TestDelegate d;
6533 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6527 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6534 test_server_.GetURL("echoheader?Accept-Charset"), DEFAULT_PRIORITY, &d, 6528 test_server_.GetURL("echoheader?Accept-Charset"), DEFAULT_PRIORITY, &d));
6535 NULL));
6536 HttpRequestHeaders headers; 6529 HttpRequestHeaders headers;
6537 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); 6530 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r");
6538 req->SetExtraRequestHeaders(headers); 6531 req->SetExtraRequestHeaders(headers);
6539 req->Start(); 6532 req->Start();
6540 base::RunLoop().Run(); 6533 base::RunLoop().Run();
6541 EXPECT_EQ(std::string("koi-8r"), d.data_received()); 6534 EXPECT_EQ(std::string("koi-8r"), d.data_received());
6542 } 6535 }
6543 6536
6544 // Check that default User-Agent header is sent. 6537 // Check that default User-Agent header is sent.
6545 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { 6538 TEST_F(URLRequestTestHTTP, DefaultUserAgent) {
6546 ASSERT_TRUE(test_server_.Start()); 6539 ASSERT_TRUE(test_server_.Start());
6547 6540
6548 TestDelegate d; 6541 TestDelegate d;
6549 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6542 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6550 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d, 6543 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d));
6551 NULL));
6552 req->Start(); 6544 req->Start();
6553 base::RunLoop().Run(); 6545 base::RunLoop().Run();
6554 EXPECT_EQ(default_context_.http_user_agent_settings()->GetUserAgent(), 6546 EXPECT_EQ(default_context_.http_user_agent_settings()->GetUserAgent(),
6555 d.data_received()); 6547 d.data_received());
6556 } 6548 }
6557 6549
6558 // Check that if request overrides the User-Agent header, 6550 // Check that if request overrides the User-Agent header,
6559 // the default is not appended. 6551 // the default is not appended.
6560 TEST_F(URLRequestTestHTTP, OverrideUserAgent) { 6552 TEST_F(URLRequestTestHTTP, OverrideUserAgent) {
6561 ASSERT_TRUE(test_server_.Start()); 6553 ASSERT_TRUE(test_server_.Start());
6562 6554
6563 TestDelegate d; 6555 TestDelegate d;
6564 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6556 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6565 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d, 6557 test_server_.GetURL("echoheader?User-Agent"), DEFAULT_PRIORITY, &d));
6566 NULL));
6567 HttpRequestHeaders headers; 6558 HttpRequestHeaders headers;
6568 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); 6559 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)");
6569 req->SetExtraRequestHeaders(headers); 6560 req->SetExtraRequestHeaders(headers);
6570 req->Start(); 6561 req->Start();
6571 base::RunLoop().Run(); 6562 base::RunLoop().Run();
6572 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); 6563 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received());
6573 } 6564 }
6574 6565
6575 // Check that a NULL HttpUserAgentSettings causes the corresponding empty 6566 // Check that a NULL HttpUserAgentSettings causes the corresponding empty
6576 // User-Agent header to be sent but does not send the Accept-Language and 6567 // User-Agent header to be sent but does not send the Accept-Language and
(...skipping 12 matching lines...) Expand all
6589 struct { 6580 struct {
6590 const char* request; 6581 const char* request;
6591 const char* expected_response; 6582 const char* expected_response;
6592 } tests[] = { { "echoheader?Accept-Language", "None" }, 6583 } tests[] = { { "echoheader?Accept-Language", "None" },
6593 { "echoheader?Accept-Charset", "None" }, 6584 { "echoheader?Accept-Charset", "None" },
6594 { "echoheader?User-Agent", "" } }; 6585 { "echoheader?User-Agent", "" } };
6595 6586
6596 for (size_t i = 0; i < arraysize(tests); i++) { 6587 for (size_t i = 0; i < arraysize(tests); i++) {
6597 TestDelegate d; 6588 TestDelegate d;
6598 scoped_ptr<URLRequest> req(context.CreateRequest( 6589 scoped_ptr<URLRequest> req(context.CreateRequest(
6599 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d, NULL)); 6590 test_server_.GetURL(tests[i].request), DEFAULT_PRIORITY, &d));
6600 req->Start(); 6591 req->Start();
6601 base::RunLoop().Run(); 6592 base::RunLoop().Run();
6602 EXPECT_EQ(tests[i].expected_response, d.data_received()) 6593 EXPECT_EQ(tests[i].expected_response, d.data_received())
6603 << " Request = \"" << tests[i].request << "\""; 6594 << " Request = \"" << tests[i].request << "\"";
6604 } 6595 }
6605 } 6596 }
6606 6597
6607 // Make sure that URLRequest passes on its priority updates to 6598 // Make sure that URLRequest passes on its priority updates to
6608 // newly-created jobs after the first one. 6599 // newly-created jobs after the first one.
6609 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { 6600 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) {
6610 ASSERT_TRUE(test_server_.Start()); 6601 ASSERT_TRUE(test_server_.Start());
6611 6602
6612 TestDelegate d; 6603 TestDelegate d;
6613 scoped_ptr<URLRequest> req(default_context_.CreateRequest( 6604 scoped_ptr<URLRequest> req(default_context_.CreateRequest(
6614 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d, NULL)); 6605 test_server_.GetURL("empty.html"), DEFAULT_PRIORITY, &d));
6615 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); 6606 EXPECT_EQ(DEFAULT_PRIORITY, req->priority());
6616 6607
6617 scoped_refptr<URLRequestRedirectJob> redirect_job = 6608 scoped_refptr<URLRequestRedirectJob> redirect_job =
6618 new URLRequestRedirectJob( 6609 new URLRequestRedirectJob(
6619 req.get(), &default_network_delegate_, test_server_.GetURL("echo"), 6610 req.get(), &default_network_delegate_, test_server_.GetURL("echo"),
6620 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason"); 6611 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason");
6621 AddTestInterceptor()->set_main_intercept_job(redirect_job.get()); 6612 AddTestInterceptor()->set_main_intercept_job(redirect_job.get());
6622 6613
6623 req->SetPriority(LOW); 6614 req->SetPriority(LOW);
6624 req->Start(); 6615 req->Start();
(...skipping 28 matching lines...) Expand all
6653 network_layer->OnSuspend(); 6644 network_layer->OnSuspend();
6654 6645
6655 HttpCache http_cache(network_layer.release(), default_context_.net_log(), 6646 HttpCache http_cache(network_layer.release(), default_context_.net_log(),
6656 HttpCache::DefaultBackend::InMemory(0)); 6647 HttpCache::DefaultBackend::InMemory(0));
6657 6648
6658 TestURLRequestContext context(true); 6649 TestURLRequestContext context(true);
6659 context.set_http_transaction_factory(&http_cache); 6650 context.set_http_transaction_factory(&http_cache);
6660 context.Init(); 6651 context.Init();
6661 6652
6662 TestDelegate d; 6653 TestDelegate d;
6663 scoped_ptr<URLRequest> req(context.CreateRequest( 6654 scoped_ptr<URLRequest> req(
6664 GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, NULL)); 6655 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d));
6665 req->Start(); 6656 req->Start();
6666 base::RunLoop().Run(); 6657 base::RunLoop().Run();
6667 6658
6668 EXPECT_TRUE(d.request_failed()); 6659 EXPECT_TRUE(d.request_failed());
6669 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 6660 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
6670 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); 6661 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error());
6671 } 6662 }
6672 6663
6673 // Check that creating a network request while entering/exiting suspend mode 6664 // Check that creating a network request while entering/exiting suspend mode
6674 // fails as it should in the case there is no cache. This is the only case 6665 // fails as it should in the case there is no cache. This is the only case
(...skipping 11 matching lines...) Expand all
6686 params.network_delegate = &default_network_delegate_; 6677 params.network_delegate = &default_network_delegate_;
6687 params.http_server_properties = default_context_.http_server_properties(); 6678 params.http_server_properties = default_context_.http_server_properties();
6688 HttpNetworkLayer network_layer(new HttpNetworkSession(params)); 6679 HttpNetworkLayer network_layer(new HttpNetworkSession(params));
6689 network_layer.OnSuspend(); 6680 network_layer.OnSuspend();
6690 6681
6691 TestURLRequestContext context(true); 6682 TestURLRequestContext context(true);
6692 context.set_http_transaction_factory(&network_layer); 6683 context.set_http_transaction_factory(&network_layer);
6693 context.Init(); 6684 context.Init();
6694 6685
6695 TestDelegate d; 6686 TestDelegate d;
6696 scoped_ptr<URLRequest> req(context.CreateRequest( 6687 scoped_ptr<URLRequest> req(
6697 GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, NULL)); 6688 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d));
6698 req->Start(); 6689 req->Start();
6699 base::RunLoop().Run(); 6690 base::RunLoop().Run();
6700 6691
6701 EXPECT_TRUE(d.request_failed()); 6692 EXPECT_TRUE(d.request_failed());
6702 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status()); 6693 EXPECT_EQ(URLRequestStatus::FAILED, req->status().status());
6703 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error()); 6694 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, req->status().error());
6704 } 6695 }
6705 6696
6706 class URLRequestInterceptorTestHTTP : public URLRequestTestHTTP { 6697 class URLRequestInterceptorTestHTTP : public URLRequestTestHTTP {
6707 public: 6698 public:
(...skipping 20 matching lines...) Expand all
6728 TEST_F(URLRequestInterceptorTestHTTP, 6719 TEST_F(URLRequestInterceptorTestHTTP,
6729 NetworkDelegateNotificationOnRedirectIntercept) { 6720 NetworkDelegateNotificationOnRedirectIntercept) {
6730 interceptor()->set_intercept_redirect(true); 6721 interceptor()->set_intercept_redirect(true);
6731 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers()); 6722 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers());
6732 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data()); 6723 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data());
6733 6724
6734 ASSERT_TRUE(test_server()->Start()); 6725 ASSERT_TRUE(test_server()->Start());
6735 6726
6736 TestDelegate d; 6727 TestDelegate d;
6737 scoped_ptr<URLRequest> req(default_context().CreateRequest( 6728 scoped_ptr<URLRequest> req(default_context().CreateRequest(
6738 test_server()->GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, 6729 test_server()->GetURL("files/redirect-test.html"), DEFAULT_PRIORITY, &d));
6739 &d, nullptr));
6740 req->Start(); 6730 req->Start();
6741 base::RunLoop().Run(); 6731 base::RunLoop().Run();
6742 6732
6743 EXPECT_TRUE(interceptor()->did_intercept_redirect()); 6733 EXPECT_TRUE(interceptor()->did_intercept_redirect());
6744 // Check we got one good response 6734 // Check we got one good response
6745 EXPECT_TRUE(req->status().is_success()); 6735 EXPECT_TRUE(req->status().is_success());
6746 if (req->status().is_success()) 6736 if (req->status().is_success())
6747 EXPECT_EQ(200, req->response_headers()->response_code()); 6737 EXPECT_EQ(200, req->response_headers()->response_code());
6748 6738
6749 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); 6739 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received());
(...skipping 11 matching lines...) Expand all
6761 interceptor()->set_intercept_final_response(true); 6751 interceptor()->set_intercept_final_response(true);
6762 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); 6752 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers());
6763 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); 6753 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data());
6764 default_network_delegate()->set_can_be_intercepted_on_error(true); 6754 default_network_delegate()->set_can_be_intercepted_on_error(true);
6765 6755
6766 ASSERT_TRUE(test_server()->Start()); 6756 ASSERT_TRUE(test_server()->Start());
6767 6757
6768 TestDelegate d; 6758 TestDelegate d;
6769 scoped_ptr<URLRequest> req(default_context().CreateRequest( 6759 scoped_ptr<URLRequest> req(default_context().CreateRequest(
6770 test_server()->GetURL("files/two-content-lengths.html"), DEFAULT_PRIORITY, 6760 test_server()->GetURL("files/two-content-lengths.html"), DEFAULT_PRIORITY,
6771 &d, nullptr)); 6761 &d));
6772 req->set_method("GET"); 6762 req->set_method("GET");
6773 req->Start(); 6763 req->Start();
6774 base::RunLoop().Run(); 6764 base::RunLoop().Run();
6775 6765
6776 EXPECT_TRUE(interceptor()->did_intercept_final()); 6766 EXPECT_TRUE(interceptor()->did_intercept_final());
6777 6767
6778 // Check we received one good response. 6768 // Check we received one good response.
6779 EXPECT_TRUE(req->status().is_success()); 6769 EXPECT_TRUE(req->status().is_success());
6780 if (req->status().is_success()) 6770 if (req->status().is_success())
6781 EXPECT_EQ(200, req->response_headers()->response_code()); 6771 EXPECT_EQ(200, req->response_headers()->response_code());
(...skipping 11 matching lines...) Expand all
6793 // Intercept that error and respond with an OK response. 6783 // Intercept that error and respond with an OK response.
6794 interceptor()->set_intercept_final_response(true); 6784 interceptor()->set_intercept_final_response(true);
6795 6785
6796 // Intercept with a real URLRequestHttpJob. 6786 // Intercept with a real URLRequestHttpJob.
6797 interceptor()->set_use_url_request_http_job(true); 6787 interceptor()->set_use_url_request_http_job(true);
6798 6788
6799 ASSERT_TRUE(test_server()->Start()); 6789 ASSERT_TRUE(test_server()->Start());
6800 6790
6801 TestDelegate d; 6791 TestDelegate d;
6802 scoped_ptr<URLRequest> req(default_context().CreateRequest( 6792 scoped_ptr<URLRequest> req(default_context().CreateRequest(
6803 test_server()->GetURL("files/simple.html"), DEFAULT_PRIORITY, 6793 test_server()->GetURL("files/simple.html"), DEFAULT_PRIORITY, &d));
6804 &d, nullptr));
6805 req->set_method("GET"); 6794 req->set_method("GET");
6806 req->Start(); 6795 req->Start();
6807 base::RunLoop().Run(); 6796 base::RunLoop().Run();
6808 6797
6809 EXPECT_TRUE(interceptor()->did_intercept_final()); 6798 EXPECT_TRUE(interceptor()->did_intercept_final());
6810 6799
6811 // Check we received one good response. 6800 // Check we received one good response.
6812 EXPECT_TRUE(req->status().is_success()); 6801 EXPECT_TRUE(req->status().is_success());
6813 if (req->status().is_success()) 6802 if (req->status().is_success())
6814 EXPECT_EQ(200, req->response_headers()->response_code()); 6803 EXPECT_EQ(200, req->response_headers()->response_code());
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
6861 // if the origins are meant to be distinct. Otherwise, we'll use the 6850 // if the origins are meant to be distinct. Otherwise, we'll use the
6862 // |origin_server_| for both endpoints. 6851 // |origin_server_| for both endpoints.
6863 GURL destination_url = 6852 GURL destination_url =
6864 destination_server_ ? destination_server_->GetURL("echoheader?Referer") 6853 destination_server_ ? destination_server_->GetURL("echoheader?Referer")
6865 : origin_server_->GetURL("echoheader?Referer"); 6854 : origin_server_->GetURL("echoheader?Referer");
6866 GURL origin_url = 6855 GURL origin_url =
6867 origin_server_->GetURL("server-redirect?" + destination_url.spec()); 6856 origin_server_->GetURL("server-redirect?" + destination_url.spec());
6868 6857
6869 TestDelegate d; 6858 TestDelegate d;
6870 scoped_ptr<URLRequest> req( 6859 scoped_ptr<URLRequest> req(
6871 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d, NULL)); 6860 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d));
6872 req->set_referrer_policy(policy); 6861 req->set_referrer_policy(policy);
6873 req->SetReferrer(referrer.spec()); 6862 req->SetReferrer(referrer.spec());
6874 req->Start(); 6863 req->Start();
6875 base::RunLoop().Run(); 6864 base::RunLoop().Run();
6876 6865
6877 EXPECT_EQ(1, d.response_started_count()); 6866 EXPECT_EQ(1, d.response_started_count());
6878 EXPECT_EQ(1, d.received_redirect_count()); 6867 EXPECT_EQ(1, d.received_redirect_count());
6879 EXPECT_EQ(destination_url, req->url()); 6868 EXPECT_EQ(destination_url, req->url());
6880 EXPECT_TRUE(req->status().is_success()); 6869 EXPECT_TRUE(req->status().is_success());
6881 EXPECT_EQ(200, req->response_headers()->response_code()); 6870 EXPECT_EQ(200, req->response_headers()->response_code());
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
7050 TEST_F(HTTPSRequestTest, HTTPSGetTest) { 7039 TEST_F(HTTPSRequestTest, HTTPSGetTest) {
7051 SpawnedTestServer test_server( 7040 SpawnedTestServer test_server(
7052 SpawnedTestServer::TYPE_HTTPS, 7041 SpawnedTestServer::TYPE_HTTPS,
7053 SpawnedTestServer::kLocalhost, 7042 SpawnedTestServer::kLocalhost,
7054 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7043 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7055 ASSERT_TRUE(test_server.Start()); 7044 ASSERT_TRUE(test_server.Start());
7056 7045
7057 TestDelegate d; 7046 TestDelegate d;
7058 { 7047 {
7059 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7048 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7060 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 7049 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d));
7061 r->Start(); 7050 r->Start();
7062 EXPECT_TRUE(r->is_pending()); 7051 EXPECT_TRUE(r->is_pending());
7063 7052
7064 base::RunLoop().Run(); 7053 base::RunLoop().Run();
7065 7054
7066 EXPECT_EQ(1, d.response_started_count()); 7055 EXPECT_EQ(1, d.response_started_count());
7067 EXPECT_FALSE(d.received_data_before_response()); 7056 EXPECT_FALSE(d.received_data_before_response());
7068 EXPECT_NE(0, d.bytes_received()); 7057 EXPECT_NE(0, d.bytes_received());
7069 CheckSSLInfo(r->ssl_info()); 7058 CheckSSLInfo(r->ssl_info());
7070 EXPECT_EQ(test_server.host_port_pair().host(), 7059 EXPECT_EQ(test_server.host_port_pair().host(),
(...skipping 11 matching lines...) Expand all
7082 ssl_options, 7071 ssl_options,
7083 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7072 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7084 ASSERT_TRUE(test_server.Start()); 7073 ASSERT_TRUE(test_server.Start());
7085 7074
7086 bool err_allowed = true; 7075 bool err_allowed = true;
7087 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 7076 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
7088 TestDelegate d; 7077 TestDelegate d;
7089 { 7078 {
7090 d.set_allow_certificate_errors(err_allowed); 7079 d.set_allow_certificate_errors(err_allowed);
7091 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7080 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7092 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 7081 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d));
7093 7082
7094 r->Start(); 7083 r->Start();
7095 EXPECT_TRUE(r->is_pending()); 7084 EXPECT_TRUE(r->is_pending());
7096 7085
7097 base::RunLoop().Run(); 7086 base::RunLoop().Run();
7098 7087
7099 EXPECT_EQ(1, d.response_started_count()); 7088 EXPECT_EQ(1, d.response_started_count());
7100 EXPECT_FALSE(d.received_data_before_response()); 7089 EXPECT_FALSE(d.received_data_before_response());
7101 EXPECT_TRUE(d.have_certificate_errors()); 7090 EXPECT_TRUE(d.have_certificate_errors());
7102 if (err_allowed) { 7091 if (err_allowed) {
(...skipping 16 matching lines...) Expand all
7119 ASSERT_TRUE(test_server.Start()); 7108 ASSERT_TRUE(test_server.Start());
7120 7109
7121 // Iterate from false to true, just so that we do the opposite of the 7110 // Iterate from false to true, just so that we do the opposite of the
7122 // previous test in order to increase test coverage. 7111 // previous test in order to increase test coverage.
7123 bool err_allowed = false; 7112 bool err_allowed = false;
7124 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { 7113 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) {
7125 TestDelegate d; 7114 TestDelegate d;
7126 { 7115 {
7127 d.set_allow_certificate_errors(err_allowed); 7116 d.set_allow_certificate_errors(err_allowed);
7128 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7117 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7129 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 7118 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d));
7130 7119
7131 r->Start(); 7120 r->Start();
7132 EXPECT_TRUE(r->is_pending()); 7121 EXPECT_TRUE(r->is_pending());
7133 7122
7134 base::RunLoop().Run(); 7123 base::RunLoop().Run();
7135 7124
7136 EXPECT_EQ(1, d.response_started_count()); 7125 EXPECT_EQ(1, d.response_started_count());
7137 EXPECT_FALSE(d.received_data_before_response()); 7126 EXPECT_FALSE(d.received_data_before_response());
7138 EXPECT_TRUE(d.have_certificate_errors()); 7127 EXPECT_TRUE(d.have_certificate_errors());
7139 if (err_allowed) { 7128 if (err_allowed) {
(...skipping 28 matching lines...) Expand all
7168 TestURLRequestContext context(true); 7157 TestURLRequestContext context(true);
7169 context.set_network_delegate(&network_delegate); 7158 context.set_network_delegate(&network_delegate);
7170 context.set_host_resolver(&host_resolver); 7159 context.set_host_resolver(&host_resolver);
7171 TransportSecurityState transport_security_state; 7160 TransportSecurityState transport_security_state;
7172 context.set_transport_security_state(&transport_security_state); 7161 context.set_transport_security_state(&transport_security_state);
7173 context.Init(); 7162 context.Init();
7174 7163
7175 TestDelegate d; 7164 TestDelegate d;
7176 scoped_ptr<URLRequest> r(context.CreateRequest( 7165 scoped_ptr<URLRequest> r(context.CreateRequest(
7177 GURL(base::StringPrintf("https://www.google.com:%d", 7166 GURL(base::StringPrintf("https://www.google.com:%d",
7178 test_server.host_port_pair().port())), 7167 test_server.host_port_pair().port())),
7179 DEFAULT_PRIORITY, &d, NULL)); 7168 DEFAULT_PRIORITY, &d));
7180 7169
7181 r->Start(); 7170 r->Start();
7182 EXPECT_TRUE(r->is_pending()); 7171 EXPECT_TRUE(r->is_pending());
7183 7172
7184 base::RunLoop().Run(); 7173 base::RunLoop().Run();
7185 7174
7186 EXPECT_EQ(1, d.response_started_count()); 7175 EXPECT_EQ(1, d.response_started_count());
7187 EXPECT_FALSE(d.received_data_before_response()); 7176 EXPECT_FALSE(d.received_data_before_response());
7188 EXPECT_TRUE(d.have_certificate_errors()); 7177 EXPECT_TRUE(d.have_certificate_errors());
7189 EXPECT_TRUE(d.certificate_errors_are_fatal()); 7178 EXPECT_TRUE(d.certificate_errors_are_fatal());
(...skipping 30 matching lines...) Expand all
7220 context.set_transport_security_state(&transport_security_state); 7209 context.set_transport_security_state(&transport_security_state);
7221 context.Init(); 7210 context.Init();
7222 7211
7223 TransportSecurityState::DomainState dynamic_domain_state; 7212 TransportSecurityState::DomainState dynamic_domain_state;
7224 EXPECT_FALSE(transport_security_state.GetDynamicDomainState( 7213 EXPECT_FALSE(transport_security_state.GetDynamicDomainState(
7225 "www.google.com", &dynamic_domain_state)); 7214 "www.google.com", &dynamic_domain_state));
7226 7215
7227 TestDelegate d; 7216 TestDelegate d;
7228 scoped_ptr<URLRequest> r(context.CreateRequest( 7217 scoped_ptr<URLRequest> r(context.CreateRequest(
7229 GURL(base::StringPrintf("https://www.google.com:%d", 7218 GURL(base::StringPrintf("https://www.google.com:%d",
7230 test_server.host_port_pair().port())), 7219 test_server.host_port_pair().port())),
7231 DEFAULT_PRIORITY, &d, NULL)); 7220 DEFAULT_PRIORITY, &d));
7232 7221
7233 r->Start(); 7222 r->Start();
7234 EXPECT_TRUE(r->is_pending()); 7223 EXPECT_TRUE(r->is_pending());
7235 7224
7236 base::RunLoop().Run(); 7225 base::RunLoop().Run();
7237 7226
7238 EXPECT_EQ(1, d.response_started_count()); 7227 EXPECT_EQ(1, d.response_started_count());
7239 EXPECT_FALSE(d.received_data_before_response()); 7228 EXPECT_FALSE(d.received_data_before_response());
7240 EXPECT_TRUE(d.have_certificate_errors()); 7229 EXPECT_TRUE(d.have_certificate_errors());
7241 EXPECT_TRUE(d.certificate_errors_are_fatal()); 7230 EXPECT_TRUE(d.certificate_errors_are_fatal());
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
7294 context.set_network_delegate(&network_delegate); 7283 context.set_network_delegate(&network_delegate);
7295 context.Init(); 7284 context.Init();
7296 7285
7297 TestDelegate d; 7286 TestDelegate d;
7298 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will 7287 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will
7299 // cause a certificate error. Ignore the error. 7288 // cause a certificate error. Ignore the error.
7300 d.set_allow_certificate_errors(true); 7289 d.set_allow_certificate_errors(true);
7301 7290
7302 scoped_ptr<URLRequest> req(context.CreateRequest( 7291 scoped_ptr<URLRequest> req(context.CreateRequest(
7303 GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", 7292 GURL(base::StringPrintf("http://www.somewhere.com:%d/echo",
7304 test_server.host_port_pair().port())), 7293 test_server.host_port_pair().port())),
7305 DEFAULT_PRIORITY, &d, NULL)); 7294 DEFAULT_PRIORITY, &d));
7306 req->set_method("POST"); 7295 req->set_method("POST");
7307 req->set_upload(CreateSimpleUploadData(kData)); 7296 req->set_upload(CreateSimpleUploadData(kData));
7308 7297
7309 req->Start(); 7298 req->Start();
7310 base::RunLoop().Run(); 7299 base::RunLoop().Run();
7311 7300
7312 EXPECT_EQ("https", req->url().scheme()); 7301 EXPECT_EQ("https", req->url().scheme());
7313 EXPECT_EQ("POST", req->method()); 7302 EXPECT_EQ("POST", req->method());
7314 EXPECT_EQ(kData, d.data_received()); 7303 EXPECT_EQ(kData, d.data_received());
7315 7304
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
7357 test_server.host_port_pair().port())); 7346 test_server.host_port_pair().port()));
7358 url::Replacements<char> replacements; 7347 url::Replacements<char> replacements;
7359 const char kNewScheme[] = "https"; 7348 const char kNewScheme[] = "https";
7360 replacements.SetScheme(kNewScheme, url::Component(0, strlen(kNewScheme))); 7349 replacements.SetScheme(kNewScheme, url::Component(0, strlen(kNewScheme)));
7361 GURL hsts_https_url = hsts_http_url.ReplaceComponents(replacements); 7350 GURL hsts_https_url = hsts_http_url.ReplaceComponents(replacements);
7362 7351
7363 TestDelegate d; 7352 TestDelegate d;
7364 // Quit on redirect to allow response header inspection upon redirect. 7353 // Quit on redirect to allow response header inspection upon redirect.
7365 d.set_quit_on_redirect(true); 7354 d.set_quit_on_redirect(true);
7366 7355
7367 scoped_ptr<URLRequest> req(context.CreateRequest(hsts_http_url, 7356 scoped_ptr<URLRequest> req(
7368 DEFAULT_PRIORITY, &d, NULL)); 7357 context.CreateRequest(hsts_http_url, DEFAULT_PRIORITY, &d));
7369 // Set Origin header to simulate a cross-origin request. 7358 // Set Origin header to simulate a cross-origin request.
7370 HttpRequestHeaders request_headers; 7359 HttpRequestHeaders request_headers;
7371 request_headers.SetHeader("Origin", kOriginHeaderValue); 7360 request_headers.SetHeader("Origin", kOriginHeaderValue);
7372 req->SetExtraRequestHeaders(request_headers); 7361 req->SetExtraRequestHeaders(request_headers);
7373 7362
7374 req->Start(); 7363 req->Start();
7375 base::RunLoop().Run(); 7364 base::RunLoop().Run();
7376 7365
7377 EXPECT_EQ(1, d.received_redirect_count()); 7366 EXPECT_EQ(1, d.received_redirect_count());
7378 7367
(...skipping 16 matching lines...) Expand all
7395 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1); 7384 base::Time expiry = base::Time::Now() + base::TimeDelta::FromDays(1);
7396 bool include_subdomains = false; 7385 bool include_subdomains = false;
7397 transport_security_state.AddHSTS("example.net", expiry, include_subdomains); 7386 transport_security_state.AddHSTS("example.net", expiry, include_subdomains);
7398 TestURLRequestContext context(true); 7387 TestURLRequestContext context(true);
7399 context.set_transport_security_state(&transport_security_state); 7388 context.set_transport_security_state(&transport_security_state);
7400 context.set_network_delegate(&network_delegate); 7389 context.set_network_delegate(&network_delegate);
7401 context.Init(); 7390 context.Init();
7402 GURL ws_url("ws://example.net/echo"); 7391 GURL ws_url("ws://example.net/echo");
7403 TestDelegate delegate; 7392 TestDelegate delegate;
7404 scoped_ptr<URLRequest> request( 7393 scoped_ptr<URLRequest> request(
7405 context.CreateRequest(ws_url, DEFAULT_PRIORITY, &delegate, NULL)); 7394 context.CreateRequest(ws_url, DEFAULT_PRIORITY, &delegate));
7406 EXPECT_TRUE(request->GetHSTSRedirect(&ws_url)); 7395 EXPECT_TRUE(request->GetHSTSRedirect(&ws_url));
7407 EXPECT_TRUE(ws_url.SchemeIs("wss")); 7396 EXPECT_TRUE(ws_url.SchemeIs("wss"));
7408 } 7397 }
7409 7398
7410 namespace { 7399 namespace {
7411 7400
7412 class SSLClientAuthTestDelegate : public TestDelegate { 7401 class SSLClientAuthTestDelegate : public TestDelegate {
7413 public: 7402 public:
7414 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) { 7403 SSLClientAuthTestDelegate() : on_certificate_requested_count_(0) {
7415 } 7404 }
(...skipping 21 matching lines...) Expand all
7437 ssl_options.request_client_certificate = true; 7426 ssl_options.request_client_certificate = true;
7438 SpawnedTestServer test_server( 7427 SpawnedTestServer test_server(
7439 SpawnedTestServer::TYPE_HTTPS, 7428 SpawnedTestServer::TYPE_HTTPS,
7440 ssl_options, 7429 ssl_options,
7441 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7430 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7442 ASSERT_TRUE(test_server.Start()); 7431 ASSERT_TRUE(test_server.Start());
7443 7432
7444 SSLClientAuthTestDelegate d; 7433 SSLClientAuthTestDelegate d;
7445 { 7434 {
7446 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7435 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7447 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 7436 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d));
7448 7437
7449 r->Start(); 7438 r->Start();
7450 EXPECT_TRUE(r->is_pending()); 7439 EXPECT_TRUE(r->is_pending());
7451 7440
7452 base::RunLoop().Run(); 7441 base::RunLoop().Run();
7453 7442
7454 EXPECT_EQ(1, d.on_certificate_requested_count()); 7443 EXPECT_EQ(1, d.on_certificate_requested_count());
7455 EXPECT_FALSE(d.received_data_before_response()); 7444 EXPECT_FALSE(d.received_data_before_response());
7456 EXPECT_EQ(0, d.bytes_received()); 7445 EXPECT_EQ(0, d.bytes_received());
7457 7446
(...skipping 19 matching lines...) Expand all
7477 SpawnedTestServer::TYPE_HTTPS, 7466 SpawnedTestServer::TYPE_HTTPS,
7478 ssl_options, 7467 ssl_options,
7479 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7468 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7480 ASSERT_TRUE(test_server.Start()); 7469 ASSERT_TRUE(test_server.Start());
7481 7470
7482 SSLClientSocket::ClearSessionCache(); 7471 SSLClientSocket::ClearSessionCache();
7483 7472
7484 { 7473 {
7485 TestDelegate d; 7474 TestDelegate d;
7486 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7475 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7487 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); 7476 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d));
7488 7477
7489 r->Start(); 7478 r->Start();
7490 EXPECT_TRUE(r->is_pending()); 7479 EXPECT_TRUE(r->is_pending());
7491 7480
7492 base::RunLoop().Run(); 7481 base::RunLoop().Run();
7493 7482
7494 EXPECT_EQ(1, d.response_started_count()); 7483 EXPECT_EQ(1, d.response_started_count());
7495 } 7484 }
7496 7485
7497 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> 7486 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())->
7498 CloseAllConnections(); 7487 CloseAllConnections();
7499 7488
7500 { 7489 {
7501 TestDelegate d; 7490 TestDelegate d;
7502 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7491 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7503 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); 7492 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d));
7504 7493
7505 r->Start(); 7494 r->Start();
7506 EXPECT_TRUE(r->is_pending()); 7495 EXPECT_TRUE(r->is_pending());
7507 7496
7508 base::RunLoop().Run(); 7497 base::RunLoop().Run();
7509 7498
7510 // The response will look like; 7499 // The response will look like;
7511 // insert abc 7500 // insert abc
7512 // lookup abc 7501 // lookup abc
7513 // insert xyz 7502 // insert xyz
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
7568 SpawnedTestServer::TYPE_HTTPS, 7557 SpawnedTestServer::TYPE_HTTPS,
7569 ssl_options, 7558 ssl_options,
7570 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7559 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7571 ASSERT_TRUE(test_server.Start()); 7560 ASSERT_TRUE(test_server.Start());
7572 7561
7573 SSLClientSocket::ClearSessionCache(); 7562 SSLClientSocket::ClearSessionCache();
7574 7563
7575 { 7564 {
7576 TestDelegate d; 7565 TestDelegate d;
7577 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7566 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7578 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); 7567 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d));
7579 7568
7580 r->Start(); 7569 r->Start();
7581 EXPECT_TRUE(r->is_pending()); 7570 EXPECT_TRUE(r->is_pending());
7582 7571
7583 base::RunLoop().Run(); 7572 base::RunLoop().Run();
7584 7573
7585 EXPECT_EQ(1, d.response_started_count()); 7574 EXPECT_EQ(1, d.response_started_count());
7586 } 7575 }
7587 7576
7588 // Now create a new HttpCache with a different ssl_session_cache_shard value. 7577 // Now create a new HttpCache with a different ssl_session_cache_shard value.
(...skipping 11 matching lines...) Expand all
7600 7589
7601 scoped_ptr<HttpCache> cache(new HttpCache( 7590 scoped_ptr<HttpCache> cache(new HttpCache(
7602 new HttpNetworkSession(params), 7591 new HttpNetworkSession(params),
7603 HttpCache::DefaultBackend::InMemory(0))); 7592 HttpCache::DefaultBackend::InMemory(0)));
7604 7593
7605 default_context_.set_http_transaction_factory(cache.get()); 7594 default_context_.set_http_transaction_factory(cache.get());
7606 7595
7607 { 7596 {
7608 TestDelegate d; 7597 TestDelegate d;
7609 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7598 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7610 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); 7599 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d));
7611 7600
7612 r->Start(); 7601 r->Start();
7613 EXPECT_TRUE(r->is_pending()); 7602 EXPECT_TRUE(r->is_pending());
7614 7603
7615 base::RunLoop().Run(); 7604 base::RunLoop().Run();
7616 7605
7617 // The response will look like; 7606 // The response will look like;
7618 // insert abc 7607 // insert abc
7619 // insert xyz 7608 // insert xyz
7620 // 7609 //
(...skipping 29 matching lines...) Expand all
7650 } 7639 }
7651 7640
7652 SpawnedTestServer test_server( 7641 SpawnedTestServer test_server(
7653 SpawnedTestServer::TYPE_HTTPS, 7642 SpawnedTestServer::TYPE_HTTPS,
7654 SpawnedTestServer::kLocalhost, 7643 SpawnedTestServer::kLocalhost,
7655 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7644 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7656 ASSERT_TRUE(test_server.Start()); 7645 ASSERT_TRUE(test_server.Start());
7657 7646
7658 TestDelegate d; 7647 TestDelegate d;
7659 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 7648 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
7660 test_server.GetURL("client-cipher-list"), DEFAULT_PRIORITY, &d, NULL)); 7649 test_server.GetURL("client-cipher-list"), DEFAULT_PRIORITY, &d));
7661 r->Start(); 7650 r->Start();
7662 EXPECT_TRUE(r->is_pending()); 7651 EXPECT_TRUE(r->is_pending());
7663 7652
7664 base::RunLoop().Run(); 7653 base::RunLoop().Run();
7665 7654
7666 EXPECT_EQ(1, d.response_started_count()); 7655 EXPECT_EQ(1, d.response_started_count());
7667 std::vector<std::string> lines; 7656 std::vector<std::string> lines;
7668 base::SplitString(d.data_received(), '\n', &lines); 7657 base::SplitString(d.data_received(), '\n', &lines);
7669 7658
7670 for (size_t i = 0; i < lines.size(); i++) { 7659 for (size_t i = 0; i < lines.size(); i++) {
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
7750 DCHECK(!request_); 7739 DCHECK(!request_);
7751 context_.Init(); 7740 context_.Init();
7752 delegate_.set_allow_certificate_errors(true); 7741 delegate_.set_allow_certificate_errors(true);
7753 7742
7754 SpawnedTestServer test_server( 7743 SpawnedTestServer test_server(
7755 SpawnedTestServer::TYPE_HTTPS, 7744 SpawnedTestServer::TYPE_HTTPS,
7756 ssl_options, 7745 ssl_options,
7757 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 7746 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
7758 ASSERT_TRUE(test_server.Start()); 7747 ASSERT_TRUE(test_server.Start());
7759 7748
7760 request_ = context_.CreateRequest( 7749 request_ = context_.CreateRequest(test_server.GetURL(std::string()),
7761 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &delegate_, NULL); 7750 DEFAULT_PRIORITY, &delegate_);
7762 request_->Start(); 7751 request_->Start();
7763 7752
7764 base::RunLoop().Run(); 7753 base::RunLoop().Run();
7765 } 7754 }
7766 7755
7767 void set_fallback_min_version(uint16 version) { 7756 void set_fallback_min_version(uint16 version) {
7768 context_.set_fallback_min_version(version); 7757 context_.set_fallback_min_version(version);
7769 } 7758 }
7770 7759
7771 void ExpectConnection(int version) { 7760 void ExpectConnection(int version) {
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
7921 // Make a connection that does a probe fallback to SSLv3 but fails because 7910 // Make a connection that does a probe fallback to SSLv3 but fails because
7922 // SSLv3 fallback is disabled. We don't wish a session for this connection to 7911 // SSLv3 fallback is disabled. We don't wish a session for this connection to
7923 // be inserted locally. 7912 // be inserted locally.
7924 { 7913 {
7925 TestDelegate delegate; 7914 TestDelegate delegate;
7926 FallbackTestURLRequestContext context(true); 7915 FallbackTestURLRequestContext context(true);
7927 7916
7928 context.set_fallback_min_version(SSL_PROTOCOL_VERSION_TLS1); 7917 context.set_fallback_min_version(SSL_PROTOCOL_VERSION_TLS1);
7929 context.Init(); 7918 context.Init();
7930 scoped_ptr<URLRequest> request(context.CreateRequest( 7919 scoped_ptr<URLRequest> request(context.CreateRequest(
7931 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &delegate, NULL)); 7920 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &delegate));
7932 request->Start(); 7921 request->Start();
7933 7922
7934 base::RunLoop().Run(); 7923 base::RunLoop().Run();
7935 7924
7936 EXPECT_EQ(1, delegate.response_started_count()); 7925 EXPECT_EQ(1, delegate.response_started_count());
7937 EXPECT_FALSE(request->status().is_success()); 7926 EXPECT_FALSE(request->status().is_success());
7938 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status()); 7927 EXPECT_EQ(URLRequestStatus::FAILED, request->status().status());
7939 EXPECT_EQ(ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION, 7928 EXPECT_EQ(ERR_SSL_FALLBACK_BEYOND_MINIMUM_VERSION,
7940 request->status().error()); 7929 request->status().error());
7941 } 7930 }
7942 7931
7943 // Now allow SSLv3 connections and request the session cache log. 7932 // Now allow SSLv3 connections and request the session cache log.
7944 { 7933 {
7945 TestDelegate delegate; 7934 TestDelegate delegate;
7946 FallbackTestURLRequestContext context(true); 7935 FallbackTestURLRequestContext context(true);
7947 context.set_fallback_min_version(SSL_PROTOCOL_VERSION_SSL3); 7936 context.set_fallback_min_version(SSL_PROTOCOL_VERSION_SSL3);
7948 7937
7949 context.Init(); 7938 context.Init();
7950 scoped_ptr<URLRequest> request( 7939 scoped_ptr<URLRequest> request(context.CreateRequest(
7951 context.CreateRequest(test_server.GetURL("ssl-session-cache"), 7940 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &delegate));
7952 DEFAULT_PRIORITY,
7953 &delegate,
7954 NULL));
7955 request->Start(); 7941 request->Start();
7956 7942
7957 base::RunLoop().Run(); 7943 base::RunLoop().Run();
7958 7944
7959 EXPECT_EQ(1, delegate.response_started_count()); 7945 EXPECT_EQ(1, delegate.response_started_count());
7960 EXPECT_NE(0, delegate.bytes_received()); 7946 EXPECT_NE(0, delegate.bytes_received());
7961 EXPECT_EQ(SSL_CONNECTION_VERSION_SSL3, SSLConnectionStatusToVersion( 7947 EXPECT_EQ(SSL_CONNECTION_VERSION_SSL3, SSLConnectionStatusToVersion(
7962 request->ssl_info().connection_status)); 7948 request->ssl_info().connection_status));
7963 EXPECT_TRUE(request->ssl_info().connection_status & 7949 EXPECT_TRUE(request->ssl_info().connection_status &
7964 SSL_CONNECTION_VERSION_FALLBACK); 7950 SSL_CONNECTION_VERSION_FALLBACK);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
8015 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 8001 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
8016 ASSERT_TRUE(test_server.Start()); 8002 ASSERT_TRUE(test_server.Start());
8017 8003
8018 SSLClientSocket::ClearSessionCache(); 8004 SSLClientSocket::ClearSessionCache();
8019 8005
8020 // Simulate the certificate being expired and attempt a connection. 8006 // Simulate the certificate being expired and attempt a connection.
8021 cert_verifier_.set_default_result(ERR_CERT_DATE_INVALID); 8007 cert_verifier_.set_default_result(ERR_CERT_DATE_INVALID);
8022 { 8008 {
8023 TestDelegate d; 8009 TestDelegate d;
8024 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8010 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8025 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); 8011 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d));
8026 8012
8027 r->Start(); 8013 r->Start();
8028 EXPECT_TRUE(r->is_pending()); 8014 EXPECT_TRUE(r->is_pending());
8029 8015
8030 base::RunLoop().Run(); 8016 base::RunLoop().Run();
8031 8017
8032 EXPECT_EQ(1, d.response_started_count()); 8018 EXPECT_EQ(1, d.response_started_count());
8033 } 8019 }
8034 8020
8035 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> 8021 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())->
8036 CloseAllConnections(); 8022 CloseAllConnections();
8037 8023
8038 // Now change the certificate to be acceptable (so that the response is 8024 // Now change the certificate to be acceptable (so that the response is
8039 // loaded), and ensure that no session id is presented to the peer. 8025 // loaded), and ensure that no session id is presented to the peer.
8040 cert_verifier_.set_default_result(OK); 8026 cert_verifier_.set_default_result(OK);
8041 { 8027 {
8042 TestDelegate d; 8028 TestDelegate d;
8043 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8029 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8044 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, NULL)); 8030 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d));
8045 8031
8046 r->Start(); 8032 r->Start();
8047 EXPECT_TRUE(r->is_pending()); 8033 EXPECT_TRUE(r->is_pending());
8048 8034
8049 base::RunLoop().Run(); 8035 base::RunLoop().Run();
8050 8036
8051 // The response will look like; 8037 // The response will look like;
8052 // insert abc 8038 // insert abc
8053 // insert xyz 8039 // insert xyz
8054 // 8040 //
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
8116 *out_cert_status = 0; 8102 *out_cert_status = 0;
8117 SpawnedTestServer test_server( 8103 SpawnedTestServer test_server(
8118 SpawnedTestServer::TYPE_HTTPS, 8104 SpawnedTestServer::TYPE_HTTPS,
8119 ssl_options, 8105 ssl_options,
8120 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); 8106 base::FilePath(FILE_PATH_LITERAL("net/data/ssl")));
8121 ASSERT_TRUE(test_server.Start()); 8107 ASSERT_TRUE(test_server.Start());
8122 8108
8123 TestDelegate d; 8109 TestDelegate d;
8124 d.set_allow_certificate_errors(true); 8110 d.set_allow_certificate_errors(true);
8125 scoped_ptr<URLRequest> r(context_.CreateRequest( 8111 scoped_ptr<URLRequest> r(context_.CreateRequest(
8126 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d, NULL)); 8112 test_server.GetURL(std::string()), DEFAULT_PRIORITY, &d));
8127 r->Start(); 8113 r->Start();
8128 8114
8129 base::RunLoop().Run(); 8115 base::RunLoop().Run();
8130 8116
8131 EXPECT_EQ(1, d.response_started_count()); 8117 EXPECT_EQ(1, d.response_started_count());
8132 *out_cert_status = r->ssl_info().cert_status; 8118 *out_cert_status = r->ssl_info().cert_status;
8133 } 8119 }
8134 8120
8135 ~HTTPSOCSPTest() override { 8121 ~HTTPSOCSPTest() override {
8136 #if defined(USE_NSS) || defined(OS_IOS) 8122 #if defined(USE_NSS) || defined(OS_IOS)
(...skipping 494 matching lines...) Expand 10 before | Expand all | Expand 10 after
8631 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); 8617 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver());
8632 8618
8633 GURL url("ftp://127.0.0.1:7"); 8619 GURL url("ftp://127.0.0.1:7");
8634 job_factory.SetProtocolHandler( 8620 job_factory.SetProtocolHandler(
8635 "ftp", 8621 "ftp",
8636 new FtpProtocolHandler(&ftp_transaction_factory)); 8622 new FtpProtocolHandler(&ftp_transaction_factory));
8637 default_context_.set_job_factory(&job_factory); 8623 default_context_.set_job_factory(&job_factory);
8638 8624
8639 TestDelegate d; 8625 TestDelegate d;
8640 { 8626 {
8641 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8627 scoped_ptr<URLRequest> r(
8642 url, DEFAULT_PRIORITY, &d, NULL)); 8628 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d));
8643 r->Start(); 8629 r->Start();
8644 EXPECT_TRUE(r->is_pending()); 8630 EXPECT_TRUE(r->is_pending());
8645 8631
8646 base::RunLoop().Run(); 8632 base::RunLoop().Run();
8647 8633
8648 EXPECT_FALSE(r->is_pending()); 8634 EXPECT_FALSE(r->is_pending());
8649 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); 8635 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status());
8650 EXPECT_EQ(ERR_UNSAFE_PORT, r->status().error()); 8636 EXPECT_EQ(ERR_UNSAFE_PORT, r->status().error());
8651 } 8637 }
8652 } 8638 }
8653 8639
8654 // Flaky, see http://crbug.com/25045. 8640 // Flaky, see http://crbug.com/25045.
8655 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { 8641 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) {
8656 ASSERT_TRUE(test_server_.Start()); 8642 ASSERT_TRUE(test_server_.Start());
8657 8643
8658 TestDelegate d; 8644 TestDelegate d;
8659 { 8645 {
8660 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8646 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8661 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d, NULL)); 8647 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d));
8662 r->Start(); 8648 r->Start();
8663 EXPECT_TRUE(r->is_pending()); 8649 EXPECT_TRUE(r->is_pending());
8664 8650
8665 base::RunLoop().Run(); 8651 base::RunLoop().Run();
8666 8652
8667 EXPECT_FALSE(r->is_pending()); 8653 EXPECT_FALSE(r->is_pending());
8668 EXPECT_EQ(1, d.response_started_count()); 8654 EXPECT_EQ(1, d.response_started_count());
8669 EXPECT_FALSE(d.received_data_before_response()); 8655 EXPECT_FALSE(d.received_data_before_response());
8670 EXPECT_LT(0, d.bytes_received()); 8656 EXPECT_LT(0, d.bytes_received());
8671 EXPECT_EQ(test_server_.host_port_pair().host(), 8657 EXPECT_EQ(test_server_.host_port_pair().host(),
8672 r->GetSocketAddress().host()); 8658 r->GetSocketAddress().host());
8673 EXPECT_EQ(test_server_.host_port_pair().port(), 8659 EXPECT_EQ(test_server_.host_port_pair().port(),
8674 r->GetSocketAddress().port()); 8660 r->GetSocketAddress().port());
8675 } 8661 }
8676 } 8662 }
8677 8663
8678 // Flaky, see http://crbug.com/25045. 8664 // Flaky, see http://crbug.com/25045.
8679 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { 8665 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) {
8680 ASSERT_TRUE(test_server_.Start()); 8666 ASSERT_TRUE(test_server_.Start());
8681 8667
8682 base::FilePath app_path; 8668 base::FilePath app_path;
8683 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 8669 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8684 app_path = app_path.AppendASCII("LICENSE"); 8670 app_path = app_path.AppendASCII("LICENSE");
8685 TestDelegate d; 8671 TestDelegate d;
8686 { 8672 {
8687 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8673 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8688 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, &d, NULL)); 8674 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, &d));
8689 r->Start(); 8675 r->Start();
8690 EXPECT_TRUE(r->is_pending()); 8676 EXPECT_TRUE(r->is_pending());
8691 8677
8692 base::RunLoop().Run(); 8678 base::RunLoop().Run();
8693 8679
8694 int64 file_size = 0; 8680 int64 file_size = 0;
8695 base::GetFileSize(app_path, &file_size); 8681 base::GetFileSize(app_path, &file_size);
8696 8682
8697 EXPECT_FALSE(r->is_pending()); 8683 EXPECT_FALSE(r->is_pending());
8698 EXPECT_EQ(1, d.response_started_count()); 8684 EXPECT_EQ(1, d.response_started_count());
(...skipping 10 matching lines...) Expand all
8709 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { 8695 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) {
8710 ASSERT_TRUE(test_server_.Start()); 8696 ASSERT_TRUE(test_server_.Start());
8711 8697
8712 base::FilePath app_path; 8698 base::FilePath app_path;
8713 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 8699 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8714 app_path = app_path.AppendASCII("LICENSE"); 8700 app_path = app_path.AppendASCII("LICENSE");
8715 TestDelegate d; 8701 TestDelegate d;
8716 { 8702 {
8717 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8703 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8718 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), 8704 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"),
8719 DEFAULT_PRIORITY, &d, NULL)); 8705 DEFAULT_PRIORITY, &d));
8720 r->Start(); 8706 r->Start();
8721 EXPECT_TRUE(r->is_pending()); 8707 EXPECT_TRUE(r->is_pending());
8722 8708
8723 base::RunLoop().Run(); 8709 base::RunLoop().Run();
8724 8710
8725 int64 file_size = 0; 8711 int64 file_size = 0;
8726 base::GetFileSize(app_path, &file_size); 8712 base::GetFileSize(app_path, &file_size);
8727 8713
8728 EXPECT_FALSE(r->is_pending()); 8714 EXPECT_FALSE(r->is_pending());
8729 EXPECT_EQ(test_server_.host_port_pair().host(), 8715 EXPECT_EQ(test_server_.host_port_pair().host(),
(...skipping 15 matching lines...) Expand all
8745 ASSERT_TRUE(test_server_.Start()); 8731 ASSERT_TRUE(test_server_.Start());
8746 8732
8747 base::FilePath app_path; 8733 base::FilePath app_path;
8748 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 8734 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8749 app_path = app_path.AppendASCII("LICENSE"); 8735 app_path = app_path.AppendASCII("LICENSE");
8750 TestDelegate d; 8736 TestDelegate d;
8751 { 8737 {
8752 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8738 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8753 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", 8739 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome",
8754 "wrong_password"), 8740 "wrong_password"),
8755 DEFAULT_PRIORITY, &d, NULL)); 8741 DEFAULT_PRIORITY, &d));
8756 r->Start(); 8742 r->Start();
8757 EXPECT_TRUE(r->is_pending()); 8743 EXPECT_TRUE(r->is_pending());
8758 8744
8759 base::RunLoop().Run(); 8745 base::RunLoop().Run();
8760 8746
8761 int64 file_size = 0; 8747 int64 file_size = 0;
8762 base::GetFileSize(app_path, &file_size); 8748 base::GetFileSize(app_path, &file_size);
8763 8749
8764 EXPECT_FALSE(r->is_pending()); 8750 EXPECT_FALSE(r->is_pending());
8765 EXPECT_EQ(1, d.response_started_count()); 8751 EXPECT_EQ(1, d.response_started_count());
(...skipping 10 matching lines...) Expand all
8776 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 8762 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8777 app_path = app_path.AppendASCII("LICENSE"); 8763 app_path = app_path.AppendASCII("LICENSE");
8778 TestDelegate d; 8764 TestDelegate d;
8779 // Set correct login credentials. The delegate will be asked for them when 8765 // Set correct login credentials. The delegate will be asked for them when
8780 // the initial login with wrong credentials will fail. 8766 // the initial login with wrong credentials will fail.
8781 d.set_credentials(AuthCredentials(kChrome, kChrome)); 8767 d.set_credentials(AuthCredentials(kChrome, kChrome));
8782 { 8768 {
8783 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8769 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8784 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", 8770 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome",
8785 "wrong_password"), 8771 "wrong_password"),
8786 DEFAULT_PRIORITY, &d, NULL)); 8772 DEFAULT_PRIORITY, &d));
8787 r->Start(); 8773 r->Start();
8788 EXPECT_TRUE(r->is_pending()); 8774 EXPECT_TRUE(r->is_pending());
8789 8775
8790 base::RunLoop().Run(); 8776 base::RunLoop().Run();
8791 8777
8792 int64 file_size = 0; 8778 int64 file_size = 0;
8793 base::GetFileSize(app_path, &file_size); 8779 base::GetFileSize(app_path, &file_size);
8794 8780
8795 EXPECT_FALSE(r->is_pending()); 8781 EXPECT_FALSE(r->is_pending());
8796 EXPECT_EQ(1, d.response_started_count()); 8782 EXPECT_EQ(1, d.response_started_count());
8797 EXPECT_FALSE(d.received_data_before_response()); 8783 EXPECT_FALSE(d.received_data_before_response());
8798 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 8784 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
8799 } 8785 }
8800 } 8786 }
8801 8787
8802 // Flaky, see http://crbug.com/25045. 8788 // Flaky, see http://crbug.com/25045.
8803 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { 8789 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) {
8804 ASSERT_TRUE(test_server_.Start()); 8790 ASSERT_TRUE(test_server_.Start());
8805 8791
8806 base::FilePath app_path; 8792 base::FilePath app_path;
8807 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 8793 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8808 app_path = app_path.AppendASCII("LICENSE"); 8794 app_path = app_path.AppendASCII("LICENSE");
8809 TestDelegate d; 8795 TestDelegate d;
8810 { 8796 {
8811 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8797 scoped_ptr<URLRequest> r(
8812 test_server_.GetURLWithUserAndPassword("/LICENSE", "wrong_user", 8798 default_context_.CreateRequest(test_server_.GetURLWithUserAndPassword(
8813 "chrome"), 8799 "/LICENSE", "wrong_user", "chrome"),
8814 DEFAULT_PRIORITY, &d, NULL)); 8800 DEFAULT_PRIORITY, &d));
8815 r->Start(); 8801 r->Start();
8816 EXPECT_TRUE(r->is_pending()); 8802 EXPECT_TRUE(r->is_pending());
8817 8803
8818 base::RunLoop().Run(); 8804 base::RunLoop().Run();
8819 8805
8820 int64 file_size = 0; 8806 int64 file_size = 0;
8821 base::GetFileSize(app_path, &file_size); 8807 base::GetFileSize(app_path, &file_size);
8822 8808
8823 EXPECT_FALSE(r->is_pending()); 8809 EXPECT_FALSE(r->is_pending());
8824 EXPECT_EQ(1, d.response_started_count()); 8810 EXPECT_EQ(1, d.response_started_count());
8825 EXPECT_FALSE(d.received_data_before_response()); 8811 EXPECT_FALSE(d.received_data_before_response());
8826 EXPECT_EQ(d.bytes_received(), 0); 8812 EXPECT_EQ(d.bytes_received(), 0);
8827 } 8813 }
8828 } 8814 }
8829 8815
8830 // Flaky, see http://crbug.com/25045. 8816 // Flaky, see http://crbug.com/25045.
8831 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { 8817 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) {
8832 ASSERT_TRUE(test_server_.Start()); 8818 ASSERT_TRUE(test_server_.Start());
8833 8819
8834 base::FilePath app_path; 8820 base::FilePath app_path;
8835 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 8821 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8836 app_path = app_path.AppendASCII("LICENSE"); 8822 app_path = app_path.AppendASCII("LICENSE");
8837 TestDelegate d; 8823 TestDelegate d;
8838 // Set correct login credentials. The delegate will be asked for them when 8824 // Set correct login credentials. The delegate will be asked for them when
8839 // the initial login with wrong credentials will fail. 8825 // the initial login with wrong credentials will fail.
8840 d.set_credentials(AuthCredentials(kChrome, kChrome)); 8826 d.set_credentials(AuthCredentials(kChrome, kChrome));
8841 { 8827 {
8842 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8828 scoped_ptr<URLRequest> r(
8843 test_server_.GetURLWithUserAndPassword("/LICENSE", "wrong_user", 8829 default_context_.CreateRequest(test_server_.GetURLWithUserAndPassword(
8844 "chrome"), 8830 "/LICENSE", "wrong_user", "chrome"),
8845 DEFAULT_PRIORITY, &d, NULL)); 8831 DEFAULT_PRIORITY, &d));
8846 r->Start(); 8832 r->Start();
8847 EXPECT_TRUE(r->is_pending()); 8833 EXPECT_TRUE(r->is_pending());
8848 8834
8849 base::RunLoop().Run(); 8835 base::RunLoop().Run();
8850 8836
8851 int64 file_size = 0; 8837 int64 file_size = 0;
8852 base::GetFileSize(app_path, &file_size); 8838 base::GetFileSize(app_path, &file_size);
8853 8839
8854 EXPECT_FALSE(r->is_pending()); 8840 EXPECT_FALSE(r->is_pending());
8855 EXPECT_EQ(1, d.response_started_count()); 8841 EXPECT_EQ(1, d.response_started_count());
8856 EXPECT_FALSE(d.received_data_before_response()); 8842 EXPECT_FALSE(d.received_data_before_response());
8857 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); 8843 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size));
8858 } 8844 }
8859 } 8845 }
8860 8846
8861 // Flaky, see http://crbug.com/25045. 8847 // Flaky, see http://crbug.com/25045.
8862 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { 8848 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) {
8863 ASSERT_TRUE(test_server_.Start()); 8849 ASSERT_TRUE(test_server_.Start());
8864 8850
8865 base::FilePath app_path; 8851 base::FilePath app_path;
8866 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); 8852 PathService::Get(base::DIR_SOURCE_ROOT, &app_path);
8867 app_path = app_path.AppendASCII("LICENSE"); 8853 app_path = app_path.AppendASCII("LICENSE");
8868 8854
8869 scoped_ptr<TestDelegate> d(new TestDelegate); 8855 scoped_ptr<TestDelegate> d(new TestDelegate);
8870 { 8856 {
8871 // Pass correct login identity in the URL. 8857 // Pass correct login identity in the URL.
8872 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8858 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8873 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), 8859 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"),
8874 DEFAULT_PRIORITY, d.get(), NULL)); 8860 DEFAULT_PRIORITY, d.get()));
8875 r->Start(); 8861 r->Start();
8876 EXPECT_TRUE(r->is_pending()); 8862 EXPECT_TRUE(r->is_pending());
8877 8863
8878 base::RunLoop().Run(); 8864 base::RunLoop().Run();
8879 8865
8880 int64 file_size = 0; 8866 int64 file_size = 0;
8881 base::GetFileSize(app_path, &file_size); 8867 base::GetFileSize(app_path, &file_size);
8882 8868
8883 EXPECT_FALSE(r->is_pending()); 8869 EXPECT_FALSE(r->is_pending());
8884 EXPECT_EQ(1, d->response_started_count()); 8870 EXPECT_EQ(1, d->response_started_count());
8885 EXPECT_FALSE(d->received_data_before_response()); 8871 EXPECT_FALSE(d->received_data_before_response());
8886 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 8872 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8887 } 8873 }
8888 8874
8889 d.reset(new TestDelegate); 8875 d.reset(new TestDelegate);
8890 { 8876 {
8891 // This request should use cached identity from previous request. 8877 // This request should use cached identity from previous request.
8892 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8878 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8893 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get(), NULL)); 8879 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get()));
8894 r->Start(); 8880 r->Start();
8895 EXPECT_TRUE(r->is_pending()); 8881 EXPECT_TRUE(r->is_pending());
8896 8882
8897 base::RunLoop().Run(); 8883 base::RunLoop().Run();
8898 8884
8899 int64 file_size = 0; 8885 int64 file_size = 0;
8900 base::GetFileSize(app_path, &file_size); 8886 base::GetFileSize(app_path, &file_size);
8901 8887
8902 EXPECT_FALSE(r->is_pending()); 8888 EXPECT_FALSE(r->is_pending());
8903 EXPECT_EQ(1, d->response_started_count()); 8889 EXPECT_EQ(1, d->response_started_count());
(...skipping 11 matching lines...) Expand all
8915 app_path = app_path.AppendASCII("LICENSE"); 8901 app_path = app_path.AppendASCII("LICENSE");
8916 8902
8917 scoped_ptr<TestDelegate> d(new TestDelegate); 8903 scoped_ptr<TestDelegate> d(new TestDelegate);
8918 // Set correct login credentials. The delegate will be asked for them when 8904 // Set correct login credentials. The delegate will be asked for them when
8919 // the initial login with wrong credentials will fail. 8905 // the initial login with wrong credentials will fail.
8920 d->set_credentials(AuthCredentials(kChrome, kChrome)); 8906 d->set_credentials(AuthCredentials(kChrome, kChrome));
8921 { 8907 {
8922 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8908 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8923 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", 8909 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome",
8924 "wrong_password"), 8910 "wrong_password"),
8925 DEFAULT_PRIORITY, d.get(), NULL)); 8911 DEFAULT_PRIORITY, d.get()));
8926 r->Start(); 8912 r->Start();
8927 EXPECT_TRUE(r->is_pending()); 8913 EXPECT_TRUE(r->is_pending());
8928 8914
8929 base::RunLoop().Run(); 8915 base::RunLoop().Run();
8930 8916
8931 int64 file_size = 0; 8917 int64 file_size = 0;
8932 base::GetFileSize(app_path, &file_size); 8918 base::GetFileSize(app_path, &file_size);
8933 8919
8934 EXPECT_FALSE(r->is_pending()); 8920 EXPECT_FALSE(r->is_pending());
8935 EXPECT_EQ(1, d->response_started_count()); 8921 EXPECT_EQ(1, d->response_started_count());
8936 EXPECT_FALSE(d->received_data_before_response()); 8922 EXPECT_FALSE(d->received_data_before_response());
8937 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 8923 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8938 } 8924 }
8939 8925
8940 // Use a new delegate without explicit credentials. The cached ones should be 8926 // Use a new delegate without explicit credentials. The cached ones should be
8941 // used. 8927 // used.
8942 d.reset(new TestDelegate); 8928 d.reset(new TestDelegate);
8943 { 8929 {
8944 // Don't pass wrong credentials in the URL, they would override valid cached 8930 // Don't pass wrong credentials in the URL, they would override valid cached
8945 // ones. 8931 // ones.
8946 scoped_ptr<URLRequest> r(default_context_.CreateRequest( 8932 scoped_ptr<URLRequest> r(default_context_.CreateRequest(
8947 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get(), NULL)); 8933 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get()));
8948 r->Start(); 8934 r->Start();
8949 EXPECT_TRUE(r->is_pending()); 8935 EXPECT_TRUE(r->is_pending());
8950 8936
8951 base::RunLoop().Run(); 8937 base::RunLoop().Run();
8952 8938
8953 int64 file_size = 0; 8939 int64 file_size = 0;
8954 base::GetFileSize(app_path, &file_size); 8940 base::GetFileSize(app_path, &file_size);
8955 8941
8956 EXPECT_FALSE(r->is_pending()); 8942 EXPECT_FALSE(r->is_pending());
8957 EXPECT_EQ(1, d->response_started_count()); 8943 EXPECT_EQ(1, d->response_started_count());
8958 EXPECT_FALSE(d->received_data_before_response()); 8944 EXPECT_FALSE(d->received_data_before_response());
8959 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 8945 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
8960 } 8946 }
8961 } 8947 }
8962 #endif // !defined(DISABLE_FTP_SUPPORT) 8948 #endif // !defined(DISABLE_FTP_SUPPORT)
8963 8949
8964 } // namespace net 8950 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698