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..d41b0f69039a001ccf9e48cf8ce09b729dead3bf 100644 |
| --- a/chrome/browser/memory/tab_manager_unittest.cc |
| +++ b/chrome/browser/memory/tab_manager_unittest.cc |
| @@ -672,7 +672,15 @@ TEST_F(TabManagerTest, MAYBE_ChildProcessNotifications) { |
| ASSERT_TRUE(tabstrip.empty()); |
| } |
| -TEST_F(TabManagerTest, NextPurgeAndSuspendState) { |
| +TEST_F(TabManagerTest, DefaultTimeToPurgeInCorrectRange) { |
| + TabManager tab_manager; |
| + base::TimeDelta time_to_purge = |
| + tab_manager.GetTimeToPurge(TabManager::kDefaultMinTimeToPurge); |
| + EXPECT_GE(time_to_purge, base::TimeDelta::FromMinutes(30)); |
| + EXPECT_LT(time_to_purge, base::TimeDelta::FromMinutes(60)); |
| +} |
| + |
| +TEST_F(TabManagerTest, ShouldPurgeAtDefaultTime) { |
| TabManager tab_manager; |
| TabStripDummyDelegate delegate; |
| TabStripModel tabstrip(&delegate, profile()); |
| @@ -681,63 +689,37 @@ 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; |
| + tab_manager.set_test_tick_clock(&test_clock); |
| + tab_manager.GetWebContentsData(test_contents)->set_is_purged(false); |
| tab_manager.GetWebContentsData(test_contents) |
| - ->SetPurgeAndSuspendState(TabManager::RUNNING); |
| + ->SetLastInactiveTime(test_clock.NowTicks()); |
| tab_manager.GetWebContentsData(test_contents) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
| + ->set_time_to_purge(base::TimeDelta::FromMinutes(1)); |
| - // Wait 30 minutes and verify that the tab is still RUNNING. |
| - test_clock.Advance(base::TimeDelta::FromMinutes(30)); |
| - EXPECT_EQ(TabManager::RUNNING, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| + // Wait 1 minute and verify that the tab is still not to be purged. |
| + test_clock.Advance(base::TimeDelta::FromMinutes(1)); |
| + EXPECT_FALSE(tab_manager.ShouldPurgeAtTime(test_contents)); |
| - // Wait another second and verify that it is now SUSPENDED. |
| + // Wait another 1 second and verify that it should be purged now . |
| test_clock.Advance(base::TimeDelta::FromSeconds(1)); |
| - EXPECT_EQ(TabManager::SUSPENDED, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| + EXPECT_TRUE(tab_manager.ShouldPurgeAtTime(test_contents)); |
| + tab_manager.GetWebContentsData(test_contents)->set_is_purged(true); |
| tab_manager.GetWebContentsData(test_contents) |
| - ->SetPurgeAndSuspendState(TabManager::SUSPENDED); |
| - tab_manager.GetWebContentsData(test_contents) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
| + ->SetLastInactiveTime(test_clock.NowTicks()); |
| - test_clock.Advance(base::TimeDelta::FromSeconds(1200)); |
| - EXPECT_EQ(TabManager::SUSPENDED, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| - |
| - test_clock.Advance(base::TimeDelta::FromSeconds(1)); |
| - EXPECT_EQ(TabManager::RESUMED, |
| - tab_manager.GetNextPurgeAndSuspendState( |
| - test_contents, test_clock.NowTicks(), threshold)); |
| - |
| - tab_manager.GetWebContentsData(test_contents) |
| - ->SetPurgeAndSuspendState(TabManager::RESUMED); |
| - tab_manager.GetWebContentsData(test_contents) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(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)); |
| + // Wait 1 day and verify that the tab is still be purged. |
| + test_clock.Advance(base::TimeDelta::FromMinutes(60 * 24)); |
|
Wez
2017/03/03 21:06:51
You can use FromHours(24) here.
tasak
2017/03/06 10:30:19
Done.
|
| + EXPECT_FALSE(tab_manager.ShouldPurgeAtTime(test_contents)); |
| // 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 +732,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)->is_purged()); |
| - tab_manager.GetWebContentsData(tab2)->SetPurgeAndSuspendState( |
| - TabManager::SUSPENDED); |
| - tab_manager.GetWebContentsData(tab2) |
| - ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks()); |
| + tab_manager.GetWebContentsData(tab2)->set_is_purged(true); |
|
Wez
2017/03/03 21:06:51
You're not actually going through the normal purge
tasak
2017/03/06 10:30:19
Done.
However, what I want to do here is just chec
|
| + 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)->is_purged()); |
| // Clean up the tabstrip. |
| tabstrip.CloseAllTabs(); |