| 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 "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/strings/stringprintf.h" | 6 #include "base/strings/stringprintf.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "content/browser/frame_host/frame_navigation_entry.h" | 8 #include "content/browser/frame_host/frame_navigation_entry.h" |
| 9 #include "content/browser/frame_host/frame_tree.h" | 9 #include "content/browser/frame_host/frame_tree.h" |
| 10 #include "content/browser/frame_host/navigation_controller_impl.h" | 10 #include "content/browser/frame_host/navigation_controller_impl.h" |
| (...skipping 1674 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1685 EXPECT_EQ( | 1685 EXPECT_EQ( |
| 1686 " Site A ------------ proxies for B\n" | 1686 " Site A ------------ proxies for B\n" |
| 1687 " |--Site A ------- proxies for B\n" | 1687 " |--Site A ------- proxies for B\n" |
| 1688 " +--Site B ------- proxies for A\n" | 1688 " +--Site B ------- proxies for A\n" |
| 1689 "Where A = http://127.0.0.1/\n" | 1689 "Where A = http://127.0.0.1/\n" |
| 1690 " B = http://baz.com/", | 1690 " B = http://baz.com/", |
| 1691 visualizer.DepictFrameTree(root)); | 1691 visualizer.DepictFrameTree(root)); |
| 1692 } | 1692 } |
| 1693 } | 1693 } |
| 1694 | 1694 |
| 1695 // Verify that the tree of FrameNavigationEntries is preserved after in-page |
| 1696 // navigations (both in the main frame and in subframes). Otherwise we cannot |
| 1697 // navigate in those subframes or add new subframes to them. |
| 1698 // See https://crbug.com/522193. |
| 1699 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1700 FrameNavigationEntry_SubframeAfterInPage) { |
| 1701 // 1. Start on a page with a subframe. |
| 1702 GURL main_url(embedded_test_server()->GetURL( |
| 1703 "/navigation_controller/page_with_iframe.html")); |
| 1704 NavigateToURL(shell(), main_url); |
| 1705 const NavigationControllerImpl& controller = |
| 1706 static_cast<const NavigationControllerImpl&>( |
| 1707 shell()->web_contents()->GetController()); |
| 1708 FrameTreeNode* root = |
| 1709 static_cast<WebContentsImpl*>(shell()->web_contents())-> |
| 1710 GetFrameTree()->root(); |
| 1711 |
| 1712 ASSERT_EQ(1U, root->child_count()); |
| 1713 ASSERT_NE(nullptr, root->child_at(0)); |
| 1714 |
| 1715 // Navigate to a real page in the subframe, so that the next navigation will |
| 1716 // be MANUAL_SUBFRAME. |
| 1717 GURL subframe_url(embedded_test_server()->GetURL( |
| 1718 "/navigation_controller/simple_page_1.html")); |
| 1719 { |
| 1720 LoadCommittedCapturer capturer(root->child_at(0)); |
| 1721 NavigateFrameToURL(root->child_at(0), subframe_url); |
| 1722 capturer.Wait(); |
| 1723 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1724 } |
| 1725 |
| 1726 // 2. In-page navigation in the main frame. |
| 1727 std::string push_script = "history.pushState({}, 'page 2', 'page_2.html')"; |
| 1728 EXPECT_TRUE(content::ExecuteScript(root->current_frame_host(), push_script)); |
| 1729 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1730 |
| 1731 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 1732 EXPECT_EQ(2, controller.GetEntryCount()); |
| 1733 NavigationEntryImpl* entry = controller.GetLastCommittedEntry(); |
| 1734 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 1735 // The entry should still have a subframe entry. |
| 1736 ASSERT_EQ(1U, entry->root_node()->children.size()); |
| 1737 FrameNavigationEntry* frame_entry = |
| 1738 entry->root_node()->children[0]->frame_entry.get(); |
| 1739 EXPECT_EQ(subframe_url, frame_entry->url()); |
| 1740 } else { |
| 1741 // There are no subframe FrameNavigationEntries by default. |
| 1742 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1743 } |
| 1744 |
| 1745 // 3. Add a nested subframe. |
| 1746 { |
| 1747 LoadCommittedCapturer capturer(shell()->web_contents()); |
| 1748 std::string script = "var iframe = document.createElement('iframe');" |
| 1749 "iframe.src = '" + subframe_url.spec() + "';" |
| 1750 "document.body.appendChild(iframe);"; |
| 1751 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| 1752 script)); |
| 1753 capturer.Wait(); |
| 1754 EXPECT_EQ(ui::PAGE_TRANSITION_AUTO_SUBFRAME, capturer.transition_type()); |
| 1755 } |
| 1756 |
| 1757 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 1758 EXPECT_EQ(2, controller.GetEntryCount()); |
| 1759 entry = controller.GetLastCommittedEntry(); |
| 1760 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 1761 // The entry should have two subframe FrameNavigationEntries, nested. |
| 1762 ASSERT_EQ(1U, entry->root_node()->children.size()); |
| 1763 ASSERT_EQ(1U, entry->root_node()->children[0]->children.size()); |
| 1764 FrameNavigationEntry* frame_entry = |
| 1765 entry->root_node()->children[0]->children[0]->frame_entry.get(); |
| 1766 EXPECT_EQ(subframe_url, frame_entry->url()); |
| 1767 } else { |
| 1768 // There are no subframe FrameNavigationEntries by default. |
| 1769 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1770 } |
| 1771 |
| 1772 // 4. Navigate in-page in subframe. |
| 1773 EXPECT_TRUE(content::ExecuteScript(root->child_at(0)->current_frame_host(), |
| 1774 push_script)); |
| 1775 EXPECT_TRUE(WaitForLoadStop(shell()->web_contents())); |
| 1776 |
| 1777 // Verify subframe entries if they're enabled (e.g. in --site-per-process). |
| 1778 EXPECT_EQ(3, controller.GetEntryCount()); |
| 1779 entry = controller.GetLastCommittedEntry(); |
| 1780 if (SiteIsolationPolicy::UseSubframeNavigationEntries()) { |
| 1781 // The entry should still have two subframe FrameNavigationEntries, nested. |
| 1782 ASSERT_EQ(1U, entry->root_node()->children.size()); |
| 1783 ASSERT_EQ(1U, entry->root_node()->children[0]->children.size()); |
| 1784 FrameNavigationEntry* frame_entry = |
| 1785 entry->root_node()->children[0]->children[0]->frame_entry.get(); |
| 1786 EXPECT_EQ(subframe_url, frame_entry->url()); |
| 1787 } else { |
| 1788 // There are no subframe FrameNavigationEntries by default. |
| 1789 EXPECT_EQ(0U, entry->root_node()->children.size()); |
| 1790 } |
| 1791 |
| 1792 // 5. Navigate in innermost subframe. |
| 1793 GURL nested_url(embedded_test_server()->GetURL( |
| 1794 "/navigation_controller/simple_page_2.html")); |
| 1795 { |
| 1796 FrameNavigateParamsCapturer capturer(root->child_at(0)->child_at(0)); |
| 1797 NavigateFrameToURL(root->child_at(0)->child_at(0), nested_url); |
| 1798 capturer.Wait(); |
| 1799 EXPECT_EQ(ui::PAGE_TRANSITION_MANUAL_SUBFRAME, |
| 1800 capturer.params().transition); |
| 1801 EXPECT_EQ(NAVIGATION_TYPE_NEW_SUBFRAME, capturer.details().type); |
| 1802 } |
| 1803 } |
| 1804 |
| 1695 // Verify the tree of FrameNavigationEntries after back/forward navigations in a | 1805 // Verify the tree of FrameNavigationEntries after back/forward navigations in a |
| 1696 // cross-site subframe. | 1806 // cross-site subframe. |
| 1697 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, | 1807 IN_PROC_BROWSER_TEST_F(NavigationControllerBrowserTest, |
| 1698 FrameNavigationEntry_SubframeBackForward) { | 1808 FrameNavigationEntry_SubframeBackForward) { |
| 1699 GURL main_url(embedded_test_server()->GetURL( | 1809 GURL main_url(embedded_test_server()->GetURL( |
| 1700 "/navigation_controller/simple_page_1.html")); | 1810 "/navigation_controller/simple_page_1.html")); |
| 1701 NavigateToURL(shell(), main_url); | 1811 NavigateToURL(shell(), main_url); |
| 1702 const NavigationControllerImpl& controller = | 1812 const NavigationControllerImpl& controller = |
| 1703 static_cast<const NavigationControllerImpl&>( | 1813 static_cast<const NavigationControllerImpl&>( |
| 1704 shell()->web_contents()->GetController()); | 1814 shell()->web_contents()->GetController()); |
| (...skipping 629 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2334 EXPECT_EQ(original_url, capturer.all_params()[1].url); | 2444 EXPECT_EQ(original_url, capturer.all_params()[1].url); |
| 2335 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); | 2445 EXPECT_EQ(original_url, shell()->web_contents()->GetLastCommittedURL()); |
| 2336 } | 2446 } |
| 2337 | 2447 |
| 2338 // Make sure the renderer is still alive. | 2448 // Make sure the renderer is still alive. |
| 2339 EXPECT_TRUE( | 2449 EXPECT_TRUE( |
| 2340 ExecuteScript(shell()->web_contents(), "console.log('Success');")); | 2450 ExecuteScript(shell()->web_contents(), "console.log('Success');")); |
| 2341 } | 2451 } |
| 2342 | 2452 |
| 2343 } // namespace content | 2453 } // namespace content |
| OLD | NEW |