Chromium Code Reviews| 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 "content/browser/renderer_host/media/audio_input_device_manager.h" | 5 #include "content/browser/renderer_host/media/audio_input_device_manager.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <string> | 10 #include <string> |
| 11 | 11 |
| 12 #include "base/bind.h" | 12 #include "base/bind.h" |
| 13 #include "base/command_line.h" | 13 #include "base/command_line.h" |
| 14 #include "base/location.h" | 14 #include "base/location.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ref_counted.h" | 16 #include "base/memory/ref_counted.h" |
| 17 #include "base/run_loop.h" | 17 #include "base/run_loop.h" |
| 18 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
| 19 #include "base/threading/thread_task_runner_handle.h" | 19 #include "base/threading/thread_task_runner_handle.h" |
| 20 #include "build/build_config.h" | 20 #include "build/build_config.h" |
| 21 #include "content/public/common/media_stream_request.h" | 21 #include "content/public/common/media_stream_request.h" |
| 22 #include "content/public/test/test_browser_thread_bundle.h" | 22 #include "content/public/test/test_browser_thread_bundle.h" |
| 23 #include "media/audio/audio_manager_base.h" | |
| 24 #include "media/audio/audio_system_impl.h" | 23 #include "media/audio/audio_system_impl.h" |
| 25 #include "media/audio/audio_thread_impl.h" | 24 #include "media/audio/audio_thread_impl.h" |
| 25 #include "media/audio/mock_audio_manager.h" | |
| 26 #include "media/base/media_switches.h" | 26 #include "media/base/media_switches.h" |
| 27 #include "media/base/test_helpers.h" | 27 #include "media/base/test_helpers.h" |
| 28 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 29 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 30 | 30 |
| 31 using testing::InSequence; | 31 using testing::InSequence; |
| 32 | 32 |
| 33 namespace content { | 33 namespace content { |
| 34 | 34 |
| 35 class MockAudioInputDeviceManagerListener | 35 class MockAudioInputDeviceManagerListener |
| (...skipping 21 matching lines...) Expand all Loading... | |
| 57 #define MAYBE_AudioInputDeviceManagerTest DISABLED_AudioInputDeviceManagerTest | 57 #define MAYBE_AudioInputDeviceManagerTest DISABLED_AudioInputDeviceManagerTest |
| 58 #else | 58 #else |
| 59 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest | 59 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest |
| 60 #endif | 60 #endif |
| 61 | 61 |
| 62 class MAYBE_AudioInputDeviceManagerTest : public testing::Test { | 62 class MAYBE_AudioInputDeviceManagerTest : public testing::Test { |
| 63 public: | 63 public: |
| 64 MAYBE_AudioInputDeviceManagerTest() {} | 64 MAYBE_AudioInputDeviceManagerTest() {} |
| 65 | 65 |
| 66 protected: | 66 protected: |
| 67 void SetUp() override { | 67 virtual void Initialize() { |
| 68 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 68 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 69 switches::kUseFakeDeviceForMediaStream); | 69 switches::kUseFakeDeviceForMediaStream); |
| 70 // AudioInputDeviceManager accesses AudioSystem from IO thread, so it never | 70 // AudioInputDeviceManager accesses AudioSystem from IO thread, so it never |
| 71 // runs on the same thread with it, even on Mac. | 71 // runs on the same thread with it, even on Mac. |
| 72 audio_manager_ = media::AudioManager::CreateForTesting( | 72 audio_manager_ = media::AudioManager::CreateForTesting( |
| 73 base::MakeUnique<media::AudioThreadImpl>()); | 73 base::MakeUnique<media::AudioThreadImpl>()); |
| 74 // Flush the message loop to ensure proper initialization of AudioManager. | 74 // Flush the message loop to ensure proper initialization of AudioManager. |
| 75 base::RunLoop().RunUntilIdle(); | 75 base::RunLoop().RunUntilIdle(); |
| 76 | 76 |
| 77 // Use fake devices. | |
| 78 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1", | |
| 79 "fake_device_1"); | |
| 80 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2", | |
| 81 "fake_device_2"); | |
| 82 } | |
| 83 | |
| 84 void SetUp() override { | |
| 85 Initialize(); | |
| 86 | |
| 77 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 87 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
| 78 manager_ = new AudioInputDeviceManager(audio_system_.get()); | 88 manager_ = new AudioInputDeviceManager(audio_system_.get()); |
| 79 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); | 89 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); |
| 80 manager_->RegisterListener(audio_input_listener_.get()); | 90 manager_->RegisterListener(audio_input_listener_.get()); |
| 81 | 91 |
| 82 // Use fake devices. | |
| 83 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1", | |
| 84 "fake_device_1"); | |
| 85 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2", | |
| 86 "fake_device_2"); | |
| 87 | |
| 88 // Wait until we get the list. | 92 // Wait until we get the list. |
| 89 base::RunLoop().RunUntilIdle(); | 93 base::RunLoop().RunUntilIdle(); |
| 90 } | 94 } |
| 91 | 95 |
| 92 void TearDown() override { | 96 void TearDown() override { |
| 93 manager_->UnregisterListener(audio_input_listener_.get()); | 97 manager_->UnregisterListener(audio_input_listener_.get()); |
| 94 audio_manager_->Shutdown(); | 98 audio_manager_->Shutdown(); |
| 95 } | 99 } |
| 96 | 100 |
| 97 void WaitForOpenCompletion() { | 101 void WaitForOpenCompletion() { |
| (...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 289 manager_->GetOpenedDeviceInfoById(invalid_session_id); | 293 manager_->GetOpenedDeviceInfoById(invalid_session_id); |
| 290 DCHECK(!info); | 294 DCHECK(!info); |
| 291 | 295 |
| 292 manager_->Close(session_id); | 296 manager_->Close(session_id); |
| 293 EXPECT_CALL(*audio_input_listener_, | 297 EXPECT_CALL(*audio_input_listener_, |
| 294 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) | 298 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) |
| 295 .Times(1); | 299 .Times(1); |
| 296 base::RunLoop().RunUntilIdle(); | 300 base::RunLoop().RunUntilIdle(); |
| 297 } | 301 } |
| 298 | 302 |
| 303 class AudioInputDeviceManagerNoDevicesTest | |
| 304 : public MAYBE_AudioInputDeviceManagerTest { | |
| 305 public: | |
| 306 AudioInputDeviceManagerNoDevicesTest(){}; | |
| 307 | |
| 308 protected: | |
| 309 void Initialize() override { | |
| 310 audio_manager_ = base::MakeUnique<media::MockAudioManager>( | |
| 311 base::MakeUnique<media::AudioThreadImpl>()); | |
| 312 | |
| 313 devices_.emplace_back(MEDIA_TAB_AUDIO_CAPTURE, "Tab capture", | |
|
Guido Urdaneta
2017/07/05 09:37:12
If this is about no devices, why are there three d
o1ka
2017/07/05 10:10:31
There are no physical devices: we use a mock audio
Guido Urdaneta
2017/07/05 13:28:32
Add a comment in the initialization of |audio_mana
| |
| 314 "tab_capture"); | |
| 315 | |
| 316 devices_.emplace_back(MEDIA_DESKTOP_AUDIO_CAPTURE, "Desktop capture", | |
| 317 "desktop_capture"); | |
| 318 | |
| 319 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device", | |
| 320 "fake_device"); | |
| 321 } | |
| 322 | |
| 323 private: | |
| 324 DISALLOW_COPY_AND_ASSIGN(AudioInputDeviceManagerNoDevicesTest); | |
| 325 }; | |
| 326 | |
| 327 TEST_F(AudioInputDeviceManagerNoDevicesTest, | |
| 328 ParametersValidWithoutAudioDevices) { | |
| 329 ASSERT_FALSE(devices_.empty()); | |
| 330 | |
| 331 InSequence s; | |
| 332 | |
| 333 for (StreamDeviceInfoArray::const_iterator iter = devices_.begin(); | |
| 334 iter != devices_.end(); ++iter) { | |
| 335 // Opens/closes the devices. | |
| 336 int session_id = manager_->Open(iter->device); | |
| 337 | |
| 338 // Expected mock call with expected return value. | |
| 339 EXPECT_CALL(*audio_input_listener_, Opened(iter->device.type, session_id)) | |
| 340 .Times(1); | |
| 341 // Waits for the callback. | |
| 342 WaitForOpenCompletion(); | |
| 343 | |
| 344 // Expects that device parameters stored by the manager are valid. | |
| 345 const StreamDeviceInfo* device_info = | |
| 346 manager_->GetOpenedDeviceInfoById(session_id); | |
| 347 EXPECT_TRUE( | |
| 348 media::AudioParameters(media::AudioParameters::AUDIO_FAKE, | |
| 349 static_cast<media::ChannelLayout>( | |
| 350 device_info->device.input.channel_layout), | |
| 351 device_info->device.input.sample_rate, 16, | |
| 352 device_info->device.input.frames_per_buffer) | |
| 353 .IsValid()); | |
| 354 | |
| 355 manager_->Close(session_id); | |
| 356 EXPECT_CALL(*audio_input_listener_, Closed(iter->device.type, session_id)) | |
| 357 .Times(1); | |
| 358 | |
| 359 // Waits for the callback. | |
| 360 base::RunLoop().RunUntilIdle(); | |
| 361 } | |
| 362 } | |
| 363 | |
| 299 } // namespace content | 364 } // namespace content |
| OLD | NEW |