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

Side by Side Diff: content/browser/frame_host/navigation_controller_impl_browsertest.cc

Issue 2155443002: Clear stale NavigationParams from HistoryController. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2785
Patch Set: Created 4 years, 5 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
« no previous file with comments | « no previous file | content/renderer/history_controller.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/frame_host/navigation_controller_impl.h" 5 #include "content/browser/frame_host/navigation_controller_impl.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 #include <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 4667 matching lines...) Expand 10 before | Expand all | Expand 10 after
4678 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); 4678 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4679 4679
4680 // We should be on url_b, and the renderer process shouldn't be killed. 4680 // We should be on url_b, and the renderer process shouldn't be killed.
4681 ASSERT_TRUE(root->current_frame_host()->IsRenderFrameLive()); 4681 ASSERT_TRUE(root->current_frame_host()->IsRenderFrameLive());
4682 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex()); 4682 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4683 EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL()); 4683 EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL());
4684 EXPECT_EQ(url_b, root->current_url()); 4684 EXPECT_EQ(url_b, root->current_url());
4685 EXPECT_EQ(0U, root->child_count()); 4685 EXPECT_EQ(0U, root->child_count());
4686 } 4686 }
4687 4687
4688 // Ensure that we do not corrupt a NavigationEntry's PageState if two forward
4689 // navigations compete in different frames, and the main frame entry contains an
4690 // iframe of its own. See https://crbug.com/623319.
4691 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
4692 PageStateWithIframeAfterForwardInCompetingFrames) {
4693 // Navigate to a page with an iframe.
4694 GURL url_a(embedded_test_server()->GetURL(
4695 "/navigation_controller/page_with_data_iframe.html"));
4696 GURL data_url("data:text/html,Subframe");
4697 EXPECT_TRUE(NavigateToURL(shell(), url_a));
4698
4699 NavigationController& controller = shell()->web_contents()->GetController();
4700 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
4701 ->GetFrameTree()
4702 ->root();
4703 EXPECT_EQ(url_a, root->current_url());
4704 EXPECT_EQ(data_url, root->child_at(0)->current_url());
4705
4706 // Navigate the iframe to a first real page.
4707 GURL frame_url_a1 = embedded_test_server()->GetURL(
4708 "/navigation_controller/simple_page_1.html");
4709 NavigateFrameToURL(root->child_at(0), frame_url_a1);
4710
4711 // Navigate the iframe to a second real page.
4712 GURL frame_url_a2 = embedded_test_server()->GetURL(
4713 "/navigation_controller/simple_page_2.html");
4714 NavigateFrameToURL(root->child_at(0), frame_url_a2);
4715 EXPECT_EQ(3, controller.GetEntryCount());
4716 EXPECT_EQ(2, controller.GetLastCommittedEntryIndex());
4717 EXPECT_EQ(url_a, root->current_url());
4718 EXPECT_EQ(frame_url_a2, root->child_at(0)->current_url());
4719
4720 // Go back to the middle entry.
4721 controller.GoBack();
4722 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4723 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4724
4725 // Replace the entry with a cross-site top-level page with an iframe. By
4726 // doing a replacement, the main frame pages before and after have the same
4727 // item sequence number, and thus going between them only requires loads in
4728 // the subframe.
4729 GURL url_b(embedded_test_server()->GetURL(
4730 "b.com", "/navigation_controller/page_with_data_iframe.html"));
4731 std::string replace_script = "location.replace('" + url_b.spec() + "')";
4732 TestNavigationObserver replace_observer(shell()->web_contents());
4733 EXPECT_TRUE(ExecuteScript(shell()->web_contents(), replace_script));
4734 replace_observer.Wait();
4735 EXPECT_EQ(3, controller.GetEntryCount());
4736 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4737 EXPECT_EQ(url_b, root->current_url());
4738 EXPECT_EQ(data_url, root->child_at(0)->current_url());
4739
4740 // Go back to the original page.
4741 controller.GoBack();
4742 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4743
4744 // Navigate forward twice using script. This will race, but in either outcome
4745 // we want to ensure that the subframes target entry index 1 and not 2. In
4746 // https://crbug.com/623319, the subframes targeted the wrong entry, leading
4747 // to a URL spoof and renderer kill.
4748 EXPECT_TRUE(ExecuteScript(shell()->web_contents(),
4749 "history.forward(); history.forward();"));
4750 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4751 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4752 EXPECT_TRUE(root->current_frame_host()->IsRenderFrameLive());
4753 EXPECT_EQ(url_b, root->current_url());
4754 EXPECT_EQ(data_url, root->child_at(0)->current_url());
4755 NavigationEntry* entry = controller.GetLastCommittedEntry();
4756 EXPECT_EQ(url_b, entry->GetURL());
4757 ExplodedPageState exploded_state;
4758 EXPECT_TRUE(
4759 DecodePageState(entry->GetPageState().ToEncodedData(), &exploded_state));
4760 EXPECT_EQ(url_b, GURL(exploded_state.top.url_string.string()));
4761
4762 // Go back and then forward to see if the PageState loads correctly.
4763 controller.GoBack();
4764 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4765 controller.GoForward();
4766 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents()));
4767
4768 // We should be on url_b, and the renderer process shouldn't be killed.
4769 ASSERT_TRUE(root->current_frame_host()->IsRenderFrameLive());
4770 EXPECT_EQ(1, controller.GetLastCommittedEntryIndex());
4771 EXPECT_EQ(url_b, shell()->web_contents()->GetVisibleURL());
4772 EXPECT_EQ(url_b, root->current_url());
4773 EXPECT_EQ(data_url, root->child_at(0)->current_url());
4774 }
4775
4688 // Ensure that forward navigations in cloned tabs can commit if they redirect to 4776 // Ensure that forward navigations in cloned tabs can commit if they redirect to
4689 // a different site than before. This causes the navigation's item sequence 4777 // a different site than before. This causes the navigation's item sequence
4690 // number to change, meaning that we can't use it for determining whether the 4778 // number to change, meaning that we can't use it for determining whether the
4691 // commit matches the history item. See https://crbug.com/600238. 4779 // commit matches the history item. See https://crbug.com/600238.
4692 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, 4780 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest,
4693 ForwardRedirectWithNoCommittedEntry) { 4781 ForwardRedirectWithNoCommittedEntry) {
4694 NavigationController& controller = shell()->web_contents()->GetController(); 4782 NavigationController& controller = shell()->web_contents()->GetController();
4695 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents()) 4783 FrameTreeNode* root = static_cast<WebContentsImpl*>(shell()->web_contents())
4696 ->GetFrameTree() 4784 ->GetFrameTree()
4697 ->root(); 4785 ->root();
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
4834 std::string body; 4922 std::string body;
4835 EXPECT_TRUE(ExecuteScriptAndExtractString( 4923 EXPECT_TRUE(ExecuteScriptAndExtractString(
4836 shell()->web_contents(), 4924 shell()->web_contents(),
4837 "window.domAutomationController.send(" 4925 "window.domAutomationController.send("
4838 "document.getElementsByTagName('pre')[0].innerText);", 4926 "document.getElementsByTagName('pre')[0].innerText);",
4839 &body)); 4927 &body));
4840 EXPECT_EQ("text=value\n", body); 4928 EXPECT_EQ("text=value\n", body);
4841 } 4929 }
4842 4930
4843 } // namespace content 4931 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/renderer/history_controller.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698