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

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: Fixed the linking issue. Created 6 years, 4 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 1557 matching lines...) Expand 10 before | Expand all | Expand 10 after
1568 EXPECT_FALSE(rvh_deleted_observer.deleted()); 1568 EXPECT_FALSE(rvh_deleted_observer.deleted());
1569 } 1569 }
1570 } 1570 }
1571 1571
1572 // PlzNavigate: Test that a proper NavigationRequest is created by 1572 // PlzNavigate: Test that a proper NavigationRequest is created by
1573 // BeginNavigation. 1573 // BeginNavigation.
1574 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) { 1574 TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
1575 const GURL kUrl1("http://www.google.com/"); 1575 const GURL kUrl1("http://www.google.com/");
1576 const GURL kUrl2("http://www.chromium.org/"); 1576 const GURL kUrl2("http://www.chromium.org/");
1577 const GURL kUrl3("http://www.gmail.com/"); 1577 const GURL kUrl3("http://www.gmail.com/");
1578 const int64 kFirstNavRequestID = 1;
1578 1579
1579 // TODO(clamy): we should be enabling browser side navigations here 1580 // TODO(clamy): we should be enabling browser side navigations here
1580 // when CommitNavigation is properly implemented. 1581 // when CommitNavigation is properly implemented.
1581 // Navigate to the first page. 1582 // Navigate to the first page.
1582 contents()->NavigateAndCommit(kUrl1); 1583 contents()->NavigateAndCommit(kUrl1);
1583 1584
1584 EnableBrowserSideNavigation(); 1585 EnableBrowserSideNavigation();
1585 // Add a subframe. 1586 // Add a subframe.
1586 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>( 1587 TestRenderFrameHost* subframe_rfh = static_cast<TestRenderFrameHost*>(
1587 contents()->GetFrameTree()->AddFrame( 1588 contents()->GetFrameTree()->AddFrame(
1588 contents()->GetFrameTree()->root(), 14, "Child")); 1589 contents()->GetFrameTree()->root(), 14, "Child"));
1589 1590
1590 // Simulate a BeginNavigation IPC on the subframe. 1591 // Simulate a BeginNavigation IPC on the subframe.
1591 subframe_rfh->SendBeginNavigationWithURL(kUrl2); 1592 subframe_rfh->SendBeginNavigationWithURL(kUrl2);
1592 NavigationRequest* subframe_request = 1593 NavigationRequest* subframe_request =
1593 GetNavigationRequestForRenderFrameManager( 1594 GetNavigationRequestForRenderFrameManager(
1594 subframe_rfh->frame_tree_node()->render_manager()); 1595 subframe_rfh->frame_tree_node()->render_manager());
1595 ASSERT_TRUE(subframe_request); 1596 ASSERT_TRUE(subframe_request);
1596 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url); 1597 EXPECT_EQ(kUrl2, subframe_request->info().navigation_params.url);
1597 // First party for cookies url should be that of the main frame. 1598 // First party for cookies url should be that of the main frame.
1598 EXPECT_EQ( 1599 EXPECT_EQ(
1599 kUrl1, subframe_request->info().first_party_for_cookies); 1600 kUrl1, subframe_request->info().first_party_for_cookies);
1600 EXPECT_FALSE(subframe_request->info().is_main_frame); 1601 EXPECT_FALSE(subframe_request->info().is_main_frame);
1601 EXPECT_TRUE(subframe_request->info().parent_is_main_frame); 1602 EXPECT_TRUE(subframe_request->info().parent_is_main_frame);
1603 EXPECT_EQ(kFirstNavRequestID, subframe_request->navigation_request_id());
1602 1604
1603 // Simulate a BeginNavigation IPC on the main frame. 1605 // Simulate a BeginNavigation IPC on the main frame.
1604 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3); 1606 contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3);
1605 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager( 1607 NavigationRequest* main_request = GetNavigationRequestForRenderFrameManager(
1606 contents()->GetMainFrame()->frame_tree_node()->render_manager()); 1608 contents()->GetMainFrame()->frame_tree_node()->render_manager());
1607 ASSERT_TRUE(main_request); 1609 ASSERT_TRUE(main_request);
1608 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url); 1610 EXPECT_EQ(kUrl3, main_request->info().navigation_params.url);
1609 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies); 1611 EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies);
1610 EXPECT_TRUE(main_request->info().is_main_frame); 1612 EXPECT_TRUE(main_request->info().is_main_frame);
1611 EXPECT_FALSE(main_request->info().parent_is_main_frame); 1613 EXPECT_FALSE(main_request->info().parent_is_main_frame);
1614 EXPECT_EQ(kFirstNavRequestID + 1, main_request->navigation_request_id());
1612 } 1615 }
1613 1616
1614 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that 1617 // PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
1615 // RenderFrameHost is not modified when the navigation commits. 1618 // RenderFrameHost is not modified when the navigation commits.
1616 TEST_F(RenderFrameHostManagerTest, 1619 TEST_F(RenderFrameHostManagerTest,
1617 BrowserSideNavigationRequestNavigationNoLiveRenderer) { 1620 BrowserSideNavigationRequestNavigationNoLiveRenderer) {
1618 const GURL kUrl("http://www.google.com/"); 1621 const GURL kUrl("http://www.google.com/");
1619 1622
1620 EnableBrowserSideNavigation(); 1623 EnableBrowserSideNavigation();
1621 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive()); 1624 EXPECT_FALSE(main_test_rfh()->render_view_host()->IsRenderViewLive());
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1658 1661
1659 EnableBrowserSideNavigation(); 1662 EnableBrowserSideNavigation();
1660 // Navigate to a different site. 1663 // Navigate to a different site.
1661 main_test_rfh()->SendBeginNavigationWithURL(kUrl2); 1664 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
1662 NavigationRequest* main_request = 1665 NavigationRequest* main_request =
1663 GetNavigationRequestForRenderFrameManager(render_manager); 1666 GetNavigationRequestForRenderFrameManager(render_manager);
1664 ASSERT_TRUE(main_request); 1667 ASSERT_TRUE(main_request);
1665 1668
1666 NavigationBeforeCommitInfo commit_info; 1669 NavigationBeforeCommitInfo commit_info;
1667 commit_info.navigation_url = kUrl2; 1670 commit_info.navigation_url = kUrl2;
1671 commit_info.navigation_request_id = main_request->navigation_request_id();
1668 render_manager->CommitNavigation(commit_info); 1672 render_manager->CommitNavigation(commit_info);
1669 main_request = GetNavigationRequestForRenderFrameManager(render_manager);
1670 EXPECT_NE(main_test_rfh(), rfh); 1673 EXPECT_NE(main_test_rfh(), rfh);
1671 } 1674 }
1672 1675
1676 // PlzNavigate: Test that a navigation commit is ignored if another request has
1677 // been issued in the meantime.
1678 // TODO(carlosk): enable proper URL expectations once those are properly set
1679 // after the navigation is committed successfully.
1680 TEST_F(RenderFrameHostManagerTest,
1681 BrowserSideNavigationIgnoreOutdatedNavigationCommit) {
1682 const GURL kUrl0("http://www.wikipedia.org/");
1683 const GURL kUrl1("http://www.chromium.org/");
1684 const GURL kUrl2("http://www.google.com/");
1685 // Initialization.
nasko 2014/08/21 21:53:44 nit: Some spacing between comments and code makes
carlosk 2014/08/22 13:43:03 Done! I felt that as well but was uncertain about
nasko 2014/08/22 14:00:34 Guiding rule is that the code must be readable. If
carlosk 2014/08/22 16:54:41 Acknowledged.
1686 contents()->NavigateAndCommit(kUrl0);
1687 RenderFrameHostImpl* rfh = main_test_rfh();
1688 RenderFrameHostManager* render_manager =
1689 main_test_rfh()->frame_tree_node()->render_manager();
1690 EnableBrowserSideNavigation();
1691 // Request navigation to the 1st URL and gather data.
1692 main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
1693 NavigationRequest* request1 =
1694 GetNavigationRequestForRenderFrameManager(render_manager);
1695 int64 request_id1 = request1->navigation_request_id();
1696 ASSERT_TRUE(request1);
1697 // Request navigation to the 2nd URL and gather more data.
1698 main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
1699 NavigationRequest* request2 =
1700 GetNavigationRequestForRenderFrameManager(render_manager);
1701 ASSERT_TRUE(request2);
1702 int64 request_id2 = request2->navigation_request_id();
1703 EXPECT_NE(request_id1, request_id2);
1704 // Confirms that a stale commit is ignored by the RHFM.
1705 NavigationBeforeCommitInfo nbc_info;
1706 nbc_info.navigation_url = kUrl1;
1707 nbc_info.navigation_request_id = request_id1;
1708 render_manager->CommitNavigation(nbc_info);
1709 EXPECT_EQ(main_test_rfh(), rfh);
1710 // Confirms that a valid, request-matching commit is correctly processed.
1711 nbc_info.navigation_url = kUrl2;
1712 nbc_info.navigation_request_id = request_id2;
1713 render_manager->CommitNavigation(nbc_info);
1714 EXPECT_NE(main_test_rfh(), rfh);
1715
1716 }
1717
1673 } // namespace content 1718 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698