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

Side by Side Diff: content/browser/session_history_browsertest.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 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <utility> 5 #include <utility>
6 6
7 #include "base/strings/string_util.h" 7 #include "base/strings/string_util.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "content/public/browser/navigation_controller.h" 10 #include "content/public/browser/navigation_controller.h"
11 #include "content/public/browser/notification_service.h" 11 #include "content/public/browser/notification_service.h"
12 #include "content/public/browser/notification_types.h" 12 #include "content/public/browser/notification_types.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "content/public/common/url_constants.h" 14 #include "content/public/common/url_constants.h"
15 #include "content/public/test/browser_test_utils.h" 15 #include "content/public/test/browser_test_utils.h"
16 #include "content/public/test/content_browser_test.h" 16 #include "content/public/test/content_browser_test.h"
17 #include "content/public/test/content_browser_test_utils.h" 17 #include "content/public/test/content_browser_test_utils.h"
18 #include "content/public/test/test_navigation_observer.h"
18 #include "content/public/test/test_utils.h" 19 #include "content/public/test/test_utils.h"
19 #include "content/shell/browser/shell.h" 20 #include "content/shell/browser/shell.h"
21 #include "net/dns/mock_host_resolver.h"
20 #include "net/test/embedded_test_server/embedded_test_server.h" 22 #include "net/test/embedded_test_server/embedded_test_server.h"
21 #include "net/test/embedded_test_server/http_request.h" 23 #include "net/test/embedded_test_server/http_request.h"
22 #include "net/test/embedded_test_server/http_response.h" 24 #include "net/test/embedded_test_server/http_response.h"
23 #include "testing/gtest/include/gtest/gtest.h" 25 #include "testing/gtest/include/gtest/gtest.h"
24 26
25 namespace content { 27 namespace content {
26 28
27 namespace { 29 namespace {
28 30
29 // Handles |request| by serving a response with title set to request contents. 31 // Handles |request| by serving a response with title set to request contents.
(...skipping 14 matching lines...) Expand all
44 return std::move(http_response); 46 return std::move(http_response);
45 } 47 }
46 48
47 } // namespace 49 } // namespace
48 50
49 class SessionHistoryTest : public ContentBrowserTest { 51 class SessionHistoryTest : public ContentBrowserTest {
50 protected: 52 protected:
51 SessionHistoryTest() {} 53 SessionHistoryTest() {}
52 54
53 void SetUpOnMainThread() override { 55 void SetUpOnMainThread() override {
56 host_resolver()->AddRule("*", "127.0.0.1");
57
54 ASSERT_TRUE(embedded_test_server()->Start()); 58 ASSERT_TRUE(embedded_test_server()->Start());
59 SetupCrossSiteRedirector(embedded_test_server());
55 embedded_test_server()->RegisterRequestHandler( 60 embedded_test_server()->RegisterRequestHandler(
56 base::Bind(&HandleEchoTitleRequest, "/echotitle")); 61 base::Bind(&HandleEchoTitleRequest, "/echotitle"));
57 62
58 NavigateToURL(shell(), GURL(url::kAboutBlankURL)); 63 NavigateToURL(shell(), GURL(url::kAboutBlankURL));
59 } 64 }
60 65
61 // Simulate clicking a link. Only works on the frames.html testserver page. 66 // Simulate clicking a link. Only works on the frames.html testserver page.
62 void ClickLink(const std::string& node_id) { 67 void ClickLink(const std::string& node_id) {
63 GURL url("javascript:clickLink('" + node_id + "')"); 68 GURL url("javascript:clickLink('" + node_id + "')");
64 NavigateToURL(shell(), url); 69 NavigateToURL(shell(), url);
(...skipping 427 matching lines...) Expand 10 before | Expand all | Expand 10 after
492 // Ensure history.length is properly truncated. 497 // Ensure history.length is properly truncated.
493 NavigateToURL(shell(), GetURL("title2.html")); 498 NavigateToURL(shell(), GetURL("title2.html"));
494 499
495 ASSERT_TRUE(ExecuteScriptAndExtractInt( 500 ASSERT_TRUE(ExecuteScriptAndExtractInt(
496 shell()->web_contents(), 501 shell()->web_contents(),
497 "domAutomationController.send(history.length)", 502 "domAutomationController.send(history.length)",
498 &length)); 503 &length));
499 EXPECT_EQ(2, length); 504 EXPECT_EQ(2, length);
500 } 505 }
501 506
507 // 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.
508 // history state - https://crbug.com/613004.
509 //
510 // Trigerring a cross-process transfer via embedded_test_server requires use of
511 // 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
512 // up accidentally testing redirection logic as well - in particular, the test
513 // uses 307 (rather than 302) redirect to preserve the body of HTTP POST across
514 // redirects (as mandated by https://tools.ietf.org/html/rfc7231#section-6.4.7).
515 IN_PROC_BROWSER_TEST_F(SessionHistoryTest,
516 GoBackToCrossSitePostWithRedirect) {
517 GURL form_url(embedded_test_server()->GetURL(
518 "a.com", "/session_history/form_that_posts_cross_site.html"));
519 GURL redirect_target_url(embedded_test_server()->GetURL(
520 "x.com", "/echoall"));
521 GURL page_to_go_back_from(embedded_test_server()->GetURL(
522 "c.com", "/title1.html"));
523
524 // Navigate to the page with form that posts via 307 redirection to
525 // |redirect_target_url| (cross-site from |form_url|).
526 EXPECT_TRUE(NavigateToURL(shell(), form_url));
527
528 // Submit the form.
529 TestNavigationObserver form_post_observer(shell()->web_contents(), 1);
530 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
531 "document.getElementById('form').submit();"));
532 form_post_observer.Wait();
533
534 // Verify that we arrived at the expected, redirected location.
535 EXPECT_EQ(redirect_target_url,
536 shell()->web_contents()->GetLastCommittedURL());
537
538 // Verify that POST body got preserved by 307 redirect. This expectation
539 // comes from: https://tools.ietf.org/html/rfc7231#section-6.4.7
540 std::string body;
541 EXPECT_TRUE(ExecuteScriptAndExtractString(
542 shell()->web_contents(),
543 "window.domAutomationController.send("
544 "document.getElementsByTagName('pre')[0].innerText);",
545 &body));
546 EXPECT_EQ("text=value\n", body);
547
548 // Navigate to a page from yet another site.
549 EXPECT_TRUE(NavigateToURL(shell(), page_to_go_back_from));
550
551 // Go back - this should resubmit form's post data.
552 TestNavigationObserver back_nav_observer(shell()->web_contents(), 1);
553 shell()->web_contents()->GetController().GoBack();
554 back_nav_observer.Wait();
555
556 // Again verify that we arrived at the expected, redirected location.
557 EXPECT_EQ(redirect_target_url,
558 shell()->web_contents()->GetLastCommittedURL());
559
560 // Again verify that POST body got preserved by 307 redirect.
561 std::string body_after_back_navigation;
562 EXPECT_TRUE(ExecuteScriptAndExtractString(
563 shell()->web_contents(),
564 "window.domAutomationController.send("
565 "document.getElementsByTagName('pre')[0].innerText);",
566 &body_after_back_navigation));
567 EXPECT_EQ("text=value\n", body_after_back_navigation);
568 }
569
502 } // namespace content 570 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/public/test/browser_test_utils.h » ('j') | content/public/test/browser_test_utils.h » ('J')

Powered by Google App Engine
This is Rietveld 408576698