| OLD | NEW |
| 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 5690 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5701 EXPECT_EQ(1U, root->child_count()); | 5701 EXPECT_EQ(1U, root->child_count()); |
| 5702 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { | 5702 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 5703 EXPECT_EQ(1U, nav_entry->root_node()->children.size()); | 5703 EXPECT_EQ(1U, nav_entry->root_node()->children.size()); |
| 5704 EXPECT_EQ(tree_node, nav_entry->root_node()->children[0]); | 5704 EXPECT_EQ(tree_node, nav_entry->root_node()->children[0]); |
| 5705 } | 5705 } |
| 5706 | 5706 |
| 5707 EXPECT_TRUE(ExecuteScript(root, kRemoveFrameScript)); | 5707 EXPECT_TRUE(ExecuteScript(root, kRemoveFrameScript)); |
| 5708 EXPECT_EQ(0U, root->child_count()); | 5708 EXPECT_EQ(0U, root->child_count()); |
| 5709 } | 5709 } |
| 5710 | 5710 |
| 5711 // Test that navigations classified as SAME_PAGE properly update all the |
| 5712 // members of FrameNavigationEntry. If not, it is possible to get a mismatch |
| 5713 // between the origin and URL of a document as seen in |
| 5714 // https://crbug.com/630103. |
| 5715 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 5716 EnsureSamePageNavigationUpdatesFrameNavigationEntry) { |
| 5717 WebContentsImpl* web_contents = |
| 5718 static_cast<WebContentsImpl*>(shell()->web_contents()); |
| 5719 FrameTreeNode* root = web_contents->GetFrameTree()->root(); |
| 5720 |
| 5721 // Navigate to a simple page and then perform an in-page navigation. |
| 5722 GURL start_url(embedded_test_server()->GetURL("a.com", "/title1.html")); |
| 5723 EXPECT_TRUE(NavigateToURL(shell(), start_url)); |
| 5724 |
| 5725 GURL same_page_url( |
| 5726 embedded_test_server()->GetURL("a.com", "/title1.html#foo")); |
| 5727 EXPECT_TRUE(NavigateToURL(shell(), same_page_url)); |
| 5728 EXPECT_EQ(2, web_contents->GetController().GetEntryCount()); |
| 5729 |
| 5730 // Replace the URL of the current NavigationEntry with one that will cause |
| 5731 // a server redirect when loaded. |
| 5732 { |
| 5733 GURL redirect_dest_url( |
| 5734 embedded_test_server()->GetURL("sub.a.com", "/simple_page.html")); |
| 5735 TestNavigationObserver observer(web_contents); |
| 5736 std::string script = "history.replaceState({}, '', '/server-redirect?" + |
| 5737 redirect_dest_url.spec() + "')"; |
| 5738 EXPECT_TRUE(ExecuteScript(root, script)); |
| 5739 observer.Wait(); |
| 5740 } |
| 5741 |
| 5742 // Simulate the user hitting Enter in the omnibox without changing the URL. |
| 5743 { |
| 5744 TestNavigationObserver observer(web_contents); |
| 5745 web_contents->GetController().LoadURL(web_contents->GetLastCommittedURL(), |
| 5746 Referrer(), ui::PAGE_TRANSITION_LINK, |
| 5747 std::string()); |
| 5748 observer.Wait(); |
| 5749 } |
| 5750 |
| 5751 // Prior to fixing the issue, the above omnibox navigation (which is |
| 5752 // classified as SAME_PAGE) was leaving the FrameNavigationEntry with the |
| 5753 // same document sequence number as the previous entry but updates the URL. |
| 5754 // Doing a back session history navigation now will cause the browser to |
| 5755 // consider it as in-page because of this matching document sequence number |
| 5756 // and lead to a mismatch of origin and URL in the renderer process. |
| 5757 { |
| 5758 TestNavigationObserver observer(web_contents); |
| 5759 web_contents->GetController().GoBack(); |
| 5760 observer.Wait(); |
| 5761 } |
| 5762 |
| 5763 // Verify the expected origin through JavaScript. It also has the additional |
| 5764 // verification of the process also being still alive. |
| 5765 std::string origin; |
| 5766 EXPECT_TRUE(ExecuteScriptAndExtractString( |
| 5767 web_contents, "domAutomationController.send(document.origin)", &origin)); |
| 5768 EXPECT_EQ(start_url.GetOrigin().spec(), origin + "/"); |
| 5769 } |
| 5770 |
| 5711 } // namespace content | 5771 } // namespace content |
| OLD | NEW |