| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "build/build_config.h" | 5 #include "build/build_config.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #include <shlobj.h> | 9 #include <shlobj.h> |
| 10 #endif | 10 #endif |
| 11 | 11 |
| 12 #include <stdint.h> | 12 #include <stdint.h> |
| 13 | 13 |
| 14 #include <algorithm> | 14 #include <algorithm> |
| 15 | 15 |
| 16 #include "base/basictypes.h" | 16 #include "base/basictypes.h" |
| 17 #include "base/bind.h" | 17 #include "base/bind.h" |
| 18 #include "base/compiler_specific.h" | 18 #include "base/compiler_specific.h" |
| 19 #include "base/files/file_path.h" |
| 19 #include "base/files/file_util.h" | 20 #include "base/files/file_util.h" |
| 20 #include "base/files/scoped_temp_dir.h" | 21 #include "base/files/scoped_temp_dir.h" |
| 21 #include "base/format_macros.h" | 22 #include "base/format_macros.h" |
| 22 #include "base/memory/scoped_ptr.h" | 23 #include "base/memory/scoped_ptr.h" |
| 23 #include "base/memory/weak_ptr.h" | 24 #include "base/memory/weak_ptr.h" |
| 24 #include "base/message_loop/message_loop.h" | 25 #include "base/message_loop/message_loop.h" |
| 25 #include "base/message_loop/message_loop_proxy.h" | 26 #include "base/message_loop/message_loop_proxy.h" |
| 26 #include "base/path_service.h" | 27 #include "base/path_service.h" |
| 27 #include "base/run_loop.h" | 28 #include "base/run_loop.h" |
| 28 #include "base/strings/string_number_conversions.h" | 29 #include "base/strings/string_number_conversions.h" |
| (...skipping 19 matching lines...) Expand all Loading... |
| 48 #include "net/base/upload_data_stream.h" | 49 #include "net/base/upload_data_stream.h" |
| 49 #include "net/base/upload_file_element_reader.h" | 50 #include "net/base/upload_file_element_reader.h" |
| 50 #include "net/cert/ev_root_ca_metadata.h" | 51 #include "net/cert/ev_root_ca_metadata.h" |
| 51 #include "net/cert/mock_cert_verifier.h" | 52 #include "net/cert/mock_cert_verifier.h" |
| 52 #include "net/cert/test_root_certs.h" | 53 #include "net/cert/test_root_certs.h" |
| 53 #include "net/cert_net/nss_ocsp.h" | 54 #include "net/cert_net/nss_ocsp.h" |
| 54 #include "net/cookies/cookie_monster.h" | 55 #include "net/cookies/cookie_monster.h" |
| 55 #include "net/cookies/cookie_store_test_helpers.h" | 56 #include "net/cookies/cookie_store_test_helpers.h" |
| 56 #include "net/disk_cache/disk_cache.h" | 57 #include "net/disk_cache/disk_cache.h" |
| 57 #include "net/dns/mock_host_resolver.h" | 58 #include "net/dns/mock_host_resolver.h" |
| 58 #include "net/ftp/ftp_network_layer.h" | |
| 59 #include "net/http/http_byte_range.h" | 59 #include "net/http/http_byte_range.h" |
| 60 #include "net/http/http_cache.h" | 60 #include "net/http/http_cache.h" |
| 61 #include "net/http/http_network_layer.h" | 61 #include "net/http/http_network_layer.h" |
| 62 #include "net/http/http_network_session.h" | 62 #include "net/http/http_network_session.h" |
| 63 #include "net/http/http_request_headers.h" | 63 #include "net/http/http_request_headers.h" |
| 64 #include "net/http/http_response_headers.h" | 64 #include "net/http/http_response_headers.h" |
| 65 #include "net/http/http_util.h" | 65 #include "net/http/http_util.h" |
| 66 #include "net/log/net_log.h" | 66 #include "net/log/net_log.h" |
| 67 #include "net/log/test_net_log.h" | 67 #include "net/log/test_net_log.h" |
| 68 #include "net/log/test_net_log_entry.h" | 68 #include "net/log/test_net_log_entry.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 85 #include "net/url_request/url_request_test_util.h" | 85 #include "net/url_request/url_request_test_util.h" |
| 86 #include "testing/gtest/include/gtest/gtest.h" | 86 #include "testing/gtest/include/gtest/gtest.h" |
| 87 #include "testing/platform_test.h" | 87 #include "testing/platform_test.h" |
| 88 | 88 |
| 89 #if !defined(DISABLE_FILE_SUPPORT) | 89 #if !defined(DISABLE_FILE_SUPPORT) |
| 90 #include "net/base/filename_util.h" | 90 #include "net/base/filename_util.h" |
| 91 #include "net/url_request/file_protocol_handler.h" | 91 #include "net/url_request/file_protocol_handler.h" |
| 92 #include "net/url_request/url_request_file_dir_job.h" | 92 #include "net/url_request/url_request_file_dir_job.h" |
| 93 #endif | 93 #endif |
| 94 | 94 |
| 95 #if !defined(DISABLE_FTP_SUPPORT) | 95 #if !defined(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) |
| 96 #include "net/ftp/ftp_network_layer.h" |
| 96 #include "net/url_request/ftp_protocol_handler.h" | 97 #include "net/url_request/ftp_protocol_handler.h" |
| 97 #endif | 98 #endif |
| 98 | 99 |
| 99 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
| 100 #include "base/win/scoped_com_initializer.h" | 101 #include "base/win/scoped_com_initializer.h" |
| 101 #include "base/win/scoped_comptr.h" | 102 #include "base/win/scoped_comptr.h" |
| 102 #include "base/win/windows_version.h" | 103 #include "base/win/windows_version.h" |
| 103 #endif | 104 #endif |
| 104 | 105 |
| 105 using base::ASCIIToUTF16; | 106 using base::ASCIIToUTF16; |
| 106 using base::Time; | 107 using base::Time; |
| 107 using std::string; | 108 using std::string; |
| 108 | 109 |
| 109 namespace net { | 110 namespace net { |
| 110 | 111 |
| 111 namespace { | 112 namespace { |
| 112 | 113 |
| 113 const base::string16 kChrome(ASCIIToUTF16("chrome")); | 114 const base::string16 kChrome(ASCIIToUTF16("chrome")); |
| 114 const base::string16 kSecret(ASCIIToUTF16("secret")); | 115 const base::string16 kSecret(ASCIIToUTF16("secret")); |
| 115 const base::string16 kUser(ASCIIToUTF16("user")); | 116 const base::string16 kUser(ASCIIToUTF16("user")); |
| 116 | 117 |
| 118 const base::FilePath::CharType kTestFilePath[] = |
| 119 FILE_PATH_LITERAL("net/data/url_request_unittest"); |
| 120 |
| 121 #if !defined(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) |
| 122 // Test file used in most FTP tests. |
| 123 const char kFtpTestFile[] = "BullRunSpeech.txt"; |
| 124 #endif |
| 125 |
| 117 // Tests load timing information in the case a fresh connection was used, with | 126 // Tests load timing information in the case a fresh connection was used, with |
| 118 // no proxy. | 127 // no proxy. |
| 119 void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, | 128 void TestLoadTimingNotReused(const LoadTimingInfo& load_timing_info, |
| 120 int connect_timing_flags) { | 129 int connect_timing_flags) { |
| 121 EXPECT_FALSE(load_timing_info.socket_reused); | 130 EXPECT_FALSE(load_timing_info.socket_reused); |
| 122 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 131 EXPECT_NE(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 123 | 132 |
| 124 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); | 133 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); |
| 125 EXPECT_FALSE(load_timing_info.request_start.is_null()); | 134 EXPECT_FALSE(load_timing_info.request_start.is_null()); |
| 126 | 135 |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 216 | 225 |
| 217 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); | 226 ExpectConnectTimingHasNoTimes(load_timing_info.connect_timing); |
| 218 EXPECT_LE(load_timing_info.request_start, load_timing_info.send_start); | 227 EXPECT_LE(load_timing_info.request_start, load_timing_info.send_start); |
| 219 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); | 228 EXPECT_LE(load_timing_info.send_start, load_timing_info.send_end); |
| 220 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end); | 229 EXPECT_LE(load_timing_info.send_end, load_timing_info.receive_headers_end); |
| 221 | 230 |
| 222 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); | 231 EXPECT_TRUE(load_timing_info.proxy_resolve_start.is_null()); |
| 223 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); | 232 EXPECT_TRUE(load_timing_info.proxy_resolve_end.is_null()); |
| 224 } | 233 } |
| 225 | 234 |
| 226 #if !defined(DISABLE_FTP_SUPPORT) | 235 #if !defined(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) |
| 227 // Tests load timing in the case that there is no HTTP response. This can be | 236 // Tests load timing in the case that there is no HTTP response. This can be |
| 228 // used to test in the case of errors or non-HTTP requests. | 237 // used to test in the case of errors or non-HTTP requests. |
| 229 void TestLoadTimingNoHttpResponse( | 238 void TestLoadTimingNoHttpResponse( |
| 230 const LoadTimingInfo& load_timing_info) { | 239 const LoadTimingInfo& load_timing_info) { |
| 231 EXPECT_FALSE(load_timing_info.socket_reused); | 240 EXPECT_FALSE(load_timing_info.socket_reused); |
| 232 EXPECT_EQ(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); | 241 EXPECT_EQ(NetLog::Source::kInvalidId, load_timing_info.socket_log_id); |
| 233 | 242 |
| 234 // Only the request times should be non-null. | 243 // Only the request times should be non-null. |
| 235 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); | 244 EXPECT_FALSE(load_timing_info.request_start_time.is_null()); |
| 236 EXPECT_FALSE(load_timing_info.request_start.is_null()); | 245 EXPECT_FALSE(load_timing_info.request_start.is_null()); |
| (...skipping 730 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 967 } | 976 } |
| 968 | 977 |
| 969 TEST_F(URLRequestTest, FileDirOutputSanity) { | 978 TEST_F(URLRequestTest, FileDirOutputSanity) { |
| 970 // Verify the general sanity of the the output of the file: | 979 // Verify the general sanity of the the output of the file: |
| 971 // directory lister by checking for the output of a known existing | 980 // directory lister by checking for the output of a known existing |
| 972 // file. | 981 // file. |
| 973 const char sentinel_name[] = "filedir-sentinel"; | 982 const char sentinel_name[] = "filedir-sentinel"; |
| 974 | 983 |
| 975 base::FilePath path; | 984 base::FilePath path; |
| 976 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 985 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 977 path = path.Append(FILE_PATH_LITERAL("net")); | 986 path = path.Append(kTestFilePath); |
| 978 path = path.Append(FILE_PATH_LITERAL("data")); | |
| 979 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | |
| 980 | 987 |
| 981 TestDelegate d; | 988 TestDelegate d; |
| 982 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 989 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 983 FilePathToFileURL(path), DEFAULT_PRIORITY, &d)); | 990 FilePathToFileURL(path), DEFAULT_PRIORITY, &d)); |
| 984 req->Start(); | 991 req->Start(); |
| 985 base::RunLoop().Run(); | 992 base::RunLoop().Run(); |
| 986 | 993 |
| 987 // Generate entry for the sentinel file. | 994 // Generate entry for the sentinel file. |
| 988 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); | 995 base::FilePath sentinel_path = path.AppendASCII(sentinel_name); |
| 989 base::File::Info info; | 996 base::File::Info info; |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1004 ASSERT_NE(data.find(sentinel_output), std::string::npos); | 1011 ASSERT_NE(data.find(sentinel_output), std::string::npos); |
| 1005 } | 1012 } |
| 1006 | 1013 |
| 1007 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { | 1014 TEST_F(URLRequestTest, FileDirRedirectNoCrash) { |
| 1008 // There is an implicit redirect when loading a file path that matches a | 1015 // There is an implicit redirect when loading a file path that matches a |
| 1009 // directory and does not end with a slash. Ensure that following such | 1016 // directory and does not end with a slash. Ensure that following such |
| 1010 // redirects does not crash. See http://crbug.com/18686. | 1017 // redirects does not crash. See http://crbug.com/18686. |
| 1011 | 1018 |
| 1012 base::FilePath path; | 1019 base::FilePath path; |
| 1013 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 1020 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 1014 path = path.Append(FILE_PATH_LITERAL("net")); | 1021 path = path.Append(kTestFilePath); |
| 1015 path = path.Append(FILE_PATH_LITERAL("data")); | |
| 1016 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | |
| 1017 | 1022 |
| 1018 TestDelegate d; | 1023 TestDelegate d; |
| 1019 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 1024 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 1020 FilePathToFileURL(path), DEFAULT_PRIORITY, &d)); | 1025 FilePathToFileURL(path), DEFAULT_PRIORITY, &d)); |
| 1021 req->Start(); | 1026 req->Start(); |
| 1022 base::RunLoop().Run(); | 1027 base::RunLoop().Run(); |
| 1023 | 1028 |
| 1024 ASSERT_EQ(1, d.received_redirect_count()); | 1029 ASSERT_EQ(1, d.received_redirect_count()); |
| 1025 ASSERT_LT(0, d.bytes_received()); | 1030 ASSERT_LT(0, d.bytes_received()); |
| 1026 ASSERT_FALSE(d.request_failed()); | 1031 ASSERT_FALSE(d.request_failed()); |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1069 | 1074 |
| 1070 req->Start(); | 1075 req->Start(); |
| 1071 base::RunLoop().Run(); | 1076 base::RunLoop().Run(); |
| 1072 EXPECT_TRUE(d.request_failed()); | 1077 EXPECT_TRUE(d.request_failed()); |
| 1073 } | 1078 } |
| 1074 | 1079 |
| 1075 #if defined(OS_WIN) | 1080 #if defined(OS_WIN) |
| 1076 TEST_F(URLRequestTest, ResolveShortcutTest) { | 1081 TEST_F(URLRequestTest, ResolveShortcutTest) { |
| 1077 base::FilePath app_path; | 1082 base::FilePath app_path; |
| 1078 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | 1083 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); |
| 1079 app_path = app_path.AppendASCII("net"); | 1084 app_path = app_path.Append(kTestFilePath); |
| 1080 app_path = app_path.AppendASCII("data"); | |
| 1081 app_path = app_path.AppendASCII("url_request_unittest"); | |
| 1082 app_path = app_path.AppendASCII("with-headers.html"); | 1085 app_path = app_path.AppendASCII("with-headers.html"); |
| 1083 | 1086 |
| 1084 std::wstring lnk_path = app_path.value() + L".lnk"; | 1087 std::wstring lnk_path = app_path.value() + L".lnk"; |
| 1085 | 1088 |
| 1086 base::win::ScopedCOMInitializer com_initializer; | 1089 base::win::ScopedCOMInitializer com_initializer; |
| 1087 | 1090 |
| 1088 // Temporarily create a shortcut for test | 1091 // Temporarily create a shortcut for test |
| 1089 { | 1092 { |
| 1090 base::win::ScopedComPtr<IShellLink> shell; | 1093 base::win::ScopedComPtr<IShellLink> shell; |
| 1091 ASSERT_TRUE(SUCCEEDED(shell.CreateInstance(CLSID_ShellLink, NULL, | 1094 ASSERT_TRUE(SUCCEEDED(shell.CreateInstance(CLSID_ShellLink, NULL, |
| (...skipping 1720 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2812 | 2815 |
| 2813 req->Start(); | 2816 req->Start(); |
| 2814 base::RunLoop().Run(); | 2817 base::RunLoop().Run(); |
| 2815 | 2818 |
| 2816 EXPECT_EQ("None", d.data_received()); | 2819 EXPECT_EQ("None", d.data_received()); |
| 2817 } | 2820 } |
| 2818 } | 2821 } |
| 2819 | 2822 |
| 2820 class URLRequestTestHTTP : public URLRequestTest { | 2823 class URLRequestTestHTTP : public URLRequestTest { |
| 2821 public: | 2824 public: |
| 2822 URLRequestTestHTTP() | 2825 URLRequestTestHTTP() : test_server_(base::FilePath(kTestFilePath)) {} |
| 2823 : test_server_(base::FilePath(FILE_PATH_LITERAL( | |
| 2824 "net/data/url_request_unittest"))) { | |
| 2825 } | |
| 2826 | 2826 |
| 2827 protected: | 2827 protected: |
| 2828 // Requests |redirect_url|, which must return a HTTP 3xx redirect. | 2828 // Requests |redirect_url|, which must return a HTTP 3xx redirect. |
| 2829 // |request_method| is the method to use for the initial request. | 2829 // |request_method| is the method to use for the initial request. |
| 2830 // |redirect_method| is the method that is expected to be used for the second | 2830 // |redirect_method| is the method that is expected to be used for the second |
| 2831 // request, after redirection. | 2831 // request, after redirection. |
| 2832 // If |include_data| is true, data is uploaded with the request. The | 2832 // If |include_data| is true, data is uploaded with the request. The |
| 2833 // response body is expected to match it exactly, if and only if | 2833 // response body is expected to match it exactly, if and only if |
| 2834 // |request_method| == |redirect_method|. | 2834 // |request_method| == |redirect_method|. |
| 2835 void HTTPRedirectMethodTest(const GURL& redirect_url, | 2835 void HTTPRedirectMethodTest(const GURL& redirect_url, |
| (...skipping 2318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5154 r->set_method("POST"); | 5154 r->set_method("POST"); |
| 5155 | 5155 |
| 5156 base::FilePath dir; | 5156 base::FilePath dir; |
| 5157 PathService::Get(base::DIR_EXE, &dir); | 5157 PathService::Get(base::DIR_EXE, &dir); |
| 5158 base::SetCurrentDirectory(dir); | 5158 base::SetCurrentDirectory(dir); |
| 5159 | 5159 |
| 5160 ScopedVector<UploadElementReader> element_readers; | 5160 ScopedVector<UploadElementReader> element_readers; |
| 5161 | 5161 |
| 5162 base::FilePath path; | 5162 base::FilePath path; |
| 5163 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 5163 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 5164 path = path.Append(FILE_PATH_LITERAL("net")); | 5164 path = path.Append(kTestFilePath); |
| 5165 path = path.Append(FILE_PATH_LITERAL("data")); | |
| 5166 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | |
| 5167 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 5165 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 5168 element_readers.push_back( | 5166 element_readers.push_back( |
| 5169 new UploadFileElementReader(base::MessageLoopProxy::current().get(), | 5167 new UploadFileElementReader(base::MessageLoopProxy::current().get(), |
| 5170 path, | 5168 path, |
| 5171 0, | 5169 0, |
| 5172 kuint64max, | 5170 kuint64max, |
| 5173 base::Time())); | 5171 base::Time())); |
| 5174 r->set_upload(make_scoped_ptr<UploadDataStream>( | 5172 r->set_upload(make_scoped_ptr<UploadDataStream>( |
| 5175 new ElementsUploadDataStream(element_readers.Pass(), 0))); | 5173 new ElementsUploadDataStream(element_readers.Pass(), 0))); |
| 5176 | 5174 |
| (...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5314 // The response has two "X-Multiple-Entries" headers. | 5312 // The response has two "X-Multiple-Entries" headers. |
| 5315 // This verfies our output has them concatenated together. | 5313 // This verfies our output has them concatenated together. |
| 5316 header.clear(); | 5314 header.clear(); |
| 5317 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); | 5315 EXPECT_TRUE(headers->GetNormalizedHeader("x-multiple-entries", &header)); |
| 5318 EXPECT_EQ("a, b", header); | 5316 EXPECT_EQ("a, b", header); |
| 5319 } | 5317 } |
| 5320 | 5318 |
| 5321 TEST_F(URLRequestTestHTTP, ProcessSTS) { | 5319 TEST_F(URLRequestTestHTTP, ProcessSTS) { |
| 5322 SpawnedTestServer::SSLOptions ssl_options( | 5320 SpawnedTestServer::SSLOptions ssl_options( |
| 5323 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5321 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
| 5324 SpawnedTestServer https_test_server( | 5322 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 5325 SpawnedTestServer::TYPE_HTTPS, | 5323 ssl_options, |
| 5326 ssl_options, | 5324 base::FilePath(kTestFilePath)); |
| 5327 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
| 5328 ASSERT_TRUE(https_test_server.Start()); | 5325 ASSERT_TRUE(https_test_server.Start()); |
| 5329 | 5326 |
| 5330 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5327 std::string test_server_hostname = https_test_server.GetURL("").host(); |
| 5331 | 5328 |
| 5332 TestDelegate d; | 5329 TestDelegate d; |
| 5333 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5330 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5334 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, | 5331 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, |
| 5335 &d)); | 5332 &d)); |
| 5336 request->Start(); | 5333 request->Start(); |
| 5337 base::RunLoop().Run(); | 5334 base::RunLoop().Run(); |
| 5338 | 5335 |
| 5339 TransportSecurityState* security_state = | 5336 TransportSecurityState* security_state = |
| 5340 default_context_.transport_security_state(); | 5337 default_context_.transport_security_state(); |
| 5341 TransportSecurityState::DomainState domain_state; | 5338 TransportSecurityState::DomainState domain_state; |
| 5342 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, | 5339 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, |
| 5343 &domain_state)); | 5340 &domain_state)); |
| 5344 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5341 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 5345 domain_state.sts.upgrade_mode); | 5342 domain_state.sts.upgrade_mode); |
| 5346 EXPECT_TRUE(domain_state.sts.include_subdomains); | 5343 EXPECT_TRUE(domain_state.sts.include_subdomains); |
| 5347 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5344 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
| 5348 #if defined(OS_ANDROID) | 5345 #if defined(OS_ANDROID) |
| 5349 // Android's CertVerifyProc does not (yet) handle pins. | 5346 // Android's CertVerifyProc does not (yet) handle pins. |
| 5350 #else | 5347 #else |
| 5351 EXPECT_FALSE(domain_state.HasPublicKeyPins()); | 5348 EXPECT_FALSE(domain_state.HasPublicKeyPins()); |
| 5352 #endif | 5349 #endif |
| 5353 } | 5350 } |
| 5354 | 5351 |
| 5355 TEST_F(URLRequestTestHTTP, STSNotProcessedOnIP) { | 5352 TEST_F(URLRequestTestHTTP, STSNotProcessedOnIP) { |
| 5356 SpawnedTestServer https_test_server( | 5353 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 5357 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::SSLOptions(), | 5354 SpawnedTestServer::SSLOptions(), |
| 5358 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5355 base::FilePath(kTestFilePath)); |
| 5359 ASSERT_TRUE(https_test_server.Start()); | 5356 ASSERT_TRUE(https_test_server.Start()); |
| 5360 // Make sure this test fails if the test server is changed to not | 5357 // Make sure this test fails if the test server is changed to not |
| 5361 // listen on an IP by default. | 5358 // listen on an IP by default. |
| 5362 ASSERT_TRUE(https_test_server.GetURL("").HostIsIPAddress()); | 5359 ASSERT_TRUE(https_test_server.GetURL("").HostIsIPAddress()); |
| 5363 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5360 std::string test_server_hostname = https_test_server.GetURL("").host(); |
| 5364 | 5361 |
| 5365 TestDelegate d; | 5362 TestDelegate d; |
| 5366 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5363 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5367 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, | 5364 https_test_server.GetURL("files/hsts-headers.html"), DEFAULT_PRIORITY, |
| 5368 &d)); | 5365 &d)); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 5383 #define MAYBE_ProcessPKP DISABLED_ProcessPKP | 5380 #define MAYBE_ProcessPKP DISABLED_ProcessPKP |
| 5384 #else | 5381 #else |
| 5385 #define MAYBE_ProcessPKP ProcessPKP | 5382 #define MAYBE_ProcessPKP ProcessPKP |
| 5386 #endif | 5383 #endif |
| 5387 | 5384 |
| 5388 // Tests that enabling HPKP on a domain does not affect the HSTS | 5385 // Tests that enabling HPKP on a domain does not affect the HSTS |
| 5389 // validity/expiration. | 5386 // validity/expiration. |
| 5390 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { | 5387 TEST_F(URLRequestTestHTTP, MAYBE_ProcessPKP) { |
| 5391 SpawnedTestServer::SSLOptions ssl_options( | 5388 SpawnedTestServer::SSLOptions ssl_options( |
| 5392 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5389 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
| 5393 SpawnedTestServer https_test_server( | 5390 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 5394 SpawnedTestServer::TYPE_HTTPS, | 5391 ssl_options, |
| 5395 ssl_options, | 5392 base::FilePath(kTestFilePath)); |
| 5396 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
| 5397 ASSERT_TRUE(https_test_server.Start()); | 5393 ASSERT_TRUE(https_test_server.Start()); |
| 5398 | 5394 |
| 5399 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5395 std::string test_server_hostname = https_test_server.GetURL("").host(); |
| 5400 | 5396 |
| 5401 TestDelegate d; | 5397 TestDelegate d; |
| 5402 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5398 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5403 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, | 5399 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, |
| 5404 &d)); | 5400 &d)); |
| 5405 request->Start(); | 5401 request->Start(); |
| 5406 base::RunLoop().Run(); | 5402 base::RunLoop().Run(); |
| 5407 | 5403 |
| 5408 TransportSecurityState* security_state = | 5404 TransportSecurityState* security_state = |
| 5409 default_context_.transport_security_state(); | 5405 default_context_.transport_security_state(); |
| 5410 TransportSecurityState::DomainState domain_state; | 5406 TransportSecurityState::DomainState domain_state; |
| 5411 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, | 5407 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, |
| 5412 &domain_state)); | 5408 &domain_state)); |
| 5413 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, | 5409 EXPECT_EQ(TransportSecurityState::DomainState::MODE_DEFAULT, |
| 5414 domain_state.sts.upgrade_mode); | 5410 domain_state.sts.upgrade_mode); |
| 5415 EXPECT_FALSE(domain_state.sts.include_subdomains); | 5411 EXPECT_FALSE(domain_state.sts.include_subdomains); |
| 5416 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5412 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
| 5417 EXPECT_TRUE(domain_state.HasPublicKeyPins()); | 5413 EXPECT_TRUE(domain_state.HasPublicKeyPins()); |
| 5418 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); | 5414 EXPECT_NE(domain_state.sts.expiry, domain_state.pkp.expiry); |
| 5419 } | 5415 } |
| 5420 | 5416 |
| 5421 TEST_F(URLRequestTestHTTP, PKPNotProcessedOnIP) { | 5417 TEST_F(URLRequestTestHTTP, PKPNotProcessedOnIP) { |
| 5422 SpawnedTestServer https_test_server( | 5418 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 5423 SpawnedTestServer::TYPE_HTTPS, SpawnedTestServer::SSLOptions(), | 5419 SpawnedTestServer::SSLOptions(), |
| 5424 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | 5420 base::FilePath(kTestFilePath)); |
| 5425 ASSERT_TRUE(https_test_server.Start()); | 5421 ASSERT_TRUE(https_test_server.Start()); |
| 5426 // Make sure this test fails if the test server is changed to not | 5422 // Make sure this test fails if the test server is changed to not |
| 5427 // listen on an IP by default. | 5423 // listen on an IP by default. |
| 5428 ASSERT_TRUE(https_test_server.GetURL("").HostIsIPAddress()); | 5424 ASSERT_TRUE(https_test_server.GetURL("").HostIsIPAddress()); |
| 5429 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5425 std::string test_server_hostname = https_test_server.GetURL("").host(); |
| 5430 | 5426 |
| 5431 TestDelegate d; | 5427 TestDelegate d; |
| 5432 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5428 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5433 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, | 5429 https_test_server.GetURL("files/hpkp-headers.html"), DEFAULT_PRIORITY, |
| 5434 &d)); | 5430 &d)); |
| 5435 request->Start(); | 5431 request->Start(); |
| 5436 base::RunLoop().Run(); | 5432 base::RunLoop().Run(); |
| 5437 | 5433 |
| 5438 TransportSecurityState* security_state = | 5434 TransportSecurityState* security_state = |
| 5439 default_context_.transport_security_state(); | 5435 default_context_.transport_security_state(); |
| 5440 TransportSecurityState::DomainState domain_state; | 5436 TransportSecurityState::DomainState domain_state; |
| 5441 EXPECT_FALSE(security_state->GetDynamicDomainState(test_server_hostname, | 5437 EXPECT_FALSE(security_state->GetDynamicDomainState(test_server_hostname, |
| 5442 &domain_state)); | 5438 &domain_state)); |
| 5443 } | 5439 } |
| 5444 | 5440 |
| 5445 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { | 5441 TEST_F(URLRequestTestHTTP, ProcessSTSOnce) { |
| 5446 SpawnedTestServer::SSLOptions ssl_options( | 5442 SpawnedTestServer::SSLOptions ssl_options( |
| 5447 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5443 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
| 5448 SpawnedTestServer https_test_server( | 5444 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 5449 SpawnedTestServer::TYPE_HTTPS, | 5445 ssl_options, |
| 5450 ssl_options, | 5446 base::FilePath(kTestFilePath)); |
| 5451 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
| 5452 ASSERT_TRUE(https_test_server.Start()); | 5447 ASSERT_TRUE(https_test_server.Start()); |
| 5453 | 5448 |
| 5454 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5449 std::string test_server_hostname = https_test_server.GetURL("").host(); |
| 5455 | 5450 |
| 5456 TestDelegate d; | 5451 TestDelegate d; |
| 5457 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5452 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5458 https_test_server.GetURL("files/hsts-multiple-headers.html"), | 5453 https_test_server.GetURL("files/hsts-multiple-headers.html"), |
| 5459 DEFAULT_PRIORITY, &d)); | 5454 DEFAULT_PRIORITY, &d)); |
| 5460 request->Start(); | 5455 request->Start(); |
| 5461 base::RunLoop().Run(); | 5456 base::RunLoop().Run(); |
| 5462 | 5457 |
| 5463 // We should have set parameters from the first header, not the second. | 5458 // We should have set parameters from the first header, not the second. |
| 5464 TransportSecurityState* security_state = | 5459 TransportSecurityState* security_state = |
| 5465 default_context_.transport_security_state(); | 5460 default_context_.transport_security_state(); |
| 5466 TransportSecurityState::DomainState domain_state; | 5461 TransportSecurityState::DomainState domain_state; |
| 5467 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, | 5462 EXPECT_TRUE(security_state->GetDynamicDomainState(test_server_hostname, |
| 5468 &domain_state)); | 5463 &domain_state)); |
| 5469 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, | 5464 EXPECT_EQ(TransportSecurityState::DomainState::MODE_FORCE_HTTPS, |
| 5470 domain_state.sts.upgrade_mode); | 5465 domain_state.sts.upgrade_mode); |
| 5471 EXPECT_FALSE(domain_state.sts.include_subdomains); | 5466 EXPECT_FALSE(domain_state.sts.include_subdomains); |
| 5472 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5467 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
| 5473 } | 5468 } |
| 5474 | 5469 |
| 5475 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { | 5470 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP) { |
| 5476 SpawnedTestServer::SSLOptions ssl_options( | 5471 SpawnedTestServer::SSLOptions ssl_options( |
| 5477 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5472 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
| 5478 SpawnedTestServer https_test_server( | 5473 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 5479 SpawnedTestServer::TYPE_HTTPS, | 5474 ssl_options, |
| 5480 ssl_options, | 5475 base::FilePath(kTestFilePath)); |
| 5481 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
| 5482 ASSERT_TRUE(https_test_server.Start()); | 5476 ASSERT_TRUE(https_test_server.Start()); |
| 5483 | 5477 |
| 5484 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5478 std::string test_server_hostname = https_test_server.GetURL("").host(); |
| 5485 | 5479 |
| 5486 TestDelegate d; | 5480 TestDelegate d; |
| 5487 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5481 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5488 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), | 5482 https_test_server.GetURL("files/hsts-and-hpkp-headers.html"), |
| 5489 DEFAULT_PRIORITY, &d)); | 5483 DEFAULT_PRIORITY, &d)); |
| 5490 request->Start(); | 5484 request->Start(); |
| 5491 base::RunLoop().Run(); | 5485 base::RunLoop().Run(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 5510 EXPECT_FALSE(domain_state.sts.include_subdomains); | 5504 EXPECT_FALSE(domain_state.sts.include_subdomains); |
| 5511 // includeSubdomains does not occur in the test HPKP header. | 5505 // includeSubdomains does not occur in the test HPKP header. |
| 5512 EXPECT_FALSE(domain_state.pkp.include_subdomains); | 5506 EXPECT_FALSE(domain_state.pkp.include_subdomains); |
| 5513 } | 5507 } |
| 5514 | 5508 |
| 5515 // Tests that when multiple HPKP headers are present, asserting different | 5509 // Tests that when multiple HPKP headers are present, asserting different |
| 5516 // policies, that only the first such policy is processed. | 5510 // policies, that only the first such policy is processed. |
| 5517 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { | 5511 TEST_F(URLRequestTestHTTP, ProcessSTSAndPKP2) { |
| 5518 SpawnedTestServer::SSLOptions ssl_options( | 5512 SpawnedTestServer::SSLOptions ssl_options( |
| 5519 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); | 5513 SpawnedTestServer::SSLOptions::CERT_COMMON_NAME_IS_DOMAIN); |
| 5520 SpawnedTestServer https_test_server( | 5514 SpawnedTestServer https_test_server(SpawnedTestServer::TYPE_HTTPS, |
| 5521 SpawnedTestServer::TYPE_HTTPS, | 5515 ssl_options, |
| 5522 ssl_options, | 5516 base::FilePath(kTestFilePath)); |
| 5523 base::FilePath(FILE_PATH_LITERAL("net/data/url_request_unittest"))); | |
| 5524 ASSERT_TRUE(https_test_server.Start()); | 5517 ASSERT_TRUE(https_test_server.Start()); |
| 5525 | 5518 |
| 5526 std::string test_server_hostname = https_test_server.GetURL("").host(); | 5519 std::string test_server_hostname = https_test_server.GetURL("").host(); |
| 5527 | 5520 |
| 5528 TestDelegate d; | 5521 TestDelegate d; |
| 5529 scoped_ptr<URLRequest> request(default_context_.CreateRequest( | 5522 scoped_ptr<URLRequest> request(default_context_.CreateRequest( |
| 5530 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), | 5523 https_test_server.GetURL("files/hsts-and-hpkp-headers2.html"), |
| 5531 DEFAULT_PRIORITY, &d)); | 5524 DEFAULT_PRIORITY, &d)); |
| 5532 request->Start(); | 5525 request->Start(); |
| 5533 base::RunLoop().Run(); | 5526 base::RunLoop().Run(); |
| (...skipping 500 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6034 | 6027 |
| 6035 req->FollowDeferredRedirect(); | 6028 req->FollowDeferredRedirect(); |
| 6036 base::RunLoop().Run(); | 6029 base::RunLoop().Run(); |
| 6037 | 6030 |
| 6038 EXPECT_EQ(1, d.response_started_count()); | 6031 EXPECT_EQ(1, d.response_started_count()); |
| 6039 EXPECT_FALSE(d.received_data_before_response()); | 6032 EXPECT_FALSE(d.received_data_before_response()); |
| 6040 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6033 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6041 | 6034 |
| 6042 base::FilePath path; | 6035 base::FilePath path; |
| 6043 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 6036 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 6044 path = path.Append(FILE_PATH_LITERAL("net")); | 6037 path = path.Append(kTestFilePath); |
| 6045 path = path.Append(FILE_PATH_LITERAL("data")); | |
| 6046 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | |
| 6047 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 6038 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 6048 | 6039 |
| 6049 std::string contents; | 6040 std::string contents; |
| 6050 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 6041 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 6051 EXPECT_EQ(contents, d.data_received()); | 6042 EXPECT_EQ(contents, d.data_received()); |
| 6052 } | 6043 } |
| 6053 } | 6044 } |
| 6054 | 6045 |
| 6055 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { | 6046 TEST_F(URLRequestTestHTTP, DeferredRedirect_GetFullRequestHeaders) { |
| 6056 ASSERT_TRUE(test_server_.Start()); | 6047 ASSERT_TRUE(test_server_.Start()); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 6077 | 6068 |
| 6078 GURL target_url(test_server_.GetURL("files/with-headers.html")); | 6069 GURL target_url(test_server_.GetURL("files/with-headers.html")); |
| 6079 EXPECT_EQ(1, d.response_started_count()); | 6070 EXPECT_EQ(1, d.response_started_count()); |
| 6080 EXPECT_TRUE(d.have_full_request_headers()); | 6071 EXPECT_TRUE(d.have_full_request_headers()); |
| 6081 CheckFullRequestHeaders(d.full_request_headers(), target_url); | 6072 CheckFullRequestHeaders(d.full_request_headers(), target_url); |
| 6082 EXPECT_FALSE(d.received_data_before_response()); | 6073 EXPECT_FALSE(d.received_data_before_response()); |
| 6083 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); | 6074 EXPECT_EQ(URLRequestStatus::SUCCESS, req->status().status()); |
| 6084 | 6075 |
| 6085 base::FilePath path; | 6076 base::FilePath path; |
| 6086 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 6077 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 6087 path = path.Append(FILE_PATH_LITERAL("net")); | 6078 path = path.Append(kTestFilePath); |
| 6088 path = path.Append(FILE_PATH_LITERAL("data")); | |
| 6089 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | |
| 6090 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 6079 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 6091 | 6080 |
| 6092 std::string contents; | 6081 std::string contents; |
| 6093 EXPECT_TRUE(base::ReadFileToString(path, &contents)); | 6082 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 6094 EXPECT_EQ(contents, d.data_received()); | 6083 EXPECT_EQ(contents, d.data_received()); |
| 6095 } | 6084 } |
| 6096 } | 6085 } |
| 6097 | 6086 |
| 6098 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { | 6087 TEST_F(URLRequestTestHTTP, CancelDeferredRedirect) { |
| 6099 ASSERT_TRUE(test_server_.Start()); | 6088 ASSERT_TRUE(test_server_.Start()); |
| (...skipping 950 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7050 | 7039 |
| 7051 class URLRequestTestReferrerPolicy : public URLRequestTest { | 7040 class URLRequestTestReferrerPolicy : public URLRequestTest { |
| 7052 public: | 7041 public: |
| 7053 URLRequestTestReferrerPolicy() {} | 7042 URLRequestTestReferrerPolicy() {} |
| 7054 | 7043 |
| 7055 void InstantiateSameOriginServers(SpawnedTestServer::Type origin_type) { | 7044 void InstantiateSameOriginServers(SpawnedTestServer::Type origin_type) { |
| 7056 origin_server_.reset(new SpawnedTestServer( | 7045 origin_server_.reset(new SpawnedTestServer( |
| 7057 origin_type, SpawnedTestServer::kLocalhost, | 7046 origin_type, SpawnedTestServer::kLocalhost, |
| 7058 origin_type == SpawnedTestServer::TYPE_HTTPS | 7047 origin_type == SpawnedTestServer::TYPE_HTTPS |
| 7059 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) | 7048 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) |
| 7060 : base::FilePath( | 7049 : base::FilePath(kTestFilePath))); |
| 7061 FILE_PATH_LITERAL("net/data/url_request_unittest")))); | |
| 7062 ASSERT_TRUE(origin_server_->Start()); | 7050 ASSERT_TRUE(origin_server_->Start()); |
| 7063 } | 7051 } |
| 7064 | 7052 |
| 7065 void InstantiateCrossOriginServers(SpawnedTestServer::Type origin_type, | 7053 void InstantiateCrossOriginServers(SpawnedTestServer::Type origin_type, |
| 7066 SpawnedTestServer::Type destination_type) { | 7054 SpawnedTestServer::Type destination_type) { |
| 7067 origin_server_.reset(new SpawnedTestServer( | 7055 origin_server_.reset(new SpawnedTestServer( |
| 7068 origin_type, SpawnedTestServer::kLocalhost, | 7056 origin_type, SpawnedTestServer::kLocalhost, |
| 7069 origin_type == SpawnedTestServer::TYPE_HTTPS | 7057 origin_type == SpawnedTestServer::TYPE_HTTPS |
| 7070 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) | 7058 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) |
| 7071 : base::FilePath( | 7059 : base::FilePath(kTestFilePath))); |
| 7072 FILE_PATH_LITERAL("net/data/url_request_unittest")))); | |
| 7073 ASSERT_TRUE(origin_server_->Start()); | 7060 ASSERT_TRUE(origin_server_->Start()); |
| 7074 | 7061 |
| 7075 destination_server_.reset(new SpawnedTestServer( | 7062 destination_server_.reset(new SpawnedTestServer( |
| 7076 destination_type, SpawnedTestServer::kLocalhost, | 7063 destination_type, SpawnedTestServer::kLocalhost, |
| 7077 destination_type == SpawnedTestServer::TYPE_HTTPS | 7064 destination_type == SpawnedTestServer::TYPE_HTTPS |
| 7078 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) | 7065 ? base::FilePath(FILE_PATH_LITERAL("net/data/ssl")) |
| 7079 : base::FilePath( | 7066 : base::FilePath(kTestFilePath))); |
| 7080 FILE_PATH_LITERAL("net/data/url_request_unittest")))); | |
| 7081 ASSERT_TRUE(destination_server_->Start()); | 7067 ASSERT_TRUE(destination_server_->Start()); |
| 7082 } | 7068 } |
| 7083 | 7069 |
| 7084 void VerifyReferrerAfterRedirect(URLRequest::ReferrerPolicy policy, | 7070 void VerifyReferrerAfterRedirect(URLRequest::ReferrerPolicy policy, |
| 7085 const GURL& referrer, | 7071 const GURL& referrer, |
| 7086 const GURL& expected) { | 7072 const GURL& expected) { |
| 7087 // Create and execute the request: we'll only have a |destination_server_| | 7073 // Create and execute the request: we'll only have a |destination_server_| |
| 7088 // if the origins are meant to be distinct. Otherwise, we'll use the | 7074 // if the origins are meant to be distinct. Otherwise, we'll use the |
| 7089 // |origin_server_| for both endpoints. | 7075 // |origin_server_| for both endpoints. |
| 7090 GURL destination_url = | 7076 GURL destination_url = |
| (...skipping 1750 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 8841 | 8827 |
| 8842 // If the certificate is recorded as revoked in the CRLSet, that should be | 8828 // If the certificate is recorded as revoked in the CRLSet, that should be |
| 8843 // reflected without online revocation checking. | 8829 // reflected without online revocation checking. |
| 8844 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); | 8830 EXPECT_EQ(CERT_STATUS_REVOKED, cert_status & CERT_STATUS_ALL_ERRORS); |
| 8845 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); | 8831 EXPECT_FALSE(cert_status & CERT_STATUS_IS_EV); |
| 8846 EXPECT_FALSE( | 8832 EXPECT_FALSE( |
| 8847 static_cast<bool>(cert_status & CERT_STATUS_REV_CHECKING_ENABLED)); | 8833 static_cast<bool>(cert_status & CERT_STATUS_REV_CHECKING_ENABLED)); |
| 8848 } | 8834 } |
| 8849 #endif // !defined(OS_IOS) | 8835 #endif // !defined(OS_IOS) |
| 8850 | 8836 |
| 8851 #if !defined(DISABLE_FTP_SUPPORT) | 8837 #if !defined(DISABLE_FTP_SUPPORT) && !defined(OS_ANDROID) |
| 8838 // These tests aren't passing on Android. Either the RemoteTestServer isn't |
| 8839 // starting up successfully, or it can't access the test files. |
| 8840 // TODO(mmenke): Fix this. See http://crbug.com/495220 |
| 8852 class URLRequestTestFTP : public URLRequestTest { | 8841 class URLRequestTestFTP : public URLRequestTest { |
| 8853 public: | 8842 public: |
| 8854 URLRequestTestFTP() | 8843 URLRequestTestFTP() |
| 8855 : test_server_(SpawnedTestServer::TYPE_FTP, SpawnedTestServer::kLocalhost, | 8844 : ftp_transaction_factory_(&host_resolver_), |
| 8856 base::FilePath()) { | 8845 test_server_(SpawnedTestServer::TYPE_FTP, |
| 8846 SpawnedTestServer::kLocalhost, |
| 8847 base::FilePath(kTestFilePath)) { |
| 8848 // Can't use |default_context_|'s HostResolver to set up the |
| 8849 // FTPTransactionFactory because it hasn't been created yet. |
| 8850 default_context_.set_host_resolver(&host_resolver_); |
| 8851 } |
| 8852 |
| 8853 // URLRequestTest interface: |
| 8854 void SetUpFactory() override { |
| 8855 // Add FTP support to the default URLRequestContext. |
| 8856 job_factory_impl_->SetProtocolHandler( |
| 8857 "ftp", new FtpProtocolHandler(&ftp_transaction_factory_)); |
| 8858 } |
| 8859 |
| 8860 std::string GetTestFileContents() { |
| 8861 base::FilePath path; |
| 8862 EXPECT_TRUE(PathService::Get(base::DIR_SOURCE_ROOT, &path)); |
| 8863 path = path.Append(kTestFilePath); |
| 8864 path = path.AppendASCII(kFtpTestFile); |
| 8865 std::string contents; |
| 8866 EXPECT_TRUE(base::ReadFileToString(path, &contents)); |
| 8867 return contents; |
| 8857 } | 8868 } |
| 8858 | 8869 |
| 8859 protected: | 8870 protected: |
| 8871 MockHostResolver host_resolver_; |
| 8872 FtpNetworkLayer ftp_transaction_factory_; |
| 8873 |
| 8860 SpawnedTestServer test_server_; | 8874 SpawnedTestServer test_server_; |
| 8861 }; | 8875 }; |
| 8862 | 8876 |
| 8863 // Make sure an FTP request using an unsafe ports fails. | 8877 // Make sure an FTP request using an unsafe ports fails. |
| 8864 TEST_F(URLRequestTestFTP, UnsafePort) { | 8878 TEST_F(URLRequestTestFTP, UnsafePort) { |
| 8865 ASSERT_TRUE(test_server_.Start()); | |
| 8866 | |
| 8867 URLRequestJobFactoryImpl job_factory; | |
| 8868 FtpNetworkLayer ftp_transaction_factory(default_context_.host_resolver()); | |
| 8869 | |
| 8870 GURL url("ftp://127.0.0.1:7"); | 8879 GURL url("ftp://127.0.0.1:7"); |
| 8871 job_factory.SetProtocolHandler( | |
| 8872 "ftp", | |
| 8873 new FtpProtocolHandler(&ftp_transaction_factory)); | |
| 8874 default_context_.set_job_factory(&job_factory); | |
| 8875 | 8880 |
| 8876 TestDelegate d; | 8881 TestDelegate d; |
| 8877 { | 8882 { |
| 8878 scoped_ptr<URLRequest> r( | 8883 scoped_ptr<URLRequest> r( |
| 8879 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); | 8884 default_context_.CreateRequest(url, DEFAULT_PRIORITY, &d)); |
| 8880 r->Start(); | 8885 r->Start(); |
| 8881 EXPECT_TRUE(r->is_pending()); | 8886 EXPECT_TRUE(r->is_pending()); |
| 8882 | 8887 |
| 8883 base::RunLoop().Run(); | 8888 base::RunLoop().Run(); |
| 8884 | 8889 |
| 8885 EXPECT_FALSE(r->is_pending()); | 8890 EXPECT_FALSE(r->is_pending()); |
| 8886 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); | 8891 EXPECT_EQ(URLRequestStatus::FAILED, r->status().status()); |
| 8887 EXPECT_EQ(ERR_UNSAFE_PORT, r->status().error()); | 8892 EXPECT_EQ(ERR_UNSAFE_PORT, r->status().error()); |
| 8888 } | 8893 } |
| 8889 } | 8894 } |
| 8890 | 8895 |
| 8891 // Flaky, see http://crbug.com/25045. | 8896 TEST_F(URLRequestTestFTP, FTPDirectoryListing) { |
| 8892 TEST_F(URLRequestTestFTP, DISABLED_FTPDirectoryListing) { | |
| 8893 ASSERT_TRUE(test_server_.Start()); | 8897 ASSERT_TRUE(test_server_.Start()); |
| 8894 | 8898 |
| 8895 TestDelegate d; | 8899 TestDelegate d; |
| 8896 { | 8900 { |
| 8897 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 8901 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8898 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d)); | 8902 test_server_.GetURL("/"), DEFAULT_PRIORITY, &d)); |
| 8899 r->Start(); | 8903 r->Start(); |
| 8900 EXPECT_TRUE(r->is_pending()); | 8904 EXPECT_TRUE(r->is_pending()); |
| 8901 | 8905 |
| 8902 base::RunLoop().Run(); | 8906 base::RunLoop().Run(); |
| 8903 | 8907 |
| 8904 EXPECT_FALSE(r->is_pending()); | 8908 EXPECT_FALSE(r->is_pending()); |
| 8905 EXPECT_EQ(1, d.response_started_count()); | 8909 EXPECT_EQ(1, d.response_started_count()); |
| 8906 EXPECT_FALSE(d.received_data_before_response()); | 8910 EXPECT_FALSE(d.received_data_before_response()); |
| 8907 EXPECT_LT(0, d.bytes_received()); | 8911 EXPECT_LT(0, d.bytes_received()); |
| 8908 EXPECT_EQ(test_server_.host_port_pair().host(), | 8912 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 8909 r->GetSocketAddress().host()); | 8913 r->GetSocketAddress().host()); |
| 8910 EXPECT_EQ(test_server_.host_port_pair().port(), | 8914 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 8911 r->GetSocketAddress().port()); | 8915 r->GetSocketAddress().port()); |
| 8912 } | 8916 } |
| 8913 } | 8917 } |
| 8914 | 8918 |
| 8915 // Flaky, see http://crbug.com/25045. | 8919 TEST_F(URLRequestTestFTP, FTPGetTestAnonymous) { |
| 8916 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTestAnonymous) { | |
| 8917 ASSERT_TRUE(test_server_.Start()); | 8920 ASSERT_TRUE(test_server_.Start()); |
| 8918 | 8921 |
| 8919 base::FilePath app_path; | |
| 8920 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
| 8921 app_path = app_path.AppendASCII("LICENSE"); | |
| 8922 TestDelegate d; | 8922 TestDelegate d; |
| 8923 { | 8923 { |
| 8924 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 8924 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8925 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, &d)); | 8925 test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, &d)); |
| 8926 r->Start(); | 8926 r->Start(); |
| 8927 EXPECT_TRUE(r->is_pending()); | 8927 EXPECT_TRUE(r->is_pending()); |
| 8928 | 8928 |
| 8929 base::RunLoop().Run(); | 8929 base::RunLoop().Run(); |
| 8930 | 8930 |
| 8931 int64 file_size = 0; | |
| 8932 base::GetFileSize(app_path, &file_size); | |
| 8933 | |
| 8934 EXPECT_FALSE(r->is_pending()); | 8931 EXPECT_FALSE(r->is_pending()); |
| 8935 EXPECT_EQ(1, d.response_started_count()); | 8932 EXPECT_EQ(1, d.response_started_count()); |
| 8936 EXPECT_FALSE(d.received_data_before_response()); | 8933 EXPECT_FALSE(d.received_data_before_response()); |
| 8937 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 8934 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 8938 EXPECT_EQ(test_server_.host_port_pair().host(), | 8935 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 8939 r->GetSocketAddress().host()); | 8936 r->GetSocketAddress().host()); |
| 8940 EXPECT_EQ(test_server_.host_port_pair().port(), | 8937 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 8941 r->GetSocketAddress().port()); | 8938 r->GetSocketAddress().port()); |
| 8942 } | 8939 } |
| 8943 } | 8940 } |
| 8944 | 8941 |
| 8945 // Flaky, see http://crbug.com/25045. | 8942 TEST_F(URLRequestTestFTP, FTPGetTest) { |
| 8946 TEST_F(URLRequestTestFTP, DISABLED_FTPGetTest) { | |
| 8947 ASSERT_TRUE(test_server_.Start()); | 8943 ASSERT_TRUE(test_server_.Start()); |
| 8948 | 8944 |
| 8949 base::FilePath app_path; | |
| 8950 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
| 8951 app_path = app_path.AppendASCII("LICENSE"); | |
| 8952 TestDelegate d; | 8945 TestDelegate d; |
| 8953 { | 8946 { |
| 8954 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 8947 scoped_ptr<URLRequest> r( |
| 8955 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 8948 default_context_.CreateRequest(test_server_.GetURLWithUserAndPassword( |
| 8956 DEFAULT_PRIORITY, &d)); | 8949 kFtpTestFile, "chrome", "chrome"), |
| 8950 DEFAULT_PRIORITY, &d)); |
| 8957 r->Start(); | 8951 r->Start(); |
| 8958 EXPECT_TRUE(r->is_pending()); | 8952 EXPECT_TRUE(r->is_pending()); |
| 8959 | 8953 |
| 8960 base::RunLoop().Run(); | 8954 base::RunLoop().Run(); |
| 8961 | 8955 |
| 8962 int64 file_size = 0; | |
| 8963 base::GetFileSize(app_path, &file_size); | |
| 8964 | |
| 8965 EXPECT_FALSE(r->is_pending()); | 8956 EXPECT_FALSE(r->is_pending()); |
| 8957 EXPECT_EQ(1, d.response_started_count()); |
| 8958 EXPECT_FALSE(d.received_data_before_response()); |
| 8959 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 8966 EXPECT_EQ(test_server_.host_port_pair().host(), | 8960 EXPECT_EQ(test_server_.host_port_pair().host(), |
| 8967 r->GetSocketAddress().host()); | 8961 r->GetSocketAddress().host()); |
| 8968 EXPECT_EQ(test_server_.host_port_pair().port(), | 8962 EXPECT_EQ(test_server_.host_port_pair().port(), |
| 8969 r->GetSocketAddress().port()); | 8963 r->GetSocketAddress().port()); |
| 8970 EXPECT_EQ(1, d.response_started_count()); | |
| 8971 EXPECT_FALSE(d.received_data_before_response()); | |
| 8972 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | |
| 8973 | 8964 |
| 8974 LoadTimingInfo load_timing_info; | 8965 LoadTimingInfo load_timing_info; |
| 8975 r->GetLoadTimingInfo(&load_timing_info); | 8966 r->GetLoadTimingInfo(&load_timing_info); |
| 8976 TestLoadTimingNoHttpResponse(load_timing_info); | 8967 TestLoadTimingNoHttpResponse(load_timing_info); |
| 8977 } | 8968 } |
| 8978 } | 8969 } |
| 8979 | 8970 |
| 8980 // Flaky, see http://crbug.com/25045. | 8971 TEST_F(URLRequestTestFTP, FTPCheckWrongPassword) { |
| 8981 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPassword) { | |
| 8982 ASSERT_TRUE(test_server_.Start()); | 8972 ASSERT_TRUE(test_server_.Start()); |
| 8983 | 8973 |
| 8984 base::FilePath app_path; | |
| 8985 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
| 8986 app_path = app_path.AppendASCII("LICENSE"); | |
| 8987 TestDelegate d; | 8974 TestDelegate d; |
| 8988 { | 8975 { |
| 8989 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 8976 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 8990 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", | 8977 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 8991 "wrong_password"), | 8978 "wrong_password"), |
| 8992 DEFAULT_PRIORITY, &d)); | 8979 DEFAULT_PRIORITY, &d)); |
| 8993 r->Start(); | 8980 r->Start(); |
| 8994 EXPECT_TRUE(r->is_pending()); | 8981 EXPECT_TRUE(r->is_pending()); |
| 8995 | 8982 |
| 8996 base::RunLoop().Run(); | 8983 base::RunLoop().Run(); |
| 8997 | 8984 |
| 8998 int64 file_size = 0; | |
| 8999 base::GetFileSize(app_path, &file_size); | |
| 9000 | |
| 9001 EXPECT_FALSE(r->is_pending()); | 8985 EXPECT_FALSE(r->is_pending()); |
| 9002 EXPECT_EQ(1, d.response_started_count()); | 8986 EXPECT_EQ(1, d.response_started_count()); |
| 9003 EXPECT_FALSE(d.received_data_before_response()); | 8987 EXPECT_FALSE(d.received_data_before_response()); |
| 9004 EXPECT_EQ(d.bytes_received(), 0); | 8988 EXPECT_EQ(d.bytes_received(), 0); |
| 9005 } | 8989 } |
| 9006 } | 8990 } |
| 9007 | 8991 |
| 9008 // Flaky, see http://crbug.com/25045. | 8992 TEST_F(URLRequestTestFTP, FTPCheckWrongPasswordRestart) { |
| 9009 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongPasswordRestart) { | |
| 9010 ASSERT_TRUE(test_server_.Start()); | 8993 ASSERT_TRUE(test_server_.Start()); |
| 9011 | 8994 |
| 9012 base::FilePath app_path; | |
| 9013 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
| 9014 app_path = app_path.AppendASCII("LICENSE"); | |
| 9015 TestDelegate d; | 8995 TestDelegate d; |
| 9016 // Set correct login credentials. The delegate will be asked for them when | 8996 // Set correct login credentials. The delegate will be asked for them when |
| 9017 // the initial login with wrong credentials will fail. | 8997 // the initial login with wrong credentials will fail. |
| 9018 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 8998 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 9019 { | 8999 { |
| 9020 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9000 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9021 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", | 9001 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 9022 "wrong_password"), | 9002 "wrong_password"), |
| 9023 DEFAULT_PRIORITY, &d)); | 9003 DEFAULT_PRIORITY, &d)); |
| 9024 r->Start(); | 9004 r->Start(); |
| 9025 EXPECT_TRUE(r->is_pending()); | 9005 EXPECT_TRUE(r->is_pending()); |
| 9026 | 9006 |
| 9027 base::RunLoop().Run(); | 9007 base::RunLoop().Run(); |
| 9028 | 9008 |
| 9029 int64 file_size = 0; | |
| 9030 base::GetFileSize(app_path, &file_size); | |
| 9031 | |
| 9032 EXPECT_FALSE(r->is_pending()); | 9009 EXPECT_FALSE(r->is_pending()); |
| 9033 EXPECT_EQ(1, d.response_started_count()); | 9010 EXPECT_EQ(1, d.response_started_count()); |
| 9034 EXPECT_FALSE(d.received_data_before_response()); | 9011 EXPECT_FALSE(d.received_data_before_response()); |
| 9035 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 9012 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 9036 } | 9013 } |
| 9037 } | 9014 } |
| 9038 | 9015 |
| 9039 // Flaky, see http://crbug.com/25045. | 9016 TEST_F(URLRequestTestFTP, FTPCheckWrongUser) { |
| 9040 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUser) { | |
| 9041 ASSERT_TRUE(test_server_.Start()); | 9017 ASSERT_TRUE(test_server_.Start()); |
| 9042 | 9018 |
| 9043 base::FilePath app_path; | |
| 9044 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
| 9045 app_path = app_path.AppendASCII("LICENSE"); | |
| 9046 TestDelegate d; | 9019 TestDelegate d; |
| 9047 { | 9020 { |
| 9048 scoped_ptr<URLRequest> r( | 9021 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9049 default_context_.CreateRequest(test_server_.GetURLWithUserAndPassword( | 9022 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", |
| 9050 "/LICENSE", "wrong_user", "chrome"), | 9023 "chrome"), |
| 9051 DEFAULT_PRIORITY, &d)); | 9024 DEFAULT_PRIORITY, &d)); |
| 9052 r->Start(); | 9025 r->Start(); |
| 9053 EXPECT_TRUE(r->is_pending()); | 9026 EXPECT_TRUE(r->is_pending()); |
| 9054 | 9027 |
| 9055 base::RunLoop().Run(); | 9028 base::RunLoop().Run(); |
| 9056 | 9029 |
| 9057 int64 file_size = 0; | |
| 9058 base::GetFileSize(app_path, &file_size); | |
| 9059 | |
| 9060 EXPECT_FALSE(r->is_pending()); | 9030 EXPECT_FALSE(r->is_pending()); |
| 9061 EXPECT_EQ(1, d.response_started_count()); | 9031 EXPECT_EQ(1, d.response_started_count()); |
| 9062 EXPECT_FALSE(d.received_data_before_response()); | 9032 EXPECT_FALSE(d.received_data_before_response()); |
| 9063 EXPECT_EQ(d.bytes_received(), 0); | 9033 EXPECT_EQ(0, d.bytes_received()); |
| 9064 } | 9034 } |
| 9065 } | 9035 } |
| 9066 | 9036 |
| 9067 // Flaky, see http://crbug.com/25045. | 9037 TEST_F(URLRequestTestFTP, FTPCheckWrongUserRestart) { |
| 9068 TEST_F(URLRequestTestFTP, DISABLED_FTPCheckWrongUserRestart) { | |
| 9069 ASSERT_TRUE(test_server_.Start()); | 9038 ASSERT_TRUE(test_server_.Start()); |
| 9070 | 9039 |
| 9071 base::FilePath app_path; | |
| 9072 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
| 9073 app_path = app_path.AppendASCII("LICENSE"); | |
| 9074 TestDelegate d; | 9040 TestDelegate d; |
| 9075 // Set correct login credentials. The delegate will be asked for them when | 9041 // Set correct login credentials. The delegate will be asked for them when |
| 9076 // the initial login with wrong credentials will fail. | 9042 // the initial login with wrong credentials will fail. |
| 9077 d.set_credentials(AuthCredentials(kChrome, kChrome)); | 9043 d.set_credentials(AuthCredentials(kChrome, kChrome)); |
| 9078 { | 9044 { |
| 9079 scoped_ptr<URLRequest> r( | 9045 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9080 default_context_.CreateRequest(test_server_.GetURLWithUserAndPassword( | 9046 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "wrong_user", |
| 9081 "/LICENSE", "wrong_user", "chrome"), | 9047 "chrome"), |
| 9082 DEFAULT_PRIORITY, &d)); | 9048 DEFAULT_PRIORITY, &d)); |
| 9083 r->Start(); | 9049 r->Start(); |
| 9084 EXPECT_TRUE(r->is_pending()); | 9050 EXPECT_TRUE(r->is_pending()); |
| 9085 | 9051 |
| 9086 base::RunLoop().Run(); | 9052 base::RunLoop().Run(); |
| 9087 | 9053 |
| 9088 int64 file_size = 0; | |
| 9089 base::GetFileSize(app_path, &file_size); | |
| 9090 | |
| 9091 EXPECT_FALSE(r->is_pending()); | 9054 EXPECT_FALSE(r->is_pending()); |
| 9092 EXPECT_EQ(1, d.response_started_count()); | 9055 EXPECT_EQ(1, d.response_started_count()); |
| 9093 EXPECT_FALSE(d.received_data_before_response()); | 9056 EXPECT_FALSE(d.received_data_before_response()); |
| 9094 EXPECT_EQ(d.bytes_received(), static_cast<int>(file_size)); | 9057 EXPECT_EQ(GetTestFileContents(), d.data_received()); |
| 9095 } | 9058 } |
| 9096 } | 9059 } |
| 9097 | 9060 |
| 9098 // Flaky, see http://crbug.com/25045. | 9061 TEST_F(URLRequestTestFTP, FTPCacheURLCredentials) { |
| 9099 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheURLCredentials) { | |
| 9100 ASSERT_TRUE(test_server_.Start()); | 9062 ASSERT_TRUE(test_server_.Start()); |
| 9101 | 9063 |
| 9102 base::FilePath app_path; | |
| 9103 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
| 9104 app_path = app_path.AppendASCII("LICENSE"); | |
| 9105 | |
| 9106 scoped_ptr<TestDelegate> d(new TestDelegate); | 9064 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 9107 { | 9065 { |
| 9108 // Pass correct login identity in the URL. | 9066 // Pass correct login identity in the URL. |
| 9109 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9067 scoped_ptr<URLRequest> r( |
| 9110 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", "chrome"), | 9068 default_context_.CreateRequest(test_server_.GetURLWithUserAndPassword( |
| 9111 DEFAULT_PRIORITY, d.get())); | 9069 kFtpTestFile, "chrome", "chrome"), |
| 9070 DEFAULT_PRIORITY, d.get())); |
| 9112 r->Start(); | 9071 r->Start(); |
| 9113 EXPECT_TRUE(r->is_pending()); | 9072 EXPECT_TRUE(r->is_pending()); |
| 9114 | 9073 |
| 9115 base::RunLoop().Run(); | 9074 base::RunLoop().Run(); |
| 9116 | 9075 |
| 9117 int64 file_size = 0; | |
| 9118 base::GetFileSize(app_path, &file_size); | |
| 9119 | |
| 9120 EXPECT_FALSE(r->is_pending()); | 9076 EXPECT_FALSE(r->is_pending()); |
| 9121 EXPECT_EQ(1, d->response_started_count()); | 9077 EXPECT_EQ(1, d->response_started_count()); |
| 9122 EXPECT_FALSE(d->received_data_before_response()); | 9078 EXPECT_FALSE(d->received_data_before_response()); |
| 9123 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 9079 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 9124 } | 9080 } |
| 9125 | 9081 |
| 9126 d.reset(new TestDelegate); | 9082 d.reset(new TestDelegate); |
| 9127 { | 9083 { |
| 9128 // This request should use cached identity from previous request. | 9084 // This request should use cached identity from previous request. |
| 9129 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9085 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9130 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get())); | 9086 test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get())); |
| 9131 r->Start(); | 9087 r->Start(); |
| 9132 EXPECT_TRUE(r->is_pending()); | 9088 EXPECT_TRUE(r->is_pending()); |
| 9133 | 9089 |
| 9134 base::RunLoop().Run(); | 9090 base::RunLoop().Run(); |
| 9135 | 9091 |
| 9136 int64 file_size = 0; | |
| 9137 base::GetFileSize(app_path, &file_size); | |
| 9138 | |
| 9139 EXPECT_FALSE(r->is_pending()); | 9092 EXPECT_FALSE(r->is_pending()); |
| 9140 EXPECT_EQ(1, d->response_started_count()); | 9093 EXPECT_EQ(1, d->response_started_count()); |
| 9141 EXPECT_FALSE(d->received_data_before_response()); | 9094 EXPECT_FALSE(d->received_data_before_response()); |
| 9142 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 9095 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 9143 } | 9096 } |
| 9144 } | 9097 } |
| 9145 | 9098 |
| 9146 // Flaky, see http://crbug.com/25045. | 9099 TEST_F(URLRequestTestFTP, FTPCacheLoginBoxCredentials) { |
| 9147 TEST_F(URLRequestTestFTP, DISABLED_FTPCacheLoginBoxCredentials) { | |
| 9148 ASSERT_TRUE(test_server_.Start()); | 9100 ASSERT_TRUE(test_server_.Start()); |
| 9149 | 9101 |
| 9150 base::FilePath app_path; | |
| 9151 PathService::Get(base::DIR_SOURCE_ROOT, &app_path); | |
| 9152 app_path = app_path.AppendASCII("LICENSE"); | |
| 9153 | |
| 9154 scoped_ptr<TestDelegate> d(new TestDelegate); | 9102 scoped_ptr<TestDelegate> d(new TestDelegate); |
| 9155 // Set correct login credentials. The delegate will be asked for them when | 9103 // Set correct login credentials. The delegate will be asked for them when |
| 9156 // the initial login with wrong credentials will fail. | 9104 // the initial login with wrong credentials will fail. |
| 9157 d->set_credentials(AuthCredentials(kChrome, kChrome)); | 9105 d->set_credentials(AuthCredentials(kChrome, kChrome)); |
| 9158 { | 9106 { |
| 9159 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9107 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9160 test_server_.GetURLWithUserAndPassword("/LICENSE", "chrome", | 9108 test_server_.GetURLWithUserAndPassword(kFtpTestFile, "chrome", |
| 9161 "wrong_password"), | 9109 "wrong_password"), |
| 9162 DEFAULT_PRIORITY, d.get())); | 9110 DEFAULT_PRIORITY, d.get())); |
| 9163 r->Start(); | 9111 r->Start(); |
| 9164 EXPECT_TRUE(r->is_pending()); | 9112 EXPECT_TRUE(r->is_pending()); |
| 9165 | 9113 |
| 9166 base::RunLoop().Run(); | 9114 base::RunLoop().Run(); |
| 9167 | 9115 |
| 9168 int64 file_size = 0; | |
| 9169 base::GetFileSize(app_path, &file_size); | |
| 9170 | |
| 9171 EXPECT_FALSE(r->is_pending()); | 9116 EXPECT_FALSE(r->is_pending()); |
| 9172 EXPECT_EQ(1, d->response_started_count()); | 9117 EXPECT_EQ(1, d->response_started_count()); |
| 9173 EXPECT_FALSE(d->received_data_before_response()); | 9118 EXPECT_FALSE(d->received_data_before_response()); |
| 9174 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 9119 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 9175 } | 9120 } |
| 9176 | 9121 |
| 9177 // Use a new delegate without explicit credentials. The cached ones should be | 9122 // Use a new delegate without explicit credentials. The cached ones should be |
| 9178 // used. | 9123 // used. |
| 9179 d.reset(new TestDelegate); | 9124 d.reset(new TestDelegate); |
| 9180 { | 9125 { |
| 9181 // Don't pass wrong credentials in the URL, they would override valid cached | 9126 // Don't pass wrong credentials in the URL, they would override valid cached |
| 9182 // ones. | 9127 // ones. |
| 9183 scoped_ptr<URLRequest> r(default_context_.CreateRequest( | 9128 scoped_ptr<URLRequest> r(default_context_.CreateRequest( |
| 9184 test_server_.GetURL("/LICENSE"), DEFAULT_PRIORITY, d.get())); | 9129 test_server_.GetURL(kFtpTestFile), DEFAULT_PRIORITY, d.get())); |
| 9185 r->Start(); | 9130 r->Start(); |
| 9186 EXPECT_TRUE(r->is_pending()); | 9131 EXPECT_TRUE(r->is_pending()); |
| 9187 | 9132 |
| 9188 base::RunLoop().Run(); | 9133 base::RunLoop().Run(); |
| 9189 | 9134 |
| 9190 int64 file_size = 0; | |
| 9191 base::GetFileSize(app_path, &file_size); | |
| 9192 | |
| 9193 EXPECT_FALSE(r->is_pending()); | 9135 EXPECT_FALSE(r->is_pending()); |
| 9194 EXPECT_EQ(1, d->response_started_count()); | 9136 EXPECT_EQ(1, d->response_started_count()); |
| 9195 EXPECT_FALSE(d->received_data_before_response()); | 9137 EXPECT_FALSE(d->received_data_before_response()); |
| 9196 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 9138 EXPECT_EQ(GetTestFileContents(), d->data_received()); |
| 9197 } | 9139 } |
| 9198 } | 9140 } |
| 9199 #endif // !defined(DISABLE_FTP_SUPPORT) | 9141 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 9200 | 9142 |
| 9201 TEST_F(URLRequestTest, NetworkAccessedClearBeforeNetworkStart) { | 9143 TEST_F(URLRequestTest, NetworkAccessedClearBeforeNetworkStart) { |
| 9202 TestDelegate d; | 9144 TestDelegate d; |
| 9203 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | 9145 scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
| 9204 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 9146 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); |
| 9205 d.set_quit_on_network_start(true); | 9147 d.set_quit_on_network_start(true); |
| 9206 | 9148 |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9245 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 9187 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); |
| 9246 | 9188 |
| 9247 EXPECT_FALSE(req->response_info().network_accessed); | 9189 EXPECT_FALSE(req->response_info().network_accessed); |
| 9248 | 9190 |
| 9249 req->Start(); | 9191 req->Start(); |
| 9250 base::RunLoop().Run(); | 9192 base::RunLoop().Run(); |
| 9251 EXPECT_TRUE(req->response_info().network_accessed); | 9193 EXPECT_TRUE(req->response_info().network_accessed); |
| 9252 } | 9194 } |
| 9253 | 9195 |
| 9254 } // namespace net | 9196 } // namespace net |
| OLD | NEW |