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

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

Powered by Google App Engine
This is Rietveld 408576698