Chromium Code Reviews| Index: content/public/test/browser_test_utils.cc |
| diff --git a/content/public/test/browser_test_utils.cc b/content/public/test/browser_test_utils.cc |
| index f24c5f4ba08ac33e3fadb40627838b36845638a6..bb8bc6687cdb5460732d75f2d4c94e762bcc2ab5 100644 |
| --- a/content/public/test/browser_test_utils.cc |
| +++ b/content/public/test/browser_test_utils.cc |
| @@ -291,12 +291,25 @@ void SetCookieOnIOThread(const GURL& url, |
| std::unique_ptr<net::test_server::HttpResponse> |
| CrossSiteRedirectResponseHandler(const GURL& server_base_url, |
| const net::test_server::HttpRequest& request) { |
| - std::string prefix("/cross-site/"); |
| - if (!base::StartsWith(request.relative_url, prefix, |
| - base::CompareCase::SENSITIVE)) |
| + net::HttpStatusCode http_status_code; |
| + |
| + // Inspect the prefix and extract the remainder of the url into |params|. |
| + size_t length_of_chosen_prefix; |
| + std::string prefix_302("/cross-site/"); |
| + std::string prefix_307("/cross-site-307/"); |
|
Charlie Reis
2016/05/23 20:51:35
Hmm, this feels like it's growing into a bit of a
Łukasz Anforowicz
2016/05/24 19:08:08
I think it would feel much less like a hack if it
|
| + if (base::StartsWith(request.relative_url, prefix_302, |
| + base::CompareCase::SENSITIVE)) { |
| + http_status_code = net::HTTP_MOVED_PERMANENTLY; |
| + length_of_chosen_prefix = prefix_302.length(); |
| + } else if (base::StartsWith(request.relative_url, prefix_307, |
| + base::CompareCase::SENSITIVE)) { |
| + http_status_code = net::HTTP_TEMPORARY_REDIRECT; |
| + length_of_chosen_prefix = prefix_307.length(); |
| + } else { |
| + // Unrecognized prefix - let somebody else handle this request. |
| return std::unique_ptr<net::test_server::HttpResponse>(); |
| - |
| - std::string params = request.relative_url.substr(prefix.length()); |
| + } |
| + std::string params = request.relative_url.substr(length_of_chosen_prefix); |
| // A hostname to redirect to must be included in the URL, therefore at least |
| // one '/' character is expected. |
| @@ -316,7 +329,7 @@ CrossSiteRedirectResponseHandler(const GURL& server_base_url, |
| std::unique_ptr<net::test_server::BasicHttpResponse> http_response( |
| new net::test_server::BasicHttpResponse); |
| - http_response->set_code(net::HTTP_MOVED_PERMANENTLY); |
| + http_response->set_code(http_status_code); |
| http_response->AddCustomHeader("Location", redirect_target.spec()); |
| return std::move(http_response); |
| } |