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

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

Issue 475783002: PlzNavigate: add cancel navigation logic for uncommitted requests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed CR comments and removed the weird Observer. Trying to get this CL through and have the mo… Created 6 years, 3 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 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
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());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1781 1784
1782 EnableBrowserSideNavigation(); 1785 EnableBrowserSideNavigation();
1783 // Navigate to a different site. 1786 // Navigate to a different site.
1784 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 1787 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
1785 NavigationRequest* main_request = 1788 NavigationRequest* main_request =
1786 GetNavigationRequestForRenderFrameManager(render_manager); 1789 GetNavigationRequestForRenderFrameManager(render_manager);
1787 ASSERT_TRUE(main_request); 1790 ASSERT_TRUE(main_request);
1788 1791
1789 NavigationBeforeCommitInfo commit_info; 1792 NavigationBeforeCommitInfo commit_info;
1790 commit_info.navigation_url = kUrl2; 1793 commit_info.navigation_url = kUrl2;
1794 commit_info.navigation_request_id = main_request->navigation_request_id();
1791 render_manager->CommitNavigation(commit_info); 1795 render_manager->CommitNavigation(commit_info);
1792 main_request = GetNavigationRequestForRenderFrameManager(render_manager);
1793 EXPECT_NE(main_test_rfh(), rfh); 1796 EXPECT_NE(main_test_rfh(), rfh);
1794 } 1797 }
1795 1798
1799 // PlzNavigate: Test that a navigation commit is ignored if another request has
1800 // been issued in the meantime.
1801 // TODO(carlosk): add URL expectations once those are properly set after the
1802 // navigation is committed successfully.
1803 // TODO(carlosk): add checks to assert that the cancel call was sent to
1804 // ResourceDispatcherHost in the IO thread.
1805 TEST_F(RenderFrameHostManagerTest,
1806 BrowserSideNavigationIgnoreStaleNavigationCommit) {
1807 const GURL kUrl0("http://www.wikipedia.org/");
1808 const GURL kUrl1("http://www.chromium.org/");
1809 const GURL kUrl2("http://www.google.com/");
1810
1811 // Initialization.
1812 contents()->NavigateAndCommit(kUrl0);
1813 RenderFrameHostImpl* rfh1 = main_test_rfh();
1814 RenderFrameHostManager* render_manager =
1815 main_test_rfh()->frame_tree_node()->render_manager();
1816 EnableBrowserSideNavigation();
1817
1818 // Request navigation to the 1st URL and gather data.
1819 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
1820 NavigationRequest* request1 =
1821 GetNavigationRequestForRenderFrameManager(render_manager);
1822 ASSERT_TRUE(request1);
1823 int64 request_id1 = request1->navigation_request_id();
1824
1825 // Request navigation to the 2nd URL and gather more data.
1826 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
1827 NavigationRequest* request2 =
1828 GetNavigationRequestForRenderFrameManager(render_manager);
1829 ASSERT_TRUE(request2);
1830 int64 request_id2 = request2->navigation_request_id();
1831 EXPECT_NE(request_id1, request_id2);
1832
1833 // Confirms that a stale commit is ignored by the RHFM.
1834 NavigationBeforeCommitInfo nbc_info;
1835 nbc_info.navigation_url = kUrl1;
1836 nbc_info.navigation_request_id = request_id1;
1837 render_manager->CommitNavigation(nbc_info);
1838 EXPECT_EQ(main_test_rfh(), rfh1);
nasko 2014/09/02 14:10:57 I think it is better to compare SiteInstances of t
carlosk 2014/09/02 15:30:09 Done! When I initially wrote this test the that w
(Do not use) nasko 2014/09/02 17:20:28 You can just capture the site instance of an RFH i
carlosk 2014/09/03 18:27:00 Executed as discussed with Nasko.
1839
1840 // Confirms that a valid, request-matching commit is correctly processed.
1841 nbc_info.navigation_url = kUrl2;
1842 nbc_info.navigation_request_id = request_id2;
1843 render_manager->CommitNavigation(nbc_info);
1844 EXPECT_NE(main_test_rfh(), rfh1);
1845 }
1846
1796 } // namespace content 1847 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698