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

Side by Side Diff: content/browser/renderer_host/media/media_devices_dispatcher_host_unittest.cc

Issue 2784433002: Ensures that audio tasks cannot run after AudioManager is deleted. (Closed)
Patch Set: rebase Created 3 years, 7 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "content/browser/renderer_host/media/media_devices_dispatcher_host.h" 5 #include "content/browser/renderer_host/media/media_devices_dispatcher_host.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <queue> 10 #include <queue>
11 #include <utility> 11 #include <utility>
12 #include <vector> 12 #include <vector>
13 13
14 #include "base/bind.h" 14 #include "base/bind.h"
15 #include "base/command_line.h" 15 #include "base/command_line.h"
16 #include "base/memory/ptr_util.h" 16 #include "base/memory/ptr_util.h"
17 #include "base/run_loop.h" 17 #include "base/run_loop.h"
18 #include "base/strings/stringprintf.h" 18 #include "base/strings/stringprintf.h"
19 #include "base/threading/thread_task_runner_handle.h" 19 #include "base/threading/thread_task_runner_handle.h"
20 #include "content/browser/renderer_host/media/media_stream_manager.h" 20 #include "content/browser/renderer_host/media/media_stream_manager.h"
21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h" 21 #include "content/browser/renderer_host/media/media_stream_ui_proxy.h"
22 #include "content/browser/renderer_host/media/video_capture_manager.h" 22 #include "content/browser/renderer_host/media/video_capture_manager.h"
23 #include "content/public/browser/browser_context.h" 23 #include "content/public/browser/browser_context.h"
24 #include "content/public/browser/media_device_id.h" 24 #include "content/public/browser/media_device_id.h"
25 #include "content/public/test/test_browser_context.h" 25 #include "content/public/test/test_browser_context.h"
26 #include "content/public/test/test_browser_thread_bundle.h" 26 #include "content/public/test/test_browser_thread_bundle.h"
27 #include "media/audio/audio_device_description.h" 27 #include "media/audio/audio_device_description.h"
28 #include "media/audio/audio_system_impl.h" 28 #include "media/audio/audio_system_impl.h"
29 #include "media/audio/mock_audio_manager.h" 29 #include "media/audio/mock_audio_manager.h"
30 #include "media/audio/test_audio_thread.h"
30 #include "media/base/media_switches.h" 31 #include "media/base/media_switches.h"
31 #include "media/capture/video/fake_video_capture_device_factory.h" 32 #include "media/capture/video/fake_video_capture_device_factory.h"
32 #include "mojo/public/cpp/bindings/binding.h" 33 #include "mojo/public/cpp/bindings/binding.h"
33 #include "testing/gmock/include/gmock/gmock.h" 34 #include "testing/gmock/include/gmock/gmock.h"
34 #include "testing/gtest/include/gtest/gtest.h" 35 #include "testing/gtest/include/gtest/gtest.h"
35 #include "url/origin.h" 36 #include "url/origin.h"
36 37
37 using testing::_; 38 using testing::_;
38 using testing::SaveArg; 39 using testing::SaveArg;
39 using testing::InvokeWithoutArgs; 40 using testing::InvokeWithoutArgs;
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
74 class MediaDevicesDispatcherHostTest : public testing::Test { 75 class MediaDevicesDispatcherHostTest : public testing::Test {
75 public: 76 public:
76 MediaDevicesDispatcherHostTest() 77 MediaDevicesDispatcherHostTest()
77 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP), 78 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP),
78 origin_(GURL("https://test.com")) { 79 origin_(GURL("https://test.com")) {
79 // Make sure we use fake devices to avoid long delays. 80 // Make sure we use fake devices to avoid long delays.
80 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( 81 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
81 switches::kUseFakeDeviceForMediaStream, 82 switches::kUseFakeDeviceForMediaStream,
82 base::StringPrintf("device-count=%zu, video-input-default-id=%s", 83 base::StringPrintf("device-count=%zu, video-input-default-id=%s",
83 kNumFakeVideoDevices, kDefaultVideoDeviceID)); 84 kNumFakeVideoDevices, kDefaultVideoDeviceID));
84 audio_manager_.reset( 85 audio_manager_.reset(new media::MockAudioManager(
85 new media::MockAudioManager(base::ThreadTaskRunnerHandle::Get())); 86 base::MakeUnique<media::TestAudioThread>()));
86 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); 87 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
87 media_stream_manager_ = 88 media_stream_manager_ =
88 base::MakeUnique<MediaStreamManager>(audio_system_.get()); 89 base::MakeUnique<MediaStreamManager>(audio_system_.get());
89 90
90 host_ = base::MakeUnique<MediaDevicesDispatcherHost>( 91 host_ = base::MakeUnique<MediaDevicesDispatcherHost>(
91 kProcessId, kRenderId, browser_context_.GetMediaDeviceIDSalt(), 92 kProcessId, kRenderId, browser_context_.GetMediaDeviceIDSalt(),
92 media_stream_manager_.get()); 93 media_stream_manager_.get());
93 } 94 }
95 ~MediaDevicesDispatcherHostTest() override { audio_manager_->Shutdown(); }
94 96
95 void SetUp() override { 97 void SetUp() override {
96 base::RunLoop run_loop; 98 base::RunLoop run_loop;
97 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate; 99 MediaDevicesManager::BoolDeviceTypes devices_to_enumerate;
98 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true; 100 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_INPUT] = true;
99 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true; 101 devices_to_enumerate[MEDIA_DEVICE_TYPE_VIDEO_INPUT] = true;
100 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true; 102 devices_to_enumerate[MEDIA_DEVICE_TYPE_AUDIO_OUTPUT] = true;
101 media_stream_manager_->media_devices_manager()->EnumerateDevices( 103 media_stream_manager_->media_devices_manager()->EnumerateDevices(
102 devices_to_enumerate, 104 devices_to_enumerate,
103 base::Bind(&PhysicalDevicesEnumerated, run_loop.QuitClosure(), 105 base::Bind(&PhysicalDevicesEnumerated, run_loop.QuitClosure(),
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after
291 } 293 }
292 294
293 // The order of these members is important on teardown: 295 // The order of these members is important on teardown:
294 // MediaDevicesDispatcherHost expects to be destroyed on the IO thread while 296 // MediaDevicesDispatcherHost expects to be destroyed on the IO thread while
295 // MediaStreamManager expects to be destroyed after the IO thread has been 297 // MediaStreamManager expects to be destroyed after the IO thread has been
296 // uninitialized. 298 // uninitialized.
297 std::unique_ptr<MediaStreamManager> media_stream_manager_; 299 std::unique_ptr<MediaStreamManager> media_stream_manager_;
298 content::TestBrowserThreadBundle thread_bundle_; 300 content::TestBrowserThreadBundle thread_bundle_;
299 std::unique_ptr<MediaDevicesDispatcherHost> host_; 301 std::unique_ptr<MediaDevicesDispatcherHost> host_;
300 302
301 std::unique_ptr<media::AudioManager, media::AudioManagerDeleter> 303 std::unique_ptr<media::AudioManager> audio_manager_;
302 audio_manager_;
303 std::unique_ptr<media::AudioSystem> audio_system_; 304 std::unique_ptr<media::AudioSystem> audio_system_;
304 content::TestBrowserContext browser_context_; 305 content::TestBrowserContext browser_context_;
305 MediaDeviceEnumeration physical_devices_; 306 MediaDeviceEnumeration physical_devices_;
306 url::Origin origin_; 307 url::Origin origin_;
307 308
308 std::vector<MediaDeviceInfoArray> enumerated_devices_; 309 std::vector<MediaDeviceInfoArray> enumerated_devices_;
309 }; 310 };
310 311
311 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioInputDevices) { 312 TEST_F(MediaDevicesDispatcherHostTest, EnumerateAudioInputDevices) {
312 EnumerateDevicesAndWaitForResult(true, false, false); 313 EnumerateDevicesAndWaitForResult(true, false, false);
(...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 EXPECT_CALL(*this, MockVideoInputCapabilitiesCallback()) 393 EXPECT_CALL(*this, MockVideoInputCapabilitiesCallback())
393 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); })); 394 .WillOnce(InvokeWithoutArgs([&run_loop]() { run_loop.Quit(); }));
394 host_->GetVideoInputCapabilities( 395 host_->GetVideoInputCapabilities(
395 url::Origin(), base::Bind(&MediaDevicesDispatcherHostTest:: 396 url::Origin(), base::Bind(&MediaDevicesDispatcherHostTest::
396 VideoInputCapabilitiesUniqueOriginCallback, 397 VideoInputCapabilitiesUniqueOriginCallback,
397 base::Unretained(this))); 398 base::Unretained(this)));
398 run_loop.Run(); 399 run_loop.Run();
399 } 400 }
400 401
401 }; // namespace content 402 }; // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698