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 2835 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 2846 if (request_method == redirect_method) { | 2846 if (request_method == redirect_method) { |
| 2847 EXPECT_EQ(kData, d.data_received()); | 2847 EXPECT_EQ(kData, d.data_received()); |
| 2848 } else { | 2848 } else { |
| 2849 EXPECT_NE(kData, d.data_received()); | 2849 EXPECT_NE(kData, d.data_received()); |
| 2850 } | 2850 } |
| 2851 } | 2851 } |
| 2852 if (HasFailure()) | 2852 if (HasFailure()) |
| 2853 LOG(WARNING) << "Request method was: " << request_method; | 2853 LOG(WARNING) << "Request method was: " << request_method; |
| 2854 } | 2854 } |
| 2855 | 2855 |
| 2856 // Requests |redirect_url|, which must return a HTTP 3xx redirect. | |
| 2857 // |request_method| is the method to use for the initial request. | |
| 2858 // |redirect_method| is the method that is expected to be used for the second | |
| 2859 // request, after redirection. | |
| 2860 // If |include_data| is true, data is uploaded with the request. The | |
| 2861 // response body is expected to match it exactly, if and only if | |
| 2862 // |request_method| == |redirect_method|. | |
| 2863 // | |
|
Ryan Sleevi
2015/03/19 03:46:35
Copy pasta?
jww
2015/03/19 17:53:10
Done.
| |
| 2864 | |
| 2865 // Requests |redirect_url|, which must return a HTTP 3xx redirect. | |
| 2866 // |request_method| is the method to use for the initial request. | |
| 2867 // |redirect_method| is the method that is expected to be used for the second | |
| 2868 // request, after redirection. | |
| 2869 // |origin_value| is the expected value for the Origin header after | |
| 2870 // redirection. If empty, expects that there will be no Origin header. | |
| 2871 void HTTPRedirectOriginHeaderTest(const GURL& redirect_url, | |
| 2872 const std::string& request_method, | |
| 2873 const std::string& redirect_method, | |
| 2874 const std::string& origin_value) { | |
| 2875 TestDelegate d; | |
| 2876 scoped_ptr<URLRequest> req(default_context_.CreateRequest( | |
| 2877 redirect_url, DEFAULT_PRIORITY, &d, NULL)); | |
| 2878 req->set_method(request_method); | |
| 2879 req->SetExtraRequestHeaderByName(HttpRequestHeaders::kOrigin, | |
| 2880 redirect_url.GetOrigin().spec(), false); | |
| 2881 req->Start(); | |
| 2882 base::RunLoop().Run(); | |
|
Ryan Sleevi
2015/03/19 03:46:35
slight readability pedantry: newlines between 2881
jww
2015/03/19 17:53:10
Done.
| |
| 2883 EXPECT_EQ(redirect_method, req->method()); | |
| 2884 // Note that there is no check for request success here because, for | |
| 2885 // purposes of testing, the request very well may fail. For example, if the | |
| 2886 // test redirects to an FTP server so it is cross origin, there is no such | |
| 2887 // FTP server, so the request would fail. However, that's fine, as long as | |
| 2888 // the request headers are in order and pass the checks below. | |
| 2889 if (origin_value.empty()) { | |
| 2890 EXPECT_FALSE( | |
| 2891 req->extra_request_headers().HasHeader(HttpRequestHeaders::kOrigin)); | |
| 2892 } else { | |
| 2893 std::string origin_header; | |
| 2894 EXPECT_TRUE(req->extra_request_headers().GetHeader( | |
| 2895 HttpRequestHeaders::kOrigin, &origin_header)); | |
| 2896 EXPECT_EQ(origin_value, origin_header); | |
| 2897 } | |
| 2898 } | |
| 2899 | |
| 2856 void HTTPUploadDataOperationTest(const std::string& method) { | 2900 void HTTPUploadDataOperationTest(const std::string& method) { |
| 2857 const int kMsgSize = 20000; // multiple of 10 | 2901 const int kMsgSize = 20000; // multiple of 10 |
| 2858 const int kIterations = 50; | 2902 const int kIterations = 50; |
| 2859 char* uploadBytes = new char[kMsgSize+1]; | 2903 char* uploadBytes = new char[kMsgSize+1]; |
| 2860 char* ptr = uploadBytes; | 2904 char* ptr = uploadBytes; |
| 2861 char marker = 'a'; | 2905 char marker = 'a'; |
| 2862 for (int idx = 0; idx < kMsgSize/10; idx++) { | 2906 for (int idx = 0; idx < kMsgSize/10; idx++) { |
| 2863 memcpy(ptr, "----------", 10); | 2907 memcpy(ptr, "----------", 10); |
| 2864 ptr += 10; | 2908 ptr += 10; |
| 2865 if (idx % 100 == 0) { | 2909 if (idx % 100 == 0) { |
| (...skipping 3371 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 6237 } | 6281 } |
| 6238 | 6282 |
| 6239 // The following tests check that we handle mutating the request method for | 6283 // The following tests check that we handle mutating the request method for |
| 6240 // HTTP redirects as expected. | 6284 // HTTP redirects as expected. |
| 6241 // See http://crbug.com/56373 and http://crbug.com/102130. | 6285 // See http://crbug.com/56373 and http://crbug.com/102130. |
| 6242 | 6286 |
| 6243 TEST_F(URLRequestTestHTTP, Redirect301Tests) { | 6287 TEST_F(URLRequestTestHTTP, Redirect301Tests) { |
| 6244 ASSERT_TRUE(test_server_.Start()); | 6288 ASSERT_TRUE(test_server_.Start()); |
| 6245 | 6289 |
| 6246 const GURL url = test_server_.GetURL("files/redirect301-to-echo"); | 6290 const GURL url = test_server_.GetURL("files/redirect301-to-echo"); |
| 6291 const GURL ftp_redirect_url = test_server_.GetURL("files/redirect301-to-ftp"); | |
| 6247 | 6292 |
| 6248 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6293 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6249 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6294 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6250 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6295 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6296 | |
| 6297 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | |
| 6298 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); | |
| 6299 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | |
| 6300 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "GET", std::string()); | |
| 6251 } | 6301 } |
| 6252 | 6302 |
| 6253 TEST_F(URLRequestTestHTTP, Redirect302Tests) { | 6303 TEST_F(URLRequestTestHTTP, Redirect302Tests) { |
| 6254 ASSERT_TRUE(test_server_.Start()); | 6304 ASSERT_TRUE(test_server_.Start()); |
| 6255 | 6305 |
| 6256 const GURL url = test_server_.GetURL("files/redirect302-to-echo"); | 6306 const GURL url = test_server_.GetURL("files/redirect302-to-echo"); |
| 6307 const GURL ftp_redirect_url = test_server_.GetURL("files/redirect302-to-ftp"); | |
| 6257 | 6308 |
| 6258 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6309 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6259 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6310 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6260 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6311 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6312 | |
| 6313 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | |
| 6314 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); | |
| 6315 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | |
| 6316 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "GET", std::string()); | |
| 6261 } | 6317 } |
| 6262 | 6318 |
| 6263 TEST_F(URLRequestTestHTTP, Redirect303Tests) { | 6319 TEST_F(URLRequestTestHTTP, Redirect303Tests) { |
| 6264 ASSERT_TRUE(test_server_.Start()); | 6320 ASSERT_TRUE(test_server_.Start()); |
| 6265 | 6321 |
| 6266 const GURL url = test_server_.GetURL("files/redirect303-to-echo"); | 6322 const GURL url = test_server_.GetURL("files/redirect303-to-echo"); |
| 6323 const GURL ftp_redirect_url = test_server_.GetURL("files/redirect303-to-ftp"); | |
| 6267 | 6324 |
| 6268 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6325 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6269 HTTPRedirectMethodTest(url, "PUT", "GET", true); | 6326 HTTPRedirectMethodTest(url, "PUT", "GET", true); |
| 6270 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6327 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6328 | |
| 6329 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | |
| 6330 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); | |
| 6331 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | |
| 6332 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "GET", std::string()); | |
| 6271 } | 6333 } |
| 6272 | 6334 |
| 6273 TEST_F(URLRequestTestHTTP, Redirect307Tests) { | 6335 TEST_F(URLRequestTestHTTP, Redirect307Tests) { |
| 6274 ASSERT_TRUE(test_server_.Start()); | 6336 ASSERT_TRUE(test_server_.Start()); |
| 6275 | 6337 |
| 6276 const GURL url = test_server_.GetURL("files/redirect307-to-echo"); | 6338 const GURL url = test_server_.GetURL("files/redirect307-to-echo"); |
| 6339 const GURL ftp_redirect_url = test_server_.GetURL("files/redirect307-to-ftp"); | |
| 6277 | 6340 |
| 6278 HTTPRedirectMethodTest(url, "POST", "POST", true); | 6341 HTTPRedirectMethodTest(url, "POST", "POST", true); |
| 6279 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6342 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6280 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6343 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6344 | |
| 6345 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | |
| 6346 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); | |
| 6347 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); | |
| 6348 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "POST", "null"); | |
| 6281 } | 6349 } |
| 6282 | 6350 |
| 6283 TEST_F(URLRequestTestHTTP, Redirect308Tests) { | 6351 TEST_F(URLRequestTestHTTP, Redirect308Tests) { |
| 6284 ASSERT_TRUE(test_server_.Start()); | 6352 ASSERT_TRUE(test_server_.Start()); |
| 6285 | 6353 |
| 6286 const GURL url = test_server_.GetURL("files/redirect308-to-echo"); | 6354 const GURL url = test_server_.GetURL("files/redirect308-to-echo"); |
| 6355 const GURL ftp_redirect_url = test_server_.GetURL("files/redirect308-to-ftp"); | |
| 6287 | 6356 |
| 6288 HTTPRedirectMethodTest(url, "POST", "POST", true); | 6357 HTTPRedirectMethodTest(url, "POST", "POST", true); |
| 6289 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6358 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6290 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6359 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6360 | |
| 6361 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | |
| 6362 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); | |
| 6363 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); | |
| 6364 HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "POST", "null"); | |
| 6291 } | 6365 } |
| 6292 | 6366 |
| 6293 // Make sure that 308 responses without bodies are not treated as redirects. | 6367 // Make sure that 308 responses without bodies are not treated as redirects. |
| 6294 // Certain legacy apis that pre-date the response code expect this behavior | 6368 // Certain legacy apis that pre-date the response code expect this behavior |
| 6295 // (Like Google Drive). | 6369 // (Like Google Drive). |
| 6296 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { | 6370 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { |
| 6297 ASSERT_TRUE(test_server_.Start()); | 6371 ASSERT_TRUE(test_server_.Start()); |
| 6298 | 6372 |
| 6299 TestDelegate d; | 6373 TestDelegate d; |
| 6300 const GURL url = test_server_.GetURL("files/308-without-location-header"); | 6374 const GURL url = test_server_.GetURL("files/308-without-location-header"); |
| (...skipping 2654 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 8955 | 9029 |
| 8956 EXPECT_FALSE(r->is_pending()); | 9030 EXPECT_FALSE(r->is_pending()); |
| 8957 EXPECT_EQ(1, d->response_started_count()); | 9031 EXPECT_EQ(1, d->response_started_count()); |
| 8958 EXPECT_FALSE(d->received_data_before_response()); | 9032 EXPECT_FALSE(d->received_data_before_response()); |
| 8959 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 9033 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 8960 } | 9034 } |
| 8961 } | 9035 } |
| 8962 #endif // !defined(DISABLE_FTP_SUPPORT) | 9036 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 8963 | 9037 |
| 8964 } // namespace net | 9038 } // namespace net |
| OLD | NEW |