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

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

Issue 1630443002: [Merge M49] [TabManager] Protect tabs that are using camera/microphone. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2623
Patch Set: Created 4 years, 11 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') | chrome/browser/memory/tab_manager_unittest.cc » ('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/media_capture_devices_dispatcher.h"
12 #include "chrome/browser/media/media_stream_capture_indicator.h"
11 #include "chrome/browser/memory/tab_manager.h" 13 #include "chrome/browser/memory/tab_manager.h"
12 #include "chrome/browser/memory/tab_manager_web_contents_data.h" 14 #include "chrome/browser/memory/tab_manager_web_contents_data.h"
13 #include "chrome/browser/ui/browser.h" 15 #include "chrome/browser/ui/browser.h"
14 #include "chrome/browser/ui/browser_commands.h" 16 #include "chrome/browser/ui/browser_commands.h"
15 #include "chrome/browser/ui/find_bar/find_bar_controller.h" 17 #include "chrome/browser/ui/find_bar/find_bar_controller.h"
16 #include "chrome/browser/ui/tabs/tab_strip_model.h" 18 #include "chrome/browser/ui/tabs/tab_strip_model.h"
17 #include "chrome/common/chrome_features.h" 19 #include "chrome/common/chrome_features.h"
18 #include "chrome/common/url_constants.h" 20 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/in_process_browser_test.h" 21 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/interactive_test_utils.h" 22 #include "chrome/test/base/interactive_test_utils.h"
(...skipping 290 matching lines...) Expand 10 before | Expand all | Expand 10 after
311 // Should not be able to discard a tab. 313 // Should not be able to discard a tab.
312 ASSERT_FALSE(tab_manager->DiscardTab()); 314 ASSERT_FALSE(tab_manager->DiscardTab());
313 315
314 // Advance the clock for more than the protection time. 316 // Advance the clock for more than the protection time.
315 test_clock_.Advance(base::TimeDelta::FromMinutes(protection_time / 2 + 2)); 317 test_clock_.Advance(base::TimeDelta::FromMinutes(protection_time / 2 + 2));
316 318
317 // Should be able to discard the background tab now. 319 // Should be able to discard the background tab now.
318 EXPECT_TRUE(tab_manager->DiscardTab()); 320 EXPECT_TRUE(tab_manager->DiscardTab());
319 } 321 }
320 322
323 // Makes sure that tabs using media devices are protected.
324 IN_PROC_BROWSER_TEST_F(TabManagerTest, ProtectVideoTabs) {
325 TabManager* tab_manager = g_browser_process->GetTabManager();
326 ASSERT_TRUE(tab_manager);
327
328 // Open 2 tabs, the second one being in the background.
329 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kChromeUIAboutURL));
330 ui_test_utils::NavigateToURLWithDisposition(
331 browser(), GURL(chrome::kChromeUIAboutURL), NEW_BACKGROUND_TAB,
332 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION);
333
334 auto tab = browser()->tab_strip_model()->GetWebContentsAt(1);
335
336 // Simulate that a video stream is now being captured.
337 content::MediaStreamDevice fake_media_device(
338 content::MEDIA_DEVICE_VIDEO_CAPTURE, "fake_media_device",
339 "fake_media_device");
340 content::MediaStreamDevices video_devices(1, fake_media_device);
341 MediaCaptureDevicesDispatcher* dispatcher =
342 MediaCaptureDevicesDispatcher::GetInstance();
343 dispatcher->SetTestVideoCaptureDevices(video_devices);
344 scoped_ptr<content::MediaStreamUI> video_stream_ui =
345 dispatcher->GetMediaStreamCaptureIndicator()->RegisterMediaStream(
346 tab, video_devices);
347 video_stream_ui->OnStarted(base::Closure());
348
349 // Should not be able to discard a tab.
350 ASSERT_FALSE(tab_manager->DiscardTab());
351
352 // Remove the video stream.
353 video_stream_ui.reset();
354
355 // Should be able to discard the background tab now.
356 EXPECT_TRUE(tab_manager->DiscardTab());
357 }
358
321 } // namespace memory 359 } // namespace memory
322 360
323 #endif // OS_WIN || OS_CHROMEOS 361 #endif // OS_WIN || OS_CHROMEOS
OLDNEW
« 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