| 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 fc9210effcfb06b6e23cb66a16216b9bdc428455..409d35586b06595d9749ba97449ade565103ad68 100644
|
| --- a/chrome/browser/memory/tab_manager_unittest.cc
|
| +++ b/chrome/browser/memory/tab_manager_unittest.cc
|
| @@ -671,4 +671,108 @@ TEST_F(TabManagerTest, MAYBE_ChildProcessNotifications) {
|
| ASSERT_TRUE(tabstrip.empty());
|
| }
|
|
|
| +TEST_F(TabManagerTest, NextPurgeAndSuspendState) {
|
| + TabManager tab_manager;
|
| + TabStripDummyDelegate delegate;
|
| + TabStripModel tabstrip(&delegate, profile());
|
| + tabstrip.AddObserver(&tab_manager);
|
| +
|
| + WebContents* test_contents = CreateWebContents();
|
| + tabstrip.AppendWebContents(test_contents, false);
|
| +
|
| + base::TimeDelta threshold = base::TimeDelta::FromSeconds(180);
|
| + base::SimpleTestTickClock test_clock;
|
| +
|
| + tab_manager.GetWebContentsData(test_contents)
|
| + ->SetPurgeAndSuspendState(TabManager::RUNNING);
|
| + tab_manager.GetWebContentsData(test_contents)
|
| + ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks());
|
| +
|
| + test_clock.Advance(base::TimeDelta::FromSeconds(180));
|
| + EXPECT_EQ(TabManager::RUNNING,
|
| + 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));
|
| +
|
| + tab_manager.GetWebContentsData(test_contents)
|
| + ->SetPurgeAndSuspendState(TabManager::SUSPENDED);
|
| + tab_manager.GetWebContentsData(test_contents)
|
| + ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks());
|
| +
|
| + test_clock.Advance(base::TimeDelta::FromSeconds(120));
|
| + 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));
|
| +
|
| + // Clean up the tabstrip.
|
| + tabstrip.CloseAllTabs();
|
| + EXPECT_TRUE(tabstrip.empty());
|
| +}
|
| +
|
| +TEST_F(TabManagerTest, ActivateTabResetPurgeAndSuspendState) {
|
| + TabManager tab_manager;
|
| + TabStripDummyDelegate delegate;
|
| + TabStripModel tabstrip(&delegate, profile());
|
| + tabstrip.AddObserver(&tab_manager);
|
| +
|
| + WebContents* tab1 = CreateWebContents();
|
| + WebContents* tab2 = CreateWebContents();
|
| + tabstrip.AppendWebContents(tab1, true);
|
| + tabstrip.AppendWebContents(tab2, false);
|
| +
|
| + base::SimpleTestTickClock test_clock;
|
| +
|
| + // Initially PurgeAndSuspend state should be RUNNING.
|
| + EXPECT_EQ(TabManager::RUNNING,
|
| + tab_manager.GetWebContentsData(tab2)->GetPurgeAndSuspendState());
|
| +
|
| + tab_manager.GetWebContentsData(tab2)->SetPurgeAndSuspendState(
|
| + TabManager::SUSPENDED);
|
| + tab_manager.GetWebContentsData(tab2)
|
| + ->SetLastPurgeAndSuspendModifiedTimeForTesting(test_clock.NowTicks());
|
| +
|
| + // Activate tab2. Tab2's PurgeAndSuspend state should be RUNNING.
|
| + 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());
|
| +
|
| + // Clean up the tabstrip.
|
| + tabstrip.CloseAllTabs();
|
| + EXPECT_TRUE(tabstrip.empty());
|
| +}
|
| +
|
| } // namespace memory
|
|
|