| Index: media/audio/audio_input_controller_unittest.cc
|
| diff --git a/media/audio/audio_input_controller_unittest.cc b/media/audio/audio_input_controller_unittest.cc
|
| index 3d9ba1a98030ed61b3e54f3f7ceb14a58462cc54..a8f0984051e1310dfdb364f2045ddc15c2312a02 100644
|
| --- a/media/audio/audio_input_controller_unittest.cc
|
| +++ b/media/audio/audio_input_controller_unittest.cc
|
| @@ -14,6 +14,7 @@
|
| #include "base/threading/thread.h"
|
| #include "media/audio/audio_device_description.h"
|
| #include "media/audio/audio_thread_impl.h"
|
| +#include "media/audio/fake_audio_input_stream.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
|
|
| @@ -62,6 +63,7 @@ class MockAudioInputControllerEventHandler
|
| MOCK_METHOD2(OnLog,
|
| void(AudioInputController* controller,
|
| const std::string& message));
|
| + MOCK_METHOD2(OnMuted, void(AudioInputController* controller, bool is_muted));
|
|
|
| private:
|
| DISALLOW_COPY_AND_ASSIGN(MockAudioInputControllerEventHandler);
|
| @@ -223,4 +225,78 @@ TEST_F(AudioInputControllerTest, CloseTwice) {
|
| base::RunLoop().Run();
|
| }
|
|
|
| +// Test that AudioInputController sends OnMute callbacks properly.
|
| +TEST_F(AudioInputControllerTest, TestOnmutedCallbackInitiallyUnmuted) {
|
| + base::RunLoop run_loop;
|
| +
|
| + MockAudioInputControllerEventHandler event_handler;
|
| + MockSyncWriter sync_writer;
|
| + scoped_refptr<AudioInputController> controller;
|
| + WaitableEvent callback_event(WaitableEvent::ResetPolicy::AUTOMATIC,
|
| + WaitableEvent::InitialState::NOT_SIGNALED);
|
| +
|
| + AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
|
| + kSampleRate, kBitsPerSample, kSamplesPerPacket);
|
| +
|
| + SuspendAudioThread();
|
| + FakeAudioInputStream::SetGlobalMutedState(false);
|
| + controller = AudioInputController::Create(
|
| + audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
|
| + AudioDeviceDescription::kDefaultDeviceId, false);
|
| + ASSERT_TRUE(controller.get());
|
| + EXPECT_CALL(event_handler, OnCreated(controller.get())).Times(Exactly(1));
|
| + EXPECT_CALL(event_handler, OnLog(controller.get(), _));
|
| + EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
|
| + EXPECT_CALL(event_handler, OnMuted(controller.get(), true))
|
| + .WillOnce(InvokeWithoutArgs([&] { callback_event.Signal(); }));
|
| + EXPECT_CALL(event_handler, OnMuted(controller.get(), false))
|
| + .WillOnce(InvokeWithoutArgs([&] { callback_event.Signal(); }));
|
| + ResumeAudioThread();
|
| +
|
| + // AudioInputController will poll once every second, so wait at most a bit
|
| + // more than that for the callbacks.
|
| + FakeAudioInputStream::SetGlobalMutedState(true);
|
| + callback_event.TimedWait(base::TimeDelta::FromMilliseconds(1500));
|
| + FakeAudioInputStream::SetGlobalMutedState(false);
|
| + callback_event.TimedWait(base::TimeDelta::FromMilliseconds(1500));
|
| +
|
| + CloseAudioController(controller.get());
|
| +}
|
| +
|
| +TEST_F(AudioInputControllerTest, TestOnmutedCallbackInitiallyMuted) {
|
| + base::RunLoop run_loop;
|
| +
|
| + MockAudioInputControllerEventHandler event_handler;
|
| + MockSyncWriter sync_writer;
|
| + scoped_refptr<AudioInputController> controller;
|
| + WaitableEvent callback_event(WaitableEvent::ResetPolicy::AUTOMATIC,
|
| + WaitableEvent::InitialState::NOT_SIGNALED);
|
| +
|
| + AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
|
| + kSampleRate, kBitsPerSample, kSamplesPerPacket);
|
| +
|
| + SuspendAudioThread();
|
| + FakeAudioInputStream::SetGlobalMutedState(true);
|
| + controller = AudioInputController::Create(
|
| + audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
|
| + AudioDeviceDescription::kDefaultDeviceId, false);
|
| + ASSERT_TRUE(controller.get());
|
| + EXPECT_CALL(event_handler, OnCreated(controller.get())).Times(Exactly(1));
|
| + EXPECT_CALL(event_handler, OnLog(controller.get(), _));
|
| + EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
|
| + EXPECT_CALL(event_handler, OnMuted(controller.get(), true))
|
| + .WillOnce(InvokeWithoutArgs([&] { callback_event.Signal(); }));
|
| + EXPECT_CALL(event_handler, OnMuted(controller.get(), false))
|
| + .WillOnce(InvokeWithoutArgs([&] { callback_event.Signal(); }));
|
| + ResumeAudioThread();
|
| +
|
| + // AudioInputController will poll once every second, so wait at most a bit
|
| + // more than that for the callbacks.
|
| + callback_event.TimedWait(base::TimeDelta::FromMilliseconds(1500));
|
| + FakeAudioInputStream::SetGlobalMutedState(false);
|
| + callback_event.TimedWait(base::TimeDelta::FromMilliseconds(1500));
|
| +
|
| + CloseAudioController(controller.get());
|
| +}
|
| +
|
| } // namespace media
|
|
|