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

Unified 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 Nasko's comments 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/frame_host/render_frame_host_manager_unittest.cc
diff --git a/content/browser/frame_host/render_frame_host_manager_unittest.cc b/content/browser/frame_host/render_frame_host_manager_unittest.cc
index 7cc3cb139214ae3d2a1313f25042ececf9b7fef6..9e04f4a2eb1061674135975bac43bfebebb2c544 100644
--- a/content/browser/frame_host/render_frame_host_manager_unittest.cc
+++ b/content/browser/frame_host/render_frame_host_manager_unittest.cc
@@ -1575,6 +1575,7 @@ TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
const GURL kUrl1("http://www.google.com/");
const GURL kUrl2("http://www.chromium.org/");
const GURL kUrl3("http://www.gmail.com/");
+ const int64 kFirstNavRequestID = 1;
// TODO(clamy): we should be enabling browser side navigations here
// when CommitNavigation is properly implemented.
@@ -1599,6 +1600,7 @@ TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
kUrl1, subframe_request->info().first_party_for_cookies);
EXPECT_FALSE(subframe_request->info().is_main_frame);
EXPECT_TRUE(subframe_request->info().parent_is_main_frame);
+ EXPECT_EQ(kFirstNavRequestID, subframe_request->navigation_request_id());
// Simulate a BeginNavigation IPC on the main frame.
contents()->GetMainFrame()->SendBeginNavigationWithURL(kUrl3);
@@ -1609,6 +1611,7 @@ TEST_F(RenderFrameHostManagerTest, BrowserSideNavigationBeginNavigation) {
EXPECT_EQ(kUrl3, main_request->info().first_party_for_cookies);
EXPECT_TRUE(main_request->info().is_main_frame);
EXPECT_FALSE(main_request->info().parent_is_main_frame);
+ EXPECT_EQ(kFirstNavRequestID + 1, main_request->navigation_request_id());
}
// PlzNavigate: Test that RequestNavigation creates a NavigationRequest and that
@@ -1665,8 +1668,54 @@ TEST_F(RenderFrameHostManagerTest,
NavigationBeforeCommitInfo commit_info;
commit_info.navigation_url = kUrl2;
+ commit_info.navigation_request_id = main_request->navigation_request_id();
render_manager->CommitNavigation(commit_info);
- main_request = GetNavigationRequestForRenderFrameManager(render_manager);
+ EXPECT_NE(main_test_rfh(), rfh);
+}
+
+// PlzNavigate: Test that a navigation commit is ignored if another request has
+// been issued in the meantime.
+// TODO(carlosk): enable proper URL expectations once those are properly set
+// after the navigation is committed successfully.
+TEST_F(RenderFrameHostManagerTest,
+ BrowserSideNavigationIgnoreOutdatedNavigationCommit) {
+ const GURL kUrl0("http://www.wikipedia.org/");
+ const GURL kUrl1("http://www.chromium.org/");
+ const GURL kUrl2("http://www.google.com/");
+
+ // Initialization.
+ contents()->NavigateAndCommit(kUrl0);
+ RenderFrameHostImpl* rfh = main_test_rfh();
+ RenderFrameHostManager* render_manager =
+ main_test_rfh()->frame_tree_node()->render_manager();
+ EnableBrowserSideNavigation();
+
+ // Request navigation to the 1st URL and gather data.
+ main_test_rfh()->SendBeginNavigationWithURL(kUrl1);
+ NavigationRequest* request1 =
+ GetNavigationRequestForRenderFrameManager(render_manager);
+ ASSERT_TRUE(request1);
+ int64 request_id1 = request1->navigation_request_id();
+
+ // Request navigation to the 2nd URL and gather more data.
+ main_test_rfh()->SendBeginNavigationWithURL(kUrl2);
+ NavigationRequest* request2 =
+ GetNavigationRequestForRenderFrameManager(render_manager);
+ ASSERT_TRUE(request2);
+ int64 request_id2 = request2->navigation_request_id();
+ EXPECT_NE(request_id1, request_id2);
+
+ // Confirms that a stale commit is ignored by the RHFM.
+ NavigationBeforeCommitInfo nbc_info;
+ nbc_info.navigation_url = kUrl1;
+ nbc_info.navigation_request_id = request_id1;
+ render_manager->CommitNavigation(nbc_info);
+ EXPECT_EQ(main_test_rfh(), rfh);
+
+ // Confirms that a valid, request-matching commit is correctly processed.
+ nbc_info.navigation_url = kUrl2;
+ nbc_info.navigation_request_id = request_id2;
+ render_manager->CommitNavigation(nbc_info);
EXPECT_NE(main_test_rfh(), rfh);
}

Powered by Google App Engine
This is Rietveld 408576698