| 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 5313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5324 &default_context_); | 5324 &default_context_); |
| 5325 | 5325 |
| 5326 r.Start(); | 5326 r.Start(); |
| 5327 base::RunLoop().Run(); | 5327 base::RunLoop().Run(); |
| 5328 | 5328 |
| 5329 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); | 5329 EXPECT_EQ(URLRequestStatus::FAILED, r.status().status()); |
| 5330 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r.status().error()); | 5330 EXPECT_EQ(ERR_UNSAFE_REDIRECT, r.status().error()); |
| 5331 } | 5331 } |
| 5332 } | 5332 } |
| 5333 | 5333 |
| 5334 // Redirects from an URL with fragment to an unsafe URL without fragment should | |
| 5335 // be allowed. | |
| 5336 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithReferenceFragment) { | |
| 5337 ASSERT_TRUE(test_server_.Start()); | |
| 5338 | |
| 5339 GURL original_url(test_server_.GetURL("original#fragment")); | |
| 5340 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect"); | |
| 5341 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment"); | |
| 5342 | |
| 5343 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | |
| 5344 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | |
| 5345 | |
| 5346 TestDelegate d; | |
| 5347 { | |
| 5348 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | |
| 5349 | |
| 5350 r.Start(); | |
| 5351 base::RunLoop().Run(); | |
| 5352 | |
| 5353 EXPECT_EQ(2U, r.url_chain().size()); | |
| 5354 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | |
| 5355 EXPECT_EQ(net::OK, r.status().error()); | |
| 5356 EXPECT_EQ(original_url, r.original_url()); | |
| 5357 EXPECT_EQ(expected_url, r.url()); | |
| 5358 } | |
| 5359 } | |
| 5360 | |
| 5361 // Redirects from an URL with fragment to an unsafe URL with fragment should | 5334 // Redirects from an URL with fragment to an unsafe URL with fragment should |
| 5362 // be allowed, and the reference fragment of the target URL should be preserved. | 5335 // be allowed, and the reference fragment of the target URL should be preserved. |
| 5363 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { | 5336 TEST_F(URLRequestTestHTTP, UnsafeRedirectWithDifferentReferenceFragment) { |
| 5364 ASSERT_TRUE(test_server_.Start()); | 5337 ASSERT_TRUE(test_server_.Start()); |
| 5365 | 5338 |
| 5366 GURL original_url(test_server_.GetURL("original#fragment1")); | 5339 GURL original_url(test_server_.GetURL("original#fragment1")); |
| 5367 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | 5340 GURL unsafe_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); |
| 5368 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); | 5341 GURL expected_url("data:,url-marked-safe-and-used-in-redirect#fragment2"); |
| 5369 | 5342 |
| 5370 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); | 5343 default_network_delegate_.set_redirect_on_headers_received_url(unsafe_url); |
| 5371 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 5344 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); |
| 5372 | 5345 |
| 5373 TestDelegate d; | 5346 TestDelegate d; |
| 5374 { | 5347 { |
| 5375 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 5348 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 5376 | 5349 |
| 5377 r.Start(); | 5350 r.Start(); |
| 5378 base::RunLoop().Run(); | 5351 base::RunLoop().Run(); |
| 5379 | 5352 |
| 5380 EXPECT_EQ(2U, r.url_chain().size()); | 5353 EXPECT_EQ(2U, r.url_chain().size()); |
| 5381 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 5354 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 5382 EXPECT_EQ(net::OK, r.status().error()); | 5355 EXPECT_EQ(net::OK, r.status().error()); |
| 5383 EXPECT_EQ(original_url, r.original_url()); | 5356 EXPECT_EQ(original_url, r.original_url()); |
| 5384 EXPECT_EQ(expected_url, r.url()); | 5357 EXPECT_EQ(expected_url, r.url()); |
| 5385 } | 5358 } |
| 5386 } | 5359 } |
| 5387 | 5360 |
| 5388 // When a delegate has specified a safe redirect URL, but it does not match the | 5361 // When a delegate has specified a safe redirect URL, assume that the redirect |
| 5389 // redirect target, then do not prevent the reference fragment from being added. | 5362 // URL should not be changed. In particular, the reference fragment should not |
| 5363 // be modified. |
| 5390 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { | 5364 TEST_F(URLRequestTestHTTP, RedirectWithReferenceFragment) { |
| 5391 ASSERT_TRUE(test_server_.Start()); | 5365 ASSERT_TRUE(test_server_.Start()); |
| 5392 | 5366 |
| 5393 GURL original_url(test_server_.GetURL("original#expected-fragment")); | 5367 GURL original_url(test_server_.GetURL("original#should-not-be-appended")); |
| 5394 GURL unsafe_url("data:text/html,this-url-does-not-match-redirect-url"); | 5368 GURL redirect_url("data:text/html,expect-no-reference-fragment"); |
| 5395 GURL redirect_url(test_server_.GetURL("target")); | |
| 5396 GURL expected_redirect_url(test_server_.GetURL("target#expected-fragment")); | |
| 5397 | 5369 |
| 5398 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); | 5370 default_network_delegate_.set_redirect_on_headers_received_url(redirect_url); |
| 5399 default_network_delegate_.set_allowed_unsafe_redirect_url(unsafe_url); | 5371 default_network_delegate_.set_allowed_unsafe_redirect_url(redirect_url); |
| 5400 | 5372 |
| 5401 TestDelegate d; | 5373 TestDelegate d; |
| 5402 { | 5374 { |
| 5403 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); | 5375 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 5404 | 5376 |
| 5405 r.Start(); | 5377 r.Start(); |
| 5406 base::RunLoop().Run(); | 5378 base::RunLoop().Run(); |
| 5407 | 5379 |
| 5408 EXPECT_EQ(2U, r.url_chain().size()); | 5380 EXPECT_EQ(2U, r.url_chain().size()); |
| 5409 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); | 5381 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 5410 EXPECT_EQ(net::OK, r.status().error()); | 5382 EXPECT_EQ(net::OK, r.status().error()); |
| 5411 EXPECT_EQ(original_url, r.original_url()); | 5383 EXPECT_EQ(original_url, r.original_url()); |
| 5412 EXPECT_EQ(expected_redirect_url, r.url()); | 5384 EXPECT_EQ(redirect_url, r.url()); |
| 5413 } | 5385 } |
| 5414 } | 5386 } |
| 5415 | 5387 |
| 5416 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { | 5388 TEST_F(URLRequestTestHTTP, NoUserPassInReferrer) { |
| 5417 ASSERT_TRUE(test_server_.Start()); | 5389 ASSERT_TRUE(test_server_.Start()); |
| 5418 | 5390 |
| 5419 TestDelegate d; | 5391 TestDelegate d; |
| 5420 URLRequest req(test_server_.GetURL("echoheader?Referer"), | 5392 URLRequest req(test_server_.GetURL("echoheader?Referer"), |
| 5421 DEFAULT_PRIORITY, | 5393 DEFAULT_PRIORITY, |
| 5422 &d, | 5394 &d, |
| (...skipping 562 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5985 TEST_F(URLRequestTestHTTP, Redirect307Tests) { | 5957 TEST_F(URLRequestTestHTTP, Redirect307Tests) { |
| 5986 ASSERT_TRUE(test_server_.Start()); | 5958 ASSERT_TRUE(test_server_.Start()); |
| 5987 | 5959 |
| 5988 const GURL url = test_server_.GetURL("files/redirect307-to-echo"); | 5960 const GURL url = test_server_.GetURL("files/redirect307-to-echo"); |
| 5989 | 5961 |
| 5990 HTTPRedirectMethodTest(url, "POST", "POST", true); | 5962 HTTPRedirectMethodTest(url, "POST", "POST", true); |
| 5991 HTTPRedirectMethodTest(url, "PUT", "PUT", true); | 5963 HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
| 5992 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); | 5964 HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
| 5993 } | 5965 } |
| 5994 | 5966 |
| 5967 TEST_F(URLRequestTestHTTP, Redirect302PreserveReferenceFragment) { |
| 5968 ASSERT_TRUE(test_server_.Start()); |
| 5969 |
| 5970 GURL original_url(test_server_.GetURL("files/redirect302-to-echo#fragment")); |
| 5971 GURL expected_url(test_server_.GetURL("echo#fragment")); |
| 5972 |
| 5973 TestDelegate d; |
| 5974 { |
| 5975 URLRequest r(original_url, DEFAULT_PRIORITY, &d, &default_context_); |
| 5976 |
| 5977 r.Start(); |
| 5978 base::RunLoop().Run(); |
| 5979 |
| 5980 EXPECT_EQ(2U, r.url_chain().size()); |
| 5981 EXPECT_EQ(URLRequestStatus::SUCCESS, r.status().status()); |
| 5982 EXPECT_EQ(net::OK, r.status().error()); |
| 5983 EXPECT_EQ(original_url, r.original_url()); |
| 5984 EXPECT_EQ(expected_url, r.url()); |
| 5985 } |
| 5986 } |
| 5987 |
| 5995 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { | 5988 TEST_F(URLRequestTestHTTP, InterceptPost302RedirectGet) { |
| 5996 ASSERT_TRUE(test_server_.Start()); | 5989 ASSERT_TRUE(test_server_.Start()); |
| 5997 | 5990 |
| 5998 const char kData[] = "hello world"; | 5991 const char kData[] = "hello world"; |
| 5999 | 5992 |
| 6000 TestDelegate d; | 5993 TestDelegate d; |
| 6001 URLRequest req(test_server_.GetURL("empty.html"), | 5994 URLRequest req(test_server_.GetURL("empty.html"), |
| 6002 DEFAULT_PRIORITY, | 5995 DEFAULT_PRIORITY, |
| 6003 &d, | 5996 &d, |
| 6004 &default_context_); | 5997 &default_context_); |
| (...skipping 1912 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7917 | 7910 |
| 7918 EXPECT_FALSE(r.is_pending()); | 7911 EXPECT_FALSE(r.is_pending()); |
| 7919 EXPECT_EQ(1, d->response_started_count()); | 7912 EXPECT_EQ(1, d->response_started_count()); |
| 7920 EXPECT_FALSE(d->received_data_before_response()); | 7913 EXPECT_FALSE(d->received_data_before_response()); |
| 7921 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); | 7914 EXPECT_EQ(d->bytes_received(), static_cast<int>(file_size)); |
| 7922 } | 7915 } |
| 7923 } | 7916 } |
| 7924 #endif // !defined(DISABLE_FTP_SUPPORT) | 7917 #endif // !defined(DISABLE_FTP_SUPPORT) |
| 7925 | 7918 |
| 7926 } // namespace net | 7919 } // namespace net |
| OLD | NEW |