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

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

Issue 11439008: net: Change argument of URLRequest::set_upload from UploadData to UploadDataStream (Closed) Base URL: http://git.chromium.org/chromium/src.git@chunk
Patch Set: Fix android Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « net/url_request/url_request.cc ('k') | webkit/glue/resource_request_body.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "build/build_config.h" 5 #include "build/build_config.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #include <shlobj.h> 9 #include <shlobj.h>
10 #endif 10 #endif
(...skipping 21 matching lines...) Expand all
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
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 scoped_ptr<UploadElementReader> reader(
115 upload->AppendBytes(data, strlen(data)); 117 new UploadBytesElementReader(data, strlen(data)));
116 return upload; 118 return UploadDataStream::CreateWithReader(reader.Pass(), 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
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(make_scoped_ptr(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
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 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(uploadBytes)));
1958 upload_data->AppendBytes(uploadBytes, kMsgSize);
1959 r.set_upload(upload_data);
1960 1960
1961 r.Start(); 1961 r.Start();
1962 EXPECT_TRUE(r.is_pending()); 1962 EXPECT_TRUE(r.is_pending());
1963 1963
1964 MessageLoop::current()->Run(); 1964 MessageLoop::current()->Run();
1965 1965
1966 ASSERT_EQ(1, d.response_started_count()) 1966 ASSERT_EQ(1, d.response_started_count())
1967 << "request failed: " << r.status().status() 1967 << "request failed: " << r.status().status()
1968 << ", os error: " << r.status().error(); 1968 << ", os error: " << r.status().error();
1969 1969
(...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after
2315 network_delegate.set_redirect_url(redirect_url); 2315 network_delegate.set_redirect_url(redirect_url);
2316 2316
2317 TestURLRequestContext context(true); 2317 TestURLRequestContext context(true);
2318 context.set_network_delegate(&network_delegate); 2318 context.set_network_delegate(&network_delegate);
2319 context.Init(); 2319 context.Init();
2320 2320
2321 { 2321 {
2322 GURL original_url(test_server_.GetURL("empty.html")); 2322 GURL original_url(test_server_.GetURL("empty.html"));
2323 URLRequest r(original_url, &d, &context); 2323 URLRequest r(original_url, &d, &context);
2324 r.set_method("POST"); 2324 r.set_method("POST");
2325 r.set_upload(CreateSimpleUploadData(kData).get()); 2325 r.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
2326 HttpRequestHeaders headers; 2326 HttpRequestHeaders headers;
2327 headers.SetHeader(HttpRequestHeaders::kContentLength, 2327 headers.SetHeader(HttpRequestHeaders::kContentLength,
2328 base::UintToString(arraysize(kData) - 1)); 2328 base::UintToString(arraysize(kData) - 1));
2329 r.SetExtraRequestHeaders(headers); 2329 r.SetExtraRequestHeaders(headers);
2330 r.Start(); 2330 r.Start();
2331 MessageLoop::current()->Run(); 2331 MessageLoop::current()->Run();
2332 2332
2333 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); 2333 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status());
2334 EXPECT_EQ(0, r.status().error()); 2334 EXPECT_EQ(0, r.status().error());
2335 EXPECT_EQ(redirect_url, r.url()); 2335 EXPECT_EQ(redirect_url, r.url());
(...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after
3121 3121
3122 TestDelegate d; 3122 TestDelegate d;
3123 { 3123 {
3124 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_); 3124 URLRequest r(test_server_.GetURL("echo"), &d, &default_context_);
3125 r.set_method("POST"); 3125 r.set_method("POST");
3126 3126
3127 FilePath dir; 3127 FilePath dir;
3128 PathService::Get(base::DIR_EXE, &dir); 3128 PathService::Get(base::DIR_EXE, &dir);
3129 file_util::SetCurrentDirectory(dir); 3129 file_util::SetCurrentDirectory(dir);
3130 3130
3131 scoped_refptr<UploadData> upload_data(new UploadData); 3131 ScopedVector<UploadElementReader> element_readers;
3132 3132
3133 FilePath path; 3133 FilePath path;
3134 PathService::Get(base::DIR_SOURCE_ROOT, &path); 3134 PathService::Get(base::DIR_SOURCE_ROOT, &path);
3135 path = path.Append(FILE_PATH_LITERAL("net")); 3135 path = path.Append(FILE_PATH_LITERAL("net"));
3136 path = path.Append(FILE_PATH_LITERAL("data")); 3136 path = path.Append(FILE_PATH_LITERAL("data"));
3137 path = path.Append(FILE_PATH_LITERAL("url_request_unittest")); 3137 path = path.Append(FILE_PATH_LITERAL("url_request_unittest"));
3138 path = path.Append(FILE_PATH_LITERAL("with-headers.html")); 3138 path = path.Append(FILE_PATH_LITERAL("with-headers.html"));
3139 upload_data->AppendFileRange(path, 0, kuint64max, base::Time()); 3139 element_readers.push_back(new UploadFileElementReader(
3140 path, 0, kuint64max, base::Time()));
3140 3141
3141 // This file should just be ignored in the upload stream. 3142 // This file should just be ignored in the upload stream.
3142 upload_data->AppendFileRange( 3143 element_readers.push_back(new UploadFileElementReader(
3143 FilePath(FILE_PATH_LITERAL( 3144 FilePath(FILE_PATH_LITERAL(
3144 "c:\\path\\to\\non\\existant\\file.randomness.12345")), 3145 "c:\\path\\to\\non\\existant\\file.randomness.12345")),
3145 0, kuint64max, base::Time()); 3146 0, kuint64max, base::Time()));
3146 r.set_upload(upload_data); 3147 r.set_upload(make_scoped_ptr(new UploadDataStream(&element_readers, 0)));
3147 3148
3148 r.Start(); 3149 r.Start();
3149 EXPECT_TRUE(r.is_pending()); 3150 EXPECT_TRUE(r.is_pending());
3150 3151
3151 MessageLoop::current()->Run(); 3152 MessageLoop::current()->Run();
3152 3153
3153 int64 size = 0; 3154 int64 size = 0;
3154 ASSERT_EQ(true, file_util::GetFileSize(path, &size)); 3155 ASSERT_EQ(true, file_util::GetFileSize(path, &size));
3155 scoped_array<char> buf(new char[size]); 3156 scoped_array<char> buf(new char[size]);
3156 3157
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
3584 // http://code.google.com/p/chromium/issues/detail?id=843 3585 // http://code.google.com/p/chromium/issues/detail?id=843
3585 TEST_F(URLRequestTestHTTP, Post302RedirectGet) { 3586 TEST_F(URLRequestTestHTTP, Post302RedirectGet) {
3586 ASSERT_TRUE(test_server_.Start()); 3587 ASSERT_TRUE(test_server_.Start());
3587 3588
3588 const char kData[] = "hello world"; 3589 const char kData[] = "hello world";
3589 3590
3590 TestDelegate d; 3591 TestDelegate d;
3591 URLRequest req( 3592 URLRequest req(
3592 test_server_.GetURL("files/redirect-to-echoall"), &d, &default_context_); 3593 test_server_.GetURL("files/redirect-to-echoall"), &d, &default_context_);
3593 req.set_method("POST"); 3594 req.set_method("POST");
3594 req.set_upload(CreateSimpleUploadData(kData)); 3595 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
3595 3596
3596 // Set headers (some of which are specific to the POST). 3597 // Set headers (some of which are specific to the POST).
3597 HttpRequestHeaders headers; 3598 HttpRequestHeaders headers;
3598 headers.AddHeadersFromString( 3599 headers.AddHeadersFromString(
3599 "Content-Type: multipart/form-data; " 3600 "Content-Type: multipart/form-data; "
3600 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n" 3601 "boundary=----WebKitFormBoundaryAADeAA+NAAWMAAwZ\r\n"
3601 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9," 3602 "Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,"
3602 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n" 3603 "text/plain;q=0.8,image/png,*/*;q=0.5\r\n"
3603 "Accept-Language: en-US,en\r\n" 3604 "Accept-Language: en-US,en\r\n"
3604 "Accept-Charset: ISO-8859-1,*,utf-8\r\n" 3605 "Accept-Charset: ISO-8859-1,*,utf-8\r\n"
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
3670 } 3671 }
3671 3672
3672 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { 3673 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) {
3673 ASSERT_TRUE(test_server_.Start()); 3674 ASSERT_TRUE(test_server_.Start());
3674 3675
3675 const char kData[] = "hello world"; 3676 const char kData[] = "hello world";
3676 3677
3677 TestDelegate d; 3678 TestDelegate d;
3678 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); 3679 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_);
3679 req.set_method("POST"); 3680 req.set_method("POST");
3680 req.set_upload(CreateSimpleUploadData(kData).get()); 3681 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
3681 HttpRequestHeaders headers; 3682 HttpRequestHeaders headers;
3682 headers.SetHeader(HttpRequestHeaders::kContentLength, 3683 headers.SetHeader(HttpRequestHeaders::kContentLength,
3683 base::UintToString(arraysize(kData) - 1)); 3684 base::UintToString(arraysize(kData) - 1));
3684 req.SetExtraRequestHeaders(headers); 3685 req.SetExtraRequestHeaders(headers);
3685 3686
3686 URLRequestRedirectJob* job = new URLRequestRedirectJob( 3687 URLRequestRedirectJob* job = new URLRequestRedirectJob(
3687 &req, default_context_.network_delegate(), test_server_.GetURL("echo"), 3688 &req, default_context_.network_delegate(), test_server_.GetURL("echo"),
3688 URLRequestRedirectJob::REDIRECT_302_FOUND); 3689 URLRequestRedirectJob::REDIRECT_302_FOUND);
3689 AddTestInterceptor()->set_main_intercept_job(job); 3690 AddTestInterceptor()->set_main_intercept_job(job);
3690 3691
3691 req.Start(); 3692 req.Start();
3692 MessageLoop::current()->Run(); 3693 MessageLoop::current()->Run();
3693 EXPECT_EQ("GET", req.method()); 3694 EXPECT_EQ("GET", req.method());
3694 } 3695 }
3695 3696
3696 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) { 3697 TEST_F(URLRequestTestHTTP, InterceptPost307RedirectPost) {
3697 ASSERT_TRUE(test_server_.Start()); 3698 ASSERT_TRUE(test_server_.Start());
3698 3699
3699 const char kData[] = "hello world"; 3700 const char kData[] = "hello world";
3700 3701
3701 TestDelegate d; 3702 TestDelegate d;
3702 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_); 3703 URLRequest req(test_server_.GetURL("empty.html"), &d, &default_context_);
3703 req.set_method("POST"); 3704 req.set_method("POST");
3704 req.set_upload(CreateSimpleUploadData(kData).get()); 3705 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
3705 HttpRequestHeaders headers; 3706 HttpRequestHeaders headers;
3706 headers.SetHeader(HttpRequestHeaders::kContentLength, 3707 headers.SetHeader(HttpRequestHeaders::kContentLength,
3707 base::UintToString(arraysize(kData) - 1)); 3708 base::UintToString(arraysize(kData) - 1));
3708 req.SetExtraRequestHeaders(headers); 3709 req.SetExtraRequestHeaders(headers);
3709 3710
3710 URLRequestRedirectJob* job = new URLRequestRedirectJob( 3711 URLRequestRedirectJob* job = new URLRequestRedirectJob(
3711 &req, default_context_.network_delegate(), test_server_.GetURL("echo"), 3712 &req, default_context_.network_delegate(), test_server_.GetURL("echo"),
3712 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT); 3713 URLRequestRedirectJob::REDIRECT_307_TEMPORARY_REDIRECT);
3713 AddTestInterceptor()->set_main_intercept_job(job); 3714 AddTestInterceptor()->set_main_intercept_job(job);
3714 3715
(...skipping 499 matching lines...) Expand 10 before | Expand all | Expand 10 after
4214 TestDelegate d; 4215 TestDelegate d;
4215 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will 4216 // Navigating to https://www.somewhere.com instead of https://127.0.0.1 will
4216 // cause a certificate error. Ignore the error. 4217 // cause a certificate error. Ignore the error.
4217 d.set_allow_certificate_errors(true); 4218 d.set_allow_certificate_errors(true);
4218 4219
4219 URLRequest req(GURL(StringPrintf("http://www.somewhere.com:%d/echo", 4220 URLRequest req(GURL(StringPrintf("http://www.somewhere.com:%d/echo",
4220 test_server.host_port_pair().port())), 4221 test_server.host_port_pair().port())),
4221 &d, 4222 &d,
4222 &context); 4223 &context);
4223 req.set_method("POST"); 4224 req.set_method("POST");
4224 req.set_upload(CreateSimpleUploadData(kData).get()); 4225 req.set_upload(make_scoped_ptr(CreateSimpleUploadData(kData)));
4225 4226
4226 req.Start(); 4227 req.Start();
4227 MessageLoop::current()->Run(); 4228 MessageLoop::current()->Run();
4228 4229
4229 EXPECT_EQ("https", req.url().scheme()); 4230 EXPECT_EQ("https", req.url().scheme());
4230 EXPECT_EQ("POST", req.method()); 4231 EXPECT_EQ("POST", req.method());
4231 EXPECT_EQ(kData, d.data_received()); 4232 EXPECT_EQ(kData, d.data_received());
4232 } 4233 }
4233 4234
4234 TEST_F(HTTPSRequestTest, SSLv3Fallback) { 4235 TEST_F(HTTPSRequestTest, SSLv3Fallback) {
(...skipping 930 matching lines...) Expand 10 before | Expand all | Expand 10 after
5165 5166
5166 EXPECT_FALSE(r.is_pending()); 5167 EXPECT_FALSE(r.is_pending());
5167 EXPECT_EQ(1, d->response_started_count()); 5168 EXPECT_EQ(1, d->response_started_count());
5168 EXPECT_FALSE(d->received_data_before_response()); 5169 EXPECT_FALSE(d->received_data_before_response());
5169 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); 5170 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size));
5170 } 5171 }
5171 } 5172 }
5172 #endif // !defined(DISABLE_FTP_SUPPORT) 5173 #endif // !defined(DISABLE_FTP_SUPPORT)
5173 5174
5174 } // namespace net 5175 } // namespace net
OLDNEW
« no previous file with comments | « net/url_request/url_request.cc ('k') | webkit/glue/resource_request_body.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698