| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 <shlobj.h> | 8 #include <shlobj.h> |
| 9 #include <windows.h> | 9 #include <windows.h> |
| 10 #endif | 10 #endif |
| (...skipping 265 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 | 276 |
| 277 class URLRequestTestHTTP : public URLRequestTest { | 277 class URLRequestTestHTTP : public URLRequestTest { |
| 278 public: | 278 public: |
| 279 URLRequestTestHTTP() | 279 URLRequestTestHTTP() |
| 280 : test_server_(TestServer::TYPE_HTTP, | 280 : test_server_(TestServer::TYPE_HTTP, |
| 281 FilePath(FILE_PATH_LITERAL( | 281 FilePath(FILE_PATH_LITERAL( |
| 282 "net/data/url_request_unittest"))) { | 282 "net/data/url_request_unittest"))) { |
| 283 } | 283 } |
| 284 | 284 |
| 285 protected: | 285 protected: |
| 286 // Requests |redirect_url|, which must return a HTTP 3xx redirect. |
| 287 // |request_method| is the method to use for the initial request. |
| 288 // |redirect_method| is the method that is expected to be used for the second |
| 289 // request, after redirection. |
| 290 // If |include_data| is true, data is uploaded with the request. The |
| 291 // response body is expected to match it exactly, if and only if |
| 292 // |request_method| == |redirect_method|. |
| 293 void HTTPRedirectMethodTest(const GURL& redirect_url, |
| 294 const std::string& request_method, |
| 295 const std::string& redirect_method, |
| 296 bool include_data) { |
| 297 static const char kData[] = "hello world"; |
| 298 TestDelegate d; |
| 299 TestURLRequest req(redirect_url, &d); |
| 300 req.set_context(default_context_); |
| 301 req.set_method(request_method); |
| 302 if (include_data) { |
| 303 req.set_upload(CreateSimpleUploadData(kData).get()); |
| 304 HttpRequestHeaders headers; |
| 305 headers.SetHeader(HttpRequestHeaders::kContentLength, |
| 306 base::UintToString(arraysize(kData) - 1)); |
| 307 req.SetExtraRequestHeaders(headers); |
| 308 } |
| 309 req.Start(); |
| 310 MessageLoop::current()->Run(); |
| 311 EXPECT_EQ(redirect_method, req.method()); |
| 312 EXPECT_EQ(URLRequestStatus::SUCCESS, req.status().status()); |
| 313 EXPECT_EQ(OK, req.status().error()); |
| 314 if (include_data) { |
| 315 if (request_method == redirect_method) { |
| 316 EXPECT_EQ(kData, d.data_received()); |
| 317 } else { |
| 318 EXPECT_NE(kData, d.data_received()); |
| 319 } |
| 320 } |
| 321 if (HasFailure()) |
| 322 LOG(WARNING) << "Request method was: " << request_method; |
| 323 } |
| 324 |
| 286 void HTTPUploadDataOperationTest(const std::string& method) { | 325 void HTTPUploadDataOperationTest(const std::string& method) { |
| 287 const int kMsgSize = 20000; // multiple of 10 | 326 const int kMsgSize = 20000; // multiple of 10 |
| 288 const int kIterations = 50; | 327 const int kIterations = 50; |
| 289 char *uploadBytes = new char[kMsgSize+1]; | 328 char *uploadBytes = new char[kMsgSize+1]; |
| 290 char *ptr = uploadBytes; | 329 char *ptr = uploadBytes; |
| 291 char marker = 'a'; | 330 char marker = 'a'; |
| 292 for (int idx = 0; idx < kMsgSize/10; idx++) { | 331 for (int idx = 0; idx < kMsgSize/10; idx++) { |
| 293 memcpy(ptr, "----------", 10); | 332 memcpy(ptr, "----------", 10); |
| 294 ptr += 10; | 333 ptr += 10; |
| 295 if (idx % 100 == 0) { | 334 if (idx % 100 == 0) { |
| (...skipping 2140 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2436 EXPECT_FALSE(ContainsString(data, "Content-Length:")); | 2475 EXPECT_FALSE(ContainsString(data, "Content-Length:")); |
| 2437 EXPECT_FALSE(ContainsString(data, "Content-Type:")); | 2476 EXPECT_FALSE(ContainsString(data, "Content-Type:")); |
| 2438 EXPECT_FALSE(ContainsString(data, "Origin:")); | 2477 EXPECT_FALSE(ContainsString(data, "Origin:")); |
| 2439 | 2478 |
| 2440 // These extra request headers should not have been stripped. | 2479 // These extra request headers should not have been stripped. |
| 2441 EXPECT_TRUE(ContainsString(data, "Accept:")); | 2480 EXPECT_TRUE(ContainsString(data, "Accept:")); |
| 2442 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); | 2481 EXPECT_TRUE(ContainsString(data, "Accept-Language:")); |
| 2443 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); | 2482 EXPECT_TRUE(ContainsString(data, "Accept-Charset:")); |
| 2444 } | 2483 } |
| 2445 | 2484 |
| 2446 TEST_F(URLRequestTestHTTP, Post307RedirectPost) { | 2485 // The following tests check that we handle mutating the request method for |
| 2486 // HTTP redirects as expected. See http://crbug.com/56373. |
| 2487 |
| 2488 TEST_F(URLRequestTestHTTP, Redirect301Tests) { |
| 2447 ASSERT_TRUE(test_server_.Start()); | 2489 ASSERT_TRUE(test_server_.Start()); |
| 2448 | 2490 |
| 2449 const char kData[] = "hello world"; | 2491 const GURL url = test_server_.GetURL("files/redirect301-to-echo"); |
| 2450 | 2492 |
| 2451 TestDelegate d; | 2493 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 2452 TestURLRequest req(test_server_.GetURL("files/redirect307-to-echo"), &d); | 2494 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 2453 req.set_context(default_context_); | 2495 } |
| 2454 req.set_method("POST"); | 2496 |
| 2455 req.set_upload(CreateSimpleUploadData(kData).get()); | 2497 TEST_F(URLRequestTestHTTP, Redirect302Tests) { |
| 2456 HttpRequestHeaders headers; | 2498 ASSERT_TRUE(test_server_.Start()); |
| 2457 headers.SetHeader(HttpRequestHeaders::kContentLength, | 2499 |
| 2458 base::UintToString(arraysize(kData) - 1)); | 2500 const GURL url = test_server_.GetURL("files/redirect302-to-echo"); |
| 2459 req.SetExtraRequestHeaders(headers); | 2501 |
| 2460 req.Start(); | 2502 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 2461 MessageLoop::current()->Run(); | 2503 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 2462 EXPECT_EQ("POST", req.method()); | 2504 } |
| 2463 EXPECT_EQ(kData, d.data_received()); | 2505 |
| 2506 TEST_F(URLRequestTestHTTP, Redirect303Tests) { |
| 2507 ASSERT_TRUE(test_server_.Start()); |
| 2508 |
| 2509 const GURL url = test_server_.GetURL("files/redirect303-to-echo"); |
| 2510 |
| 2511 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 2512 HTTPRedirectMethodTest(url, "PUT", "GET", true); |
| 2513 } |
| 2514 |
| 2515 TEST_F(URLRequestTestHTTP, Redirect307Tests) { |
| 2516 ASSERT_TRUE(test_server_.Start()); |
| 2517 |
| 2518 const GURL url = test_server_.GetURL("files/redirect307-to-echo"); |
| 2519 |
| 2520 HTTPRedirectMethodTest(url, "POST", "POST", true); |
| 2521 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 2464 } | 2522 } |
| 2465 | 2523 |
| 2466 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 2524 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
| 2467 ASSERT_TRUE(test_server_.Start()); | 2525 ASSERT_TRUE(test_server_.Start()); |
| 2468 | 2526 |
| 2469 const char kData[] = "hello world"; | 2527 const char kData[] = "hello world"; |
| 2470 | 2528 |
| 2471 TestDelegate d; | 2529 TestDelegate d; |
| 2472 TestURLRequest req(test_server_.GetURL("empty.html"), &d); | 2530 TestURLRequest req(test_server_.GetURL("empty.html"), &d); |
| 2473 req.set_context(default_context_); | 2531 req.set_context(default_context_); |
| (...skipping 1098 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3572 req.SetExtraRequestHeaders(headers); | 3630 req.SetExtraRequestHeaders(headers); |
| 3573 req.Start(); | 3631 req.Start(); |
| 3574 MessageLoop::current()->Run(); | 3632 MessageLoop::current()->Run(); |
| 3575 // If the net tests are being run with ChromeFrame then we need to allow for | 3633 // If the net tests are being run with ChromeFrame then we need to allow for |
| 3576 // the 'chromeframe' suffix which is added to the user agent before the | 3634 // the 'chromeframe' suffix which is added to the user agent before the |
| 3577 // closing parentheses. | 3635 // closing parentheses. |
| 3578 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); | 3636 EXPECT_TRUE(StartsWithASCII(d.data_received(), "Lynx (textmode", true)); |
| 3579 } | 3637 } |
| 3580 | 3638 |
| 3581 } // namespace net | 3639 } // namespace net |
| OLD | NEW |