| Index: content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
|
| diff --git a/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc b/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
|
| index bf3b80a5528b2ecc579ddfedbbb3281c6f043d9b..b83c57ee47456ecca6dfc09d94b17fcb3d089a59 100644
|
| --- a/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
|
| +++ b/content/browser/renderer_host/media/audio_input_device_manager_unittest.cc
|
| @@ -21,7 +21,9 @@
|
| #include "content/public/common/media_stream_request.h"
|
| #include "content/public/test/test_browser_thread_bundle.h"
|
| #include "media/audio/audio_manager_base.h"
|
| +#include "media/audio/audio_system_impl.h"
|
| #include "media/base/media_switches.h"
|
| +#include "media/base/test_helpers.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -58,18 +60,21 @@ class MockAudioInputDeviceManagerListener
|
|
|
| class MAYBE_AudioInputDeviceManagerTest : public testing::Test {
|
| public:
|
| - MAYBE_AudioInputDeviceManagerTest() {}
|
| + MAYBE_AudioInputDeviceManagerTest() : audio_thread_("AudioSystemThread") {
|
| + audio_thread_.StartAndWaitForTesting();
|
| + }
|
|
|
| protected:
|
| void SetUp() override {
|
| base::CommandLine::ForCurrentProcess()->AppendSwitch(
|
| switches::kUseFakeDeviceForMediaStream);
|
| - audio_manager_ = media::AudioManager::CreateForTesting(
|
| - base::ThreadTaskRunnerHandle::Get());
|
| + audio_manager_ =
|
| + media::AudioManager::CreateForTesting(audio_thread_.task_runner());
|
| // Flush the message loop to ensure proper initialization of AudioManager.
|
| base::RunLoop().RunUntilIdle();
|
|
|
| - manager_ = new AudioInputDeviceManager(audio_manager_.get());
|
| + audio_system_ = media::AudioSystemImpl::Create(audio_manager_.get());
|
| + manager_ = new AudioInputDeviceManager(audio_system_.get());
|
| audio_input_listener_.reset(new MockAudioInputDeviceManagerListener());
|
| manager_->RegisterListener(audio_input_listener_.get());
|
|
|
| @@ -87,10 +92,22 @@ class MAYBE_AudioInputDeviceManagerTest : public testing::Test {
|
| manager_->UnregisterListener(audio_input_listener_.get());
|
| }
|
|
|
| + void WaitForOpenCompletion() {
|
| + media::WaitableMessageLoopEvent event;
|
| + audio_thread_.task_runner()->PostTaskAndReply(
|
| + FROM_HERE, base::Bind(&base::DoNothing), event.GetClosure());
|
| + // Runs the loop and waits for the |audio_thread_| to call event's
|
| + // closure.
|
| + event.RunAndWait();
|
| + base::RunLoop().RunUntilIdle();
|
| + }
|
| +
|
| TestBrowserThreadBundle thread_bundle_;
|
| + base::Thread audio_thread_;
|
| scoped_refptr<AudioInputDeviceManager> manager_;
|
| std::unique_ptr<MockAudioInputDeviceManagerListener> audio_input_listener_;
|
| media::ScopedAudioManagerPtr audio_manager_;
|
| + std::unique_ptr<media::AudioSystem> audio_system_;
|
| StreamDeviceInfoArray devices_;
|
|
|
| private:
|
| @@ -113,7 +130,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenAndCloseDevice) {
|
| Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
|
| .Times(1);
|
| // Waits for the callback.
|
| - base::RunLoop().RunUntilIdle();
|
| + WaitForOpenCompletion();
|
|
|
| manager_->Close(session_id);
|
| EXPECT_CALL(*audio_input_listener_,
|
| @@ -146,7 +163,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenMultipleDevices) {
|
| .Times(1);
|
|
|
| // Waits for the callback.
|
| - base::RunLoop().RunUntilIdle();
|
| + WaitForOpenCompletion();
|
| }
|
|
|
| // Checks if the session_ids are unique.
|
| @@ -183,7 +200,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenNotExistingDevice) {
|
| .Times(1);
|
|
|
| // Waits for the callback.
|
| - base::RunLoop().RunUntilIdle();
|
| + WaitForOpenCompletion();
|
| }
|
|
|
| // Opens default device twice.
|
| @@ -205,7 +222,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenDeviceTwice) {
|
| Opened(MEDIA_DEVICE_AUDIO_CAPTURE, second_session_id))
|
| .Times(1);
|
| // Waits for the callback.
|
| - base::RunLoop().RunUntilIdle();
|
| + WaitForOpenCompletion();
|
|
|
| manager_->Close(first_session_id);
|
| manager_->Close(second_session_id);
|
| @@ -238,7 +255,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessAndCloseSession) {
|
| EXPECT_CALL(*audio_input_listener_,
|
| Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id[index]))
|
| .Times(1);
|
| - base::RunLoop().RunUntilIdle();
|
| + WaitForOpenCompletion();
|
|
|
| const StreamDeviceInfo* info = manager_->GetOpenedDeviceInfoById(
|
| session_id[index]);
|
| @@ -262,7 +279,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessInvalidSession) {
|
| EXPECT_CALL(*audio_input_listener_,
|
| Opened(MEDIA_DEVICE_AUDIO_CAPTURE, session_id))
|
| .Times(1);
|
| - base::RunLoop().RunUntilIdle();
|
| + WaitForOpenCompletion();
|
|
|
| // Access a non-opened device.
|
| // This should fail and return an empty StreamDeviceInfo.
|
| @@ -278,4 +295,14 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, AccessInvalidSession) {
|
| base::RunLoop().RunUntilIdle();
|
| }
|
|
|
| +// No crash during shutdown while Open() is in progress (i.e there are tasks
|
| +// queued on audio thread).
|
| +TEST_F(MAYBE_AudioInputDeviceManagerTest, NoCrashOnShutdown) {
|
| + // Loops through the devices and calls Open() for each device.
|
| + for (StreamDeviceInfoArray::const_iterator iter = devices_.begin();
|
| + iter != devices_.end(); ++iter) {
|
| + manager_->Open(iter->device);
|
| + }
|
| +}
|
| +
|
| } // namespace content
|
|
|