Chromium Code Reviews| 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 |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 32 #include "net/base/load_flags.h" | 32 #include "net/base/load_flags.h" |
| 33 #include "net/base/mock_host_resolver.h" | 33 #include "net/base/mock_host_resolver.h" |
| 34 #include "net/base/net_errors.h" | 34 #include "net/base/net_errors.h" |
| 35 #include "net/base/net_log.h" | 35 #include "net/base/net_log.h" |
| 36 #include "net/base/net_log_unittest.h" | 36 #include "net/base/net_log_unittest.h" |
| 37 #include "net/base/net_module.h" | 37 #include "net/base/net_module.h" |
| 38 #include "net/base/net_util.h" | 38 #include "net/base/net_util.h" |
| 39 #include "net/base/ssl_connection_status_flags.h" | 39 #include "net/base/ssl_connection_status_flags.h" |
| 40 #include "net/base/test_data_directory.h" | 40 #include "net/base/test_data_directory.h" |
| 41 #include "net/base/test_root_certs.h" | 41 #include "net/base/test_root_certs.h" |
| 42 #include "net/base/upload_data.h" | 42 #include "net/base/upload_bytes_element_reader.h" |
| 43 #include "net/base/upload_data_stream.h" | |
| 44 #include "net/base/upload_file_element_reader.h" | |
| 43 #include "net/cookies/cookie_monster.h" | 45 #include "net/cookies/cookie_monster.h" |
| 44 #include "net/cookies/cookie_store_test_helpers.h" | 46 #include "net/cookies/cookie_store_test_helpers.h" |
| 45 #include "net/disk_cache/disk_cache.h" | 47 #include "net/disk_cache/disk_cache.h" |
| 46 #include "net/ftp/ftp_network_layer.h" | 48 #include "net/ftp/ftp_network_layer.h" |
| 47 #include "net/http/http_cache.h" | 49 #include "net/http/http_cache.h" |
| 48 #include "net/http/http_network_layer.h" | 50 #include "net/http/http_network_layer.h" |
| 49 #include "net/http/http_network_session.h" | 51 #include "net/http/http_network_session.h" |
| 50 #include "net/http/http_request_headers.h" | 52 #include "net/http/http_request_headers.h" |
| 51 #include "net/http/http_response_headers.h" | 53 #include "net/http/http_response_headers.h" |
| 52 #include "net/ocsp/nss_ocsp.h" | 54 #include "net/ocsp/nss_ocsp.h" |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 srand(seed); | 105 srand(seed); |
| 104 } | 106 } |
| 105 | 107 |
| 106 for (size_t i = 0; i < len; i++) { | 108 for (size_t i = 0; i < len; i++) { |
| 107 buffer[i] = static_cast<char>(rand()); | 109 buffer[i] = static_cast<char>(rand()); |
| 108 if (!buffer[i]) | 110 if (!buffer[i]) |
| 109 buffer[i] = 'g'; | 111 buffer[i] = 'g'; |
| 110 } | 112 } |
| 111 } | 113 } |
| 112 | 114 |
| 113 scoped_refptr<UploadData> CreateSimpleUploadData(const char* data) { | 115 UploadDataStream* CreateSimpleUploadData(const char* data) { |
| 114 scoped_refptr<UploadData> upload(new UploadData); | 116 ScopedVector<UploadElementReader> element_readers; |
| 115 upload->AppendBytes(data, strlen(data)); | 117 element_readers.push_back(new UploadBytesElementReader(data, strlen(data))); |
| 116 return upload; | 118 return new UploadDataStream(&element_readers, 0); |
| 117 } | 119 } |
| 118 | 120 |
| 119 // Verify that the SSLInfo of a successful SSL connection has valid values. | 121 // Verify that the SSLInfo of a successful SSL connection has valid values. |
| 120 void CheckSSLInfo(const SSLInfo& ssl_info) { | 122 void CheckSSLInfo(const SSLInfo& ssl_info) { |
| 121 // Allow ChromeFrame fake SSLInfo to get through. | 123 // Allow ChromeFrame fake SSLInfo to get through. |
| 122 if (ssl_info.cert.get() && | 124 if (ssl_info.cert.get() && |
| 123 ssl_info.cert.get()->issuer().GetDisplayName() == "Chrome Internal") { | 125 ssl_info.cert.get()->issuer().GetDisplayName() == "Chrome Internal") { |
| 124 // -1 means unknown. | 126 // -1 means unknown. |
| 125 EXPECT_EQ(ssl_info.security_bits, -1); | 127 EXPECT_EQ(ssl_info.security_bits, -1); |
| 126 return; | 128 return; |
| (...skipping 1775 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1902 // |request_method| == |redirect_method|. | 1904 // |request_method| == |redirect_method|. |
| 1903 void HTTPRedirectMethodTest(const GURL& redirect_url, | 1905 void HTTPRedirectMethodTest(const GURL& redirect_url, |
| 1904 const std::string& request_method, | 1906 const std::string& request_method, |
| 1905 const std::string& redirect_method, | 1907 const std::string& redirect_method, |
| 1906 bool include_data) { | 1908 bool include_data) { |
| 1907 static const char kData[] = "hello world"; | 1909 static const char kData[] = "hello world"; |
| 1908 TestDelegate d; | 1910 TestDelegate d; |
| 1909 URLRequest req(redirect_url, &d, &default_context_); | 1911 URLRequest req(redirect_url, &d, &default_context_); |
| 1910 req.set_method(request_method); | 1912 req.set_method(request_method); |
| 1911 if (include_data) { | 1913 if (include_data) { |
| 1912 req.set_upload(CreateSimpleUploadData(kData).get()); | 1914 req.set_upload(CreateSimpleUploadData(kData)); |
| 1913 HttpRequestHeaders headers; | 1915 HttpRequestHeaders headers; |
| 1914 headers.SetHeader(HttpRequestHeaders::kContentLength, | 1916 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 1915 base::UintToString(arraysize(kData) - 1)); | 1917 base::UintToString(arraysize(kData) - 1)); |
| 1916 req.SetExtraRequestHeaders(headers); | 1918 req.SetExtraRequestHeaders(headers); |
| 1917 } | 1919 } |
| 1918 req.Start(); | 1920 req.Start(); |
| 1919 MessageLoop::current()->Run(); | 1921 MessageLoop::current()->Run(); |
| 1920 EXPECT_EQ(redirect_method, req.method()); | 1922 EXPECT_EQ(redirect_method, req.method()); |
| 1921 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); | 1923 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); |
| 1922 EXPECT_EQ(OK, req.status().error()); | 1924 EXPECT_EQ(OK, req.status().error()); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 1947 marker = 'a'; | 1949 marker = 'a'; |
| 1948 } | 1950 } |
| 1949 } | 1951 } |
| 1950 uploadBytes[kMsgSize] = '\0'; | 1952 uploadBytes[kMsgSize] = '\0'; |
| 1951 | 1953 |
| 1952 for (int i = 0; i < kIterations; ++i) { | 1954 for (int i = 0; i < kIterations; ++i) { |
| 1953 TestDelegate d; | 1955 TestDelegate d; |
| 1954 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 1956 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
| 1955 r.set_method(method.c_str()); | 1957 r.set_method(method.c_str()); |
| 1956 | 1958 |
| 1957 scoped_refptr<UploadData> upload_data(new UploadData()); | 1959 ScopedVector<UploadElementReader> element_readers; |
| 1958 upload_data->AppendBytes(uploadBytes, kMsgSize); | 1960 element_readers.push_back(new UploadBytesElementReader( |
| 1959 r.set_upload(upload_data); | 1961 uploadBytes, kMsgSize)); |
| 1962 r.set_upload(new UploadDataStream(&element_readers, 0)); | |
|
mmenke
2012/12/11 18:53:21
Looks to me like you can just use CreateSimpleUplo
hashimoto
2012/12/12 10:29:07
Done.
| |
| 1960 | 1963 |
| 1961 r.Start(); | 1964 r.Start(); |
| 1962 EXPECT_TRUE(r.is_pending()); | 1965 EXPECT_TRUE(r.is_pending()); |
| 1963 | 1966 |
| 1964 MessageLoop::current()->Run(); | 1967 MessageLoop::current()->Run(); |
| 1965 | 1968 |
| 1966 ASSERT_EQ(1, d.response_started_count()) | 1969 ASSERT_EQ(1, d.response_started_count()) |
| 1967 << "request failed: " << r.status().status() | 1970 << "request failed: " << r.status().status() |
| 1968 << ", os error: " << r.status().error(); | 1971 << ", os error: " << r.status().error(); |
| 1969 | 1972 |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2315 network_delegate.set_redirect_url(redirect_url); | 2318 network_delegate.set_redirect_url(redirect_url); |
| 2316 | 2319 |
| 2317 TestURLRequestContext context(true); | 2320 TestURLRequestContext context(true); |
| 2318 context.set_network_delegate(&network_delegate); | 2321 context.set_network_delegate(&network_delegate); |
| 2319 context.Init(); | 2322 context.Init(); |
| 2320 | 2323 |
| 2321 { | 2324 { |
| 2322 GURL original_url(test_server_.GetURL("empty.html")); | 2325 GURL original_url(test_server_.GetURL("empty.html")); |
| 2323 URLRequest r(original_url, &d, &context); | 2326 URLRequest r(original_url, &d, &context); |
| 2324 r.set_method("POST"); | 2327 r.set_method("POST"); |
| 2325 r.set_upload(CreateSimpleUploadData(kData).get()); | 2328 r.set_upload(CreateSimpleUploadData(kData)); |
| 2326 HttpRequestHeaders headers; | 2329 HttpRequestHeaders headers; |
| 2327 headers.SetHeader(HttpRequestHeaders::kContentLength, | 2330 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 2328 base::UintToString(arraysize(kData) - 1)); | 2331 base::UintToString(arraysize(kData) - 1)); |
| 2329 r.SetExtraRequestHeaders(headers); | 2332 r.SetExtraRequestHeaders(headers); |
| 2330 r.Start(); | 2333 r.Start(); |
| 2331 MessageLoop::current()->Run(); | 2334 MessageLoop::current()->Run(); |
| 2332 | 2335 |
| 2333 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 2336 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 2334 EXPECT_EQ(0, r.status().error()); | 2337 EXPECT_EQ(0, r.status().error()); |
| 2335 EXPECT_EQ(redirect_url, r.url()); | 2338 EXPECT_EQ(redirect_url, r.url()); |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3121 | 3124 |
| 3122 TestDelegate d; | 3125 TestDelegate d; |
| 3123 { | 3126 { |
| 3124 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); | 3127 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); |
| 3125 r.set_method("POST"); | 3128 r.set_method("POST"); |
| 3126 | 3129 |
| 3127 FilePath dir; | 3130 FilePath dir; |
| 3128 PathService::Get(base::DIR_EXE, &dir); | 3131 PathService::Get(base::DIR_EXE, &dir); |
| 3129 file_util::SetCurrentDirectory(dir); | 3132 file_util::SetCurrentDirectory(dir); |
| 3130 | 3133 |
| 3131 scoped_refptr<UploadData> upload_data(new UploadData); | 3134 ScopedVector<UploadElementReader> element_readers; |
| 3132 | 3135 |
| 3133 FilePath path; | 3136 FilePath path; |
| 3134 PathService::Get(base::DIR_SOURCE_ROOT, &path); | 3137 PathService::Get(base::DIR_SOURCE_ROOT, &path); |
| 3135 path = path.Append(FILE_PATH_LITERAL("net")); | 3138 path = path.Append(FILE_PATH_LITERAL("net")); |
| 3136 path = path.Append(FILE_PATH_LITERAL("data")); | 3139 path = path.Append(FILE_PATH_LITERAL("data")); |
| 3137 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); | 3140 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); |
| 3138 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); | 3141 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); |
| 3139 upload_data->AppendFileRange(path, 0, kuint64max, base::Time()); | 3142 element_readers.push_back(new UploadFileElementReader( |
| 3143 path, 0, kuint64max, base::Time())); | |
| 3140 | 3144 |
| 3141 // This file should just be ignored in the upload stream. | 3145 // This file should just be ignored in the upload stream. |
| 3142 upload_data->AppendFileRange( | 3146 element_readers.push_back(new UploadFileElementReader( |
| 3143 FilePath(FILE_PATH_LITERAL( | 3147 FilePath(FILE_PATH_LITERAL( |
| 3144 "c:\\path\\to\\non\\existant\\file.randomness.12345")), | 3148 "c:\\path\\to\\non\\existant\\file.randomness.12345")), |
| 3145 0, kuint64max, base::Time()); | 3149 0, kuint64max, base::Time())); |
| 3146 r.set_upload(upload_data); | 3150 r.set_upload(new UploadDataStream(&element_readers, 0)); |
| 3147 | 3151 |
| 3148 r.Start(); | 3152 r.Start(); |
| 3149 EXPECT_TRUE(r.is_pending()); | 3153 EXPECT_TRUE(r.is_pending()); |
| 3150 | 3154 |
| 3151 MessageLoop::current()->Run(); | 3155 MessageLoop::current()->Run(); |
| 3152 | 3156 |
| 3153 int64 size = 0; | 3157 int64 size = 0; |
| 3154 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); | 3158 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); |
| 3155 scoped_array<char> buf(new char[size]); | 3159 scoped_array<char> buf(new char[size]); |
| 3156 | 3160 |
| (...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3670 } | 3674 } |
| 3671 | 3675 |
| 3672 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 3676 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
| 3673 ASSERT_TRUE(test_server_.Start()); | 3677 ASSERT_TRUE(test_server_.Start()); |
| 3674 | 3678 |
| 3675 const char kData[] = "hello world"; | 3679 const char kData[] = "hello world"; |
| 3676 | 3680 |
| 3677 TestDelegate d; | 3681 TestDelegate d; |
| 3678 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 3682 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
| 3679 req.set_method("POST"); | 3683 req.set_method("POST"); |
| 3680 req.set_upload(CreateSimpleUploadData(kData).get()); | 3684 req.set_upload(CreateSimpleUploadData(kData)); |
| 3681 HttpRequestHeaders headers; | 3685 HttpRequestHeaders headers; |
| 3682 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3686 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 3683 base::UintToString(arraysize(kData) - 1)); | 3687 base::UintToString(arraysize(kData) - 1)); |
| 3684 req.SetExtraRequestHeaders(headers); | 3688 req.SetExtraRequestHeaders(headers); |
| 3685 | 3689 |
| 3686 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 3690 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 3687 &req, default_context_.network_delegate(), test_server_.GetURL("echo"), | 3691 &req, default_context_.network_delegate(), test_server_.GetURL("echo"), |
| 3688 URLRequestRedirectJob::REDIRECT_302_FOUND); | 3692 URLRequestRedirectJob::REDIRECT_302_FOUND); |
| 3689 AddTestInterceptor()->set_main_intercept_job(job); | 3693 AddTestInterceptor()->set_main_intercept_job(job); |
| 3690 | 3694 |
| 3691 req.Start(); | 3695 req.Start(); |
| 3692 MessageLoop::current()->Run(); | 3696 MessageLoop::current()->Run(); |
| 3693 EXPECT_EQ("GET", req.method()); | 3697 EXPECT_EQ("GET", req.method()); |
| 3694 } | 3698 } |
| 3695 | 3699 |
| 3696 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { | 3700 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { |
| 3697 ASSERT_TRUE(test_server_.Start()); | 3701 ASSERT_TRUE(test_server_.Start()); |
| 3698 | 3702 |
| 3699 const char kData[] = "hello world"; | 3703 const char kData[] = "hello world"; |
| 3700 | 3704 |
| 3701 TestDelegate d; | 3705 TestDelegate d; |
| 3702 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); | 3706 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); |
| 3703 req.set_method("POST"); | 3707 req.set_method("POST"); |
| 3704 req.set_upload(CreateSimpleUploadData(kData).get()); | 3708 req.set_upload(CreateSimpleUploadData(kData)); |
| 3705 HttpRequestHeaders headers; | 3709 HttpRequestHeaders headers; |
| 3706 headers.SetHeader(HttpRequestHeaders::kContentLength, | 3710 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 3707 base::UintToString(arraysize(kData) - 1)); | 3711 base::UintToString(arraysize(kData) - 1)); |
| 3708 req.SetExtraRequestHeaders(headers); | 3712 req.SetExtraRequestHeaders(headers); |
| 3709 | 3713 |
| 3710 URLRequestRedirectJob* job = new URLRequestRedirectJob( | 3714 URLRequestRedirectJob* job = new URLRequestRedirectJob( |
| 3711 &req, default_context_.network_delegate(), test_server_.GetURL("echo"), | 3715 &req, default_context_.network_delegate(), test_server_.GetURL("echo"), |
| 3712 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); | 3716 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); |
| 3713 AddTestInterceptor()->set_main_intercept_job(job); | 3717 AddTestInterceptor()->set_main_intercept_job(job); |
| 3714 | 3718 |
| (...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 4214 TestDelegate d; | 4218 TestDelegate d; |
| 4215 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will | 4219 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will |
| 4216 // cause a certificate error. Ignore the error. | 4220 // cause a certificate error. Ignore the error. |
| 4217 d.set_allow_certificate_errors(true); | 4221 d.set_allow_certificate_errors(true); |
| 4218 | 4222 |
| 4219 URLRequest req(GURL(StringPrintf("http://www.somewhere.com:%d/echo", | 4223 URLRequest req(GURL(StringPrintf("http://www.somewhere.com:%d/echo", |
| 4220 test_server.host_port_pair().port())), | 4224 test_server.host_port_pair().port())), |
| 4221 &d, | 4225 &d, |
| 4222 &context); | 4226 &context); |
| 4223 req.set_method("POST"); | 4227 req.set_method("POST"); |
| 4224 req.set_upload(CreateSimpleUploadData(kData).get()); | 4228 req.set_upload(CreateSimpleUploadData(kData)); |
| 4225 | 4229 |
| 4226 req.Start(); | 4230 req.Start(); |
| 4227 MessageLoop::current()->Run(); | 4231 MessageLoop::current()->Run(); |
| 4228 | 4232 |
| 4229 EXPECT_EQ("https", req.url().scheme()); | 4233 EXPECT_EQ("https", req.url().scheme()); |
| 4230 EXPECT_EQ("POST", req.method()); | 4234 EXPECT_EQ("POST", req.method()); |
| 4231 EXPECT_EQ(kData, d.data_received()); | 4235 EXPECT_EQ(kData, d.data_received()); |
| 4232 } | 4236 } |
| 4233 | 4237 |
| 4234 TEST_F(HTTPSRequestTest, SSLv3Fallback) { | 4238 TEST_F(HTTPSRequestTest, SSLv3Fallback) { |
| (...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 5165 | 5169 |
| 5166 EXPECT_FALSE(r.is_pending()); | 5170 EXPECT_FALSE(r.is_pending()); |
| 5167 EXPECT_EQ(1, d->response_started_count()); | 5171 EXPECT_EQ(1, d->response_started_count()); |
| 5168 EXPECT_FALSE(d->received_data_before_response()); | 5172 EXPECT_FALSE(d->received_data_before_response()); |
| 5169 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 5173 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 5170 } | 5174 } |
| 5171 } | 5175 } |
| 5172 #endif // !defined(DISABLE_FTP_SUPPORT) | 5176 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 5173 | 5177 |
| 5174 } // namespace net | 5178 } // namespace net |
| OLD | NEW |