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

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

Issue 2389683002: Modify PurgeAndSuspend to see WebContents (Closed)
Patch Set: Add unittest Created 4 years, 2 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') | no next file » | 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 917d57f17dfb6a8ea0dcac87988c32588cccc02f..45caebd254b275cbfc0f535ff5789190f6166df6 100644
--- a/chrome/browser/memory/tab_manager_browsertest.cc
+++ b/chrome/browser/memory/tab_manager_browsertest.cc
@@ -17,6 +17,7 @@
#include "chrome/browser/ui/find_bar/find_bar_controller.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_features.h"
+#include "chrome/common/chrome_switches.h"
#include "chrome/common/url_constants.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/base/interactive_test_utils.h"
@@ -435,6 +436,78 @@ IN_PROC_BROWSER_TEST_F(TabManagerTest, AutoDiscardable) {
EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0)));
}
+IN_PROC_BROWSER_TEST_F(TabManagerTest, CanSuspendBasics) {
+ using content::WindowedNotificationObserver;
+ TabManager* tab_manager = g_browser_process->GetTabManager();
+
+ // Get two tabs open.
+ 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();
+
+ 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();
+
+ 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 tab_stats = tab_manager->GetUnsortedTabStats();
+ EXPECT_TRUE(tab_manager->CanPurgeAndSuspendBackgroundedTab(
+ tab_stats.at(0).tab_contents_id));
+ EXPECT_TRUE(tab_manager->CanPurgeAndSuspendBackgroundedTab(
+ tab_stats.at(1).tab_contents_id));
+ EXPECT_TRUE(tab_manager->CanPurgeAndSuspendBackgroundedTab(
+ tab_stats.at(2).tab_contents_id));
+}
+
+IN_PROC_BROWSER_TEST_F(TabManagerTest, CannotSuspendTabWithMedia) {
+ // Open 2 tabs, the second one being in the background.
+ ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
+ ui_test_utils::NavigateToURLWithDisposition(
+ browser(), GURL(chrome::kChromeUIAboutURL),
+ WindowOpenDisposition::NEW_BACKGROUND_TAB,
+ ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
+
+ auto* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
+
+ // Simulate that a video stream is now being captured.
+ content::MediaStreamDevice fake_media_device(
+ content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_media_device",
+ "fake_media_device");
+ content::MediaStreamDevices video_devices(1, fake_media_device);
+ MediaCaptureDevicesDispatcher* dispatcher =
+ MediaCaptureDevicesDispatcher::GetInstance();
+ dispatcher->SetTestVideoCaptureDevices(video_devices);
+ std::unique_ptr<content::MediaStreamUI> video_stream_ui =
+ dispatcher->GetMediaStreamCaptureIndicator()->RegisterMediaStream(
+ tab, video_devices);
+ video_stream_ui->OnStarted(base::Closure());
+
+ TabManager* tab_manager = g_browser_process->GetTabManager();
+ auto tab_stats = tab_manager->GetUnsortedTabStats();
+ EXPECT_TRUE(tab_manager->CanPurgeAndSuspendBackgroundedTab(
+ tab_stats.at(0).tab_contents_id));
+ EXPECT_FALSE(tab_manager->CanPurgeAndSuspendBackgroundedTab(
+ tab_stats.at(1).tab_contents_id));
+}
+
} // namespace memory
#endif // OS_WIN || OS_MAXOSX || OS_LINUX
« no previous file with comments | « chrome/browser/memory/tab_manager.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698