Chromium Code Reviews| 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..800bc74b2d48148785aa9a6252dc564b3b1285bf 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 { |
|
DaleCurtis
2017/03/28 18:22:11
Hmm, does MAYBE actually work as a classname? I th
o1ka
2017/03/30 15:11:53
Looks like it does: https://github.com/google/goog
|
| 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()); |
| @@ -85,12 +90,27 @@ class MAYBE_AudioInputDeviceManagerTest : public testing::Test { |
| void TearDown() override { |
| manager_->UnregisterListener(audio_input_listener_.get()); |
| + audio_system_.reset(); |
| + audio_manager_.reset(); |
| + audio_thread_.Stop(); |
| + } |
| + |
| + 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 +133,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 +166,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 +203,7 @@ TEST_F(MAYBE_AudioInputDeviceManagerTest, OpenNotExistingDevice) { |
| .Times(1); |
| // Waits for the callback. |
| - base::RunLoop().RunUntilIdle(); |
| + WaitForOpenCompletion(); |
| } |
| // Opens default device twice. |
| @@ -205,7 +225,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 +258,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 +282,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 +298,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 |