Commit f69ed366 authored by ahest@yandex-team.ru's avatar ahest@yandex-team.ru

Copy max_restored_page_id_ when needed.

BUG=366597
R=nasko@chromium.org,jcivelli@chromium.org

Review URL: https://codereview.chromium.org/257463004

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@266552 0039d316-1c4b-4281-b951-d872f2087c98
parent 698fd44c
...@@ -1316,6 +1316,7 @@ void NavigationControllerImpl::CopyStateFromAndPrune( ...@@ -1316,6 +1316,7 @@ void NavigationControllerImpl::CopyStateFromAndPrune(
// that new and existing navigations in the tab's current SiteInstances // that new and existing navigations in the tab's current SiteInstances
// are identified properly. // are identified properly.
delegate_->CopyMaxPageIDsFrom(source->delegate()->GetWebContents()); delegate_->CopyMaxPageIDsFrom(source->delegate()->GetWebContents());
max_restored_page_id_ = source->max_restored_page_id_;
// If there is a last committed entry, be sure to include it in the new // If there is a last committed entry, be sure to include it in the new
// max page ID map. // max page ID map.
......
...@@ -3748,6 +3748,61 @@ TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntriesReplaceEntry) { ...@@ -3748,6 +3748,61 @@ TEST_F(NavigationControllerTest, CopyStateFromAndPruneMaxEntriesReplaceEntry) {
NavigationControllerImpl::set_max_entry_count_for_testing(original_count); 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) // Tests that navigations initiated from the page (with the history object)
// work as expected, creating pending entries. // work as expected, creating pending entries.
TEST_F(NavigationControllerTest, HistoryNavigate) { TEST_F(NavigationControllerTest, HistoryNavigate) {
......
...@@ -100,6 +100,7 @@ bool TestWebContents::CreateRenderViewForRenderManager( ...@@ -100,6 +100,7 @@ bool TestWebContents::CreateRenderViewForRenderManager(
RenderViewHost* render_view_host, RenderViewHost* render_view_host,
int opener_route_id, int opener_route_id,
CrossProcessFrameConnector* frame_connector) { CrossProcessFrameConnector* frame_connector) {
UpdateMaxPageIDIfNecessary(render_view_host);
// This will go to a TestRenderViewHost. // This will go to a TestRenderViewHost.
static_cast<RenderViewHostImpl*>( static_cast<RenderViewHostImpl*>(
render_view_host)->CreateRenderView(base::string16(), render_view_host)->CreateRenderView(base::string16(),
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment