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

Unified Diff: chrome/browser/memory/tab_manager_browsertest.cc

Issue 2711093002: Purge once random minutes(between 30min and 60min) after backgrounded. (Closed)
Patch Set: Fixed Created 3 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/memory/tab_manager.cc ('k') | chrome/browser/memory/tab_manager_unittest.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/memory/tab_manager_browsertest.cc
diff --git a/chrome/browser/memory/tab_manager_browsertest.cc b/chrome/browser/memory/tab_manager_browsertest.cc
index 6f6226852639fe4e4afc511e5c4ea1ba26f959ad..a5bad6babb5d26e83446c2ca9e57d70978de01bb 100644
--- a/chrome/browser/memory/tab_manager_browsertest.cc
+++ b/chrome/browser/memory/tab_manager_browsertest.cc
@@ -481,6 +481,107 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, AutoDiscardable) {
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0)));
}
+IN_PROC_BROWSER_TEST_F(TabManagerTest, PurgeBackgroundRenderer) {
+ TabManager* tab_manager = g_browser_process->GetTabManager();
+
+ base::SimpleTestTickClock test_clock_;
+ tab_manager->set_test_tick_clock(&test_clock_);
+
+ // Get three tabs open.
+ content::WindowedNotificationObserver load1(
+ content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(),
+ WindowOpenDisposition::CURRENT_TAB,
+ ui::PAGE_TRANSITION_TYPED, false);
+ browser()->OpenURL(open1);
+ load1.Wait();
+
+ content::WindowedNotificationObserver load2(
+ content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(),
+ WindowOpenDisposition::NEW_FOREGROUND_TAB,
+ ui::PAGE_TRANSITION_TYPED, false);
+ browser()->OpenURL(open2);
+ load2.Wait();
+
+ content::WindowedNotificationObserver load3(
+ content::NOTIFICATION_NAV_ENTRY_COMMITTED,
+ content::NotificationService::AllSources());
+ OpenURLParams open3(GURL(chrome::kChromeUITermsURL), content::Referrer(),
+ WindowOpenDisposition::NEW_FOREGROUND_TAB,
+ ui::PAGE_TRANSITION_TYPED, false);
+ browser()->OpenURL(open3);
+ load3.Wait();
+
+ auto* tsm = browser()->tab_strip_model();
+ TabManager::WebContentsData* tab1_contents_data =
+ tab_manager->GetWebContentsData(tsm->GetWebContentsAt(0));
+ TabManager::WebContentsData* tab2_contents_data =
+ tab_manager->GetWebContentsData(tsm->GetWebContentsAt(1));
+ TabManager::WebContentsData* tab3_contents_data =
+ tab_manager->GetWebContentsData(tsm->GetWebContentsAt(2));
+
+ // The time-to-purge initialized at ActiveTabChanged should be in the
+ // right default range.
+ EXPECT_GE(tab1_contents_data->time_to_purge(),
+ base::TimeDelta::FromMinutes(30));
+ EXPECT_LT(tab1_contents_data->time_to_purge(),
+ base::TimeDelta::FromMinutes(60));
+ EXPECT_GE(tab2_contents_data->time_to_purge(),
+ base::TimeDelta::FromMinutes(30));
+ EXPECT_LT(tab2_contents_data->time_to_purge(),
+ base::TimeDelta::FromMinutes(60));
+ EXPECT_GE(tab3_contents_data->time_to_purge(),
+ base::TimeDelta::FromMinutes(30));
+ EXPECT_LT(tab3_contents_data->time_to_purge(),
+ base::TimeDelta::FromMinutes(60));
+
+ // To make it easy to test, configure time-to-purge here.
+ base::TimeDelta time_to_purge1 = base::TimeDelta::FromMinutes(30);
+ base::TimeDelta time_to_purge2 = base::TimeDelta::FromMinutes(40);
+ tab1_contents_data->set_time_to_purge(time_to_purge1);
+ tab2_contents_data->set_time_to_purge(time_to_purge2);
+ tab3_contents_data->set_time_to_purge(time_to_purge1);
+
+ // No tabs are not purged yet.
+ ASSERT_FALSE(tab1_contents_data->is_purged());
+ ASSERT_FALSE(tab2_contents_data->is_purged());
+ ASSERT_FALSE(tab3_contents_data->is_purged());
+
+ // Advance the clock for time_to_purge1.
+ test_clock_.Advance(time_to_purge1);
+ tab_manager->PurgeBackgroundedTabsIfNeeded();
+
+ ASSERT_FALSE(tab1_contents_data->is_purged());
+ ASSERT_FALSE(tab2_contents_data->is_purged());
+ ASSERT_FALSE(tab3_contents_data->is_purged());
+
+ // Advance the clock for 1 minutes.
+ test_clock_.Advance(base::TimeDelta::FromMinutes(1));
+ tab_manager->PurgeBackgroundedTabsIfNeeded();
+
+ // Since tab1 is kept inactive and background for more than
+ // time_to_purge1, tab1 should be purged.
+ ASSERT_TRUE(tab1_contents_data->is_purged());
+ ASSERT_FALSE(tab2_contents_data->is_purged());
+ ASSERT_FALSE(tab3_contents_data->is_purged());
+
+ // Advance the clock.
+ test_clock_.Advance(time_to_purge2 - time_to_purge1);
+ tab_manager->PurgeBackgroundedTabsIfNeeded();
+
+ // Since tab2 is kept inactive and background for more than
+ // time_to_purge2, tab1 should be purged.
+ // Since tab3 is active, tab3 should not be purged.
+ ASSERT_TRUE(tab1_contents_data->is_purged());
+ ASSERT_TRUE(tab2_contents_data->is_purged());
+ ASSERT_FALSE(tab3_contents_data->is_purged());
+
+ tsm->CloseAllTabs();
+}
+
} // namespace memory
#endif // OS_WIN || OS_MAXOSX || OS_LINUX
« no previous file with comments | « chrome/browser/memory/tab_manager.cc ('k') | chrome/browser/memory/tab_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698