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..8dbf291481c9e5b2afd1796eb86b50eeaadf9cf4 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,59 @@ IN_PROC_BROWSER_TEST_F(SessionHistoryTest, HistoryLength) { |
| EXPECT_EQ(2, length); |
| } |
| +IN_PROC_BROWSER_TEST_F(SessionHistoryTest, |
|
Charlie Reis
2016/05/23 20:51:35
Let's put an explanation up here about the differe
Łukasz Anforowicz
2016/05/24 19:08:08
Done.
|
| + 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 |