Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1683)

Unified Diff: content/public/test/browser_test_utils.cc

Issue 1993093002: Test for navigating back to navigation that posts to a cross-site 307 redirect. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed remaining CR feedback from creis@. Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..d9f017d5bcf06773d42d2fca00488d487326b728 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/");
+ 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);
}
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/test/data/session_history/form_that_posts_cross_site.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698