Chromium Code Reviews| Index: chrome/browser/memory/tab_manager_unittest.cc |
| diff --git a/chrome/browser/memory/tab_manager_unittest.cc b/chrome/browser/memory/tab_manager_unittest.cc |
| index c20c3946fc9d2b29eb99a79ca8ccaea6b7079005..68d968b56415f5377d00dee241eef8b1c7864e6a 100644 |
| --- a/chrome/browser/memory/tab_manager_unittest.cc |
| +++ b/chrome/browser/memory/tab_manager_unittest.cc |
| @@ -672,7 +672,7 @@ TEST_F(TabManagerTest, MAYBE_ChildProcessNotifications) { |
| ASSERT_TRUE(tabstrip.empty()); |
| } |
| -TEST_F(TabManagerTest, NextPurgeAndSuspendState) { |
| +TEST_F(TabManagerTest, NextPurgeState) { |
|
Wez
2017/03/02 02:28:32
NextPurgeState was the name of the function - you
tasak
2017/03/02 09:22:47
Renamed to be ShouldPurgeAtDefaultTime.
Wez
2017/03/03 21:06:51
Acknowledged.
|
| TabManager tab_manager; |
| TabStripDummyDelegate delegate; |
| TabStripModel tabstrip(&delegate, profile()); |
| @@ -681,63 +681,40 @@ TEST_F(TabManagerTest, NextPurgeAndSuspendState) { |
| WebContents* test_contents = CreateWebContents(); |
| tabstrip.AppendWebContents(test_contents, false); |
| - // Use default time-to-first-purge defined in TabManager. |
| - base::TimeDelta threshold = TabManager::kDefaultTimeToFirstPurge; |
| base::SimpleTestTickClock test_clock; |
|
Wez
2017/03/02 02:28:32
You probably want to tab_manager.set_test_tick_clo
tasak
2017/03/02 09:22:47
Done.
|
| + tab_manager.GetWebContentsData(test_contents)->SetPurgeState(false); |
| tab_manager.GetWebContentsData(test_contents) |
| - ->SetPurgeAndSuspendState(TabManager::RUNNING); |
| - tab_manager.GetWebContentsData(test_contents) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
| + ->SetLastInactiveTime(test_clock.NowTicks()); |
| + // Use default min-time-to-purge defined in TabManager. |
| + base::TimeDelta time_to_purge = |
| + tab_manager.GetTimeToPurge(TabManager::kDefaultMinTimeToPurge); |
| + tab_manager.GetWebContentsData(test_contents)->SetTimeToPurge(time_to_purge); |
| - // Wait 30 minutes and verify that the tab is still RUNNING. |
| + // Wait 30 minutes and verify that the tab is still NOT_PURGED. |
| test_clock.Advance(base::TimeDelta::FromMinutes(30)); |
| - EXPECT_EQ(TabManager::RUNNING, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| - |
| - // Wait another second and verify that it is now SUSPENDED. |
| - test_clock.Advance(base::TimeDelta::FromSeconds(1)); |
| - EXPECT_EQ(TabManager::SUSPENDED, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| - |
| - tab_manager.GetWebContentsData(test_contents) |
| - ->SetPurgeAndSuspendState(TabManager::SUSPENDED); |
| - tab_manager.GetWebContentsData(test_contents) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
| - |
| - test_clock.Advance(base::TimeDelta::FromSeconds(1200)); |
| - EXPECT_EQ(TabManager::SUSPENDED, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| + EXPECT_FALSE( |
| + tab_manager.ShouldPurgeAtTime(test_contents, test_clock.NowTicks())); |
| - test_clock.Advance(base::TimeDelta::FromSeconds(1)); |
| - EXPECT_EQ(TabManager::RESUMED, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| + // Wait another 30 minutes and verify that it should be purged now . |
| + test_clock.Advance(base::TimeDelta::FromMinutes(30)); |
| + EXPECT_TRUE( |
| + tab_manager.ShouldPurgeAtTime(test_contents, test_clock.NowTicks())); |
| + tab_manager.GetWebContentsData(test_contents)->SetPurgeState(true); |
| tab_manager.GetWebContentsData(test_contents) |
| - ->SetPurgeAndSuspendState(TabManager::RESUMED); |
| - tab_manager.GetWebContentsData(test_contents) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
| + ->SetLastInactiveTime(test_clock.NowTicks()); |
| - test_clock.Advance(base::TimeDelta::FromSeconds(10)); |
| - EXPECT_EQ(TabManager::RESUMED, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| - |
| - test_clock.Advance(base::TimeDelta::FromSeconds(1)); |
| - EXPECT_EQ(TabManager::SUSPENDED, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| + test_clock.Advance(base::TimeDelta::FromMinutes(120)); |
| + EXPECT_FALSE( |
| + tab_manager.ShouldPurgeAtTime(test_contents, test_clock.NowTicks())); |
| // Clean up the tabstrip. |
| tabstrip.CloseAllTabs(); |
| EXPECT_TRUE(tabstrip.empty()); |
| } |
| -TEST_F(TabManagerTest, ActivateTabResetPurgeAndSuspendState) { |
| +TEST_F(TabManagerTest, ActivateTabResetPurgeState) { |
| TabManager tab_manager; |
| TabStripDummyDelegate delegate; |
| TabStripModel tabstrip(&delegate, profile()); |
| @@ -750,29 +727,16 @@ TEST_F(TabManagerTest, ActivateTabResetPurgeAndSuspendState) { |
| base::SimpleTestTickClock test_clock; |
| - // Initially PurgeAndSuspend state should be RUNNING. |
| - EXPECT_EQ(TabManager::RUNNING, |
| - tab_manager.GetWebContentsData(tab2)->GetPurgeAndSuspendState()); |
| + // Initially PurgeAndSuspend state should be NOT_PURGED. |
| + EXPECT_FALSE(tab_manager.GetWebContentsData(tab2)->IsPurged()); |
| - tab_manager.GetWebContentsData(tab2)->SetPurgeAndSuspendState( |
| - TabManager::SUSPENDED); |
| - tab_manager.GetWebContentsData(tab2) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
| + tab_manager.GetWebContentsData(tab2)->SetPurgeState(true); |
| + tab_manager.GetWebContentsData(tab2)->SetLastInactiveTime( |
| + test_clock.NowTicks()); |
| - // Activate tab2. Tab2's PurgeAndSuspend state should be RUNNING. |
| + // Activate tab2. Tab2's PurgeAndSuspend state should be NOT_PURGED. |
| tabstrip.ActivateTabAt(1, true /* user_gesture */); |
| - EXPECT_EQ(TabManager::RUNNING, |
| - tab_manager.GetWebContentsData(tab2)->GetPurgeAndSuspendState()); |
| - |
| - tab_manager.GetWebContentsData(tab1)->SetPurgeAndSuspendState( |
| - TabManager::RESUMED); |
| - tab_manager.GetWebContentsData(tab1) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
| - |
| - // Activate tab1. Tab1's PurgeAndSuspend state should be RUNNING. |
| - tabstrip.ActivateTabAt(0, true /* user_gesture */); |
| - EXPECT_EQ(TabManager::RUNNING, |
| - tab_manager.GetWebContentsData(tab1)->GetPurgeAndSuspendState()); |
| + EXPECT_FALSE(tab_manager.GetWebContentsData(tab2)->IsPurged()); |
| // Clean up the tabstrip. |
| tabstrip.CloseAllTabs(); |