Portals: Remove NavigationController::CopyStateFromAndPrune
The method was only used to adjust history after a portal activation,
and portals has been removed.
Bug: 40287334
Change-Id: I96583b8bfbf7991dc1040a26f1eb5ed7b212dc5b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/5660456
Reviewed-by: Alex Moshchuk <[email protected]>
Commit-Queue: Adithya Srinivasan <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1320073}
diff --git a/content/browser/renderer_host/navigation_controller_impl.cc b/content/browser/renderer_host/navigation_controller_impl.cc
index 0cf8cde..895fdab 100644
--- a/content/browser/renderer_host/navigation_controller_impl.cc
+++ b/content/browser/renderer_host/navigation_controller_impl.cc
@@ -2510,47 +2510,8 @@
FinishRestore(source->last_committed_entry_index_, RestoreType::kRestored);
}
-void NavigationControllerImpl::CopyStateFromAndPrune(NavigationController* temp,
- bool replace_entry) {
- // It is up to callers to check the invariants before calling this.
- CHECK(CanPruneAllButLastCommitted());
-
- NavigationControllerImpl* source =
- static_cast<NavigationControllerImpl*>(temp);
-
- // Remove all the entries leaving the last committed entry.
- PruneAllButLastCommittedInternal();
-
- // We now have one entry, possibly with a new pending entry. Ensure that
- // adding the entries from source won't put us over the limit.
- DCHECK_EQ(1, GetEntryCount());
- if (!replace_entry)
- source->PruneOldestSkippableEntryIfFull();
-
- // Insert the entries from source. Ignore any pending entry, since it has not
- // committed in source.
- int max_source_index = source->last_committed_entry_index_;
- DCHECK_NE(max_source_index, -1);
- max_source_index++;
-
- // Ignore the source's current entry if merging with replacement.
- // TODO(davidben): This should preserve entries forward of the current
- // too. http://crbug.com/317872
- if (replace_entry && max_source_index > 0)
- max_source_index--;
-
- InsertEntriesFrom(source, max_source_index);
-
- // Adjust indices such that the last entry and pending are at the end now.
- last_committed_entry_index_ = GetEntryCount() - 1;
-
- BroadcastHistoryOffsetAndLength();
-}
-
bool NavigationControllerImpl::CanPruneAllButLastCommitted() {
- // If there is no last committed entry, we cannot prune. Even if there is a
- // pending entry, it may not commit, leaving this WebContents blank, despite
- // possibly giving it new entries via CopyStateFromAndPrune.
+ // If there is no last committed entry, we cannot prune.
if (last_committed_entry_index_ == -1)
return false;
diff --git a/content/browser/renderer_host/navigation_controller_impl.h b/content/browser/renderer_host/navigation_controller_impl.h
index 31cb11c5..925aa992 100644
--- a/content/browser/renderer_host/navigation_controller_impl.h
+++ b/content/browser/renderer_host/navigation_controller_impl.h
@@ -147,8 +147,6 @@
void Reload(ReloadType reload_type, bool check_for_repost) override;
void NotifyEntryChanged(NavigationEntry* entry) override;
void CopyStateFrom(NavigationController* source, bool needs_reload) override;
- void CopyStateFromAndPrune(NavigationController* source,
- bool replace_entry) override;
bool CanPruneAllButLastCommitted() override;
void PruneAllButLastCommitted() override;
void DeleteNavigationEntries(
diff --git a/content/browser/renderer_host/navigation_controller_impl_unittest.cc b/content/browser/renderer_host/navigation_controller_impl_unittest.cc
index 6d91305..b5934f9 100644
--- a/content/browser/renderer_host/navigation_controller_impl_unittest.cc
+++ b/content/browser/renderer_host/navigation_controller_impl_unittest.cc
@@ -3197,271 +3197,6 @@
}
}
-// Tests CopyStateFromAndPrune with 2 urls in source, 1 in dest.
-TEST_F(NavigationControllerTest, CopyStateFromAndPrune) {
- NavigationControllerImpl& controller = controller_impl();
- const GURL url1("http://foo/1");
- const GURL url2("http://foo/2");
- const GURL url3("http://foo/3");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
-
- SiteInstance* instance1 = controller.GetEntryAtIndex(0)->site_instance();
- SiteInstance* instance2 = controller.GetEntryAtIndex(1)->site_instance();
- if (CanSameSiteMainFrameNavigationsChangeSiteInstances()) {
- // If ProactivelySwapBrowsingInstance is enabled for same-site navigations,
- // the same-site navigation from |url1| to |url2| should use different
- // SiteInstances.
- EXPECT_NE(instance1, instance2);
- } else {
- // Otherwise, the first two entries should have the same SiteInstance.
- EXPECT_EQ(instance1, instance2);
- }
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url3);
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(2, 3));
- other_controller.CopyStateFromAndPrune(&controller, false);
-
- // other_controller should now contain the 3 urls: url1, url2 and url3.
-
- ASSERT_EQ(3, other_controller.GetEntryCount());
-
- ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
- EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
-
- // A new SiteInstance in a different BrowsingInstance should be used for the
- // new tab.
- SiteInstance* instance3 =
- other_controller.GetEntryAtIndex(2)->site_instance();
- EXPECT_NE(instance3, instance1);
- EXPECT_FALSE(instance3->IsRelatedSiteInstance(instance1));
-}
-
-// Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry in
-// the target.
-TEST_F(NavigationControllerTest, CopyStateFromAndPrune2) {
- NavigationControllerImpl& controller = controller_impl();
- const GURL url1("http://foo1");
- const GURL url2("http://foo2");
- const GURL url3("http://foo3");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
- controller.GoBack();
- contents()->CommitPendingNavigation();
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url3);
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(1, 2));
- other_controller.CopyStateFromAndPrune(&controller, false);
-
- // other_controller should now contain: url1, url3
-
- ASSERT_EQ(2, other_controller.GetEntryCount());
- ASSERT_EQ(1, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
-}
-
-// Test CopyStateFromAndPrune with 2 urls, the last selected and 2 entries in
-// the target.
-TEST_F(NavigationControllerTest, CopyStateFromAndPrune3) {
- NavigationControllerImpl& controller = controller_impl();
- const GURL url1("http://foo1");
- const GURL url2("http://foo2");
- const GURL url3("http://foo3");
- const GURL url4("http://foo4");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url3);
- other_contents->NavigateAndCommit(url4);
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(2, 3));
- other_controller.CopyStateFromAndPrune(&controller, false);
-
- // other_controller should now contain: url1, url2, url4
-
- ASSERT_EQ(3, other_controller.GetEntryCount());
- ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
- EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
-}
-
-// Test CopyStateFromAndPrune with 2 urls, 2 entries in the target, with
-// not the last entry selected in the target.
-TEST_F(NavigationControllerTest, CopyStateFromAndPruneNotLast) {
- NavigationControllerImpl& controller = controller_impl();
- const GURL url1("http://foo1");
- const GURL url2("http://foo2");
- const GURL url3("http://foo3");
- const GURL url4("http://foo4");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url3);
- other_contents->NavigateAndCommit(url4);
- other_controller.GoBack();
- other_contents->CommitPendingNavigation();
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(2, 3));
- other_controller.CopyStateFromAndPrune(&controller, false);
-
- // other_controller should now contain: url1, url2, url3
-
- ASSERT_EQ(3, other_controller.GetEntryCount());
- ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
- EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
-}
-
-// Test CopyStateFromAndPrune with 2 urls, the first selected and 1 entry plus
-// a pending entry in the target.
-TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending) {
- NavigationControllerImpl& controller = controller_impl();
- const GURL url1("http://foo1");
- const GURL url2("http://foo2");
- const GURL url3("http://foo3");
- const GURL url4("http://foo4");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
- controller.GoBack();
- contents()->CommitPendingNavigation();
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url3);
- other_controller.LoadURL(url4, Referrer(), ui::PAGE_TRANSITION_TYPED,
- std::string());
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(1, 2));
- other_controller.CopyStateFromAndPrune(&controller, false);
-
- // other_controller should now contain url1, url3, and a pending entry
- // for url4.
-
- ASSERT_EQ(2, other_controller.GetEntryCount());
- EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
-
- // And there should be a pending entry for url4.
- ASSERT_TRUE(other_controller.GetPendingEntry());
- EXPECT_EQ(url4, other_controller.GetPendingEntry()->GetURL());
-}
-
-// Test CopyStateFromAndPrune with 1 url in the source, 1 entry and a pending
-// client redirect entry in the target. This used to crash
-// (http://crbug.com/234809).
-TEST_F(NavigationControllerTest, CopyStateFromAndPruneTargetPending2) {
- NavigationControllerImpl& controller = controller_impl();
- const GURL url1("http://foo1");
- const GURL url2a("http://foo2/a");
- const GURL url2b("http://foo2/b");
-
- NavigateAndCommit(url1);
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url2a);
- // Simulate a client redirect, which has the same page ID as entry 2a.
- other_controller.LoadURL(url2b, Referrer(), ui::PAGE_TRANSITION_LINK,
- std::string());
-
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(1, 2));
- other_controller.CopyStateFromAndPrune(&controller, false);
-
- // other_controller should now contain url1, url2a, and a pending entry
- // for url2b.
-
- ASSERT_EQ(2, other_controller.GetEntryCount());
- EXPECT_EQ(1, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url2a, other_controller.GetEntryAtIndex(1)->GetURL());
-
- // And there should be a pending entry for url4.
- ASSERT_TRUE(other_controller.GetPendingEntry());
- EXPECT_EQ(url2b, other_controller.GetPendingEntry()->GetURL());
-
- // Let the pending entry commit.
- other_contents->GetPrimaryMainFrame()->SendNavigateWithTransition(
- 0, false, url2b, ui::PAGE_TRANSITION_LINK);
-}
-
-// Test CopyStateFromAndPrune with 2 urls, a back navigation pending in the
-// source, and 1 entry in the target. The back pending entry should be ignored.
-TEST_F(NavigationControllerTest, CopyStateFromAndPruneSourcePending) {
- NavigationControllerImpl& controller = controller_impl();
- const GURL url1("http://foo1");
- const GURL url2("http://foo2");
- const GURL url3("http://foo3");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
- controller.GoBack();
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url3);
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(2, 3));
- other_controller.CopyStateFromAndPrune(&controller, false);
-
- // other_controller should now contain: url1, url2, url3
-
- ASSERT_EQ(3, other_controller.GetEntryCount());
- ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
- EXPECT_EQ(url3, other_controller.GetEntryAtIndex(2)->GetURL());
-}
-
// Tests DeleteNavigationEntries.
TEST_F(NavigationControllerTest, DeleteNavigationEntries) {
NavigationControllerImpl& controller = controller_impl();
@@ -3523,209 +3258,6 @@
EXPECT_EQ(0U, navigation_list_pruned_counter_);
}
-// Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest,
-// when the max entry count is 3. We should prune one entry.
-TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntries) {
- NavigationControllerImpl& controller = controller_impl();
- size_t original_count = NavigationControllerImpl::max_entry_count();
- const int kMaxEntryCount = 3;
-
- NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount);
-
- const GURL url1("http://foo/1");
- const GURL url2("http://foo/2");
- const GURL url3("http://foo/3");
- const GURL url4("http://foo/4");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
- NavigateAndCommit(url3);
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url4);
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(2, 3));
- other_controller.CopyStateFromAndPrune(&controller, false);
-
- // We should have received a pruned notification.
- EXPECT_EQ(1U, navigation_list_pruned_counter_);
- EXPECT_EQ(0, last_navigation_entry_pruned_details_.index);
- EXPECT_EQ(1, last_navigation_entry_pruned_details_.count);
-
- // other_controller should now contain only 3 urls: url2, url3 and url4.
-
- ASSERT_EQ(3, other_controller.GetEntryCount());
-
- ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url2, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
- EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
-
- NavigationControllerImpl::set_max_entry_count_for_testing(original_count);
-}
-
-// Tests CopyStateFromAndPrune with 2 urls in source, 1 in dest, with
-// replace_entry set to true.
-TEST_F(NavigationControllerTest, CopyStateFromAndPruneReplaceEntry) {
- NavigationControllerImpl& controller = controller_impl();
- const GURL url1("http://foo/1");
- const GURL url2("http://foo/2");
- const GURL url3("http://foo/3");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
-
- SiteInstance* instance1 = controller.GetEntryAtIndex(0)->site_instance();
- SiteInstance* instance2 = controller.GetEntryAtIndex(1)->site_instance();
- if (CanSameSiteMainFrameNavigationsChangeSiteInstances()) {
- // If ProactivelySwapBrowsingInstance is enabled for same-site navigations,
- // the same-site navigation from |url1| to |url2| should use different
- // SiteInstances.
- EXPECT_NE(instance1, instance2);
- } else {
- // Otherwise, the first two entries should have the same SiteInstance.
- EXPECT_EQ(instance1, instance2);
- }
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url3);
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(1, 2));
- other_controller.CopyStateFromAndPrune(&controller, true);
-
- // other_controller should now contain the 2 urls: url1 and url3.
-
- ASSERT_EQ(2, other_controller.GetEntryCount());
-
- ASSERT_EQ(1, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url3, other_controller.GetEntryAtIndex(1)->GetURL());
-
- // A new SiteInstance in a different BrowsingInstance should be used for the
- // new tab.
- SiteInstance* instance3 =
- other_controller.GetEntryAtIndex(1)->site_instance();
- EXPECT_NE(instance3, instance1);
- EXPECT_FALSE(instance3->IsRelatedSiteInstance(instance1));
-}
-
-// Tests CopyStateFromAndPrune with 3 urls in source, 1 in dest, when the max
-// entry count is 3 and replace_entry is true. We should not prune entries.
-TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntriesReplaceEntry) {
- NavigationControllerImpl& controller = controller_impl();
- size_t original_count = NavigationControllerImpl::max_entry_count();
- const int kMaxEntryCount = 3;
-
- NavigationControllerImpl::set_max_entry_count_for_testing(kMaxEntryCount);
-
- const GURL url1("http://foo/1");
- const GURL url2("http://foo/2");
- const GURL url3("http://foo/3");
- const GURL url4("http://foo/4");
-
- NavigateAndCommit(url1);
- NavigateAndCommit(url2);
- NavigateAndCommit(url3);
-
- std::unique_ptr<TestWebContents> other_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& other_controller = other_contents->GetController();
- other_contents->NavigateAndCommit(url4);
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- other_contents->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(2, 3));
- other_controller.CopyStateFromAndPrune(&controller, true);
-
- // We should have received no pruned notification.
- EXPECT_EQ(0U, navigation_list_pruned_counter_);
-
- // other_controller should now contain only 3 urls: url1, url2 and url4.
-
- ASSERT_EQ(3, other_controller.GetEntryCount());
-
- ASSERT_EQ(2, other_controller.GetCurrentEntryIndex());
-
- EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
- EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
- EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
-
- 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");
-
- NavigationEntryRestoreContextImpl context;
- std::vector<std::unique_ptr<NavigationEntry>> entries;
- for (const GURL& restoredUrl : kRestoredUrls) {
- std::unique_ptr<NavigationEntryImpl> entry =
- NavigationEntryImpl::FromNavigationEntry(
- NavigationController::CreateNavigationEntry(
- restoredUrl, Referrer(), std::nullopt /* initiator_origin= */,
- /* initiator_base_url= */ std::nullopt,
- ui::PAGE_TRANSITION_RELOAD, false, std::string(),
- browser_context(), nullptr /* blob_url_loader_factory */));
- entry->SetPageState(blink::PageState::CreateFromURL(restoredUrl), &context);
- entries.push_back(std::move(entry));
- }
-
- // Create a WebContents with restored entries.
- std::unique_ptr<TestWebContents> source_contents(
- static_cast<TestWebContents*>(CreateTestWebContents().release()));
- NavigationControllerImpl& source_controller =
- source_contents->GetController();
- source_controller.Restore(entries.size() - 1, RestoreType::kRestored,
- &entries);
- ASSERT_EQ(0u, entries.size());
- source_controller.LoadIfNecessary();
- source_contents->CommitPendingNavigation();
-
- // Load a page, then copy state from |source_contents|.
- {
- NavigateAndCommit(kInitialUrl);
- testing::NiceMock<MockPageBroadcast> mock_page_broadcast;
- contents()->GetRenderViewHost()->BindPageBroadcast(
- mock_page_broadcast.GetRemote());
- EXPECT_CALL(mock_page_broadcast, SetHistoryOffsetAndLength(2, 3));
- 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().GetLastCommittedEntry()->GetURL());
-
- controller_impl().GoBack();
- contents()->CommitPendingNavigation();
- EXPECT_EQ(1, controller_impl().GetCurrentEntryIndex());
- EXPECT_EQ(kRestoredUrls[1],
- controller_impl().GetLastCommittedEntry()->GetURL());
-
- controller_impl().GoBack();
- contents()->CommitPendingNavigation();
- EXPECT_EQ(0, controller_impl().GetCurrentEntryIndex());
- EXPECT_EQ(kRestoredUrls[0],
- controller_impl().GetLastCommittedEntry()->GetURL());
-}
-
// Tests that navigations initiated from the page (with the history object)
// work as expected, creating pending entries.
TEST_F(NavigationControllerTest, HistoryNavigate) {