OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/files/file_path.h" | 6 #include "base/files/file_path.h" |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "base/time/time.h" | 8 #include "base/time/time.h" |
9 #include "content/browser/frame_host/cross_site_transferring_request.h" | 9 #include "content/browser/frame_host/cross_site_transferring_request.h" |
10 #include "content/browser/frame_host/navigation_before_commit_info.h" | 10 #include "content/browser/frame_host/navigation_before_commit_info.h" |
(...skipping 1680 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1691 EXPECT_FALSE(rvh_deleted_observer.deleted()); | 1691 EXPECT_FALSE(rvh_deleted_observer.deleted()); |
1692 } | 1692 } |
1693 } | 1693 } |
1694 | 1694 |
1695 // PlzNavigate: Test that a proper NavigationRequest is created by | 1695 // PlzNavigate: Test that a proper NavigationRequest is created by |
1696 // BeginNavigation. | 1696 // BeginNavigation. |
1697 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { | 1697 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { |
1698 const GURL kUrl1("http://www.google.com/"); | 1698 const GURL kUrl1("http://www.google.com/"); |
1699 const GURL kUrl2("http://www.chromium.org/"); | 1699 const GURL kUrl2("http://www.chromium.org/"); |
1700 const GURL kUrl3("http://www.gmail.com/"); | 1700 const GURL kUrl3("http://www.gmail.com/"); |
| 1701 const int64 kFirstNavRequestID = 1; |
1701 | 1702 |
1702 // TODO(clamy): we should be enabling browser side navigations here | 1703 // TODO(clamy): we should be enabling browser side navigations here |
1703 // when CommitNavigation is properly implemented. | 1704 // when CommitNavigation is properly implemented. |
1704 // Navigate to the first page. | 1705 // Navigate to the first page. |
1705 contents()->NavigateAndCommit(kUrl1); | 1706 contents()->NavigateAndCommit(kUrl1); |
1706 | 1707 |
1707 EnableBrowserSideNavigation(); | 1708 EnableBrowserSideNavigation(); |
1708 // Add a subframe. | 1709 // Add a subframe. |
1709 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( | 1710 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( |
1710 contents()->GetFrameTree()->AddFrame( | 1711 contents()->GetFrameTree()->AddFrame( |
1711 contents()->GetFrameTree()->root(), 14, "Child")); | 1712 contents()->GetFrameTree()->root(), 14, "Child")); |
1712 | 1713 |
1713 // Simulate a BeginNavigation IPC on the subframe. | 1714 // Simulate a BeginNavigation IPC on the subframe. |
1714 subframe_rfh->SendBeginNavigationWithURL(kUrl2); | 1715 subframe_rfh->SendBeginNavigationWithURL(kUrl2); |
1715 NavigationRequest* subframe_request = | 1716 NavigationRequest* subframe_request = |
1716 GetNavigationRequestForRenderFrameManager( | 1717 GetNavigationRequestForRenderFrameManager( |
1717 subframe_rfh->frame_tree_node()->render_manager()); | 1718 subframe_rfh->frame_tree_node()->render_manager()); |
1718 ASSERT_TRUE(subframe_request); | 1719 ASSERT_TRUE(subframe_request); |
1719 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url); | 1720 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url); |
1720 // First party for cookies url should be that of the main frame. | 1721 // First party for cookies url should be that of the main frame. |
1721 EXPECT_EQ( | 1722 EXPECT_EQ( |
1722 kUrl1, subframe_request->info().first_party_for_cookies); | 1723 kUrl1, subframe_request->info().first_party_for_cookies); |
1723 EXPECT_FALSE(subframe_request->info().is_main_frame); | 1724 EXPECT_FALSE(subframe_request->info().is_main_frame); |
1724 EXPECT_TRUE(subframe_request->info().parent_is_main_frame); | 1725 EXPECT_TRUE(subframe_request->info().parent_is_main_frame); |
| 1726 EXPECT_EQ(kFirstNavRequestID, subframe_request->navigation_request_id()); |
1725 | 1727 |
1726 // Simulate a BeginNavigation IPC on the main frame. | 1728 // Simulate a BeginNavigation IPC on the main frame. |
1727 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); | 1729 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); |
1728 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager( | 1730 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager( |
1729 contents()->GetMainFrame()->frame_tree_node()->render_manager()); | 1731 contents()->GetMainFrame()->frame_tree_node()->render_manager()); |
1730 ASSERT_TRUE(main_request); | 1732 ASSERT_TRUE(main_request); |
1731 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url); | 1733 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url); |
1732 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies); | 1734 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies); |
1733 EXPECT_TRUE(main_request->info().is_main_frame); | 1735 EXPECT_TRUE(main_request->info().is_main_frame); |
1734 EXPECT_FALSE(main_request->info().parent_is_main_frame); | 1736 EXPECT_FALSE(main_request->info().parent_is_main_frame); |
| 1737 EXPECT_EQ(kFirstNavRequestID + 1, main_request->navigation_request_id()); |
1735 } | 1738 } |
1736 | 1739 |
1737 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that | 1740 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that |
1738 // RenderFrameHost is not modified when the navigation commits. | 1741 // RenderFrameHost is not modified when the navigation commits. |
1739 TEST_F(RenderFrameHostManagerTest, | 1742 TEST_F(RenderFrameHostManagerTest, |
1740 BrowserSideNavigationRequestNavigationNoLiveRenderer) { | 1743 BrowserSideNavigationRequestNavigationNoLiveRenderer) { |
1741 const GURL kUrl("http://www.google.com/"); | 1744 const GURL kUrl("http://www.google.com/"); |
1742 | 1745 |
1743 EnableBrowserSideNavigation(); | 1746 EnableBrowserSideNavigation(); |
1744 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1747 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1745 contents()->GetController().LoadURL( | 1748 contents()->GetController().LoadURL( |
1746 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); | 1749 kUrl, Referrer(), PAGE_TRANSITION_LINK, std::string()); |
1747 RenderFrameHostManager* render_manager = | 1750 RenderFrameHostManager* render_manager = |
1748 main_test_rfh()->frame_tree_node()->render_manager(); | 1751 main_test_rfh()->frame_tree_node()->render_manager(); |
1749 NavigationRequest* main_request = | 1752 NavigationRequest* main_request = |
1750 GetNavigationRequestForRenderFrameManager(render_manager); | 1753 GetNavigationRequestForRenderFrameManager(render_manager); |
1751 // A NavigationRequest should have been generated. | 1754 // A NavigationRequest should have been generated. |
1752 EXPECT_TRUE(main_request != NULL); | 1755 EXPECT_TRUE(main_request != NULL); |
1753 RenderFrameHostImpl* rfh = main_test_rfh(); | 1756 RenderFrameHostImpl* rfh = main_test_rfh(); |
1754 | 1757 |
1755 // Now commit the same url. | 1758 // Now commit the same url. |
1756 NavigationBeforeCommitInfo commit_info; | 1759 NavigationBeforeCommitInfo commit_info; |
1757 commit_info.navigation_url = kUrl; | 1760 commit_info.navigation_url = kUrl; |
| 1761 commit_info.navigation_request_id = main_request->navigation_request_id(); |
1758 render_manager->CommitNavigation(commit_info); | 1762 render_manager->CommitNavigation(commit_info); |
1759 main_request = GetNavigationRequestForRenderFrameManager(render_manager); | 1763 main_request = GetNavigationRequestForRenderFrameManager(render_manager); |
1760 | 1764 |
1761 // The main RFH should not have been changed, and the renderer should have | 1765 // The main RFH should not have been changed, and the renderer should have |
1762 // been initialized. | 1766 // been initialized. |
1763 EXPECT_EQ(rfh, main_test_rfh()); | 1767 EXPECT_EQ(rfh, main_test_rfh()); |
1764 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1768 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1765 } | 1769 } |
1766 | 1770 |
1767 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross | 1771 // PlzNavigate: Test that a new RenderFrameHost is created when doing a cross |
(...skipping 15 matching lines...) Expand all Loading... |
1783 | 1787 |
1784 EnableBrowserSideNavigation(); | 1788 EnableBrowserSideNavigation(); |
1785 // Navigate to a different site. | 1789 // Navigate to a different site. |
1786 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); | 1790 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
1787 NavigationRequest* main_request = | 1791 NavigationRequest* main_request = |
1788 GetNavigationRequestForRenderFrameManager(render_manager); | 1792 GetNavigationRequestForRenderFrameManager(render_manager); |
1789 ASSERT_TRUE(main_request); | 1793 ASSERT_TRUE(main_request); |
1790 | 1794 |
1791 NavigationBeforeCommitInfo commit_info; | 1795 NavigationBeforeCommitInfo commit_info; |
1792 commit_info.navigation_url = kUrl2; | 1796 commit_info.navigation_url = kUrl2; |
| 1797 commit_info.navigation_request_id = main_request->navigation_request_id(); |
1793 render_manager->CommitNavigation(commit_info); | 1798 render_manager->CommitNavigation(commit_info); |
1794 main_request = GetNavigationRequestForRenderFrameManager(render_manager); | |
1795 EXPECT_NE(main_test_rfh(), rfh); | 1799 EXPECT_NE(main_test_rfh(), rfh); |
1796 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); | 1800 EXPECT_TRUE(main_test_rfh()->render_view_host()->IsRenderViewLive()); |
1797 } | 1801 } |
1798 | 1802 |
| 1803 // PlzNavigate: Test that a navigation commit is ignored if another request has |
| 1804 // been issued in the meantime. |
| 1805 // TODO(carlosk): add checks to assert that the cancel call was sent to |
| 1806 // ResourceDispatcherHost in the IO thread by extending |
| 1807 // ResourceDispatcherHostDelegate (like in cross_site_transfer_browsertest.cc |
| 1808 // and plugin_browsertest.cc). |
| 1809 TEST_F(RenderFrameHostManagerTest, |
| 1810 BrowserSideNavigationIgnoreStaleNavigationCommit) { |
| 1811 const GURL kUrl0("http://www.wikipedia.org/"); |
| 1812 const GURL kUrl0_site = SiteInstance::GetSiteForURL(browser_context(), kUrl0); |
| 1813 const GURL kUrl1("http://www.chromium.org/"); |
| 1814 const GURL kUrl2("http://www.google.com/"); |
| 1815 const GURL kUrl2_site = SiteInstance::GetSiteForURL(browser_context(), kUrl2); |
| 1816 |
| 1817 // Initialization. |
| 1818 contents()->NavigateAndCommit(kUrl0); |
| 1819 RenderFrameHostManager* render_manager = |
| 1820 main_test_rfh()->frame_tree_node()->render_manager(); |
| 1821 EnableBrowserSideNavigation(); |
| 1822 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
| 1823 |
| 1824 // Request navigation to the 1st URL and gather data. |
| 1825 main_test_rfh()->SendBeginNavigationWithURL(kUrl1); |
| 1826 NavigationRequest* request1 = |
| 1827 GetNavigationRequestForRenderFrameManager(render_manager); |
| 1828 ASSERT_TRUE(request1); |
| 1829 int64 request_id1 = request1->navigation_request_id(); |
| 1830 |
| 1831 // Request navigation to the 2nd URL and gather more data. |
| 1832 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); |
| 1833 NavigationRequest* request2 = |
| 1834 GetNavigationRequestForRenderFrameManager(render_manager); |
| 1835 ASSERT_TRUE(request2); |
| 1836 int64 request_id2 = request2->navigation_request_id(); |
| 1837 EXPECT_NE(request_id1, request_id2); |
| 1838 |
| 1839 // Confirms that a stale commit is ignored by the RHFM. |
| 1840 NavigationBeforeCommitInfo nbc_info; |
| 1841 nbc_info.navigation_url = kUrl1; |
| 1842 nbc_info.navigation_request_id = request_id1; |
| 1843 render_manager->CommitNavigation(nbc_info); |
| 1844 EXPECT_EQ(kUrl0_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
| 1845 |
| 1846 // Confirms that a valid, request-matching commit is correctly processed. |
| 1847 nbc_info.navigation_url = kUrl2; |
| 1848 nbc_info.navigation_request_id = request_id2; |
| 1849 render_manager->CommitNavigation(nbc_info); |
| 1850 EXPECT_EQ(kUrl2_site, main_test_rfh()->GetSiteInstance()->GetSiteURL()); |
| 1851 } |
| 1852 |
1799 } // namespace content | 1853 } // namespace content |
OLD | NEW |