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

Unified Diff: chrome/browser/tab_contents/navigation_controller_unittest.cc

Issue 3346005: Don't create pending entries when a navigation is initiated by the page. (Closed) Base URL: http://src.chromium.org/git/chromium.git
Patch Set: Created 10 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: chrome/browser/tab_contents/navigation_controller_unittest.cc
diff --git a/chrome/browser/tab_contents/navigation_controller_unittest.cc b/chrome/browser/tab_contents/navigation_controller_unittest.cc
index 8d9f4f6791b2fe3d94302f1836b0004dff0644b2..0794a38b0ea8dff35844186a97f1e137be64fd79 100644
--- a/chrome/browser/tab_contents/navigation_controller_unittest.cc
+++ b/chrome/browser/tab_contents/navigation_controller_unittest.cc
@@ -1805,6 +1805,59 @@ TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) {
EXPECT_EQ(controller().session_id().id(), other_controller.session_id().id());
}
+// Tests that navigations initiated from the page (with the history object)
+// work as expected without navigation entries.
+TEST_F(NavigationControllerTest, HistoryNavigate) {
+ const GURL url1("http://foo1");
+ const GURL url2("http://foo2");
+ const GURL url3("http://foo3");
+
+ NavigateAndCommit(url1);
+ NavigateAndCommit(url2);
+ NavigateAndCommit(url3);
+ controller().GoBack();
+ contents()->CommitPendingNavigation();
+
+ // Casts the TabContents to a RenderViewHostDelegate::BrowserIntegration so we
+ // can call GoToEntryAtOffset which is private.
+ RenderViewHostDelegate::BrowserIntegration* rvh_delegate =
+ static_cast<RenderViewHostDelegate::BrowserIntegration*>(contents());
+
+ // Simulate the page calling history.back(), it should not create a pending
+ // entry.
+ rvh_delegate->GoToEntryAtOffset(-1);
+ EXPECT_EQ(-1, controller().pending_entry_index());
+ // The actual cross-navigation is suspended until the current RVH tells us
+ // it unloaded, simulate that.
+ contents()->ProceedWithCrossSiteNavigation();
+ // Also make sure we told the page to navigate.
+ const IPC::Message* message =
+ process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID);
+ ASSERT_TRUE(message != NULL);
+ Tuple1<ViewMsg_Navigate_Params> nav_params;
+ ViewMsg_Navigate::Read(message, &nav_params);
+ EXPECT_EQ(url1, nav_params.a.url);
+ process()->sink().ClearMessages();
+
+ // Now test history.forward()
+ rvh_delegate->GoToEntryAtOffset(1);
+ EXPECT_EQ(-1, controller().pending_entry_index());
+ // The actual cross-navigation is suspended until the current RVH tells us
+ // it unloaded, simulate that.
+ contents()->ProceedWithCrossSiteNavigation();
+ message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID);
+ ASSERT_TRUE(message != NULL);
+ ViewMsg_Navigate::Read(message, &nav_params);
+ EXPECT_EQ(url3, nav_params.a.url);
+ process()->sink().ClearMessages();
+
+ // Make sure an extravagant history.go() doesn't break.
+ rvh_delegate->GoToEntryAtOffset(120); // Out of bounds.
+ EXPECT_EQ(-1, controller().pending_entry_index());
+ message = process()->sink().GetFirstMessageMatching(ViewMsg_Navigate::ID);
+ EXPECT_TRUE(message == NULL);
+}
+
/* TODO(brettw) These test pass on my local machine but fail on the XP buildbot
(but not Vista) cleaning up the directory after they run.
This should be fixed.

Powered by Google App Engine
This is Rietveld 408576698