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

Side by Side Diff: chrome/browser/memory/tab_manager_browsertest.cc

Issue 2399293002: Add MemoryCoordinatorDelegate (Closed)
Patch Set: Add a separate delegate class 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 unified diff | Download patch
« no previous file with comments | « chrome/browser/memory/tab_manager.cc ('k') | content/browser/memory/memory_coordinator.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/base_switches.h" 5 #include "base/base_switches.h"
6 #include "base/command_line.h" 6 #include "base/command_line.h"
7 #include "base/memory/memory_pressure_listener.h" 7 #include "base/memory/memory_pressure_listener.h"
8 #include "base/test/simple_test_tick_clock.h" 8 #include "base/test/simple_test_tick_clock.h"
9 #include "build/build_config.h" 9 #include "build/build_config.h"
10 #include "chrome/browser/browser_process.h" 10 #include "chrome/browser/browser_process.h"
11 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h" 11 #include "chrome/browser/media/webrtc/media_capture_devices_dispatcher.h"
12 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h" 12 #include "chrome/browser/media/webrtc/media_stream_capture_indicator.h"
13 #include "chrome/browser/memory/tab_manager.h" 13 #include "chrome/browser/memory/tab_manager.h"
14 #include "chrome/browser/memory/tab_manager_web_contents_data.h" 14 #include "chrome/browser/memory/tab_manager_web_contents_data.h"
15 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
16 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
17 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 17 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
18 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
19 #include "chrome/common/chrome_features.h" 19 #include "chrome/common/chrome_features.h"
20 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
21 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
22 #include "chrome/test/base/interactive_test_utils.h" 22 #include "chrome/test/base/interactive_test_utils.h"
23 #include "content/public/browser/notification_service.h" 23 #include "content/public/browser/notification_service.h"
24 #include "content/public/browser/notification_types.h" 24 #include "content/public/browser/notification_types.h"
25 #include "content/public/browser/render_process_host.h"
25 #include "content/public/common/content_switches.h" 26 #include "content/public/common/content_switches.h"
26 #include "content/public/test/test_utils.h" 27 #include "content/public/test/test_utils.h"
27 #include "url/gurl.h" 28 #include "url/gurl.h"
28 29
29 using content::OpenURLParams; 30 using content::OpenURLParams;
30 31
31 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX) 32 #if defined(OS_WIN) || defined(OS_MACOSX) || defined(OS_LINUX)
32 33
33 namespace memory { 34 namespace memory {
34 35
(...skipping 350 matching lines...) Expand 10 before | Expand all | Expand 10 after
385 // Should not be able to discard a tab. 386 // Should not be able to discard a tab.
386 ASSERT_FALSE(tab_manager->DiscardTabImpl()); 387 ASSERT_FALSE(tab_manager->DiscardTabImpl());
387 388
388 // Remove the video stream. 389 // Remove the video stream.
389 video_stream_ui.reset(); 390 video_stream_ui.reset();
390 391
391 // Should be able to discard the background tab now. 392 // Should be able to discard the background tab now.
392 EXPECT_TRUE(tab_manager->DiscardTabImpl()); 393 EXPECT_TRUE(tab_manager->DiscardTabImpl());
393 } 394 }
394 395
396 IN_PROC_BROWSER_TEST_F(TabManagerTest, CanSuspendBackgroundedRenderer) {
397 TabManager* tab_manager = g_browser_process->GetTabManager();
398
399 // Open 2 tabs, the second one being in the background.
400 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
401 ui_test_utils::NavigateToURLWithDisposition(
402 browser(), GURL(chrome::kChromeUIAboutURL),
403 WindowOpenDisposition::NEW_BACKGROUND_TAB,
404 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
405
406 auto* tab = browser()->tab_strip_model()->GetWebContentsAt(1);
407 // Simulate that a video stream is now being captured.
408 content::MediaStreamDevice fake_media_device(
409 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_media_device",
410 "fake_media_device");
411 content::MediaStreamDevices video_devices(1, fake_media_device);
412 MediaCaptureDevicesDispatcher* dispatcher =
413 MediaCaptureDevicesDispatcher::GetInstance();
414 dispatcher->SetTestVideoCaptureDevices(video_devices);
415 std::unique_ptr<content::MediaStreamUI> video_stream_ui =
416 dispatcher->GetMediaStreamCaptureIndicator()->RegisterMediaStream(
417 tab, video_devices);
418 video_stream_ui->OnStarted(base::Closure());
419
420 // Should not be able to suspend a tab which plays a video.
421 int render_process_id = tab->GetRenderProcessHost()->GetID();
422 ASSERT_FALSE(tab_manager->CanSuspendBackgroundedRenderer(render_process_id));
423
424 // Remove the video stream.
425 video_stream_ui.reset();
426
427 // Should be able to suspend the background tab now.
428 EXPECT_TRUE(tab_manager->CanSuspendBackgroundedRenderer(render_process_id));
429 }
430
395 IN_PROC_BROWSER_TEST_F(TabManagerTest, AutoDiscardable) { 431 IN_PROC_BROWSER_TEST_F(TabManagerTest, AutoDiscardable) {
396 using content::WindowedNotificationObserver; 432 using content::WindowedNotificationObserver;
397 TabManager* tab_manager = g_browser_process->GetTabManager(); 433 TabManager* tab_manager = g_browser_process->GetTabManager();
398 434
399 // Disable the protection of recent tabs. 435 // Disable the protection of recent tabs.
400 tab_manager->set_minimum_protection_time_for_tests( 436 tab_manager->set_minimum_protection_time_for_tests(
401 base::TimeDelta::FromMinutes(0)); 437 base::TimeDelta::FromMinutes(0));
402 438
403 // Get two tabs open. 439 // Get two tabs open.
404 WindowedNotificationObserver load1( 440 WindowedNotificationObserver load1(
(...skipping 26 matching lines...) Expand all
431 tab_manager->SetTabAutoDiscardableState(tsm->GetWebContentsAt(0), true); 467 tab_manager->SetTabAutoDiscardableState(tsm->GetWebContentsAt(0), true);
432 468
433 // Now it should be able to discard the tab. 469 // Now it should be able to discard the tab.
434 EXPECT_TRUE(tab_manager->DiscardTabImpl()); 470 EXPECT_TRUE(tab_manager->DiscardTabImpl());
435 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); 471 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0)));
436 } 472 }
437 473
438 } // namespace memory 474 } // namespace memory
439 475
440 #endif // OS_WIN || OS_MAXOSX || OS_LINUX 476 #endif // OS_WIN || OS_MAXOSX || OS_LINUX
OLDNEW
« no previous file with comments | « chrome/browser/memory/tab_manager.cc ('k') | content/browser/memory/memory_coordinator.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698