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