OLD | NEW |
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/chrome_switches.h" |
20 #include "chrome/common/url_constants.h" | 21 #include "chrome/common/url_constants.h" |
21 #include "chrome/test/base/in_process_browser_test.h" | 22 #include "chrome/test/base/in_process_browser_test.h" |
22 #include "chrome/test/base/interactive_test_utils.h" | 23 #include "chrome/test/base/interactive_test_utils.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_types.h" | 25 #include "content/public/browser/notification_types.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; |
(...skipping 398 matching lines...) Loading... |
428 EXPECT_FALSE(tab_manager->DiscardTabImpl()); | 429 EXPECT_FALSE(tab_manager->DiscardTabImpl()); |
429 | 430 |
430 // Reset auto-discardable state to true. | 431 // Reset auto-discardable state to true. |
431 tab_manager->SetTabAutoDiscardableState(tsm->GetWebContentsAt(0), true); | 432 tab_manager->SetTabAutoDiscardableState(tsm->GetWebContentsAt(0), true); |
432 | 433 |
433 // Now it should be able to discard the tab. | 434 // Now it should be able to discard the tab. |
434 EXPECT_TRUE(tab_manager->DiscardTabImpl()); | 435 EXPECT_TRUE(tab_manager->DiscardTabImpl()); |
435 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); | 436 EXPECT_TRUE(tab_manager->IsTabDiscarded(tsm->GetWebContentsAt(0))); |
436 } | 437 } |
437 | 438 |
| 439 IN_PROC_BROWSER_TEST_F(TabManagerTest, CanSuspendBasics) { |
| 440 using content::WindowedNotificationObserver; |
| 441 TabManager* tab_manager = g_browser_process->GetTabManager(); |
| 442 |
| 443 // Get two tabs open. |
| 444 WindowedNotificationObserver load1( |
| 445 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 446 content::NotificationService::AllSources()); |
| 447 OpenURLParams open1(GURL(chrome::kChromeUIAboutURL), content::Referrer(), |
| 448 WindowOpenDisposition::CURRENT_TAB, |
| 449 ui::PAGE_TRANSITION_TYPED, false); |
| 450 browser()->OpenURL(open1); |
| 451 load1.Wait(); |
| 452 |
| 453 WindowedNotificationObserver load2( |
| 454 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 455 content::NotificationService::AllSources()); |
| 456 OpenURLParams open2(GURL(chrome::kChromeUICreditsURL), content::Referrer(), |
| 457 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 458 ui::PAGE_TRANSITION_TYPED, false); |
| 459 browser()->OpenURL(open2); |
| 460 load2.Wait(); |
| 461 |
| 462 WindowedNotificationObserver load3( |
| 463 content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 464 content::NotificationService::AllSources()); |
| 465 OpenURLParams open3(GURL(chrome::kChromeUITermsURL), content::Referrer(), |
| 466 WindowOpenDisposition::NEW_FOREGROUND_TAB, |
| 467 ui::PAGE_TRANSITION_TYPED, false); |
| 468 browser()->OpenURL(open3); |
| 469 load3.Wait(); |
| 470 |
| 471 auto tab_stats = tab_manager->GetUnsortedTabStats(); |
| 472 EXPECT_TRUE(tab_manager->CanPurgeAndSuspendBackgroundedTab( |
| 473 tab_stats.at(0).tab_contents_id)); |
| 474 EXPECT_TRUE(tab_manager->CanPurgeAndSuspendBackgroundedTab( |
| 475 tab_stats.at(1).tab_contents_id)); |
| 476 EXPECT_TRUE(tab_manager->CanPurgeAndSuspendBackgroundedTab( |
| 477 tab_stats.at(2).tab_contents_id)); |
| 478 } |
| 479 |
| 480 IN_PROC_BROWSER_TEST_F(TabManagerTest, CannotSuspendTabWithMedia) { |
| 481 // Open 2 tabs, the second one being in the background. |
| 482 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL)); |
| 483 ui_test_utils::NavigateToURLWithDisposition( |
| 484 browser(), GURL(chrome::kChromeUIAboutURL), |
| 485 WindowOpenDisposition::NEW_BACKGROUND_TAB, |
| 486 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION); |
| 487 |
| 488 auto* tab = browser()->tab_strip_model()->GetWebContentsAt(1); |
| 489 |
| 490 // Simulate that a video stream is now being captured. |
| 491 content::MediaStreamDevice fake_media_device( |
| 492 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_media_device", |
| 493 "fake_media_device"); |
| 494 content::MediaStreamDevices video_devices(1, fake_media_device); |
| 495 MediaCaptureDevicesDispatcher* dispatcher = |
| 496 MediaCaptureDevicesDispatcher::GetInstance(); |
| 497 dispatcher->SetTestVideoCaptureDevices(video_devices); |
| 498 std::unique_ptr<content::MediaStreamUI> video_stream_ui = |
| 499 dispatcher->GetMediaStreamCaptureIndicator()->RegisterMediaStream( |
| 500 tab, video_devices); |
| 501 video_stream_ui->OnStarted(base::Closure()); |
| 502 |
| 503 TabManager* tab_manager = g_browser_process->GetTabManager(); |
| 504 auto tab_stats = tab_manager->GetUnsortedTabStats(); |
| 505 EXPECT_TRUE(tab_manager->CanPurgeAndSuspendBackgroundedTab( |
| 506 tab_stats.at(0).tab_contents_id)); |
| 507 EXPECT_FALSE(tab_manager->CanPurgeAndSuspendBackgroundedTab( |
| 508 tab_stats.at(1).tab_contents_id)); |
| 509 } |
| 510 |
438 } // namespace memory | 511 } // namespace memory |
439 | 512 |
440 #endif // OS_WIN || OS_MAXOSX || OS_LINUX | 513 #endif // OS_WIN || OS_MAXOSX || OS_LINUX |
OLD | NEW |