diff options
author | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-12 04:57:55 +0000 |
---|---|---|
committer | jamescook@chromium.org <jamescook@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-04-12 04:57:55 +0000 |
commit | c9fffec5a3d8cfd7f591410414555342f77fd175 (patch) | |
tree | 98be351097b3601f1460731b1c87b950ae7f2696 /content/browser/web_contents/navigation_controller_impl_unittest.cc | |
parent | 582771846968b74a57b3fbeabc0f0dc536a59945 (diff) | |
download | chromium_src-c9fffec5a3d8cfd7f591410414555342f77fd175.zip chromium_src-c9fffec5a3d8cfd7f591410414555342f77fd175.tar.gz chromium_src-c9fffec5a3d8cfd7f591410414555342f77fd175.tar.bz2 |
cros: Change tab discard code to use CopyStateFrom, add tests
* Use NavigationController::CopyStateFrom() to preserve the back/forward history of discarded tabs.
* Extend browser_test to ensure back/forward history is preserved.
* Change browser_test to wait for NAV_ENTRY_COMMITTED notification, which eliminates a source of flake in the test.
* Wrote small unit test for NavigationController::CopyStateFrom() - strangely it didn't have one.
* Added scaffolding and TODO for using SuddenTerminationAllowed() in the scoring system for discard.
BUG=121453
TEST=content_unittests NavigationControllerTest and browser_tests OomPriorityManagerTest
Review URL: http://codereview.chromium.org/10052017
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@131931 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'content/browser/web_contents/navigation_controller_impl_unittest.cc')
-rw-r--r-- | content/browser/web_contents/navigation_controller_impl_unittest.cc | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/content/browser/web_contents/navigation_controller_impl_unittest.cc b/content/browser/web_contents/navigation_controller_impl_unittest.cc index 33ca391..3812a38 100644 --- a/content/browser/web_contents/navigation_controller_impl_unittest.cc +++ b/content/browser/web_contents/navigation_controller_impl_unittest.cc @@ -2064,6 +2064,41 @@ TEST_F(NavigationControllerTest, SubframeWhilePending) { EXPECT_EQ(url2, controller.GetActiveEntry()->GetURL()); } +// Test CopyStateFrom with 2 urls, the first selected and nothing in the target. +TEST_F(NavigationControllerTest, CopyStateFrom) { + NavigationControllerImpl& controller = controller_impl(); + const GURL url1("http://foo1"); + const GURL url2("http://foo2"); + + NavigateAndCommit(url1); + NavigateAndCommit(url2); + controller.GoBack(); + contents()->CommitPendingNavigation(); + + scoped_ptr<TestWebContents> other_contents( + static_cast<TestWebContents*>(CreateTestWebContents())); + NavigationControllerImpl& other_controller = + other_contents->GetControllerImpl(); + other_controller.CopyStateFrom(controller); + + // other_controller should now contain 2 urls. + ASSERT_EQ(2, other_controller.GetEntryCount()); + // We should be looking at the first one. + ASSERT_EQ(0, other_controller.GetCurrentEntryIndex()); + + EXPECT_EQ(url1, other_controller.GetEntryAtIndex(0)->GetURL()); + EXPECT_EQ(0, other_controller.GetEntryAtIndex(0)->GetPageID()); + EXPECT_EQ(url2, other_controller.GetEntryAtIndex(1)->GetURL()); + // This is a different site than url1, so the IDs start again at 0. + EXPECT_EQ(0, other_controller.GetEntryAtIndex(1)->GetPageID()); + + // The max page ID map should be copied over and updated with the max page ID + // from the current tab. + SiteInstance* instance1 = + GetSiteInstanceFromEntry(other_controller.GetEntryAtIndex(0)); + EXPECT_EQ(0, other_contents->GetMaxPageIDForSiteInstance(instance1)); +} + // Tests CopyStateFromAndPrune with 2 urls in source, 1 in dest. TEST_F(NavigationControllerTest, CopyStateFromAndPrune) { NavigationControllerImpl& controller = controller_impl(); |