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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/basictypes.h" 5 #include "base/basictypes.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/path_service.h" 9 #include "base/path_service.h"
10 #include "base/stl_util.h" 10 #include "base/stl_util.h"
(...skipping 3730 matching lines...) Expand 10 before | Expand all | Expand 10 after
3741 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); 3741 EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL());
3742 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); 3742 EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL());
3743 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL()); 3743 EXPECT_EQ(url4, other_controller.GetEntryAtIndex(2)->GetURL());
3744 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); 3744 EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID());
3745 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID()); 3745 EXPECT_EQ(1, other_controller.GetEntryAtIndex(1)->GetPageID());
3746 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID()); 3746 EXPECT_EQ(0, other_controller.GetEntryAtIndex(2)->GetPageID());
3747 3747
3748 NavigationControllerImpl::set_max_entry_count_for_testing(original_count); 3748 NavigationControllerImpl::set_max_entry_count_for_testing(original_count);
3749 } 3749 }
3750 3750
3751 // Tests that we can navigate to the restored entries
3752 // imported by CopyStateFromAndPrune.
3753 TEST_F(NavigationControllerTest, CopyRestoredStateAndNavigate) {
3754 const GURL kRestoredUrls[] = {
3755 GURL("http://site1.com"),
3756 GURL("http://site2.com"),
3757 };
3758 const GURL kInitialUrl("http://site3.com");
3759
3760 std::vector<NavigationEntry*> entries;
3761 for (size_t i = 0; i < arraysize(kRestoredUrls); ++i) {
3762 NavigationEntry* entry = NavigationControllerImpl::CreateNavigationEntry(
3763 kRestoredUrls[i], Referrer(), PAGE_TRANSITION_RELOAD, false,
3764 std::string(), browser_context());
3765 entry->SetPageID(static_cast<int>(i));
3766 entries.push_back(entry);
3767 }
3768
3769 // Create a WebContents with restored entries.
3770 scoped_ptr<TestWebContents> source_contents(
3771 static_cast<TestWebContents*>(CreateTestWebContents()));
3772 NavigationControllerImpl& source_controller =
3773 source_contents->GetController();
3774 source_controller.Restore(
3775 entries.size() - 1,
3776 NavigationController::RESTORE_LAST_SESSION_EXITED_CLEANLY,
3777 &entries);
3778 ASSERT_EQ(0u, entries.size());
3779 source_controller.LoadIfNecessary();
3780 source_contents->CommitPendingNavigation();
3781
3782 // Load a page, then copy state from |source_contents|.
3783 NavigateAndCommit(kInitialUrl);
3784 contents()->ExpectSetHistoryLengthAndPrune(
3785 GetSiteInstanceFromEntry(controller_impl().GetEntryAtIndex(0)), 2,
3786 controller_impl().GetEntryAtIndex(0)->GetPageID());
3787 controller_impl().CopyStateFromAndPrune(&source_controller, false);
3788 ASSERT_EQ(3, controller_impl().GetEntryCount());
3789
3790 // Go back to the first entry one at a time and
3791 // verify that it works as expected.
3792 EXPECT_EQ(2, controller_impl().GetCurrentEntryIndex());
3793 EXPECT_EQ(kInitialUrl, controller_impl().GetActiveEntry()->GetURL());
3794
3795 controller_impl().GoBack();
3796 contents()->CommitPendingNavigation();
3797 EXPECT_EQ(1, controller_impl().GetCurrentEntryIndex());
3798 EXPECT_EQ(kRestoredUrls[1], controller_impl().GetActiveEntry()->GetURL());
3799
3800 controller_impl().GoBack();
3801 contents()->CommitPendingNavigation();
3802 EXPECT_EQ(0, controller_impl().GetCurrentEntryIndex());
3803 EXPECT_EQ(kRestoredUrls[0], controller_impl().GetActiveEntry()->GetURL());
3804 }
3805
3751 // Tests that navigations initiated from the page (with the history object) 3806 // Tests that navigations initiated from the page (with the history object)
3752 // work as expected, creating pending entries. 3807 // work as expected, creating pending entries.
3753 TEST_F(NavigationControllerTest, HistoryNavigate) { 3808 TEST_F(NavigationControllerTest, HistoryNavigate) {
3754 NavigationControllerImpl& controller = controller_impl(); 3809 NavigationControllerImpl& controller = controller_impl();
3755 const GURL url1("http://foo/1"); 3810 const GURL url1("http://foo/1");
3756 const GURL url2("http://foo/2"); 3811 const GURL url2("http://foo/2");
3757 const GURL url3("http://foo/3"); 3812 const GURL url3("http://foo/3");
3758 3813
3759 NavigateAndCommit(url1); 3814 NavigateAndCommit(url1);
3760 NavigateAndCommit(url2); 3815 NavigateAndCommit(url2);
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
4166 EXPECT_EQ(1, controller.GetEntryCount()); 4221 EXPECT_EQ(1, controller.GetEntryCount());
4167 EXPECT_EQ(0, controller.GetCurrentEntryIndex()); 4222 EXPECT_EQ(0, controller.GetCurrentEntryIndex());
4168 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex()); 4223 EXPECT_EQ(0, controller.GetLastCommittedEntryIndex());
4169 EXPECT_EQ(-1, controller.GetPendingEntryIndex()); 4224 EXPECT_EQ(-1, controller.GetPendingEntryIndex());
4170 EXPECT_FALSE(controller.CanGoBack()); 4225 EXPECT_FALSE(controller.CanGoBack());
4171 EXPECT_FALSE(controller.CanGoForward()); 4226 EXPECT_FALSE(controller.CanGoForward());
4172 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL()); 4227 EXPECT_EQ(url4, controller.GetVisibleEntry()->GetURL());
4173 } 4228 }
4174 4229
4175 } // namespace content 4230 } // namespace content
OLDNEW
« 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