| 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" | 23 #include "media/audio/audio_manager_base.h" |
| 24 #include "media/audio/audio_system_impl.h" | 24 #include "media/audio/audio_system_impl.h" |
| 25 #include "media/audio/audio_thread_impl.h" |
| 25 #include "media/base/media_switches.h" | 26 #include "media/base/media_switches.h" |
| 26 #include "media/base/test_helpers.h" | 27 #include "media/base/test_helpers.h" |
| 27 #include "testing/gmock/include/gmock/gmock.h" | 28 #include "testing/gmock/include/gmock/gmock.h" |
| 28 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 29 | 30 |
| 30 using testing::InSequence; | 31 using testing::InSequence; |
| 31 | 32 |
| 32 namespace content { | 33 namespace content { |
| 33 | 34 |
| 34 class MockAudioInputDeviceManagerListener | 35 class MockAudioInputDeviceManagerListener |
| (...skipping 18 matching lines...) Expand all Loading... |
| 53 // AudioInputDeviceManager::Open() must be called on the audio thread. | 54 // AudioInputDeviceManager::Open() must be called on the audio thread. |
| 54 // This test suite must be modified to run on Android. | 55 // This test suite must be modified to run on Android. |
| 55 #if defined(OS_ANDROID) | 56 #if defined(OS_ANDROID) |
| 56 #define MAYBE_AudioInputDeviceManagerTest DISABLED_AudioInputDeviceManagerTest | 57 #define MAYBE_AudioInputDeviceManagerTest DISABLED_AudioInputDeviceManagerTest |
| 57 #else | 58 #else |
| 58 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest | 59 #define MAYBE_AudioInputDeviceManagerTest AudioInputDeviceManagerTest |
| 59 #endif | 60 #endif |
| 60 | 61 |
| 61 class MAYBE_AudioInputDeviceManagerTest : public testing::Test { | 62 class MAYBE_AudioInputDeviceManagerTest : public testing::Test { |
| 62 public: | 63 public: |
| 63 MAYBE_AudioInputDeviceManagerTest() : audio_thread_("AudioSystemThread") { | 64 MAYBE_AudioInputDeviceManagerTest() {} |
| 64 audio_thread_.StartAndWaitForTesting(); | |
| 65 } | |
| 66 | 65 |
| 67 protected: | 66 protected: |
| 68 void SetUp() override { | 67 void SetUp() override { |
| 69 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 68 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 70 switches::kUseFakeDeviceForMediaStream); | 69 switches::kUseFakeDeviceForMediaStream); |
| 71 // AudioInputDeviceManager accesses AudioSystem from IO thread, so it never | 70 // AudioInputDeviceManager accesses AudioSystem from IO thread, so it never |
| 72 // runs on the same thread with it, even on Mac. | 71 // runs on the same thread with it, even on Mac. |
| 73 audio_manager_ = | 72 audio_manager_ = media::AudioManager::CreateForTesting( |
| 74 media::AudioManager::CreateForTesting(audio_thread_.task_runner()); | 73 base::MakeUnique<media::AudioThreadImpl>()); |
| 75 // Flush the message loop to ensure proper initialization of AudioManager. | 74 // Flush the message loop to ensure proper initialization of AudioManager. |
| 76 base::RunLoop().RunUntilIdle(); | 75 base::RunLoop().RunUntilIdle(); |
| 77 | 76 |
| 78 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); | 77 audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get()); |
| 79 manager_ = new AudioInputDeviceManager(audio_system_.get()); | 78 manager_ = new AudioInputDeviceManager(audio_system_.get()); |
| 80 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); | 79 audio_input_listener_.reset(new MockAudioInputDeviceManagerListener()); |
| 81 manager_->RegisterListener(audio_input_listener_.get()); | 80 manager_->RegisterListener(audio_input_listener_.get()); |
| 82 | 81 |
| 83 // Use fake devices. | 82 // Use fake devices. |
| 84 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1", | 83 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 1", |
| 85 "fake_device_1"); | 84 "fake_device_1"); |
| 86 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2", | 85 devices_.emplace_back(MEDIA_DEVICE_AUDIO_CAPTURE, "Fake Device 2", |
| 87 "fake_device_2"); | 86 "fake_device_2"); |
| 88 | 87 |
| 89 // Wait until we get the list. | 88 // Wait until we get the list. |
| 90 base::RunLoop().RunUntilIdle(); | 89 base::RunLoop().RunUntilIdle(); |
| 91 } | 90 } |
| 92 | 91 |
| 93 void TearDown() override { | 92 void TearDown() override { |
| 94 manager_->UnregisterListener(audio_input_listener_.get()); | 93 manager_->UnregisterListener(audio_input_listener_.get()); |
| 95 audio_system_.reset(); | 94 audio_manager_->Shutdown(); |
| 96 audio_manager_.reset(); | |
| 97 audio_thread_.Stop(); | |
| 98 } | 95 } |
| 99 | 96 |
| 100 void WaitForOpenCompletion() { | 97 void WaitForOpenCompletion() { |
| 101 media::WaitableMessageLoopEvent event; | 98 media::WaitableMessageLoopEvent event; |
| 102 audio_thread_.task_runner()->PostTaskAndReply( | 99 audio_manager_->GetTaskRunner()->PostTaskAndReply( |
| 103 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure()); | 100 FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure()); |
| 104 // Runs the loop and waits for the |audio_thread_| to call event's | 101 // Runs the loop and waits for the audio thread to call event's |
| 105 // closure. | 102 // closure. |
| 106 event.RunAndWait(); | 103 event.RunAndWait(); |
| 107 base::RunLoop().RunUntilIdle(); | 104 base::RunLoop().RunUntilIdle(); |
| 108 } | 105 } |
| 109 | 106 |
| 110 TestBrowserThreadBundle thread_bundle_; | 107 TestBrowserThreadBundle thread_bundle_; |
| 111 base::Thread audio_thread_; | 108 std::unique_ptr<media::AudioManager> audio_manager_; |
| 112 media::ScopedAudioManagerPtr audio_manager_; | |
| 113 std::unique_ptr<media::AudioSystem> audio_system_; | 109 std::unique_ptr<media::AudioSystem> audio_system_; |
| 114 scoped_refptr<AudioInputDeviceManager> manager_; | 110 scoped_refptr<AudioInputDeviceManager> manager_; |
| 115 std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; | 111 std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_; |
| 116 StreamDeviceInfoArray devices_; | 112 StreamDeviceInfoArray devices_; |
| 117 | 113 |
| 118 private: | 114 private: |
| 119 DISALLOW_COPY_AND_ASSIGN(MAYBE_AudioInputDeviceManagerTest); | 115 DISALLOW_COPY_AND_ASSIGN(MAYBE_AudioInputDeviceManagerTest); |
| 120 }; | 116 }; |
| 121 | 117 |
| 122 // Opens and closes the devices. | 118 // Opens and closes the devices. |
| (...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 DCHECK(!info); | 290 DCHECK(!info); |
| 295 | 291 |
| 296 manager_->Close(session_id); | 292 manager_->Close(session_id); |
| 297 EXPECT_CALL(*audio_input_listener_, | 293 EXPECT_CALL(*audio_input_listener_, |
| 298 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) | 294 Closed(MEDIA_DEVICE_AUDIO_CAPTURE, session_id)) |
| 299 .Times(1); | 295 .Times(1); |
| 300 base::RunLoop().RunUntilIdle(); | 296 base::RunLoop().RunUntilIdle(); |
| 301 } | 297 } |
| 302 | 298 |
| 303 } // namespace content | 299 } // namespace content |
| OLD | NEW |