Index: net/url_request/url_request_unittest.cc |
diff --git a/net/url_request/url_request_unittest.cc b/net/url_request/url_request_unittest.cc |
index ba4d52a56994039b0015b7db4a3fc76b08eeae61..3d3999997d5d8ee2746fbbc5699e142d2ffffc5f 100644 |
--- a/net/url_request/url_request_unittest.cc |
+++ b/net/url_request/url_request_unittest.cc |
@@ -2853,6 +2853,43 @@ class URLRequestTestHTTP : public URLRequestTest { |
LOG(WARNING) << "Request method was: " << request_method; |
} |
+ // Requests |redirect_url|, which must return a HTTP 3xx redirect. |
+ // |request_method| is the method to use for the initial request. |
+ // |redirect_method| is the method that is expected to be used for the second |
+ // request, after redirection. |
+ // |origin_value| is the expected value for the Origin header after |
+ // redirection. If empty, expects that there will be no Origin header. |
+ void HTTPRedirectOriginHeaderTest(const GURL& redirect_url, |
+ const std::string& request_method, |
+ const std::string& redirect_method, |
+ const std::string& origin_value) { |
+ TestDelegate d; |
+ scoped_ptr<URLRequest> req(default_context_.CreateRequest( |
+ redirect_url, DEFAULT_PRIORITY, &d, NULL)); |
davidben
2015/03/24 23:47:38
Note: you'll need to remove that trailing NULL on
jww
2015/03/27 22:16:15
Will do.
|
+ req->set_method(request_method); |
+ req->SetExtraRequestHeaderByName(HttpRequestHeaders::kOrigin, |
+ redirect_url.GetOrigin().spec(), false); |
+ req->Start(); |
+ |
+ base::RunLoop().Run(); |
+ |
+ EXPECT_EQ(redirect_method, req->method()); |
+ // Note that there is no check for request success here because, for |
+ // purposes of testing, the request very well may fail. For example, if the |
+ // test redirects to an FTP server so it is cross origin, there is no such |
+ // FTP server, so the request would fail. However, that's fine, as long as |
+ // the request headers are in order and pass the checks below. |
davidben
2015/03/24 23:47:38
It's sort of confusing to have these tests use FTP
jww
2015/03/27 22:16:15
Agreed. I've rejiggered all of these new tests to
|
+ if (origin_value.empty()) { |
+ EXPECT_FALSE( |
+ req->extra_request_headers().HasHeader(HttpRequestHeaders::kOrigin)); |
+ } else { |
+ std::string origin_header; |
+ EXPECT_TRUE(req->extra_request_headers().GetHeader( |
+ HttpRequestHeaders::kOrigin, &origin_header)); |
+ EXPECT_EQ(origin_value, origin_header); |
+ } |
+ } |
+ |
void HTTPUploadDataOperationTest(const std::string& method) { |
const int kMsgSize = 20000; // multiple of 10 |
const int kIterations = 50; |
@@ -6244,50 +6281,80 @@ TEST_F(URLRequestTestHTTP, Redirect301Tests) { |
ASSERT_TRUE(test_server_.Start()); |
const GURL url = test_server_.GetURL("files/redirect301-to-echo"); |
+ const GURL ftp_redirect_url = test_server_.GetURL("files/redirect301-to-ftp"); |
HTTPRedirectMethodTest(url, "POST", "GET", true); |
HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
+ |
+ HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); |
+ HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
davidben
2015/03/24 23:47:38
Aside: does the spec say to drop the Origin header
jww
2015/03/27 22:16:15
No, RFC 6454 does not say to do so, nor can I find
|
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "GET", std::string()); |
} |
TEST_F(URLRequestTestHTTP, Redirect302Tests) { |
ASSERT_TRUE(test_server_.Start()); |
const GURL url = test_server_.GetURL("files/redirect302-to-echo"); |
+ const GURL ftp_redirect_url = test_server_.GetURL("files/redirect302-to-ftp"); |
HTTPRedirectMethodTest(url, "POST", "GET", true); |
HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
+ |
+ HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); |
+ HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "GET", std::string()); |
} |
TEST_F(URLRequestTestHTTP, Redirect303Tests) { |
ASSERT_TRUE(test_server_.Start()); |
const GURL url = test_server_.GetURL("files/redirect303-to-echo"); |
+ const GURL ftp_redirect_url = test_server_.GetURL("files/redirect303-to-ftp"); |
HTTPRedirectMethodTest(url, "POST", "GET", true); |
HTTPRedirectMethodTest(url, "PUT", "GET", true); |
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
+ |
+ HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); |
+ HTTPRedirectOriginHeaderTest(url, "POST", "GET", std::string()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "GET", std::string()); |
} |
TEST_F(URLRequestTestHTTP, Redirect307Tests) { |
ASSERT_TRUE(test_server_.Start()); |
const GURL url = test_server_.GetURL("files/redirect307-to-echo"); |
+ const GURL ftp_redirect_url = test_server_.GetURL("files/redirect307-to-ftp"); |
HTTPRedirectMethodTest(url, "POST", "POST", true); |
HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
+ |
+ HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); |
+ HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "POST", "null"); |
} |
TEST_F(URLRequestTestHTTP, Redirect308Tests) { |
ASSERT_TRUE(test_server_.Start()); |
const GURL url = test_server_.GetURL("files/redirect308-to-echo"); |
+ const GURL ftp_redirect_url = test_server_.GetURL("files/redirect308-to-ftp"); |
HTTPRedirectMethodTest(url, "POST", "POST", true); |
HTTPRedirectMethodTest(url, "PUT", "PUT", true); |
HTTPRedirectMethodTest(url, "HEAD", "HEAD", false); |
+ |
+ HTTPRedirectOriginHeaderTest(url, "GET", "GET", url.GetOrigin().spec()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "GET", "GET", "null"); |
+ HTTPRedirectOriginHeaderTest(url, "POST", "POST", url.GetOrigin().spec()); |
+ HTTPRedirectOriginHeaderTest(ftp_redirect_url, "POST", "POST", "null"); |
} |
// Make sure that 308 responses without bodies are not treated as redirects. |