Chromium Code Reviews| Index: content/browser/session_history_browsertest.cc |
| diff --git a/content/browser/session_history_browsertest.cc b/content/browser/session_history_browsertest.cc |
| index aae42f6252170cd383a86acbf20eaed558ca32b6..edef091f821dbab2da40be26b0e20c30bf1584b8 100644 |
| --- a/content/browser/session_history_browsertest.cc |
| +++ b/content/browser/session_history_browsertest.cc |
| @@ -15,8 +15,10 @@ |
| #include "content/public/test/browser_test_utils.h" |
| #include "content/public/test/content_browser_test.h" |
| #include "content/public/test/content_browser_test_utils.h" |
| +#include "content/public/test/test_navigation_observer.h" |
| #include "content/public/test/test_utils.h" |
| #include "content/shell/browser/shell.h" |
| +#include "net/dns/mock_host_resolver.h" |
| #include "net/test/embedded_test_server/embedded_test_server.h" |
| #include "net/test/embedded_test_server/http_request.h" |
| #include "net/test/embedded_test_server/http_response.h" |
| @@ -51,7 +53,10 @@ class SessionHistoryTest : public ContentBrowserTest { |
| SessionHistoryTest() {} |
| void SetUpOnMainThread() override { |
| + host_resolver()->AddRule("*", "127.0.0.1"); |
| + |
| ASSERT_TRUE(embedded_test_server()->Start()); |
| + SetupCrossSiteRedirector(embedded_test_server()); |
| embedded_test_server()->RegisterRequestHandler( |
| base::Bind(&HandleEchoTitleRequest, "/echotitle")); |
| @@ -499,4 +504,67 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { |
| EXPECT_EQ(2, length); |
| } |
| +// Test that verifies that a cross-process transfer doesn't loose session |
|
Charlie Reis
2016/05/24 20:49:53
nit: lose
Łukasz Anforowicz
2016/05/24 21:05:19
Done.
|
| +// history state - https://crbug.com/613004. |
| +// |
| +// Trigerring a cross-process transfer via embedded_test_server requires use of |
| +// a HTTP redirect reponse (to preserve port number). Therefore the test ends |
|
Charlie Reis
2016/05/24 20:49:53
nit: response
Łukasz Anforowicz
2016/05/24 21:05:19
Done. I did try to proof-read what I wrote and mi
|
| +// up accidentally testing redirection logic as well - in particular, the test |
| +// uses 307 (rather than 302) redirect to preserve the body of HTTP POST across |
| +// redirects (as mandated by https://tools.ietf.org/html/rfc7231#section-6.4.7). |
| +IN_PROC_BROWSER_TEST_F(SessionHistoryTest, |
| + GoBackToCrossSitePostWithRedirect) { |
| + GURL form_url(embedded_test_server()->GetURL( |
| + "a.com", "/session_history/form_that_posts_cross_site.html")); |
| + GURL redirect_target_url(embedded_test_server()->GetURL( |
| + "x.com", "/echoall")); |
| + GURL page_to_go_back_from(embedded_test_server()->GetURL( |
| + "c.com", "/title1.html")); |
| + |
| + // Navigate to the page with form that posts via 307 redirection to |
| + // |redirect_target_url| (cross-site from |form_url|). |
| + EXPECT_TRUE(NavigateToURL(shell(), form_url)); |
| + |
| + // Submit the form. |
| + TestNavigationObserver form_post_observer(shell()->web_contents(), 1); |
| + EXPECT_TRUE(ExecuteScript(shell()->web_contents(), |
| + "document.getElementById('form').submit();")); |
| + form_post_observer.Wait(); |
| + |
| + // Verify that we arrived at the expected, redirected location. |
| + EXPECT_EQ(redirect_target_url, |
| + shell()->web_contents()->GetLastCommittedURL()); |
| + |
| + // Verify that POST body got preserved by 307 redirect. This expectation |
| + // comes from: https://tools.ietf.org/html/rfc7231#section-6.4.7 |
| + std::string body; |
| + EXPECT_TRUE(ExecuteScriptAndExtractString( |
| + shell()->web_contents(), |
| + "window.domAutomationController.send(" |
| + "document.getElementsByTagName('pre')[0].innerText);", |
| + &body)); |
| + EXPECT_EQ("text=value\n", body); |
| + |
| + // Navigate to a page from yet another site. |
| + EXPECT_TRUE(NavigateToURL(shell(), page_to_go_back_from)); |
| + |
| + // Go back - this should resubmit form's post data. |
| + TestNavigationObserver back_nav_observer(shell()->web_contents(), 1); |
| + shell()->web_contents()->GetController().GoBack(); |
| + back_nav_observer.Wait(); |
| + |
| + // Again verify that we arrived at the expected, redirected location. |
| + EXPECT_EQ(redirect_target_url, |
| + shell()->web_contents()->GetLastCommittedURL()); |
| + |
| + // Again verify that POST body got preserved by 307 redirect. |
| + std::string body_after_back_navigation; |
| + EXPECT_TRUE(ExecuteScriptAndExtractString( |
| + shell()->web_contents(), |
| + "window.domAutomationController.send(" |
| + "document.getElementsByTagName('pre')[0].innerText);", |
| + &body_after_back_navigation)); |
| + EXPECT_EQ("text=value\n", body_after_back_navigation); |
| +} |
| + |
| } // namespace content |