| 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 2856 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2867 // redirection. If empty, expects that there will be no Origin header. | 2867 // redirection. If empty, expects that there will be no Origin header. |
| 2868 void HTTPRedirectOriginHeaderTest(const GURL& redirect_url, | 2868 void HTTPRedirectOriginHeaderTest(const GURL& redirect_url, |
| 2869 const std::string& request_method, | 2869 const std::string& request_method, |
| 2870 const std::string& redirect_method, | 2870 const std::string& redirect_method, |
| 2871 const std::string& origin_value) { | 2871 const std::string& origin_value) { |
| 2872 TestDelegate d; | 2872 TestDelegate d; |
| 2873 scoped_ptr<URLRequest> req( | 2873 scoped_ptr<URLRequest> req( |
| 2874 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); | 2874 default_context_.CreateRequest(redirect_url, DEFAULT_PRIORITY, &d)); |
| 2875 req->set_method(request_method); | 2875 req->set_method(request_method); |
| 2876 req->SetExtraRequestHeaderByName(HttpRequestHeaders::kOrigin, | 2876 req->SetExtraRequestHeaderByName(HttpRequestHeaders::kOrigin, |
| 2877 redirect_url.GetOrigin().spec(), false); | 2877 url::Origin(redirect_url).serialize(), fals
e); |
| 2878 req->Start(); | 2878 req->Start(); |
| 2879 | 2879 |
| 2880 base::RunLoop().Run(); | 2880 base::RunLoop().Run(); |
| 2881 | 2881 |
| 2882 EXPECT_EQ(redirect_method, req->method()); | 2882 EXPECT_EQ(redirect_method, req->method()); |
| 2883 // Note that there is no check for request success here because, for | 2883 // Note that there is no check for request success here because, for |
| 2884 // purposes of testing, the request very well may fail. For example, if the | 2884 // purposes of testing, the request very well may fail. For example, if the |
| 2885 // test redirects to an HTTPS server from an HTTP origin, thus it is cross | 2885 // test redirects to an HTTPS server from an HTTP origin, thus it is cross |
| 2886 // origin, there is not an HTTPS server in this unit test framework, so the | 2886 // origin, there is not an HTTPS server in this unit test framework, so the |
| 2887 // request would fail. However, that's fine, as long as the request headers | 2887 // request would fail. However, that's fine, as long as the request headers |
| (...skipping 3446 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6334 ASSERT_TRUE(test_server_.Start()); | 6334 ASSERT_TRUE(test_server_.Start()); |
| 6335 | 6335 |
| 6336 const GURL url = test_server_.GetURL("files/redirect301-to-echo"); | 6336 const GURL url = test_server_.GetURL("files/redirect301-to-echo"); |
| 6337 const GURL https_redirect_url = | 6337 const GURL https_redirect_url = |
| 6338 test_server_.GetURL("files/redirect301-to-https"); | 6338 test_server_.GetURL("files/redirect301-to-https"); |
| 6339 | 6339 |
| 6340 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6340 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6341 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6341 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6342 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6342 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6343 | 6343 |
| 6344 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6344 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url::Origin(url).serialize()); |
| 6345 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6345 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6346 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | 6346 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
| 6347 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", | 6347 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", |
| 6348 std::string()); | 6348 std::string()); |
| 6349 } | 6349 } |
| 6350 | 6350 |
| 6351 TEST_F(URLRequestTestHTTP, Redirect302Tests) { | 6351 TEST_F(URLRequestTestHTTP, Redirect302Tests) { |
| 6352 ASSERT_TRUE(test_server_.Start()); | 6352 ASSERT_TRUE(test_server_.Start()); |
| 6353 | 6353 |
| 6354 const GURL url = test_server_.GetURL("files/redirect302-to-echo"); | 6354 const GURL url = test_server_.GetURL("files/redirect302-to-echo"); |
| 6355 const GURL https_redirect_url = | 6355 const GURL https_redirect_url = |
| 6356 test_server_.GetURL("files/redirect302-to-https"); | 6356 test_server_.GetURL("files/redirect302-to-https"); |
| 6357 | 6357 |
| 6358 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6358 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6359 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6359 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6360 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6360 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6361 | 6361 |
| 6362 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6362 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url::Origin(url).serialize()); |
| 6363 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6363 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6364 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | 6364 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
| 6365 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", | 6365 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", |
| 6366 std::string()); | 6366 std::string()); |
| 6367 } | 6367 } |
| 6368 | 6368 |
| 6369 TEST_F(URLRequestTestHTTP, Redirect303Tests) { | 6369 TEST_F(URLRequestTestHTTP, Redirect303Tests) { |
| 6370 ASSERT_TRUE(test_server_.Start()); | 6370 ASSERT_TRUE(test_server_.Start()); |
| 6371 | 6371 |
| 6372 const GURL url = test_server_.GetURL("files/redirect303-to-echo"); | 6372 const GURL url = test_server_.GetURL("files/redirect303-to-echo"); |
| 6373 const GURL https_redirect_url = | 6373 const GURL https_redirect_url = |
| 6374 test_server_.GetURL("files/redirect303-to-https"); | 6374 test_server_.GetURL("files/redirect303-to-https"); |
| 6375 | 6375 |
| 6376 HTTPRedirectMethodTest(url, "POST", "GET", true); | 6376 HTTPRedirectMethodTest(url, "POST", "GET", true); |
| 6377 HTTPRedirectMethodTest(url, "PUT", "GET", true); | 6377 HTTPRedirectMethodTest(url, "PUT", "GET", true); |
| 6378 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6378 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6379 | 6379 |
| 6380 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6380 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url::Origin(url).serialize()); |
| 6381 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6381 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6382 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); | 6382 HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
| 6383 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", | 6383 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "GET", |
| 6384 std::string()); | 6384 std::string()); |
| 6385 } | 6385 } |
| 6386 | 6386 |
| 6387 TEST_F(URLRequestTestHTTP, Redirect307Tests) { | 6387 TEST_F(URLRequestTestHTTP, Redirect307Tests) { |
| 6388 ASSERT_TRUE(test_server_.Start()); | 6388 ASSERT_TRUE(test_server_.Start()); |
| 6389 | 6389 |
| 6390 const GURL url = test_server_.GetURL("files/redirect307-to-echo"); | 6390 const GURL url = test_server_.GetURL("files/redirect307-to-echo"); |
| 6391 const GURL https_redirect_url = | 6391 const GURL https_redirect_url = |
| 6392 test_server_.GetURL("files/redirect307-to-https"); | 6392 test_server_.GetURL("files/redirect307-to-https"); |
| 6393 | 6393 |
| 6394 HTTPRedirectMethodTest(url, "POST", "POST", true); | 6394 HTTPRedirectMethodTest(url, "POST", "POST", true); |
| 6395 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6395 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6396 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6396 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6397 | 6397 |
| 6398 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6398 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url::Origin(url).serialize()); |
| 6399 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6399 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6400 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); | 6400 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url::Origin(url).serialize()
); |
| 6401 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "POST", "null"); | 6401 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "POST", "null"); |
| 6402 } | 6402 } |
| 6403 | 6403 |
| 6404 TEST_F(URLRequestTestHTTP, Redirect308Tests) { | 6404 TEST_F(URLRequestTestHTTP, Redirect308Tests) { |
| 6405 ASSERT_TRUE(test_server_.Start()); | 6405 ASSERT_TRUE(test_server_.Start()); |
| 6406 | 6406 |
| 6407 const GURL url = test_server_.GetURL("files/redirect308-to-echo"); | 6407 const GURL url = test_server_.GetURL("files/redirect308-to-echo"); |
| 6408 const GURL https_redirect_url = | 6408 const GURL https_redirect_url = |
| 6409 test_server_.GetURL("files/redirect308-to-https"); | 6409 test_server_.GetURL("files/redirect308-to-https"); |
| 6410 | 6410 |
| 6411 HTTPRedirectMethodTest(url, "POST", "POST", true); | 6411 HTTPRedirectMethodTest(url, "POST", "POST", true); |
| 6412 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 6412 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 6413 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 6413 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 6414 | 6414 |
| 6415 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); | 6415 HTTPRedirectOriginHeaderTest(url, "GET", "GET", url::Origin(url).serialize()); |
| 6416 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); | 6416 HTTPRedirectOriginHeaderTest(https_redirect_url, "GET", "GET", "null"); |
| 6417 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); | 6417 HTTPRedirectOriginHeaderTest(url, "POST", "POST", url::Origin(url).serialize()
); |
| 6418 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "POST", "null"); | 6418 HTTPRedirectOriginHeaderTest(https_redirect_url, "POST", "POST", "null"); |
| 6419 } | 6419 } |
| 6420 | 6420 |
| 6421 // Make sure that 308 responses without bodies are not treated as redirects. | 6421 // Make sure that 308 responses without bodies are not treated as redirects. |
| 6422 // Certain legacy apis that pre-date the response code expect this behavior | 6422 // Certain legacy apis that pre-date the response code expect this behavior |
| 6423 // (Like Google Drive). | 6423 // (Like Google Drive). |
| 6424 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { | 6424 TEST_F(URLRequestTestHTTP, NoRedirectOn308WithoutLocationHeader) { |
| 6425 ASSERT_TRUE(test_server_.Start()); | 6425 ASSERT_TRUE(test_server_.Start()); |
| 6426 | 6426 |
| 6427 TestDelegate d; | 6427 TestDelegate d; |
| (...skipping 2761 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 9189 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); | 9189 GURL("http://test_intercept/foo"), DEFAULT_PRIORITY, &d)); |
| 9190 | 9190 |
| 9191 EXPECT_FALSE(req->response_info().network_accessed); | 9191 EXPECT_FALSE(req->response_info().network_accessed); |
| 9192 | 9192 |
| 9193 req->Start(); | 9193 req->Start(); |
| 9194 base::RunLoop().Run(); | 9194 base::RunLoop().Run(); |
| 9195 EXPECT_TRUE(req->response_info().network_accessed); | 9195 EXPECT_TRUE(req->response_info().network_accessed); |
| 9196 } | 9196 } |
| 9197 | 9197 |
| 9198 } // namespace net | 9198 } // namespace net |
| OLD | NEW |