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

Unified Diff: content/browser/frame_host/navigation_controller_impl_unittest.cc

Issue 257463004: Copy max_restored_page_id_ when needed. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 8 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
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.cc ('k') | content/test/test_web_contents.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/frame_host/navigation_controller_impl_unittest.cc
diff --git a/content/browser/frame_host/navigation_controller_impl_unittest.cc b/content/browser/frame_host/navigation_controller_impl_unittest.cc
index 8003d5a38197055d7fc81a37b4cde28bff519266..7d9bdfbc5e3f292a0ad860fb3a42752b1eadccfb 100644
--- a/content/browser/frame_host/navigation_controller_impl_unittest.cc
+++ b/content/browser/frame_host/navigation_controller_impl_unittest.cc
@@ -3748,6 +3748,61 @@ TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntriesReplaceEntry) {
NavigationControllerImpl::set_max_entry_count_for_testing(original_count);
}
+// Tests that we can navigate to the restored entries
+// imported by CopyStateFromAndPrune.
+TEST_F(NavigationControllerTest, CopyRestoredStateAndNavigate) {
+ const GURL kRestoredUrls[] = {
+ GURL("http://site1.com"),
+ GURL("http://site2.com"),
+ };
+ const GURL kInitialUrl("http://site3.com");
+
+ std::vector<NavigationEntry*> entries;
+ for (size_t i = 0; i < arraysize(kRestoredUrls); ++i) {
+ NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry(
+ kRestoredUrls[i], Referrer(), PAGE_TRANSITION_RELOAD, false,
+ std::string(), browser_context());
+ entry->SetPageID(static_cast<int>(i));
+ entries.push_back(entry);
+ }
+
+ // Create a WebContents with restored entries.
+ scoped_ptr<TestWebContents> source_contents(
+ static_cast<TestWebContents*>(CreateTestWebContents()));
+ NavigationControllerImpl& source_controller =
+ source_contents->GetController();
+ source_controller.Restore(
+ entries.size() - 1,
+ NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
+ &entries);
+ ASSERT_EQ(0u, entries.size());
+ source_controller.LoadIfNecessary();
+ source_contents->CommitPendingNavigation();
+
+ // Load a page, then copy state from |source_contents|.
+ NavigateAndCommit(kInitialUrl);
+ contents()->ExpectSetHistoryLengthAndPrune(
+ GetSiteInstanceFromEntry(controller_impl().GetEntryAtIndex(0)), 2,
+ controller_impl().GetEntryAtIndex(0)->GetPageID());
+ controller_impl().CopyStateFromAndPrune(&source_controller, false);
+ ASSERT_EQ(3, controller_impl().GetEntryCount());
+
+ // Go back to the first entry one at a time and
+ // verify that it works as expected.
+ EXPECT_EQ(2, controller_impl().GetCurrentEntryIndex());
+ EXPECT_EQ(kInitialUrl, controller_impl().GetActiveEntry()->GetURL());
+
+ controller_impl().GoBack();
+ contents()->CommitPendingNavigation();
+ EXPECT_EQ(1, controller_impl().GetCurrentEntryIndex());
+ EXPECT_EQ(kRestoredUrls[1], controller_impl().GetActiveEntry()->GetURL());
+
+ controller_impl().GoBack();
+ contents()->CommitPendingNavigation();
+ EXPECT_EQ(0, controller_impl().GetCurrentEntryIndex());
+ EXPECT_EQ(kRestoredUrls[0], controller_impl().GetActiveEntry()->GetURL());
+}
+
// Tests that navigations initiated from the page (with the history object)
// work as expected, creating pending entries.
TEST_F(NavigationControllerTest, HistoryNavigate) {
« no previous file with comments | « content/browser/frame_host/navigation_controller_impl.cc ('k') | content/test/test_web_contents.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698