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

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: Added the actual calls to cancel the navigation request 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 class TestNavigationRequestObserver : public NavigationRequest::Observer {
1800 public:
1801 explicit TestNavigationRequestObserver(NavigationRequest* nv)
1802 : NavigationRequest::Observer(nv), cancelCounter(0), destroyCounter(0) {}
1803
1804 virtual void RequestCanceled(NavigationRequest* nv) OVERRIDE {
1805 ++cancelCounter;
1806 }
1807
1808 virtual void RequestDestroyed(NavigationRequest* nv) OVERRIDE {
1809 ++destroyCounter;
1810 }
1811
1812 int cancelCounter;
clamy 2014/08/28 12:17:01 I would rather have a boolean than a counter here.
carlosk 2014/08/29 15:54:43 In this case I prefer counters instead of booleans
1813
clamy 2014/08/28 12:17:01 nit: unnecessary line.
carlosk 2014/08/29 15:54:43 Done.
1814 int destroyCounter;
1815
clamy 2014/08/28 12:17:01 nit: unnecessary line.
carlosk 2014/08/29 15:54:43 Done.
1816 };
1817
1818 // PlzNavigate: Test that a navigation commit is ignored if another request has
1819 // been issued in the meantime.
1820 // TODO(carlosk): add URL expectations once those are properly set after the
1821 // navigation is committed successfully.
1822 TEST_F(RenderFrameHostManagerTest,
1823 BrowserSideNavigationIgnoreStaleNavigationCommit) {
1824 const GURL kUrl0("http://www.wikipedia.org/");
1825 const GURL kUrl1("http://www.chromium.org/");
1826 const GURL kUrl2("http://www.google.com/");
1827
1828 // Initialization.
1829 contents()->NavigateAndCommit(kUrl0);
1830 RenderFrameHostImpl* rfh1 = main_test_rfh();
1831 RenderFrameHostManager* render_manager =
1832 main_test_rfh()->frame_tree_node()->render_manager();
1833 EnableBrowserSideNavigation();
1834
1835 // Request navigation to the 1st URL and gather data.
1836 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
1837 NavigationRequest* request1 =
1838 GetNavigationRequestForRenderFrameManager(render_manager);
1839 ASSERT_TRUE(request1);
1840 TestNavigationRequestObserver observer1(request1);
1841 int64 request_id1 = request1->navigation_request_id();
1842
1843 // Request navigation to the 2nd URL and gather more data.
1844 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
1845 NavigationRequest* request2 =
1846 GetNavigationRequestForRenderFrameManager(render_manager);
1847 ASSERT_TRUE(request2);
1848 int64 request_id2 = request2->navigation_request_id();
1849 EXPECT_NE(request_id1, request_id2);
1850 TestNavigationRequestObserver observer2(request2);
1851
1852 // Confirms the 1st observer is at the expected state
1853 EXPECT_EQ(1, observer1.cancelCounter);
1854 EXPECT_EQ(1, observer1.destroyCounter);
1855
1856 // Confirms that a stale commit is ignored by the RHFM.
1857 NavigationBeforeCommitInfo nbc_info;
1858 nbc_info.navigation_url = kUrl1;
1859 nbc_info.navigation_request_id = request_id1;
1860 render_manager->CommitNavigation(nbc_info);
1861 EXPECT_EQ(main_test_rfh(), rfh1);
1862
1863 // Confirms that a valid, request-matching commit is correctly processed.
1864 nbc_info.navigation_url = kUrl2;
1865 nbc_info.navigation_request_id = request_id2;
1866 render_manager->CommitNavigation(nbc_info);
1867 EXPECT_NE(main_test_rfh(), rfh1);
1868
1869 // Confirms both 1st and 2nd observers are at the expected states
clamy 2014/08/28 12:17:01 I would replace this comment with something a bit
carlosk 2014/08/29 15:54:43 Done.
1870 EXPECT_EQ(1, observer1.cancelCounter);
1871 EXPECT_EQ(1, observer1.destroyCounter);
1872 EXPECT_EQ(0, observer2.cancelCounter);
1873 EXPECT_EQ(0, observer2.destroyCounter);
1874
1875 // Finishes the navigation process
1876 int32 new_page_id = 1 + contents()->GetMaxPageIDForSiteInstance(
1877 active_rvh()->GetSiteInstance());
1878 active_test_rvh()->SendNavigate(new_page_id, kUrl2);
1879
1880 // Confirms both 1st and 2nd observers are at the expected states
clamy 2014/08/28 12:17:01 I would replace the comment with something like: T
carlosk 2014/08/29 15:54:43 Done.
1881 EXPECT_EQ(1, observer1.cancelCounter);
1882 EXPECT_EQ(1, observer1.destroyCounter);
1883 EXPECT_EQ(0, observer2.cancelCounter);
1884 EXPECT_EQ(1, observer2.destroyCounter);
1885 }
1886
1796 } // namespace content 1887 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698