| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <memory> | 5 #include <memory> |
| 6 #include <utility> | 6 #include <utility> |
| 7 | 7 |
| 8 #include "base/memory/ptr_util.h" | 8 #include "base/memory/ptr_util.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "build/build_config.h" | 10 #include "build/build_config.h" |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 101 #include "net/ssl/ssl_server_config.h" | 101 #include "net/ssl/ssl_server_config.h" |
| 102 #include "net/ssl/token_binding.h" | 102 #include "net/ssl/token_binding.h" |
| 103 #include "net/test/cert_test_util.h" | 103 #include "net/test/cert_test_util.h" |
| 104 #include "net/test/embedded_test_server/embedded_test_server.h" | 104 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 105 #include "net/test/embedded_test_server/http_request.h" | 105 #include "net/test/embedded_test_server/http_request.h" |
| 106 #include "net/test/embedded_test_server/http_response.h" | 106 #include "net/test/embedded_test_server/http_response.h" |
| 107 #include "net/test/gtest_util.h" | 107 #include "net/test/gtest_util.h" |
| 108 #include "net/test/spawned_test_server/spawned_test_server.h" | 108 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 109 #include "net/test/test_data_directory.h" | 109 #include "net/test/test_data_directory.h" |
| 110 #include "net/test/url_request/url_request_failed_job.h" | 110 #include "net/test/url_request/url_request_failed_job.h" |
| 111 #include "net/traffic_annotation/network_traffic_annotation_test_helper.h" |
| 111 #include "net/url_request/data_protocol_handler.h" | 112 #include "net/url_request/data_protocol_handler.h" |
| 112 #include "net/url_request/static_http_user_agent_settings.h" | 113 #include "net/url_request/static_http_user_agent_settings.h" |
| 113 #include "net/url_request/url_request.h" | 114 #include "net/url_request/url_request.h" |
| 114 #include "net/url_request/url_request_filter.h" | 115 #include "net/url_request/url_request_filter.h" |
| 115 #include "net/url_request/url_request_http_job.h" | 116 #include "net/url_request/url_request_http_job.h" |
| 116 #include "net/url_request/url_request_intercepting_job_factory.h" | 117 #include "net/url_request/url_request_intercepting_job_factory.h" |
| 117 #include "net/url_request/url_request_interceptor.h" | 118 #include "net/url_request/url_request_interceptor.h" |
| 118 #include "net/url_request/url_request_job_factory_impl.h" | 119 #include "net/url_request/url_request_job_factory_impl.h" |
| 119 #include "net/url_request/url_request_redirect_job.h" | 120 #include "net/url_request/url_request_redirect_job.h" |
| 120 #include "net/url_request/url_request_test_job.h" | 121 #include "net/url_request/url_request_test_job.h" |
| (...skipping 713 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 834 TestNetLog net_log_; | 835 TestNetLog net_log_; |
| 835 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. | 836 TestNetworkDelegate default_network_delegate_; // Must outlive URLRequest. |
| 836 URLRequestJobFactoryImpl* job_factory_impl_; | 837 URLRequestJobFactoryImpl* job_factory_impl_; |
| 837 std::unique_ptr<URLRequestJobFactory> job_factory_; | 838 std::unique_ptr<URLRequestJobFactory> job_factory_; |
| 838 TestURLRequestContext default_context_; | 839 TestURLRequestContext default_context_; |
| 839 }; | 840 }; |
| 840 | 841 |
| 841 TEST_F(URLRequestTest, AboutBlankTest) { | 842 TEST_F(URLRequestTest, AboutBlankTest) { |
| 842 TestDelegate d; | 843 TestDelegate d; |
| 843 { | 844 { |
| 844 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 845 std::unique_ptr<URLRequest> r( |
| 845 GURL("about:blank"), DEFAULT_PRIORITY, &d)); | 846 default_context_.CreateRequest(GURL("about:blank"), DEFAULT_PRIORITY, |
| 847 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 846 | 848 |
| 847 r->Start(); | 849 r->Start(); |
| 848 EXPECT_TRUE(r->is_pending()); | 850 EXPECT_TRUE(r->is_pending()); |
| 849 | 851 |
| 850 base::RunLoop().Run(); | 852 base::RunLoop().Run(); |
| 851 | 853 |
| 852 EXPECT_TRUE(!r->is_pending()); | 854 EXPECT_TRUE(!r->is_pending()); |
| 853 EXPECT_FALSE(d.received_data_before_response()); | 855 EXPECT_FALSE(d.received_data_before_response()); |
| 854 EXPECT_EQ(d.bytes_received(), 0); | 856 EXPECT_EQ(d.bytes_received(), 0); |
| 855 EXPECT_EQ("", r->GetSocketAddress().host()); | 857 EXPECT_EQ("", r->GetSocketAddress().host()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 878 "D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTbxXX1T5xsV9tm9r4TQwHLiZw/pdDZJ" | 880 "D3eOjtBbNUEIZYyqsvj4V4wY92eNJ4IoyhTbxXX1T5xsV9tm9r4TQwHLiZw/pdDZJ" |
| 879 "ea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5MrVvMzNaI3+ERHfrFzPKQukrQ" | 881 "ea8TKmsmR/K0uLh/GwnCHghTja6lPhphezPfO5/5MrVvMzNaI3+ERHfrFzPKQukrQ" |
| 880 "GI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gVMd6q5c8GdosynKmSeRuGz" | 882 "GI4d/3EFD/3E2mVNYvi4at7CXWREaxZGD+3hg28zD3gVMd6q5c8GdosynKmSeRuGz" |
| 881 "pjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq/uxxZKzNiZFGD0wRC" | 883 "pjyl1/9UDGtPR5HeaKT8Wjo17WXk579BXVUhN64ehF9fhRtq/uxxZKzNiZFGD0wRC" |
| 882 "3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7FUx1qLnV7MGF40" | 884 "3NFROZ5mwIPL/96K/rKMMLrIzF9uhHr+/sYH7DAbwlgC4J+R2Z7FUx1qLnV7MGF40" |
| 883 "smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufBJbsysjjW4" | 885 "smVSoJ/jvHRfYhQeUJd/SnYtGWhPHR0Sz+GE2F2yth0B36Vcz2KpnufBJbsysjjW4" |
| 884 "kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJMnlm2O" | 886 "kblBUiIjiURUWqJY65zxbnTy57GQyH58zgy0QBtTQv5gH15XMdKkYu+TGaJMnlm2O" |
| 885 "34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfmm" | 887 "34uI4b9tflqp1+QEFGzoW/ulmcofcpkZCYJhDfSpme7QcrHa+Xfji8paEQkTkSfmm" |
| 886 "oRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV" | 888 "oRWRNZr/F1KfVMjW+IKEnv2FwZfKdzt0BQR6lClcZR0EfEXEfv/G6W9iLiIyCoReV" |
| 887 "5EnhORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), | 889 "5EnhORIBHx+ufPj/gLB/zGI/G4Bk0AAAAASUVORK5CYII="), |
| 888 DEFAULT_PRIORITY, &d)); | 890 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 889 | 891 |
| 890 r->Start(); | 892 r->Start(); |
| 891 EXPECT_TRUE(r->is_pending()); | 893 EXPECT_TRUE(r->is_pending()); |
| 892 | 894 |
| 893 base::RunLoop().Run(); | 895 base::RunLoop().Run(); |
| 894 | 896 |
| 895 EXPECT_TRUE(!r->is_pending()); | 897 EXPECT_TRUE(!r->is_pending()); |
| 896 EXPECT_FALSE(d.received_data_before_response()); | 898 EXPECT_FALSE(d.received_data_before_response()); |
| 897 EXPECT_EQ(d.bytes_received(), 911); | 899 EXPECT_EQ(d.bytes_received(), 911); |
| 898 EXPECT_EQ("", r->GetSocketAddress().host()); | 900 EXPECT_EQ("", r->GetSocketAddress().host()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 912 // Use /etc/hosts instead | 914 // Use /etc/hosts instead |
| 913 app_path = base::FilePath("/etc/hosts"); | 915 app_path = base::FilePath("/etc/hosts"); |
| 914 #else | 916 #else |
| 915 PathService::Get(base::FILE_EXE, &app_path); | 917 PathService::Get(base::FILE_EXE, &app_path); |
| 916 #endif // OS_ANDROID | 918 #endif // OS_ANDROID |
| 917 | 919 |
| 918 GURL app_url = FilePathToFileURL(app_path); | 920 GURL app_url = FilePathToFileURL(app_path); |
| 919 | 921 |
| 920 TestDelegate d; | 922 TestDelegate d; |
| 921 { | 923 { |
| 922 std::unique_ptr<URLRequest> r( | 924 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 923 default_context_.CreateRequest(app_url, DEFAULT_PRIORITY, &d)); | 925 app_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 924 | 926 |
| 925 r->Start(); | 927 r->Start(); |
| 926 EXPECT_TRUE(r->is_pending()); | 928 EXPECT_TRUE(r->is_pending()); |
| 927 | 929 |
| 928 base::RunLoop().Run(); | 930 base::RunLoop().Run(); |
| 929 | 931 |
| 930 int64_t file_size = -1; | 932 int64_t file_size = -1; |
| 931 EXPECT_TRUE(base::GetFileSize(app_path, &file_size)); | 933 EXPECT_TRUE(base::GetFileSize(app_path, &file_size)); |
| 932 | 934 |
| 933 EXPECT_TRUE(!r->is_pending()); | 935 EXPECT_TRUE(!r->is_pending()); |
| 934 EXPECT_EQ(1, d.response_started_count()); | 936 EXPECT_EQ(1, d.response_started_count()); |
| 935 EXPECT_FALSE(d.received_data_before_response()); | 937 EXPECT_FALSE(d.received_data_before_response()); |
| 936 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 938 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); |
| 937 EXPECT_EQ("", r->GetSocketAddress().host()); | 939 EXPECT_EQ("", r->GetSocketAddress().host()); |
| 938 EXPECT_EQ(0, r->GetSocketAddress().port()); | 940 EXPECT_EQ(0, r->GetSocketAddress().port()); |
| 939 | 941 |
| 940 HttpRequestHeaders headers; | 942 HttpRequestHeaders headers; |
| 941 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); | 943 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); |
| 942 } | 944 } |
| 943 } | 945 } |
| 944 | 946 |
| 945 TEST_F(URLRequestTest, FileTestCancel) { | 947 TEST_F(URLRequestTest, FileTestCancel) { |
| 946 base::FilePath app_path; | 948 base::FilePath app_path; |
| 947 PathService::Get(base::FILE_EXE, &app_path); | 949 PathService::Get(base::FILE_EXE, &app_path); |
| 948 GURL app_url = FilePathToFileURL(app_path); | 950 GURL app_url = FilePathToFileURL(app_path); |
| 949 | 951 |
| 950 TestDelegate d; | 952 TestDelegate d; |
| 951 { | 953 { |
| 952 std::unique_ptr<URLRequest> r( | 954 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 953 default_context_.CreateRequest(app_url, DEFAULT_PRIORITY, &d)); | 955 app_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 954 | 956 |
| 955 r->Start(); | 957 r->Start(); |
| 956 EXPECT_TRUE(r->is_pending()); | 958 EXPECT_TRUE(r->is_pending()); |
| 957 r->Cancel(); | 959 r->Cancel(); |
| 958 } | 960 } |
| 959 // Async cancellation should be safe even when URLRequest has been already | 961 // Async cancellation should be safe even when URLRequest has been already |
| 960 // destroyed. | 962 // destroyed. |
| 961 base::RunLoop().RunUntilIdle(); | 963 base::RunLoop().RunUntilIdle(); |
| 962 } | 964 } |
| 963 | 965 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 976 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 978 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 977 | 979 |
| 978 const size_t first_byte_position = 500; | 980 const size_t first_byte_position = 500; |
| 979 const size_t last_byte_position = buffer_size - first_byte_position; | 981 const size_t last_byte_position = buffer_size - first_byte_position; |
| 980 const size_t content_length = last_byte_position - first_byte_position + 1; | 982 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 981 std::string partial_buffer_string(buffer.get() + first_byte_position, | 983 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 982 buffer.get() + last_byte_position + 1); | 984 buffer.get() + last_byte_position + 1); |
| 983 | 985 |
| 984 TestDelegate d; | 986 TestDelegate d; |
| 985 { | 987 { |
| 986 std::unique_ptr<URLRequest> r( | 988 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 987 default_context_.CreateRequest(temp_url, DEFAULT_PRIORITY, &d)); | 989 temp_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 988 | 990 |
| 989 HttpRequestHeaders headers; | 991 HttpRequestHeaders headers; |
| 990 headers.SetHeader( | 992 headers.SetHeader( |
| 991 HttpRequestHeaders::kRange, | 993 HttpRequestHeaders::kRange, |
| 992 HttpByteRange::Bounded( | 994 HttpByteRange::Bounded( |
| 993 first_byte_position, last_byte_position).GetHeaderValue()); | 995 first_byte_position, last_byte_position).GetHeaderValue()); |
| 994 r->SetExtraRequestHeaders(headers); | 996 r->SetExtraRequestHeaders(headers); |
| 995 r->Start(); | 997 r->Start(); |
| 996 EXPECT_TRUE(r->is_pending()); | 998 EXPECT_TRUE(r->is_pending()); |
| 997 | 999 |
| (...skipping 23 matching lines...) Expand all Loading... |
| 1021 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 1023 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 1022 | 1024 |
| 1023 const size_t first_byte_position = 500; | 1025 const size_t first_byte_position = 500; |
| 1024 const size_t last_byte_position = buffer_size - 1; | 1026 const size_t last_byte_position = buffer_size - 1; |
| 1025 const size_t content_length = last_byte_position - first_byte_position + 1; | 1027 const size_t content_length = last_byte_position - first_byte_position + 1; |
| 1026 std::string partial_buffer_string(buffer.get() + first_byte_position, | 1028 std::string partial_buffer_string(buffer.get() + first_byte_position, |
| 1027 buffer.get() + last_byte_position + 1); | 1029 buffer.get() + last_byte_position + 1); |
| 1028 | 1030 |
| 1029 TestDelegate d; | 1031 TestDelegate d; |
| 1030 { | 1032 { |
| 1031 std::unique_ptr<URLRequest> r( | 1033 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 1032 default_context_.CreateRequest(temp_url, DEFAULT_PRIORITY, &d)); | 1034 temp_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1033 | 1035 |
| 1034 HttpRequestHeaders headers; | 1036 HttpRequestHeaders headers; |
| 1035 headers.SetHeader(HttpRequestHeaders::kRange, | 1037 headers.SetHeader(HttpRequestHeaders::kRange, |
| 1036 HttpByteRange::RightUnbounded( | 1038 HttpByteRange::RightUnbounded( |
| 1037 first_byte_position).GetHeaderValue()); | 1039 first_byte_position).GetHeaderValue()); |
| 1038 r->SetExtraRequestHeaders(headers); | 1040 r->SetExtraRequestHeaders(headers); |
| 1039 r->Start(); | 1041 r->Start(); |
| 1040 EXPECT_TRUE(r->is_pending()); | 1042 EXPECT_TRUE(r->is_pending()); |
| 1041 | 1043 |
| 1042 base::RunLoop().Run(); | 1044 base::RunLoop().Run(); |
| (...skipping 16 matching lines...) Expand all Loading... |
| 1059 base::FilePath temp_path; | 1061 base::FilePath temp_path; |
| 1060 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); | 1062 EXPECT_TRUE(base::CreateTemporaryFile(&temp_path)); |
| 1061 GURL temp_url = FilePathToFileURL(temp_path); | 1063 GURL temp_url = FilePathToFileURL(temp_path); |
| 1062 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); | 1064 EXPECT_TRUE(base::WriteFile(temp_path, buffer.get(), buffer_size)); |
| 1063 | 1065 |
| 1064 int64_t file_size; | 1066 int64_t file_size; |
| 1065 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); | 1067 EXPECT_TRUE(base::GetFileSize(temp_path, &file_size)); |
| 1066 | 1068 |
| 1067 TestDelegate d; | 1069 TestDelegate d; |
| 1068 { | 1070 { |
| 1069 std::unique_ptr<URLRequest> r( | 1071 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 1070 default_context_.CreateRequest(temp_url, DEFAULT_PRIORITY, &d)); | 1072 temp_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1071 | 1073 |
| 1072 HttpRequestHeaders headers; | 1074 HttpRequestHeaders headers; |
| 1073 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); | 1075 headers.SetHeader(HttpRequestHeaders::kRange, "bytes=0-0,10-200,200-300"); |
| 1074 r->SetExtraRequestHeaders(headers); | 1076 r->SetExtraRequestHeaders(headers); |
| 1075 r->Start(); | 1077 r->Start(); |
| 1076 EXPECT_TRUE(r->is_pending()); | 1078 EXPECT_TRUE(r->is_pending()); |
| 1077 | 1079 |
| 1078 base::RunLoop().Run(); | 1080 base::RunLoop().Run(); |
| 1079 EXPECT_TRUE(d.request_failed()); | 1081 EXPECT_TRUE(d.request_failed()); |
| 1080 } | 1082 } |
| 1081 | 1083 |
| 1082 EXPECT_TRUE(base::DeleteFile(temp_path, false)); | 1084 EXPECT_TRUE(base::DeleteFile(temp_path, false)); |
| 1083 } | 1085 } |
| 1084 | 1086 |
| 1085 TEST_F(URLRequestTest, AllowFileURLs) { | 1087 TEST_F(URLRequestTest, AllowFileURLs) { |
| 1086 base::ScopedTempDir temp_dir; | 1088 base::ScopedTempDir temp_dir; |
| 1087 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 1089 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
| 1088 base::FilePath test_file; | 1090 base::FilePath test_file; |
| 1089 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.GetPath(), &test_file)); | 1091 ASSERT_TRUE(base::CreateTemporaryFileInDir(temp_dir.GetPath(), &test_file)); |
| 1090 std::string test_data("monkey"); | 1092 std::string test_data("monkey"); |
| 1091 base::WriteFile(test_file, test_data.data(), test_data.size()); | 1093 base::WriteFile(test_file, test_data.data(), test_data.size()); |
| 1092 GURL test_file_url = FilePathToFileURL(test_file); | 1094 GURL test_file_url = FilePathToFileURL(test_file); |
| 1093 | 1095 |
| 1094 { | 1096 { |
| 1095 TestDelegate d; | 1097 TestDelegate d; |
| 1096 TestNetworkDelegate network_delegate; | 1098 TestNetworkDelegate network_delegate; |
| 1097 network_delegate.set_can_access_files(true); | 1099 network_delegate.set_can_access_files(true); |
| 1098 default_context_.set_network_delegate(&network_delegate); | 1100 default_context_.set_network_delegate(&network_delegate); |
| 1099 std::unique_ptr<URLRequest> r( | 1101 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 1100 default_context_.CreateRequest(test_file_url, DEFAULT_PRIORITY, &d)); | 1102 test_file_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1101 r->Start(); | 1103 r->Start(); |
| 1102 base::RunLoop().Run(); | 1104 base::RunLoop().Run(); |
| 1103 EXPECT_FALSE(d.request_failed()); | 1105 EXPECT_FALSE(d.request_failed()); |
| 1104 EXPECT_EQ(test_data, d.data_received()); | 1106 EXPECT_EQ(test_data, d.data_received()); |
| 1105 } | 1107 } |
| 1106 | 1108 |
| 1107 { | 1109 { |
| 1108 TestDelegate d; | 1110 TestDelegate d; |
| 1109 TestNetworkDelegate network_delegate; | 1111 TestNetworkDelegate network_delegate; |
| 1110 network_delegate.set_can_access_files(false); | 1112 network_delegate.set_can_access_files(false); |
| 1111 default_context_.set_network_delegate(&network_delegate); | 1113 default_context_.set_network_delegate(&network_delegate); |
| 1112 std::unique_ptr<URLRequest> r( | 1114 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 1113 default_context_.CreateRequest(test_file_url, DEFAULT_PRIORITY, &d)); | 1115 test_file_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1114 r->Start(); | 1116 r->Start(); |
| 1115 base::RunLoop().Run(); | 1117 base::RunLoop().Run(); |
| 1116 EXPECT_TRUE(d.request_failed()); | 1118 EXPECT_TRUE(d.request_failed()); |
| 1117 EXPECT_EQ("", d.data_received()); | 1119 EXPECT_EQ("", d.data_received()); |
| 1118 } | 1120 } |
| 1119 } | 1121 } |
| 1120 | 1122 |
| 1121 | 1123 |
| 1122 TEST_F(URLRequestTest, FileDirCancelTest) { | 1124 TEST_F(URLRequestTest, FileDirCancelTest) { |
| 1123 // Put in mock resource provider. | 1125 // Put in mock resource provider. |
| 1124 NetModule::SetResourceProvider(TestNetResourceProvider); | 1126 NetModule::SetResourceProvider(TestNetResourceProvider); |
| 1125 | 1127 |
| 1126 TestDelegate d; | 1128 TestDelegate d; |
| 1127 { | 1129 { |
| 1128 base::FilePath file_path; | 1130 base::FilePath file_path; |
| 1129 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); | 1131 PathService::Get(base::DIR_SOURCE_ROOT, &file_path); |
| 1130 file_path = file_path.Append(FILE_PATH_LITERAL("net")); | 1132 file_path = file_path.Append(FILE_PATH_LITERAL("net")); |
| 1131 file_path = file_path.Append(FILE_PATH_LITERAL("data")); | 1133 file_path = file_path.Append(FILE_PATH_LITERAL("data")); |
| 1132 | 1134 |
| 1133 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 1135 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1134 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d)); | 1136 FilePathToFileURL(file_path), DEFAULT_PRIORITY, &d, |
| 1137 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1135 req->Start(); | 1138 req->Start(); |
| 1136 EXPECT_TRUE(req->is_pending()); | 1139 EXPECT_TRUE(req->is_pending()); |
| 1137 | 1140 |
| 1138 d.set_cancel_in_received_data_pending(true); | 1141 d.set_cancel_in_received_data_pending(true); |
| 1139 | 1142 |
| 1140 base::RunLoop().Run(); | 1143 base::RunLoop().Run(); |
| 1141 } | 1144 } |
| 1142 | 1145 |
| 1143 // Take out mock resource provider. | 1146 // Take out mock resource provider. |
| 1144 NetModule::SetResourceProvider(NULL); | 1147 NetModule::SetResourceProvider(NULL); |
| 1145 } | 1148 } |
| 1146 | 1149 |
| 1147 TEST_F(URLRequestTest, FileDirOutputSanity) { | 1150 TEST_F(URLRequestTest, FileDirOutputSanity) { |
| 1148 // Verify the general sanity of the the output of the file: | 1151 // Verify the general sanity of the the output of the file: |
| 1149 // directory lister by checking for the output of a known existing | 1152 // directory lister by checking for the output of a known existing |
| 1150 // file. | 1153 // file. |
| 1151 const char sentinel_name[] = "filedir-sentinel"; | 1154 const char sentinel_name[] = "filedir-sentinel"; |
| 1152 | 1155 |
| 1153 base::FilePath path; | 1156 base::FilePath path; |
| 1154 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 1157 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 1155 path = path.Append(kTestFilePath); | 1158 path = path.Append(kTestFilePath); |
| 1156 | 1159 |
| 1157 TestDelegate d; | 1160 TestDelegate d; |
| 1158 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 1161 std::unique_ptr<URLRequest> req( |
| 1159 FilePathToFileURL(path), DEFAULT_PRIORITY, &d)); | 1162 default_context_.CreateRequest(FilePathToFileURL(path), DEFAULT_PRIORITY, |
| 1163 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1160 req->Start(); | 1164 req->Start(); |
| 1161 base::RunLoop().Run(); | 1165 base::RunLoop().Run(); |
| 1162 | 1166 |
| 1163 // Generate entry for the sentinel file. | 1167 // Generate entry for the sentinel file. |
| 1164 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); | 1168 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); |
| 1165 base::File::Info info; | 1169 base::File::Info info; |
| 1166 EXPECT_TRUE(base::GetFileInfo(sentinel_path, &info)); | 1170 EXPECT_TRUE(base::GetFileInfo(sentinel_path, &info)); |
| 1167 EXPECT_GT(info.size, 0); | 1171 EXPECT_GT(info.size, 0); |
| 1168 std::string sentinel_output = GetDirectoryListingEntry( | 1172 std::string sentinel_output = GetDirectoryListingEntry( |
| 1169 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)), | 1173 base::string16(sentinel_name, sentinel_name + strlen(sentinel_name)), |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1183 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { | 1187 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { |
| 1184 // There is an implicit redirect when loading a file path that matches a | 1188 // There is an implicit redirect when loading a file path that matches a |
| 1185 // directory and does not end with a slash. Ensure that following such | 1189 // directory and does not end with a slash. Ensure that following such |
| 1186 // redirects does not crash. See http://crbug.com/18686. | 1190 // redirects does not crash. See http://crbug.com/18686. |
| 1187 | 1191 |
| 1188 base::FilePath path; | 1192 base::FilePath path; |
| 1189 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 1193 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 1190 path = path.Append(kTestFilePath); | 1194 path = path.Append(kTestFilePath); |
| 1191 | 1195 |
| 1192 TestDelegate d; | 1196 TestDelegate d; |
| 1193 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 1197 std::unique_ptr<URLRequest> req( |
| 1194 FilePathToFileURL(path), DEFAULT_PRIORITY, &d)); | 1198 default_context_.CreateRequest(FilePathToFileURL(path), DEFAULT_PRIORITY, |
| 1199 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1195 req->Start(); | 1200 req->Start(); |
| 1196 base::RunLoop().Run(); | 1201 base::RunLoop().Run(); |
| 1197 | 1202 |
| 1198 ASSERT_EQ(1, d.received_redirect_count()); | 1203 ASSERT_EQ(1, d.received_redirect_count()); |
| 1199 ASSERT_LT(0, d.bytes_received()); | 1204 ASSERT_LT(0, d.bytes_received()); |
| 1200 ASSERT_FALSE(d.request_failed()); | 1205 ASSERT_FALSE(d.request_failed()); |
| 1201 EXPECT_EQ(OK, d.request_status()); | 1206 EXPECT_EQ(OK, d.request_status()); |
| 1202 } | 1207 } |
| 1203 | 1208 |
| 1204 #if defined(OS_WIN) | 1209 #if defined(OS_WIN) |
| 1205 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. | 1210 // Don't accept the url "file:///" on windows. See http://crbug.com/1474. |
| 1206 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { | 1211 TEST_F(URLRequestTest, FileDirRedirectSingleSlash) { |
| 1207 TestDelegate d; | 1212 TestDelegate d; |
| 1208 std::unique_ptr<URLRequest> req( | 1213 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1209 default_context_.CreateRequest(GURL("file:///"), DEFAULT_PRIORITY, &d)); | 1214 GURL("file:///"), DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1210 req->Start(); | 1215 req->Start(); |
| 1211 base::RunLoop().Run(); | 1216 base::RunLoop().Run(); |
| 1212 | 1217 |
| 1213 ASSERT_EQ(1, d.received_redirect_count()); | 1218 ASSERT_EQ(1, d.received_redirect_count()); |
| 1214 EXPECT_NE(OK, d.request_status()); | 1219 EXPECT_NE(OK, d.request_status()); |
| 1215 } | 1220 } |
| 1216 #endif // defined(OS_WIN) | 1221 #endif // defined(OS_WIN) |
| 1217 | 1222 |
| 1218 #endif // !BUILDFLAG(DISABLE_FILE_SUPPORT) | 1223 #endif // !BUILDFLAG(DISABLE_FILE_SUPPORT) |
| 1219 | 1224 |
| 1220 TEST_F(URLRequestTest, InvalidUrlTest) { | 1225 TEST_F(URLRequestTest, InvalidUrlTest) { |
| 1221 TestDelegate d; | 1226 TestDelegate d; |
| 1222 { | 1227 { |
| 1223 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 1228 std::unique_ptr<URLRequest> r( |
| 1224 GURL("invalid url"), DEFAULT_PRIORITY, &d)); | 1229 default_context_.CreateRequest(GURL("invalid url"), DEFAULT_PRIORITY, |
| 1230 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1225 | 1231 |
| 1226 r->Start(); | 1232 r->Start(); |
| 1227 EXPECT_TRUE(r->is_pending()); | 1233 EXPECT_TRUE(r->is_pending()); |
| 1228 | 1234 |
| 1229 base::RunLoop().Run(); | 1235 base::RunLoop().Run(); |
| 1230 EXPECT_TRUE(d.request_failed()); | 1236 EXPECT_TRUE(d.request_failed()); |
| 1231 } | 1237 } |
| 1232 } | 1238 } |
| 1233 | 1239 |
| 1234 TEST_F(URLRequestTest, InvalidReferrerTest) { | 1240 TEST_F(URLRequestTest, InvalidReferrerTest) { |
| 1235 TestURLRequestContext context; | 1241 TestURLRequestContext context; |
| 1236 TestNetworkDelegate network_delegate; | 1242 TestNetworkDelegate network_delegate; |
| 1237 network_delegate.set_cancel_request_with_policy_violating_referrer(true); | 1243 network_delegate.set_cancel_request_with_policy_violating_referrer(true); |
| 1238 context.set_network_delegate(&network_delegate); | 1244 context.set_network_delegate(&network_delegate); |
| 1239 TestDelegate d; | 1245 TestDelegate d; |
| 1240 std::unique_ptr<URLRequest> req( | 1246 std::unique_ptr<URLRequest> req( |
| 1241 context.CreateRequest(GURL("http://localhost/"), DEFAULT_PRIORITY, &d)); | 1247 context.CreateRequest(GURL("http://localhost/"), DEFAULT_PRIORITY, &d, |
| 1248 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1242 req->SetReferrer("https://somewhere.com/"); | 1249 req->SetReferrer("https://somewhere.com/"); |
| 1243 | 1250 |
| 1244 req->Start(); | 1251 req->Start(); |
| 1245 base::RunLoop().Run(); | 1252 base::RunLoop().Run(); |
| 1246 EXPECT_TRUE(d.request_failed()); | 1253 EXPECT_TRUE(d.request_failed()); |
| 1247 } | 1254 } |
| 1248 | 1255 |
| 1249 #if defined(OS_WIN) | 1256 #if defined(OS_WIN) |
| 1250 TEST_F(URLRequestTest, ResolveShortcutTest) { | 1257 TEST_F(URLRequestTest, ResolveShortcutTest) { |
| 1251 base::FilePath app_path; | 1258 base::FilePath app_path; |
| (...skipping 13 matching lines...) Expand all Loading... |
| 1265 base::win::ScopedComPtr<IPersistFile> persist; | 1272 base::win::ScopedComPtr<IPersistFile> persist; |
| 1266 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); | 1273 ASSERT_TRUE(SUCCEEDED(shell.QueryInterface(persist.Receive()))); |
| 1267 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); | 1274 EXPECT_TRUE(SUCCEEDED(shell->SetPath(app_path.value().c_str()))); |
| 1268 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); | 1275 EXPECT_TRUE(SUCCEEDED(shell->SetDescription(L"ResolveShortcutTest"))); |
| 1269 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); | 1276 EXPECT_TRUE(SUCCEEDED(persist->Save(lnk_path.c_str(), TRUE))); |
| 1270 } | 1277 } |
| 1271 | 1278 |
| 1272 TestDelegate d; | 1279 TestDelegate d; |
| 1273 { | 1280 { |
| 1274 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 1281 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 1275 FilePathToFileURL(base::FilePath(lnk_path)), DEFAULT_PRIORITY, &d)); | 1282 FilePathToFileURL(base::FilePath(lnk_path)), DEFAULT_PRIORITY, &d, |
| 1283 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1276 | 1284 |
| 1277 r->Start(); | 1285 r->Start(); |
| 1278 EXPECT_TRUE(r->is_pending()); | 1286 EXPECT_TRUE(r->is_pending()); |
| 1279 | 1287 |
| 1280 base::RunLoop().Run(); | 1288 base::RunLoop().Run(); |
| 1281 | 1289 |
| 1282 WIN32_FILE_ATTRIBUTE_DATA data; | 1290 WIN32_FILE_ATTRIBUTE_DATA data; |
| 1283 GetFileAttributesEx(app_path.value().c_str(), | 1291 GetFileAttributesEx(app_path.value().c_str(), |
| 1284 GetFileExInfoStandard, &data); | 1292 GetFileExInfoStandard, &data); |
| 1285 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, | 1293 HANDLE file = CreateFile(app_path.value().c_str(), GENERIC_READ, |
| (...skipping 363 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1649 MockURLRequestInterceptor* interceptor_; | 1657 MockURLRequestInterceptor* interceptor_; |
| 1650 }; | 1658 }; |
| 1651 | 1659 |
| 1652 TEST_F(URLRequestInterceptorTest, Intercept) { | 1660 TEST_F(URLRequestInterceptorTest, Intercept) { |
| 1653 // Intercept the main request and respond with a simple response. | 1661 // Intercept the main request and respond with a simple response. |
| 1654 interceptor()->set_intercept_main_request(true); | 1662 interceptor()->set_intercept_main_request(true); |
| 1655 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers()); | 1663 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers()); |
| 1656 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data()); | 1664 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data()); |
| 1657 TestDelegate d; | 1665 TestDelegate d; |
| 1658 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1666 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1659 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1667 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1668 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1660 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); | 1669 base::SupportsUserData::Data* user_data0 = new base::SupportsUserData::Data(); |
| 1661 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); | 1670 base::SupportsUserData::Data* user_data1 = new base::SupportsUserData::Data(); |
| 1662 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); | 1671 base::SupportsUserData::Data* user_data2 = new base::SupportsUserData::Data(); |
| 1663 req->SetUserData(nullptr, user_data0); | 1672 req->SetUserData(nullptr, user_data0); |
| 1664 req->SetUserData(&user_data1, user_data1); | 1673 req->SetUserData(&user_data1, user_data1); |
| 1665 req->SetUserData(&user_data2, user_data2); | 1674 req->SetUserData(&user_data2, user_data2); |
| 1666 req->set_method("GET"); | 1675 req->set_method("GET"); |
| 1667 req->Start(); | 1676 req->Start(); |
| 1668 base::RunLoop().Run(); | 1677 base::RunLoop().Run(); |
| 1669 | 1678 |
| (...skipping 17 matching lines...) Expand all Loading... |
| 1687 MockURLRequestInterceptor::redirect_headers()); | 1696 MockURLRequestInterceptor::redirect_headers()); |
| 1688 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data()); | 1697 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data()); |
| 1689 | 1698 |
| 1690 // Intercept that redirect and respond with a final OK response. | 1699 // Intercept that redirect and respond with a final OK response. |
| 1691 interceptor()->set_intercept_redirect(true); | 1700 interceptor()->set_intercept_redirect(true); |
| 1692 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers()); | 1701 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers()); |
| 1693 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data()); | 1702 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data()); |
| 1694 | 1703 |
| 1695 TestDelegate d; | 1704 TestDelegate d; |
| 1696 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1705 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1697 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1706 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1707 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1698 req->set_method("GET"); | 1708 req->set_method("GET"); |
| 1699 req->Start(); | 1709 req->Start(); |
| 1700 base::RunLoop().Run(); | 1710 base::RunLoop().Run(); |
| 1701 | 1711 |
| 1702 // Check that the interceptor got called as expected. | 1712 // Check that the interceptor got called as expected. |
| 1703 EXPECT_TRUE(interceptor()->did_intercept_main()); | 1713 EXPECT_TRUE(interceptor()->did_intercept_main()); |
| 1704 EXPECT_TRUE(interceptor()->did_intercept_redirect()); | 1714 EXPECT_TRUE(interceptor()->did_intercept_redirect()); |
| 1705 | 1715 |
| 1706 // Check that we got one good response. | 1716 // Check that we got one good response. |
| 1707 int status = d.request_status(); | 1717 int status = d.request_status(); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 1720 interceptor()->set_main_headers(MockURLRequestInterceptor::error_headers()); | 1730 interceptor()->set_main_headers(MockURLRequestInterceptor::error_headers()); |
| 1721 interceptor()->set_main_data(MockURLRequestInterceptor::error_data()); | 1731 interceptor()->set_main_data(MockURLRequestInterceptor::error_data()); |
| 1722 | 1732 |
| 1723 // Intercept that error and respond with an OK response. | 1733 // Intercept that error and respond with an OK response. |
| 1724 interceptor()->set_intercept_final_response(true); | 1734 interceptor()->set_intercept_final_response(true); |
| 1725 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); | 1735 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); |
| 1726 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); | 1736 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); |
| 1727 | 1737 |
| 1728 TestDelegate d; | 1738 TestDelegate d; |
| 1729 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1739 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1730 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1740 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1741 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1731 req->set_method("GET"); | 1742 req->set_method("GET"); |
| 1732 req->Start(); | 1743 req->Start(); |
| 1733 base::RunLoop().Run(); | 1744 base::RunLoop().Run(); |
| 1734 | 1745 |
| 1735 // Check that the interceptor got called as expected. | 1746 // Check that the interceptor got called as expected. |
| 1736 EXPECT_TRUE(interceptor()->did_intercept_main()); | 1747 EXPECT_TRUE(interceptor()->did_intercept_main()); |
| 1737 EXPECT_TRUE(interceptor()->did_intercept_final()); | 1748 EXPECT_TRUE(interceptor()->did_intercept_final()); |
| 1738 | 1749 |
| 1739 // Check that we got one good response. | 1750 // Check that we got one good response. |
| 1740 EXPECT_EQ(OK, d.request_status()); | 1751 EXPECT_EQ(OK, d.request_status()); |
| 1741 EXPECT_EQ(200, req->response_headers()->response_code()); | 1752 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 1742 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); | 1753 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); |
| 1743 EXPECT_EQ(1, d.response_started_count()); | 1754 EXPECT_EQ(1, d.response_started_count()); |
| 1744 EXPECT_EQ(0, d.received_redirect_count()); | 1755 EXPECT_EQ(0, d.received_redirect_count()); |
| 1745 } | 1756 } |
| 1746 | 1757 |
| 1747 TEST_F(URLRequestInterceptorTest, InterceptNetworkError) { | 1758 TEST_F(URLRequestInterceptorTest, InterceptNetworkError) { |
| 1748 // Intercept the main request to simulate a network error. | 1759 // Intercept the main request to simulate a network error. |
| 1749 interceptor()->set_simulate_main_network_error(true); | 1760 interceptor()->set_simulate_main_network_error(true); |
| 1750 | 1761 |
| 1751 // Intercept that error and respond with an OK response. | 1762 // Intercept that error and respond with an OK response. |
| 1752 interceptor()->set_intercept_final_response(true); | 1763 interceptor()->set_intercept_final_response(true); |
| 1753 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); | 1764 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); |
| 1754 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); | 1765 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); |
| 1755 | 1766 |
| 1756 TestDelegate d; | 1767 TestDelegate d; |
| 1757 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1768 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1758 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1769 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1770 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1759 req->set_method("GET"); | 1771 req->set_method("GET"); |
| 1760 req->Start(); | 1772 req->Start(); |
| 1761 base::RunLoop().Run(); | 1773 base::RunLoop().Run(); |
| 1762 | 1774 |
| 1763 // Check that the interceptor got called as expected. | 1775 // Check that the interceptor got called as expected. |
| 1764 EXPECT_TRUE(interceptor()->did_simulate_error_main()); | 1776 EXPECT_TRUE(interceptor()->did_simulate_error_main()); |
| 1765 EXPECT_TRUE(interceptor()->did_intercept_final()); | 1777 EXPECT_TRUE(interceptor()->did_intercept_final()); |
| 1766 | 1778 |
| 1767 // Check that we received one good response. | 1779 // Check that we received one good response. |
| 1768 EXPECT_EQ(OK, d.request_status()); | 1780 EXPECT_EQ(OK, d.request_status()); |
| 1769 EXPECT_EQ(200, req->response_headers()->response_code()); | 1781 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 1770 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); | 1782 EXPECT_EQ(MockURLRequestInterceptor::ok_data(), d.data_received()); |
| 1771 EXPECT_EQ(1, d.response_started_count()); | 1783 EXPECT_EQ(1, d.response_started_count()); |
| 1772 EXPECT_EQ(0, d.received_redirect_count()); | 1784 EXPECT_EQ(0, d.received_redirect_count()); |
| 1773 } | 1785 } |
| 1774 | 1786 |
| 1775 TEST_F(URLRequestInterceptorTest, InterceptRestartRequired) { | 1787 TEST_F(URLRequestInterceptorTest, InterceptRestartRequired) { |
| 1776 // Restart the main request. | 1788 // Restart the main request. |
| 1777 interceptor()->set_restart_main_request(true); | 1789 interceptor()->set_restart_main_request(true); |
| 1778 | 1790 |
| 1779 // then intercept the new main request and respond with an OK response | 1791 // then intercept the new main request and respond with an OK response |
| 1780 interceptor()->set_intercept_main_request(true); | 1792 interceptor()->set_intercept_main_request(true); |
| 1781 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers()); | 1793 interceptor()->set_main_headers(MockURLRequestInterceptor::ok_headers()); |
| 1782 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data()); | 1794 interceptor()->set_main_data(MockURLRequestInterceptor::ok_data()); |
| 1783 | 1795 |
| 1784 TestDelegate d; | 1796 TestDelegate d; |
| 1785 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1797 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1786 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1798 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1799 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1787 req->set_method("GET"); | 1800 req->set_method("GET"); |
| 1788 req->Start(); | 1801 req->Start(); |
| 1789 base::RunLoop().Run(); | 1802 base::RunLoop().Run(); |
| 1790 | 1803 |
| 1791 // Check that the interceptor got called as expected. | 1804 // Check that the interceptor got called as expected. |
| 1792 EXPECT_TRUE(interceptor()->did_restart_main()); | 1805 EXPECT_TRUE(interceptor()->did_restart_main()); |
| 1793 EXPECT_TRUE(interceptor()->did_intercept_main()); | 1806 EXPECT_TRUE(interceptor()->did_intercept_main()); |
| 1794 | 1807 |
| 1795 // Check that we received one good response. | 1808 // Check that we received one good response. |
| 1796 int status = d.request_status(); | 1809 int status = d.request_status(); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 1807 // Intercept the main request and cancel from within the restarted job. | 1820 // Intercept the main request and cancel from within the restarted job. |
| 1808 interceptor()->set_cancel_main_request(true); | 1821 interceptor()->set_cancel_main_request(true); |
| 1809 | 1822 |
| 1810 // Set up to intercept the final response and override it with an OK response. | 1823 // Set up to intercept the final response and override it with an OK response. |
| 1811 interceptor()->set_intercept_final_response(true); | 1824 interceptor()->set_intercept_final_response(true); |
| 1812 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); | 1825 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); |
| 1813 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); | 1826 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); |
| 1814 | 1827 |
| 1815 TestDelegate d; | 1828 TestDelegate d; |
| 1816 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1829 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1817 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1830 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1831 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1818 req->set_method("GET"); | 1832 req->set_method("GET"); |
| 1819 req->Start(); | 1833 req->Start(); |
| 1820 base::RunLoop().Run(); | 1834 base::RunLoop().Run(); |
| 1821 | 1835 |
| 1822 // Check that the interceptor got called as expected. | 1836 // Check that the interceptor got called as expected. |
| 1823 EXPECT_TRUE(interceptor()->did_cancel_main()); | 1837 EXPECT_TRUE(interceptor()->did_cancel_main()); |
| 1824 EXPECT_FALSE(interceptor()->did_intercept_final()); | 1838 EXPECT_FALSE(interceptor()->did_intercept_final()); |
| 1825 | 1839 |
| 1826 // Check that we see a canceled request. | 1840 // Check that we see a canceled request. |
| 1827 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 1841 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 1828 } | 1842 } |
| 1829 | 1843 |
| 1830 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelRedirect) { | 1844 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelRedirect) { |
| 1831 // Intercept the main request and respond with a redirect. | 1845 // Intercept the main request and respond with a redirect. |
| 1832 interceptor()->set_intercept_main_request(true); | 1846 interceptor()->set_intercept_main_request(true); |
| 1833 interceptor()->set_main_headers( | 1847 interceptor()->set_main_headers( |
| 1834 MockURLRequestInterceptor::redirect_headers()); | 1848 MockURLRequestInterceptor::redirect_headers()); |
| 1835 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data()); | 1849 interceptor()->set_main_data(MockURLRequestInterceptor::redirect_data()); |
| 1836 | 1850 |
| 1837 // Intercept the redirect and cancel from within that job. | 1851 // Intercept the redirect and cancel from within that job. |
| 1838 interceptor()->set_cancel_redirect_request(true); | 1852 interceptor()->set_cancel_redirect_request(true); |
| 1839 | 1853 |
| 1840 // Set up to intercept the final response and override it with an OK response. | 1854 // Set up to intercept the final response and override it with an OK response. |
| 1841 interceptor()->set_intercept_final_response(true); | 1855 interceptor()->set_intercept_final_response(true); |
| 1842 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); | 1856 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); |
| 1843 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); | 1857 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); |
| 1844 | 1858 |
| 1845 TestDelegate d; | 1859 TestDelegate d; |
| 1846 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1860 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1847 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1861 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1862 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1848 req->set_method("GET"); | 1863 req->set_method("GET"); |
| 1849 req->Start(); | 1864 req->Start(); |
| 1850 base::RunLoop().Run(); | 1865 base::RunLoop().Run(); |
| 1851 | 1866 |
| 1852 // Check that the interceptor got called as expected. | 1867 // Check that the interceptor got called as expected. |
| 1853 EXPECT_TRUE(interceptor()->did_intercept_main()); | 1868 EXPECT_TRUE(interceptor()->did_intercept_main()); |
| 1854 EXPECT_TRUE(interceptor()->did_cancel_redirect()); | 1869 EXPECT_TRUE(interceptor()->did_cancel_redirect()); |
| 1855 EXPECT_FALSE(interceptor()->did_intercept_final()); | 1870 EXPECT_FALSE(interceptor()->did_intercept_final()); |
| 1856 | 1871 |
| 1857 // Check that we see a canceled request. | 1872 // Check that we see a canceled request. |
| 1858 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 1873 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 1859 } | 1874 } |
| 1860 | 1875 |
| 1861 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) { | 1876 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelFinal) { |
| 1862 // Intercept the main request to simulate a network error. | 1877 // Intercept the main request to simulate a network error. |
| 1863 interceptor()->set_simulate_main_network_error(true); | 1878 interceptor()->set_simulate_main_network_error(true); |
| 1864 | 1879 |
| 1865 // Set up to intercept final the response and cancel from within that job. | 1880 // Set up to intercept final the response and cancel from within that job. |
| 1866 interceptor()->set_cancel_final_request(true); | 1881 interceptor()->set_cancel_final_request(true); |
| 1867 | 1882 |
| 1868 TestDelegate d; | 1883 TestDelegate d; |
| 1869 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1884 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1870 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1885 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1886 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1871 req->set_method("GET"); | 1887 req->set_method("GET"); |
| 1872 req->Start(); | 1888 req->Start(); |
| 1873 base::RunLoop().Run(); | 1889 base::RunLoop().Run(); |
| 1874 | 1890 |
| 1875 // Check that the interceptor got called as expected. | 1891 // Check that the interceptor got called as expected. |
| 1876 EXPECT_TRUE(interceptor()->did_simulate_error_main()); | 1892 EXPECT_TRUE(interceptor()->did_simulate_error_main()); |
| 1877 EXPECT_TRUE(interceptor()->did_cancel_final()); | 1893 EXPECT_TRUE(interceptor()->did_cancel_final()); |
| 1878 | 1894 |
| 1879 // Check that we see a canceled request. | 1895 // Check that we see a canceled request. |
| 1880 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 1896 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 1881 } | 1897 } |
| 1882 | 1898 |
| 1883 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelInRestart) { | 1899 TEST_F(URLRequestInterceptorTest, InterceptRespectsCancelInRestart) { |
| 1884 // Intercept the main request and cancel then restart from within that job. | 1900 // Intercept the main request and cancel then restart from within that job. |
| 1885 interceptor()->set_cancel_then_restart_main_request(true); | 1901 interceptor()->set_cancel_then_restart_main_request(true); |
| 1886 | 1902 |
| 1887 // Set up to intercept the final response and override it with an OK response. | 1903 // Set up to intercept the final response and override it with an OK response. |
| 1888 interceptor()->set_intercept_final_response(true); | 1904 interceptor()->set_intercept_final_response(true); |
| 1889 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); | 1905 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); |
| 1890 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); | 1906 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); |
| 1891 | 1907 |
| 1892 TestDelegate d; | 1908 TestDelegate d; |
| 1893 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 1909 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 1894 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1910 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 1911 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1895 req->set_method("GET"); | 1912 req->set_method("GET"); |
| 1896 req->Start(); | 1913 req->Start(); |
| 1897 base::RunLoop().Run(); | 1914 base::RunLoop().Run(); |
| 1898 | 1915 |
| 1899 // Check that the interceptor got called as expected. | 1916 // Check that the interceptor got called as expected. |
| 1900 EXPECT_TRUE(interceptor()->did_cancel_then_restart_main()); | 1917 EXPECT_TRUE(interceptor()->did_cancel_then_restart_main()); |
| 1901 EXPECT_FALSE(interceptor()->did_intercept_final()); | 1918 EXPECT_FALSE(interceptor()->did_intercept_final()); |
| 1902 | 1919 |
| 1903 // Check that we see a canceled request. | 1920 // Check that we see a canceled request. |
| 1904 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 1921 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1954 return load_timing; | 1971 return load_timing; |
| 1955 } | 1972 } |
| 1956 | 1973 |
| 1957 LoadTimingInfo RunURLRequestInterceptorLoadTimingTest( | 1974 LoadTimingInfo RunURLRequestInterceptorLoadTimingTest( |
| 1958 const LoadTimingInfo& job_load_timing, | 1975 const LoadTimingInfo& job_load_timing, |
| 1959 const URLRequestContext& context, | 1976 const URLRequestContext& context, |
| 1960 MockURLRequestInterceptor* interceptor) { | 1977 MockURLRequestInterceptor* interceptor) { |
| 1961 interceptor->set_intercept_main_request(true); | 1978 interceptor->set_intercept_main_request(true); |
| 1962 interceptor->set_main_request_load_timing_info(job_load_timing); | 1979 interceptor->set_main_request_load_timing_info(job_load_timing); |
| 1963 TestDelegate d; | 1980 TestDelegate d; |
| 1964 std::unique_ptr<URLRequest> req(context.CreateRequest( | 1981 std::unique_ptr<URLRequest> req( |
| 1965 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 1982 context.CreateRequest(GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, |
| 1983 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 1966 req->Start(); | 1984 req->Start(); |
| 1967 base::RunLoop().Run(); | 1985 base::RunLoop().Run(); |
| 1968 | 1986 |
| 1969 LoadTimingInfo resulting_load_timing; | 1987 LoadTimingInfo resulting_load_timing; |
| 1970 req->GetLoadTimingInfo(&resulting_load_timing); | 1988 req->GetLoadTimingInfo(&resulting_load_timing); |
| 1971 | 1989 |
| 1972 // None of these should be modified by the URLRequest. | 1990 // None of these should be modified by the URLRequest. |
| 1973 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); | 1991 EXPECT_EQ(job_load_timing.socket_reused, resulting_load_timing.socket_reused); |
| 1974 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); | 1992 EXPECT_EQ(job_load_timing.socket_log_id, resulting_load_timing.socket_log_id); |
| 1975 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); | 1993 EXPECT_EQ(job_load_timing.send_start, resulting_load_timing.send_start); |
| (...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2174 // Other times should have been left null. | 2192 // Other times should have been left null. |
| 2175 TestLoadTimingNotReusedWithProxy(load_timing_result, | 2193 TestLoadTimingNotReusedWithProxy(load_timing_result, |
| 2176 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); | 2194 CONNECT_TIMING_HAS_CONNECT_TIMES_ONLY); |
| 2177 } | 2195 } |
| 2178 | 2196 |
| 2179 // Check that two different URL requests have different identifiers. | 2197 // Check that two different URL requests have different identifiers. |
| 2180 TEST_F(URLRequestTest, Identifiers) { | 2198 TEST_F(URLRequestTest, Identifiers) { |
| 2181 TestDelegate d; | 2199 TestDelegate d; |
| 2182 TestURLRequestContext context; | 2200 TestURLRequestContext context; |
| 2183 std::unique_ptr<URLRequest> req( | 2201 std::unique_ptr<URLRequest> req( |
| 2184 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d)); | 2202 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d, |
| 2203 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2185 std::unique_ptr<URLRequest> other_req( | 2204 std::unique_ptr<URLRequest> other_req( |
| 2186 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d)); | 2205 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d, |
| 2206 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2187 | 2207 |
| 2188 ASSERT_NE(req->identifier(), other_req->identifier()); | 2208 ASSERT_NE(req->identifier(), other_req->identifier()); |
| 2189 } | 2209 } |
| 2190 | 2210 |
| 2191 #if defined(OS_IOS) | 2211 #if defined(OS_IOS) |
| 2192 // TODO(droger): Check that a failure to connect to the proxy is reported to | 2212 // TODO(droger): Check that a failure to connect to the proxy is reported to |
| 2193 // the network delegate. crbug.com/496743 | 2213 // the network delegate. crbug.com/496743 |
| 2194 #define MAYBE_NetworkDelegateProxyError DISABLED_NetworkDelegateProxyError | 2214 #define MAYBE_NetworkDelegateProxyError DISABLED_NetworkDelegateProxyError |
| 2195 #else | 2215 #else |
| 2196 #define MAYBE_NetworkDelegateProxyError NetworkDelegateProxyError | 2216 #define MAYBE_NetworkDelegateProxyError NetworkDelegateProxyError |
| 2197 #endif | 2217 #endif |
| 2198 TEST_F(URLRequestTest, MAYBE_NetworkDelegateProxyError) { | 2218 TEST_F(URLRequestTest, MAYBE_NetworkDelegateProxyError) { |
| 2199 MockHostResolver host_resolver; | 2219 MockHostResolver host_resolver; |
| 2200 host_resolver.rules()->AddSimulatedFailure("*"); | 2220 host_resolver.rules()->AddSimulatedFailure("*"); |
| 2201 | 2221 |
| 2202 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 2222 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 2203 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); | 2223 TestURLRequestContextWithProxy context("myproxy:70", &network_delegate); |
| 2204 | 2224 |
| 2205 TestDelegate d; | 2225 TestDelegate d; |
| 2206 std::unique_ptr<URLRequest> req( | 2226 std::unique_ptr<URLRequest> req( |
| 2207 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d)); | 2227 context.CreateRequest(GURL("http://example.com"), DEFAULT_PRIORITY, &d, |
| 2228 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2208 req->set_method("GET"); | 2229 req->set_method("GET"); |
| 2209 | 2230 |
| 2210 req->Start(); | 2231 req->Start(); |
| 2211 base::RunLoop().Run(); | 2232 base::RunLoop().Run(); |
| 2212 | 2233 |
| 2213 // Check we see a failed request. | 2234 // Check we see a failed request. |
| 2214 // The proxy server is not set before failure. | 2235 // The proxy server is not set before failure. |
| 2215 EXPECT_FALSE(req->proxy_server().is_valid()); | 2236 EXPECT_FALSE(req->proxy_server().is_valid()); |
| 2216 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, d.request_status()); | 2237 EXPECT_EQ(ERR_PROXY_CONNECTION_FAILED, d.request_status()); |
| 2217 | 2238 |
| 2218 EXPECT_EQ(1, network_delegate.error_count()); | 2239 EXPECT_EQ(1, network_delegate.error_count()); |
| 2219 EXPECT_THAT(network_delegate.last_error(), | 2240 EXPECT_THAT(network_delegate.last_error(), |
| 2220 IsError(ERR_PROXY_CONNECTION_FAILED)); | 2241 IsError(ERR_PROXY_CONNECTION_FAILED)); |
| 2221 EXPECT_EQ(1, network_delegate.completed_requests()); | 2242 EXPECT_EQ(1, network_delegate.completed_requests()); |
| 2222 } | 2243 } |
| 2223 | 2244 |
| 2224 // Make sure that NetworkDelegate::NotifyCompleted is called if | 2245 // Make sure that NetworkDelegate::NotifyCompleted is called if |
| 2225 // content is empty. | 2246 // content is empty. |
| 2226 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { | 2247 TEST_F(URLRequestTest, RequestCompletionForEmptyResponse) { |
| 2227 TestDelegate d; | 2248 TestDelegate d; |
| 2228 std::unique_ptr<URLRequest> req( | 2249 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2229 default_context_.CreateRequest(GURL("data:,"), DEFAULT_PRIORITY, &d)); | 2250 GURL("data:,"), DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2230 req->Start(); | 2251 req->Start(); |
| 2231 base::RunLoop().Run(); | 2252 base::RunLoop().Run(); |
| 2232 EXPECT_EQ("", d.data_received()); | 2253 EXPECT_EQ("", d.data_received()); |
| 2233 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 2254 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
| 2234 } | 2255 } |
| 2235 | 2256 |
| 2236 // Make sure that SetPriority actually sets the URLRequest's priority | 2257 // Make sure that SetPriority actually sets the URLRequest's priority |
| 2237 // correctly, both before and after start. | 2258 // correctly, both before and after start. |
| 2238 TEST_F(URLRequestTest, SetPriorityBasic) { | 2259 TEST_F(URLRequestTest, SetPriorityBasic) { |
| 2239 TestDelegate d; | 2260 TestDelegate d; |
| 2240 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2261 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2241 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 2262 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 2263 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2242 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); | 2264 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
| 2243 | 2265 |
| 2244 req->SetPriority(LOW); | 2266 req->SetPriority(LOW); |
| 2245 EXPECT_EQ(LOW, req->priority()); | 2267 EXPECT_EQ(LOW, req->priority()); |
| 2246 | 2268 |
| 2247 req->Start(); | 2269 req->Start(); |
| 2248 EXPECT_EQ(LOW, req->priority()); | 2270 EXPECT_EQ(LOW, req->priority()); |
| 2249 | 2271 |
| 2250 req->SetPriority(MEDIUM); | 2272 req->SetPriority(MEDIUM); |
| 2251 EXPECT_EQ(MEDIUM, req->priority()); | 2273 EXPECT_EQ(MEDIUM, req->priority()); |
| 2252 } | 2274 } |
| 2253 | 2275 |
| 2254 // Make sure that URLRequest calls SetPriority on a job before calling | 2276 // Make sure that URLRequest calls SetPriority on a job before calling |
| 2255 // Start on it. | 2277 // Start on it. |
| 2256 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { | 2278 TEST_F(URLRequestTest, SetJobPriorityBeforeJobStart) { |
| 2257 TestDelegate d; | 2279 TestDelegate d; |
| 2258 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2280 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2259 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 2281 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 2282 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2260 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); | 2283 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
| 2261 | 2284 |
| 2262 RequestPriority job_priority; | 2285 RequestPriority job_priority; |
| 2263 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( | 2286 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( |
| 2264 req.get(), &default_network_delegate_, &job_priority)); | 2287 req.get(), &default_network_delegate_, &job_priority)); |
| 2265 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 2288 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 2266 EXPECT_EQ(DEFAULT_PRIORITY, job_priority); | 2289 EXPECT_EQ(DEFAULT_PRIORITY, job_priority); |
| 2267 | 2290 |
| 2268 req->SetPriority(LOW); | 2291 req->SetPriority(LOW); |
| 2269 | 2292 |
| 2270 req->Start(); | 2293 req->Start(); |
| 2271 EXPECT_EQ(LOW, job_priority); | 2294 EXPECT_EQ(LOW, job_priority); |
| 2272 } | 2295 } |
| 2273 | 2296 |
| 2274 // Make sure that URLRequest passes on its priority updates to its | 2297 // Make sure that URLRequest passes on its priority updates to its |
| 2275 // job. | 2298 // job. |
| 2276 TEST_F(URLRequestTest, SetJobPriority) { | 2299 TEST_F(URLRequestTest, SetJobPriority) { |
| 2277 TestDelegate d; | 2300 TestDelegate d; |
| 2278 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2301 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2279 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 2302 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d, |
| 2303 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2280 | 2304 |
| 2281 RequestPriority job_priority; | 2305 RequestPriority job_priority; |
| 2282 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( | 2306 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( |
| 2283 req.get(), &default_network_delegate_, &job_priority)); | 2307 req.get(), &default_network_delegate_, &job_priority)); |
| 2284 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 2308 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 2285 | 2309 |
| 2286 req->SetPriority(LOW); | 2310 req->SetPriority(LOW); |
| 2287 req->Start(); | 2311 req->Start(); |
| 2288 EXPECT_EQ(LOW, job_priority); | 2312 EXPECT_EQ(LOW, job_priority); |
| 2289 | 2313 |
| 2290 req->SetPriority(MEDIUM); | 2314 req->SetPriority(MEDIUM); |
| 2291 EXPECT_EQ(MEDIUM, req->priority()); | 2315 EXPECT_EQ(MEDIUM, req->priority()); |
| 2292 EXPECT_EQ(MEDIUM, job_priority); | 2316 EXPECT_EQ(MEDIUM, job_priority); |
| 2293 } | 2317 } |
| 2294 | 2318 |
| 2295 // Setting the IGNORE_LIMITS load flag should be okay if the priority | 2319 // Setting the IGNORE_LIMITS load flag should be okay if the priority |
| 2296 // is MAXIMUM_PRIORITY. | 2320 // is MAXIMUM_PRIORITY. |
| 2297 TEST_F(URLRequestTest, PriorityIgnoreLimits) { | 2321 TEST_F(URLRequestTest, PriorityIgnoreLimits) { |
| 2298 TestDelegate d; | 2322 TestDelegate d; |
| 2299 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2323 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2300 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d)); | 2324 GURL("http://test_intercept/foo"), MAXIMUM_PRIORITY, &d, |
| 2325 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2301 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2326 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 2302 | 2327 |
| 2303 RequestPriority job_priority; | 2328 RequestPriority job_priority; |
| 2304 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( | 2329 std::unique_ptr<URLRequestJob> job(new PriorityMonitoringURLRequestJob( |
| 2305 req.get(), &default_network_delegate_, &job_priority)); | 2330 req.get(), &default_network_delegate_, &job_priority)); |
| 2306 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 2331 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 2307 | 2332 |
| 2308 req->SetLoadFlags(LOAD_IGNORE_LIMITS); | 2333 req->SetLoadFlags(LOAD_IGNORE_LIMITS); |
| 2309 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); | 2334 EXPECT_EQ(MAXIMUM_PRIORITY, req->priority()); |
| 2310 | 2335 |
| (...skipping 27 matching lines...) Expand all Loading... |
| 2338 std::unique_ptr<DelayedCookieMonster> delayed_cm(new DelayedCookieMonster()); | 2363 std::unique_ptr<DelayedCookieMonster> delayed_cm(new DelayedCookieMonster()); |
| 2339 context.set_cookie_store(delayed_cm.get()); | 2364 context.set_cookie_store(delayed_cm.get()); |
| 2340 | 2365 |
| 2341 // Set up a cookie. | 2366 // Set up a cookie. |
| 2342 { | 2367 { |
| 2343 TestNetworkDelegate network_delegate; | 2368 TestNetworkDelegate network_delegate; |
| 2344 context.set_network_delegate(&network_delegate); | 2369 context.set_network_delegate(&network_delegate); |
| 2345 TestDelegate d; | 2370 TestDelegate d; |
| 2346 std::unique_ptr<URLRequest> req(context.CreateRequest( | 2371 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 2347 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, | 2372 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2348 &d)); | 2373 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2349 req->Start(); | 2374 req->Start(); |
| 2350 base::RunLoop().Run(); | 2375 base::RunLoop().Run(); |
| 2351 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2376 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2352 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2377 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2353 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2378 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2354 } | 2379 } |
| 2355 | 2380 |
| 2356 // Verify that the cookie is set. | 2381 // Verify that the cookie is set. |
| 2357 { | 2382 { |
| 2358 TestNetworkDelegate network_delegate; | 2383 TestNetworkDelegate network_delegate; |
| 2359 context.set_network_delegate(&network_delegate); | 2384 context.set_network_delegate(&network_delegate); |
| 2360 TestDelegate d; | 2385 TestDelegate d; |
| 2361 std::unique_ptr<URLRequest> req(context.CreateRequest( | 2386 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 2362 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2387 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2388 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2363 req->Start(); | 2389 req->Start(); |
| 2364 base::RunLoop().Run(); | 2390 base::RunLoop().Run(); |
| 2365 | 2391 |
| 2366 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2392 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2367 != std::string::npos); | 2393 != std::string::npos); |
| 2368 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2394 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2369 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2395 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2370 } | 2396 } |
| 2371 } | 2397 } |
| 2372 | 2398 |
| 2373 TEST_F(URLRequestTest, DoNotSendCookies) { | 2399 TEST_F(URLRequestTest, DoNotSendCookies) { |
| 2374 LocalHttpTestServer test_server; | 2400 LocalHttpTestServer test_server; |
| 2375 ASSERT_TRUE(test_server.Start()); | 2401 ASSERT_TRUE(test_server.Start()); |
| 2376 | 2402 |
| 2377 // Set up a cookie. | 2403 // Set up a cookie. |
| 2378 { | 2404 { |
| 2379 TestNetworkDelegate network_delegate; | 2405 TestNetworkDelegate network_delegate; |
| 2380 default_context_.set_network_delegate(&network_delegate); | 2406 default_context_.set_network_delegate(&network_delegate); |
| 2381 TestDelegate d; | 2407 TestDelegate d; |
| 2382 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2408 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2383 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, | 2409 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2384 &d)); | 2410 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2385 req->Start(); | 2411 req->Start(); |
| 2386 base::RunLoop().Run(); | 2412 base::RunLoop().Run(); |
| 2387 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2413 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2388 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2414 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2389 } | 2415 } |
| 2390 | 2416 |
| 2391 // Verify that the cookie is set. | 2417 // Verify that the cookie is set. |
| 2392 { | 2418 { |
| 2393 TestNetworkDelegate network_delegate; | 2419 TestNetworkDelegate network_delegate; |
| 2394 default_context_.set_network_delegate(&network_delegate); | 2420 default_context_.set_network_delegate(&network_delegate); |
| 2395 TestDelegate d; | 2421 TestDelegate d; |
| 2396 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2422 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2397 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2423 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2424 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2398 req->Start(); | 2425 req->Start(); |
| 2399 base::RunLoop().Run(); | 2426 base::RunLoop().Run(); |
| 2400 | 2427 |
| 2401 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2428 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2402 != std::string::npos); | 2429 != std::string::npos); |
| 2403 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2430 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2404 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2431 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2405 } | 2432 } |
| 2406 | 2433 |
| 2407 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. | 2434 // Verify that the cookie isn't sent when LOAD_DO_NOT_SEND_COOKIES is set. |
| 2408 { | 2435 { |
| 2409 TestNetworkDelegate network_delegate; | 2436 TestNetworkDelegate network_delegate; |
| 2410 default_context_.set_network_delegate(&network_delegate); | 2437 default_context_.set_network_delegate(&network_delegate); |
| 2411 TestDelegate d; | 2438 TestDelegate d; |
| 2412 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2439 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2413 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2440 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2441 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2414 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); | 2442 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); |
| 2415 req->Start(); | 2443 req->Start(); |
| 2416 base::RunLoop().Run(); | 2444 base::RunLoop().Run(); |
| 2417 | 2445 |
| 2418 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2446 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2419 == std::string::npos); | 2447 == std::string::npos); |
| 2420 | 2448 |
| 2421 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. | 2449 // LOAD_DO_NOT_SEND_COOKIES does not trigger OnGetCookies. |
| 2422 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2450 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2423 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2451 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2424 } | 2452 } |
| 2425 } | 2453 } |
| 2426 | 2454 |
| 2427 TEST_F(URLRequestTest, DoNotSaveCookies) { | 2455 TEST_F(URLRequestTest, DoNotSaveCookies) { |
| 2428 LocalHttpTestServer test_server; | 2456 LocalHttpTestServer test_server; |
| 2429 ASSERT_TRUE(test_server.Start()); | 2457 ASSERT_TRUE(test_server.Start()); |
| 2430 | 2458 |
| 2431 // Set up a cookie. | 2459 // Set up a cookie. |
| 2432 { | 2460 { |
| 2433 TestNetworkDelegate network_delegate; | 2461 TestNetworkDelegate network_delegate; |
| 2434 default_context_.set_network_delegate(&network_delegate); | 2462 default_context_.set_network_delegate(&network_delegate); |
| 2435 TestDelegate d; | 2463 TestDelegate d; |
| 2436 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2464 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2437 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, | 2465 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2438 &d)); | 2466 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2439 req->Start(); | 2467 req->Start(); |
| 2440 base::RunLoop().Run(); | 2468 base::RunLoop().Run(); |
| 2441 | 2469 |
| 2442 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2470 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2443 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2471 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2444 EXPECT_EQ(1, network_delegate.set_cookie_count()); | 2472 EXPECT_EQ(1, network_delegate.set_cookie_count()); |
| 2445 } | 2473 } |
| 2446 | 2474 |
| 2447 // Try to set-up another cookie and update the previous cookie. | 2475 // Try to set-up another cookie and update the previous cookie. |
| 2448 { | 2476 { |
| 2449 TestNetworkDelegate network_delegate; | 2477 TestNetworkDelegate network_delegate; |
| 2450 default_context_.set_network_delegate(&network_delegate); | 2478 default_context_.set_network_delegate(&network_delegate); |
| 2451 TestDelegate d; | 2479 TestDelegate d; |
| 2452 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2480 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2453 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2481 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2454 DEFAULT_PRIORITY, &d)); | 2482 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2455 req->SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES); | 2483 req->SetLoadFlags(LOAD_DO_NOT_SAVE_COOKIES); |
| 2456 req->Start(); | 2484 req->Start(); |
| 2457 | 2485 |
| 2458 base::RunLoop().Run(); | 2486 base::RunLoop().Run(); |
| 2459 | 2487 |
| 2460 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. | 2488 // LOAD_DO_NOT_SAVE_COOKIES does not trigger OnSetCookie. |
| 2461 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2489 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2462 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2490 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2463 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2491 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2464 } | 2492 } |
| 2465 | 2493 |
| 2466 // Verify the cookies weren't saved or updated. | 2494 // Verify the cookies weren't saved or updated. |
| 2467 { | 2495 { |
| 2468 TestNetworkDelegate network_delegate; | 2496 TestNetworkDelegate network_delegate; |
| 2469 default_context_.set_network_delegate(&network_delegate); | 2497 default_context_.set_network_delegate(&network_delegate); |
| 2470 TestDelegate d; | 2498 TestDelegate d; |
| 2471 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2499 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2472 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2500 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2501 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2473 req->Start(); | 2502 req->Start(); |
| 2474 base::RunLoop().Run(); | 2503 base::RunLoop().Run(); |
| 2475 | 2504 |
| 2476 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2505 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2477 == std::string::npos); | 2506 == std::string::npos); |
| 2478 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2507 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2479 != std::string::npos); | 2508 != std::string::npos); |
| 2480 | 2509 |
| 2481 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2510 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2482 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2511 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2483 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2512 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2484 } | 2513 } |
| 2485 } | 2514 } |
| 2486 | 2515 |
| 2487 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { | 2516 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy) { |
| 2488 LocalHttpTestServer test_server; | 2517 LocalHttpTestServer test_server; |
| 2489 ASSERT_TRUE(test_server.Start()); | 2518 ASSERT_TRUE(test_server.Start()); |
| 2490 | 2519 |
| 2491 // Set up a cookie. | 2520 // Set up a cookie. |
| 2492 { | 2521 { |
| 2493 TestNetworkDelegate network_delegate; | 2522 TestNetworkDelegate network_delegate; |
| 2494 default_context_.set_network_delegate(&network_delegate); | 2523 default_context_.set_network_delegate(&network_delegate); |
| 2495 TestDelegate d; | 2524 TestDelegate d; |
| 2496 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2525 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2497 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, | 2526 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2498 &d)); | 2527 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2499 req->Start(); | 2528 req->Start(); |
| 2500 base::RunLoop().Run(); | 2529 base::RunLoop().Run(); |
| 2501 | 2530 |
| 2502 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2531 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2503 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2532 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2504 } | 2533 } |
| 2505 | 2534 |
| 2506 // Verify that the cookie is set. | 2535 // Verify that the cookie is set. |
| 2507 { | 2536 { |
| 2508 TestNetworkDelegate network_delegate; | 2537 TestNetworkDelegate network_delegate; |
| 2509 default_context_.set_network_delegate(&network_delegate); | 2538 default_context_.set_network_delegate(&network_delegate); |
| 2510 TestDelegate d; | 2539 TestDelegate d; |
| 2511 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2540 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2512 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2541 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2542 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2513 req->Start(); | 2543 req->Start(); |
| 2514 base::RunLoop().Run(); | 2544 base::RunLoop().Run(); |
| 2515 | 2545 |
| 2516 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2546 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2517 != std::string::npos); | 2547 != std::string::npos); |
| 2518 | 2548 |
| 2519 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2549 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2520 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2550 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2521 } | 2551 } |
| 2522 | 2552 |
| 2523 // Verify that the cookie isn't sent. | 2553 // Verify that the cookie isn't sent. |
| 2524 { | 2554 { |
| 2525 TestNetworkDelegate network_delegate; | 2555 TestNetworkDelegate network_delegate; |
| 2526 default_context_.set_network_delegate(&network_delegate); | 2556 default_context_.set_network_delegate(&network_delegate); |
| 2527 TestDelegate d; | 2557 TestDelegate d; |
| 2528 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2558 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2529 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2559 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2530 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2560 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2561 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2531 req->Start(); | 2562 req->Start(); |
| 2532 base::RunLoop().Run(); | 2563 base::RunLoop().Run(); |
| 2533 | 2564 |
| 2534 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2565 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2535 == std::string::npos); | 2566 == std::string::npos); |
| 2536 | 2567 |
| 2537 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2568 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2538 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2569 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2539 } | 2570 } |
| 2540 } | 2571 } |
| 2541 | 2572 |
| 2542 // TODO(crbug.com/564656) This test is flaky on iOS. | 2573 // TODO(crbug.com/564656) This test is flaky on iOS. |
| 2543 #if defined(OS_IOS) | 2574 #if defined(OS_IOS) |
| 2544 #define MAYBE_DoNotSaveCookies_ViaPolicy FLAKY_DoNotSaveCookies_ViaPolicy | 2575 #define MAYBE_DoNotSaveCookies_ViaPolicy FLAKY_DoNotSaveCookies_ViaPolicy |
| 2545 #else | 2576 #else |
| 2546 #define MAYBE_DoNotSaveCookies_ViaPolicy DoNotSaveCookies_ViaPolicy | 2577 #define MAYBE_DoNotSaveCookies_ViaPolicy DoNotSaveCookies_ViaPolicy |
| 2547 #endif | 2578 #endif |
| 2548 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { | 2579 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy) { |
| 2549 LocalHttpTestServer test_server; | 2580 LocalHttpTestServer test_server; |
| 2550 ASSERT_TRUE(test_server.Start()); | 2581 ASSERT_TRUE(test_server.Start()); |
| 2551 | 2582 |
| 2552 // Set up a cookie. | 2583 // Set up a cookie. |
| 2553 { | 2584 { |
| 2554 TestNetworkDelegate network_delegate; | 2585 TestNetworkDelegate network_delegate; |
| 2555 default_context_.set_network_delegate(&network_delegate); | 2586 default_context_.set_network_delegate(&network_delegate); |
| 2556 TestDelegate d; | 2587 TestDelegate d; |
| 2557 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2588 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2558 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, | 2589 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2559 &d)); | 2590 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2560 req->Start(); | 2591 req->Start(); |
| 2561 base::RunLoop().Run(); | 2592 base::RunLoop().Run(); |
| 2562 | 2593 |
| 2563 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2594 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2564 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2595 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2565 } | 2596 } |
| 2566 | 2597 |
| 2567 // Try to set-up another cookie and update the previous cookie. | 2598 // Try to set-up another cookie and update the previous cookie. |
| 2568 { | 2599 { |
| 2569 TestNetworkDelegate network_delegate; | 2600 TestNetworkDelegate network_delegate; |
| 2570 default_context_.set_network_delegate(&network_delegate); | 2601 default_context_.set_network_delegate(&network_delegate); |
| 2571 TestDelegate d; | 2602 TestDelegate d; |
| 2572 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2603 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 2573 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2604 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2574 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2605 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2575 DEFAULT_PRIORITY, &d)); | 2606 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2576 req->Start(); | 2607 req->Start(); |
| 2577 | 2608 |
| 2578 base::RunLoop().Run(); | 2609 base::RunLoop().Run(); |
| 2579 | 2610 |
| 2580 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2611 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2581 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2612 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 2582 } | 2613 } |
| 2583 | 2614 |
| 2584 // Verify the cookies weren't saved or updated. | 2615 // Verify the cookies weren't saved or updated. |
| 2585 { | 2616 { |
| 2586 TestNetworkDelegate network_delegate; | 2617 TestNetworkDelegate network_delegate; |
| 2587 default_context_.set_network_delegate(&network_delegate); | 2618 default_context_.set_network_delegate(&network_delegate); |
| 2588 TestDelegate d; | 2619 TestDelegate d; |
| 2589 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2620 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2590 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2621 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2622 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2591 req->Start(); | 2623 req->Start(); |
| 2592 base::RunLoop().Run(); | 2624 base::RunLoop().Run(); |
| 2593 | 2625 |
| 2594 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2626 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2595 == std::string::npos); | 2627 == std::string::npos); |
| 2596 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2628 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2597 != std::string::npos); | 2629 != std::string::npos); |
| 2598 | 2630 |
| 2599 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2631 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2600 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2632 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2601 } | 2633 } |
| 2602 } | 2634 } |
| 2603 | 2635 |
| 2604 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { | 2636 TEST_F(URLRequestTest, DoNotSaveEmptyCookies) { |
| 2605 LocalHttpTestServer test_server; | 2637 LocalHttpTestServer test_server; |
| 2606 ASSERT_TRUE(test_server.Start()); | 2638 ASSERT_TRUE(test_server.Start()); |
| 2607 | 2639 |
| 2608 // Set up an empty cookie. | 2640 // Set up an empty cookie. |
| 2609 { | 2641 { |
| 2610 TestNetworkDelegate network_delegate; | 2642 TestNetworkDelegate network_delegate; |
| 2611 default_context_.set_network_delegate(&network_delegate); | 2643 default_context_.set_network_delegate(&network_delegate); |
| 2612 TestDelegate d; | 2644 TestDelegate d; |
| 2613 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2645 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2614 test_server.GetURL("/set-cookie"), DEFAULT_PRIORITY, &d)); | 2646 test_server.GetURL("/set-cookie"), DEFAULT_PRIORITY, &d, |
| 2647 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2615 req->Start(); | 2648 req->Start(); |
| 2616 base::RunLoop().Run(); | 2649 base::RunLoop().Run(); |
| 2617 | 2650 |
| 2618 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2651 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2619 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2652 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2620 EXPECT_EQ(0, network_delegate.set_cookie_count()); | 2653 EXPECT_EQ(0, network_delegate.set_cookie_count()); |
| 2621 } | 2654 } |
| 2622 } | 2655 } |
| 2623 | 2656 |
| 2624 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { | 2657 TEST_F(URLRequestTest, DoNotSendCookies_ViaPolicy_Async) { |
| 2625 LocalHttpTestServer test_server; | 2658 LocalHttpTestServer test_server; |
| 2626 ASSERT_TRUE(test_server.Start()); | 2659 ASSERT_TRUE(test_server.Start()); |
| 2627 | 2660 |
| 2628 // Set up a cookie. | 2661 // Set up a cookie. |
| 2629 { | 2662 { |
| 2630 TestNetworkDelegate network_delegate; | 2663 TestNetworkDelegate network_delegate; |
| 2631 default_context_.set_network_delegate(&network_delegate); | 2664 default_context_.set_network_delegate(&network_delegate); |
| 2632 TestDelegate d; | 2665 TestDelegate d; |
| 2633 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2666 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2634 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, | 2667 test_server.GetURL("/set-cookie?CookieToNotSend=1"), DEFAULT_PRIORITY, |
| 2635 &d)); | 2668 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2636 req->Start(); | 2669 req->Start(); |
| 2637 base::RunLoop().Run(); | 2670 base::RunLoop().Run(); |
| 2638 | 2671 |
| 2639 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2672 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2640 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2673 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2641 } | 2674 } |
| 2642 | 2675 |
| 2643 // Verify that the cookie is set. | 2676 // Verify that the cookie is set. |
| 2644 { | 2677 { |
| 2645 TestNetworkDelegate network_delegate; | 2678 TestNetworkDelegate network_delegate; |
| 2646 default_context_.set_network_delegate(&network_delegate); | 2679 default_context_.set_network_delegate(&network_delegate); |
| 2647 TestDelegate d; | 2680 TestDelegate d; |
| 2648 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2681 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2649 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2682 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2683 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2650 req->Start(); | 2684 req->Start(); |
| 2651 base::RunLoop().Run(); | 2685 base::RunLoop().Run(); |
| 2652 | 2686 |
| 2653 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") | 2687 EXPECT_TRUE(d.data_received().find("CookieToNotSend=1") |
| 2654 != std::string::npos); | 2688 != std::string::npos); |
| 2655 | 2689 |
| 2656 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2690 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2657 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2691 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2658 } | 2692 } |
| 2659 | 2693 |
| 2660 // Verify that the cookie isn't sent. | 2694 // Verify that the cookie isn't sent. |
| 2661 { | 2695 { |
| 2662 TestNetworkDelegate network_delegate; | 2696 TestNetworkDelegate network_delegate; |
| 2663 default_context_.set_network_delegate(&network_delegate); | 2697 default_context_.set_network_delegate(&network_delegate); |
| 2664 TestDelegate d; | 2698 TestDelegate d; |
| 2665 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); | 2699 network_delegate.set_cookie_options(TestNetworkDelegate::NO_GET_COOKIES); |
| 2666 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2700 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2667 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2701 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2702 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2668 req->Start(); | 2703 req->Start(); |
| 2669 base::RunLoop().Run(); | 2704 base::RunLoop().Run(); |
| 2670 | 2705 |
| 2671 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") | 2706 EXPECT_TRUE(d.data_received().find("Cookie: CookieToNotSend=1") |
| 2672 == std::string::npos); | 2707 == std::string::npos); |
| 2673 | 2708 |
| 2674 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); | 2709 EXPECT_EQ(1, network_delegate.blocked_get_cookies_count()); |
| 2675 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2710 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2676 } | 2711 } |
| 2677 } | 2712 } |
| 2678 | 2713 |
| 2679 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { | 2714 TEST_F(URLRequestTest, DoNotSaveCookies_ViaPolicy_Async) { |
| 2680 LocalHttpTestServer test_server; | 2715 LocalHttpTestServer test_server; |
| 2681 ASSERT_TRUE(test_server.Start()); | 2716 ASSERT_TRUE(test_server.Start()); |
| 2682 | 2717 |
| 2683 // Set up a cookie. | 2718 // Set up a cookie. |
| 2684 { | 2719 { |
| 2685 TestNetworkDelegate network_delegate; | 2720 TestNetworkDelegate network_delegate; |
| 2686 default_context_.set_network_delegate(&network_delegate); | 2721 default_context_.set_network_delegate(&network_delegate); |
| 2687 TestDelegate d; | 2722 TestDelegate d; |
| 2688 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2723 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2689 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, | 2724 test_server.GetURL("/set-cookie?CookieToNotUpdate=2"), DEFAULT_PRIORITY, |
| 2690 &d)); | 2725 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2691 req->Start(); | 2726 req->Start(); |
| 2692 base::RunLoop().Run(); | 2727 base::RunLoop().Run(); |
| 2693 | 2728 |
| 2694 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2729 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2695 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2730 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2696 } | 2731 } |
| 2697 | 2732 |
| 2698 // Try to set-up another cookie and update the previous cookie. | 2733 // Try to set-up another cookie and update the previous cookie. |
| 2699 { | 2734 { |
| 2700 TestNetworkDelegate network_delegate; | 2735 TestNetworkDelegate network_delegate; |
| 2701 default_context_.set_network_delegate(&network_delegate); | 2736 default_context_.set_network_delegate(&network_delegate); |
| 2702 TestDelegate d; | 2737 TestDelegate d; |
| 2703 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); | 2738 network_delegate.set_cookie_options(TestNetworkDelegate::NO_SET_COOKIE); |
| 2704 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2739 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2705 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), | 2740 test_server.GetURL("/set-cookie?CookieToNotSave=1&CookieToNotUpdate=1"), |
| 2706 DEFAULT_PRIORITY, &d)); | 2741 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2707 req->Start(); | 2742 req->Start(); |
| 2708 | 2743 |
| 2709 base::RunLoop().Run(); | 2744 base::RunLoop().Run(); |
| 2710 | 2745 |
| 2711 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2746 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2712 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); | 2747 EXPECT_EQ(2, network_delegate.blocked_set_cookie_count()); |
| 2713 } | 2748 } |
| 2714 | 2749 |
| 2715 // Verify the cookies weren't saved or updated. | 2750 // Verify the cookies weren't saved or updated. |
| 2716 { | 2751 { |
| 2717 TestNetworkDelegate network_delegate; | 2752 TestNetworkDelegate network_delegate; |
| 2718 default_context_.set_network_delegate(&network_delegate); | 2753 default_context_.set_network_delegate(&network_delegate); |
| 2719 TestDelegate d; | 2754 TestDelegate d; |
| 2720 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2755 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2721 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2756 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2757 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2722 req->Start(); | 2758 req->Start(); |
| 2723 base::RunLoop().Run(); | 2759 base::RunLoop().Run(); |
| 2724 | 2760 |
| 2725 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") | 2761 EXPECT_TRUE(d.data_received().find("CookieToNotSave=1") |
| 2726 == std::string::npos); | 2762 == std::string::npos); |
| 2727 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") | 2763 EXPECT_TRUE(d.data_received().find("CookieToNotUpdate=2") |
| 2728 != std::string::npos); | 2764 != std::string::npos); |
| 2729 | 2765 |
| 2730 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2766 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2731 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2767 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2743 const std::string kSubHost = "subdomain.example.test"; | 2779 const std::string kSubHost = "subdomain.example.test"; |
| 2744 const std::string kCrossHost = "cross-origin.test"; | 2780 const std::string kCrossHost = "cross-origin.test"; |
| 2745 | 2781 |
| 2746 // Set up two 'SameSite' cookies on 'example.test' | 2782 // Set up two 'SameSite' cookies on 'example.test' |
| 2747 { | 2783 { |
| 2748 TestDelegate d; | 2784 TestDelegate d; |
| 2749 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2785 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2750 test_server.GetURL(kHost, | 2786 test_server.GetURL(kHost, |
| 2751 "/set-cookie?StrictSameSiteCookie=1;SameSite=Strict&" | 2787 "/set-cookie?StrictSameSiteCookie=1;SameSite=Strict&" |
| 2752 "LaxSameSiteCookie=1;SameSite=Lax"), | 2788 "LaxSameSiteCookie=1;SameSite=Lax"), |
| 2753 DEFAULT_PRIORITY, &d)); | 2789 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2754 req->Start(); | 2790 req->Start(); |
| 2755 base::RunLoop().Run(); | 2791 base::RunLoop().Run(); |
| 2756 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2792 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2757 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2793 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2758 EXPECT_EQ(2, network_delegate.set_cookie_count()); | 2794 EXPECT_EQ(2, network_delegate.set_cookie_count()); |
| 2759 } | 2795 } |
| 2760 | 2796 |
| 2761 // Verify that both cookies are sent for same-site requests. | 2797 // Verify that both cookies are sent for same-site requests. |
| 2762 { | 2798 { |
| 2763 TestDelegate d; | 2799 TestDelegate d; |
| 2764 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2800 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2765 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2801 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2802 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2766 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); | 2803 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); |
| 2767 req->set_initiator(url::Origin(test_server.GetURL(kHost, "/"))); | 2804 req->set_initiator(url::Origin(test_server.GetURL(kHost, "/"))); |
| 2768 req->Start(); | 2805 req->Start(); |
| 2769 base::RunLoop().Run(); | 2806 base::RunLoop().Run(); |
| 2770 | 2807 |
| 2771 EXPECT_NE(std::string::npos, | 2808 EXPECT_NE(std::string::npos, |
| 2772 d.data_received().find("StrictSameSiteCookie=1")); | 2809 d.data_received().find("StrictSameSiteCookie=1")); |
| 2773 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); | 2810 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); |
| 2774 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2811 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2775 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2812 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2776 } | 2813 } |
| 2777 | 2814 |
| 2778 // Verify that both cookies are sent when the request has no initiator (can | 2815 // Verify that both cookies are sent when the request has no initiator (can |
| 2779 // happen for main frame browser-initiated navigations). | 2816 // happen for main frame browser-initiated navigations). |
| 2780 { | 2817 { |
| 2781 TestDelegate d; | 2818 TestDelegate d; |
| 2782 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2819 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2783 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2820 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2821 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2784 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); | 2822 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); |
| 2785 req->Start(); | 2823 req->Start(); |
| 2786 base::RunLoop().Run(); | 2824 base::RunLoop().Run(); |
| 2787 | 2825 |
| 2788 EXPECT_NE(std::string::npos, | 2826 EXPECT_NE(std::string::npos, |
| 2789 d.data_received().find("StrictSameSiteCookie=1")); | 2827 d.data_received().find("StrictSameSiteCookie=1")); |
| 2790 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); | 2828 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); |
| 2791 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2829 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2792 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2830 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2793 } | 2831 } |
| 2794 | 2832 |
| 2795 // Verify that both cookies are sent for same-registrable-domain requests. | 2833 // Verify that both cookies are sent for same-registrable-domain requests. |
| 2796 { | 2834 { |
| 2797 TestDelegate d; | 2835 TestDelegate d; |
| 2798 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2836 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2799 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2837 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2838 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2800 req->set_first_party_for_cookies(test_server.GetURL(kSubHost, "/")); | 2839 req->set_first_party_for_cookies(test_server.GetURL(kSubHost, "/")); |
| 2801 req->set_initiator(url::Origin(test_server.GetURL(kSubHost, "/"))); | 2840 req->set_initiator(url::Origin(test_server.GetURL(kSubHost, "/"))); |
| 2802 req->Start(); | 2841 req->Start(); |
| 2803 base::RunLoop().Run(); | 2842 base::RunLoop().Run(); |
| 2804 | 2843 |
| 2805 EXPECT_NE(std::string::npos, | 2844 EXPECT_NE(std::string::npos, |
| 2806 d.data_received().find("StrictSameSiteCookie=1")); | 2845 d.data_received().find("StrictSameSiteCookie=1")); |
| 2807 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); | 2846 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); |
| 2808 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2847 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2809 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2848 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2810 } | 2849 } |
| 2811 | 2850 |
| 2812 // Verify that neither cookie is not sent for cross-site requests. | 2851 // Verify that neither cookie is not sent for cross-site requests. |
| 2813 { | 2852 { |
| 2814 TestDelegate d; | 2853 TestDelegate d; |
| 2815 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2854 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2816 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2855 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2856 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2817 req->set_first_party_for_cookies(test_server.GetURL(kCrossHost, "/")); | 2857 req->set_first_party_for_cookies(test_server.GetURL(kCrossHost, "/")); |
| 2818 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); | 2858 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); |
| 2819 req->Start(); | 2859 req->Start(); |
| 2820 base::RunLoop().Run(); | 2860 base::RunLoop().Run(); |
| 2821 | 2861 |
| 2822 EXPECT_EQ(std::string::npos, | 2862 EXPECT_EQ(std::string::npos, |
| 2823 d.data_received().find("StrictSameSiteCookie=1")); | 2863 d.data_received().find("StrictSameSiteCookie=1")); |
| 2824 EXPECT_EQ(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); | 2864 EXPECT_EQ(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); |
| 2825 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2865 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2826 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2866 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2827 } | 2867 } |
| 2828 | 2868 |
| 2829 // Verify that the lax cookie is sent for cross-site initiators when the | 2869 // Verify that the lax cookie is sent for cross-site initiators when the |
| 2830 // method is "safe". | 2870 // method is "safe". |
| 2831 { | 2871 { |
| 2832 TestDelegate d; | 2872 TestDelegate d; |
| 2833 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2873 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2834 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2874 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2875 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2835 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); | 2876 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); |
| 2836 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); | 2877 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); |
| 2837 req->set_method("GET"); | 2878 req->set_method("GET"); |
| 2838 req->Start(); | 2879 req->Start(); |
| 2839 base::RunLoop().Run(); | 2880 base::RunLoop().Run(); |
| 2840 | 2881 |
| 2841 EXPECT_EQ(std::string::npos, | 2882 EXPECT_EQ(std::string::npos, |
| 2842 d.data_received().find("StrictSameSiteCookie=1")); | 2883 d.data_received().find("StrictSameSiteCookie=1")); |
| 2843 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); | 2884 EXPECT_NE(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); |
| 2844 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2885 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2845 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2886 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2846 } | 2887 } |
| 2847 | 2888 |
| 2848 // Verify that neither cookie is sent for cross-site initiators when the | 2889 // Verify that neither cookie is sent for cross-site initiators when the |
| 2849 // method is unsafe (e.g. POST). | 2890 // method is unsafe (e.g. POST). |
| 2850 { | 2891 { |
| 2851 TestDelegate d; | 2892 TestDelegate d; |
| 2852 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 2893 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 2853 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2894 test_server.GetURL(kHost, "/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2895 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2854 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); | 2896 req->set_first_party_for_cookies(test_server.GetURL(kHost, "/")); |
| 2855 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); | 2897 req->set_initiator(url::Origin(test_server.GetURL(kCrossHost, "/"))); |
| 2856 req->set_method("POST"); | 2898 req->set_method("POST"); |
| 2857 req->Start(); | 2899 req->Start(); |
| 2858 base::RunLoop().Run(); | 2900 base::RunLoop().Run(); |
| 2859 | 2901 |
| 2860 EXPECT_EQ(std::string::npos, | 2902 EXPECT_EQ(std::string::npos, |
| 2861 d.data_received().find("StrictSameSiteCookie=1")); | 2903 d.data_received().find("StrictSameSiteCookie=1")); |
| 2862 EXPECT_EQ(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); | 2904 EXPECT_EQ(std::string::npos, d.data_received().find("LaxSameSiteCookie=1")); |
| 2863 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2905 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 2879 TestNetworkDelegate network_delegate; | 2921 TestNetworkDelegate network_delegate; |
| 2880 TestURLRequestContext context(true); | 2922 TestURLRequestContext context(true); |
| 2881 context.set_network_delegate(&network_delegate); | 2923 context.set_network_delegate(&network_delegate); |
| 2882 context.Init(); | 2924 context.Init(); |
| 2883 | 2925 |
| 2884 // Try to set a Secure __Secure- cookie. | 2926 // Try to set a Secure __Secure- cookie. |
| 2885 { | 2927 { |
| 2886 TestDelegate d; | 2928 TestDelegate d; |
| 2887 std::unique_ptr<URLRequest> req(context.CreateRequest( | 2929 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 2888 http_server.GetURL("/set-cookie?__Secure-nonsecure-origin=1;Secure"), | 2930 http_server.GetURL("/set-cookie?__Secure-nonsecure-origin=1;Secure"), |
| 2889 DEFAULT_PRIORITY, &d)); | 2931 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2890 req->Start(); | 2932 req->Start(); |
| 2891 base::RunLoop().Run(); | 2933 base::RunLoop().Run(); |
| 2892 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2934 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2893 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2935 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2894 } | 2936 } |
| 2895 | 2937 |
| 2896 // Verify that the cookie is not set. | 2938 // Verify that the cookie is not set. |
| 2897 { | 2939 { |
| 2898 TestDelegate d; | 2940 TestDelegate d; |
| 2899 std::unique_ptr<URLRequest> req(context.CreateRequest( | 2941 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 2900 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2942 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2943 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2901 req->Start(); | 2944 req->Start(); |
| 2902 base::RunLoop().Run(); | 2945 base::RunLoop().Run(); |
| 2903 | 2946 |
| 2904 EXPECT_EQ(d.data_received().find("__Secure-nonsecure-origin=1"), | 2947 EXPECT_EQ(d.data_received().find("__Secure-nonsecure-origin=1"), |
| 2905 std::string::npos); | 2948 std::string::npos); |
| 2906 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2949 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2907 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2950 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2908 } | 2951 } |
| 2909 } | 2952 } |
| 2910 | 2953 |
| 2911 TEST_F(URLRequestTest, SecureCookiePrefixNonsecure) { | 2954 TEST_F(URLRequestTest, SecureCookiePrefixNonsecure) { |
| 2912 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); | 2955 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); |
| 2913 https_server.AddDefaultHandlers( | 2956 https_server.AddDefaultHandlers( |
| 2914 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 2957 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 2915 ASSERT_TRUE(https_server.Start()); | 2958 ASSERT_TRUE(https_server.Start()); |
| 2916 | 2959 |
| 2917 TestNetworkDelegate network_delegate; | 2960 TestNetworkDelegate network_delegate; |
| 2918 TestURLRequestContext context(true); | 2961 TestURLRequestContext context(true); |
| 2919 context.set_network_delegate(&network_delegate); | 2962 context.set_network_delegate(&network_delegate); |
| 2920 context.Init(); | 2963 context.Init(); |
| 2921 | 2964 |
| 2922 // Try to set a non-Secure __Secure- cookie. | 2965 // Try to set a non-Secure __Secure- cookie. |
| 2923 { | 2966 { |
| 2924 TestDelegate d; | 2967 TestDelegate d; |
| 2925 std::unique_ptr<URLRequest> req( | 2968 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 2926 context.CreateRequest(https_server.GetURL("/set-cookie?__Secure-foo=1"), | 2969 https_server.GetURL("/set-cookie?__Secure-foo=1"), DEFAULT_PRIORITY, &d, |
| 2927 DEFAULT_PRIORITY, &d)); | 2970 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2928 req->Start(); | 2971 req->Start(); |
| 2929 base::RunLoop().Run(); | 2972 base::RunLoop().Run(); |
| 2930 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2973 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2931 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2974 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2932 } | 2975 } |
| 2933 | 2976 |
| 2934 // Verify that the cookie is not set. | 2977 // Verify that the cookie is not set. |
| 2935 { | 2978 { |
| 2936 TestDelegate d; | 2979 TestDelegate d; |
| 2937 std::unique_ptr<URLRequest> req(context.CreateRequest( | 2980 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 2938 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 2981 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 2982 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2939 req->Start(); | 2983 req->Start(); |
| 2940 base::RunLoop().Run(); | 2984 base::RunLoop().Run(); |
| 2941 | 2985 |
| 2942 EXPECT_EQ(d.data_received().find("__Secure-foo=1"), std::string::npos); | 2986 EXPECT_EQ(d.data_received().find("__Secure-foo=1"), std::string::npos); |
| 2943 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 2987 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2944 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 2988 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2945 } | 2989 } |
| 2946 } | 2990 } |
| 2947 | 2991 |
| 2948 TEST_F(URLRequestTest, SecureCookiePrefixSecure) { | 2992 TEST_F(URLRequestTest, SecureCookiePrefixSecure) { |
| 2949 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); | 2993 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); |
| 2950 https_server.AddDefaultHandlers( | 2994 https_server.AddDefaultHandlers( |
| 2951 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 2995 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 2952 ASSERT_TRUE(https_server.Start()); | 2996 ASSERT_TRUE(https_server.Start()); |
| 2953 | 2997 |
| 2954 TestNetworkDelegate network_delegate; | 2998 TestNetworkDelegate network_delegate; |
| 2955 TestURLRequestContext context(true); | 2999 TestURLRequestContext context(true); |
| 2956 context.set_network_delegate(&network_delegate); | 3000 context.set_network_delegate(&network_delegate); |
| 2957 context.Init(); | 3001 context.Init(); |
| 2958 | 3002 |
| 2959 // Try to set a Secure __Secure- cookie. | 3003 // Try to set a Secure __Secure- cookie. |
| 2960 { | 3004 { |
| 2961 TestDelegate d; | 3005 TestDelegate d; |
| 2962 std::unique_ptr<URLRequest> req(context.CreateRequest( | 3006 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 2963 https_server.GetURL("/set-cookie?__Secure-bar=1;Secure"), | 3007 https_server.GetURL("/set-cookie?__Secure-bar=1;Secure"), |
| 2964 DEFAULT_PRIORITY, &d)); | 3008 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2965 req->Start(); | 3009 req->Start(); |
| 2966 base::RunLoop().Run(); | 3010 base::RunLoop().Run(); |
| 2967 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3011 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2968 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3012 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2969 } | 3013 } |
| 2970 | 3014 |
| 2971 // Verify that the cookie is set. | 3015 // Verify that the cookie is set. |
| 2972 { | 3016 { |
| 2973 TestDelegate d; | 3017 TestDelegate d; |
| 2974 std::unique_ptr<URLRequest> req(context.CreateRequest( | 3018 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 2975 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 3019 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 3020 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 2976 req->Start(); | 3021 req->Start(); |
| 2977 base::RunLoop().Run(); | 3022 base::RunLoop().Run(); |
| 2978 | 3023 |
| 2979 EXPECT_NE(d.data_received().find("__Secure-bar=1"), std::string::npos); | 3024 EXPECT_NE(d.data_received().find("__Secure-bar=1"), std::string::npos); |
| 2980 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3025 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 2981 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3026 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 2982 } | 3027 } |
| 2983 } | 3028 } |
| 2984 | 3029 |
| 2985 // Tests that secure cookies can't be set on non-secure origins if strict secure | 3030 // Tests that secure cookies can't be set on non-secure origins if strict secure |
| (...skipping 11 matching lines...) Expand all Loading... |
| 2997 TestExperimentalFeaturesNetworkDelegate network_delegate; | 3042 TestExperimentalFeaturesNetworkDelegate network_delegate; |
| 2998 TestURLRequestContext context(true); | 3043 TestURLRequestContext context(true); |
| 2999 context.set_network_delegate(&network_delegate); | 3044 context.set_network_delegate(&network_delegate); |
| 3000 context.Init(); | 3045 context.Init(); |
| 3001 | 3046 |
| 3002 // Try to set a Secure cookie, with experimental features enabled. | 3047 // Try to set a Secure cookie, with experimental features enabled. |
| 3003 { | 3048 { |
| 3004 TestDelegate d; | 3049 TestDelegate d; |
| 3005 std::unique_ptr<URLRequest> req(context.CreateRequest( | 3050 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 3006 http_server.GetURL("/set-cookie?nonsecure-origin=1;Secure"), | 3051 http_server.GetURL("/set-cookie?nonsecure-origin=1;Secure"), |
| 3007 DEFAULT_PRIORITY, &d)); | 3052 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3008 req->Start(); | 3053 req->Start(); |
| 3009 base::RunLoop().Run(); | 3054 base::RunLoop().Run(); |
| 3010 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3055 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3011 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3056 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3012 } | 3057 } |
| 3013 | 3058 |
| 3014 // Verify that the cookie is not set. | 3059 // Verify that the cookie is not set. |
| 3015 { | 3060 { |
| 3016 TestDelegate d; | 3061 TestDelegate d; |
| 3017 std::unique_ptr<URLRequest> req(context.CreateRequest( | 3062 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 3018 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 3063 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 3064 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3019 req->Start(); | 3065 req->Start(); |
| 3020 base::RunLoop().Run(); | 3066 base::RunLoop().Run(); |
| 3021 | 3067 |
| 3022 EXPECT_EQ(d.data_received().find("nonsecure-origin=1"), std::string::npos); | 3068 EXPECT_EQ(d.data_received().find("nonsecure-origin=1"), std::string::npos); |
| 3023 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3069 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3024 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3070 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3025 } | 3071 } |
| 3026 } | 3072 } |
| 3027 | 3073 |
| 3028 // Tests that secure cookies can be set on secure origins even if strict secure | 3074 // Tests that secure cookies can be set on secure origins even if strict secure |
| 3029 // cookies are enabled. | 3075 // cookies are enabled. |
| 3030 TEST_F(URLRequestTest, StrictSecureCookiesOnSecureOrigin) { | 3076 TEST_F(URLRequestTest, StrictSecureCookiesOnSecureOrigin) { |
| 3031 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); | 3077 EmbeddedTestServer https_server(EmbeddedTestServer::TYPE_HTTPS); |
| 3032 https_server.AddDefaultHandlers( | 3078 https_server.AddDefaultHandlers( |
| 3033 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 3079 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 3034 ASSERT_TRUE(https_server.Start()); | 3080 ASSERT_TRUE(https_server.Start()); |
| 3035 | 3081 |
| 3036 TestExperimentalFeaturesNetworkDelegate network_delegate; | 3082 TestExperimentalFeaturesNetworkDelegate network_delegate; |
| 3037 TestURLRequestContext context(true); | 3083 TestURLRequestContext context(true); |
| 3038 context.set_network_delegate(&network_delegate); | 3084 context.set_network_delegate(&network_delegate); |
| 3039 context.Init(); | 3085 context.Init(); |
| 3040 | 3086 |
| 3041 // Try to set a Secure cookie, with experimental features enabled. | 3087 // Try to set a Secure cookie, with experimental features enabled. |
| 3042 { | 3088 { |
| 3043 TestDelegate d; | 3089 TestDelegate d; |
| 3044 std::unique_ptr<URLRequest> req(context.CreateRequest( | 3090 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 3045 https_server.GetURL("/set-cookie?secure-origin=1;Secure"), | 3091 https_server.GetURL("/set-cookie?secure-origin=1;Secure"), |
| 3046 DEFAULT_PRIORITY, &d)); | 3092 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3047 req->Start(); | 3093 req->Start(); |
| 3048 base::RunLoop().Run(); | 3094 base::RunLoop().Run(); |
| 3049 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3095 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3050 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3096 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3051 } | 3097 } |
| 3052 | 3098 |
| 3053 // Verify that the cookie is not set. | 3099 // Verify that the cookie is not set. |
| 3054 { | 3100 { |
| 3055 TestDelegate d; | 3101 TestDelegate d; |
| 3056 std::unique_ptr<URLRequest> req(context.CreateRequest( | 3102 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 3057 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 3103 https_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 3104 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3058 req->Start(); | 3105 req->Start(); |
| 3059 base::RunLoop().Run(); | 3106 base::RunLoop().Run(); |
| 3060 | 3107 |
| 3061 EXPECT_NE(d.data_received().find("secure-origin=1"), std::string::npos); | 3108 EXPECT_NE(d.data_received().find("secure-origin=1"), std::string::npos); |
| 3062 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); | 3109 EXPECT_EQ(0, network_delegate.blocked_get_cookies_count()); |
| 3063 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); | 3110 EXPECT_EQ(0, network_delegate.blocked_set_cookie_count()); |
| 3064 } | 3111 } |
| 3065 } | 3112 } |
| 3066 | 3113 |
| 3067 // Tests that a request is cancelled while entering suspend mode. Uses mocks | 3114 // Tests that a request is cancelled while entering suspend mode. Uses mocks |
| 3068 // rather than a spawned test server because the connection used to talk to | 3115 // rather than a spawned test server because the connection used to talk to |
| 3069 // the test server is affected by entering suspend mode on Android. | 3116 // the test server is affected by entering suspend mode on Android. |
| 3070 TEST_F(URLRequestTest, CancelOnSuspend) { | 3117 TEST_F(URLRequestTest, CancelOnSuspend) { |
| 3071 TestPowerMonitorSource* power_monitor_source = new TestPowerMonitorSource(); | 3118 TestPowerMonitorSource* power_monitor_source = new TestPowerMonitorSource(); |
| 3072 base::PowerMonitor power_monitor(base::WrapUnique(power_monitor_source)); | 3119 base::PowerMonitor power_monitor(base::WrapUnique(power_monitor_source)); |
| 3073 | 3120 |
| 3074 URLRequestFailedJob::AddUrlHandler(); | 3121 URLRequestFailedJob::AddUrlHandler(); |
| 3075 | 3122 |
| 3076 TestDelegate d; | 3123 TestDelegate d; |
| 3077 // Request that just hangs. | 3124 // Request that just hangs. |
| 3078 GURL url(URLRequestFailedJob::GetMockHttpUrl(ERR_IO_PENDING)); | 3125 GURL url(URLRequestFailedJob::GetMockHttpUrl(ERR_IO_PENDING)); |
| 3079 std::unique_ptr<URLRequest> r( | 3126 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3080 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3127 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3081 r->Start(); | 3128 r->Start(); |
| 3082 | 3129 |
| 3083 power_monitor_source->Suspend(); | 3130 power_monitor_source->Suspend(); |
| 3084 // Wait for the suspend notification to cause the request to fail. | 3131 // Wait for the suspend notification to cause the request to fail. |
| 3085 base::RunLoop().Run(); | 3132 base::RunLoop().Run(); |
| 3086 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 3133 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 3087 EXPECT_TRUE(d.request_failed()); | 3134 EXPECT_TRUE(d.request_failed()); |
| 3088 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 3135 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
| 3089 | 3136 |
| 3090 URLRequestFilter::GetInstance()->ClearHandlers(); | 3137 URLRequestFilter::GetInstance()->ClearHandlers(); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3143 ASSERT_TRUE(test_server.Start()); | 3190 ASSERT_TRUE(test_server.Start()); |
| 3144 | 3191 |
| 3145 // Set up an expired cookie. | 3192 // Set up an expired cookie. |
| 3146 { | 3193 { |
| 3147 TestNetworkDelegate network_delegate; | 3194 TestNetworkDelegate network_delegate; |
| 3148 default_context_.set_network_delegate(&network_delegate); | 3195 default_context_.set_network_delegate(&network_delegate); |
| 3149 TestDelegate d; | 3196 TestDelegate d; |
| 3150 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 3197 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3151 test_server.GetURL( | 3198 test_server.GetURL( |
| 3152 "/set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 3199 "/set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), |
| 3153 DEFAULT_PRIORITY, &d)); | 3200 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3154 req->Start(); | 3201 req->Start(); |
| 3155 base::RunLoop().Run(); | 3202 base::RunLoop().Run(); |
| 3156 } | 3203 } |
| 3157 // Verify that the cookie is not set. | 3204 // Verify that the cookie is not set. |
| 3158 { | 3205 { |
| 3159 TestNetworkDelegate network_delegate; | 3206 TestNetworkDelegate network_delegate; |
| 3160 default_context_.set_network_delegate(&network_delegate); | 3207 default_context_.set_network_delegate(&network_delegate); |
| 3161 TestDelegate d; | 3208 TestDelegate d; |
| 3162 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 3209 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3163 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 3210 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 3211 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3164 req->Start(); | 3212 req->Start(); |
| 3165 base::RunLoop().Run(); | 3213 base::RunLoop().Run(); |
| 3166 | 3214 |
| 3167 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); | 3215 EXPECT_TRUE(d.data_received().find("StillGood=1") == std::string::npos); |
| 3168 } | 3216 } |
| 3169 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. | 3217 // Set up a cookie with clock skew and "UTC" HTTP Date timezone specifier. |
| 3170 { | 3218 { |
| 3171 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); | 3219 FixedDateNetworkDelegate network_delegate("18-Apr-1977 22:49:13 UTC"); |
| 3172 default_context_.set_network_delegate(&network_delegate); | 3220 default_context_.set_network_delegate(&network_delegate); |
| 3173 TestDelegate d; | 3221 TestDelegate d; |
| 3174 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 3222 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3175 test_server.GetURL( | 3223 test_server.GetURL( |
| 3176 "/set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), | 3224 "/set-cookie?StillGood=1;expires=Mon,18-Apr-1977,22:50:13,GMT"), |
| 3177 DEFAULT_PRIORITY, &d)); | 3225 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3178 req->Start(); | 3226 req->Start(); |
| 3179 base::RunLoop().Run(); | 3227 base::RunLoop().Run(); |
| 3180 } | 3228 } |
| 3181 // Verify that the cookie is set. | 3229 // Verify that the cookie is set. |
| 3182 { | 3230 { |
| 3183 TestNetworkDelegate network_delegate; | 3231 TestNetworkDelegate network_delegate; |
| 3184 default_context_.set_network_delegate(&network_delegate); | 3232 default_context_.set_network_delegate(&network_delegate); |
| 3185 TestDelegate d; | 3233 TestDelegate d; |
| 3186 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 3234 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3187 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d)); | 3235 test_server.GetURL("/echoheader?Cookie"), DEFAULT_PRIORITY, &d, |
| 3236 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3188 req->Start(); | 3237 req->Start(); |
| 3189 base::RunLoop().Run(); | 3238 base::RunLoop().Run(); |
| 3190 | 3239 |
| 3191 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); | 3240 EXPECT_TRUE(d.data_received().find("StillGood=1") != std::string::npos); |
| 3192 } | 3241 } |
| 3193 } | 3242 } |
| 3194 | 3243 |
| 3195 | 3244 |
| 3196 // Check that it is impossible to change the referrer in the extra headers of | 3245 // Check that it is impossible to change the referrer in the extra headers of |
| 3197 // an URLRequest. | 3246 // an URLRequest. |
| 3198 TEST_F(URLRequestTest, DoNotOverrideReferrer) { | 3247 TEST_F(URLRequestTest, DoNotOverrideReferrer) { |
| 3199 LocalHttpTestServer test_server; | 3248 LocalHttpTestServer test_server; |
| 3200 ASSERT_TRUE(test_server.Start()); | 3249 ASSERT_TRUE(test_server.Start()); |
| 3201 | 3250 |
| 3202 // If extra headers contain referer and the request contains a referer, | 3251 // If extra headers contain referer and the request contains a referer, |
| 3203 // only the latter shall be respected. | 3252 // only the latter shall be respected. |
| 3204 { | 3253 { |
| 3205 TestDelegate d; | 3254 TestDelegate d; |
| 3206 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 3255 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3207 test_server.GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 3256 test_server.GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d, |
| 3257 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3208 req->SetReferrer("http://foo.com/"); | 3258 req->SetReferrer("http://foo.com/"); |
| 3209 | 3259 |
| 3210 HttpRequestHeaders headers; | 3260 HttpRequestHeaders headers; |
| 3211 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 3261 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 3212 req->SetExtraRequestHeaders(headers); | 3262 req->SetExtraRequestHeaders(headers); |
| 3213 | 3263 |
| 3214 req->Start(); | 3264 req->Start(); |
| 3215 base::RunLoop().Run(); | 3265 base::RunLoop().Run(); |
| 3216 | 3266 |
| 3217 EXPECT_EQ("http://foo.com/", d.data_received()); | 3267 EXPECT_EQ("http://foo.com/", d.data_received()); |
| 3218 } | 3268 } |
| 3219 | 3269 |
| 3220 // If extra headers contain a referer but the request does not, no referer | 3270 // If extra headers contain a referer but the request does not, no referer |
| 3221 // shall be sent in the header. | 3271 // shall be sent in the header. |
| 3222 { | 3272 { |
| 3223 TestDelegate d; | 3273 TestDelegate d; |
| 3224 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 3274 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3225 test_server.GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 3275 test_server.GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d, |
| 3276 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3226 | 3277 |
| 3227 HttpRequestHeaders headers; | 3278 HttpRequestHeaders headers; |
| 3228 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); | 3279 headers.SetHeader(HttpRequestHeaders::kReferer, "http://bar.com/"); |
| 3229 req->SetExtraRequestHeaders(headers); | 3280 req->SetExtraRequestHeaders(headers); |
| 3230 req->SetLoadFlags(LOAD_VALIDATE_CACHE); | 3281 req->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 3231 | 3282 |
| 3232 req->Start(); | 3283 req->Start(); |
| 3233 base::RunLoop().Run(); | 3284 base::RunLoop().Run(); |
| 3234 | 3285 |
| 3235 EXPECT_EQ("None", d.data_received()); | 3286 EXPECT_EQ("None", d.data_received()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3247 // request, after redirection. | 3298 // request, after redirection. |
| 3248 // If |include_data| is true, data is uploaded with the request. The | 3299 // If |include_data| is true, data is uploaded with the request. The |
| 3249 // response body is expected to match it exactly, if and only if | 3300 // response body is expected to match it exactly, if and only if |
| 3250 // |request_method| == |redirect_method|. | 3301 // |request_method| == |redirect_method|. |
| 3251 void HTTPRedirectMethodTest(const GURL& redirect_url, | 3302 void HTTPRedirectMethodTest(const GURL& redirect_url, |
| 3252 const std::string& request_method, | 3303 const std::string& request_method, |
| 3253 const std::string& redirect_method, | 3304 const std::string& redirect_method, |
| 3254 bool include_data) { | 3305 bool include_data) { |
| 3255 static const char kData[] = "hello world"; | 3306 static const char kData[] = "hello world"; |
| 3256 TestDelegate d; | 3307 TestDelegate d; |
| 3257 std::unique_ptr<URLRequest> req( | 3308 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3258 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 3309 redirect_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3259 req->set_method(request_method); | 3310 req->set_method(request_method); |
| 3260 if (include_data) { | 3311 if (include_data) { |
| 3261 req->set_upload(CreateSimpleUploadData(kData)); | 3312 req->set_upload(CreateSimpleUploadData(kData)); |
| 3262 HttpRequestHeaders headers; | 3313 HttpRequestHeaders headers; |
| 3263 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3314 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 3264 base::SizeTToString(arraysize(kData) - 1)); | 3315 base::SizeTToString(arraysize(kData) - 1)); |
| 3265 headers.SetHeader(HttpRequestHeaders::kContentType, "text/plain"); | 3316 headers.SetHeader(HttpRequestHeaders::kContentType, "text/plain"); |
| 3266 req->SetExtraRequestHeaders(headers); | 3317 req->SetExtraRequestHeaders(headers); |
| 3267 } | 3318 } |
| 3268 req->Start(); | 3319 req->Start(); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3292 // |request_method| is the method to use for the initial request. | 3343 // |request_method| is the method to use for the initial request. |
| 3293 // |redirect_method| is the method that is expected to be used for the second | 3344 // |redirect_method| is the method that is expected to be used for the second |
| 3294 // request, after redirection. | 3345 // request, after redirection. |
| 3295 // |origin_value| is the expected value for the Origin header after | 3346 // |origin_value| is the expected value for the Origin header after |
| 3296 // redirection. If empty, expects that there will be no Origin header. | 3347 // redirection. If empty, expects that there will be no Origin header. |
| 3297 void HTTPRedirectOriginHeaderTest(const GURL& redirect_url, | 3348 void HTTPRedirectOriginHeaderTest(const GURL& redirect_url, |
| 3298 const std::string& request_method, | 3349 const std::string& request_method, |
| 3299 const std::string& redirect_method, | 3350 const std::string& redirect_method, |
| 3300 const std::string& origin_value) { | 3351 const std::string& origin_value) { |
| 3301 TestDelegate d; | 3352 TestDelegate d; |
| 3302 std::unique_ptr<URLRequest> req( | 3353 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 3303 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 3354 redirect_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3304 req->set_method(request_method); | 3355 req->set_method(request_method); |
| 3305 req->SetExtraRequestHeaderByName(HttpRequestHeaders::kOrigin, | 3356 req->SetExtraRequestHeaderByName(HttpRequestHeaders::kOrigin, |
| 3306 redirect_url.GetOrigin().spec(), false); | 3357 redirect_url.GetOrigin().spec(), false); |
| 3307 req->Start(); | 3358 req->Start(); |
| 3308 | 3359 |
| 3309 base::RunLoop().Run(); | 3360 base::RunLoop().Run(); |
| 3310 | 3361 |
| 3311 EXPECT_EQ(redirect_method, req->method()); | 3362 EXPECT_EQ(redirect_method, req->method()); |
| 3312 // Note that there is no check for request success here because, for | 3363 // Note that there is no check for request success here because, for |
| 3313 // purposes of testing, the request very well may fail. For example, if the | 3364 // purposes of testing, the request very well may fail. For example, if the |
| (...skipping 26 matching lines...) Expand all Loading... |
| 3340 *ptr++ = marker; | 3391 *ptr++ = marker; |
| 3341 if (++marker > 'z') | 3392 if (++marker > 'z') |
| 3342 marker = 'a'; | 3393 marker = 'a'; |
| 3343 } | 3394 } |
| 3344 } | 3395 } |
| 3345 uploadBytes[kMsgSize] = '\0'; | 3396 uploadBytes[kMsgSize] = '\0'; |
| 3346 | 3397 |
| 3347 for (int i = 0; i < kIterations; ++i) { | 3398 for (int i = 0; i < kIterations; ++i) { |
| 3348 TestDelegate d; | 3399 TestDelegate d; |
| 3349 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 3400 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3350 test_server_.GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 3401 test_server_.GetURL("/echo"), DEFAULT_PRIORITY, &d, |
| 3402 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3351 r->set_method(method.c_str()); | 3403 r->set_method(method.c_str()); |
| 3352 | 3404 |
| 3353 r->set_upload(CreateSimpleUploadData(uploadBytes)); | 3405 r->set_upload(CreateSimpleUploadData(uploadBytes)); |
| 3354 | 3406 |
| 3355 r->Start(); | 3407 r->Start(); |
| 3356 EXPECT_TRUE(r->is_pending()); | 3408 EXPECT_TRUE(r->is_pending()); |
| 3357 | 3409 |
| 3358 base::RunLoop().Run(); | 3410 base::RunLoop().Run(); |
| 3359 | 3411 |
| 3360 ASSERT_EQ(1, d.response_started_count()) << "request failed. Error: " | 3412 ASSERT_EQ(1, d.response_started_count()) << "request failed. Error: " |
| 3361 << d.request_status(); | 3413 << d.request_status(); |
| 3362 | 3414 |
| 3363 EXPECT_FALSE(d.received_data_before_response()); | 3415 EXPECT_FALSE(d.received_data_before_response()); |
| 3364 EXPECT_EQ(uploadBytes, d.data_received()); | 3416 EXPECT_EQ(uploadBytes, d.data_received()); |
| 3365 } | 3417 } |
| 3366 delete[] uploadBytes; | 3418 delete[] uploadBytes; |
| 3367 } | 3419 } |
| 3368 | 3420 |
| 3369 bool DoManyCookiesRequest(int num_cookies) { | 3421 bool DoManyCookiesRequest(int num_cookies) { |
| 3370 TestDelegate d; | 3422 TestDelegate d; |
| 3371 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 3423 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3372 test_server_.GetURL("/set-many-cookies?" + | 3424 test_server_.GetURL("/set-many-cookies?" + |
| 3373 base::IntToString(num_cookies)), | 3425 base::IntToString(num_cookies)), |
| 3374 DEFAULT_PRIORITY, &d)); | 3426 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3375 | 3427 |
| 3376 r->Start(); | 3428 r->Start(); |
| 3377 EXPECT_TRUE(r->is_pending()); | 3429 EXPECT_TRUE(r->is_pending()); |
| 3378 | 3430 |
| 3379 base::RunLoop().Run(); | 3431 base::RunLoop().Run(); |
| 3380 | 3432 |
| 3381 if (d.request_status() != OK) { | 3433 if (d.request_status() != OK) { |
| 3382 EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, d.request_status()); | 3434 EXPECT_EQ(ERR_RESPONSE_HEADERS_TOO_BIG, d.request_status()); |
| 3383 return false; | 3435 return false; |
| 3384 } | 3436 } |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3478 SpawnedTestServer::SSLOptions ssl_options; | 3530 SpawnedTestServer::SSLOptions ssl_options; |
| 3479 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); | 3531 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); |
| 3480 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 3532 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 3481 ssl_options, | 3533 ssl_options, |
| 3482 base::FilePath(kTestFilePath)); | 3534 base::FilePath(kTestFilePath)); |
| 3483 ASSERT_TRUE(https_test_server.Start()); | 3535 ASSERT_TRUE(https_test_server.Start()); |
| 3484 | 3536 |
| 3485 TestDelegate d; | 3537 TestDelegate d; |
| 3486 { | 3538 { |
| 3487 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 3539 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3488 https_test_server.GetURL("tokbind-ekm"), DEFAULT_PRIORITY, &d)); | 3540 https_test_server.GetURL("tokbind-ekm"), DEFAULT_PRIORITY, &d, |
| 3541 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3489 r->Start(); | 3542 r->Start(); |
| 3490 EXPECT_TRUE(r->is_pending()); | 3543 EXPECT_TRUE(r->is_pending()); |
| 3491 | 3544 |
| 3492 base::RunLoop().Run(); | 3545 base::RunLoop().Run(); |
| 3493 | 3546 |
| 3494 EXPECT_EQ(OK, d.request_status()); | 3547 EXPECT_EQ(OK, d.request_status()); |
| 3495 | 3548 |
| 3496 HttpRequestHeaders headers; | 3549 HttpRequestHeaders headers; |
| 3497 std::string token_binding_header, token_binding_message; | 3550 std::string token_binding_header, token_binding_message; |
| 3498 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); | 3551 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 3521 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); | 3574 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); |
| 3522 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 3575 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 3523 ssl_options, | 3576 ssl_options, |
| 3524 base::FilePath(kTestFilePath)); | 3577 base::FilePath(kTestFilePath)); |
| 3525 ASSERT_TRUE(https_test_server.Start()); | 3578 ASSERT_TRUE(https_test_server.Start()); |
| 3526 | 3579 |
| 3527 TestDelegate d; | 3580 TestDelegate d; |
| 3528 { | 3581 { |
| 3529 GURL redirect_url = | 3582 GURL redirect_url = |
| 3530 https_test_server.GetURL("forward-tokbind?/tokbind-ekm"); | 3583 https_test_server.GetURL("forward-tokbind?/tokbind-ekm"); |
| 3531 std::unique_ptr<URLRequest> r( | 3584 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3532 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 3585 redirect_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3533 r->Start(); | 3586 r->Start(); |
| 3534 EXPECT_TRUE(r->is_pending()); | 3587 EXPECT_TRUE(r->is_pending()); |
| 3535 | 3588 |
| 3536 base::RunLoop().Run(); | 3589 base::RunLoop().Run(); |
| 3537 | 3590 |
| 3538 EXPECT_EQ(OK, d.request_status()); | 3591 EXPECT_EQ(OK, d.request_status()); |
| 3539 | 3592 |
| 3540 HttpRequestHeaders headers; | 3593 HttpRequestHeaders headers; |
| 3541 std::string token_binding_header, token_binding_message; | 3594 std::string token_binding_header, token_binding_message; |
| 3542 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); | 3595 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3576 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); | 3629 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); |
| 3577 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, | 3630 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 3578 ssl_options, | 3631 ssl_options, |
| 3579 base::FilePath(kTestFilePath)); | 3632 base::FilePath(kTestFilePath)); |
| 3580 ASSERT_TRUE(https_test_server.Start()); | 3633 ASSERT_TRUE(https_test_server.Start()); |
| 3581 | 3634 |
| 3582 TestDelegate d; | 3635 TestDelegate d; |
| 3583 { | 3636 { |
| 3584 GURL redirect_url = http_server.GetURL( | 3637 GURL redirect_url = http_server.GetURL( |
| 3585 "forward-tokbind?" + https_test_server.GetURL("tokbind-ekm").spec()); | 3638 "forward-tokbind?" + https_test_server.GetURL("tokbind-ekm").spec()); |
| 3586 std::unique_ptr<URLRequest> r( | 3639 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3587 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 3640 redirect_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3588 r->Start(); | 3641 r->Start(); |
| 3589 EXPECT_TRUE(r->is_pending()); | 3642 EXPECT_TRUE(r->is_pending()); |
| 3590 | 3643 |
| 3591 base::RunLoop().Run(); | 3644 base::RunLoop().Run(); |
| 3592 | 3645 |
| 3593 EXPECT_EQ(OK, d.request_status()); | 3646 EXPECT_EQ(OK, d.request_status()); |
| 3594 | 3647 |
| 3595 HttpRequestHeaders headers; | 3648 HttpRequestHeaders headers; |
| 3596 std::string token_binding_header, token_binding_message; | 3649 std::string token_binding_header, token_binding_message; |
| 3597 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); | 3650 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 3628 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); | 3681 ssl_options.supported_token_binding_params.push_back(TB_PARAM_ECDSAP256); |
| 3629 SpawnedTestServer token_binding_test_server(SpawnedTestServer::TYPE_HTTPS, | 3682 SpawnedTestServer token_binding_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 3630 ssl_options, | 3683 ssl_options, |
| 3631 base::FilePath(kTestFilePath)); | 3684 base::FilePath(kTestFilePath)); |
| 3632 ASSERT_TRUE(token_binding_test_server.Start()); | 3685 ASSERT_TRUE(token_binding_test_server.Start()); |
| 3633 | 3686 |
| 3634 TestDelegate d; | 3687 TestDelegate d; |
| 3635 { | 3688 { |
| 3636 GURL redirect_url = token_binding_test_server.GetURL( | 3689 GURL redirect_url = token_binding_test_server.GetURL( |
| 3637 "forward-tokbind?" + https_test_server.GetURL("tokbind-ekm").spec()); | 3690 "forward-tokbind?" + https_test_server.GetURL("tokbind-ekm").spec()); |
| 3638 std::unique_ptr<URLRequest> r( | 3691 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 3639 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 3692 redirect_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3640 r->Start(); | 3693 r->Start(); |
| 3641 EXPECT_TRUE(r->is_pending()); | 3694 EXPECT_TRUE(r->is_pending()); |
| 3642 | 3695 |
| 3643 base::RunLoop().Run(); | 3696 base::RunLoop().Run(); |
| 3644 | 3697 |
| 3645 EXPECT_EQ(OK, d.request_status()); | 3698 EXPECT_EQ(OK, d.request_status()); |
| 3646 | 3699 |
| 3647 HttpRequestHeaders headers; | 3700 HttpRequestHeaders headers; |
| 3648 std::string token_binding_header, token_binding_message; | 3701 std::string token_binding_header, token_binding_message; |
| 3649 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); | 3702 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 3663 base::Bind(&HandleRedirectConnect)); | 3716 base::Bind(&HandleRedirectConnect)); |
| 3664 ASSERT_TRUE(http_test_server()->Start()); | 3717 ASSERT_TRUE(http_test_server()->Start()); |
| 3665 | 3718 |
| 3666 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3719 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3667 TestURLRequestContextWithProxy context( | 3720 TestURLRequestContextWithProxy context( |
| 3668 http_test_server()->host_port_pair().ToString(), &network_delegate); | 3721 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3669 | 3722 |
| 3670 TestDelegate d; | 3723 TestDelegate d; |
| 3671 { | 3724 { |
| 3672 std::unique_ptr<URLRequest> r(context.CreateRequest( | 3725 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 3673 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); | 3726 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, |
| 3727 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3674 r->Start(); | 3728 r->Start(); |
| 3675 EXPECT_TRUE(r->is_pending()); | 3729 EXPECT_TRUE(r->is_pending()); |
| 3676 | 3730 |
| 3677 base::RunLoop().Run(); | 3731 base::RunLoop().Run(); |
| 3678 | 3732 |
| 3679 // The proxy server is not set before failure. | 3733 // The proxy server is not set before failure. |
| 3680 EXPECT_FALSE(r->proxy_server().is_valid()); | 3734 EXPECT_FALSE(r->proxy_server().is_valid()); |
| 3681 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); | 3735 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); |
| 3682 EXPECT_EQ(1, d.response_started_count()); | 3736 EXPECT_EQ(1, d.response_started_count()); |
| 3683 // We should not have followed the redirect. | 3737 // We should not have followed the redirect. |
| 3684 EXPECT_EQ(0, d.received_redirect_count()); | 3738 EXPECT_EQ(0, d.received_redirect_count()); |
| 3685 } | 3739 } |
| 3686 } | 3740 } |
| 3687 | 3741 |
| 3688 // This is the same as the previous test, but checks that the network delegate | 3742 // This is the same as the previous test, but checks that the network delegate |
| 3689 // registers the error. | 3743 // registers the error. |
| 3690 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { | 3744 TEST_F(URLRequestTestHTTP, NetworkDelegateTunnelConnectionFailed) { |
| 3691 ASSERT_TRUE(http_test_server()->Start()); | 3745 ASSERT_TRUE(http_test_server()->Start()); |
| 3692 | 3746 |
| 3693 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 3747 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 3694 TestURLRequestContextWithProxy context( | 3748 TestURLRequestContextWithProxy context( |
| 3695 http_test_server()->host_port_pair().ToString(), &network_delegate); | 3749 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3696 | 3750 |
| 3697 TestDelegate d; | 3751 TestDelegate d; |
| 3698 { | 3752 { |
| 3699 std::unique_ptr<URLRequest> r(context.CreateRequest( | 3753 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 3700 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d)); | 3754 GURL("https://www.redirect.com/"), DEFAULT_PRIORITY, &d, |
| 3755 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3701 r->Start(); | 3756 r->Start(); |
| 3702 EXPECT_TRUE(r->is_pending()); | 3757 EXPECT_TRUE(r->is_pending()); |
| 3703 | 3758 |
| 3704 base::RunLoop().Run(); | 3759 base::RunLoop().Run(); |
| 3705 | 3760 |
| 3706 // The proxy server is not set before failure. | 3761 // The proxy server is not set before failure. |
| 3707 EXPECT_FALSE(r->proxy_server().is_valid()); | 3762 EXPECT_FALSE(r->proxy_server().is_valid()); |
| 3708 EXPECT_EQ(1, d.response_started_count()); | 3763 EXPECT_EQ(1, d.response_started_count()); |
| 3709 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); | 3764 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); |
| 3710 // We should not have followed the redirect. | 3765 // We should not have followed the redirect. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 3734 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | | 3789 BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST | |
| 3735 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | | 3790 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS | |
| 3736 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 3791 BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 3737 | 3792 |
| 3738 TestURLRequestContext context(true); | 3793 TestURLRequestContext context(true); |
| 3739 context.set_network_delegate(&network_delegate); | 3794 context.set_network_delegate(&network_delegate); |
| 3740 context.Init(); | 3795 context.Init(); |
| 3741 | 3796 |
| 3742 { | 3797 { |
| 3743 std::unique_ptr<URLRequest> r(context.CreateRequest( | 3798 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 3744 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 3799 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 3800 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3745 | 3801 |
| 3746 r->Start(); | 3802 r->Start(); |
| 3747 for (size_t i = 0; i < blocking_stages_length; ++i) { | 3803 for (size_t i = 0; i < blocking_stages_length; ++i) { |
| 3748 base::RunLoop().Run(); | 3804 base::RunLoop().Run(); |
| 3749 EXPECT_EQ(blocking_stages[i], | 3805 EXPECT_EQ(blocking_stages[i], |
| 3750 network_delegate.stage_blocked_for_callback()); | 3806 network_delegate.stage_blocked_for_callback()); |
| 3751 network_delegate.DoCallback(OK); | 3807 network_delegate.DoCallback(OK); |
| 3752 } | 3808 } |
| 3753 base::RunLoop().Run(); | 3809 base::RunLoop().Run(); |
| 3754 EXPECT_EQ(200, r->GetResponseCode()); | 3810 EXPECT_EQ(200, r->GetResponseCode()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 3766 TestDelegate d; | 3822 TestDelegate d; |
| 3767 BlockingNetworkDelegate network_delegate( | 3823 BlockingNetworkDelegate network_delegate( |
| 3768 BlockingNetworkDelegate::AUTO_CALLBACK); | 3824 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3769 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3825 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3770 network_delegate.set_retval(ERR_EMPTY_RESPONSE); | 3826 network_delegate.set_retval(ERR_EMPTY_RESPONSE); |
| 3771 | 3827 |
| 3772 TestURLRequestContextWithProxy context( | 3828 TestURLRequestContextWithProxy context( |
| 3773 http_test_server()->host_port_pair().ToString(), &network_delegate); | 3829 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3774 | 3830 |
| 3775 { | 3831 { |
| 3776 std::unique_ptr<URLRequest> r(context.CreateRequest( | 3832 std::unique_ptr<URLRequest> r( |
| 3777 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 3833 context.CreateRequest(http_test_server()->GetURL("/"), DEFAULT_PRIORITY, |
| 3834 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3778 | 3835 |
| 3779 r->Start(); | 3836 r->Start(); |
| 3780 base::RunLoop().Run(); | 3837 base::RunLoop().Run(); |
| 3781 | 3838 |
| 3782 // The proxy server is not set before cancellation. | 3839 // The proxy server is not set before cancellation. |
| 3783 EXPECT_FALSE(r->proxy_server().is_valid()); | 3840 EXPECT_FALSE(r->proxy_server().is_valid()); |
| 3784 EXPECT_EQ(ERR_EMPTY_RESPONSE, d.request_status()); | 3841 EXPECT_EQ(ERR_EMPTY_RESPONSE, d.request_status()); |
| 3785 EXPECT_EQ(1, network_delegate.created_requests()); | 3842 EXPECT_EQ(1, network_delegate.created_requests()); |
| 3786 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 3843 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 3787 } | 3844 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 3798 TestDelegate d; | 3855 TestDelegate d; |
| 3799 BlockingNetworkDelegate network_delegate(block_mode); | 3856 BlockingNetworkDelegate network_delegate(block_mode); |
| 3800 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); | 3857 network_delegate.set_retval(ERR_BLOCKED_BY_CLIENT); |
| 3801 network_delegate.set_block_on(stage); | 3858 network_delegate.set_block_on(stage); |
| 3802 | 3859 |
| 3803 TestURLRequestContext context(true); | 3860 TestURLRequestContext context(true); |
| 3804 context.set_network_delegate(&network_delegate); | 3861 context.set_network_delegate(&network_delegate); |
| 3805 context.Init(); | 3862 context.Init(); |
| 3806 | 3863 |
| 3807 { | 3864 { |
| 3808 std::unique_ptr<URLRequest> r( | 3865 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 3809 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 3866 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3810 | 3867 |
| 3811 r->Start(); | 3868 r->Start(); |
| 3812 base::RunLoop().Run(); | 3869 base::RunLoop().Run(); |
| 3813 | 3870 |
| 3814 // The proxy server is not set before cancellation. | 3871 // The proxy server is not set before cancellation. |
| 3815 if (stage == BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST || | 3872 if (stage == BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST || |
| 3816 stage == BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS) { | 3873 stage == BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS) { |
| 3817 EXPECT_FALSE(r->proxy_server().is_valid()); | 3874 EXPECT_FALSE(r->proxy_server().is_valid()); |
| 3818 } else if (stage == BlockingNetworkDelegate::ON_HEADERS_RECEIVED) { | 3875 } else if (stage == BlockingNetworkDelegate::ON_HEADERS_RECEIVED) { |
| 3819 EXPECT_TRUE(r->proxy_server().is_direct()); | 3876 EXPECT_TRUE(r->proxy_server().is_direct()); |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3883 BlockingNetworkDelegate::AUTO_CALLBACK); | 3940 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 3884 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 3941 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3885 GURL redirect_url(http_test_server()->GetURL("/simple.html")); | 3942 GURL redirect_url(http_test_server()->GetURL("/simple.html")); |
| 3886 network_delegate.set_redirect_url(redirect_url); | 3943 network_delegate.set_redirect_url(redirect_url); |
| 3887 | 3944 |
| 3888 TestURLRequestContextWithProxy context( | 3945 TestURLRequestContextWithProxy context( |
| 3889 http_test_server()->host_port_pair().ToString(), &network_delegate); | 3946 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3890 | 3947 |
| 3891 { | 3948 { |
| 3892 GURL original_url(http_test_server()->GetURL("/defaultresponse")); | 3949 GURL original_url(http_test_server()->GetURL("/defaultresponse")); |
| 3893 std::unique_ptr<URLRequest> r( | 3950 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 3894 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 3951 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3895 | 3952 |
| 3896 // Quit after hitting the redirect, so can check the headers. | 3953 // Quit after hitting the redirect, so can check the headers. |
| 3897 d.set_quit_on_redirect(true); | 3954 d.set_quit_on_redirect(true); |
| 3898 r->Start(); | 3955 r->Start(); |
| 3899 base::RunLoop().Run(); | 3956 base::RunLoop().Run(); |
| 3900 | 3957 |
| 3901 // Check headers from URLRequestJob. | 3958 // Check headers from URLRequestJob. |
| 3902 EXPECT_EQ(307, r->GetResponseCode()); | 3959 EXPECT_EQ(307, r->GetResponseCode()); |
| 3903 EXPECT_EQ(307, r->response_headers()->response_code()); | 3960 EXPECT_EQ(307, r->response_headers()->response_code()); |
| 3904 std::string location; | 3961 std::string location; |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3938 BlockingNetworkDelegate network_delegate( | 3995 BlockingNetworkDelegate network_delegate( |
| 3939 BlockingNetworkDelegate::SYNCHRONOUS); | 3996 BlockingNetworkDelegate::SYNCHRONOUS); |
| 3940 GURL redirect_url(http_test_server()->GetURL("/simple.html")); | 3997 GURL redirect_url(http_test_server()->GetURL("/simple.html")); |
| 3941 network_delegate.set_redirect_url(redirect_url); | 3998 network_delegate.set_redirect_url(redirect_url); |
| 3942 | 3999 |
| 3943 TestURLRequestContextWithProxy context( | 4000 TestURLRequestContextWithProxy context( |
| 3944 http_test_server()->host_port_pair().ToString(), &network_delegate); | 4001 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 3945 | 4002 |
| 3946 { | 4003 { |
| 3947 GURL original_url(http_test_server()->GetURL("/defaultresponse")); | 4004 GURL original_url(http_test_server()->GetURL("/defaultresponse")); |
| 3948 std::unique_ptr<URLRequest> r( | 4005 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 3949 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 4006 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 3950 | 4007 |
| 3951 // Quit after hitting the redirect, so can check the headers. | 4008 // Quit after hitting the redirect, so can check the headers. |
| 3952 d.set_quit_on_redirect(true); | 4009 d.set_quit_on_redirect(true); |
| 3953 r->Start(); | 4010 r->Start(); |
| 3954 base::RunLoop().Run(); | 4011 base::RunLoop().Run(); |
| 3955 | 4012 |
| 3956 // Check headers from URLRequestJob. | 4013 // Check headers from URLRequestJob. |
| 3957 EXPECT_EQ(307, r->GetResponseCode()); | 4014 EXPECT_EQ(307, r->GetResponseCode()); |
| 3958 EXPECT_EQ(307, r->response_headers()->response_code()); | 4015 EXPECT_EQ(307, r->response_headers()->response_code()); |
| 3959 std::string location; | 4016 std::string location; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3996 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 4053 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 3997 GURL redirect_url(http_test_server()->GetURL("/echo")); | 4054 GURL redirect_url(http_test_server()->GetURL("/echo")); |
| 3998 network_delegate.set_redirect_url(redirect_url); | 4055 network_delegate.set_redirect_url(redirect_url); |
| 3999 | 4056 |
| 4000 TestURLRequestContext context(true); | 4057 TestURLRequestContext context(true); |
| 4001 context.set_network_delegate(&network_delegate); | 4058 context.set_network_delegate(&network_delegate); |
| 4002 context.Init(); | 4059 context.Init(); |
| 4003 | 4060 |
| 4004 { | 4061 { |
| 4005 GURL original_url(http_test_server()->GetURL("/defaultresponse")); | 4062 GURL original_url(http_test_server()->GetURL("/defaultresponse")); |
| 4006 std::unique_ptr<URLRequest> r( | 4063 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4007 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 4064 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4008 r->set_method("POST"); | 4065 r->set_method("POST"); |
| 4009 r->set_upload(CreateSimpleUploadData(kData)); | 4066 r->set_upload(CreateSimpleUploadData(kData)); |
| 4010 HttpRequestHeaders headers; | 4067 HttpRequestHeaders headers; |
| 4011 headers.SetHeader(HttpRequestHeaders::kContentLength, | 4068 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 4012 base::SizeTToString(arraysize(kData) - 1)); | 4069 base::SizeTToString(arraysize(kData) - 1)); |
| 4013 r->SetExtraRequestHeaders(headers); | 4070 r->SetExtraRequestHeaders(headers); |
| 4014 | 4071 |
| 4015 // Quit after hitting the redirect, so can check the headers. | 4072 // Quit after hitting the redirect, so can check the headers. |
| 4016 d.set_quit_on_redirect(true); | 4073 d.set_quit_on_redirect(true); |
| 4017 r->Start(); | 4074 r->Start(); |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4051 BlockingNetworkDelegate::AUTO_CALLBACK); | 4108 BlockingNetworkDelegate::AUTO_CALLBACK); |
| 4052 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 4109 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 4053 GURL redirect_url(http_test_server()->GetURL("/simple.html")); | 4110 GURL redirect_url(http_test_server()->GetURL("/simple.html")); |
| 4054 network_delegate.set_redirect_on_headers_received_url(redirect_url); | 4111 network_delegate.set_redirect_on_headers_received_url(redirect_url); |
| 4055 | 4112 |
| 4056 TestURLRequestContextWithProxy context( | 4113 TestURLRequestContextWithProxy context( |
| 4057 http_test_server()->host_port_pair().ToString(), &network_delegate); | 4114 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 4058 | 4115 |
| 4059 { | 4116 { |
| 4060 GURL original_url(http_test_server()->GetURL("/defaultresponse")); | 4117 GURL original_url(http_test_server()->GetURL("/defaultresponse")); |
| 4061 std::unique_ptr<URLRequest> r( | 4118 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4062 context.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 4119 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4063 | 4120 |
| 4064 r->Start(); | 4121 r->Start(); |
| 4065 base::RunLoop().Run(); | 4122 base::RunLoop().Run(); |
| 4066 | 4123 |
| 4067 EXPECT_EQ(OK, d.request_status()); | 4124 EXPECT_EQ(OK, d.request_status()); |
| 4068 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, | 4125 EXPECT_EQ(ProxyServer(ProxyServer::SCHEME_HTTP, |
| 4069 http_test_server()->host_port_pair()), | 4126 http_test_server()->host_port_pair()), |
| 4070 r->proxy_server()); | 4127 r->proxy_server()); |
| 4071 // before_send_headers_with_proxy_count only increments for headers sent | 4128 // before_send_headers_with_proxy_count only increments for headers sent |
| 4072 // through an untunneled proxy. | 4129 // through an untunneled proxy. |
| (...skipping 23 matching lines...) Expand all Loading... |
| 4096 BlockingNetworkDelegate::SYNCHRONOUS); | 4153 BlockingNetworkDelegate::SYNCHRONOUS); |
| 4097 | 4154 |
| 4098 TestURLRequestContext context(true); | 4155 TestURLRequestContext context(true); |
| 4099 context.set_network_delegate(&network_delegate); | 4156 context.set_network_delegate(&network_delegate); |
| 4100 context.Init(); | 4157 context.Init(); |
| 4101 | 4158 |
| 4102 d.set_credentials(AuthCredentials(kUser, kSecret)); | 4159 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 4103 | 4160 |
| 4104 { | 4161 { |
| 4105 GURL url(http_test_server()->GetURL("/auth-basic")); | 4162 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 4106 std::unique_ptr<URLRequest> r( | 4163 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4107 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 4164 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4108 r->Start(); | 4165 r->Start(); |
| 4109 | 4166 |
| 4110 base::RunLoop().Run(); | 4167 base::RunLoop().Run(); |
| 4111 | 4168 |
| 4112 EXPECT_EQ(OK, d.request_status()); | 4169 EXPECT_EQ(OK, d.request_status()); |
| 4113 EXPECT_EQ(200, r->GetResponseCode()); | 4170 EXPECT_EQ(200, r->GetResponseCode()); |
| 4114 EXPECT_TRUE(d.auth_required_called()); | 4171 EXPECT_TRUE(d.auth_required_called()); |
| 4115 EXPECT_EQ(1, network_delegate.created_requests()); | 4172 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4116 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4173 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4117 } | 4174 } |
| 4118 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4175 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4119 } | 4176 } |
| 4120 | 4177 |
| 4121 TEST_F(URLRequestTestHTTP, | 4178 TEST_F(URLRequestTestHTTP, |
| 4122 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { | 4179 NetworkDelegateOnAuthRequiredSyncNoAction_GetFullRequestHeaders) { |
| 4123 ASSERT_TRUE(http_test_server()->Start()); | 4180 ASSERT_TRUE(http_test_server()->Start()); |
| 4124 | 4181 |
| 4125 TestDelegate d; | 4182 TestDelegate d; |
| 4126 BlockingNetworkDelegate network_delegate( | 4183 BlockingNetworkDelegate network_delegate( |
| 4127 BlockingNetworkDelegate::SYNCHRONOUS); | 4184 BlockingNetworkDelegate::SYNCHRONOUS); |
| 4128 | 4185 |
| 4129 TestURLRequestContext context(true); | 4186 TestURLRequestContext context(true); |
| 4130 context.set_network_delegate(&network_delegate); | 4187 context.set_network_delegate(&network_delegate); |
| 4131 context.Init(); | 4188 context.Init(); |
| 4132 | 4189 |
| 4133 d.set_credentials(AuthCredentials(kUser, kSecret)); | 4190 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 4134 | 4191 |
| 4135 { | 4192 { |
| 4136 GURL url(http_test_server()->GetURL("/auth-basic")); | 4193 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 4137 std::unique_ptr<URLRequest> r( | 4194 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4138 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 4195 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4139 r->Start(); | 4196 r->Start(); |
| 4140 | 4197 |
| 4141 { | 4198 { |
| 4142 HttpRequestHeaders headers; | 4199 HttpRequestHeaders headers; |
| 4143 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); | 4200 EXPECT_TRUE(r->GetFullRequestHeaders(&headers)); |
| 4144 EXPECT_FALSE(headers.HasHeader("Authorization")); | 4201 EXPECT_FALSE(headers.HasHeader("Authorization")); |
| 4145 } | 4202 } |
| 4146 | 4203 |
| 4147 base::RunLoop().Run(); | 4204 base::RunLoop().Run(); |
| 4148 | 4205 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4168 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 4225 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 4169 | 4226 |
| 4170 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 4227 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 4171 | 4228 |
| 4172 TestURLRequestContext context(true); | 4229 TestURLRequestContext context(true); |
| 4173 context.set_network_delegate(&network_delegate); | 4230 context.set_network_delegate(&network_delegate); |
| 4174 context.Init(); | 4231 context.Init(); |
| 4175 | 4232 |
| 4176 { | 4233 { |
| 4177 GURL url(http_test_server()->GetURL("/auth-basic")); | 4234 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 4178 std::unique_ptr<URLRequest> r( | 4235 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4179 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 4236 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4180 r->Start(); | 4237 r->Start(); |
| 4181 base::RunLoop().Run(); | 4238 base::RunLoop().Run(); |
| 4182 | 4239 |
| 4183 EXPECT_EQ(OK, d.request_status()); | 4240 EXPECT_EQ(OK, d.request_status()); |
| 4184 EXPECT_EQ(200, r->GetResponseCode()); | 4241 EXPECT_EQ(200, r->GetResponseCode()); |
| 4185 EXPECT_FALSE(d.auth_required_called()); | 4242 EXPECT_FALSE(d.auth_required_called()); |
| 4186 EXPECT_EQ(1, network_delegate.created_requests()); | 4243 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4187 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4244 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4188 } | 4245 } |
| 4189 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4246 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4203 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); | 4260 NetworkDelegate::AUTH_REQUIRED_RESPONSE_SET_AUTH); |
| 4204 | 4261 |
| 4205 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); | 4262 network_delegate.set_auth_credentials(AuthCredentials(kUser, kSecret)); |
| 4206 | 4263 |
| 4207 TestURLRequestContext context(true); | 4264 TestURLRequestContext context(true); |
| 4208 context.set_network_delegate(&network_delegate); | 4265 context.set_network_delegate(&network_delegate); |
| 4209 context.Init(); | 4266 context.Init(); |
| 4210 | 4267 |
| 4211 { | 4268 { |
| 4212 GURL url(http_test_server()->GetURL("/auth-basic")); | 4269 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 4213 std::unique_ptr<URLRequest> r( | 4270 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4214 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 4271 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4215 r->Start(); | 4272 r->Start(); |
| 4216 base::RunLoop().Run(); | 4273 base::RunLoop().Run(); |
| 4217 | 4274 |
| 4218 EXPECT_EQ(OK, d.request_status()); | 4275 EXPECT_EQ(OK, d.request_status()); |
| 4219 EXPECT_EQ(200, r->GetResponseCode()); | 4276 EXPECT_EQ(200, r->GetResponseCode()); |
| 4220 EXPECT_FALSE(d.auth_required_called()); | 4277 EXPECT_FALSE(d.auth_required_called()); |
| 4221 EXPECT_EQ(1, network_delegate.created_requests()); | 4278 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4222 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4279 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4223 | 4280 |
| 4224 { | 4281 { |
| (...skipping 16 matching lines...) Expand all Loading... |
| 4241 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 4298 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 4242 network_delegate.set_auth_retval( | 4299 network_delegate.set_auth_retval( |
| 4243 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 4300 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 4244 | 4301 |
| 4245 TestURLRequestContext context(true); | 4302 TestURLRequestContext context(true); |
| 4246 context.set_network_delegate(&network_delegate); | 4303 context.set_network_delegate(&network_delegate); |
| 4247 context.Init(); | 4304 context.Init(); |
| 4248 | 4305 |
| 4249 { | 4306 { |
| 4250 GURL url(http_test_server()->GetURL("/auth-basic")); | 4307 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 4251 std::unique_ptr<URLRequest> r( | 4308 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4252 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 4309 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4253 r->Start(); | 4310 r->Start(); |
| 4254 base::RunLoop().Run(); | 4311 base::RunLoop().Run(); |
| 4255 | 4312 |
| 4256 EXPECT_EQ(OK, d.request_status()); | 4313 EXPECT_EQ(OK, d.request_status()); |
| 4257 EXPECT_EQ(401, r->GetResponseCode()); | 4314 EXPECT_EQ(401, r->GetResponseCode()); |
| 4258 EXPECT_FALSE(d.auth_required_called()); | 4315 EXPECT_FALSE(d.auth_required_called()); |
| 4259 EXPECT_EQ(1, network_delegate.created_requests()); | 4316 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4260 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4317 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4261 } | 4318 } |
| 4262 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4319 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| (...skipping 12 matching lines...) Expand all Loading... |
| 4275 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 4332 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 4276 | 4333 |
| 4277 TestURLRequestContext context(true); | 4334 TestURLRequestContext context(true); |
| 4278 context.set_network_delegate(&network_delegate); | 4335 context.set_network_delegate(&network_delegate); |
| 4279 context.Init(); | 4336 context.Init(); |
| 4280 | 4337 |
| 4281 d.set_credentials(AuthCredentials(kUser, kSecret)); | 4338 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 4282 | 4339 |
| 4283 { | 4340 { |
| 4284 GURL url(http_test_server()->GetURL("/auth-basic")); | 4341 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 4285 std::unique_ptr<URLRequest> r( | 4342 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4286 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 4343 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4287 r->Start(); | 4344 r->Start(); |
| 4288 base::RunLoop().Run(); | 4345 base::RunLoop().Run(); |
| 4289 | 4346 |
| 4290 EXPECT_EQ(OK, d.request_status()); | 4347 EXPECT_EQ(OK, d.request_status()); |
| 4291 EXPECT_EQ(200, r->GetResponseCode()); | 4348 EXPECT_EQ(200, r->GetResponseCode()); |
| 4292 EXPECT_TRUE(d.auth_required_called()); | 4349 EXPECT_TRUE(d.auth_required_called()); |
| 4293 EXPECT_EQ(1, network_delegate.created_requests()); | 4350 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4294 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4351 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4295 } | 4352 } |
| 4296 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4353 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4310 | 4367 |
| 4311 AuthCredentials auth_credentials(kUser, kSecret); | 4368 AuthCredentials auth_credentials(kUser, kSecret); |
| 4312 network_delegate.set_auth_credentials(auth_credentials); | 4369 network_delegate.set_auth_credentials(auth_credentials); |
| 4313 | 4370 |
| 4314 TestURLRequestContext context(true); | 4371 TestURLRequestContext context(true); |
| 4315 context.set_network_delegate(&network_delegate); | 4372 context.set_network_delegate(&network_delegate); |
| 4316 context.Init(); | 4373 context.Init(); |
| 4317 | 4374 |
| 4318 { | 4375 { |
| 4319 GURL url(http_test_server()->GetURL("/auth-basic")); | 4376 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 4320 std::unique_ptr<URLRequest> r( | 4377 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4321 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 4378 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4322 r->Start(); | 4379 r->Start(); |
| 4323 base::RunLoop().Run(); | 4380 base::RunLoop().Run(); |
| 4324 | 4381 |
| 4325 EXPECT_EQ(OK, d.request_status()); | 4382 EXPECT_EQ(OK, d.request_status()); |
| 4326 EXPECT_EQ(200, r->GetResponseCode()); | 4383 EXPECT_EQ(200, r->GetResponseCode()); |
| 4327 EXPECT_FALSE(d.auth_required_called()); | 4384 EXPECT_FALSE(d.auth_required_called()); |
| 4328 EXPECT_EQ(1, network_delegate.created_requests()); | 4385 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4329 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4386 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4330 } | 4387 } |
| 4331 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4388 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 4342 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 4399 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 4343 network_delegate.set_auth_retval( | 4400 network_delegate.set_auth_retval( |
| 4344 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); | 4401 NetworkDelegate::AUTH_REQUIRED_RESPONSE_CANCEL_AUTH); |
| 4345 | 4402 |
| 4346 TestURLRequestContext context(true); | 4403 TestURLRequestContext context(true); |
| 4347 context.set_network_delegate(&network_delegate); | 4404 context.set_network_delegate(&network_delegate); |
| 4348 context.Init(); | 4405 context.Init(); |
| 4349 | 4406 |
| 4350 { | 4407 { |
| 4351 GURL url(http_test_server()->GetURL("/auth-basic")); | 4408 GURL url(http_test_server()->GetURL("/auth-basic")); |
| 4352 std::unique_ptr<URLRequest> r( | 4409 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4353 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 4410 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4354 r->Start(); | 4411 r->Start(); |
| 4355 base::RunLoop().Run(); | 4412 base::RunLoop().Run(); |
| 4356 | 4413 |
| 4357 EXPECT_EQ(OK, d.request_status()); | 4414 EXPECT_EQ(OK, d.request_status()); |
| 4358 EXPECT_EQ(401, r->GetResponseCode()); | 4415 EXPECT_EQ(401, r->GetResponseCode()); |
| 4359 EXPECT_FALSE(d.auth_required_called()); | 4416 EXPECT_FALSE(d.auth_required_called()); |
| 4360 EXPECT_EQ(1, network_delegate.created_requests()); | 4417 EXPECT_EQ(1, network_delegate.created_requests()); |
| 4361 EXPECT_EQ(0, network_delegate.destroyed_requests()); | 4418 EXPECT_EQ(0, network_delegate.destroyed_requests()); |
| 4362 } | 4419 } |
| 4363 EXPECT_EQ(1, network_delegate.destroyed_requests()); | 4420 EXPECT_EQ(1, network_delegate.destroyed_requests()); |
| 4364 } | 4421 } |
| 4365 | 4422 |
| 4366 // Tests that we can handle when a network request was canceled while we were | 4423 // Tests that we can handle when a network request was canceled while we were |
| 4367 // waiting for the network delegate. | 4424 // waiting for the network delegate. |
| 4368 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. | 4425 // Part 1: Request is cancelled while waiting for OnBeforeURLRequest callback. |
| 4369 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { | 4426 TEST_F(URLRequestTestHTTP, NetworkDelegateCancelWhileWaiting1) { |
| 4370 ASSERT_TRUE(http_test_server()->Start()); | 4427 ASSERT_TRUE(http_test_server()->Start()); |
| 4371 | 4428 |
| 4372 TestDelegate d; | 4429 TestDelegate d; |
| 4373 BlockingNetworkDelegate network_delegate( | 4430 BlockingNetworkDelegate network_delegate( |
| 4374 BlockingNetworkDelegate::USER_CALLBACK); | 4431 BlockingNetworkDelegate::USER_CALLBACK); |
| 4375 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); | 4432 network_delegate.set_block_on(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST); |
| 4376 | 4433 |
| 4377 TestURLRequestContext context(true); | 4434 TestURLRequestContext context(true); |
| 4378 context.set_network_delegate(&network_delegate); | 4435 context.set_network_delegate(&network_delegate); |
| 4379 context.Init(); | 4436 context.Init(); |
| 4380 | 4437 |
| 4381 { | 4438 { |
| 4382 std::unique_ptr<URLRequest> r(context.CreateRequest( | 4439 std::unique_ptr<URLRequest> r( |
| 4383 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 4440 context.CreateRequest(http_test_server()->GetURL("/"), DEFAULT_PRIORITY, |
| 4441 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4384 | 4442 |
| 4385 r->Start(); | 4443 r->Start(); |
| 4386 base::RunLoop().Run(); | 4444 base::RunLoop().Run(); |
| 4387 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, | 4445 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_URL_REQUEST, |
| 4388 network_delegate.stage_blocked_for_callback()); | 4446 network_delegate.stage_blocked_for_callback()); |
| 4389 EXPECT_EQ(0, network_delegate.completed_requests()); | 4447 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 4390 // Cancel before callback. | 4448 // Cancel before callback. |
| 4391 r->Cancel(); | 4449 r->Cancel(); |
| 4392 // Ensure that network delegate is notified. | 4450 // Ensure that network delegate is notified. |
| 4393 EXPECT_EQ(1, network_delegate.completed_requests()); | 4451 EXPECT_EQ(1, network_delegate.completed_requests()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4409 BlockingNetworkDelegate network_delegate( | 4467 BlockingNetworkDelegate network_delegate( |
| 4410 BlockingNetworkDelegate::USER_CALLBACK); | 4468 BlockingNetworkDelegate::USER_CALLBACK); |
| 4411 network_delegate.set_block_on( | 4469 network_delegate.set_block_on( |
| 4412 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); | 4470 BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS); |
| 4413 | 4471 |
| 4414 TestURLRequestContext context(true); | 4472 TestURLRequestContext context(true); |
| 4415 context.set_network_delegate(&network_delegate); | 4473 context.set_network_delegate(&network_delegate); |
| 4416 context.Init(); | 4474 context.Init(); |
| 4417 | 4475 |
| 4418 { | 4476 { |
| 4419 std::unique_ptr<URLRequest> r(context.CreateRequest( | 4477 std::unique_ptr<URLRequest> r( |
| 4420 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 4478 context.CreateRequest(http_test_server()->GetURL("/"), DEFAULT_PRIORITY, |
| 4479 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4421 | 4480 |
| 4422 r->Start(); | 4481 r->Start(); |
| 4423 base::RunLoop().Run(); | 4482 base::RunLoop().Run(); |
| 4424 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, | 4483 EXPECT_EQ(BlockingNetworkDelegate::ON_BEFORE_SEND_HEADERS, |
| 4425 network_delegate.stage_blocked_for_callback()); | 4484 network_delegate.stage_blocked_for_callback()); |
| 4426 EXPECT_EQ(0, network_delegate.completed_requests()); | 4485 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 4427 // Cancel before callback. | 4486 // Cancel before callback. |
| 4428 r->Cancel(); | 4487 r->Cancel(); |
| 4429 // Ensure that network delegate is notified. | 4488 // Ensure that network delegate is notified. |
| 4430 EXPECT_EQ(1, network_delegate.completed_requests()); | 4489 EXPECT_EQ(1, network_delegate.completed_requests()); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 4444 TestDelegate d; | 4503 TestDelegate d; |
| 4445 BlockingNetworkDelegate network_delegate( | 4504 BlockingNetworkDelegate network_delegate( |
| 4446 BlockingNetworkDelegate::USER_CALLBACK); | 4505 BlockingNetworkDelegate::USER_CALLBACK); |
| 4447 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); | 4506 network_delegate.set_block_on(BlockingNetworkDelegate::ON_HEADERS_RECEIVED); |
| 4448 | 4507 |
| 4449 TestURLRequestContext context(true); | 4508 TestURLRequestContext context(true); |
| 4450 context.set_network_delegate(&network_delegate); | 4509 context.set_network_delegate(&network_delegate); |
| 4451 context.Init(); | 4510 context.Init(); |
| 4452 | 4511 |
| 4453 { | 4512 { |
| 4454 std::unique_ptr<URLRequest> r(context.CreateRequest( | 4513 std::unique_ptr<URLRequest> r( |
| 4455 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 4514 context.CreateRequest(http_test_server()->GetURL("/"), DEFAULT_PRIORITY, |
| 4515 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4456 | 4516 |
| 4457 r->Start(); | 4517 r->Start(); |
| 4458 base::RunLoop().Run(); | 4518 base::RunLoop().Run(); |
| 4459 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, | 4519 EXPECT_EQ(BlockingNetworkDelegate::ON_HEADERS_RECEIVED, |
| 4460 network_delegate.stage_blocked_for_callback()); | 4520 network_delegate.stage_blocked_for_callback()); |
| 4461 EXPECT_EQ(0, network_delegate.completed_requests()); | 4521 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 4462 // Cancel before callback. | 4522 // Cancel before callback. |
| 4463 r->Cancel(); | 4523 r->Cancel(); |
| 4464 // Ensure that network delegate is notified. | 4524 // Ensure that network delegate is notified. |
| 4465 EXPECT_EQ(1, network_delegate.completed_requests()); | 4525 EXPECT_EQ(1, network_delegate.completed_requests()); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 4480 BlockingNetworkDelegate network_delegate( | 4540 BlockingNetworkDelegate network_delegate( |
| 4481 BlockingNetworkDelegate::USER_CALLBACK); | 4541 BlockingNetworkDelegate::USER_CALLBACK); |
| 4482 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); | 4542 network_delegate.set_block_on(BlockingNetworkDelegate::ON_AUTH_REQUIRED); |
| 4483 | 4543 |
| 4484 TestURLRequestContext context(true); | 4544 TestURLRequestContext context(true); |
| 4485 context.set_network_delegate(&network_delegate); | 4545 context.set_network_delegate(&network_delegate); |
| 4486 context.Init(); | 4546 context.Init(); |
| 4487 | 4547 |
| 4488 { | 4548 { |
| 4489 std::unique_ptr<URLRequest> r(context.CreateRequest( | 4549 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4490 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); | 4550 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d, |
| 4551 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4491 | 4552 |
| 4492 r->Start(); | 4553 r->Start(); |
| 4493 base::RunLoop().Run(); | 4554 base::RunLoop().Run(); |
| 4494 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, | 4555 EXPECT_EQ(BlockingNetworkDelegate::ON_AUTH_REQUIRED, |
| 4495 network_delegate.stage_blocked_for_callback()); | 4556 network_delegate.stage_blocked_for_callback()); |
| 4496 EXPECT_EQ(0, network_delegate.completed_requests()); | 4557 EXPECT_EQ(0, network_delegate.completed_requests()); |
| 4497 // Cancel before callback. | 4558 // Cancel before callback. |
| 4498 r->Cancel(); | 4559 r->Cancel(); |
| 4499 // Ensure that network delegate is notified. | 4560 // Ensure that network delegate is notified. |
| 4500 EXPECT_EQ(1, network_delegate.completed_requests()); | 4561 EXPECT_EQ(1, network_delegate.completed_requests()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4533 base::Bind(&HandleServerAuthConnect)); | 4594 base::Bind(&HandleServerAuthConnect)); |
| 4534 ASSERT_TRUE(http_test_server()->Start()); | 4595 ASSERT_TRUE(http_test_server()->Start()); |
| 4535 | 4596 |
| 4536 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 4597 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 4537 TestURLRequestContextWithProxy context( | 4598 TestURLRequestContextWithProxy context( |
| 4538 http_test_server()->host_port_pair().ToString(), &network_delegate); | 4599 http_test_server()->host_port_pair().ToString(), &network_delegate); |
| 4539 | 4600 |
| 4540 TestDelegate d; | 4601 TestDelegate d; |
| 4541 { | 4602 { |
| 4542 std::unique_ptr<URLRequest> r(context.CreateRequest( | 4603 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 4543 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d)); | 4604 GURL("https://www.server-auth.com/"), DEFAULT_PRIORITY, &d, |
| 4605 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4544 | 4606 |
| 4545 r->Start(); | 4607 r->Start(); |
| 4546 EXPECT_TRUE(r->is_pending()); | 4608 EXPECT_TRUE(r->is_pending()); |
| 4547 | 4609 |
| 4548 base::RunLoop().Run(); | 4610 base::RunLoop().Run(); |
| 4549 | 4611 |
| 4550 // The proxy server is not set before failure. | 4612 // The proxy server is not set before failure. |
| 4551 EXPECT_FALSE(r->proxy_server().is_valid()); | 4613 EXPECT_FALSE(r->proxy_server().is_valid()); |
| 4552 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); | 4614 EXPECT_EQ(ERR_TUNNEL_CONNECTION_FAILED, d.request_status()); |
| 4553 } | 4615 } |
| 4554 } | 4616 } |
| 4555 | 4617 |
| 4556 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { | 4618 TEST_F(URLRequestTestHTTP, GetTest_NoCache) { |
| 4557 ASSERT_TRUE(http_test_server()->Start()); | 4619 ASSERT_TRUE(http_test_server()->Start()); |
| 4558 | 4620 |
| 4559 TestDelegate d; | 4621 TestDelegate d; |
| 4560 { | 4622 { |
| 4561 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 4623 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4562 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 4624 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 4625 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4563 | 4626 |
| 4564 r->Start(); | 4627 r->Start(); |
| 4565 EXPECT_TRUE(r->is_pending()); | 4628 EXPECT_TRUE(r->is_pending()); |
| 4566 | 4629 |
| 4567 base::RunLoop().Run(); | 4630 base::RunLoop().Run(); |
| 4568 | 4631 |
| 4569 EXPECT_EQ(1, d.response_started_count()); | 4632 EXPECT_EQ(1, d.response_started_count()); |
| 4570 EXPECT_FALSE(d.received_data_before_response()); | 4633 EXPECT_FALSE(d.received_data_before_response()); |
| 4571 EXPECT_NE(0, d.bytes_received()); | 4634 EXPECT_NE(0, d.bytes_received()); |
| 4572 EXPECT_EQ(http_test_server()->host_port_pair().host(), | 4635 EXPECT_EQ(http_test_server()->host_port_pair().host(), |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4619 } | 4682 } |
| 4620 // Success: the test did not crash. | 4683 // Success: the test did not crash. |
| 4621 } | 4684 } |
| 4622 | 4685 |
| 4623 TEST_F(URLRequestTestHTTP, GetTest) { | 4686 TEST_F(URLRequestTestHTTP, GetTest) { |
| 4624 ASSERT_TRUE(http_test_server()->Start()); | 4687 ASSERT_TRUE(http_test_server()->Start()); |
| 4625 | 4688 |
| 4626 TestDelegate d; | 4689 TestDelegate d; |
| 4627 { | 4690 { |
| 4628 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 4691 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4629 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 4692 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 4693 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4630 | 4694 |
| 4631 r->Start(); | 4695 r->Start(); |
| 4632 EXPECT_TRUE(r->is_pending()); | 4696 EXPECT_TRUE(r->is_pending()); |
| 4633 | 4697 |
| 4634 base::RunLoop().Run(); | 4698 base::RunLoop().Run(); |
| 4635 | 4699 |
| 4636 EXPECT_EQ(1, d.response_started_count()); | 4700 EXPECT_EQ(1, d.response_started_count()); |
| 4637 EXPECT_FALSE(d.received_data_before_response()); | 4701 EXPECT_FALSE(d.received_data_before_response()); |
| 4638 EXPECT_NE(0, d.bytes_received()); | 4702 EXPECT_NE(0, d.bytes_received()); |
| 4639 EXPECT_EQ(http_test_server()->host_port_pair().host(), | 4703 EXPECT_EQ(http_test_server()->host_port_pair().host(), |
| 4640 r->GetSocketAddress().host()); | 4704 r->GetSocketAddress().host()); |
| 4641 EXPECT_EQ(http_test_server()->host_port_pair().port(), | 4705 EXPECT_EQ(http_test_server()->host_port_pair().port(), |
| 4642 r->GetSocketAddress().port()); | 4706 r->GetSocketAddress().port()); |
| 4643 } | 4707 } |
| 4644 } | 4708 } |
| 4645 | 4709 |
| 4646 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { | 4710 TEST_F(URLRequestTestHTTP, GetTest_GetFullRequestHeaders) { |
| 4647 ASSERT_TRUE(http_test_server()->Start()); | 4711 ASSERT_TRUE(http_test_server()->Start()); |
| 4648 | 4712 |
| 4649 TestDelegate d; | 4713 TestDelegate d; |
| 4650 { | 4714 { |
| 4651 GURL test_url(http_test_server()->GetURL("/defaultresponse")); | 4715 GURL test_url(http_test_server()->GetURL("/defaultresponse")); |
| 4652 std::unique_ptr<URLRequest> r( | 4716 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4653 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 4717 test_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4654 | 4718 |
| 4655 HttpRequestHeaders headers; | 4719 HttpRequestHeaders headers; |
| 4656 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); | 4720 EXPECT_FALSE(r->GetFullRequestHeaders(&headers)); |
| 4657 | 4721 |
| 4658 r->Start(); | 4722 r->Start(); |
| 4659 EXPECT_TRUE(r->is_pending()); | 4723 EXPECT_TRUE(r->is_pending()); |
| 4660 | 4724 |
| 4661 base::RunLoop().Run(); | 4725 base::RunLoop().Run(); |
| 4662 | 4726 |
| 4663 EXPECT_EQ(1, d.response_started_count()); | 4727 EXPECT_EQ(1, d.response_started_count()); |
| 4664 EXPECT_FALSE(d.received_data_before_response()); | 4728 EXPECT_FALSE(d.received_data_before_response()); |
| 4665 EXPECT_NE(0, d.bytes_received()); | 4729 EXPECT_NE(0, d.bytes_received()); |
| 4666 EXPECT_EQ(http_test_server()->host_port_pair().host(), | 4730 EXPECT_EQ(http_test_server()->host_port_pair().host(), |
| 4667 r->GetSocketAddress().host()); | 4731 r->GetSocketAddress().host()); |
| 4668 EXPECT_EQ(http_test_server()->host_port_pair().port(), | 4732 EXPECT_EQ(http_test_server()->host_port_pair().port(), |
| 4669 r->GetSocketAddress().port()); | 4733 r->GetSocketAddress().port()); |
| 4670 | 4734 |
| 4671 EXPECT_TRUE(d.have_full_request_headers()); | 4735 EXPECT_TRUE(d.have_full_request_headers()); |
| 4672 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 4736 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
| 4673 } | 4737 } |
| 4674 } | 4738 } |
| 4675 | 4739 |
| 4676 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { | 4740 TEST_F(URLRequestTestHTTP, GetTestLoadTiming) { |
| 4677 ASSERT_TRUE(http_test_server()->Start()); | 4741 ASSERT_TRUE(http_test_server()->Start()); |
| 4678 | 4742 |
| 4679 TestDelegate d; | 4743 TestDelegate d; |
| 4680 { | 4744 { |
| 4681 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 4745 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 4682 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 4746 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 4747 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4683 | 4748 |
| 4684 r->Start(); | 4749 r->Start(); |
| 4685 EXPECT_TRUE(r->is_pending()); | 4750 EXPECT_TRUE(r->is_pending()); |
| 4686 | 4751 |
| 4687 base::RunLoop().Run(); | 4752 base::RunLoop().Run(); |
| 4688 | 4753 |
| 4689 LoadTimingInfo load_timing_info; | 4754 LoadTimingInfo load_timing_info; |
| 4690 r->GetLoadTimingInfo(&load_timing_info); | 4755 r->GetLoadTimingInfo(&load_timing_info); |
| 4691 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 4756 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 4692 | 4757 |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4734 TestDelegate d; | 4799 TestDelegate d; |
| 4735 { | 4800 { |
| 4736 std::string test_file = base::StringPrintf( | 4801 std::string test_file = base::StringPrintf( |
| 4737 "compressedfiles/BullRunSpeech.txt?%c", test_parameters[i]); | 4802 "compressedfiles/BullRunSpeech.txt?%c", test_parameters[i]); |
| 4738 | 4803 |
| 4739 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 4804 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 4740 TestURLRequestContext context(true); | 4805 TestURLRequestContext context(true); |
| 4741 context.set_network_delegate(&network_delegate); | 4806 context.set_network_delegate(&network_delegate); |
| 4742 context.Init(); | 4807 context.Init(); |
| 4743 | 4808 |
| 4744 std::unique_ptr<URLRequest> r(context.CreateRequest( | 4809 std::unique_ptr<URLRequest> r( |
| 4745 test_server.GetURL(test_file), DEFAULT_PRIORITY, &d)); | 4810 context.CreateRequest(test_server.GetURL(test_file), DEFAULT_PRIORITY, |
| 4811 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4746 r->Start(); | 4812 r->Start(); |
| 4747 EXPECT_TRUE(r->is_pending()); | 4813 EXPECT_TRUE(r->is_pending()); |
| 4748 | 4814 |
| 4749 base::RunLoop().Run(); | 4815 base::RunLoop().Run(); |
| 4750 | 4816 |
| 4751 EXPECT_EQ(1, d.response_started_count()); | 4817 EXPECT_EQ(1, d.response_started_count()); |
| 4752 EXPECT_FALSE(d.received_data_before_response()); | 4818 EXPECT_FALSE(d.received_data_before_response()); |
| 4753 VLOG(1) << " Received " << d.bytes_received() << " bytes" | 4819 VLOG(1) << " Received " << d.bytes_received() << " bytes" |
| 4754 << " error = " << d.request_status(); | 4820 << " error = " << d.request_status(); |
| 4755 if (test_expect_success[i]) { | 4821 if (test_expect_success[i]) { |
| (...skipping 15 matching lines...) Expand all Loading... |
| 4771 } | 4837 } |
| 4772 #endif // !defined(OS_IOS) | 4838 #endif // !defined(OS_IOS) |
| 4773 | 4839 |
| 4774 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { | 4840 TEST_F(URLRequestTestHTTP, RedirectLoadTiming) { |
| 4775 ASSERT_TRUE(http_test_server()->Start()); | 4841 ASSERT_TRUE(http_test_server()->Start()); |
| 4776 | 4842 |
| 4777 GURL destination_url = http_test_server()->GetURL("/"); | 4843 GURL destination_url = http_test_server()->GetURL("/"); |
| 4778 GURL original_url = | 4844 GURL original_url = |
| 4779 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); | 4845 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); |
| 4780 TestDelegate d; | 4846 TestDelegate d; |
| 4781 std::unique_ptr<URLRequest> req( | 4847 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 4782 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 4848 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4783 req->Start(); | 4849 req->Start(); |
| 4784 base::RunLoop().Run(); | 4850 base::RunLoop().Run(); |
| 4785 | 4851 |
| 4786 EXPECT_EQ(1, d.response_started_count()); | 4852 EXPECT_EQ(1, d.response_started_count()); |
| 4787 EXPECT_EQ(1, d.received_redirect_count()); | 4853 EXPECT_EQ(1, d.received_redirect_count()); |
| 4788 EXPECT_EQ(destination_url, req->url()); | 4854 EXPECT_EQ(destination_url, req->url()); |
| 4789 EXPECT_EQ(original_url, req->original_url()); | 4855 EXPECT_EQ(original_url, req->original_url()); |
| 4790 ASSERT_EQ(2U, req->url_chain().size()); | 4856 ASSERT_EQ(2U, req->url_chain().size()); |
| 4791 EXPECT_EQ(original_url, req->url_chain()[0]); | 4857 EXPECT_EQ(original_url, req->url_chain()[0]); |
| 4792 EXPECT_EQ(destination_url, req->url_chain()[1]); | 4858 EXPECT_EQ(destination_url, req->url_chain()[1]); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 4812 | 4878 |
| 4813 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { | 4879 TEST_F(URLRequestTestHTTP, MultipleRedirectTest) { |
| 4814 ASSERT_TRUE(http_test_server()->Start()); | 4880 ASSERT_TRUE(http_test_server()->Start()); |
| 4815 | 4881 |
| 4816 GURL destination_url = http_test_server()->GetURL("/"); | 4882 GURL destination_url = http_test_server()->GetURL("/"); |
| 4817 GURL middle_redirect_url = | 4883 GURL middle_redirect_url = |
| 4818 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); | 4884 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); |
| 4819 GURL original_url = http_test_server()->GetURL("/server-redirect?" + | 4885 GURL original_url = http_test_server()->GetURL("/server-redirect?" + |
| 4820 middle_redirect_url.spec()); | 4886 middle_redirect_url.spec()); |
| 4821 TestDelegate d; | 4887 TestDelegate d; |
| 4822 std::unique_ptr<URLRequest> req( | 4888 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 4823 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 4889 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 4824 req->Start(); | 4890 req->Start(); |
| 4825 base::RunLoop().Run(); | 4891 base::RunLoop().Run(); |
| 4826 | 4892 |
| 4827 EXPECT_EQ(1, d.response_started_count()); | 4893 EXPECT_EQ(1, d.response_started_count()); |
| 4828 EXPECT_EQ(2, d.received_redirect_count()); | 4894 EXPECT_EQ(2, d.received_redirect_count()); |
| 4829 EXPECT_EQ(destination_url, req->url()); | 4895 EXPECT_EQ(destination_url, req->url()); |
| 4830 EXPECT_EQ(original_url, req->original_url()); | 4896 EXPECT_EQ(original_url, req->original_url()); |
| 4831 ASSERT_EQ(3U, req->url_chain().size()); | 4897 ASSERT_EQ(3U, req->url_chain().size()); |
| 4832 EXPECT_EQ(original_url, req->url_chain()[0]); | 4898 EXPECT_EQ(original_url, req->url_chain()[0]); |
| 4833 EXPECT_EQ(middle_redirect_url, req->url_chain()[1]); | 4899 EXPECT_EQ(middle_redirect_url, req->url_chain()[1]); |
| (...skipping 289 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5123 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) { | 5189 TEST_F(URLRequestTestHTTP, DelegateInfoBeforeStart) { |
| 5124 ASSERT_TRUE(http_test_server()->Start()); | 5190 ASSERT_TRUE(http_test_server()->Start()); |
| 5125 | 5191 |
| 5126 TestDelegate request_delegate; | 5192 TestDelegate request_delegate; |
| 5127 TestURLRequestContext context(true); | 5193 TestURLRequestContext context(true); |
| 5128 context.set_network_delegate(NULL); | 5194 context.set_network_delegate(NULL); |
| 5129 context.set_net_log(&net_log_); | 5195 context.set_net_log(&net_log_); |
| 5130 context.Init(); | 5196 context.Init(); |
| 5131 | 5197 |
| 5132 { | 5198 { |
| 5133 std::unique_ptr<URLRequest> r( | 5199 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 5134 context.CreateRequest(http_test_server()->GetURL("/defaultresponse"), | 5200 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, |
| 5135 DEFAULT_PRIORITY, &request_delegate)); | 5201 &request_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5136 LoadStateWithParam load_state = r->GetLoadState(); | 5202 LoadStateWithParam load_state = r->GetLoadState(); |
| 5137 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 5203 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 5138 EXPECT_EQ(base::string16(), load_state.param); | 5204 EXPECT_EQ(base::string16(), load_state.param); |
| 5139 | 5205 |
| 5140 AsyncDelegateLogger::Run( | 5206 AsyncDelegateLogger::Run( |
| 5141 r.get(), | 5207 r.get(), |
| 5142 LOAD_STATE_WAITING_FOR_DELEGATE, | 5208 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 5143 LOAD_STATE_WAITING_FOR_DELEGATE, | 5209 LOAD_STATE_WAITING_FOR_DELEGATE, |
| 5144 LOAD_STATE_IDLE, | 5210 LOAD_STATE_IDLE, |
| 5145 base::Bind(&URLRequest::Start, base::Unretained(r.get()))); | 5211 base::Bind(&URLRequest::Start, base::Unretained(r.get()))); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 5167 ASSERT_TRUE(http_test_server()->Start()); | 5233 ASSERT_TRUE(http_test_server()->Start()); |
| 5168 | 5234 |
| 5169 TestDelegate request_delegate; | 5235 TestDelegate request_delegate; |
| 5170 AsyncLoggingNetworkDelegate network_delegate; | 5236 AsyncLoggingNetworkDelegate network_delegate; |
| 5171 TestURLRequestContext context(true); | 5237 TestURLRequestContext context(true); |
| 5172 context.set_network_delegate(&network_delegate); | 5238 context.set_network_delegate(&network_delegate); |
| 5173 context.set_net_log(&net_log_); | 5239 context.set_net_log(&net_log_); |
| 5174 context.Init(); | 5240 context.Init(); |
| 5175 | 5241 |
| 5176 { | 5242 { |
| 5177 std::unique_ptr<URLRequest> r( | 5243 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 5178 context.CreateRequest(http_test_server()->GetURL("/simple.html"), | 5244 http_test_server()->GetURL("/simple.html"), DEFAULT_PRIORITY, |
| 5179 DEFAULT_PRIORITY, &request_delegate)); | 5245 &request_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5180 LoadStateWithParam load_state = r->GetLoadState(); | 5246 LoadStateWithParam load_state = r->GetLoadState(); |
| 5181 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 5247 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 5182 EXPECT_EQ(base::string16(), load_state.param); | 5248 EXPECT_EQ(base::string16(), load_state.param); |
| 5183 | 5249 |
| 5184 r->Start(); | 5250 r->Start(); |
| 5185 base::RunLoop().Run(); | 5251 base::RunLoop().Run(); |
| 5186 | 5252 |
| 5187 EXPECT_EQ(200, r->GetResponseCode()); | 5253 EXPECT_EQ(200, r->GetResponseCode()); |
| 5188 EXPECT_EQ(OK, request_delegate.request_status()); | 5254 EXPECT_EQ(OK, request_delegate.request_status()); |
| 5189 EXPECT_EQ(1, network_delegate.created_requests()); | 5255 EXPECT_EQ(1, network_delegate.created_requests()); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 5220 TestDelegate request_delegate; | 5286 TestDelegate request_delegate; |
| 5221 AsyncLoggingNetworkDelegate network_delegate; | 5287 AsyncLoggingNetworkDelegate network_delegate; |
| 5222 TestURLRequestContext context(true); | 5288 TestURLRequestContext context(true); |
| 5223 context.set_network_delegate(&network_delegate); | 5289 context.set_network_delegate(&network_delegate); |
| 5224 context.set_net_log(&net_log_); | 5290 context.set_net_log(&net_log_); |
| 5225 context.Init(); | 5291 context.Init(); |
| 5226 | 5292 |
| 5227 { | 5293 { |
| 5228 std::unique_ptr<URLRequest> r(context.CreateRequest( | 5294 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 5229 http_test_server()->GetURL("/server-redirect?simple.html"), | 5295 http_test_server()->GetURL("/server-redirect?simple.html"), |
| 5230 DEFAULT_PRIORITY, &request_delegate)); | 5296 DEFAULT_PRIORITY, &request_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5231 LoadStateWithParam load_state = r->GetLoadState(); | 5297 LoadStateWithParam load_state = r->GetLoadState(); |
| 5232 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 5298 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 5233 EXPECT_EQ(base::string16(), load_state.param); | 5299 EXPECT_EQ(base::string16(), load_state.param); |
| 5234 | 5300 |
| 5235 r->Start(); | 5301 r->Start(); |
| 5236 base::RunLoop().Run(); | 5302 base::RunLoop().Run(); |
| 5237 | 5303 |
| 5238 EXPECT_EQ(200, r->GetResponseCode()); | 5304 EXPECT_EQ(200, r->GetResponseCode()); |
| 5239 EXPECT_EQ(OK, request_delegate.request_status()); | 5305 EXPECT_EQ(OK, request_delegate.request_status()); |
| 5240 EXPECT_EQ(2, network_delegate.created_requests()); | 5306 EXPECT_EQ(2, network_delegate.created_requests()); |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5291 ASSERT_TRUE(http_test_server()->Start()); | 5357 ASSERT_TRUE(http_test_server()->Start()); |
| 5292 | 5358 |
| 5293 TestDelegate request_delegate; | 5359 TestDelegate request_delegate; |
| 5294 AsyncLoggingNetworkDelegate network_delegate; | 5360 AsyncLoggingNetworkDelegate network_delegate; |
| 5295 TestURLRequestContext context(true); | 5361 TestURLRequestContext context(true); |
| 5296 context.set_network_delegate(&network_delegate); | 5362 context.set_network_delegate(&network_delegate); |
| 5297 context.set_net_log(&net_log_); | 5363 context.set_net_log(&net_log_); |
| 5298 context.Init(); | 5364 context.Init(); |
| 5299 | 5365 |
| 5300 { | 5366 { |
| 5301 std::unique_ptr<URLRequest> r( | 5367 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 5302 context.CreateRequest(http_test_server()->GetURL("/auth-basic"), | 5368 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, |
| 5303 DEFAULT_PRIORITY, &request_delegate)); | 5369 &request_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5304 LoadStateWithParam load_state = r->GetLoadState(); | 5370 LoadStateWithParam load_state = r->GetLoadState(); |
| 5305 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); | 5371 EXPECT_EQ(LOAD_STATE_IDLE, load_state.state); |
| 5306 EXPECT_EQ(base::string16(), load_state.param); | 5372 EXPECT_EQ(base::string16(), load_state.param); |
| 5307 | 5373 |
| 5308 r->Start(); | 5374 r->Start(); |
| 5309 base::RunLoop().Run(); | 5375 base::RunLoop().Run(); |
| 5310 | 5376 |
| 5311 EXPECT_EQ(200, r->GetResponseCode()); | 5377 EXPECT_EQ(200, r->GetResponseCode()); |
| 5312 EXPECT_EQ(OK, request_delegate.request_status()); | 5378 EXPECT_EQ(OK, request_delegate.request_status()); |
| 5313 EXPECT_EQ(1, network_delegate.created_requests()); | 5379 EXPECT_EQ(1, network_delegate.created_requests()); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5358 context.Init(); | 5424 context.Init(); |
| 5359 | 5425 |
| 5360 { | 5426 { |
| 5361 // A chunked response with delays between chunks is used to make sure that | 5427 // A chunked response with delays between chunks is used to make sure that |
| 5362 // attempts by the URLRequest delegate to log information while reading the | 5428 // attempts by the URLRequest delegate to log information while reading the |
| 5363 // body are ignored. Since they are ignored, this test is robust against | 5429 // body are ignored. Since they are ignored, this test is robust against |
| 5364 // the possibility of multiple reads being combined in the unlikely event | 5430 // the possibility of multiple reads being combined in the unlikely event |
| 5365 // that it occurs. | 5431 // that it occurs. |
| 5366 std::unique_ptr<URLRequest> r(context.CreateRequest( | 5432 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 5367 test_server.GetURL("/chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY, | 5433 test_server.GetURL("/chunked?waitBetweenChunks=20"), DEFAULT_PRIORITY, |
| 5368 &request_delegate)); | 5434 &request_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5369 LoadStateWithParam load_state = r->GetLoadState(); | 5435 LoadStateWithParam load_state = r->GetLoadState(); |
| 5370 r->Start(); | 5436 r->Start(); |
| 5371 base::RunLoop().Run(); | 5437 base::RunLoop().Run(); |
| 5372 | 5438 |
| 5373 EXPECT_EQ(200, r->GetResponseCode()); | 5439 EXPECT_EQ(200, r->GetResponseCode()); |
| 5374 EXPECT_EQ(OK, request_delegate.request_status()); | 5440 EXPECT_EQ(OK, request_delegate.request_status()); |
| 5375 } | 5441 } |
| 5376 | 5442 |
| 5377 TestNetLogEntry::List entries; | 5443 TestNetLogEntry::List entries; |
| 5378 net_log_.GetEntries(&entries); | 5444 net_log_.GetEntries(&entries); |
| (...skipping 28 matching lines...) Expand all Loading... |
| 5407 AsyncLoggingUrlRequestDelegate request_delegate( | 5473 AsyncLoggingUrlRequestDelegate request_delegate( |
| 5408 AsyncLoggingUrlRequestDelegate::NO_CANCEL); | 5474 AsyncLoggingUrlRequestDelegate::NO_CANCEL); |
| 5409 TestURLRequestContext context(true); | 5475 TestURLRequestContext context(true); |
| 5410 context.set_network_delegate(NULL); | 5476 context.set_network_delegate(NULL); |
| 5411 context.set_net_log(&net_log_); | 5477 context.set_net_log(&net_log_); |
| 5412 context.Init(); | 5478 context.Init(); |
| 5413 | 5479 |
| 5414 { | 5480 { |
| 5415 std::unique_ptr<URLRequest> r(context.CreateRequest( | 5481 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 5416 http_test_server()->GetURL("/server-redirect?simple.html"), | 5482 http_test_server()->GetURL("/server-redirect?simple.html"), |
| 5417 DEFAULT_PRIORITY, &request_delegate)); | 5483 DEFAULT_PRIORITY, &request_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5418 LoadStateWithParam load_state = r->GetLoadState(); | 5484 LoadStateWithParam load_state = r->GetLoadState(); |
| 5419 r->Start(); | 5485 r->Start(); |
| 5420 base::RunLoop().Run(); | 5486 base::RunLoop().Run(); |
| 5421 | 5487 |
| 5422 EXPECT_EQ(200, r->GetResponseCode()); | 5488 EXPECT_EQ(200, r->GetResponseCode()); |
| 5423 EXPECT_EQ(OK, request_delegate.request_status()); | 5489 EXPECT_EQ(OK, request_delegate.request_status()); |
| 5424 } | 5490 } |
| 5425 | 5491 |
| 5426 TestNetLogEntry::List entries; | 5492 TestNetLogEntry::List entries; |
| 5427 net_log_.GetEntries(&entries); | 5493 net_log_.GetEntries(&entries); |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5465 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); | 5531 AsyncLoggingUrlRequestDelegate request_delegate(kCancelStages[test_case]); |
| 5466 TestNetLog net_log; | 5532 TestNetLog net_log; |
| 5467 TestURLRequestContext context(true); | 5533 TestURLRequestContext context(true); |
| 5468 context.set_network_delegate(NULL); | 5534 context.set_network_delegate(NULL); |
| 5469 context.set_net_log(&net_log); | 5535 context.set_net_log(&net_log); |
| 5470 context.Init(); | 5536 context.Init(); |
| 5471 | 5537 |
| 5472 { | 5538 { |
| 5473 std::unique_ptr<URLRequest> r(context.CreateRequest( | 5539 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 5474 http_test_server()->GetURL("/server-redirect?simple.html"), | 5540 http_test_server()->GetURL("/server-redirect?simple.html"), |
| 5475 DEFAULT_PRIORITY, &request_delegate)); | 5541 DEFAULT_PRIORITY, &request_delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5476 LoadStateWithParam load_state = r->GetLoadState(); | 5542 LoadStateWithParam load_state = r->GetLoadState(); |
| 5477 r->Start(); | 5543 r->Start(); |
| 5478 base::RunLoop().Run(); | 5544 base::RunLoop().Run(); |
| 5479 EXPECT_EQ(ERR_ABORTED, request_delegate.request_status()); | 5545 EXPECT_EQ(ERR_ABORTED, request_delegate.request_status()); |
| 5480 } | 5546 } |
| 5481 | 5547 |
| 5482 TestNetLogEntry::List entries; | 5548 TestNetLogEntry::List entries; |
| 5483 net_log.GetEntries(&entries); | 5549 net_log.GetEntries(&entries); |
| 5484 | 5550 |
| 5485 // Delegate info is always logged in both OnReceivedRedirect and | 5551 // Delegate info is always logged in both OnReceivedRedirect and |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5525 } // namespace | 5591 } // namespace |
| 5526 | 5592 |
| 5527 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { | 5593 TEST_F(URLRequestTestHTTP, RedirectWithAdditionalHeadersTest) { |
| 5528 ASSERT_TRUE(http_test_server()->Start()); | 5594 ASSERT_TRUE(http_test_server()->Start()); |
| 5529 | 5595 |
| 5530 GURL destination_url = | 5596 GURL destination_url = |
| 5531 http_test_server()->GetURL("/echoheader?" + std::string(kExtraHeader)); | 5597 http_test_server()->GetURL("/echoheader?" + std::string(kExtraHeader)); |
| 5532 GURL original_url = | 5598 GURL original_url = |
| 5533 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); | 5599 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); |
| 5534 RedirectWithAdditionalHeadersDelegate d; | 5600 RedirectWithAdditionalHeadersDelegate d; |
| 5535 std::unique_ptr<URLRequest> req( | 5601 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5536 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 5602 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5537 req->Start(); | 5603 req->Start(); |
| 5538 base::RunLoop().Run(); | 5604 base::RunLoop().Run(); |
| 5539 | 5605 |
| 5540 std::string value; | 5606 std::string value; |
| 5541 const HttpRequestHeaders& headers = req->extra_request_headers(); | 5607 const HttpRequestHeaders& headers = req->extra_request_headers(); |
| 5542 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); | 5608 EXPECT_TRUE(headers.GetHeader(kExtraHeader, &value)); |
| 5543 EXPECT_EQ(kExtraValue, value); | 5609 EXPECT_EQ(kExtraValue, value); |
| 5544 EXPECT_FALSE(req->is_pending()); | 5610 EXPECT_FALSE(req->is_pending()); |
| 5545 EXPECT_FALSE(req->is_redirecting()); | 5611 EXPECT_FALSE(req->is_redirecting()); |
| 5546 EXPECT_EQ(kExtraValue, d.data_received()); | 5612 EXPECT_EQ(kExtraValue, d.data_received()); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 5562 } // namespace | 5628 } // namespace |
| 5563 | 5629 |
| 5564 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { | 5630 TEST_F(URLRequestTestHTTP, RedirectWithHeaderRemovalTest) { |
| 5565 ASSERT_TRUE(http_test_server()->Start()); | 5631 ASSERT_TRUE(http_test_server()->Start()); |
| 5566 | 5632 |
| 5567 GURL destination_url = http_test_server()->GetURL( | 5633 GURL destination_url = http_test_server()->GetURL( |
| 5568 "/echoheader?" + std::string(kExtraHeaderToRemove)); | 5634 "/echoheader?" + std::string(kExtraHeaderToRemove)); |
| 5569 GURL original_url = | 5635 GURL original_url = |
| 5570 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); | 5636 http_test_server()->GetURL("/server-redirect?" + destination_url.spec()); |
| 5571 RedirectWithHeaderRemovalDelegate d; | 5637 RedirectWithHeaderRemovalDelegate d; |
| 5572 std::unique_ptr<URLRequest> req( | 5638 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5573 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 5639 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5574 req->SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); | 5640 req->SetExtraRequestHeaderByName(kExtraHeaderToRemove, "dummy", false); |
| 5575 req->Start(); | 5641 req->Start(); |
| 5576 base::RunLoop().Run(); | 5642 base::RunLoop().Run(); |
| 5577 | 5643 |
| 5578 std::string value; | 5644 std::string value; |
| 5579 const HttpRequestHeaders& headers = req->extra_request_headers(); | 5645 const HttpRequestHeaders& headers = req->extra_request_headers(); |
| 5580 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); | 5646 EXPECT_FALSE(headers.GetHeader(kExtraHeaderToRemove, &value)); |
| 5581 EXPECT_FALSE(req->is_pending()); | 5647 EXPECT_FALSE(req->is_pending()); |
| 5582 EXPECT_FALSE(req->is_redirecting()); | 5648 EXPECT_FALSE(req->is_redirecting()); |
| 5583 EXPECT_EQ("None", d.data_received()); | 5649 EXPECT_EQ("None", d.data_received()); |
| 5584 } | 5650 } |
| 5585 | 5651 |
| 5586 TEST_F(URLRequestTestHTTP, CancelAfterStart) { | 5652 TEST_F(URLRequestTestHTTP, CancelAfterStart) { |
| 5587 TestDelegate d; | 5653 TestDelegate d; |
| 5588 { | 5654 { |
| 5589 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5655 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5590 GURL("http://www.google.com/"), DEFAULT_PRIORITY, &d)); | 5656 GURL("http://www.google.com/"), DEFAULT_PRIORITY, &d, |
| 5657 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5591 | 5658 |
| 5592 r->Start(); | 5659 r->Start(); |
| 5593 EXPECT_TRUE(r->is_pending()); | 5660 EXPECT_TRUE(r->is_pending()); |
| 5594 | 5661 |
| 5595 r->Cancel(); | 5662 r->Cancel(); |
| 5596 | 5663 |
| 5597 base::RunLoop().Run(); | 5664 base::RunLoop().Run(); |
| 5598 | 5665 |
| 5599 // We expect to receive OnResponseStarted even though the request has been | 5666 // We expect to receive OnResponseStarted even though the request has been |
| 5600 // cancelled. | 5667 // cancelled. |
| 5601 EXPECT_EQ(1, d.response_started_count()); | 5668 EXPECT_EQ(1, d.response_started_count()); |
| 5602 EXPECT_EQ(0, d.bytes_received()); | 5669 EXPECT_EQ(0, d.bytes_received()); |
| 5603 EXPECT_FALSE(d.received_data_before_response()); | 5670 EXPECT_FALSE(d.received_data_before_response()); |
| 5604 } | 5671 } |
| 5605 } | 5672 } |
| 5606 | 5673 |
| 5607 TEST_F(URLRequestTestHTTP, CancelInResponseStarted) { | 5674 TEST_F(URLRequestTestHTTP, CancelInResponseStarted) { |
| 5608 ASSERT_TRUE(http_test_server()->Start()); | 5675 ASSERT_TRUE(http_test_server()->Start()); |
| 5609 | 5676 |
| 5610 TestDelegate d; | 5677 TestDelegate d; |
| 5611 { | 5678 { |
| 5612 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5679 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5613 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 5680 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d, |
| 5681 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5614 | 5682 |
| 5615 d.set_cancel_in_response_started(true); | 5683 d.set_cancel_in_response_started(true); |
| 5616 | 5684 |
| 5617 r->Start(); | 5685 r->Start(); |
| 5618 EXPECT_TRUE(r->is_pending()); | 5686 EXPECT_TRUE(r->is_pending()); |
| 5619 | 5687 |
| 5620 base::RunLoop().Run(); | 5688 base::RunLoop().Run(); |
| 5621 | 5689 |
| 5622 EXPECT_EQ(1, d.response_started_count()); | 5690 EXPECT_EQ(1, d.response_started_count()); |
| 5623 EXPECT_EQ(0, d.bytes_received()); | 5691 EXPECT_EQ(0, d.bytes_received()); |
| 5624 EXPECT_FALSE(d.received_data_before_response()); | 5692 EXPECT_FALSE(d.received_data_before_response()); |
| 5625 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 5693 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 5626 } | 5694 } |
| 5627 } | 5695 } |
| 5628 | 5696 |
| 5629 TEST_F(URLRequestTestHTTP, CancelOnDataReceived) { | 5697 TEST_F(URLRequestTestHTTP, CancelOnDataReceived) { |
| 5630 ASSERT_TRUE(http_test_server()->Start()); | 5698 ASSERT_TRUE(http_test_server()->Start()); |
| 5631 | 5699 |
| 5632 TestDelegate d; | 5700 TestDelegate d; |
| 5633 { | 5701 { |
| 5634 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5702 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5635 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 5703 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 5704 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5636 | 5705 |
| 5637 d.set_cancel_in_received_data(true); | 5706 d.set_cancel_in_received_data(true); |
| 5638 | 5707 |
| 5639 r->Start(); | 5708 r->Start(); |
| 5640 EXPECT_TRUE(r->is_pending()); | 5709 EXPECT_TRUE(r->is_pending()); |
| 5641 | 5710 |
| 5642 base::RunLoop().Run(); | 5711 base::RunLoop().Run(); |
| 5643 | 5712 |
| 5644 EXPECT_EQ(1, d.response_started_count()); | 5713 EXPECT_EQ(1, d.response_started_count()); |
| 5645 EXPECT_NE(0, d.received_bytes_count()); | 5714 EXPECT_NE(0, d.received_bytes_count()); |
| 5646 EXPECT_FALSE(d.received_data_before_response()); | 5715 EXPECT_FALSE(d.received_data_before_response()); |
| 5647 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 5716 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 5648 } | 5717 } |
| 5649 } | 5718 } |
| 5650 | 5719 |
| 5651 TEST_F(URLRequestTestHTTP, CancelDuringEofRead) { | 5720 TEST_F(URLRequestTestHTTP, CancelDuringEofRead) { |
| 5652 ASSERT_TRUE(http_test_server()->Start()); | 5721 ASSERT_TRUE(http_test_server()->Start()); |
| 5653 | 5722 |
| 5654 TestDelegate d; | 5723 TestDelegate d; |
| 5655 { | 5724 { |
| 5656 // This returns an empty response (With headers). | 5725 // This returns an empty response (With headers). |
| 5657 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5726 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5658 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 5727 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d, |
| 5728 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5659 | 5729 |
| 5660 d.set_cancel_in_received_data(true); | 5730 d.set_cancel_in_received_data(true); |
| 5661 | 5731 |
| 5662 r->Start(); | 5732 r->Start(); |
| 5663 EXPECT_TRUE(r->is_pending()); | 5733 EXPECT_TRUE(r->is_pending()); |
| 5664 | 5734 |
| 5665 base::RunLoop().Run(); | 5735 base::RunLoop().Run(); |
| 5666 | 5736 |
| 5667 EXPECT_EQ(1, d.response_started_count()); | 5737 EXPECT_EQ(1, d.response_started_count()); |
| 5668 EXPECT_EQ(0, d.received_bytes_count()); | 5738 EXPECT_EQ(0, d.received_bytes_count()); |
| 5669 EXPECT_FALSE(d.received_data_before_response()); | 5739 EXPECT_FALSE(d.received_data_before_response()); |
| 5670 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 5740 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 5671 } | 5741 } |
| 5672 } | 5742 } |
| 5673 | 5743 |
| 5674 TEST_F(URLRequestTestHTTP, CancelByDestroyingAfterStart) { | 5744 TEST_F(URLRequestTestHTTP, CancelByDestroyingAfterStart) { |
| 5675 ASSERT_TRUE(http_test_server()->Start()); | 5745 ASSERT_TRUE(http_test_server()->Start()); |
| 5676 | 5746 |
| 5677 TestDelegate d; | 5747 TestDelegate d; |
| 5678 { | 5748 { |
| 5679 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5749 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5680 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 5750 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d, |
| 5751 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5681 | 5752 |
| 5682 r->Start(); | 5753 r->Start(); |
| 5683 EXPECT_TRUE(r->is_pending()); | 5754 EXPECT_TRUE(r->is_pending()); |
| 5684 | 5755 |
| 5685 // The request will be implicitly canceled when it is destroyed. The | 5756 // The request will be implicitly canceled when it is destroyed. The |
| 5686 // test delegate must not post a quit message when this happens because | 5757 // test delegate must not post a quit message when this happens because |
| 5687 // this test doesn't actually have a message loop. The quit message would | 5758 // this test doesn't actually have a message loop. The quit message would |
| 5688 // get put on this thread's message queue and the next test would exit | 5759 // get put on this thread's message queue and the next test would exit |
| 5689 // early, causing problems. | 5760 // early, causing problems. |
| 5690 d.set_quit_on_complete(false); | 5761 d.set_quit_on_complete(false); |
| 5691 } | 5762 } |
| 5692 // expect things to just cleanup properly. | 5763 // expect things to just cleanup properly. |
| 5693 | 5764 |
| 5694 // we won't actually get a received response here because we've never run the | 5765 // we won't actually get a received response here because we've never run the |
| 5695 // message loop | 5766 // message loop |
| 5696 EXPECT_FALSE(d.received_data_before_response()); | 5767 EXPECT_FALSE(d.received_data_before_response()); |
| 5697 EXPECT_EQ(0, d.bytes_received()); | 5768 EXPECT_EQ(0, d.bytes_received()); |
| 5698 } | 5769 } |
| 5699 | 5770 |
| 5700 TEST_F(URLRequestTestHTTP, CancelWhileReadingFromCache) { | 5771 TEST_F(URLRequestTestHTTP, CancelWhileReadingFromCache) { |
| 5701 ASSERT_TRUE(http_test_server()->Start()); | 5772 ASSERT_TRUE(http_test_server()->Start()); |
| 5702 | 5773 |
| 5703 // populate cache | 5774 // populate cache |
| 5704 { | 5775 { |
| 5705 TestDelegate d; | 5776 TestDelegate d; |
| 5706 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5777 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5707 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); | 5778 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d, |
| 5779 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5708 r->Start(); | 5780 r->Start(); |
| 5709 base::RunLoop().Run(); | 5781 base::RunLoop().Run(); |
| 5710 EXPECT_EQ(OK, d.request_status()); | 5782 EXPECT_EQ(OK, d.request_status()); |
| 5711 } | 5783 } |
| 5712 | 5784 |
| 5713 // cancel read from cache (see bug 990242) | 5785 // cancel read from cache (see bug 990242) |
| 5714 { | 5786 { |
| 5715 TestDelegate d; | 5787 TestDelegate d; |
| 5716 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5788 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5717 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); | 5789 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d, |
| 5790 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5718 r->Start(); | 5791 r->Start(); |
| 5719 r->Cancel(); | 5792 r->Cancel(); |
| 5720 base::RunLoop().Run(); | 5793 base::RunLoop().Run(); |
| 5721 | 5794 |
| 5722 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 5795 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 5723 EXPECT_EQ(1, d.response_started_count()); | 5796 EXPECT_EQ(1, d.response_started_count()); |
| 5724 EXPECT_EQ(0, d.bytes_received()); | 5797 EXPECT_EQ(0, d.bytes_received()); |
| 5725 EXPECT_FALSE(d.received_data_before_response()); | 5798 EXPECT_FALSE(d.received_data_before_response()); |
| 5726 } | 5799 } |
| 5727 } | 5800 } |
| 5728 | 5801 |
| 5729 TEST_F(URLRequestTestHTTP, PostTest) { | 5802 TEST_F(URLRequestTestHTTP, PostTest) { |
| 5730 ASSERT_TRUE(http_test_server()->Start()); | 5803 ASSERT_TRUE(http_test_server()->Start()); |
| 5731 HTTPUploadDataOperationTest("POST"); | 5804 HTTPUploadDataOperationTest("POST"); |
| 5732 } | 5805 } |
| 5733 | 5806 |
| 5734 TEST_F(URLRequestTestHTTP, PutTest) { | 5807 TEST_F(URLRequestTestHTTP, PutTest) { |
| 5735 ASSERT_TRUE(http_test_server()->Start()); | 5808 ASSERT_TRUE(http_test_server()->Start()); |
| 5736 HTTPUploadDataOperationTest("PUT"); | 5809 HTTPUploadDataOperationTest("PUT"); |
| 5737 } | 5810 } |
| 5738 | 5811 |
| 5739 TEST_F(URLRequestTestHTTP, PostEmptyTest) { | 5812 TEST_F(URLRequestTestHTTP, PostEmptyTest) { |
| 5740 ASSERT_TRUE(http_test_server()->Start()); | 5813 ASSERT_TRUE(http_test_server()->Start()); |
| 5741 | 5814 |
| 5742 TestDelegate d; | 5815 TestDelegate d; |
| 5743 { | 5816 { |
| 5744 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5817 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5745 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5818 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d, |
| 5819 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5746 r->set_method("POST"); | 5820 r->set_method("POST"); |
| 5747 | 5821 |
| 5748 r->Start(); | 5822 r->Start(); |
| 5749 EXPECT_TRUE(r->is_pending()); | 5823 EXPECT_TRUE(r->is_pending()); |
| 5750 | 5824 |
| 5751 base::RunLoop().Run(); | 5825 base::RunLoop().Run(); |
| 5752 | 5826 |
| 5753 ASSERT_EQ(1, d.response_started_count()) << "request failed. Error: " | 5827 ASSERT_EQ(1, d.response_started_count()) << "request failed. Error: " |
| 5754 << d.request_status(); | 5828 << d.request_status(); |
| 5755 | 5829 |
| 5756 EXPECT_FALSE(d.received_data_before_response()); | 5830 EXPECT_FALSE(d.received_data_before_response()); |
| 5757 EXPECT_TRUE(d.data_received().empty()); | 5831 EXPECT_TRUE(d.data_received().empty()); |
| 5758 } | 5832 } |
| 5759 } | 5833 } |
| 5760 | 5834 |
| 5761 TEST_F(URLRequestTestHTTP, PostFileTest) { | 5835 TEST_F(URLRequestTestHTTP, PostFileTest) { |
| 5762 ASSERT_TRUE(http_test_server()->Start()); | 5836 ASSERT_TRUE(http_test_server()->Start()); |
| 5763 | 5837 |
| 5764 TestDelegate d; | 5838 TestDelegate d; |
| 5765 { | 5839 { |
| 5766 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5840 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5767 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5841 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d, |
| 5842 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5768 r->set_method("POST"); | 5843 r->set_method("POST"); |
| 5769 | 5844 |
| 5770 base::FilePath dir; | 5845 base::FilePath dir; |
| 5771 PathService::Get(base::DIR_EXE, &dir); | 5846 PathService::Get(base::DIR_EXE, &dir); |
| 5772 base::SetCurrentDirectory(dir); | 5847 base::SetCurrentDirectory(dir); |
| 5773 | 5848 |
| 5774 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 5849 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 5775 | 5850 |
| 5776 base::FilePath path; | 5851 base::FilePath path; |
| 5777 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 5852 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| (...skipping 27 matching lines...) Expand all Loading... |
| 5805 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); | 5880 EXPECT_EQ(std::string(&buf[0], size), d.data_received()); |
| 5806 } | 5881 } |
| 5807 } | 5882 } |
| 5808 | 5883 |
| 5809 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { | 5884 TEST_F(URLRequestTestHTTP, PostUnreadableFileTest) { |
| 5810 ASSERT_TRUE(http_test_server()->Start()); | 5885 ASSERT_TRUE(http_test_server()->Start()); |
| 5811 | 5886 |
| 5812 TestDelegate d; | 5887 TestDelegate d; |
| 5813 { | 5888 { |
| 5814 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5889 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5815 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5890 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d, |
| 5891 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5816 r->set_method("POST"); | 5892 r->set_method("POST"); |
| 5817 | 5893 |
| 5818 std::vector<std::unique_ptr<UploadElementReader>> element_readers; | 5894 std::vector<std::unique_ptr<UploadElementReader>> element_readers; |
| 5819 | 5895 |
| 5820 element_readers.push_back(base::MakeUnique<UploadFileElementReader>( | 5896 element_readers.push_back(base::MakeUnique<UploadFileElementReader>( |
| 5821 base::ThreadTaskRunnerHandle::Get().get(), | 5897 base::ThreadTaskRunnerHandle::Get().get(), |
| 5822 base::FilePath(FILE_PATH_LITERAL( | 5898 base::FilePath(FILE_PATH_LITERAL( |
| 5823 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | 5899 "c:\\path\\to\\non\\existant\\file.randomness.12345")), |
| 5824 0, std::numeric_limits<uint64_t>::max(), base::Time())); | 5900 0, std::numeric_limits<uint64_t>::max(), base::Time())); |
| 5825 r->set_upload(base::WrapUnique<UploadDataStream>( | 5901 r->set_upload(base::WrapUnique<UploadDataStream>( |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5867 } | 5943 } |
| 5868 | 5944 |
| 5869 } // namespace | 5945 } // namespace |
| 5870 | 5946 |
| 5871 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { | 5947 TEST_F(URLRequestTestHTTP, TestPostChunkedDataBeforeStart) { |
| 5872 ASSERT_TRUE(http_test_server()->Start()); | 5948 ASSERT_TRUE(http_test_server()->Start()); |
| 5873 | 5949 |
| 5874 TestDelegate d; | 5950 TestDelegate d; |
| 5875 { | 5951 { |
| 5876 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5952 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5877 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5953 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d, |
| 5954 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5878 std::unique_ptr<ChunkedUploadDataStream> upload_data_stream( | 5955 std::unique_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5879 new ChunkedUploadDataStream(0)); | 5956 new ChunkedUploadDataStream(0)); |
| 5880 std::unique_ptr<ChunkedUploadDataStream::Writer> writer = | 5957 std::unique_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5881 upload_data_stream->CreateWriter(); | 5958 upload_data_stream->CreateWriter(); |
| 5882 r->set_upload(std::move(upload_data_stream)); | 5959 r->set_upload(std::move(upload_data_stream)); |
| 5883 r->set_method("POST"); | 5960 r->set_method("POST"); |
| 5884 AddDataToUpload(writer.get()); | 5961 AddDataToUpload(writer.get()); |
| 5885 r->Start(); | 5962 r->Start(); |
| 5886 EXPECT_TRUE(r->is_pending()); | 5963 EXPECT_TRUE(r->is_pending()); |
| 5887 | 5964 |
| 5888 base::RunLoop().Run(); | 5965 base::RunLoop().Run(); |
| 5889 | 5966 |
| 5890 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5967 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5891 } | 5968 } |
| 5892 } | 5969 } |
| 5893 | 5970 |
| 5894 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { | 5971 TEST_F(URLRequestTestHTTP, TestPostChunkedDataJustAfterStart) { |
| 5895 ASSERT_TRUE(http_test_server()->Start()); | 5972 ASSERT_TRUE(http_test_server()->Start()); |
| 5896 | 5973 |
| 5897 TestDelegate d; | 5974 TestDelegate d; |
| 5898 { | 5975 { |
| 5899 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5976 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5900 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 5977 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d, |
| 5978 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5901 std::unique_ptr<ChunkedUploadDataStream> upload_data_stream( | 5979 std::unique_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5902 new ChunkedUploadDataStream(0)); | 5980 new ChunkedUploadDataStream(0)); |
| 5903 std::unique_ptr<ChunkedUploadDataStream::Writer> writer = | 5981 std::unique_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5904 upload_data_stream->CreateWriter(); | 5982 upload_data_stream->CreateWriter(); |
| 5905 r->set_upload(base::WrapUnique(upload_data_stream.release())); | 5983 r->set_upload(base::WrapUnique(upload_data_stream.release())); |
| 5906 r->set_method("POST"); | 5984 r->set_method("POST"); |
| 5907 r->Start(); | 5985 r->Start(); |
| 5908 EXPECT_TRUE(r->is_pending()); | 5986 EXPECT_TRUE(r->is_pending()); |
| 5909 AddDataToUpload(writer.get()); | 5987 AddDataToUpload(writer.get()); |
| 5910 base::RunLoop().Run(); | 5988 base::RunLoop().Run(); |
| 5911 | 5989 |
| 5912 VerifyReceivedDataMatchesChunks(r.get(), &d); | 5990 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5913 } | 5991 } |
| 5914 } | 5992 } |
| 5915 | 5993 |
| 5916 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { | 5994 TEST_F(URLRequestTestHTTP, TestPostChunkedDataAfterStart) { |
| 5917 ASSERT_TRUE(http_test_server()->Start()); | 5995 ASSERT_TRUE(http_test_server()->Start()); |
| 5918 | 5996 |
| 5919 TestDelegate d; | 5997 TestDelegate d; |
| 5920 { | 5998 { |
| 5921 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 5999 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 5922 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d)); | 6000 http_test_server()->GetURL("/echo"), DEFAULT_PRIORITY, &d, |
| 6001 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5923 std::unique_ptr<ChunkedUploadDataStream> upload_data_stream( | 6002 std::unique_ptr<ChunkedUploadDataStream> upload_data_stream( |
| 5924 new ChunkedUploadDataStream(0)); | 6003 new ChunkedUploadDataStream(0)); |
| 5925 std::unique_ptr<ChunkedUploadDataStream::Writer> writer = | 6004 std::unique_ptr<ChunkedUploadDataStream::Writer> writer = |
| 5926 upload_data_stream->CreateWriter(); | 6005 upload_data_stream->CreateWriter(); |
| 5927 r->set_upload(std::move(upload_data_stream)); | 6006 r->set_upload(std::move(upload_data_stream)); |
| 5928 r->set_method("POST"); | 6007 r->set_method("POST"); |
| 5929 r->Start(); | 6008 r->Start(); |
| 5930 EXPECT_TRUE(r->is_pending()); | 6009 EXPECT_TRUE(r->is_pending()); |
| 5931 | 6010 |
| 5932 base::RunLoop().RunUntilIdle(); | 6011 base::RunLoop().RunUntilIdle(); |
| 5933 AddDataToUpload(writer.get()); | 6012 AddDataToUpload(writer.get()); |
| 5934 base::RunLoop().Run(); | 6013 base::RunLoop().Run(); |
| 5935 | 6014 |
| 5936 VerifyReceivedDataMatchesChunks(r.get(), &d); | 6015 VerifyReceivedDataMatchesChunks(r.get(), &d); |
| 5937 } | 6016 } |
| 5938 } | 6017 } |
| 5939 | 6018 |
| 5940 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { | 6019 TEST_F(URLRequestTestHTTP, ResponseHeadersTest) { |
| 5941 ASSERT_TRUE(http_test_server()->Start()); | 6020 ASSERT_TRUE(http_test_server()->Start()); |
| 5942 | 6021 |
| 5943 TestDelegate d; | 6022 TestDelegate d; |
| 5944 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 6023 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 5945 http_test_server()->GetURL("/with-headers.html"), DEFAULT_PRIORITY, &d)); | 6024 http_test_server()->GetURL("/with-headers.html"), DEFAULT_PRIORITY, &d, |
| 6025 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5946 req->Start(); | 6026 req->Start(); |
| 5947 base::RunLoop().Run(); | 6027 base::RunLoop().Run(); |
| 5948 | 6028 |
| 5949 const HttpResponseHeaders* headers = req->response_headers(); | 6029 const HttpResponseHeaders* headers = req->response_headers(); |
| 5950 | 6030 |
| 5951 // Simple sanity check that response_info() accesses the same data. | 6031 // Simple sanity check that response_info() accesses the same data. |
| 5952 EXPECT_EQ(headers, req->response_info().headers.get()); | 6032 EXPECT_EQ(headers, req->response_info().headers.get()); |
| 5953 | 6033 |
| 5954 std::string header; | 6034 std::string header; |
| 5955 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); | 6035 EXPECT_TRUE(headers->GetNormalizedHeader("cache-control", &header)); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 5973 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 6053 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 5974 https_test_server.SetSSLConfig( | 6054 https_test_server.SetSSLConfig( |
| 5975 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 6055 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 5976 https_test_server.ServeFilesFromSourceDirectory( | 6056 https_test_server.ServeFilesFromSourceDirectory( |
| 5977 base::FilePath(kTestFilePath)); | 6057 base::FilePath(kTestFilePath)); |
| 5978 ASSERT_TRUE(https_test_server.Start()); | 6058 ASSERT_TRUE(https_test_server.Start()); |
| 5979 | 6059 |
| 5980 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6060 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 5981 TestDelegate d; | 6061 TestDelegate d; |
| 5982 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( | 6062 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5983 https_test_server.GetURL("/hsts-headers.html"), DEFAULT_PRIORITY, &d)); | 6063 https_test_server.GetURL("/hsts-headers.html"), DEFAULT_PRIORITY, &d, |
| 6064 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 5984 request->Start(); | 6065 request->Start(); |
| 5985 base::RunLoop().Run(); | 6066 base::RunLoop().Run(); |
| 5986 | 6067 |
| 5987 TransportSecurityState* security_state = | 6068 TransportSecurityState* security_state = |
| 5988 default_context_.transport_security_state(); | 6069 default_context_.transport_security_state(); |
| 5989 TransportSecurityState::STSState sts_state; | 6070 TransportSecurityState::STSState sts_state; |
| 5990 TransportSecurityState::PKPState pkp_state; | 6071 TransportSecurityState::PKPState pkp_state; |
| 5991 EXPECT_TRUE( | 6072 EXPECT_TRUE( |
| 5992 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 6073 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 5993 EXPECT_FALSE( | 6074 EXPECT_FALSE( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 6008 https_test_server.ServeFilesFromSourceDirectory( | 6089 https_test_server.ServeFilesFromSourceDirectory( |
| 6009 base::FilePath(kTestFilePath)); | 6090 base::FilePath(kTestFilePath)); |
| 6010 ASSERT_TRUE(https_test_server.Start()); | 6091 ASSERT_TRUE(https_test_server.Start()); |
| 6011 // Make sure this test fails if the test server is changed to not | 6092 // Make sure this test fails if the test server is changed to not |
| 6012 // listen on an IP by default. | 6093 // listen on an IP by default. |
| 6013 ASSERT_TRUE(https_test_server.GetURL("/").HostIsIPAddress()); | 6094 ASSERT_TRUE(https_test_server.GetURL("/").HostIsIPAddress()); |
| 6014 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6095 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6015 | 6096 |
| 6016 TestDelegate d; | 6097 TestDelegate d; |
| 6017 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( | 6098 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( |
| 6018 https_test_server.GetURL("/hsts-headers.html"), DEFAULT_PRIORITY, &d)); | 6099 https_test_server.GetURL("/hsts-headers.html"), DEFAULT_PRIORITY, &d, |
| 6100 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6019 request->Start(); | 6101 request->Start(); |
| 6020 base::RunLoop().Run(); | 6102 base::RunLoop().Run(); |
| 6021 TransportSecurityState* security_state = | 6103 TransportSecurityState* security_state = |
| 6022 default_context_.transport_security_state(); | 6104 default_context_.transport_security_state(); |
| 6023 TransportSecurityState::STSState sts_state; | 6105 TransportSecurityState::STSState sts_state; |
| 6024 EXPECT_FALSE( | 6106 EXPECT_FALSE( |
| 6025 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 6107 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 6026 } | 6108 } |
| 6027 | 6109 |
| 6028 namespace { | 6110 namespace { |
| (...skipping 11 matching lines...) Expand all Loading... |
| 6040 https_test_server.SetSSLConfig( | 6122 https_test_server.SetSSLConfig( |
| 6041 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 6123 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 6042 https_test_server.ServeFilesFromSourceDirectory( | 6124 https_test_server.ServeFilesFromSourceDirectory( |
| 6043 base::FilePath(kTestFilePath)); | 6125 base::FilePath(kTestFilePath)); |
| 6044 ASSERT_TRUE(https_test_server.Start()); | 6126 ASSERT_TRUE(https_test_server.Start()); |
| 6045 | 6127 |
| 6046 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6128 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6047 | 6129 |
| 6048 TestDelegate d; | 6130 TestDelegate d; |
| 6049 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( | 6131 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( |
| 6050 https_test_server.GetURL("/hpkp-headers.html"), DEFAULT_PRIORITY, &d)); | 6132 https_test_server.GetURL("/hpkp-headers.html"), DEFAULT_PRIORITY, &d, |
| 6133 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6051 request->Start(); | 6134 request->Start(); |
| 6052 base::RunLoop().Run(); | 6135 base::RunLoop().Run(); |
| 6053 TransportSecurityState* security_state = | 6136 TransportSecurityState* security_state = |
| 6054 default_context_.transport_security_state(); | 6137 default_context_.transport_security_state(); |
| 6055 TransportSecurityState::STSState sts_state; | 6138 TransportSecurityState::STSState sts_state; |
| 6056 TransportSecurityState::PKPState pkp_state; | 6139 TransportSecurityState::PKPState pkp_state; |
| 6057 EXPECT_FALSE( | 6140 EXPECT_FALSE( |
| 6058 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 6141 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 6059 EXPECT_TRUE( | 6142 EXPECT_TRUE( |
| 6060 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); | 6143 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6119 TestNetworkDelegate network_delegate; | 6202 TestNetworkDelegate network_delegate; |
| 6120 TestURLRequestContext context(true); | 6203 TestURLRequestContext context(true); |
| 6121 context.set_transport_security_state(&security_state); | 6204 context.set_transport_security_state(&security_state); |
| 6122 context.set_network_delegate(&network_delegate); | 6205 context.set_network_delegate(&network_delegate); |
| 6123 context.set_cert_verifier(&cert_verifier); | 6206 context.set_cert_verifier(&cert_verifier); |
| 6124 context.Init(); | 6207 context.Init(); |
| 6125 | 6208 |
| 6126 // Now send a request to trigger the violation. | 6209 // Now send a request to trigger the violation. |
| 6127 TestDelegate d; | 6210 TestDelegate d; |
| 6128 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( | 6211 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( |
| 6129 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); | 6212 https_test_server.GetURL("/simple.html"), DEFAULT_PRIORITY, &d, |
| 6213 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6130 violating_request->Start(); | 6214 violating_request->Start(); |
| 6131 base::RunLoop().Run(); | 6215 base::RunLoop().Run(); |
| 6132 | 6216 |
| 6133 // Check that a report was sent. | 6217 // Check that a report was sent. |
| 6134 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); | 6218 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); |
| 6135 ASSERT_FALSE(mock_report_sender.latest_report().empty()); | 6219 ASSERT_FALSE(mock_report_sender.latest_report().empty()); |
| 6136 EXPECT_EQ("application/json; charset=utf-8", | 6220 EXPECT_EQ("application/json; charset=utf-8", |
| 6137 mock_report_sender.latest_content_type()); | 6221 mock_report_sender.latest_content_type()); |
| 6138 std::unique_ptr<base::Value> value( | 6222 std::unique_ptr<base::Value> value( |
| 6139 base::JSONReader::Read(mock_report_sender.latest_report())); | 6223 base::JSONReader::Read(mock_report_sender.latest_report())); |
| (...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6184 TestURLRequestContext context(true); | 6268 TestURLRequestContext context(true); |
| 6185 context.set_transport_security_state(&security_state); | 6269 context.set_transport_security_state(&security_state); |
| 6186 context.set_network_delegate(&network_delegate); | 6270 context.set_network_delegate(&network_delegate); |
| 6187 context.set_cert_verifier(&cert_verifier); | 6271 context.set_cert_verifier(&cert_verifier); |
| 6188 context.Init(); | 6272 context.Init(); |
| 6189 | 6273 |
| 6190 // Now send a request to trigger the violation. | 6274 // Now send a request to trigger the violation. |
| 6191 TestDelegate d; | 6275 TestDelegate d; |
| 6192 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( | 6276 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( |
| 6193 https_test_server.GetURL("/hpkp-headers-report-only.html"), | 6277 https_test_server.GetURL("/hpkp-headers-report-only.html"), |
| 6194 DEFAULT_PRIORITY, &d)); | 6278 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6195 violating_request->Start(); | 6279 violating_request->Start(); |
| 6196 base::RunLoop().Run(); | 6280 base::RunLoop().Run(); |
| 6197 | 6281 |
| 6198 // Check that a report was sent. | 6282 // Check that a report was sent. |
| 6199 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); | 6283 EXPECT_EQ(report_uri, mock_report_sender.latest_report_uri()); |
| 6200 ASSERT_FALSE(mock_report_sender.latest_report().empty()); | 6284 ASSERT_FALSE(mock_report_sender.latest_report().empty()); |
| 6201 EXPECT_EQ("application/json; charset=utf-8", | 6285 EXPECT_EQ("application/json; charset=utf-8", |
| 6202 mock_report_sender.latest_content_type()); | 6286 mock_report_sender.latest_content_type()); |
| 6203 std::unique_ptr<base::Value> value( | 6287 std::unique_ptr<base::Value> value( |
| 6204 base::JSONReader::Read(mock_report_sender.latest_report())); | 6288 base::JSONReader::Read(mock_report_sender.latest_report())); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 6234 context.set_transport_security_state(&security_state); | 6318 context.set_transport_security_state(&security_state); |
| 6235 context.set_network_delegate(&network_delegate); | 6319 context.set_network_delegate(&network_delegate); |
| 6236 context.set_cert_verifier(&mock_cert_verifier); | 6320 context.set_cert_verifier(&mock_cert_verifier); |
| 6237 mock_cert_verifier.set_default_result(OK); | 6321 mock_cert_verifier.set_default_result(OK); |
| 6238 context.Init(); | 6322 context.Init(); |
| 6239 | 6323 |
| 6240 // Now send a request that does not trigger the violation. | 6324 // Now send a request that does not trigger the violation. |
| 6241 TestDelegate d; | 6325 TestDelegate d; |
| 6242 std::unique_ptr<URLRequest> request(context.CreateRequest( | 6326 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 6243 https_test_server.GetURL("/hpkp-headers-report-only.html"), | 6327 https_test_server.GetURL("/hpkp-headers-report-only.html"), |
| 6244 DEFAULT_PRIORITY, &d)); | 6328 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6245 request->Start(); | 6329 request->Start(); |
| 6246 base::RunLoop().Run(); | 6330 base::RunLoop().Run(); |
| 6247 | 6331 |
| 6248 // Check that a report was not sent. | 6332 // Check that a report was not sent. |
| 6249 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); | 6333 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); |
| 6250 EXPECT_EQ(std::string(), mock_report_sender.latest_report()); | 6334 EXPECT_EQ(std::string(), mock_report_sender.latest_report()); |
| 6251 } | 6335 } |
| 6252 | 6336 |
| 6253 TEST_F(URLRequestTestHTTP, PKPNotProcessedOnIP) { | 6337 TEST_F(URLRequestTestHTTP, PKPNotProcessedOnIP) { |
| 6254 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 6338 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 6255 https_test_server.ServeFilesFromSourceDirectory( | 6339 https_test_server.ServeFilesFromSourceDirectory( |
| 6256 base::FilePath(kTestFilePath)); | 6340 base::FilePath(kTestFilePath)); |
| 6257 ASSERT_TRUE(https_test_server.Start()); | 6341 ASSERT_TRUE(https_test_server.Start()); |
| 6258 // Make sure this test fails if the test server is changed to not | 6342 // Make sure this test fails if the test server is changed to not |
| 6259 // listen on an IP by default. | 6343 // listen on an IP by default. |
| 6260 ASSERT_TRUE(https_test_server.GetURL("/").HostIsIPAddress()); | 6344 ASSERT_TRUE(https_test_server.GetURL("/").HostIsIPAddress()); |
| 6261 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6345 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6262 | 6346 |
| 6263 TestDelegate d; | 6347 TestDelegate d; |
| 6264 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( | 6348 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( |
| 6265 https_test_server.GetURL("/hpkp-headers.html"), DEFAULT_PRIORITY, &d)); | 6349 https_test_server.GetURL("/hpkp-headers.html"), DEFAULT_PRIORITY, &d, |
| 6350 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6266 request->Start(); | 6351 request->Start(); |
| 6267 base::RunLoop().Run(); | 6352 base::RunLoop().Run(); |
| 6268 | 6353 |
| 6269 TransportSecurityState* security_state = | 6354 TransportSecurityState* security_state = |
| 6270 default_context_.transport_security_state(); | 6355 default_context_.transport_security_state(); |
| 6271 TransportSecurityState::PKPState pkp_state; | 6356 TransportSecurityState::PKPState pkp_state; |
| 6272 EXPECT_FALSE( | 6357 EXPECT_FALSE( |
| 6273 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); | 6358 security_state->GetDynamicPKPState(test_server_hostname, &pkp_state)); |
| 6274 } | 6359 } |
| 6275 | 6360 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6314 | 6399 |
| 6315 TestNetworkDelegate network_delegate; | 6400 TestNetworkDelegate network_delegate; |
| 6316 TestURLRequestContext context(true); | 6401 TestURLRequestContext context(true); |
| 6317 context.set_transport_security_state(&security_state); | 6402 context.set_transport_security_state(&security_state); |
| 6318 context.set_network_delegate(&network_delegate); | 6403 context.set_network_delegate(&network_delegate); |
| 6319 context.set_cert_verifier(&cert_verifier); | 6404 context.set_cert_verifier(&cert_verifier); |
| 6320 context.Init(); | 6405 context.Init(); |
| 6321 | 6406 |
| 6322 TestDelegate d; | 6407 TestDelegate d; |
| 6323 std::unique_ptr<URLRequest> request(context.CreateRequest( | 6408 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 6324 https_test_server.GetURL("/hpkp-headers.html"), DEFAULT_PRIORITY, &d)); | 6409 https_test_server.GetURL("/hpkp-headers.html"), DEFAULT_PRIORITY, &d, |
| 6410 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6325 request->Start(); | 6411 request->Start(); |
| 6326 base::RunLoop().Run(); | 6412 base::RunLoop().Run(); |
| 6327 | 6413 |
| 6328 TransportSecurityState::PKPState pkp_state; | 6414 TransportSecurityState::PKPState pkp_state; |
| 6329 EXPECT_TRUE( | 6415 EXPECT_TRUE( |
| 6330 security_state.GetDynamicPKPState(test_server_hostname, &pkp_state)); | 6416 security_state.GetDynamicPKPState(test_server_hostname, &pkp_state)); |
| 6331 EXPECT_TRUE(request->ssl_info().pkp_bypassed); | 6417 EXPECT_TRUE(request->ssl_info().pkp_bypassed); |
| 6332 } | 6418 } |
| 6333 | 6419 |
| 6334 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { | 6420 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { |
| 6335 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 6421 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 6336 https_test_server.SetSSLConfig( | 6422 https_test_server.SetSSLConfig( |
| 6337 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 6423 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 6338 https_test_server.ServeFilesFromSourceDirectory( | 6424 https_test_server.ServeFilesFromSourceDirectory( |
| 6339 base::FilePath(kTestFilePath)); | 6425 base::FilePath(kTestFilePath)); |
| 6340 ASSERT_TRUE(https_test_server.Start()); | 6426 ASSERT_TRUE(https_test_server.Start()); |
| 6341 | 6427 |
| 6342 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6428 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6343 | 6429 |
| 6344 TestDelegate d; | 6430 TestDelegate d; |
| 6345 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( | 6431 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( |
| 6346 https_test_server.GetURL("/hsts-multiple-headers.html"), DEFAULT_PRIORITY, | 6432 https_test_server.GetURL("/hsts-multiple-headers.html"), DEFAULT_PRIORITY, |
| 6347 &d)); | 6433 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6348 request->Start(); | 6434 request->Start(); |
| 6349 base::RunLoop().Run(); | 6435 base::RunLoop().Run(); |
| 6350 | 6436 |
| 6351 // We should have set parameters from the first header, not the second. | 6437 // We should have set parameters from the first header, not the second. |
| 6352 TransportSecurityState* security_state = | 6438 TransportSecurityState* security_state = |
| 6353 default_context_.transport_security_state(); | 6439 default_context_.transport_security_state(); |
| 6354 TransportSecurityState::STSState sts_state; | 6440 TransportSecurityState::STSState sts_state; |
| 6355 EXPECT_TRUE( | 6441 EXPECT_TRUE( |
| 6356 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 6442 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 6357 EXPECT_EQ(TransportSecurityState::STSState::MODE_FORCE_HTTPS, | 6443 EXPECT_EQ(TransportSecurityState::STSState::MODE_FORCE_HTTPS, |
| 6358 sts_state.upgrade_mode); | 6444 sts_state.upgrade_mode); |
| 6359 EXPECT_FALSE(sts_state.include_subdomains); | 6445 EXPECT_FALSE(sts_state.include_subdomains); |
| 6360 EXPECT_FALSE(sts_state.include_subdomains); | 6446 EXPECT_FALSE(sts_state.include_subdomains); |
| 6361 } | 6447 } |
| 6362 | 6448 |
| 6363 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { | 6449 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { |
| 6364 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 6450 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 6365 https_test_server.SetSSLConfig( | 6451 https_test_server.SetSSLConfig( |
| 6366 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 6452 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 6367 https_test_server.ServeFilesFromSourceDirectory( | 6453 https_test_server.ServeFilesFromSourceDirectory( |
| 6368 base::FilePath(kTestFilePath)); | 6454 base::FilePath(kTestFilePath)); |
| 6369 ASSERT_TRUE(https_test_server.Start()); | 6455 ASSERT_TRUE(https_test_server.Start()); |
| 6370 | 6456 |
| 6371 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6457 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6372 | 6458 |
| 6373 TestDelegate d; | 6459 TestDelegate d; |
| 6374 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( | 6460 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( |
| 6375 https_test_server.GetURL("/hsts-and-hpkp-headers.html"), DEFAULT_PRIORITY, | 6461 https_test_server.GetURL("/hsts-and-hpkp-headers.html"), DEFAULT_PRIORITY, |
| 6376 &d)); | 6462 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6377 request->Start(); | 6463 request->Start(); |
| 6378 base::RunLoop().Run(); | 6464 base::RunLoop().Run(); |
| 6379 | 6465 |
| 6380 // We should have set parameters from the first header, not the second. | 6466 // We should have set parameters from the first header, not the second. |
| 6381 TransportSecurityState* security_state = | 6467 TransportSecurityState* security_state = |
| 6382 default_context_.transport_security_state(); | 6468 default_context_.transport_security_state(); |
| 6383 TransportSecurityState::STSState sts_state; | 6469 TransportSecurityState::STSState sts_state; |
| 6384 TransportSecurityState::PKPState pkp_state; | 6470 TransportSecurityState::PKPState pkp_state; |
| 6385 EXPECT_TRUE( | 6471 EXPECT_TRUE( |
| 6386 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 6472 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 6410 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); | 6496 net::EmbeddedTestServer::CERT_COMMON_NAME_IS_DOMAIN); |
| 6411 https_test_server.ServeFilesFromSourceDirectory( | 6497 https_test_server.ServeFilesFromSourceDirectory( |
| 6412 base::FilePath(kTestFilePath)); | 6498 base::FilePath(kTestFilePath)); |
| 6413 ASSERT_TRUE(https_test_server.Start()); | 6499 ASSERT_TRUE(https_test_server.Start()); |
| 6414 | 6500 |
| 6415 std::string test_server_hostname = https_test_server.GetURL("/").host(); | 6501 std::string test_server_hostname = https_test_server.GetURL("/").host(); |
| 6416 | 6502 |
| 6417 TestDelegate d; | 6503 TestDelegate d; |
| 6418 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( | 6504 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( |
| 6419 https_test_server.GetURL("/hsts-and-hpkp-headers2.html"), | 6505 https_test_server.GetURL("/hsts-and-hpkp-headers2.html"), |
| 6420 DEFAULT_PRIORITY, &d)); | 6506 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6421 request->Start(); | 6507 request->Start(); |
| 6422 base::RunLoop().Run(); | 6508 base::RunLoop().Run(); |
| 6423 | 6509 |
| 6424 TransportSecurityState* security_state = | 6510 TransportSecurityState* security_state = |
| 6425 default_context_.transport_security_state(); | 6511 default_context_.transport_security_state(); |
| 6426 TransportSecurityState::STSState sts_state; | 6512 TransportSecurityState::STSState sts_state; |
| 6427 TransportSecurityState::PKPState pkp_state; | 6513 TransportSecurityState::PKPState pkp_state; |
| 6428 EXPECT_TRUE( | 6514 EXPECT_TRUE( |
| 6429 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); | 6515 security_state->GetDynamicSTSState(test_server_hostname, &sts_state)); |
| 6430 EXPECT_TRUE( | 6516 EXPECT_TRUE( |
| (...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6528 context.set_cert_transparency_verifier(&ct_verifier); | 6614 context.set_cert_transparency_verifier(&ct_verifier); |
| 6529 context.set_ct_policy_enforcer(std::move(&ct_policy_enforcer)); | 6615 context.set_ct_policy_enforcer(std::move(&ct_policy_enforcer)); |
| 6530 context.Init(); | 6616 context.Init(); |
| 6531 | 6617 |
| 6532 // Now send a request to trigger the violation. | 6618 // Now send a request to trigger the violation. |
| 6533 TestDelegate d; | 6619 TestDelegate d; |
| 6534 GURL url = https_test_server.GetURL("/expect-ct-header.html"); | 6620 GURL url = https_test_server.GetURL("/expect-ct-header.html"); |
| 6535 GURL::Replacements replace_host; | 6621 GURL::Replacements replace_host; |
| 6536 replace_host.SetHostStr(kExpectCTStaticHostname); | 6622 replace_host.SetHostStr(kExpectCTStaticHostname); |
| 6537 url = url.ReplaceComponents(replace_host); | 6623 url = url.ReplaceComponents(replace_host); |
| 6538 std::unique_ptr<URLRequest> violating_request( | 6624 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( |
| 6539 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 6625 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6540 violating_request->Start(); | 6626 violating_request->Start(); |
| 6541 base::RunLoop().Run(); | 6627 base::RunLoop().Run(); |
| 6542 | 6628 |
| 6543 EXPECT_EQ(1u, reporter.num_failures()); | 6629 EXPECT_EQ(1u, reporter.num_failures()); |
| 6544 } | 6630 } |
| 6545 | 6631 |
| 6546 namespace { | 6632 namespace { |
| 6547 | 6633 |
| 6548 class TestReportingService : public ReportingService { | 6634 class TestReportingService : public ReportingService { |
| 6549 public: | 6635 public: |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6588 http_test_server()->RegisterRequestHandler(base::Bind(&SendReportToHeader)); | 6674 http_test_server()->RegisterRequestHandler(base::Bind(&SendReportToHeader)); |
| 6589 ASSERT_TRUE(http_test_server()->Start()); | 6675 ASSERT_TRUE(http_test_server()->Start()); |
| 6590 GURL request_url = http_test_server()->GetURL("/"); | 6676 GURL request_url = http_test_server()->GetURL("/"); |
| 6591 | 6677 |
| 6592 TestNetworkDelegate network_delegate; | 6678 TestNetworkDelegate network_delegate; |
| 6593 TestURLRequestContext context(true); | 6679 TestURLRequestContext context(true); |
| 6594 context.set_network_delegate(&network_delegate); | 6680 context.set_network_delegate(&network_delegate); |
| 6595 context.Init(); | 6681 context.Init(); |
| 6596 | 6682 |
| 6597 TestDelegate d; | 6683 TestDelegate d; |
| 6598 std::unique_ptr<URLRequest> request( | 6684 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 6599 context.CreateRequest(request_url, DEFAULT_PRIORITY, &d)); | 6685 request_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6600 request->Start(); | 6686 request->Start(); |
| 6601 base::RunLoop().Run(); | 6687 base::RunLoop().Run(); |
| 6602 } | 6688 } |
| 6603 | 6689 |
| 6604 TEST_F(URLRequestTestHTTP, DontProcessReportToHeaderHTTP) { | 6690 TEST_F(URLRequestTestHTTP, DontProcessReportToHeaderHTTP) { |
| 6605 http_test_server()->RegisterRequestHandler(base::Bind(&SendReportToHeader)); | 6691 http_test_server()->RegisterRequestHandler(base::Bind(&SendReportToHeader)); |
| 6606 ASSERT_TRUE(http_test_server()->Start()); | 6692 ASSERT_TRUE(http_test_server()->Start()); |
| 6607 GURL request_url = http_test_server()->GetURL("/"); | 6693 GURL request_url = http_test_server()->GetURL("/"); |
| 6608 | 6694 |
| 6609 TestNetworkDelegate network_delegate; | 6695 TestNetworkDelegate network_delegate; |
| 6610 TestReportingService reporting_service; | 6696 TestReportingService reporting_service; |
| 6611 TestURLRequestContext context(true); | 6697 TestURLRequestContext context(true); |
| 6612 context.set_network_delegate(&network_delegate); | 6698 context.set_network_delegate(&network_delegate); |
| 6613 context.set_reporting_service(&reporting_service); | 6699 context.set_reporting_service(&reporting_service); |
| 6614 context.Init(); | 6700 context.Init(); |
| 6615 | 6701 |
| 6616 TestDelegate d; | 6702 TestDelegate d; |
| 6617 std::unique_ptr<URLRequest> request( | 6703 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 6618 context.CreateRequest(request_url, DEFAULT_PRIORITY, &d)); | 6704 request_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6619 request->Start(); | 6705 request->Start(); |
| 6620 base::RunLoop().Run(); | 6706 base::RunLoop().Run(); |
| 6621 | 6707 |
| 6622 EXPECT_TRUE(reporting_service.headers().empty()); | 6708 EXPECT_TRUE(reporting_service.headers().empty()); |
| 6623 } | 6709 } |
| 6624 | 6710 |
| 6625 TEST_F(URLRequestTestHTTP, ProcessReportToHeaderHTTPS) { | 6711 TEST_F(URLRequestTestHTTP, ProcessReportToHeaderHTTPS) { |
| 6626 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 6712 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 6627 https_test_server.RegisterRequestHandler(base::Bind(&SendReportToHeader)); | 6713 https_test_server.RegisterRequestHandler(base::Bind(&SendReportToHeader)); |
| 6628 ASSERT_TRUE(https_test_server.Start()); | 6714 ASSERT_TRUE(https_test_server.Start()); |
| 6629 GURL request_url = https_test_server.GetURL("/"); | 6715 GURL request_url = https_test_server.GetURL("/"); |
| 6630 | 6716 |
| 6631 TestNetworkDelegate network_delegate; | 6717 TestNetworkDelegate network_delegate; |
| 6632 TestReportingService reporting_service; | 6718 TestReportingService reporting_service; |
| 6633 TestURLRequestContext context(true); | 6719 TestURLRequestContext context(true); |
| 6634 context.set_network_delegate(&network_delegate); | 6720 context.set_network_delegate(&network_delegate); |
| 6635 context.set_reporting_service(&reporting_service); | 6721 context.set_reporting_service(&reporting_service); |
| 6636 context.Init(); | 6722 context.Init(); |
| 6637 | 6723 |
| 6638 TestDelegate d; | 6724 TestDelegate d; |
| 6639 std::unique_ptr<URLRequest> request( | 6725 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 6640 context.CreateRequest(request_url, DEFAULT_PRIORITY, &d)); | 6726 request_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6641 request->Start(); | 6727 request->Start(); |
| 6642 base::RunLoop().Run(); | 6728 base::RunLoop().Run(); |
| 6643 | 6729 |
| 6644 ASSERT_EQ(1u, reporting_service.headers().size()); | 6730 ASSERT_EQ(1u, reporting_service.headers().size()); |
| 6645 EXPECT_EQ(request_url, reporting_service.headers()[0].url); | 6731 EXPECT_EQ(request_url, reporting_service.headers()[0].url); |
| 6646 EXPECT_EQ("foo, bar", reporting_service.headers()[0].header_value); | 6732 EXPECT_EQ("foo, bar", reporting_service.headers()[0].header_value); |
| 6647 } | 6733 } |
| 6648 | 6734 |
| 6649 TEST_F(URLRequestTestHTTP, DontProcessReportToHeaderInvalidHTTPS) { | 6735 TEST_F(URLRequestTestHTTP, DontProcessReportToHeaderInvalidHTTPS) { |
| 6650 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 6736 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 6651 https_test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | 6737 https_test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 6652 https_test_server.RegisterRequestHandler(base::Bind(&SendReportToHeader)); | 6738 https_test_server.RegisterRequestHandler(base::Bind(&SendReportToHeader)); |
| 6653 ASSERT_TRUE(https_test_server.Start()); | 6739 ASSERT_TRUE(https_test_server.Start()); |
| 6654 GURL request_url = https_test_server.GetURL("/"); | 6740 GURL request_url = https_test_server.GetURL("/"); |
| 6655 | 6741 |
| 6656 TestNetworkDelegate network_delegate; | 6742 TestNetworkDelegate network_delegate; |
| 6657 TestReportingService reporting_service; | 6743 TestReportingService reporting_service; |
| 6658 TestURLRequestContext context(true); | 6744 TestURLRequestContext context(true); |
| 6659 context.set_network_delegate(&network_delegate); | 6745 context.set_network_delegate(&network_delegate); |
| 6660 context.set_reporting_service(&reporting_service); | 6746 context.set_reporting_service(&reporting_service); |
| 6661 context.Init(); | 6747 context.Init(); |
| 6662 | 6748 |
| 6663 TestDelegate d; | 6749 TestDelegate d; |
| 6664 d.set_allow_certificate_errors(true); | 6750 d.set_allow_certificate_errors(true); |
| 6665 std::unique_ptr<URLRequest> request( | 6751 std::unique_ptr<URLRequest> request(context.CreateRequest( |
| 6666 context.CreateRequest(request_url, DEFAULT_PRIORITY, &d)); | 6752 request_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6667 request->Start(); | 6753 request->Start(); |
| 6668 base::RunLoop().Run(); | 6754 base::RunLoop().Run(); |
| 6669 | 6755 |
| 6670 EXPECT_TRUE(d.have_certificate_errors()); | 6756 EXPECT_TRUE(d.have_certificate_errors()); |
| 6671 EXPECT_TRUE(IsCertStatusError(request->ssl_info().cert_status)); | 6757 EXPECT_TRUE(IsCertStatusError(request->ssl_info().cert_status)); |
| 6672 EXPECT_TRUE(reporting_service.headers().empty()); | 6758 EXPECT_TRUE(reporting_service.headers().empty()); |
| 6673 } | 6759 } |
| 6674 | 6760 |
| 6675 #endif // !defined(OS_IOS) | 6761 #endif // !defined(OS_IOS) |
| 6676 | 6762 |
| 6677 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { | 6763 TEST_F(URLRequestTestHTTP, ContentTypeNormalizationTest) { |
| 6678 ASSERT_TRUE(http_test_server()->Start()); | 6764 ASSERT_TRUE(http_test_server()->Start()); |
| 6679 | 6765 |
| 6680 TestDelegate d; | 6766 TestDelegate d; |
| 6681 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 6767 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6682 http_test_server()->GetURL("/content-type-normalization.html"), | 6768 http_test_server()->GetURL("/content-type-normalization.html"), |
| 6683 DEFAULT_PRIORITY, &d)); | 6769 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6684 req->Start(); | 6770 req->Start(); |
| 6685 base::RunLoop().Run(); | 6771 base::RunLoop().Run(); |
| 6686 | 6772 |
| 6687 std::string mime_type; | 6773 std::string mime_type; |
| 6688 req->GetMimeType(&mime_type); | 6774 req->GetMimeType(&mime_type); |
| 6689 EXPECT_EQ("text/html", mime_type); | 6775 EXPECT_EQ("text/html", mime_type); |
| 6690 | 6776 |
| 6691 std::string charset; | 6777 std::string charset; |
| 6692 req->GetCharset(&charset); | 6778 req->GetCharset(&charset); |
| 6693 EXPECT_EQ("utf-8", charset); | 6779 EXPECT_EQ("utf-8", charset); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 6715 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). | 6801 // Test URLRequestJobFactoryImpl::IsSafeRedirectTarget(). |
| 6716 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url)); | 6802 EXPECT_FALSE(job_factory_->IsSafeRedirectTarget(file_url)); |
| 6717 } | 6803 } |
| 6718 | 6804 |
| 6719 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { | 6805 TEST_F(URLRequestTestHTTP, RestrictFileRedirects) { |
| 6720 ASSERT_TRUE(http_test_server()->Start()); | 6806 ASSERT_TRUE(http_test_server()->Start()); |
| 6721 | 6807 |
| 6722 TestDelegate d; | 6808 TestDelegate d; |
| 6723 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 6809 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6724 http_test_server()->GetURL("/redirect-to-file.html"), DEFAULT_PRIORITY, | 6810 http_test_server()->GetURL("/redirect-to-file.html"), DEFAULT_PRIORITY, |
| 6725 &d)); | 6811 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6726 req->Start(); | 6812 req->Start(); |
| 6727 base::RunLoop().Run(); | 6813 base::RunLoop().Run(); |
| 6728 | 6814 |
| 6729 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); | 6815 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); |
| 6730 } | 6816 } |
| 6731 #endif // !BUILDFLAG(DISABLE_FILE_SUPPORT) | 6817 #endif // !BUILDFLAG(DISABLE_FILE_SUPPORT) |
| 6732 | 6818 |
| 6733 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { | 6819 TEST_F(URLRequestTestHTTP, RestrictDataRedirects) { |
| 6734 ASSERT_TRUE(http_test_server()->Start()); | 6820 ASSERT_TRUE(http_test_server()->Start()); |
| 6735 | 6821 |
| 6736 TestDelegate d; | 6822 TestDelegate d; |
| 6737 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 6823 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6738 http_test_server()->GetURL("/redirect-to-data.html"), DEFAULT_PRIORITY, | 6824 http_test_server()->GetURL("/redirect-to-data.html"), DEFAULT_PRIORITY, |
| 6739 &d)); | 6825 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6740 req->Start(); | 6826 req->Start(); |
| 6741 base::RunLoop().Run(); | 6827 base::RunLoop().Run(); |
| 6742 | 6828 |
| 6743 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); | 6829 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); |
| 6744 } | 6830 } |
| 6745 | 6831 |
| 6746 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { | 6832 TEST_F(URLRequestTestHTTP, RedirectToInvalidURL) { |
| 6747 ASSERT_TRUE(http_test_server()->Start()); | 6833 ASSERT_TRUE(http_test_server()->Start()); |
| 6748 | 6834 |
| 6749 TestDelegate d; | 6835 TestDelegate d; |
| 6750 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 6836 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6751 http_test_server()->GetURL("/redirect-to-invalid-url.html"), | 6837 http_test_server()->GetURL("/redirect-to-invalid-url.html"), |
| 6752 DEFAULT_PRIORITY, &d)); | 6838 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6753 req->Start(); | 6839 req->Start(); |
| 6754 base::RunLoop().Run(); | 6840 base::RunLoop().Run(); |
| 6755 | 6841 |
| 6756 EXPECT_EQ(ERR_INVALID_URL, d.request_status()); | 6842 EXPECT_EQ(ERR_INVALID_URL, d.request_status()); |
| 6757 } | 6843 } |
| 6758 | 6844 |
| 6759 // Make sure redirects are cached, despite not reading their bodies. | 6845 // Make sure redirects are cached, despite not reading their bodies. |
| 6760 TEST_F(URLRequestTestHTTP, CacheRedirect) { | 6846 TEST_F(URLRequestTestHTTP, CacheRedirect) { |
| 6761 ASSERT_TRUE(http_test_server()->Start()); | 6847 ASSERT_TRUE(http_test_server()->Start()); |
| 6762 GURL redirect_url = | 6848 GURL redirect_url = |
| 6763 http_test_server()->GetURL("/redirect302-to-echo-cacheable"); | 6849 http_test_server()->GetURL("/redirect302-to-echo-cacheable"); |
| 6764 | 6850 |
| 6765 { | 6851 { |
| 6766 TestDelegate d; | 6852 TestDelegate d; |
| 6767 std::unique_ptr<URLRequest> req( | 6853 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6768 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 6854 redirect_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6769 req->Start(); | 6855 req->Start(); |
| 6770 base::RunLoop().Run(); | 6856 base::RunLoop().Run(); |
| 6771 EXPECT_EQ(OK, d.request_status()); | 6857 EXPECT_EQ(OK, d.request_status()); |
| 6772 EXPECT_EQ(1, d.received_redirect_count()); | 6858 EXPECT_EQ(1, d.received_redirect_count()); |
| 6773 EXPECT_EQ(http_test_server()->GetURL("/echo"), req->url()); | 6859 EXPECT_EQ(http_test_server()->GetURL("/echo"), req->url()); |
| 6774 } | 6860 } |
| 6775 | 6861 |
| 6776 { | 6862 { |
| 6777 TestDelegate d; | 6863 TestDelegate d; |
| 6778 d.set_quit_on_redirect(true); | 6864 d.set_quit_on_redirect(true); |
| 6779 std::unique_ptr<URLRequest> req( | 6865 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6780 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 6866 redirect_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6781 req->Start(); | 6867 req->Start(); |
| 6782 base::RunLoop().Run(); | 6868 base::RunLoop().Run(); |
| 6783 | 6869 |
| 6784 EXPECT_EQ(1, d.received_redirect_count()); | 6870 EXPECT_EQ(1, d.received_redirect_count()); |
| 6785 EXPECT_EQ(0, d.response_started_count()); | 6871 EXPECT_EQ(0, d.response_started_count()); |
| 6786 EXPECT_TRUE(req->was_cached()); | 6872 EXPECT_TRUE(req->was_cached()); |
| 6787 | 6873 |
| 6788 req->FollowDeferredRedirect(); | 6874 req->FollowDeferredRedirect(); |
| 6789 base::RunLoop().Run(); | 6875 base::RunLoop().Run(); |
| 6790 EXPECT_EQ(1, d.received_redirect_count()); | 6876 EXPECT_EQ(1, d.received_redirect_count()); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 6801 // URL that is normally cached. | 6887 // URL that is normally cached. |
| 6802 GURL initial_url = http_test_server()->GetURL("/cachetime"); | 6888 GURL initial_url = http_test_server()->GetURL("/cachetime"); |
| 6803 | 6889 |
| 6804 { | 6890 { |
| 6805 // Set up the TestNetworkDelegate tp force a redirect. | 6891 // Set up the TestNetworkDelegate tp force a redirect. |
| 6806 GURL redirect_to_url = http_test_server()->GetURL("/echo"); | 6892 GURL redirect_to_url = http_test_server()->GetURL("/echo"); |
| 6807 default_network_delegate_.set_redirect_on_headers_received_url( | 6893 default_network_delegate_.set_redirect_on_headers_received_url( |
| 6808 redirect_to_url); | 6894 redirect_to_url); |
| 6809 | 6895 |
| 6810 TestDelegate d; | 6896 TestDelegate d; |
| 6811 std::unique_ptr<URLRequest> req( | 6897 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6812 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d)); | 6898 initial_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6813 req->Start(); | 6899 req->Start(); |
| 6814 base::RunLoop().Run(); | 6900 base::RunLoop().Run(); |
| 6815 EXPECT_EQ(OK, d.request_status()); | 6901 EXPECT_EQ(OK, d.request_status()); |
| 6816 EXPECT_EQ(1, d.received_redirect_count()); | 6902 EXPECT_EQ(1, d.received_redirect_count()); |
| 6817 EXPECT_EQ(redirect_to_url, req->url()); | 6903 EXPECT_EQ(redirect_to_url, req->url()); |
| 6818 } | 6904 } |
| 6819 | 6905 |
| 6820 { | 6906 { |
| 6821 TestDelegate d; | 6907 TestDelegate d; |
| 6822 std::unique_ptr<URLRequest> req( | 6908 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6823 default_context_.CreateRequest(initial_url, DEFAULT_PRIORITY, &d)); | 6909 initial_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6824 req->Start(); | 6910 req->Start(); |
| 6825 base::RunLoop().Run(); | 6911 base::RunLoop().Run(); |
| 6826 | 6912 |
| 6827 EXPECT_EQ(OK, d.request_status()); | 6913 EXPECT_EQ(OK, d.request_status()); |
| 6828 EXPECT_FALSE(req->was_cached()); | 6914 EXPECT_FALSE(req->was_cached()); |
| 6829 EXPECT_EQ(0, d.received_redirect_count()); | 6915 EXPECT_EQ(0, d.received_redirect_count()); |
| 6830 EXPECT_EQ(initial_url, req->url()); | 6916 EXPECT_EQ(initial_url, req->url()); |
| 6831 } | 6917 } |
| 6832 } | 6918 } |
| 6833 | 6919 |
| 6834 // Tests that redirection to an unsafe URL is allowed when it has been marked as | 6920 // Tests that redirection to an unsafe URL is allowed when it has been marked as |
| 6835 // safe. | 6921 // safe. |
| 6836 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { | 6922 TEST_F(URLRequestTestHTTP, UnsafeRedirectToWhitelistedUnsafeURL) { |
| 6837 ASSERT_TRUE(http_test_server()->Start()); | 6923 ASSERT_TRUE(http_test_server()->Start()); |
| 6838 | 6924 |
| 6839 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); | 6925 GURL unsafe_url("data:text/html,this-is-considered-an-unsafe-url"); |
| 6840 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 6926 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 6841 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 6927 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 6842 | 6928 |
| 6843 TestDelegate d; | 6929 TestDelegate d; |
| 6844 { | 6930 { |
| 6845 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 6931 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6846 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d)); | 6932 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d, |
| 6933 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6847 | 6934 |
| 6848 r->Start(); | 6935 r->Start(); |
| 6849 base::RunLoop().Run(); | 6936 base::RunLoop().Run(); |
| 6850 | 6937 |
| 6851 EXPECT_EQ(OK, d.request_status()); | 6938 EXPECT_EQ(OK, d.request_status()); |
| 6852 EXPECT_EQ(2U, r->url_chain().size()); | 6939 EXPECT_EQ(2U, r->url_chain().size()); |
| 6853 EXPECT_EQ(unsafe_url, r->url()); | 6940 EXPECT_EQ(unsafe_url, r->url()); |
| 6854 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); | 6941 EXPECT_EQ("this-is-considered-an-unsafe-url", d.data_received()); |
| 6855 } | 6942 } |
| 6856 } | 6943 } |
| 6857 | 6944 |
| 6858 // Tests that a redirect to a different unsafe URL is blocked, even after adding | 6945 // Tests that a redirect to a different unsafe URL is blocked, even after adding |
| 6859 // some other URL to the whitelist. | 6946 // some other URL to the whitelist. |
| 6860 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { | 6947 TEST_F(URLRequestTestHTTP, UnsafeRedirectToDifferentUnsafeURL) { |
| 6861 ASSERT_TRUE(http_test_server()->Start()); | 6948 ASSERT_TRUE(http_test_server()->Start()); |
| 6862 | 6949 |
| 6863 GURL unsafe_url("data:text/html,something"); | 6950 GURL unsafe_url("data:text/html,something"); |
| 6864 GURL different_unsafe_url("data:text/html,something-else"); | 6951 GURL different_unsafe_url("data:text/html,something-else"); |
| 6865 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 6952 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 6866 default_network_delegate_.set_allowed_unsafe_redirect_url( | 6953 default_network_delegate_.set_allowed_unsafe_redirect_url( |
| 6867 different_unsafe_url); | 6954 different_unsafe_url); |
| 6868 | 6955 |
| 6869 TestDelegate d; | 6956 TestDelegate d; |
| 6870 { | 6957 { |
| 6871 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 6958 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6872 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d)); | 6959 http_test_server()->GetURL("/whatever"), DEFAULT_PRIORITY, &d, |
| 6960 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6873 | 6961 |
| 6874 r->Start(); | 6962 r->Start(); |
| 6875 base::RunLoop().Run(); | 6963 base::RunLoop().Run(); |
| 6876 | 6964 |
| 6877 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); | 6965 EXPECT_EQ(ERR_UNSAFE_REDIRECT, d.request_status()); |
| 6878 } | 6966 } |
| 6879 } | 6967 } |
| 6880 | 6968 |
| 6881 // Redirects from an URL with fragment to an unsafe URL with fragment should | 6969 // Redirects from an URL with fragment to an unsafe URL with fragment should |
| 6882 // be allowed, and the reference fragment of the target URL should be preserved. | 6970 // be allowed, and the reference fragment of the target URL should be preserved. |
| 6883 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { | 6971 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { |
| 6884 ASSERT_TRUE(http_test_server()->Start()); | 6972 ASSERT_TRUE(http_test_server()->Start()); |
| 6885 | 6973 |
| 6886 GURL original_url(http_test_server()->GetURL("/original#fragment1")); | 6974 GURL original_url(http_test_server()->GetURL("/original#fragment1")); |
| 6887 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | 6975 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); |
| 6888 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | 6976 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); |
| 6889 | 6977 |
| 6890 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 6978 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 6891 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 6979 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 6892 | 6980 |
| 6893 TestDelegate d; | 6981 TestDelegate d; |
| 6894 { | 6982 { |
| 6895 std::unique_ptr<URLRequest> r( | 6983 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6896 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 6984 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6897 | 6985 |
| 6898 r->Start(); | 6986 r->Start(); |
| 6899 base::RunLoop().Run(); | 6987 base::RunLoop().Run(); |
| 6900 | 6988 |
| 6901 EXPECT_EQ(2U, r->url_chain().size()); | 6989 EXPECT_EQ(2U, r->url_chain().size()); |
| 6902 EXPECT_EQ(OK, d.request_status()); | 6990 EXPECT_EQ(OK, d.request_status()); |
| 6903 EXPECT_EQ(original_url, r->original_url()); | 6991 EXPECT_EQ(original_url, r->original_url()); |
| 6904 EXPECT_EQ(expected_url, r->url()); | 6992 EXPECT_EQ(expected_url, r->url()); |
| 6905 } | 6993 } |
| 6906 } | 6994 } |
| 6907 | 6995 |
| 6908 // When a delegate has specified a safe redirect URL, but it does not match the | 6996 // When a delegate has specified a safe redirect URL, but it does not match the |
| 6909 // redirect target, then do not prevent the reference fragment from being added. | 6997 // redirect target, then do not prevent the reference fragment from being added. |
| 6910 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { | 6998 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragmentAndUnrelatedUnsafeUrl) { |
| 6911 ASSERT_TRUE(http_test_server()->Start()); | 6999 ASSERT_TRUE(http_test_server()->Start()); |
| 6912 | 7000 |
| 6913 GURL original_url(http_test_server()->GetURL("/original#expected-fragment")); | 7001 GURL original_url(http_test_server()->GetURL("/original#expected-fragment")); |
| 6914 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); | 7002 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); |
| 6915 GURL redirect_url(http_test_server()->GetURL("/target")); | 7003 GURL redirect_url(http_test_server()->GetURL("/target")); |
| 6916 GURL expected_redirect_url( | 7004 GURL expected_redirect_url( |
| 6917 http_test_server()->GetURL("/target#expected-fragment")); | 7005 http_test_server()->GetURL("/target#expected-fragment")); |
| 6918 | 7006 |
| 6919 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); | 7007 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); |
| 6920 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 7008 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 6921 | 7009 |
| 6922 TestDelegate d; | 7010 TestDelegate d; |
| 6923 { | 7011 { |
| 6924 std::unique_ptr<URLRequest> r( | 7012 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6925 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 7013 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6926 | 7014 |
| 6927 r->Start(); | 7015 r->Start(); |
| 6928 base::RunLoop().Run(); | 7016 base::RunLoop().Run(); |
| 6929 | 7017 |
| 6930 EXPECT_EQ(2U, r->url_chain().size()); | 7018 EXPECT_EQ(2U, r->url_chain().size()); |
| 6931 EXPECT_EQ(OK, d.request_status()); | 7019 EXPECT_EQ(OK, d.request_status()); |
| 6932 EXPECT_EQ(original_url, r->original_url()); | 7020 EXPECT_EQ(original_url, r->original_url()); |
| 6933 EXPECT_EQ(expected_redirect_url, r->url()); | 7021 EXPECT_EQ(expected_redirect_url, r->url()); |
| 6934 } | 7022 } |
| 6935 } | 7023 } |
| 6936 | 7024 |
| 6937 // When a delegate has specified a safe redirect URL, assume that the redirect | 7025 // When a delegate has specified a safe redirect URL, assume that the redirect |
| 6938 // URL should not be changed. In particular, the reference fragment should not | 7026 // URL should not be changed. In particular, the reference fragment should not |
| 6939 // be modified. | 7027 // be modified. |
| 6940 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { | 7028 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { |
| 6941 ASSERT_TRUE(http_test_server()->Start()); | 7029 ASSERT_TRUE(http_test_server()->Start()); |
| 6942 | 7030 |
| 6943 GURL original_url( | 7031 GURL original_url( |
| 6944 http_test_server()->GetURL("/original#should-not-be-appended")); | 7032 http_test_server()->GetURL("/original#should-not-be-appended")); |
| 6945 GURL redirect_url("data:text/html,expect-no-reference-fragment"); | 7033 GURL redirect_url("data:text/html,expect-no-reference-fragment"); |
| 6946 | 7034 |
| 6947 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); | 7035 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); |
| 6948 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); | 7036 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); |
| 6949 | 7037 |
| 6950 TestDelegate d; | 7038 TestDelegate d; |
| 6951 { | 7039 { |
| 6952 std::unique_ptr<URLRequest> r( | 7040 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6953 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 7041 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6954 | 7042 |
| 6955 r->Start(); | 7043 r->Start(); |
| 6956 base::RunLoop().Run(); | 7044 base::RunLoop().Run(); |
| 6957 | 7045 |
| 6958 EXPECT_EQ(2U, r->url_chain().size()); | 7046 EXPECT_EQ(2U, r->url_chain().size()); |
| 6959 EXPECT_EQ(OK, d.request_status()); | 7047 EXPECT_EQ(OK, d.request_status()); |
| 6960 EXPECT_EQ(original_url, r->original_url()); | 7048 EXPECT_EQ(original_url, r->original_url()); |
| 6961 EXPECT_EQ(redirect_url, r->url()); | 7049 EXPECT_EQ(redirect_url, r->url()); |
| 6962 } | 7050 } |
| 6963 } | 7051 } |
| 6964 | 7052 |
| 6965 // When a URLRequestRedirectJob is created, the redirection must be followed and | 7053 // When a URLRequestRedirectJob is created, the redirection must be followed and |
| 6966 // the reference fragment of the target URL must not be modified. | 7054 // the reference fragment of the target URL must not be modified. |
| 6967 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { | 7055 TEST_F(URLRequestTestHTTP, RedirectJobWithReferenceFragment) { |
| 6968 ASSERT_TRUE(http_test_server()->Start()); | 7056 ASSERT_TRUE(http_test_server()->Start()); |
| 6969 | 7057 |
| 6970 GURL original_url( | 7058 GURL original_url( |
| 6971 http_test_server()->GetURL("/original#should-not-be-appended")); | 7059 http_test_server()->GetURL("/original#should-not-be-appended")); |
| 6972 GURL redirect_url(http_test_server()->GetURL("/echo")); | 7060 GURL redirect_url(http_test_server()->GetURL("/echo")); |
| 6973 | 7061 |
| 6974 TestDelegate d; | 7062 TestDelegate d; |
| 6975 std::unique_ptr<URLRequest> r( | 7063 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 6976 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 7064 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6977 | 7065 |
| 6978 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( | 7066 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( |
| 6979 r.get(), &default_network_delegate_, redirect_url, | 7067 r.get(), &default_network_delegate_, redirect_url, |
| 6980 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); | 7068 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); |
| 6981 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 7069 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 6982 | 7070 |
| 6983 r->Start(); | 7071 r->Start(); |
| 6984 base::RunLoop().Run(); | 7072 base::RunLoop().Run(); |
| 6985 | 7073 |
| 6986 EXPECT_EQ(OK, d.request_status()); | 7074 EXPECT_EQ(OK, d.request_status()); |
| 6987 EXPECT_EQ(original_url, r->original_url()); | 7075 EXPECT_EQ(original_url, r->original_url()); |
| 6988 EXPECT_EQ(redirect_url, r->url()); | 7076 EXPECT_EQ(redirect_url, r->url()); |
| 6989 } | 7077 } |
| 6990 | 7078 |
| 6991 TEST_F(URLRequestTestHTTP, UnsupportedReferrerScheme) { | 7079 TEST_F(URLRequestTestHTTP, UnsupportedReferrerScheme) { |
| 6992 ASSERT_TRUE(http_test_server()->Start()); | 7080 ASSERT_TRUE(http_test_server()->Start()); |
| 6993 | 7081 |
| 6994 const std::string referrer("foobar://totally.legit.referrer"); | 7082 const std::string referrer("foobar://totally.legit.referrer"); |
| 6995 TestDelegate d; | 7083 TestDelegate d; |
| 6996 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7084 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 6997 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 7085 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d, |
| 7086 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 6998 req->SetReferrer(referrer); | 7087 req->SetReferrer(referrer); |
| 6999 req->Start(); | 7088 req->Start(); |
| 7000 base::RunLoop().Run(); | 7089 base::RunLoop().Run(); |
| 7001 | 7090 |
| 7002 EXPECT_EQ(std::string("None"), d.data_received()); | 7091 EXPECT_EQ(std::string("None"), d.data_received()); |
| 7003 } | 7092 } |
| 7004 | 7093 |
| 7005 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 7094 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
| 7006 ASSERT_TRUE(http_test_server()->Start()); | 7095 ASSERT_TRUE(http_test_server()->Start()); |
| 7007 | 7096 |
| 7008 TestDelegate d; | 7097 TestDelegate d; |
| 7009 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7098 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7010 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 7099 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d, |
| 7100 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7011 req->SetReferrer("http://user:pass@foo.com/"); | 7101 req->SetReferrer("http://user:pass@foo.com/"); |
| 7012 req->Start(); | 7102 req->Start(); |
| 7013 base::RunLoop().Run(); | 7103 base::RunLoop().Run(); |
| 7014 | 7104 |
| 7015 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); | 7105 EXPECT_EQ(std::string("http://foo.com/"), d.data_received()); |
| 7016 } | 7106 } |
| 7017 | 7107 |
| 7018 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { | 7108 TEST_F(URLRequestTestHTTP, NoFragmentInReferrer) { |
| 7019 ASSERT_TRUE(http_test_server()->Start()); | 7109 ASSERT_TRUE(http_test_server()->Start()); |
| 7020 | 7110 |
| 7021 TestDelegate d; | 7111 TestDelegate d; |
| 7022 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7112 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7023 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 7113 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d, |
| 7114 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7024 req->SetReferrer("http://foo.com/test#fragment"); | 7115 req->SetReferrer("http://foo.com/test#fragment"); |
| 7025 req->Start(); | 7116 req->Start(); |
| 7026 base::RunLoop().Run(); | 7117 base::RunLoop().Run(); |
| 7027 | 7118 |
| 7028 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); | 7119 EXPECT_EQ(std::string("http://foo.com/test"), d.data_received()); |
| 7029 } | 7120 } |
| 7030 | 7121 |
| 7031 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { | 7122 TEST_F(URLRequestTestHTTP, EmptyReferrerAfterValidReferrer) { |
| 7032 ASSERT_TRUE(http_test_server()->Start()); | 7123 ASSERT_TRUE(http_test_server()->Start()); |
| 7033 | 7124 |
| 7034 TestDelegate d; | 7125 TestDelegate d; |
| 7035 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7126 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7036 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d)); | 7127 http_test_server()->GetURL("/echoheader?Referer"), DEFAULT_PRIORITY, &d, |
| 7128 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7037 req->SetReferrer("http://foo.com/test#fragment"); | 7129 req->SetReferrer("http://foo.com/test#fragment"); |
| 7038 req->SetReferrer(""); | 7130 req->SetReferrer(""); |
| 7039 req->Start(); | 7131 req->Start(); |
| 7040 base::RunLoop().Run(); | 7132 base::RunLoop().Run(); |
| 7041 | 7133 |
| 7042 EXPECT_EQ(std::string("None"), d.data_received()); | 7134 EXPECT_EQ(std::string("None"), d.data_received()); |
| 7043 } | 7135 } |
| 7044 | 7136 |
| 7045 TEST_F(URLRequestTestHTTP, CancelRedirect) { | 7137 TEST_F(URLRequestTestHTTP, CancelRedirect) { |
| 7046 ASSERT_TRUE(http_test_server()->Start()); | 7138 ASSERT_TRUE(http_test_server()->Start()); |
| 7047 | 7139 |
| 7048 TestDelegate d; | 7140 TestDelegate d; |
| 7049 { | 7141 { |
| 7050 d.set_cancel_in_received_redirect(true); | 7142 d.set_cancel_in_received_redirect(true); |
| 7051 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7143 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7052 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, | 7144 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, &d, |
| 7053 &d)); | 7145 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7054 req->Start(); | 7146 req->Start(); |
| 7055 base::RunLoop().Run(); | 7147 base::RunLoop().Run(); |
| 7056 | 7148 |
| 7057 EXPECT_EQ(1, d.response_started_count()); | 7149 EXPECT_EQ(1, d.response_started_count()); |
| 7058 EXPECT_EQ(0, d.bytes_received()); | 7150 EXPECT_EQ(0, d.bytes_received()); |
| 7059 EXPECT_FALSE(d.received_data_before_response()); | 7151 EXPECT_FALSE(d.received_data_before_response()); |
| 7060 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 7152 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 7061 } | 7153 } |
| 7062 } | 7154 } |
| 7063 | 7155 |
| 7064 TEST_F(URLRequestTestHTTP, DeferredRedirect) { | 7156 TEST_F(URLRequestTestHTTP, DeferredRedirect) { |
| 7065 ASSERT_TRUE(http_test_server()->Start()); | 7157 ASSERT_TRUE(http_test_server()->Start()); |
| 7066 | 7158 |
| 7067 TestDelegate d; | 7159 TestDelegate d; |
| 7068 { | 7160 { |
| 7069 d.set_quit_on_redirect(true); | 7161 d.set_quit_on_redirect(true); |
| 7070 GURL test_url(http_test_server()->GetURL("/redirect-test.html")); | 7162 GURL test_url(http_test_server()->GetURL("/redirect-test.html")); |
| 7071 std::unique_ptr<URLRequest> req( | 7163 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7072 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 7164 test_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7073 | 7165 |
| 7074 req->Start(); | 7166 req->Start(); |
| 7075 base::RunLoop().Run(); | 7167 base::RunLoop().Run(); |
| 7076 | 7168 |
| 7077 EXPECT_EQ(1, d.received_redirect_count()); | 7169 EXPECT_EQ(1, d.received_redirect_count()); |
| 7078 | 7170 |
| 7079 req->FollowDeferredRedirect(); | 7171 req->FollowDeferredRedirect(); |
| 7080 base::RunLoop().Run(); | 7172 base::RunLoop().Run(); |
| 7081 | 7173 |
| 7082 EXPECT_EQ(1, d.response_started_count()); | 7174 EXPECT_EQ(1, d.response_started_count()); |
| (...skipping 11 matching lines...) Expand all Loading... |
| 7094 } | 7186 } |
| 7095 } | 7187 } |
| 7096 | 7188 |
| 7097 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { | 7189 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { |
| 7098 ASSERT_TRUE(http_test_server()->Start()); | 7190 ASSERT_TRUE(http_test_server()->Start()); |
| 7099 | 7191 |
| 7100 TestDelegate d; | 7192 TestDelegate d; |
| 7101 { | 7193 { |
| 7102 d.set_quit_on_redirect(true); | 7194 d.set_quit_on_redirect(true); |
| 7103 GURL test_url(http_test_server()->GetURL("/redirect-test.html")); | 7195 GURL test_url(http_test_server()->GetURL("/redirect-test.html")); |
| 7104 std::unique_ptr<URLRequest> req( | 7196 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7105 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 7197 test_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7106 | 7198 |
| 7107 EXPECT_FALSE(d.have_full_request_headers()); | 7199 EXPECT_FALSE(d.have_full_request_headers()); |
| 7108 | 7200 |
| 7109 req->Start(); | 7201 req->Start(); |
| 7110 base::RunLoop().Run(); | 7202 base::RunLoop().Run(); |
| 7111 | 7203 |
| 7112 EXPECT_EQ(1, d.received_redirect_count()); | 7204 EXPECT_EQ(1, d.received_redirect_count()); |
| 7113 EXPECT_TRUE(d.have_full_request_headers()); | 7205 EXPECT_TRUE(d.have_full_request_headers()); |
| 7114 CheckFullRequestHeaders(d.full_request_headers(), test_url); | 7206 CheckFullRequestHeaders(d.full_request_headers(), test_url); |
| 7115 d.ClearFullRequestHeaders(); | 7207 d.ClearFullRequestHeaders(); |
| (...skipping 19 matching lines...) Expand all Loading... |
| 7135 } | 7227 } |
| 7136 } | 7228 } |
| 7137 | 7229 |
| 7138 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 7230 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
| 7139 ASSERT_TRUE(http_test_server()->Start()); | 7231 ASSERT_TRUE(http_test_server()->Start()); |
| 7140 | 7232 |
| 7141 TestDelegate d; | 7233 TestDelegate d; |
| 7142 { | 7234 { |
| 7143 d.set_quit_on_redirect(true); | 7235 d.set_quit_on_redirect(true); |
| 7144 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7236 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7145 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, | 7237 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, &d, |
| 7146 &d)); | 7238 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7147 req->Start(); | 7239 req->Start(); |
| 7148 base::RunLoop().Run(); | 7240 base::RunLoop().Run(); |
| 7149 | 7241 |
| 7150 EXPECT_EQ(1, d.received_redirect_count()); | 7242 EXPECT_EQ(1, d.received_redirect_count()); |
| 7151 | 7243 |
| 7152 req->Cancel(); | 7244 req->Cancel(); |
| 7153 base::RunLoop().Run(); | 7245 base::RunLoop().Run(); |
| 7154 | 7246 |
| 7155 EXPECT_EQ(1, d.response_started_count()); | 7247 EXPECT_EQ(1, d.response_started_count()); |
| 7156 EXPECT_EQ(0, d.bytes_received()); | 7248 EXPECT_EQ(0, d.bytes_received()); |
| 7157 EXPECT_FALSE(d.received_data_before_response()); | 7249 EXPECT_FALSE(d.received_data_before_response()); |
| 7158 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 7250 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 7159 } | 7251 } |
| 7160 } | 7252 } |
| 7161 | 7253 |
| 7162 TEST_F(URLRequestTestHTTP, VaryHeader) { | 7254 TEST_F(URLRequestTestHTTP, VaryHeader) { |
| 7163 ASSERT_TRUE(http_test_server()->Start()); | 7255 ASSERT_TRUE(http_test_server()->Start()); |
| 7164 | 7256 |
| 7165 // Populate the cache. | 7257 // Populate the cache. |
| 7166 { | 7258 { |
| 7167 TestDelegate d; | 7259 TestDelegate d; |
| 7168 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7260 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7169 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, | 7261 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, |
| 7170 &d)); | 7262 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7171 HttpRequestHeaders headers; | 7263 HttpRequestHeaders headers; |
| 7172 headers.SetHeader("foo", "1"); | 7264 headers.SetHeader("foo", "1"); |
| 7173 req->SetExtraRequestHeaders(headers); | 7265 req->SetExtraRequestHeaders(headers); |
| 7174 req->Start(); | 7266 req->Start(); |
| 7175 base::RunLoop().Run(); | 7267 base::RunLoop().Run(); |
| 7176 | 7268 |
| 7177 LoadTimingInfo load_timing_info; | 7269 LoadTimingInfo load_timing_info; |
| 7178 req->GetLoadTimingInfo(&load_timing_info); | 7270 req->GetLoadTimingInfo(&load_timing_info); |
| 7179 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 7271 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 7180 } | 7272 } |
| 7181 | 7273 |
| 7182 // Expect a cache hit. | 7274 // Expect a cache hit. |
| 7183 { | 7275 { |
| 7184 TestDelegate d; | 7276 TestDelegate d; |
| 7185 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7277 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7186 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, | 7278 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, |
| 7187 &d)); | 7279 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7188 HttpRequestHeaders headers; | 7280 HttpRequestHeaders headers; |
| 7189 headers.SetHeader("foo", "1"); | 7281 headers.SetHeader("foo", "1"); |
| 7190 req->SetExtraRequestHeaders(headers); | 7282 req->SetExtraRequestHeaders(headers); |
| 7191 req->Start(); | 7283 req->Start(); |
| 7192 base::RunLoop().Run(); | 7284 base::RunLoop().Run(); |
| 7193 | 7285 |
| 7194 EXPECT_TRUE(req->was_cached()); | 7286 EXPECT_TRUE(req->was_cached()); |
| 7195 | 7287 |
| 7196 LoadTimingInfo load_timing_info; | 7288 LoadTimingInfo load_timing_info; |
| 7197 req->GetLoadTimingInfo(&load_timing_info); | 7289 req->GetLoadTimingInfo(&load_timing_info); |
| 7198 TestLoadTimingCacheHitNoNetwork(load_timing_info); | 7290 TestLoadTimingCacheHitNoNetwork(load_timing_info); |
| 7199 } | 7291 } |
| 7200 | 7292 |
| 7201 // Expect a cache miss. | 7293 // Expect a cache miss. |
| 7202 { | 7294 { |
| 7203 TestDelegate d; | 7295 TestDelegate d; |
| 7204 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7296 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7205 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, | 7297 http_test_server()->GetURL("/echoheadercache?foo"), DEFAULT_PRIORITY, |
| 7206 &d)); | 7298 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7207 HttpRequestHeaders headers; | 7299 HttpRequestHeaders headers; |
| 7208 headers.SetHeader("foo", "2"); | 7300 headers.SetHeader("foo", "2"); |
| 7209 req->SetExtraRequestHeaders(headers); | 7301 req->SetExtraRequestHeaders(headers); |
| 7210 req->Start(); | 7302 req->Start(); |
| 7211 base::RunLoop().Run(); | 7303 base::RunLoop().Run(); |
| 7212 | 7304 |
| 7213 EXPECT_FALSE(req->was_cached()); | 7305 EXPECT_FALSE(req->was_cached()); |
| 7214 | 7306 |
| 7215 LoadTimingInfo load_timing_info; | 7307 LoadTimingInfo load_timing_info; |
| 7216 req->GetLoadTimingInfo(&load_timing_info); | 7308 req->GetLoadTimingInfo(&load_timing_info); |
| 7217 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 7309 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 7218 } | 7310 } |
| 7219 } | 7311 } |
| 7220 | 7312 |
| 7221 TEST_F(URLRequestTestHTTP, BasicAuth) { | 7313 TEST_F(URLRequestTestHTTP, BasicAuth) { |
| 7222 ASSERT_TRUE(http_test_server()->Start()); | 7314 ASSERT_TRUE(http_test_server()->Start()); |
| 7223 | 7315 |
| 7224 // populate the cache | 7316 // populate the cache |
| 7225 { | 7317 { |
| 7226 TestDelegate d; | 7318 TestDelegate d; |
| 7227 d.set_credentials(AuthCredentials(kUser, kSecret)); | 7319 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 7228 | 7320 |
| 7229 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 7321 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7230 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); | 7322 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d, |
| 7323 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7231 r->Start(); | 7324 r->Start(); |
| 7232 | 7325 |
| 7233 base::RunLoop().Run(); | 7326 base::RunLoop().Run(); |
| 7234 | 7327 |
| 7235 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 7328 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 7236 } | 7329 } |
| 7237 | 7330 |
| 7238 // repeat request with end-to-end validation. since auth-basic results in a | 7331 // repeat request with end-to-end validation. since auth-basic results in a |
| 7239 // cachable page, we expect this test to result in a 304. in which case, the | 7332 // cachable page, we expect this test to result in a 304. in which case, the |
| 7240 // response should be fetched from the cache. | 7333 // response should be fetched from the cache. |
| 7241 { | 7334 { |
| 7242 TestDelegate d; | 7335 TestDelegate d; |
| 7243 d.set_credentials(AuthCredentials(kUser, kSecret)); | 7336 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 7244 | 7337 |
| 7245 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 7338 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7246 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); | 7339 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d, |
| 7340 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7247 r->SetLoadFlags(LOAD_VALIDATE_CACHE); | 7341 r->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 7248 r->Start(); | 7342 r->Start(); |
| 7249 | 7343 |
| 7250 base::RunLoop().Run(); | 7344 base::RunLoop().Run(); |
| 7251 | 7345 |
| 7252 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 7346 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 7253 | 7347 |
| 7254 // Should be the same cached document. | 7348 // Should be the same cached document. |
| 7255 EXPECT_TRUE(r->was_cached()); | 7349 EXPECT_TRUE(r->was_cached()); |
| 7256 } | 7350 } |
| (...skipping 12 matching lines...) Expand all Loading... |
| 7269 { | 7363 { |
| 7270 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 7364 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 7271 TestURLRequestContext context(true); | 7365 TestURLRequestContext context(true); |
| 7272 context.set_network_delegate(&network_delegate); | 7366 context.set_network_delegate(&network_delegate); |
| 7273 context.Init(); | 7367 context.Init(); |
| 7274 | 7368 |
| 7275 TestDelegate d; | 7369 TestDelegate d; |
| 7276 d.set_credentials(AuthCredentials(kUser, kSecret)); | 7370 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 7277 | 7371 |
| 7278 std::unique_ptr<URLRequest> r( | 7372 std::unique_ptr<URLRequest> r( |
| 7279 context.CreateRequest(url_requiring_auth, DEFAULT_PRIORITY, &d)); | 7373 context.CreateRequest(url_requiring_auth, DEFAULT_PRIORITY, &d, |
| 7374 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7280 r->Start(); | 7375 r->Start(); |
| 7281 | 7376 |
| 7282 base::RunLoop().Run(); | 7377 base::RunLoop().Run(); |
| 7283 | 7378 |
| 7284 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 7379 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 7285 | 7380 |
| 7286 // Make sure we sent the cookie in the restarted transaction. | 7381 // Make sure we sent the cookie in the restarted transaction. |
| 7287 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 7382 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 7288 != std::string::npos); | 7383 != std::string::npos); |
| 7289 } | 7384 } |
| 7290 | 7385 |
| 7291 // Same test as above, except this time the restart is initiated earlier | 7386 // Same test as above, except this time the restart is initiated earlier |
| 7292 // (without user intervention since identity is embedded in the URL). | 7387 // (without user intervention since identity is embedded in the URL). |
| 7293 { | 7388 { |
| 7294 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 7389 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 7295 TestURLRequestContext context(true); | 7390 TestURLRequestContext context(true); |
| 7296 context.set_network_delegate(&network_delegate); | 7391 context.set_network_delegate(&network_delegate); |
| 7297 context.Init(); | 7392 context.Init(); |
| 7298 | 7393 |
| 7299 TestDelegate d; | 7394 TestDelegate d; |
| 7300 | 7395 |
| 7301 GURL::Replacements replacements; | 7396 GURL::Replacements replacements; |
| 7302 replacements.SetUsernameStr("user2"); | 7397 replacements.SetUsernameStr("user2"); |
| 7303 replacements.SetPasswordStr("secret"); | 7398 replacements.SetPasswordStr("secret"); |
| 7304 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); | 7399 GURL url_with_identity = url_requiring_auth.ReplaceComponents(replacements); |
| 7305 | 7400 |
| 7306 std::unique_ptr<URLRequest> r( | 7401 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 7307 context.CreateRequest(url_with_identity, DEFAULT_PRIORITY, &d)); | 7402 url_with_identity, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7308 r->Start(); | 7403 r->Start(); |
| 7309 | 7404 |
| 7310 base::RunLoop().Run(); | 7405 base::RunLoop().Run(); |
| 7311 | 7406 |
| 7312 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); | 7407 EXPECT_TRUE(d.data_received().find("user2/secret") != std::string::npos); |
| 7313 | 7408 |
| 7314 // Make sure we sent the cookie in the restarted transaction. | 7409 // Make sure we sent the cookie in the restarted transaction. |
| 7315 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") | 7410 EXPECT_TRUE(d.data_received().find("Cookie: got_challenged=true") |
| 7316 != std::string::npos); | 7411 != std::string::npos); |
| 7317 } | 7412 } |
| 7318 } | 7413 } |
| 7319 | 7414 |
| 7320 // Tests that load timing works as expected with auth and the cache. | 7415 // Tests that load timing works as expected with auth and the cache. |
| 7321 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { | 7416 TEST_F(URLRequestTestHTTP, BasicAuthLoadTiming) { |
| 7322 ASSERT_TRUE(http_test_server()->Start()); | 7417 ASSERT_TRUE(http_test_server()->Start()); |
| 7323 | 7418 |
| 7324 // populate the cache | 7419 // populate the cache |
| 7325 { | 7420 { |
| 7326 TestDelegate d; | 7421 TestDelegate d; |
| 7327 d.set_credentials(AuthCredentials(kUser, kSecret)); | 7422 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 7328 | 7423 |
| 7329 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 7424 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7330 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); | 7425 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d, |
| 7426 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7331 r->Start(); | 7427 r->Start(); |
| 7332 | 7428 |
| 7333 base::RunLoop().Run(); | 7429 base::RunLoop().Run(); |
| 7334 | 7430 |
| 7335 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 7431 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 7336 | 7432 |
| 7337 LoadTimingInfo load_timing_info_before_auth; | 7433 LoadTimingInfo load_timing_info_before_auth; |
| 7338 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( | 7434 EXPECT_TRUE(default_network_delegate_.GetLoadTimingInfoBeforeAuth( |
| 7339 &load_timing_info_before_auth)); | 7435 &load_timing_info_before_auth)); |
| 7340 TestLoadTimingNotReused(load_timing_info_before_auth, | 7436 TestLoadTimingNotReused(load_timing_info_before_auth, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 7352 } | 7448 } |
| 7353 | 7449 |
| 7354 // Repeat request with end-to-end validation. Since auth-basic results in a | 7450 // Repeat request with end-to-end validation. Since auth-basic results in a |
| 7355 // cachable page, we expect this test to result in a 304. In which case, the | 7451 // cachable page, we expect this test to result in a 304. In which case, the |
| 7356 // response should be fetched from the cache. | 7452 // response should be fetched from the cache. |
| 7357 { | 7453 { |
| 7358 TestDelegate d; | 7454 TestDelegate d; |
| 7359 d.set_credentials(AuthCredentials(kUser, kSecret)); | 7455 d.set_credentials(AuthCredentials(kUser, kSecret)); |
| 7360 | 7456 |
| 7361 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 7457 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7362 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d)); | 7458 http_test_server()->GetURL("/auth-basic"), DEFAULT_PRIORITY, &d, |
| 7459 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7363 r->SetLoadFlags(LOAD_VALIDATE_CACHE); | 7460 r->SetLoadFlags(LOAD_VALIDATE_CACHE); |
| 7364 r->Start(); | 7461 r->Start(); |
| 7365 | 7462 |
| 7366 base::RunLoop().Run(); | 7463 base::RunLoop().Run(); |
| 7367 | 7464 |
| 7368 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); | 7465 EXPECT_TRUE(d.data_received().find("user/secret") != std::string::npos); |
| 7369 | 7466 |
| 7370 // Should be the same cached document. | 7467 // Should be the same cached document. |
| 7371 EXPECT_TRUE(r->was_cached()); | 7468 EXPECT_TRUE(r->was_cached()); |
| 7372 | 7469 |
| 7373 // Since there was a request that went over the wire, the load timing | 7470 // Since there was a request that went over the wire, the load timing |
| 7374 // information should include connection times. | 7471 // information should include connection times. |
| 7375 LoadTimingInfo load_timing_info; | 7472 LoadTimingInfo load_timing_info; |
| 7376 r->GetLoadTimingInfo(&load_timing_info); | 7473 r->GetLoadTimingInfo(&load_timing_info); |
| 7377 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); | 7474 TestLoadTimingNotReused(load_timing_info, CONNECT_TIMING_HAS_DNS_TIMES); |
| 7378 } | 7475 } |
| 7379 } | 7476 } |
| 7380 | 7477 |
| 7381 // In this test, we do a POST which the server will 302 redirect. | 7478 // In this test, we do a POST which the server will 302 redirect. |
| 7382 // The subsequent transaction should use GET, and should not send the | 7479 // The subsequent transaction should use GET, and should not send the |
| 7383 // Content-Type header. | 7480 // Content-Type header. |
| 7384 // http://code.google.com/p/chromium/issues/detail?id=843 | 7481 // http://code.google.com/p/chromium/issues/detail?id=843 |
| 7385 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { | 7482 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { |
| 7386 ASSERT_TRUE(http_test_server()->Start()); | 7483 ASSERT_TRUE(http_test_server()->Start()); |
| 7387 | 7484 |
| 7388 const char kData[] = "hello world"; | 7485 const char kData[] = "hello world"; |
| 7389 | 7486 |
| 7390 TestDelegate d; | 7487 TestDelegate d; |
| 7391 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7488 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7392 http_test_server()->GetURL("/redirect-to-echoall"), DEFAULT_PRIORITY, | 7489 http_test_server()->GetURL("/redirect-to-echoall"), DEFAULT_PRIORITY, &d, |
| 7393 &d)); | 7490 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7394 req->set_method("POST"); | 7491 req->set_method("POST"); |
| 7395 req->set_upload(CreateSimpleUploadData(kData)); | 7492 req->set_upload(CreateSimpleUploadData(kData)); |
| 7396 | 7493 |
| 7397 // Set headers (some of which are specific to the POST). | 7494 // Set headers (some of which are specific to the POST). |
| 7398 HttpRequestHeaders headers; | 7495 HttpRequestHeaders headers; |
| 7399 headers.AddHeadersFromString( | 7496 headers.AddHeadersFromString( |
| 7400 "Content-Type: multipart/form-data; " | 7497 "Content-Type: multipart/form-data; " |
| 7401 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" | 7498 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" |
| 7402 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," | 7499 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," |
| 7403 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" | 7500 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7521 | 7618 |
| 7522 // Make sure that 308 responses without bodies are not treated as redirects. | 7619 // Make sure that 308 responses without bodies are not treated as redirects. |
| 7523 // Certain legacy apis that pre-date the response code expect this behavior | 7620 // Certain legacy apis that pre-date the response code expect this behavior |
| 7524 // (Like Google Drive). | 7621 // (Like Google Drive). |
| 7525 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { | 7622 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { |
| 7526 ASSERT_TRUE(http_test_server()->Start()); | 7623 ASSERT_TRUE(http_test_server()->Start()); |
| 7527 | 7624 |
| 7528 TestDelegate d; | 7625 TestDelegate d; |
| 7529 const GURL url = http_test_server()->GetURL("/308-without-location-header"); | 7626 const GURL url = http_test_server()->GetURL("/308-without-location-header"); |
| 7530 | 7627 |
| 7531 std::unique_ptr<URLRequest> request( | 7628 std::unique_ptr<URLRequest> request(default_context_.CreateRequest( |
| 7532 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 7629 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7533 | 7630 |
| 7534 request->Start(); | 7631 request->Start(); |
| 7535 base::RunLoop().Run(); | 7632 base::RunLoop().Run(); |
| 7536 EXPECT_EQ(OK, d.request_status()); | 7633 EXPECT_EQ(OK, d.request_status()); |
| 7537 EXPECT_EQ(0, d.received_redirect_count()); | 7634 EXPECT_EQ(0, d.received_redirect_count()); |
| 7538 EXPECT_EQ(308, request->response_headers()->response_code()); | 7635 EXPECT_EQ(308, request->response_headers()->response_code()); |
| 7539 EXPECT_EQ("This is not a redirect.", d.data_received()); | 7636 EXPECT_EQ("This is not a redirect.", d.data_received()); |
| 7540 } | 7637 } |
| 7541 | 7638 |
| 7542 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { | 7639 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { |
| 7543 ASSERT_TRUE(http_test_server()->Start()); | 7640 ASSERT_TRUE(http_test_server()->Start()); |
| 7544 | 7641 |
| 7545 GURL original_url( | 7642 GURL original_url( |
| 7546 http_test_server()->GetURL("/redirect302-to-echo#fragment")); | 7643 http_test_server()->GetURL("/redirect302-to-echo#fragment")); |
| 7547 GURL expected_url(http_test_server()->GetURL("/echo#fragment")); | 7644 GURL expected_url(http_test_server()->GetURL("/echo#fragment")); |
| 7548 | 7645 |
| 7549 TestDelegate d; | 7646 TestDelegate d; |
| 7550 { | 7647 { |
| 7551 std::unique_ptr<URLRequest> r( | 7648 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7552 default_context_.CreateRequest(original_url, DEFAULT_PRIORITY, &d)); | 7649 original_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7553 | 7650 |
| 7554 r->Start(); | 7651 r->Start(); |
| 7555 base::RunLoop().Run(); | 7652 base::RunLoop().Run(); |
| 7556 | 7653 |
| 7557 EXPECT_EQ(2U, r->url_chain().size()); | 7654 EXPECT_EQ(2U, r->url_chain().size()); |
| 7558 EXPECT_EQ(OK, d.request_status()); | 7655 EXPECT_EQ(OK, d.request_status()); |
| 7559 EXPECT_EQ(original_url, r->original_url()); | 7656 EXPECT_EQ(original_url, r->original_url()); |
| 7560 EXPECT_EQ(expected_url, r->url()); | 7657 EXPECT_EQ(expected_url, r->url()); |
| 7561 } | 7658 } |
| 7562 } | 7659 } |
| 7563 | 7660 |
| 7564 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) { | 7661 TEST_F(URLRequestTestHTTP, RedirectPreserveFirstPartyURL) { |
| 7565 ASSERT_TRUE(http_test_server()->Start()); | 7662 ASSERT_TRUE(http_test_server()->Start()); |
| 7566 | 7663 |
| 7567 GURL url(http_test_server()->GetURL("/redirect302-to-echo")); | 7664 GURL url(http_test_server()->GetURL("/redirect302-to-echo")); |
| 7568 GURL first_party_url("http://example.com"); | 7665 GURL first_party_url("http://example.com"); |
| 7569 | 7666 |
| 7570 TestDelegate d; | 7667 TestDelegate d; |
| 7571 { | 7668 { |
| 7572 std::unique_ptr<URLRequest> r( | 7669 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7573 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 7670 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7574 r->set_first_party_for_cookies(first_party_url); | 7671 r->set_first_party_for_cookies(first_party_url); |
| 7575 | 7672 |
| 7576 r->Start(); | 7673 r->Start(); |
| 7577 base::RunLoop().Run(); | 7674 base::RunLoop().Run(); |
| 7578 | 7675 |
| 7579 EXPECT_EQ(2U, r->url_chain().size()); | 7676 EXPECT_EQ(2U, r->url_chain().size()); |
| 7580 EXPECT_EQ(OK, d.request_status()); | 7677 EXPECT_EQ(OK, d.request_status()); |
| 7581 EXPECT_EQ(first_party_url, r->first_party_for_cookies()); | 7678 EXPECT_EQ(first_party_url, r->first_party_for_cookies()); |
| 7582 } | 7679 } |
| 7583 } | 7680 } |
| 7584 | 7681 |
| 7585 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) { | 7682 TEST_F(URLRequestTestHTTP, RedirectUpdateFirstPartyURL) { |
| 7586 ASSERT_TRUE(http_test_server()->Start()); | 7683 ASSERT_TRUE(http_test_server()->Start()); |
| 7587 | 7684 |
| 7588 GURL url(http_test_server()->GetURL("/redirect302-to-echo")); | 7685 GURL url(http_test_server()->GetURL("/redirect302-to-echo")); |
| 7589 GURL original_first_party_url("http://example.com"); | 7686 GURL original_first_party_url("http://example.com"); |
| 7590 GURL expected_first_party_url(http_test_server()->GetURL("/echo")); | 7687 GURL expected_first_party_url(http_test_server()->GetURL("/echo")); |
| 7591 | 7688 |
| 7592 TestDelegate d; | 7689 TestDelegate d; |
| 7593 { | 7690 { |
| 7594 std::unique_ptr<URLRequest> r( | 7691 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 7595 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 7692 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7596 r->set_first_party_for_cookies(original_first_party_url); | 7693 r->set_first_party_for_cookies(original_first_party_url); |
| 7597 r->set_first_party_url_policy( | 7694 r->set_first_party_url_policy( |
| 7598 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); | 7695 URLRequest::UPDATE_FIRST_PARTY_URL_ON_REDIRECT); |
| 7599 | 7696 |
| 7600 r->Start(); | 7697 r->Start(); |
| 7601 base::RunLoop().Run(); | 7698 base::RunLoop().Run(); |
| 7602 | 7699 |
| 7603 EXPECT_EQ(2U, r->url_chain().size()); | 7700 EXPECT_EQ(2U, r->url_chain().size()); |
| 7604 EXPECT_EQ(OK, d.request_status()); | 7701 EXPECT_EQ(OK, d.request_status()); |
| 7605 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies()); | 7702 EXPECT_EQ(expected_first_party_url, r->first_party_for_cookies()); |
| 7606 } | 7703 } |
| 7607 } | 7704 } |
| 7608 | 7705 |
| 7609 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 7706 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
| 7610 ASSERT_TRUE(http_test_server()->Start()); | 7707 ASSERT_TRUE(http_test_server()->Start()); |
| 7611 | 7708 |
| 7612 const char kData[] = "hello world"; | 7709 const char kData[] = "hello world"; |
| 7613 | 7710 |
| 7614 TestDelegate d; | 7711 TestDelegate d; |
| 7615 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7712 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7616 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 7713 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 7714 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7617 req->set_method("POST"); | 7715 req->set_method("POST"); |
| 7618 req->set_upload(CreateSimpleUploadData(kData)); | 7716 req->set_upload(CreateSimpleUploadData(kData)); |
| 7619 HttpRequestHeaders headers; | 7717 HttpRequestHeaders headers; |
| 7620 headers.SetHeader(HttpRequestHeaders::kContentLength, | 7718 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 7621 base::SizeTToString(arraysize(kData) - 1)); | 7719 base::SizeTToString(arraysize(kData) - 1)); |
| 7622 req->SetExtraRequestHeaders(headers); | 7720 req->SetExtraRequestHeaders(headers); |
| 7623 | 7721 |
| 7624 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( | 7722 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( |
| 7625 req.get(), &default_network_delegate_, | 7723 req.get(), &default_network_delegate_, |
| 7626 http_test_server()->GetURL("/echo"), | 7724 http_test_server()->GetURL("/echo"), |
| 7627 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); | 7725 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); |
| 7628 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 7726 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 7629 | 7727 |
| 7630 req->Start(); | 7728 req->Start(); |
| 7631 base::RunLoop().Run(); | 7729 base::RunLoop().Run(); |
| 7632 EXPECT_EQ("GET", req->method()); | 7730 EXPECT_EQ("GET", req->method()); |
| 7633 } | 7731 } |
| 7634 | 7732 |
| 7635 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 7733 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
| 7636 ASSERT_TRUE(http_test_server()->Start()); | 7734 ASSERT_TRUE(http_test_server()->Start()); |
| 7637 | 7735 |
| 7638 const char kData[] = "hello world"; | 7736 const char kData[] = "hello world"; |
| 7639 | 7737 |
| 7640 TestDelegate d; | 7738 TestDelegate d; |
| 7641 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7739 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7642 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 7740 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 7741 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7643 req->set_method("POST"); | 7742 req->set_method("POST"); |
| 7644 req->set_upload(CreateSimpleUploadData(kData)); | 7743 req->set_upload(CreateSimpleUploadData(kData)); |
| 7645 HttpRequestHeaders headers; | 7744 HttpRequestHeaders headers; |
| 7646 headers.SetHeader(HttpRequestHeaders::kContentLength, | 7745 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 7647 base::SizeTToString(arraysize(kData) - 1)); | 7746 base::SizeTToString(arraysize(kData) - 1)); |
| 7648 req->SetExtraRequestHeaders(headers); | 7747 req->SetExtraRequestHeaders(headers); |
| 7649 | 7748 |
| 7650 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( | 7749 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( |
| 7651 req.get(), &default_network_delegate_, | 7750 req.get(), &default_network_delegate_, |
| 7652 http_test_server()->GetURL("/echo"), | 7751 http_test_server()->GetURL("/echo"), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 7667 StaticHttpUserAgentSettings settings("en", std::string()); | 7766 StaticHttpUserAgentSettings settings("en", std::string()); |
| 7668 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 7767 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 7669 TestURLRequestContext context(true); | 7768 TestURLRequestContext context(true); |
| 7670 context.set_network_delegate(&network_delegate); | 7769 context.set_network_delegate(&network_delegate); |
| 7671 context.set_http_user_agent_settings(&settings); | 7770 context.set_http_user_agent_settings(&settings); |
| 7672 context.Init(); | 7771 context.Init(); |
| 7673 | 7772 |
| 7674 TestDelegate d; | 7773 TestDelegate d; |
| 7675 std::unique_ptr<URLRequest> req(context.CreateRequest( | 7774 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 7676 http_test_server()->GetURL("/echoheader?Accept-Language"), | 7775 http_test_server()->GetURL("/echoheader?Accept-Language"), |
| 7677 DEFAULT_PRIORITY, &d)); | 7776 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7678 req->Start(); | 7777 req->Start(); |
| 7679 base::RunLoop().Run(); | 7778 base::RunLoop().Run(); |
| 7680 EXPECT_EQ("en", d.data_received()); | 7779 EXPECT_EQ("en", d.data_received()); |
| 7681 } | 7780 } |
| 7682 | 7781 |
| 7683 // Check that an empty A-L header is not sent. http://crbug.com/77365. | 7782 // Check that an empty A-L header is not sent. http://crbug.com/77365. |
| 7684 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { | 7783 TEST_F(URLRequestTestHTTP, EmptyAcceptLanguage) { |
| 7685 ASSERT_TRUE(http_test_server()->Start()); | 7784 ASSERT_TRUE(http_test_server()->Start()); |
| 7686 | 7785 |
| 7687 std::string empty_string; // Avoid most vexing parse on line below. | 7786 std::string empty_string; // Avoid most vexing parse on line below. |
| 7688 StaticHttpUserAgentSettings settings(empty_string, empty_string); | 7787 StaticHttpUserAgentSettings settings(empty_string, empty_string); |
| 7689 TestNetworkDelegate network_delegate; // Must outlive URLRequests. | 7788 TestNetworkDelegate network_delegate; // Must outlive URLRequests. |
| 7690 TestURLRequestContext context(true); | 7789 TestURLRequestContext context(true); |
| 7691 context.set_network_delegate(&network_delegate); | 7790 context.set_network_delegate(&network_delegate); |
| 7692 context.Init(); | 7791 context.Init(); |
| 7693 // We override the language after initialization because empty entries | 7792 // We override the language after initialization because empty entries |
| 7694 // get overridden by Init(). | 7793 // get overridden by Init(). |
| 7695 context.set_http_user_agent_settings(&settings); | 7794 context.set_http_user_agent_settings(&settings); |
| 7696 | 7795 |
| 7697 TestDelegate d; | 7796 TestDelegate d; |
| 7698 std::unique_ptr<URLRequest> req(context.CreateRequest( | 7797 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 7699 http_test_server()->GetURL("/echoheader?Accept-Language"), | 7798 http_test_server()->GetURL("/echoheader?Accept-Language"), |
| 7700 DEFAULT_PRIORITY, &d)); | 7799 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7701 req->Start(); | 7800 req->Start(); |
| 7702 base::RunLoop().Run(); | 7801 base::RunLoop().Run(); |
| 7703 EXPECT_EQ("None", d.data_received()); | 7802 EXPECT_EQ("None", d.data_received()); |
| 7704 } | 7803 } |
| 7705 | 7804 |
| 7706 // Check that if request overrides the A-L header, the default is not appended. | 7805 // Check that if request overrides the A-L header, the default is not appended. |
| 7707 // See http://crbug.com/20894 | 7806 // See http://crbug.com/20894 |
| 7708 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { | 7807 TEST_F(URLRequestTestHTTP, OverrideAcceptLanguage) { |
| 7709 ASSERT_TRUE(http_test_server()->Start()); | 7808 ASSERT_TRUE(http_test_server()->Start()); |
| 7710 | 7809 |
| 7711 TestDelegate d; | 7810 TestDelegate d; |
| 7712 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7811 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7713 http_test_server()->GetURL("/echoheader?Accept-Language"), | 7812 http_test_server()->GetURL("/echoheader?Accept-Language"), |
| 7714 DEFAULT_PRIORITY, &d)); | 7813 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7715 HttpRequestHeaders headers; | 7814 HttpRequestHeaders headers; |
| 7716 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); | 7815 headers.SetHeader(HttpRequestHeaders::kAcceptLanguage, "ru"); |
| 7717 req->SetExtraRequestHeaders(headers); | 7816 req->SetExtraRequestHeaders(headers); |
| 7718 req->Start(); | 7817 req->Start(); |
| 7719 base::RunLoop().Run(); | 7818 base::RunLoop().Run(); |
| 7720 EXPECT_EQ(std::string("ru"), d.data_received()); | 7819 EXPECT_EQ(std::string("ru"), d.data_received()); |
| 7721 } | 7820 } |
| 7722 | 7821 |
| 7723 // Check that default A-E header is sent. | 7822 // Check that default A-E header is sent. |
| 7724 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { | 7823 TEST_F(URLRequestTestHTTP, DefaultAcceptEncoding) { |
| 7725 ASSERT_TRUE(http_test_server()->Start()); | 7824 ASSERT_TRUE(http_test_server()->Start()); |
| 7726 | 7825 |
| 7727 TestDelegate d; | 7826 TestDelegate d; |
| 7728 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7827 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7729 http_test_server()->GetURL("/echoheader?Accept-Encoding"), | 7828 http_test_server()->GetURL("/echoheader?Accept-Encoding"), |
| 7730 DEFAULT_PRIORITY, &d)); | 7829 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7731 HttpRequestHeaders headers; | 7830 HttpRequestHeaders headers; |
| 7732 req->SetExtraRequestHeaders(headers); | 7831 req->SetExtraRequestHeaders(headers); |
| 7733 req->Start(); | 7832 req->Start(); |
| 7734 base::RunLoop().Run(); | 7833 base::RunLoop().Run(); |
| 7735 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); | 7834 EXPECT_TRUE(ContainsString(d.data_received(), "gzip")); |
| 7736 } | 7835 } |
| 7737 | 7836 |
| 7738 // Check that if request overrides the A-E header, the default is not appended. | 7837 // Check that if request overrides the A-E header, the default is not appended. |
| 7739 // See http://crbug.com/47381 | 7838 // See http://crbug.com/47381 |
| 7740 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { | 7839 TEST_F(URLRequestTestHTTP, OverrideAcceptEncoding) { |
| 7741 ASSERT_TRUE(http_test_server()->Start()); | 7840 ASSERT_TRUE(http_test_server()->Start()); |
| 7742 | 7841 |
| 7743 TestDelegate d; | 7842 TestDelegate d; |
| 7744 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7843 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7745 http_test_server()->GetURL("/echoheader?Accept-Encoding"), | 7844 http_test_server()->GetURL("/echoheader?Accept-Encoding"), |
| 7746 DEFAULT_PRIORITY, &d)); | 7845 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7747 HttpRequestHeaders headers; | 7846 HttpRequestHeaders headers; |
| 7748 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); | 7847 headers.SetHeader(HttpRequestHeaders::kAcceptEncoding, "identity"); |
| 7749 req->SetExtraRequestHeaders(headers); | 7848 req->SetExtraRequestHeaders(headers); |
| 7750 req->Start(); | 7849 req->Start(); |
| 7751 base::RunLoop().Run(); | 7850 base::RunLoop().Run(); |
| 7752 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); | 7851 EXPECT_FALSE(ContainsString(d.data_received(), "gzip")); |
| 7753 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); | 7852 EXPECT_TRUE(ContainsString(d.data_received(), "identity")); |
| 7754 } | 7853 } |
| 7755 | 7854 |
| 7756 // Check that setting the A-C header sends the proper header. | 7855 // Check that setting the A-C header sends the proper header. |
| 7757 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { | 7856 TEST_F(URLRequestTestHTTP, SetAcceptCharset) { |
| 7758 ASSERT_TRUE(http_test_server()->Start()); | 7857 ASSERT_TRUE(http_test_server()->Start()); |
| 7759 | 7858 |
| 7760 TestDelegate d; | 7859 TestDelegate d; |
| 7761 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7860 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7762 http_test_server()->GetURL("/echoheader?Accept-Charset"), | 7861 http_test_server()->GetURL("/echoheader?Accept-Charset"), |
| 7763 DEFAULT_PRIORITY, &d)); | 7862 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7764 HttpRequestHeaders headers; | 7863 HttpRequestHeaders headers; |
| 7765 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); | 7864 headers.SetHeader(HttpRequestHeaders::kAcceptCharset, "koi-8r"); |
| 7766 req->SetExtraRequestHeaders(headers); | 7865 req->SetExtraRequestHeaders(headers); |
| 7767 req->Start(); | 7866 req->Start(); |
| 7768 base::RunLoop().Run(); | 7867 base::RunLoop().Run(); |
| 7769 EXPECT_EQ(std::string("koi-8r"), d.data_received()); | 7868 EXPECT_EQ(std::string("koi-8r"), d.data_received()); |
| 7770 } | 7869 } |
| 7771 | 7870 |
| 7772 // Check that default User-Agent header is sent. | 7871 // Check that default User-Agent header is sent. |
| 7773 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { | 7872 TEST_F(URLRequestTestHTTP, DefaultUserAgent) { |
| 7774 ASSERT_TRUE(http_test_server()->Start()); | 7873 ASSERT_TRUE(http_test_server()->Start()); |
| 7775 | 7874 |
| 7776 TestDelegate d; | 7875 TestDelegate d; |
| 7777 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7876 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7778 http_test_server()->GetURL("/echoheader?User-Agent"), DEFAULT_PRIORITY, | 7877 http_test_server()->GetURL("/echoheader?User-Agent"), DEFAULT_PRIORITY, |
| 7779 &d)); | 7878 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7780 req->Start(); | 7879 req->Start(); |
| 7781 base::RunLoop().Run(); | 7880 base::RunLoop().Run(); |
| 7782 EXPECT_EQ(default_context_.http_user_agent_settings()->GetUserAgent(), | 7881 EXPECT_EQ(default_context_.http_user_agent_settings()->GetUserAgent(), |
| 7783 d.data_received()); | 7882 d.data_received()); |
| 7784 } | 7883 } |
| 7785 | 7884 |
| 7786 // Check that if request overrides the User-Agent header, | 7885 // Check that if request overrides the User-Agent header, |
| 7787 // the default is not appended. | 7886 // the default is not appended. |
| 7788 // TODO(crbug.com/564656) This test is flaky on iOS. | 7887 // TODO(crbug.com/564656) This test is flaky on iOS. |
| 7789 #if defined(OS_IOS) | 7888 #if defined(OS_IOS) |
| 7790 #define MAYBE_OverrideUserAgent FLAKY_OverrideUserAgent | 7889 #define MAYBE_OverrideUserAgent FLAKY_OverrideUserAgent |
| 7791 #else | 7890 #else |
| 7792 #define MAYBE_OverrideUserAgent OverrideUserAgent | 7891 #define MAYBE_OverrideUserAgent OverrideUserAgent |
| 7793 #endif | 7892 #endif |
| 7794 TEST_F(URLRequestTestHTTP, MAYBE_OverrideUserAgent) { | 7893 TEST_F(URLRequestTestHTTP, MAYBE_OverrideUserAgent) { |
| 7795 ASSERT_TRUE(http_test_server()->Start()); | 7894 ASSERT_TRUE(http_test_server()->Start()); |
| 7796 | 7895 |
| 7797 TestDelegate d; | 7896 TestDelegate d; |
| 7798 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7897 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7799 http_test_server()->GetURL("/echoheader?User-Agent"), DEFAULT_PRIORITY, | 7898 http_test_server()->GetURL("/echoheader?User-Agent"), DEFAULT_PRIORITY, |
| 7800 &d)); | 7899 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7801 HttpRequestHeaders headers; | 7900 HttpRequestHeaders headers; |
| 7802 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); | 7901 headers.SetHeader(HttpRequestHeaders::kUserAgent, "Lynx (textmode)"); |
| 7803 req->SetExtraRequestHeaders(headers); | 7902 req->SetExtraRequestHeaders(headers); |
| 7804 req->Start(); | 7903 req->Start(); |
| 7805 base::RunLoop().Run(); | 7904 base::RunLoop().Run(); |
| 7806 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); | 7905 EXPECT_EQ(std::string("Lynx (textmode)"), d.data_received()); |
| 7807 } | 7906 } |
| 7808 | 7907 |
| 7809 // Check that a NULL HttpUserAgentSettings causes the corresponding empty | 7908 // Check that a NULL HttpUserAgentSettings causes the corresponding empty |
| 7810 // User-Agent header to be sent but does not send the Accept-Language and | 7909 // User-Agent header to be sent but does not send the Accept-Language and |
| (...skipping 12 matching lines...) Expand all Loading... |
| 7823 struct { | 7922 struct { |
| 7824 const char* request; | 7923 const char* request; |
| 7825 const char* expected_response; | 7924 const char* expected_response; |
| 7826 } tests[] = {{"/echoheader?Accept-Language", "None"}, | 7925 } tests[] = {{"/echoheader?Accept-Language", "None"}, |
| 7827 {"/echoheader?Accept-Charset", "None"}, | 7926 {"/echoheader?Accept-Charset", "None"}, |
| 7828 {"/echoheader?User-Agent", ""}}; | 7927 {"/echoheader?User-Agent", ""}}; |
| 7829 | 7928 |
| 7830 for (size_t i = 0; i < arraysize(tests); i++) { | 7929 for (size_t i = 0; i < arraysize(tests); i++) { |
| 7831 TestDelegate d; | 7930 TestDelegate d; |
| 7832 std::unique_ptr<URLRequest> req(context.CreateRequest( | 7931 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 7833 http_test_server()->GetURL(tests[i].request), DEFAULT_PRIORITY, &d)); | 7932 http_test_server()->GetURL(tests[i].request), DEFAULT_PRIORITY, &d, |
| 7933 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7834 req->Start(); | 7934 req->Start(); |
| 7835 base::RunLoop().Run(); | 7935 base::RunLoop().Run(); |
| 7836 EXPECT_EQ(tests[i].expected_response, d.data_received()) | 7936 EXPECT_EQ(tests[i].expected_response, d.data_received()) |
| 7837 << " Request = \"" << tests[i].request << "\""; | 7937 << " Request = \"" << tests[i].request << "\""; |
| 7838 } | 7938 } |
| 7839 } | 7939 } |
| 7840 | 7940 |
| 7841 // Make sure that URLRequest passes on its priority updates to | 7941 // Make sure that URLRequest passes on its priority updates to |
| 7842 // newly-created jobs after the first one. | 7942 // newly-created jobs after the first one. |
| 7843 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { | 7943 TEST_F(URLRequestTestHTTP, SetSubsequentJobPriority) { |
| 7844 ASSERT_TRUE(http_test_server()->Start()); | 7944 ASSERT_TRUE(http_test_server()->Start()); |
| 7845 | 7945 |
| 7846 TestDelegate d; | 7946 TestDelegate d; |
| 7847 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 7947 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7848 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 7948 http_test_server()->GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 7949 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7849 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); | 7950 EXPECT_EQ(DEFAULT_PRIORITY, req->priority()); |
| 7850 | 7951 |
| 7851 std::unique_ptr<URLRequestRedirectJob> redirect_job(new URLRequestRedirectJob( | 7952 std::unique_ptr<URLRequestRedirectJob> redirect_job(new URLRequestRedirectJob( |
| 7852 req.get(), &default_network_delegate_, | 7953 req.get(), &default_network_delegate_, |
| 7853 http_test_server()->GetURL("/echo"), | 7954 http_test_server()->GetURL("/echo"), |
| 7854 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); | 7955 URLRequestRedirectJob::REDIRECT_302_FOUND, "Very Good Reason")); |
| 7855 AddTestInterceptor()->set_main_intercept_job(std::move(redirect_job)); | 7956 AddTestInterceptor()->set_main_intercept_job(std::move(redirect_job)); |
| 7856 | 7957 |
| 7857 req->SetPriority(LOW); | 7958 req->SetPriority(LOW); |
| 7858 req->Start(); | 7959 req->Start(); |
| (...skipping 21 matching lines...) Expand all Loading... |
| 7880 HttpCache http_cache(std::move(network_layer), | 7981 HttpCache http_cache(std::move(network_layer), |
| 7881 HttpCache::DefaultBackend::InMemory(0), | 7982 HttpCache::DefaultBackend::InMemory(0), |
| 7882 false /* is_main_cache */); | 7983 false /* is_main_cache */); |
| 7883 | 7984 |
| 7884 TestURLRequestContext context(true); | 7985 TestURLRequestContext context(true); |
| 7885 context.set_http_transaction_factory(&http_cache); | 7986 context.set_http_transaction_factory(&http_cache); |
| 7886 context.Init(); | 7987 context.Init(); |
| 7887 | 7988 |
| 7888 TestDelegate d; | 7989 TestDelegate d; |
| 7889 std::unique_ptr<URLRequest> req( | 7990 std::unique_ptr<URLRequest> req( |
| 7890 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); | 7991 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, |
| 7992 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7891 req->Start(); | 7993 req->Start(); |
| 7892 base::RunLoop().Run(); | 7994 base::RunLoop().Run(); |
| 7893 | 7995 |
| 7894 EXPECT_TRUE(d.request_failed()); | 7996 EXPECT_TRUE(d.request_failed()); |
| 7895 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, d.request_status()); | 7997 EXPECT_EQ(ERR_NETWORK_IO_SUSPENDED, d.request_status()); |
| 7896 } | 7998 } |
| 7897 | 7999 |
| 7898 namespace { | 8000 namespace { |
| 7899 | 8001 |
| 7900 // HttpTransactionFactory that synchronously fails to create transactions. | 8002 // HttpTransactionFactory that synchronously fails to create transactions. |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7933 TEST_F(URLRequestTestHTTP, NetworkCancelAfterCreateTransactionFailsTest) { | 8035 TEST_F(URLRequestTestHTTP, NetworkCancelAfterCreateTransactionFailsTest) { |
| 7934 FailingHttpTransactionFactory http_transaction_factory( | 8036 FailingHttpTransactionFactory http_transaction_factory( |
| 7935 default_context_.http_transaction_factory()->GetSession()); | 8037 default_context_.http_transaction_factory()->GetSession()); |
| 7936 TestURLRequestContext context(true); | 8038 TestURLRequestContext context(true); |
| 7937 context.set_http_transaction_factory(&http_transaction_factory); | 8039 context.set_http_transaction_factory(&http_transaction_factory); |
| 7938 context.set_network_delegate(default_network_delegate()); | 8040 context.set_network_delegate(default_network_delegate()); |
| 7939 context.Init(); | 8041 context.Init(); |
| 7940 | 8042 |
| 7941 TestDelegate d; | 8043 TestDelegate d; |
| 7942 std::unique_ptr<URLRequest> req( | 8044 std::unique_ptr<URLRequest> req( |
| 7943 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d)); | 8045 context.CreateRequest(GURL("http://127.0.0.1/"), DEFAULT_PRIORITY, &d, |
| 8046 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7944 // Don't send cookies (Collecting cookies is asynchronous, and need request to | 8047 // Don't send cookies (Collecting cookies is asynchronous, and need request to |
| 7945 // try to create an HttpNetworkTransaction synchronously on start). | 8048 // try to create an HttpNetworkTransaction synchronously on start). |
| 7946 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); | 8049 req->SetLoadFlags(LOAD_DO_NOT_SEND_COOKIES); |
| 7947 req->Start(); | 8050 req->Start(); |
| 7948 req->Cancel(); | 8051 req->Cancel(); |
| 7949 base::RunLoop().Run(); | 8052 base::RunLoop().Run(); |
| 7950 // Run pending error task, if there is one. | 8053 // Run pending error task, if there is one. |
| 7951 base::RunLoop().RunUntilIdle(); | 8054 base::RunLoop().RunUntilIdle(); |
| 7952 | 8055 |
| 7953 EXPECT_TRUE(d.request_failed()); | 8056 EXPECT_TRUE(d.request_failed()); |
| 7954 EXPECT_EQ(1, d.response_started_count()); | 8057 EXPECT_EQ(1, d.response_started_count()); |
| 7955 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 8058 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 7956 | 8059 |
| 7957 // NetworkDelegate should see the cancellation, but not the error. | 8060 // NetworkDelegate should see the cancellation, but not the error. |
| 7958 EXPECT_EQ(1, default_network_delegate()->canceled_requests()); | 8061 EXPECT_EQ(1, default_network_delegate()->canceled_requests()); |
| 7959 EXPECT_EQ(0, default_network_delegate()->error_count()); | 8062 EXPECT_EQ(0, default_network_delegate()->error_count()); |
| 7960 } | 8063 } |
| 7961 | 8064 |
| 7962 TEST_F(URLRequestTestHTTP, NetworkAccessedSetOnNetworkRequest) { | 8065 TEST_F(URLRequestTestHTTP, NetworkAccessedSetOnNetworkRequest) { |
| 7963 ASSERT_TRUE(http_test_server()->Start()); | 8066 ASSERT_TRUE(http_test_server()->Start()); |
| 7964 | 8067 |
| 7965 TestDelegate d; | 8068 TestDelegate d; |
| 7966 GURL test_url(http_test_server()->GetURL("/")); | 8069 GURL test_url(http_test_server()->GetURL("/")); |
| 7967 std::unique_ptr<URLRequest> req( | 8070 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7968 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 8071 test_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7969 | 8072 |
| 7970 req->Start(); | 8073 req->Start(); |
| 7971 base::RunLoop().Run(); | 8074 base::RunLoop().Run(); |
| 7972 | 8075 |
| 7973 EXPECT_TRUE(req->response_info().network_accessed); | 8076 EXPECT_TRUE(req->response_info().network_accessed); |
| 7974 } | 8077 } |
| 7975 | 8078 |
| 7976 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnCachedResponse) { | 8079 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnCachedResponse) { |
| 7977 ASSERT_TRUE(http_test_server()->Start()); | 8080 ASSERT_TRUE(http_test_server()->Start()); |
| 7978 | 8081 |
| 7979 // Populate the cache. | 8082 // Populate the cache. |
| 7980 TestDelegate d; | 8083 TestDelegate d; |
| 7981 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 8084 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 7982 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d)); | 8085 http_test_server()->GetURL("/cachetime"), DEFAULT_PRIORITY, &d, |
| 8086 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 7983 req->Start(); | 8087 req->Start(); |
| 7984 base::RunLoop().Run(); | 8088 base::RunLoop().Run(); |
| 7985 | 8089 |
| 7986 EXPECT_EQ(OK, d.request_status()); | 8090 EXPECT_EQ(OK, d.request_status()); |
| 7987 EXPECT_TRUE(req->response_info().network_accessed); | 8091 EXPECT_TRUE(req->response_info().network_accessed); |
| 7988 EXPECT_FALSE(req->response_info().was_cached); | 8092 EXPECT_FALSE(req->response_info().was_cached); |
| 7989 | 8093 |
| 7990 req = default_context_.CreateRequest(http_test_server()->GetURL("/cachetime"), | 8094 req = default_context_.CreateRequest(http_test_server()->GetURL("/cachetime"), |
| 7991 DEFAULT_PRIORITY, &d); | 8095 DEFAULT_PRIORITY, &d, |
| 8096 TRAFFIC_ANNOTATION_FOR_TESTS); |
| 7992 req->Start(); | 8097 req->Start(); |
| 7993 base::RunLoop().Run(); | 8098 base::RunLoop().Run(); |
| 7994 | 8099 |
| 7995 EXPECT_EQ(OK, d.request_status()); | 8100 EXPECT_EQ(OK, d.request_status()); |
| 7996 EXPECT_FALSE(req->response_info().network_accessed); | 8101 EXPECT_FALSE(req->response_info().network_accessed); |
| 7997 EXPECT_TRUE(req->response_info().was_cached); | 8102 EXPECT_TRUE(req->response_info().was_cached); |
| 7998 } | 8103 } |
| 7999 | 8104 |
| 8000 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnLoadOnlyFromCache) { | 8105 TEST_F(URLRequestTestHTTP, NetworkAccessedClearOnLoadOnlyFromCache) { |
| 8001 ASSERT_TRUE(http_test_server()->Start()); | 8106 ASSERT_TRUE(http_test_server()->Start()); |
| 8002 | 8107 |
| 8003 TestDelegate d; | 8108 TestDelegate d; |
| 8004 GURL test_url(http_test_server()->GetURL("/")); | 8109 GURL test_url(http_test_server()->GetURL("/")); |
| 8005 std::unique_ptr<URLRequest> req( | 8110 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 8006 default_context_.CreateRequest(test_url, DEFAULT_PRIORITY, &d)); | 8111 test_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8007 req->SetLoadFlags(LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION); | 8112 req->SetLoadFlags(LOAD_ONLY_FROM_CACHE | LOAD_SKIP_CACHE_VALIDATION); |
| 8008 | 8113 |
| 8009 req->Start(); | 8114 req->Start(); |
| 8010 base::RunLoop().Run(); | 8115 base::RunLoop().Run(); |
| 8011 | 8116 |
| 8012 EXPECT_FALSE(req->response_info().network_accessed); | 8117 EXPECT_FALSE(req->response_info().network_accessed); |
| 8013 } | 8118 } |
| 8014 | 8119 |
| 8015 // Test that a single job with a THROTTLED priority completes | 8120 // Test that a single job with a THROTTLED priority completes |
| 8016 // correctly in the absence of contention. | 8121 // correctly in the absence of contention. |
| 8017 TEST_F(URLRequestTestHTTP, ThrottledPriority) { | 8122 TEST_F(URLRequestTestHTTP, ThrottledPriority) { |
| 8018 ASSERT_TRUE(http_test_server()->Start()); | 8123 ASSERT_TRUE(http_test_server()->Start()); |
| 8019 | 8124 |
| 8020 TestDelegate d; | 8125 TestDelegate d; |
| 8021 GURL test_url(http_test_server()->GetURL("/")); | 8126 GURL test_url(http_test_server()->GetURL("/")); |
| 8022 std::unique_ptr<URLRequest> req( | 8127 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 8023 default_context_.CreateRequest(test_url, THROTTLED, &d)); | 8128 test_url, THROTTLED, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8024 req->Start(); | 8129 req->Start(); |
| 8025 base::RunLoop().Run(); | 8130 base::RunLoop().Run(); |
| 8026 | 8131 |
| 8027 EXPECT_TRUE(req->status().is_success()); | 8132 EXPECT_TRUE(req->status().is_success()); |
| 8028 } | 8133 } |
| 8029 | 8134 |
| 8030 // A class to hold state for responding to USER_NOTIFY callbacks from | 8135 // A class to hold state for responding to USER_NOTIFY callbacks from |
| 8031 // BlockingNetworkDelegate. It also accepts a RunLoop that will be | 8136 // BlockingNetworkDelegate. It also accepts a RunLoop that will be |
| 8032 // signaled via QuitWhenIdle() when any request is blocked. | 8137 // signaled via QuitWhenIdle() when any request is blocked. |
| 8033 // | 8138 // |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8092 base::Unretained(¬ification_handler))); | 8197 base::Unretained(¬ification_handler))); |
| 8093 | 8198 |
| 8094 TestURLRequestContext context(true); | 8199 TestURLRequestContext context(true); |
| 8095 context.set_network_delegate(&network_delegate); | 8200 context.set_network_delegate(&network_delegate); |
| 8096 context.Init(); | 8201 context.Init(); |
| 8097 | 8202 |
| 8098 // Use different test URLs to make sure all three requests turn into | 8203 // Use different test URLs to make sure all three requests turn into |
| 8099 // HttpNetworkTransacations. Use different URLRequest::Delegates so that | 8204 // HttpNetworkTransacations. Use different URLRequest::Delegates so that |
| 8100 // the requests may be waited on separately. | 8205 // the requests may be waited on separately. |
| 8101 TestDelegate d1; | 8206 TestDelegate d1; |
| 8102 std::unique_ptr<URLRequest> req1(context.CreateRequest( | 8207 std::unique_ptr<URLRequest> req1( |
| 8103 http_test_server()->GetURL("/echoall/l"), THROTTLED, &d1)); | 8208 context.CreateRequest(http_test_server()->GetURL("/echoall/l"), THROTTLED, |
| 8209 &d1, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8104 notification_handler.AddURLRequestToBlockList(req1.get()); | 8210 notification_handler.AddURLRequestToBlockList(req1.get()); |
| 8105 | 8211 |
| 8106 TestDelegate d2; | 8212 TestDelegate d2; |
| 8107 std::unique_ptr<URLRequest> req2(context.CreateRequest( | 8213 std::unique_ptr<URLRequest> req2( |
| 8108 http_test_server()->GetURL("/echoall/2"), THROTTLED, &d2)); | 8214 context.CreateRequest(http_test_server()->GetURL("/echoall/2"), THROTTLED, |
| 8215 &d2, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8109 notification_handler.AddURLRequestToBlockList(req2.get()); | 8216 notification_handler.AddURLRequestToBlockList(req2.get()); |
| 8110 | 8217 |
| 8111 TestDelegate d3; | 8218 TestDelegate d3; |
| 8112 std::unique_ptr<URLRequest> req3(context.CreateRequest( | 8219 std::unique_ptr<URLRequest> req3( |
| 8113 http_test_server()->GetURL("/echoall/3"), THROTTLED, &d3)); | 8220 context.CreateRequest(http_test_server()->GetURL("/echoall/3"), THROTTLED, |
| 8221 &d3, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8114 req1->Start(); | 8222 req1->Start(); |
| 8115 req2->Start(); | 8223 req2->Start(); |
| 8116 req3->Start(); | 8224 req3->Start(); |
| 8117 run_until_request_blocked.Run(); | 8225 run_until_request_blocked.Run(); |
| 8118 notification_handler.SetRunLoop(nullptr); | 8226 notification_handler.SetRunLoop(nullptr); |
| 8119 | 8227 |
| 8120 // The first two requests should be blocked based on the notification | 8228 // The first two requests should be blocked based on the notification |
| 8121 // callback, and their status should have blocked the third request | 8229 // callback, and their status should have blocked the third request |
| 8122 // through throttling. | 8230 // through throttling. |
| 8123 EXPECT_TRUE(req1->status().is_io_pending()); | 8231 EXPECT_TRUE(req1->status().is_io_pending()); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8171 base::Unretained(¬ification_handler))); | 8279 base::Unretained(¬ification_handler))); |
| 8172 | 8280 |
| 8173 TestURLRequestContext context(true); | 8281 TestURLRequestContext context(true); |
| 8174 context.set_network_delegate(&network_delegate); | 8282 context.set_network_delegate(&network_delegate); |
| 8175 context.Init(); | 8283 context.Init(); |
| 8176 | 8284 |
| 8177 // Use different test URLs to make sure all three requests turn into | 8285 // Use different test URLs to make sure all three requests turn into |
| 8178 // HttpNetworkTransacations. Use different URLRequest::Delegates so that | 8286 // HttpNetworkTransacations. Use different URLRequest::Delegates so that |
| 8179 // the requests may be waited on separately. | 8287 // the requests may be waited on separately. |
| 8180 TestDelegate d1; | 8288 TestDelegate d1; |
| 8181 std::unique_ptr<URLRequest> req1(context.CreateRequest( | 8289 std::unique_ptr<URLRequest> req1( |
| 8182 http_test_server()->GetURL("/echoall/l"), THROTTLED, &d1)); | 8290 context.CreateRequest(http_test_server()->GetURL("/echoall/l"), THROTTLED, |
| 8291 &d1, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8183 notification_handler.AddURLRequestToBlockList(req1.get()); | 8292 notification_handler.AddURLRequestToBlockList(req1.get()); |
| 8184 | 8293 |
| 8185 TestDelegate d2; | 8294 TestDelegate d2; |
| 8186 std::unique_ptr<URLRequest> req2(context.CreateRequest( | 8295 std::unique_ptr<URLRequest> req2( |
| 8187 http_test_server()->GetURL("/echoall/2"), THROTTLED, &d2)); | 8296 context.CreateRequest(http_test_server()->GetURL("/echoall/2"), THROTTLED, |
| 8297 &d2, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8188 notification_handler.AddURLRequestToBlockList(req2.get()); | 8298 notification_handler.AddURLRequestToBlockList(req2.get()); |
| 8189 | 8299 |
| 8190 TestDelegate d3; | 8300 TestDelegate d3; |
| 8191 std::unique_ptr<URLRequest> req3(context.CreateRequest( | 8301 std::unique_ptr<URLRequest> req3( |
| 8192 http_test_server()->GetURL("/echoall/3"), THROTTLED, &d3)); | 8302 context.CreateRequest(http_test_server()->GetURL("/echoall/3"), THROTTLED, |
| 8303 &d3, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8193 req1->Start(); | 8304 req1->Start(); |
| 8194 req2->Start(); | 8305 req2->Start(); |
| 8195 req3->Start(); | 8306 req3->Start(); |
| 8196 run_until_request_blocked.Run(); | 8307 run_until_request_blocked.Run(); |
| 8197 notification_handler.SetRunLoop(nullptr); | 8308 notification_handler.SetRunLoop(nullptr); |
| 8198 | 8309 |
| 8199 // The first two requests should be blocked based on the notification | 8310 // The first two requests should be blocked based on the notification |
| 8200 // callback, and their status should have blocked the third request | 8311 // callback, and their status should have blocked the third request |
| 8201 // through throttling. | 8312 // through throttling. |
| 8202 EXPECT_TRUE(req1->status().is_io_pending()); | 8313 EXPECT_TRUE(req1->status().is_io_pending()); |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8246 base::Unretained(¬ification_handler))); | 8357 base::Unretained(¬ification_handler))); |
| 8247 | 8358 |
| 8248 TestURLRequestContext context(true); | 8359 TestURLRequestContext context(true); |
| 8249 context.set_network_delegate(&network_delegate); | 8360 context.set_network_delegate(&network_delegate); |
| 8250 context.Init(); | 8361 context.Init(); |
| 8251 | 8362 |
| 8252 // Use different test URLs to make sure all three requests turn into | 8363 // Use different test URLs to make sure all three requests turn into |
| 8253 // HttpNetworkTransacations. Use different URLRequest::Delegates so that | 8364 // HttpNetworkTransacations. Use different URLRequest::Delegates so that |
| 8254 // the requests may be waited on separately. | 8365 // the requests may be waited on separately. |
| 8255 TestDelegate d1; | 8366 TestDelegate d1; |
| 8256 std::unique_ptr<URLRequest> req1(context.CreateRequest( | 8367 std::unique_ptr<URLRequest> req1( |
| 8257 http_test_server()->GetURL("/echoall/l"), THROTTLED, &d1)); | 8368 context.CreateRequest(http_test_server()->GetURL("/echoall/l"), THROTTLED, |
| 8369 &d1, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8258 notification_handler.AddURLRequestToBlockList(req1.get()); | 8370 notification_handler.AddURLRequestToBlockList(req1.get()); |
| 8259 | 8371 |
| 8260 TestDelegate d2; | 8372 TestDelegate d2; |
| 8261 std::unique_ptr<URLRequest> req2(context.CreateRequest( | 8373 std::unique_ptr<URLRequest> req2( |
| 8262 http_test_server()->GetURL("/echoall/2"), THROTTLED, &d2)); | 8374 context.CreateRequest(http_test_server()->GetURL("/echoall/2"), THROTTLED, |
| 8375 &d2, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8263 notification_handler.AddURLRequestToBlockList(req2.get()); | 8376 notification_handler.AddURLRequestToBlockList(req2.get()); |
| 8264 | 8377 |
| 8265 TestDelegate d3; | 8378 TestDelegate d3; |
| 8266 std::unique_ptr<URLRequest> req3(context.CreateRequest( | 8379 std::unique_ptr<URLRequest> req3( |
| 8267 http_test_server()->GetURL("/echoall/3"), THROTTLED, &d3)); | 8380 context.CreateRequest(http_test_server()->GetURL("/echoall/3"), THROTTLED, |
| 8381 &d3, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8268 req1->Start(); | 8382 req1->Start(); |
| 8269 req2->Start(); | 8383 req2->Start(); |
| 8270 req3->Start(); | 8384 req3->Start(); |
| 8271 run_until_request_blocked.Run(); | 8385 run_until_request_blocked.Run(); |
| 8272 notification_handler.SetRunLoop(nullptr); | 8386 notification_handler.SetRunLoop(nullptr); |
| 8273 | 8387 |
| 8274 // The first two requests should be blocked based on the notification | 8388 // The first two requests should be blocked based on the notification |
| 8275 // callback, and their status should have blocked the third request | 8389 // callback, and their status should have blocked the third request |
| 8276 // through throttling. | 8390 // through throttling. |
| 8277 EXPECT_TRUE(req1->status().is_io_pending()); | 8391 EXPECT_TRUE(req1->status().is_io_pending()); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 8300 EXPECT_TRUE(req1->status().is_io_pending()); | 8414 EXPECT_TRUE(req1->status().is_io_pending()); |
| 8301 EXPECT_TRUE(req2->status().is_io_pending()); | 8415 EXPECT_TRUE(req2->status().is_io_pending()); |
| 8302 EXPECT_EQ(URLRequestStatus::SUCCESS, req3->status().status()); | 8416 EXPECT_EQ(URLRequestStatus::SUCCESS, req3->status().status()); |
| 8303 } | 8417 } |
| 8304 | 8418 |
| 8305 TEST_F(URLRequestTestHTTP, RawBodyBytesNoContentEncoding) { | 8419 TEST_F(URLRequestTestHTTP, RawBodyBytesNoContentEncoding) { |
| 8306 ASSERT_TRUE(http_test_server()->Start()); | 8420 ASSERT_TRUE(http_test_server()->Start()); |
| 8307 | 8421 |
| 8308 TestDelegate d; | 8422 TestDelegate d; |
| 8309 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 8423 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 8310 http_test_server()->GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); | 8424 http_test_server()->GetURL("/simple.html"), DEFAULT_PRIORITY, &d, |
| 8425 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8311 req->Start(); | 8426 req->Start(); |
| 8312 base::RunLoop().Run(); | 8427 base::RunLoop().Run(); |
| 8313 | 8428 |
| 8314 EXPECT_EQ(5, req->GetRawBodyBytes()); | 8429 EXPECT_EQ(5, req->GetRawBodyBytes()); |
| 8315 } | 8430 } |
| 8316 | 8431 |
| 8317 TEST_F(URLRequestTestHTTP, RawBodyBytesGzipEncoding) { | 8432 TEST_F(URLRequestTestHTTP, RawBodyBytesGzipEncoding) { |
| 8318 ASSERT_TRUE(http_test_server()->Start()); | 8433 ASSERT_TRUE(http_test_server()->Start()); |
| 8319 | 8434 |
| 8320 TestDelegate d; | 8435 TestDelegate d; |
| 8321 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 8436 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 8322 http_test_server()->GetURL("/gzip-encoded"), DEFAULT_PRIORITY, &d)); | 8437 http_test_server()->GetURL("/gzip-encoded"), DEFAULT_PRIORITY, &d, |
| 8438 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8323 req->Start(); | 8439 req->Start(); |
| 8324 base::RunLoop().Run(); | 8440 base::RunLoop().Run(); |
| 8325 | 8441 |
| 8326 EXPECT_EQ(30, req->GetRawBodyBytes()); | 8442 EXPECT_EQ(30, req->GetRawBodyBytes()); |
| 8327 } | 8443 } |
| 8328 | 8444 |
| 8329 // Check that if NetworkDelegate::OnBeforeStartTransaction returns an error, | 8445 // Check that if NetworkDelegate::OnBeforeStartTransaction returns an error, |
| 8330 // the delegate isn't called back synchronously. | 8446 // the delegate isn't called back synchronously. |
| 8331 TEST_F(URLRequestTestHTTP, TesBeforeStartTransactionFails) { | 8447 TEST_F(URLRequestTestHTTP, TesBeforeStartTransactionFails) { |
| 8332 ASSERT_TRUE(http_test_server()->Start()); | 8448 ASSERT_TRUE(http_test_server()->Start()); |
| 8333 default_network_delegate_.set_before_start_transaction_fails(); | 8449 default_network_delegate_.set_before_start_transaction_fails(); |
| 8334 | 8450 |
| 8335 TestDelegate d; | 8451 TestDelegate d; |
| 8336 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 8452 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 8337 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d)); | 8453 http_test_server()->GetURL("/"), DEFAULT_PRIORITY, &d, |
| 8454 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8338 req->Start(); | 8455 req->Start(); |
| 8339 DCHECK(!d.response_completed()); | 8456 DCHECK(!d.response_completed()); |
| 8340 base::RunLoop().Run(); | 8457 base::RunLoop().Run(); |
| 8341 DCHECK(d.response_completed()); | 8458 DCHECK(d.response_completed()); |
| 8342 EXPECT_EQ(ERR_FAILED, d.request_status()); | 8459 EXPECT_EQ(ERR_FAILED, d.request_status()); |
| 8343 } | 8460 } |
| 8344 | 8461 |
| 8345 class URLRequestInterceptorTestHTTP : public URLRequestTestHTTP { | 8462 class URLRequestInterceptorTestHTTP : public URLRequestTestHTTP { |
| 8346 public: | 8463 public: |
| 8347 // TODO(bengr): Merge this with the URLRequestInterceptorHTTPTest fixture, | 8464 // TODO(bengr): Merge this with the URLRequestInterceptorHTTPTest fixture, |
| (...skipping 19 matching lines...) Expand all Loading... |
| 8367 TEST_F(URLRequestInterceptorTestHTTP, | 8484 TEST_F(URLRequestInterceptorTestHTTP, |
| 8368 NetworkDelegateNotificationOnRedirectIntercept) { | 8485 NetworkDelegateNotificationOnRedirectIntercept) { |
| 8369 interceptor()->set_intercept_redirect(true); | 8486 interceptor()->set_intercept_redirect(true); |
| 8370 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers()); | 8487 interceptor()->set_redirect_headers(MockURLRequestInterceptor::ok_headers()); |
| 8371 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data()); | 8488 interceptor()->set_redirect_data(MockURLRequestInterceptor::ok_data()); |
| 8372 | 8489 |
| 8373 ASSERT_TRUE(http_test_server()->Start()); | 8490 ASSERT_TRUE(http_test_server()->Start()); |
| 8374 | 8491 |
| 8375 TestDelegate d; | 8492 TestDelegate d; |
| 8376 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 8493 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 8377 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, &d)); | 8494 http_test_server()->GetURL("/redirect-test.html"), DEFAULT_PRIORITY, &d, |
| 8495 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8378 req->Start(); | 8496 req->Start(); |
| 8379 base::RunLoop().Run(); | 8497 base::RunLoop().Run(); |
| 8380 | 8498 |
| 8381 EXPECT_TRUE(interceptor()->did_intercept_redirect()); | 8499 EXPECT_TRUE(interceptor()->did_intercept_redirect()); |
| 8382 // Check we got one good response | 8500 // Check we got one good response |
| 8383 int status = d.request_status(); | 8501 int status = d.request_status(); |
| 8384 EXPECT_EQ(OK, status); | 8502 EXPECT_EQ(OK, status); |
| 8385 if (status == OK) | 8503 if (status == OK) |
| 8386 EXPECT_EQ(200, req->response_headers()->response_code()); | 8504 EXPECT_EQ(200, req->response_headers()->response_code()); |
| 8387 | 8505 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 8400 interceptor()->set_intercept_final_response(true); | 8518 interceptor()->set_intercept_final_response(true); |
| 8401 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); | 8519 interceptor()->set_final_headers(MockURLRequestInterceptor::ok_headers()); |
| 8402 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); | 8520 interceptor()->set_final_data(MockURLRequestInterceptor::ok_data()); |
| 8403 default_network_delegate()->set_can_be_intercepted_on_error(true); | 8521 default_network_delegate()->set_can_be_intercepted_on_error(true); |
| 8404 | 8522 |
| 8405 ASSERT_TRUE(http_test_server()->Start()); | 8523 ASSERT_TRUE(http_test_server()->Start()); |
| 8406 | 8524 |
| 8407 TestDelegate d; | 8525 TestDelegate d; |
| 8408 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 8526 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 8409 http_test_server()->GetURL("/two-content-lengths.html"), DEFAULT_PRIORITY, | 8527 http_test_server()->GetURL("/two-content-lengths.html"), DEFAULT_PRIORITY, |
| 8410 &d)); | 8528 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8411 req->set_method("GET"); | 8529 req->set_method("GET"); |
| 8412 req->Start(); | 8530 req->Start(); |
| 8413 base::RunLoop().Run(); | 8531 base::RunLoop().Run(); |
| 8414 | 8532 |
| 8415 EXPECT_TRUE(interceptor()->did_intercept_final()); | 8533 EXPECT_TRUE(interceptor()->did_intercept_final()); |
| 8416 | 8534 |
| 8417 // Check we received one good response. | 8535 // Check we received one good response. |
| 8418 int status = d.request_status(); | 8536 int status = d.request_status(); |
| 8419 EXPECT_EQ(OK, status); | 8537 EXPECT_EQ(OK, status); |
| 8420 if (status == OK) | 8538 if (status == OK) |
| (...skipping 12 matching lines...) Expand all Loading... |
| 8433 // Intercept that error and respond with an OK response. | 8551 // Intercept that error and respond with an OK response. |
| 8434 interceptor()->set_intercept_final_response(true); | 8552 interceptor()->set_intercept_final_response(true); |
| 8435 | 8553 |
| 8436 // Intercept with a real URLRequestHttpJob. | 8554 // Intercept with a real URLRequestHttpJob. |
| 8437 interceptor()->set_use_url_request_http_job(true); | 8555 interceptor()->set_use_url_request_http_job(true); |
| 8438 | 8556 |
| 8439 ASSERT_TRUE(http_test_server()->Start()); | 8557 ASSERT_TRUE(http_test_server()->Start()); |
| 8440 | 8558 |
| 8441 TestDelegate d; | 8559 TestDelegate d; |
| 8442 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 8560 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 8443 http_test_server()->GetURL("/simple.html"), DEFAULT_PRIORITY, &d)); | 8561 http_test_server()->GetURL("/simple.html"), DEFAULT_PRIORITY, &d, |
| 8562 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8444 req->set_method("GET"); | 8563 req->set_method("GET"); |
| 8445 req->Start(); | 8564 req->Start(); |
| 8446 base::RunLoop().Run(); | 8565 base::RunLoop().Run(); |
| 8447 | 8566 |
| 8448 EXPECT_TRUE(interceptor()->did_intercept_final()); | 8567 EXPECT_TRUE(interceptor()->did_intercept_final()); |
| 8449 | 8568 |
| 8450 // Check we received one good response. | 8569 // Check we received one good response. |
| 8451 int status = d.request_status(); | 8570 int status = d.request_status(); |
| 8452 EXPECT_EQ(OK, status); | 8571 EXPECT_EQ(OK, status); |
| 8453 if (status == OK) | 8572 if (status == OK) |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8503 // Create and execute the request: we'll only have a |destination_server_| | 8622 // Create and execute the request: we'll only have a |destination_server_| |
| 8504 // if the origins are meant to be distinct. Otherwise, we'll use the | 8623 // if the origins are meant to be distinct. Otherwise, we'll use the |
| 8505 // |origin_server_| for both endpoints. | 8624 // |origin_server_| for both endpoints. |
| 8506 GURL destination_url = | 8625 GURL destination_url = |
| 8507 destination_server_ ? destination_server_->GetURL("/echoheader?Referer") | 8626 destination_server_ ? destination_server_->GetURL("/echoheader?Referer") |
| 8508 : origin_server_->GetURL("/echoheader?Referer"); | 8627 : origin_server_->GetURL("/echoheader?Referer"); |
| 8509 GURL origin_url = | 8628 GURL origin_url = |
| 8510 origin_server_->GetURL("/server-redirect?" + destination_url.spec()); | 8629 origin_server_->GetURL("/server-redirect?" + destination_url.spec()); |
| 8511 | 8630 |
| 8512 TestDelegate d; | 8631 TestDelegate d; |
| 8513 std::unique_ptr<URLRequest> req( | 8632 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 8514 default_context_.CreateRequest(origin_url, DEFAULT_PRIORITY, &d)); | 8633 origin_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8515 req->set_referrer_policy(policy); | 8634 req->set_referrer_policy(policy); |
| 8516 req->SetReferrer(referrer.spec()); | 8635 req->SetReferrer(referrer.spec()); |
| 8517 req->Start(); | 8636 req->Start(); |
| 8518 base::RunLoop().Run(); | 8637 base::RunLoop().Run(); |
| 8519 | 8638 |
| 8520 EXPECT_EQ(1, d.response_started_count()); | 8639 EXPECT_EQ(1, d.response_started_count()); |
| 8521 EXPECT_EQ(1, d.received_redirect_count()); | 8640 EXPECT_EQ(1, d.received_redirect_count()); |
| 8522 EXPECT_EQ(destination_url, req->url()); | 8641 EXPECT_EQ(destination_url, req->url()); |
| 8523 EXPECT_EQ(OK, d.request_status()); | 8642 EXPECT_EQ(OK, d.request_status()); |
| 8524 EXPECT_EQ(200, req->response_headers()->response_code()); | 8643 EXPECT_EQ(200, req->response_headers()->response_code()); |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8696 | 8815 |
| 8697 TEST_F(HTTPSRequestTest, HTTPSGetTest) { | 8816 TEST_F(HTTPSRequestTest, HTTPSGetTest) { |
| 8698 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 8817 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 8699 test_server.AddDefaultHandlers( | 8818 test_server.AddDefaultHandlers( |
| 8700 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 8819 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 8701 ASSERT_TRUE(test_server.Start()); | 8820 ASSERT_TRUE(test_server.Start()); |
| 8702 | 8821 |
| 8703 TestDelegate d; | 8822 TestDelegate d; |
| 8704 { | 8823 { |
| 8705 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 8824 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8706 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 8825 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 8826 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8707 r->Start(); | 8827 r->Start(); |
| 8708 EXPECT_TRUE(r->is_pending()); | 8828 EXPECT_TRUE(r->is_pending()); |
| 8709 | 8829 |
| 8710 base::RunLoop().Run(); | 8830 base::RunLoop().Run(); |
| 8711 | 8831 |
| 8712 EXPECT_EQ(1, d.response_started_count()); | 8832 EXPECT_EQ(1, d.response_started_count()); |
| 8713 EXPECT_FALSE(d.received_data_before_response()); | 8833 EXPECT_FALSE(d.received_data_before_response()); |
| 8714 EXPECT_NE(0, d.bytes_received()); | 8834 EXPECT_NE(0, d.bytes_received()); |
| 8715 CheckSSLInfo(r->ssl_info()); | 8835 CheckSSLInfo(r->ssl_info()); |
| 8716 EXPECT_EQ(test_server.host_port_pair().host(), | 8836 EXPECT_EQ(test_server.host_port_pair().host(), |
| 8717 r->GetSocketAddress().host()); | 8837 r->GetSocketAddress().host()); |
| 8718 EXPECT_EQ(test_server.host_port_pair().port(), | 8838 EXPECT_EQ(test_server.host_port_pair().port(), |
| 8719 r->GetSocketAddress().port()); | 8839 r->GetSocketAddress().port()); |
| 8720 } | 8840 } |
| 8721 } | 8841 } |
| 8722 | 8842 |
| 8723 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { | 8843 TEST_F(HTTPSRequestTest, HTTPSMismatchedTest) { |
| 8724 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 8844 EmbeddedTestServer test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| 8725 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); | 8845 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_MISMATCHED_NAME); |
| 8726 test_server.AddDefaultHandlers( | 8846 test_server.AddDefaultHandlers( |
| 8727 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 8847 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 8728 ASSERT_TRUE(test_server.Start()); | 8848 ASSERT_TRUE(test_server.Start()); |
| 8729 | 8849 |
| 8730 bool err_allowed = true; | 8850 bool err_allowed = true; |
| 8731 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 8851 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 8732 TestDelegate d; | 8852 TestDelegate d; |
| 8733 { | 8853 { |
| 8734 d.set_allow_certificate_errors(err_allowed); | 8854 d.set_allow_certificate_errors(err_allowed); |
| 8735 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 8855 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8736 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 8856 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 8857 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8737 | 8858 |
| 8738 r->Start(); | 8859 r->Start(); |
| 8739 EXPECT_TRUE(r->is_pending()); | 8860 EXPECT_TRUE(r->is_pending()); |
| 8740 | 8861 |
| 8741 base::RunLoop().Run(); | 8862 base::RunLoop().Run(); |
| 8742 | 8863 |
| 8743 EXPECT_EQ(1, d.response_started_count()); | 8864 EXPECT_EQ(1, d.response_started_count()); |
| 8744 EXPECT_FALSE(d.received_data_before_response()); | 8865 EXPECT_FALSE(d.received_data_before_response()); |
| 8745 EXPECT_TRUE(d.have_certificate_errors()); | 8866 EXPECT_TRUE(d.have_certificate_errors()); |
| 8746 if (err_allowed) { | 8867 if (err_allowed) { |
| (...skipping 14 matching lines...) Expand all Loading... |
| 8761 ASSERT_TRUE(test_server.Start()); | 8882 ASSERT_TRUE(test_server.Start()); |
| 8762 | 8883 |
| 8763 // Iterate from false to true, just so that we do the opposite of the | 8884 // Iterate from false to true, just so that we do the opposite of the |
| 8764 // previous test in order to increase test coverage. | 8885 // previous test in order to increase test coverage. |
| 8765 bool err_allowed = false; | 8886 bool err_allowed = false; |
| 8766 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { | 8887 for (int i = 0; i < 2 ; i++, err_allowed = !err_allowed) { |
| 8767 TestDelegate d; | 8888 TestDelegate d; |
| 8768 { | 8889 { |
| 8769 d.set_allow_certificate_errors(err_allowed); | 8890 d.set_allow_certificate_errors(err_allowed); |
| 8770 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 8891 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8771 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 8892 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 8893 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8772 | 8894 |
| 8773 r->Start(); | 8895 r->Start(); |
| 8774 EXPECT_TRUE(r->is_pending()); | 8896 EXPECT_TRUE(r->is_pending()); |
| 8775 | 8897 |
| 8776 base::RunLoop().Run(); | 8898 base::RunLoop().Run(); |
| 8777 | 8899 |
| 8778 EXPECT_EQ(1, d.response_started_count()); | 8900 EXPECT_EQ(1, d.response_started_count()); |
| 8779 EXPECT_FALSE(d.received_data_before_response()); | 8901 EXPECT_FALSE(d.received_data_before_response()); |
| 8780 EXPECT_TRUE(d.have_certificate_errors()); | 8902 EXPECT_TRUE(d.have_certificate_errors()); |
| 8781 if (err_allowed) { | 8903 if (err_allowed) { |
| (...skipping 29 matching lines...) Expand all Loading... |
| 8811 context.set_network_delegate(&network_delegate); | 8933 context.set_network_delegate(&network_delegate); |
| 8812 context.set_host_resolver(&host_resolver); | 8934 context.set_host_resolver(&host_resolver); |
| 8813 TransportSecurityState transport_security_state; | 8935 TransportSecurityState transport_security_state; |
| 8814 context.set_transport_security_state(&transport_security_state); | 8936 context.set_transport_security_state(&transport_security_state); |
| 8815 context.Init(); | 8937 context.Init(); |
| 8816 | 8938 |
| 8817 TestDelegate d; | 8939 TestDelegate d; |
| 8818 std::unique_ptr<URLRequest> r(context.CreateRequest( | 8940 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 8819 GURL(base::StringPrintf("https://www.google.com:%d", | 8941 GURL(base::StringPrintf("https://www.google.com:%d", |
| 8820 test_server.host_port_pair().port())), | 8942 test_server.host_port_pair().port())), |
| 8821 DEFAULT_PRIORITY, &d)); | 8943 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8822 | 8944 |
| 8823 r->Start(); | 8945 r->Start(); |
| 8824 EXPECT_TRUE(r->is_pending()); | 8946 EXPECT_TRUE(r->is_pending()); |
| 8825 | 8947 |
| 8826 base::RunLoop().Run(); | 8948 base::RunLoop().Run(); |
| 8827 | 8949 |
| 8828 EXPECT_EQ(1, d.response_started_count()); | 8950 EXPECT_EQ(1, d.response_started_count()); |
| 8829 EXPECT_FALSE(d.received_data_before_response()); | 8951 EXPECT_FALSE(d.received_data_before_response()); |
| 8830 EXPECT_TRUE(d.have_certificate_errors()); | 8952 EXPECT_TRUE(d.have_certificate_errors()); |
| 8831 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 8953 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8864 TransportSecurityState::PKPState dynamic_pkp_state; | 8986 TransportSecurityState::PKPState dynamic_pkp_state; |
| 8865 EXPECT_FALSE(transport_security_state.GetDynamicSTSState("www.google.com", | 8987 EXPECT_FALSE(transport_security_state.GetDynamicSTSState("www.google.com", |
| 8866 &dynamic_sts_state)); | 8988 &dynamic_sts_state)); |
| 8867 EXPECT_FALSE(transport_security_state.GetDynamicPKPState("www.google.com", | 8989 EXPECT_FALSE(transport_security_state.GetDynamicPKPState("www.google.com", |
| 8868 &dynamic_pkp_state)); | 8990 &dynamic_pkp_state)); |
| 8869 | 8991 |
| 8870 TestDelegate d; | 8992 TestDelegate d; |
| 8871 std::unique_ptr<URLRequest> r(context.CreateRequest( | 8993 std::unique_ptr<URLRequest> r(context.CreateRequest( |
| 8872 GURL(base::StringPrintf("https://www.google.com:%d", | 8994 GURL(base::StringPrintf("https://www.google.com:%d", |
| 8873 test_server.host_port_pair().port())), | 8995 test_server.host_port_pair().port())), |
| 8874 DEFAULT_PRIORITY, &d)); | 8996 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8875 | 8997 |
| 8876 r->Start(); | 8998 r->Start(); |
| 8877 EXPECT_TRUE(r->is_pending()); | 8999 EXPECT_TRUE(r->is_pending()); |
| 8878 | 9000 |
| 8879 base::RunLoop().Run(); | 9001 base::RunLoop().Run(); |
| 8880 | 9002 |
| 8881 EXPECT_EQ(1, d.response_started_count()); | 9003 EXPECT_EQ(1, d.response_started_count()); |
| 8882 EXPECT_FALSE(d.received_data_before_response()); | 9004 EXPECT_FALSE(d.received_data_before_response()); |
| 8883 EXPECT_TRUE(d.have_certificate_errors()); | 9005 EXPECT_TRUE(d.have_certificate_errors()); |
| 8884 EXPECT_TRUE(d.certificate_errors_are_fatal()); | 9006 EXPECT_TRUE(d.certificate_errors_are_fatal()); |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8937 context.Init(); | 9059 context.Init(); |
| 8938 | 9060 |
| 8939 TestDelegate d; | 9061 TestDelegate d; |
| 8940 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will | 9062 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will |
| 8941 // cause a certificate error. Ignore the error. | 9063 // cause a certificate error. Ignore the error. |
| 8942 d.set_allow_certificate_errors(true); | 9064 d.set_allow_certificate_errors(true); |
| 8943 | 9065 |
| 8944 std::unique_ptr<URLRequest> req(context.CreateRequest( | 9066 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 8945 GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", | 9067 GURL(base::StringPrintf("http://www.somewhere.com:%d/echo", |
| 8946 test_server.host_port_pair().port())), | 9068 test_server.host_port_pair().port())), |
| 8947 DEFAULT_PRIORITY, &d)); | 9069 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 8948 req->set_method("POST"); | 9070 req->set_method("POST"); |
| 8949 req->set_upload(CreateSimpleUploadData(kData)); | 9071 req->set_upload(CreateSimpleUploadData(kData)); |
| 8950 | 9072 |
| 8951 req->Start(); | 9073 req->Start(); |
| 8952 base::RunLoop().Run(); | 9074 base::RunLoop().Run(); |
| 8953 | 9075 |
| 8954 EXPECT_EQ("https", req->url().scheme()); | 9076 EXPECT_EQ("https", req->url().scheme()); |
| 8955 EXPECT_EQ("POST", req->method()); | 9077 EXPECT_EQ("POST", req->method()); |
| 8956 EXPECT_EQ(kData, d.data_received()); | 9078 EXPECT_EQ(kData, d.data_received()); |
| 8957 | 9079 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8996 test_server.host_port_pair().port())); | 9118 test_server.host_port_pair().port())); |
| 8997 url::Replacements<char> replacements; | 9119 url::Replacements<char> replacements; |
| 8998 const char kNewScheme[] = "https"; | 9120 const char kNewScheme[] = "https"; |
| 8999 replacements.SetScheme(kNewScheme, url::Component(0, strlen(kNewScheme))); | 9121 replacements.SetScheme(kNewScheme, url::Component(0, strlen(kNewScheme))); |
| 9000 GURL hsts_https_url = hsts_http_url.ReplaceComponents(replacements); | 9122 GURL hsts_https_url = hsts_http_url.ReplaceComponents(replacements); |
| 9001 | 9123 |
| 9002 TestDelegate d; | 9124 TestDelegate d; |
| 9003 // Quit on redirect to allow response header inspection upon redirect. | 9125 // Quit on redirect to allow response header inspection upon redirect. |
| 9004 d.set_quit_on_redirect(true); | 9126 d.set_quit_on_redirect(true); |
| 9005 | 9127 |
| 9006 std::unique_ptr<URLRequest> req( | 9128 std::unique_ptr<URLRequest> req(context.CreateRequest( |
| 9007 context.CreateRequest(hsts_http_url, DEFAULT_PRIORITY, &d)); | 9129 hsts_http_url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9008 // Set Origin header to simulate a cross-origin request. | 9130 // Set Origin header to simulate a cross-origin request. |
| 9009 HttpRequestHeaders request_headers; | 9131 HttpRequestHeaders request_headers; |
| 9010 request_headers.SetHeader("Origin", kOriginHeaderValue); | 9132 request_headers.SetHeader("Origin", kOriginHeaderValue); |
| 9011 req->SetExtraRequestHeaders(request_headers); | 9133 req->SetExtraRequestHeaders(request_headers); |
| 9012 | 9134 |
| 9013 req->Start(); | 9135 req->Start(); |
| 9014 base::RunLoop().Run(); | 9136 base::RunLoop().Run(); |
| 9015 | 9137 |
| 9016 EXPECT_EQ(1, d.received_redirect_count()); | 9138 EXPECT_EQ(1, d.received_redirect_count()); |
| 9017 | 9139 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9057 ssl_config.client_cert_type = | 9179 ssl_config.client_cert_type = |
| 9058 SSLServerConfig::ClientCertType::OPTIONAL_CLIENT_CERT; | 9180 SSLServerConfig::ClientCertType::OPTIONAL_CLIENT_CERT; |
| 9059 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, ssl_config); | 9181 test_server.SetSSLConfig(net::EmbeddedTestServer::CERT_OK, ssl_config); |
| 9060 test_server.AddDefaultHandlers( | 9182 test_server.AddDefaultHandlers( |
| 9061 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 9183 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 9062 ASSERT_TRUE(test_server.Start()); | 9184 ASSERT_TRUE(test_server.Start()); |
| 9063 | 9185 |
| 9064 SSLClientAuthTestDelegate d; | 9186 SSLClientAuthTestDelegate d; |
| 9065 { | 9187 { |
| 9066 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 9188 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9067 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 9189 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 9190 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9068 | 9191 |
| 9069 r->Start(); | 9192 r->Start(); |
| 9070 EXPECT_TRUE(r->is_pending()); | 9193 EXPECT_TRUE(r->is_pending()); |
| 9071 | 9194 |
| 9072 base::RunLoop().Run(); | 9195 base::RunLoop().Run(); |
| 9073 | 9196 |
| 9074 EXPECT_EQ(1, d.on_certificate_requested_count()); | 9197 EXPECT_EQ(1, d.on_certificate_requested_count()); |
| 9075 EXPECT_FALSE(d.received_data_before_response()); | 9198 EXPECT_FALSE(d.received_data_before_response()); |
| 9076 EXPECT_EQ(0, d.bytes_received()); | 9199 EXPECT_EQ(0, d.bytes_received()); |
| 9077 | 9200 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 9097 SpawnedTestServer::TYPE_HTTPS, | 9220 SpawnedTestServer::TYPE_HTTPS, |
| 9098 ssl_options, | 9221 ssl_options, |
| 9099 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 9222 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 9100 ASSERT_TRUE(test_server.Start()); | 9223 ASSERT_TRUE(test_server.Start()); |
| 9101 | 9224 |
| 9102 SSLClientSocket::ClearSessionCache(); | 9225 SSLClientSocket::ClearSessionCache(); |
| 9103 | 9226 |
| 9104 { | 9227 { |
| 9105 TestDelegate d; | 9228 TestDelegate d; |
| 9106 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 9229 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9107 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d)); | 9230 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, |
| 9231 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9108 | 9232 |
| 9109 r->Start(); | 9233 r->Start(); |
| 9110 EXPECT_TRUE(r->is_pending()); | 9234 EXPECT_TRUE(r->is_pending()); |
| 9111 | 9235 |
| 9112 base::RunLoop().Run(); | 9236 base::RunLoop().Run(); |
| 9113 | 9237 |
| 9114 EXPECT_EQ(1, d.response_started_count()); | 9238 EXPECT_EQ(1, d.response_started_count()); |
| 9115 } | 9239 } |
| 9116 | 9240 |
| 9117 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 9241 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> |
| 9118 CloseAllConnections(); | 9242 CloseAllConnections(); |
| 9119 | 9243 |
| 9120 { | 9244 { |
| 9121 TestDelegate d; | 9245 TestDelegate d; |
| 9122 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 9246 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9123 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d)); | 9247 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, |
| 9248 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9124 | 9249 |
| 9125 r->Start(); | 9250 r->Start(); |
| 9126 EXPECT_TRUE(r->is_pending()); | 9251 EXPECT_TRUE(r->is_pending()); |
| 9127 | 9252 |
| 9128 base::RunLoop().Run(); | 9253 base::RunLoop().Run(); |
| 9129 | 9254 |
| 9130 // The response will look like; | 9255 // The response will look like; |
| 9131 // insert abc | 9256 // insert abc |
| 9132 // lookup abc | 9257 // lookup abc |
| 9133 // insert xyz | 9258 // insert xyz |
| (...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9188 SpawnedTestServer::TYPE_HTTPS, | 9313 SpawnedTestServer::TYPE_HTTPS, |
| 9189 ssl_options, | 9314 ssl_options, |
| 9190 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 9315 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 9191 ASSERT_TRUE(test_server.Start()); | 9316 ASSERT_TRUE(test_server.Start()); |
| 9192 | 9317 |
| 9193 SSLClientSocket::ClearSessionCache(); | 9318 SSLClientSocket::ClearSessionCache(); |
| 9194 | 9319 |
| 9195 { | 9320 { |
| 9196 TestDelegate d; | 9321 TestDelegate d; |
| 9197 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 9322 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9198 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d)); | 9323 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, |
| 9324 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9199 | 9325 |
| 9200 r->Start(); | 9326 r->Start(); |
| 9201 EXPECT_TRUE(r->is_pending()); | 9327 EXPECT_TRUE(r->is_pending()); |
| 9202 | 9328 |
| 9203 base::RunLoop().Run(); | 9329 base::RunLoop().Run(); |
| 9204 | 9330 |
| 9205 EXPECT_EQ(1, d.response_started_count()); | 9331 EXPECT_EQ(1, d.response_started_count()); |
| 9206 } | 9332 } |
| 9207 | 9333 |
| 9208 // Now create a new HttpCache with a different ssl_session_cache_shard value. | 9334 // Now create a new HttpCache with a different ssl_session_cache_shard value. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 9222 HttpNetworkSession network_session(params); | 9348 HttpNetworkSession network_session(params); |
| 9223 std::unique_ptr<HttpCache> cache( | 9349 std::unique_ptr<HttpCache> cache( |
| 9224 new HttpCache(&network_session, HttpCache::DefaultBackend::InMemory(0), | 9350 new HttpCache(&network_session, HttpCache::DefaultBackend::InMemory(0), |
| 9225 false /* is_main_cache */)); | 9351 false /* is_main_cache */)); |
| 9226 | 9352 |
| 9227 default_context_.set_http_transaction_factory(cache.get()); | 9353 default_context_.set_http_transaction_factory(cache.get()); |
| 9228 | 9354 |
| 9229 { | 9355 { |
| 9230 TestDelegate d; | 9356 TestDelegate d; |
| 9231 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 9357 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9232 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d)); | 9358 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, |
| 9359 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9233 | 9360 |
| 9234 r->Start(); | 9361 r->Start(); |
| 9235 EXPECT_TRUE(r->is_pending()); | 9362 EXPECT_TRUE(r->is_pending()); |
| 9236 | 9363 |
| 9237 base::RunLoop().Run(); | 9364 base::RunLoop().Run(); |
| 9238 | 9365 |
| 9239 // The response will look like; | 9366 // The response will look like; |
| 9240 // insert abc | 9367 // insert abc |
| 9241 // insert xyz | 9368 // insert xyz |
| 9242 // | 9369 // |
| (...skipping 27 matching lines...) Expand all Loading... |
| 9270 context_.Init(); | 9397 context_.Init(); |
| 9271 delegate_.set_allow_certificate_errors(true); | 9398 delegate_.set_allow_certificate_errors(true); |
| 9272 | 9399 |
| 9273 SpawnedTestServer test_server( | 9400 SpawnedTestServer test_server( |
| 9274 SpawnedTestServer::TYPE_HTTPS, | 9401 SpawnedTestServer::TYPE_HTTPS, |
| 9275 ssl_options, | 9402 ssl_options, |
| 9276 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 9403 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 9277 ASSERT_TRUE(test_server.Start()); | 9404 ASSERT_TRUE(test_server.Start()); |
| 9278 | 9405 |
| 9279 request_ = context_.CreateRequest(test_server.GetURL("/"), DEFAULT_PRIORITY, | 9406 request_ = context_.CreateRequest(test_server.GetURL("/"), DEFAULT_PRIORITY, |
| 9280 &delegate_); | 9407 &delegate_, TRAFFIC_ANNOTATION_FOR_TESTS); |
| 9281 request_->Start(); | 9408 request_->Start(); |
| 9282 | 9409 |
| 9283 base::RunLoop().Run(); | 9410 base::RunLoop().Run(); |
| 9284 } | 9411 } |
| 9285 | 9412 |
| 9286 void ExpectConnection(int version) { | 9413 void ExpectConnection(int version) { |
| 9287 EXPECT_EQ(1, delegate_.response_started_count()); | 9414 EXPECT_EQ(1, delegate_.response_started_count()); |
| 9288 EXPECT_NE(0, delegate_.bytes_received()); | 9415 EXPECT_NE(0, delegate_.bytes_received()); |
| 9289 EXPECT_EQ(version, SSLConnectionStatusToVersion( | 9416 EXPECT_EQ(version, SSLConnectionStatusToVersion( |
| 9290 request_->ssl_info().connection_status)); | 9417 request_->ssl_info().connection_status)); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9382 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 9509 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 9383 ASSERT_TRUE(test_server.Start()); | 9510 ASSERT_TRUE(test_server.Start()); |
| 9384 | 9511 |
| 9385 SSLClientSocket::ClearSessionCache(); | 9512 SSLClientSocket::ClearSessionCache(); |
| 9386 | 9513 |
| 9387 // Simulate the certificate being expired and attempt a connection. | 9514 // Simulate the certificate being expired and attempt a connection. |
| 9388 cert_verifier_.set_default_result(ERR_CERT_DATE_INVALID); | 9515 cert_verifier_.set_default_result(ERR_CERT_DATE_INVALID); |
| 9389 { | 9516 { |
| 9390 TestDelegate d; | 9517 TestDelegate d; |
| 9391 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 9518 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9392 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d)); | 9519 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, |
| 9520 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9393 | 9521 |
| 9394 r->Start(); | 9522 r->Start(); |
| 9395 EXPECT_TRUE(r->is_pending()); | 9523 EXPECT_TRUE(r->is_pending()); |
| 9396 | 9524 |
| 9397 base::RunLoop().Run(); | 9525 base::RunLoop().Run(); |
| 9398 | 9526 |
| 9399 EXPECT_EQ(1, d.response_started_count()); | 9527 EXPECT_EQ(1, d.response_started_count()); |
| 9400 } | 9528 } |
| 9401 | 9529 |
| 9402 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> | 9530 reinterpret_cast<HttpCache*>(default_context_.http_transaction_factory())-> |
| 9403 CloseAllConnections(); | 9531 CloseAllConnections(); |
| 9404 | 9532 |
| 9405 // Now change the certificate to be acceptable (so that the response is | 9533 // Now change the certificate to be acceptable (so that the response is |
| 9406 // loaded), and ensure that no session id is presented to the peer. | 9534 // loaded), and ensure that no session id is presented to the peer. |
| 9407 cert_verifier_.set_default_result(OK); | 9535 cert_verifier_.set_default_result(OK); |
| 9408 { | 9536 { |
| 9409 TestDelegate d; | 9537 TestDelegate d; |
| 9410 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 9538 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9411 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d)); | 9539 test_server.GetURL("ssl-session-cache"), DEFAULT_PRIORITY, &d, |
| 9540 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9412 | 9541 |
| 9413 r->Start(); | 9542 r->Start(); |
| 9414 EXPECT_TRUE(r->is_pending()); | 9543 EXPECT_TRUE(r->is_pending()); |
| 9415 | 9544 |
| 9416 base::RunLoop().Run(); | 9545 base::RunLoop().Run(); |
| 9417 | 9546 |
| 9418 // The response will look like; | 9547 // The response will look like; |
| 9419 // insert abc | 9548 // insert abc |
| 9420 // insert xyz | 9549 // insert xyz |
| 9421 // | 9550 // |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9486 // Always overwrite |out_ssl_info|. | 9615 // Always overwrite |out_ssl_info|. |
| 9487 out_ssl_info->Reset(); | 9616 out_ssl_info->Reset(); |
| 9488 | 9617 |
| 9489 SpawnedTestServer test_server( | 9618 SpawnedTestServer test_server( |
| 9490 SpawnedTestServer::TYPE_HTTPS, | 9619 SpawnedTestServer::TYPE_HTTPS, |
| 9491 ssl_options, | 9620 ssl_options, |
| 9492 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 9621 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 9493 ASSERT_TRUE(test_server.Start()); | 9622 ASSERT_TRUE(test_server.Start()); |
| 9494 | 9623 |
| 9495 delegate->set_allow_certificate_errors(true); | 9624 delegate->set_allow_certificate_errors(true); |
| 9496 std::unique_ptr<URLRequest> r(context_.CreateRequest( | 9625 std::unique_ptr<URLRequest> r( |
| 9497 test_server.GetURL("/"), DEFAULT_PRIORITY, delegate)); | 9626 context_.CreateRequest(test_server.GetURL("/"), DEFAULT_PRIORITY, |
| 9627 delegate, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9498 r->Start(); | 9628 r->Start(); |
| 9499 | 9629 |
| 9500 base::RunLoop().Run(); | 9630 base::RunLoop().Run(); |
| 9501 EXPECT_EQ(1, delegate->response_started_count()); | 9631 EXPECT_EQ(1, delegate->response_started_count()); |
| 9502 | 9632 |
| 9503 *out_ssl_info = r->ssl_info(); | 9633 *out_ssl_info = r->ssl_info(); |
| 9504 } | 9634 } |
| 9505 | 9635 |
| 9506 void DoConnection(const SpawnedTestServer::SSLOptions& ssl_options, | 9636 void DoConnection(const SpawnedTestServer::SSLOptions& ssl_options, |
| 9507 CertStatus* out_cert_status) { | 9637 CertStatus* out_cert_status) { |
| (...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9777 context.set_network_delegate(&network_delegate); | 9907 context.set_network_delegate(&network_delegate); |
| 9778 context.set_cert_verifier(&cert_verifier); | 9908 context.set_cert_verifier(&cert_verifier); |
| 9779 context.Init(); | 9909 context.Init(); |
| 9780 | 9910 |
| 9781 // Now send a request to trigger the violation. | 9911 // Now send a request to trigger the violation. |
| 9782 TestDelegate d; | 9912 TestDelegate d; |
| 9783 GURL url = https_test_server.GetURL("/"); | 9913 GURL url = https_test_server.GetURL("/"); |
| 9784 GURL::Replacements replace_host; | 9914 GURL::Replacements replace_host; |
| 9785 replace_host.SetHostStr(kExpectStapleStaticHostname); | 9915 replace_host.SetHostStr(kExpectStapleStaticHostname); |
| 9786 url = url.ReplaceComponents(replace_host); | 9916 url = url.ReplaceComponents(replace_host); |
| 9787 std::unique_ptr<URLRequest> violating_request( | 9917 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( |
| 9788 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 9918 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9789 violating_request->Start(); | 9919 violating_request->Start(); |
| 9790 base::RunLoop().Run(); | 9920 base::RunLoop().Run(); |
| 9791 | 9921 |
| 9792 // Confirm a report was sent. | 9922 // Confirm a report was sent. |
| 9793 EXPECT_FALSE(mock_report_sender.latest_report().empty()); | 9923 EXPECT_FALSE(mock_report_sender.latest_report().empty()); |
| 9794 EXPECT_EQ(GURL(kExpectStapleReportURI), | 9924 EXPECT_EQ(GURL(kExpectStapleReportURI), |
| 9795 mock_report_sender.latest_report_uri()); | 9925 mock_report_sender.latest_report_uri()); |
| 9796 } | 9926 } |
| 9797 | 9927 |
| 9798 // Tests that Expect-Staple reports are not sent for connections on which there | 9928 // Tests that Expect-Staple reports are not sent for connections on which there |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9837 context.Init(); | 9967 context.Init(); |
| 9838 | 9968 |
| 9839 // Make a connection to |kExpectStapleStaticHostname|. Because the | 9969 // Make a connection to |kExpectStapleStaticHostname|. Because the |
| 9840 // |verify_result| used with the |cert_verifier| will indicate a certificate | 9970 // |verify_result| used with the |cert_verifier| will indicate a certificate |
| 9841 // error, an Expect-Staple report should not be sent. | 9971 // error, an Expect-Staple report should not be sent. |
| 9842 TestDelegate d; | 9972 TestDelegate d; |
| 9843 GURL url = https_test_server.GetURL("/"); | 9973 GURL url = https_test_server.GetURL("/"); |
| 9844 GURL::Replacements replace_host; | 9974 GURL::Replacements replace_host; |
| 9845 replace_host.SetHostStr(kExpectStapleStaticHostname); | 9975 replace_host.SetHostStr(kExpectStapleStaticHostname); |
| 9846 url = url.ReplaceComponents(replace_host); | 9976 url = url.ReplaceComponents(replace_host); |
| 9847 std::unique_ptr<URLRequest> violating_request( | 9977 std::unique_ptr<URLRequest> violating_request(context.CreateRequest( |
| 9848 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 9978 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9849 violating_request->Start(); | 9979 violating_request->Start(); |
| 9850 base::RunLoop().Run(); | 9980 base::RunLoop().Run(); |
| 9851 | 9981 |
| 9852 // Confirm a report was not sent. | 9982 // Confirm a report was not sent. |
| 9853 EXPECT_TRUE(mock_report_sender.latest_report().empty()); | 9983 EXPECT_TRUE(mock_report_sender.latest_report().empty()); |
| 9854 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); | 9984 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); |
| 9855 } | 9985 } |
| 9856 | 9986 |
| 9857 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) { | 9987 TEST_F(HTTPSOCSPTest, ExpectStapleReportNotSentOnValid) { |
| 9858 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); | 9988 EmbeddedTestServer https_test_server(net::EmbeddedTestServer::TYPE_HTTPS); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 9889 context.set_network_delegate(&network_delegate); | 10019 context.set_network_delegate(&network_delegate); |
| 9890 context.set_cert_verifier(&cert_verifier); | 10020 context.set_cert_verifier(&cert_verifier); |
| 9891 context.Init(); | 10021 context.Init(); |
| 9892 | 10022 |
| 9893 // This request should not not trigger an Expect-Staple violation. | 10023 // This request should not not trigger an Expect-Staple violation. |
| 9894 TestDelegate d; | 10024 TestDelegate d; |
| 9895 GURL url = https_test_server.GetURL("/"); | 10025 GURL url = https_test_server.GetURL("/"); |
| 9896 GURL::Replacements replace_host; | 10026 GURL::Replacements replace_host; |
| 9897 replace_host.SetHostStr(kExpectStapleStaticHostname); | 10027 replace_host.SetHostStr(kExpectStapleStaticHostname); |
| 9898 url = url.ReplaceComponents(replace_host); | 10028 url = url.ReplaceComponents(replace_host); |
| 9899 std::unique_ptr<URLRequest> ok_request( | 10029 std::unique_ptr<URLRequest> ok_request(context.CreateRequest( |
| 9900 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 10030 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9901 ok_request->Start(); | 10031 ok_request->Start(); |
| 9902 base::RunLoop().Run(); | 10032 base::RunLoop().Run(); |
| 9903 | 10033 |
| 9904 // Check that no report was sent. | 10034 // Check that no report was sent. |
| 9905 EXPECT_TRUE(mock_report_sender.latest_report().empty()); | 10035 EXPECT_TRUE(mock_report_sender.latest_report().empty()); |
| 9906 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); | 10036 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); |
| 9907 } | 10037 } |
| 9908 | 10038 |
| 9909 // Tests that an Expect-Staple report is not sent when OCSP details are not | 10039 // Tests that an Expect-Staple report is not sent when OCSP details are not |
| 9910 // checked on the connection. | 10040 // checked on the connection. |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9948 | 10078 |
| 9949 // Make a connection to |kExpectStapleStaticHostname|. Because the | 10079 // Make a connection to |kExpectStapleStaticHostname|. Because the |
| 9950 // |verify_result| used with the |cert_verifier| will indicate that OCSP | 10080 // |verify_result| used with the |cert_verifier| will indicate that OCSP |
| 9951 // stapling details were not checked on the connection, an Expect-Staple | 10081 // stapling details were not checked on the connection, an Expect-Staple |
| 9952 // report should not be sent. | 10082 // report should not be sent. |
| 9953 TestDelegate d; | 10083 TestDelegate d; |
| 9954 GURL url = https_test_server.GetURL("/"); | 10084 GURL url = https_test_server.GetURL("/"); |
| 9955 GURL::Replacements replace_host; | 10085 GURL::Replacements replace_host; |
| 9956 replace_host.SetHostStr(kExpectStapleStaticHostname); | 10086 replace_host.SetHostStr(kExpectStapleStaticHostname); |
| 9957 url = url.ReplaceComponents(replace_host); | 10087 url = url.ReplaceComponents(replace_host); |
| 9958 std::unique_ptr<URLRequest> ok_request( | 10088 std::unique_ptr<URLRequest> ok_request(context.CreateRequest( |
| 9959 context.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 10089 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 9960 ok_request->Start(); | 10090 ok_request->Start(); |
| 9961 base::RunLoop().Run(); | 10091 base::RunLoop().Run(); |
| 9962 | 10092 |
| 9963 // Check that no report was sent. | 10093 // Check that no report was sent. |
| 9964 EXPECT_TRUE(mock_report_sender.latest_report().empty()); | 10094 EXPECT_TRUE(mock_report_sender.latest_report().empty()); |
| 9965 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); | 10095 EXPECT_EQ(GURL(), mock_report_sender.latest_report_uri()); |
| 9966 } | 10096 } |
| 9967 | 10097 |
| 9968 static const struct OCSPVerifyTestData { | 10098 static const struct OCSPVerifyTestData { |
| 9969 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses; | 10099 std::vector<SpawnedTestServer::SSLOptions::OCSPSingleResponse> ocsp_responses; |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10248 SpawnedTestServer::SSLOptions ssl_options( | 10378 SpawnedTestServer::SSLOptions ssl_options( |
| 10249 SpawnedTestServer::SSLOptions::CERT_AUTO_AIA_INTERMEDIATE); | 10379 SpawnedTestServer::SSLOptions::CERT_AUTO_AIA_INTERMEDIATE); |
| 10250 SpawnedTestServer test_server( | 10380 SpawnedTestServer test_server( |
| 10251 SpawnedTestServer::TYPE_HTTPS, ssl_options, | 10381 SpawnedTestServer::TYPE_HTTPS, ssl_options, |
| 10252 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); | 10382 base::FilePath(FILE_PATH_LITERAL("net/data/ssl"))); |
| 10253 ASSERT_TRUE(test_server.Start()); | 10383 ASSERT_TRUE(test_server.Start()); |
| 10254 | 10384 |
| 10255 TestDelegate d; | 10385 TestDelegate d; |
| 10256 d.set_allow_certificate_errors(true); | 10386 d.set_allow_certificate_errors(true); |
| 10257 std::unique_ptr<URLRequest> r(context_.CreateRequest( | 10387 std::unique_ptr<URLRequest> r(context_.CreateRequest( |
| 10258 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d)); | 10388 test_server.GetURL("/defaultresponse"), DEFAULT_PRIORITY, &d, |
| 10389 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10259 | 10390 |
| 10260 r->Start(); | 10391 r->Start(); |
| 10261 EXPECT_TRUE(r->is_pending()); | 10392 EXPECT_TRUE(r->is_pending()); |
| 10262 | 10393 |
| 10263 base::RunLoop().Run(); | 10394 base::RunLoop().Run(); |
| 10264 | 10395 |
| 10265 EXPECT_EQ(1, d.response_started_count()); | 10396 EXPECT_EQ(1, d.response_started_count()); |
| 10266 | 10397 |
| 10267 CertStatus cert_status = r->ssl_info().cert_status; | 10398 CertStatus cert_status = r->ssl_info().cert_status; |
| 10268 if (SystemSupportsAIA()) { | 10399 if (SystemSupportsAIA()) { |
| (...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 10601 | 10732 |
| 10602 SpawnedTestServer ftp_test_server_; | 10733 SpawnedTestServer ftp_test_server_; |
| 10603 }; | 10734 }; |
| 10604 | 10735 |
| 10605 // Make sure an FTP request using an unsafe ports fails. | 10736 // Make sure an FTP request using an unsafe ports fails. |
| 10606 TEST_F(URLRequestTestFTP, UnsafePort) { | 10737 TEST_F(URLRequestTestFTP, UnsafePort) { |
| 10607 GURL url("ftp://127.0.0.1:7"); | 10738 GURL url("ftp://127.0.0.1:7"); |
| 10608 | 10739 |
| 10609 TestDelegate d; | 10740 TestDelegate d; |
| 10610 { | 10741 { |
| 10611 std::unique_ptr<URLRequest> r( | 10742 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10612 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 10743 url, DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10613 r->Start(); | 10744 r->Start(); |
| 10614 EXPECT_TRUE(r->is_pending()); | 10745 EXPECT_TRUE(r->is_pending()); |
| 10615 | 10746 |
| 10616 base::RunLoop().Run(); | 10747 base::RunLoop().Run(); |
| 10617 | 10748 |
| 10618 EXPECT_FALSE(r->is_pending()); | 10749 EXPECT_FALSE(r->is_pending()); |
| 10619 EXPECT_EQ(ERR_UNSAFE_PORT, d.request_status()); | 10750 EXPECT_EQ(ERR_UNSAFE_PORT, d.request_status()); |
| 10620 } | 10751 } |
| 10621 } | 10752 } |
| 10622 | 10753 |
| 10623 TEST_F(URLRequestTestFTP, FTPDirectoryListing) { | 10754 TEST_F(URLRequestTestFTP, FTPDirectoryListing) { |
| 10624 ASSERT_TRUE(ftp_test_server_.Start()); | 10755 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10625 | 10756 |
| 10626 TestDelegate d; | 10757 TestDelegate d; |
| 10627 { | 10758 { |
| 10628 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10759 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10629 ftp_test_server_.GetURL("/"), DEFAULT_PRIORITY, &d)); | 10760 ftp_test_server_.GetURL("/"), DEFAULT_PRIORITY, &d, |
| 10761 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10630 r->Start(); | 10762 r->Start(); |
| 10631 EXPECT_TRUE(r->is_pending()); | 10763 EXPECT_TRUE(r->is_pending()); |
| 10632 | 10764 |
| 10633 base::RunLoop().Run(); | 10765 base::RunLoop().Run(); |
| 10634 | 10766 |
| 10635 EXPECT_FALSE(r->is_pending()); | 10767 EXPECT_FALSE(r->is_pending()); |
| 10636 EXPECT_EQ(1, d.response_started_count()); | 10768 EXPECT_EQ(1, d.response_started_count()); |
| 10637 EXPECT_FALSE(d.received_data_before_response()); | 10769 EXPECT_FALSE(d.received_data_before_response()); |
| 10638 EXPECT_LT(0, d.bytes_received()); | 10770 EXPECT_LT(0, d.bytes_received()); |
| 10639 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), | 10771 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), |
| 10640 r->GetSocketAddress().host()); | 10772 r->GetSocketAddress().host()); |
| 10641 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), | 10773 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), |
| 10642 r->GetSocketAddress().port()); | 10774 r->GetSocketAddress().port()); |
| 10643 } | 10775 } |
| 10644 } | 10776 } |
| 10645 | 10777 |
| 10646 TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) { | 10778 TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) { |
| 10647 ASSERT_TRUE(ftp_test_server_.Start()); | 10779 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10648 | 10780 |
| 10649 TestDelegate d; | 10781 TestDelegate d; |
| 10650 { | 10782 { |
| 10651 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10783 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10652 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, &d)); | 10784 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, &d, |
| 10785 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10653 r->Start(); | 10786 r->Start(); |
| 10654 EXPECT_TRUE(r->is_pending()); | 10787 EXPECT_TRUE(r->is_pending()); |
| 10655 | 10788 |
| 10656 base::RunLoop().Run(); | 10789 base::RunLoop().Run(); |
| 10657 | 10790 |
| 10658 EXPECT_FALSE(r->is_pending()); | 10791 EXPECT_FALSE(r->is_pending()); |
| 10659 EXPECT_EQ(1, d.response_started_count()); | 10792 EXPECT_EQ(1, d.response_started_count()); |
| 10660 EXPECT_FALSE(d.received_data_before_response()); | 10793 EXPECT_FALSE(d.received_data_before_response()); |
| 10661 EXPECT_EQ(GetTestFileContents(), d.data_received()); | 10794 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 10662 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), | 10795 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), |
| 10663 r->GetSocketAddress().host()); | 10796 r->GetSocketAddress().host()); |
| 10664 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), | 10797 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), |
| 10665 r->GetSocketAddress().port()); | 10798 r->GetSocketAddress().port()); |
| 10666 } | 10799 } |
| 10667 } | 10800 } |
| 10668 | 10801 |
| 10669 TEST_F(URLRequestTestFTP, FTPGetTest) { | 10802 TEST_F(URLRequestTestFTP, FTPGetTest) { |
| 10670 ASSERT_TRUE(ftp_test_server_.Start()); | 10803 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10671 | 10804 |
| 10672 TestDelegate d; | 10805 TestDelegate d; |
| 10673 { | 10806 { |
| 10674 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10807 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10675 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", | 10808 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 10676 "chrome"), | 10809 "chrome"), |
| 10677 DEFAULT_PRIORITY, &d)); | 10810 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10678 r->Start(); | 10811 r->Start(); |
| 10679 EXPECT_TRUE(r->is_pending()); | 10812 EXPECT_TRUE(r->is_pending()); |
| 10680 | 10813 |
| 10681 base::RunLoop().Run(); | 10814 base::RunLoop().Run(); |
| 10682 | 10815 |
| 10683 EXPECT_FALSE(r->is_pending()); | 10816 EXPECT_FALSE(r->is_pending()); |
| 10684 EXPECT_EQ(1, d.response_started_count()); | 10817 EXPECT_EQ(1, d.response_started_count()); |
| 10685 EXPECT_FALSE(d.received_data_before_response()); | 10818 EXPECT_FALSE(d.received_data_before_response()); |
| 10686 EXPECT_EQ(GetTestFileContents(), d.data_received()); | 10819 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 10687 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), | 10820 EXPECT_EQ(ftp_test_server_.host_port_pair().host(), |
| 10688 r->GetSocketAddress().host()); | 10821 r->GetSocketAddress().host()); |
| 10689 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), | 10822 EXPECT_EQ(ftp_test_server_.host_port_pair().port(), |
| 10690 r->GetSocketAddress().port()); | 10823 r->GetSocketAddress().port()); |
| 10691 | 10824 |
| 10692 LoadTimingInfo load_timing_info; | 10825 LoadTimingInfo load_timing_info; |
| 10693 r->GetLoadTimingInfo(&load_timing_info); | 10826 r->GetLoadTimingInfo(&load_timing_info); |
| 10694 TestLoadTimingNoHttpResponse(load_timing_info); | 10827 TestLoadTimingNoHttpResponse(load_timing_info); |
| 10695 } | 10828 } |
| 10696 } | 10829 } |
| 10697 | 10830 |
| 10698 TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) { | 10831 TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) { |
| 10699 ASSERT_TRUE(ftp_test_server_.Start()); | 10832 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10700 | 10833 |
| 10701 TestDelegate d; | 10834 TestDelegate d; |
| 10702 { | 10835 { |
| 10703 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10836 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10704 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", | 10837 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 10705 "wrong_password"), | 10838 "wrong_password"), |
| 10706 DEFAULT_PRIORITY, &d)); | 10839 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10707 r->Start(); | 10840 r->Start(); |
| 10708 EXPECT_TRUE(r->is_pending()); | 10841 EXPECT_TRUE(r->is_pending()); |
| 10709 | 10842 |
| 10710 base::RunLoop().Run(); | 10843 base::RunLoop().Run(); |
| 10711 | 10844 |
| 10712 EXPECT_FALSE(r->is_pending()); | 10845 EXPECT_FALSE(r->is_pending()); |
| 10713 EXPECT_EQ(1, d.response_started_count()); | 10846 EXPECT_EQ(1, d.response_started_count()); |
| 10714 EXPECT_FALSE(d.received_data_before_response()); | 10847 EXPECT_FALSE(d.received_data_before_response()); |
| 10715 EXPECT_EQ(d.bytes_received(), 0); | 10848 EXPECT_EQ(d.bytes_received(), 0); |
| 10716 } | 10849 } |
| 10717 } | 10850 } |
| 10718 | 10851 |
| 10719 TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) { | 10852 TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) { |
| 10720 ASSERT_TRUE(ftp_test_server_.Start()); | 10853 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10721 | 10854 |
| 10722 TestDelegate d; | 10855 TestDelegate d; |
| 10723 // Set correct login credentials. The delegate will be asked for them when | 10856 // Set correct login credentials. The delegate will be asked for them when |
| 10724 // the initial login with wrong credentials will fail. | 10857 // the initial login with wrong credentials will fail. |
| 10725 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 10858 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 10726 { | 10859 { |
| 10727 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10860 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10728 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", | 10861 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 10729 "wrong_password"), | 10862 "wrong_password"), |
| 10730 DEFAULT_PRIORITY, &d)); | 10863 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10731 r->Start(); | 10864 r->Start(); |
| 10732 EXPECT_TRUE(r->is_pending()); | 10865 EXPECT_TRUE(r->is_pending()); |
| 10733 | 10866 |
| 10734 base::RunLoop().Run(); | 10867 base::RunLoop().Run(); |
| 10735 | 10868 |
| 10736 EXPECT_FALSE(r->is_pending()); | 10869 EXPECT_FALSE(r->is_pending()); |
| 10737 EXPECT_EQ(1, d.response_started_count()); | 10870 EXPECT_EQ(1, d.response_started_count()); |
| 10738 EXPECT_FALSE(d.received_data_before_response()); | 10871 EXPECT_FALSE(d.received_data_before_response()); |
| 10739 EXPECT_EQ(GetTestFileContents(), d.data_received()); | 10872 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 10740 } | 10873 } |
| 10741 } | 10874 } |
| 10742 | 10875 |
| 10743 TEST_F(URLRequestTestFTP, FTPCheckWrongUser) { | 10876 TEST_F(URLRequestTestFTP, FTPCheckWrongUser) { |
| 10744 ASSERT_TRUE(ftp_test_server_.Start()); | 10877 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10745 | 10878 |
| 10746 TestDelegate d; | 10879 TestDelegate d; |
| 10747 { | 10880 { |
| 10748 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10881 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10749 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", | 10882 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", |
| 10750 "chrome"), | 10883 "chrome"), |
| 10751 DEFAULT_PRIORITY, &d)); | 10884 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10752 r->Start(); | 10885 r->Start(); |
| 10753 EXPECT_TRUE(r->is_pending()); | 10886 EXPECT_TRUE(r->is_pending()); |
| 10754 | 10887 |
| 10755 base::RunLoop().Run(); | 10888 base::RunLoop().Run(); |
| 10756 | 10889 |
| 10757 EXPECT_FALSE(r->is_pending()); | 10890 EXPECT_FALSE(r->is_pending()); |
| 10758 EXPECT_EQ(1, d.response_started_count()); | 10891 EXPECT_EQ(1, d.response_started_count()); |
| 10759 EXPECT_FALSE(d.received_data_before_response()); | 10892 EXPECT_FALSE(d.received_data_before_response()); |
| 10760 EXPECT_EQ(0, d.bytes_received()); | 10893 EXPECT_EQ(0, d.bytes_received()); |
| 10761 } | 10894 } |
| 10762 } | 10895 } |
| 10763 | 10896 |
| 10764 TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) { | 10897 TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) { |
| 10765 ASSERT_TRUE(ftp_test_server_.Start()); | 10898 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10766 | 10899 |
| 10767 TestDelegate d; | 10900 TestDelegate d; |
| 10768 // Set correct login credentials. The delegate will be asked for them when | 10901 // Set correct login credentials. The delegate will be asked for them when |
| 10769 // the initial login with wrong credentials will fail. | 10902 // the initial login with wrong credentials will fail. |
| 10770 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 10903 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 10771 { | 10904 { |
| 10772 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10905 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10773 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", | 10906 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", |
| 10774 "chrome"), | 10907 "chrome"), |
| 10775 DEFAULT_PRIORITY, &d)); | 10908 DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10776 r->Start(); | 10909 r->Start(); |
| 10777 EXPECT_TRUE(r->is_pending()); | 10910 EXPECT_TRUE(r->is_pending()); |
| 10778 | 10911 |
| 10779 base::RunLoop().Run(); | 10912 base::RunLoop().Run(); |
| 10780 | 10913 |
| 10781 EXPECT_FALSE(r->is_pending()); | 10914 EXPECT_FALSE(r->is_pending()); |
| 10782 EXPECT_EQ(1, d.response_started_count()); | 10915 EXPECT_EQ(1, d.response_started_count()); |
| 10783 EXPECT_FALSE(d.received_data_before_response()); | 10916 EXPECT_FALSE(d.received_data_before_response()); |
| 10784 EXPECT_EQ(GetTestFileContents(), d.data_received()); | 10917 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 10785 } | 10918 } |
| 10786 } | 10919 } |
| 10787 | 10920 |
| 10788 TEST_F(URLRequestTestFTP, FTPCacheURLCredentials) { | 10921 TEST_F(URLRequestTestFTP, FTPCacheURLCredentials) { |
| 10789 ASSERT_TRUE(ftp_test_server_.Start()); | 10922 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10790 | 10923 |
| 10791 std::unique_ptr<TestDelegate> d(new TestDelegate); | 10924 std::unique_ptr<TestDelegate> d(new TestDelegate); |
| 10792 { | 10925 { |
| 10793 // Pass correct login identity in the URL. | 10926 // Pass correct login identity in the URL. |
| 10794 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10927 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10795 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", | 10928 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 10796 "chrome"), | 10929 "chrome"), |
| 10797 DEFAULT_PRIORITY, d.get())); | 10930 DEFAULT_PRIORITY, d.get(), TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10798 r->Start(); | 10931 r->Start(); |
| 10799 EXPECT_TRUE(r->is_pending()); | 10932 EXPECT_TRUE(r->is_pending()); |
| 10800 | 10933 |
| 10801 base::RunLoop().Run(); | 10934 base::RunLoop().Run(); |
| 10802 | 10935 |
| 10803 EXPECT_FALSE(r->is_pending()); | 10936 EXPECT_FALSE(r->is_pending()); |
| 10804 EXPECT_EQ(1, d->response_started_count()); | 10937 EXPECT_EQ(1, d->response_started_count()); |
| 10805 EXPECT_FALSE(d->received_data_before_response()); | 10938 EXPECT_FALSE(d->received_data_before_response()); |
| 10806 EXPECT_EQ(GetTestFileContents(), d->data_received()); | 10939 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 10807 } | 10940 } |
| 10808 | 10941 |
| 10809 d.reset(new TestDelegate); | 10942 d.reset(new TestDelegate); |
| 10810 { | 10943 { |
| 10811 // This request should use cached identity from previous request. | 10944 // This request should use cached identity from previous request. |
| 10812 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10945 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10813 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get())); | 10946 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get(), |
| 10947 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10814 r->Start(); | 10948 r->Start(); |
| 10815 EXPECT_TRUE(r->is_pending()); | 10949 EXPECT_TRUE(r->is_pending()); |
| 10816 | 10950 |
| 10817 base::RunLoop().Run(); | 10951 base::RunLoop().Run(); |
| 10818 | 10952 |
| 10819 EXPECT_FALSE(r->is_pending()); | 10953 EXPECT_FALSE(r->is_pending()); |
| 10820 EXPECT_EQ(1, d->response_started_count()); | 10954 EXPECT_EQ(1, d->response_started_count()); |
| 10821 EXPECT_FALSE(d->received_data_before_response()); | 10955 EXPECT_FALSE(d->received_data_before_response()); |
| 10822 EXPECT_EQ(GetTestFileContents(), d->data_received()); | 10956 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 10823 } | 10957 } |
| 10824 } | 10958 } |
| 10825 | 10959 |
| 10826 TEST_F(URLRequestTestFTP, FTPCacheLoginBoxCredentials) { | 10960 TEST_F(URLRequestTestFTP, FTPCacheLoginBoxCredentials) { |
| 10827 ASSERT_TRUE(ftp_test_server_.Start()); | 10961 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10828 | 10962 |
| 10829 std::unique_ptr<TestDelegate> d(new TestDelegate); | 10963 std::unique_ptr<TestDelegate> d(new TestDelegate); |
| 10830 // Set correct login credentials. The delegate will be asked for them when | 10964 // Set correct login credentials. The delegate will be asked for them when |
| 10831 // the initial login with wrong credentials will fail. | 10965 // the initial login with wrong credentials will fail. |
| 10832 d->set_credentials(AuthCredentials(kChrome, kChrome)); | 10966 d->set_credentials(AuthCredentials(kChrome, kChrome)); |
| 10833 { | 10967 { |
| 10834 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10968 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10835 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", | 10969 ftp_test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 10836 "wrong_password"), | 10970 "wrong_password"), |
| 10837 DEFAULT_PRIORITY, d.get())); | 10971 DEFAULT_PRIORITY, d.get(), TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10838 r->Start(); | 10972 r->Start(); |
| 10839 EXPECT_TRUE(r->is_pending()); | 10973 EXPECT_TRUE(r->is_pending()); |
| 10840 | 10974 |
| 10841 base::RunLoop().Run(); | 10975 base::RunLoop().Run(); |
| 10842 | 10976 |
| 10843 EXPECT_FALSE(r->is_pending()); | 10977 EXPECT_FALSE(r->is_pending()); |
| 10844 EXPECT_EQ(1, d->response_started_count()); | 10978 EXPECT_EQ(1, d->response_started_count()); |
| 10845 EXPECT_FALSE(d->received_data_before_response()); | 10979 EXPECT_FALSE(d->received_data_before_response()); |
| 10846 EXPECT_EQ(GetTestFileContents(), d->data_received()); | 10980 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 10847 } | 10981 } |
| 10848 | 10982 |
| 10849 // Use a new delegate without explicit credentials. The cached ones should be | 10983 // Use a new delegate without explicit credentials. The cached ones should be |
| 10850 // used. | 10984 // used. |
| 10851 d.reset(new TestDelegate); | 10985 d.reset(new TestDelegate); |
| 10852 { | 10986 { |
| 10853 // Don't pass wrong credentials in the URL, they would override valid cached | 10987 // Don't pass wrong credentials in the URL, they would override valid cached |
| 10854 // ones. | 10988 // ones. |
| 10855 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( | 10989 std::unique_ptr<URLRequest> r(default_context_.CreateRequest( |
| 10856 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get())); | 10990 ftp_test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get(), |
| 10991 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10857 r->Start(); | 10992 r->Start(); |
| 10858 EXPECT_TRUE(r->is_pending()); | 10993 EXPECT_TRUE(r->is_pending()); |
| 10859 | 10994 |
| 10860 base::RunLoop().Run(); | 10995 base::RunLoop().Run(); |
| 10861 | 10996 |
| 10862 EXPECT_FALSE(r->is_pending()); | 10997 EXPECT_FALSE(r->is_pending()); |
| 10863 EXPECT_EQ(1, d->response_started_count()); | 10998 EXPECT_EQ(1, d->response_started_count()); |
| 10864 EXPECT_FALSE(d->received_data_before_response()); | 10999 EXPECT_FALSE(d->received_data_before_response()); |
| 10865 EXPECT_EQ(GetTestFileContents(), d->data_received()); | 11000 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 10866 } | 11001 } |
| 10867 } | 11002 } |
| 10868 | 11003 |
| 10869 TEST_F(URLRequestTestFTP, RawBodyBytes) { | 11004 TEST_F(URLRequestTestFTP, RawBodyBytes) { |
| 10870 ASSERT_TRUE(ftp_test_server_.Start()); | 11005 ASSERT_TRUE(ftp_test_server_.Start()); |
| 10871 | 11006 |
| 10872 TestDelegate d; | 11007 TestDelegate d; |
| 10873 std::unique_ptr<URLRequest> req(default_context().CreateRequest( | 11008 std::unique_ptr<URLRequest> req(default_context().CreateRequest( |
| 10874 ftp_test_server_.GetURL("simple.html"), DEFAULT_PRIORITY, &d)); | 11009 ftp_test_server_.GetURL("simple.html"), DEFAULT_PRIORITY, &d, |
| 11010 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10875 req->Start(); | 11011 req->Start(); |
| 10876 base::RunLoop().Run(); | 11012 base::RunLoop().Run(); |
| 10877 | 11013 |
| 10878 EXPECT_EQ(6, req->GetRawBodyBytes()); | 11014 EXPECT_EQ(6, req->GetRawBodyBytes()); |
| 10879 } | 11015 } |
| 10880 | 11016 |
| 10881 #endif // !BUILDFLAG(DISABLE_FTP_SUPPORT) | 11017 #endif // !BUILDFLAG(DISABLE_FTP_SUPPORT) |
| 10882 | 11018 |
| 10883 TEST_F(URLRequestTest, NetworkAccessedClearOnDataRequest) { | 11019 TEST_F(URLRequestTest, NetworkAccessedClearOnDataRequest) { |
| 10884 TestDelegate d; | 11020 TestDelegate d; |
| 10885 std::unique_ptr<URLRequest> req( | 11021 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 10886 default_context_.CreateRequest(GURL("data:,"), DEFAULT_PRIORITY, &d)); | 11022 GURL("data:,"), DEFAULT_PRIORITY, &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10887 | 11023 |
| 10888 EXPECT_FALSE(req->response_info().network_accessed); | 11024 EXPECT_FALSE(req->response_info().network_accessed); |
| 10889 | 11025 |
| 10890 req->Start(); | 11026 req->Start(); |
| 10891 base::RunLoop().Run(); | 11027 base::RunLoop().Run(); |
| 10892 | 11028 |
| 10893 EXPECT_EQ(1, default_network_delegate_.completed_requests()); | 11029 EXPECT_EQ(1, default_network_delegate_.completed_requests()); |
| 10894 EXPECT_FALSE(req->response_info().network_accessed); | 11030 EXPECT_FALSE(req->response_info().network_accessed); |
| 10895 } | 11031 } |
| 10896 | 11032 |
| 10897 TEST_F(URLRequestTest, NetworkAccessedSetOnHostResolutionFailure) { | 11033 TEST_F(URLRequestTest, NetworkAccessedSetOnHostResolutionFailure) { |
| 10898 MockHostResolver host_resolver; | 11034 MockHostResolver host_resolver; |
| 10899 TestNetworkDelegate network_delegate; // Must outlive URLRequest. | 11035 TestNetworkDelegate network_delegate; // Must outlive URLRequest. |
| 10900 TestURLRequestContext context(true); | 11036 TestURLRequestContext context(true); |
| 10901 context.set_network_delegate(&network_delegate); | 11037 context.set_network_delegate(&network_delegate); |
| 10902 context.set_host_resolver(&host_resolver); | 11038 context.set_host_resolver(&host_resolver); |
| 10903 host_resolver.rules()->AddSimulatedFailure("*"); | 11039 host_resolver.rules()->AddSimulatedFailure("*"); |
| 10904 context.Init(); | 11040 context.Init(); |
| 10905 | 11041 |
| 10906 TestDelegate d; | 11042 TestDelegate d; |
| 10907 std::unique_ptr<URLRequest> req(context.CreateRequest( | 11043 std::unique_ptr<URLRequest> req( |
| 10908 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 11044 context.CreateRequest(GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, |
| 11045 &d, TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10909 | 11046 |
| 10910 EXPECT_FALSE(req->response_info().network_accessed); | 11047 EXPECT_FALSE(req->response_info().network_accessed); |
| 10911 | 11048 |
| 10912 req->Start(); | 11049 req->Start(); |
| 10913 base::RunLoop().Run(); | 11050 base::RunLoop().Run(); |
| 10914 EXPECT_TRUE(req->response_info().network_accessed); | 11051 EXPECT_TRUE(req->response_info().network_accessed); |
| 10915 } | 11052 } |
| 10916 | 11053 |
| 10917 // Test that URLRequest is canceled correctly. | 11054 // Test that URLRequest is canceled correctly. |
| 10918 // See http://crbug.com/508900 | 11055 // See http://crbug.com/508900 |
| 10919 TEST_F(URLRequestTest, URLRequestRedirectJobCancelRequest) { | 11056 TEST_F(URLRequestTest, URLRequestRedirectJobCancelRequest) { |
| 10920 TestDelegate d; | 11057 TestDelegate d; |
| 10921 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( | 11058 std::unique_ptr<URLRequest> req(default_context_.CreateRequest( |
| 10922 GURL("http://not-a-real-domain/"), DEFAULT_PRIORITY, &d)); | 11059 GURL("http://not-a-real-domain/"), DEFAULT_PRIORITY, &d, |
| 11060 TRAFFIC_ANNOTATION_FOR_TESTS)); |
| 10923 | 11061 |
| 10924 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( | 11062 std::unique_ptr<URLRequestRedirectJob> job(new URLRequestRedirectJob( |
| 10925 req.get(), &default_network_delegate_, | 11063 req.get(), &default_network_delegate_, |
| 10926 GURL("http://this-should-never-be-navigated-to/"), | 11064 GURL("http://this-should-never-be-navigated-to/"), |
| 10927 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp")); | 11065 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT, "Jumbo shrimp")); |
| 10928 AddTestInterceptor()->set_main_intercept_job(std::move(job)); | 11066 AddTestInterceptor()->set_main_intercept_job(std::move(job)); |
| 10929 | 11067 |
| 10930 req->Start(); | 11068 req->Start(); |
| 10931 req->Cancel(); | 11069 req->Cancel(); |
| 10932 base::RunLoop().RunUntilIdle(); | 11070 base::RunLoop().RunUntilIdle(); |
| 10933 EXPECT_EQ(ERR_ABORTED, d.request_status()); | 11071 EXPECT_EQ(ERR_ABORTED, d.request_status()); |
| 10934 EXPECT_EQ(0, d.received_redirect_count()); | 11072 EXPECT_EQ(0, d.received_redirect_count()); |
| 10935 } | 11073 } |
| 10936 | 11074 |
| 10937 } // namespace net | 11075 } // namespace net |
| OLD | NEW |