Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(162)

Unified Diff: media/audio/audio_input_controller_unittest.cc

Issue 2919793002: Detect AudioInputStream muting and propagate to MediaStreamAudioSource. (Closed)
Patch Set: Implemented tests, addressed comments. Created 3 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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

Powered by Google App Engine
This is Rietveld 408576698