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

Side by Side 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 unified diff | Download patch
OLDNEW
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 "media/audio/audio_input_controller.h" 5 #include "media/audio/audio_input_controller.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
11 #include "base/single_thread_task_runner.h" 11 #include "base/single_thread_task_runner.h"
12 #include "base/synchronization/waitable_event.h" 12 #include "base/synchronization/waitable_event.h"
13 #include "base/test/test_timeouts.h" 13 #include "base/test/test_timeouts.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "media/audio/audio_device_description.h" 15 #include "media/audio/audio_device_description.h"
16 #include "media/audio/audio_thread_impl.h" 16 #include "media/audio/audio_thread_impl.h"
17 #include "media/audio/fake_audio_input_stream.h"
17 #include "testing/gmock/include/gmock/gmock.h" 18 #include "testing/gmock/include/gmock/gmock.h"
18 #include "testing/gtest/include/gtest/gtest.h" 19 #include "testing/gtest/include/gtest/gtest.h"
19 20
20 using ::testing::_; 21 using ::testing::_;
21 using ::testing::AnyNumber; 22 using ::testing::AnyNumber;
22 using ::testing::AtLeast; 23 using ::testing::AtLeast;
23 using ::testing::Exactly; 24 using ::testing::Exactly;
24 using ::testing::InvokeWithoutArgs; 25 using ::testing::InvokeWithoutArgs;
25 using ::testing::NotNull; 26 using ::testing::NotNull;
26 using base::WaitableEvent; 27 using base::WaitableEvent;
(...skipping 28 matching lines...) Expand all
55 : public AudioInputController::EventHandler { 56 : public AudioInputController::EventHandler {
56 public: 57 public:
57 MockAudioInputControllerEventHandler() {} 58 MockAudioInputControllerEventHandler() {}
58 59
59 MOCK_METHOD1(OnCreated, void(AudioInputController* controller)); 60 MOCK_METHOD1(OnCreated, void(AudioInputController* controller));
60 MOCK_METHOD2(OnError, void(AudioInputController* controller, 61 MOCK_METHOD2(OnError, void(AudioInputController* controller,
61 AudioInputController::ErrorCode error_code)); 62 AudioInputController::ErrorCode error_code));
62 MOCK_METHOD2(OnLog, 63 MOCK_METHOD2(OnLog,
63 void(AudioInputController* controller, 64 void(AudioInputController* controller,
64 const std::string& message)); 65 const std::string& message));
66 MOCK_METHOD2(OnMuted, void(AudioInputController* controller, bool is_muted));
65 67
66 private: 68 private:
67 DISALLOW_COPY_AND_ASSIGN(MockAudioInputControllerEventHandler); 69 DISALLOW_COPY_AND_ASSIGN(MockAudioInputControllerEventHandler);
68 }; 70 };
69 71
70 class MockSyncWriter : public AudioInputController::SyncWriter { 72 class MockSyncWriter : public AudioInputController::SyncWriter {
71 public: 73 public:
72 MockSyncWriter() {} 74 MockSyncWriter() {}
73 75
74 MOCK_METHOD4(Write, 76 MOCK_METHOD4(Write,
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 218
217 controller->Record(); 219 controller->Record();
218 220
219 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); 221 controller->Close(base::MessageLoop::QuitWhenIdleClosure());
220 base::RunLoop().Run(); 222 base::RunLoop().Run();
221 223
222 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); 224 controller->Close(base::MessageLoop::QuitWhenIdleClosure());
223 base::RunLoop().Run(); 225 base::RunLoop().Run();
224 } 226 }
225 227
228 // Test that AudioInputController sends OnMute callbacks properly.
229 TEST_F(AudioInputControllerTest, TestOnmutedCallbackInitiallyUnmuted) {
230 base::RunLoop run_loop;
231
232 MockAudioInputControllerEventHandler event_handler;
233 MockSyncWriter sync_writer;
234 scoped_refptr<AudioInputController> controller;
235 WaitableEvent callback_event(WaitableEvent::ResetPolicy::AUTOMATIC,
236 WaitableEvent::InitialState::NOT_SIGNALED);
237
238 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
239 kSampleRate, kBitsPerSample, kSamplesPerPacket);
240
241 SuspendAudioThread();
242 FakeAudioInputStream::SetGlobalMutedState(false);
243 controller = AudioInputController::Create(
244 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
245 AudioDeviceDescription::kDefaultDeviceId, false);
246 ASSERT_TRUE(controller.get());
247 EXPECT_CALL(event_handler, OnCreated(controller.get())).Times(Exactly(1));
248 EXPECT_CALL(event_handler, OnLog(controller.get(), _));
249 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
250 EXPECT_CALL(event_handler, OnMuted(controller.get(), true))
251 .WillOnce(InvokeWithoutArgs([&] { callback_event.Signal(); }));
252 EXPECT_CALL(event_handler, OnMuted(controller.get(), false))
253 .WillOnce(InvokeWithoutArgs([&] { callback_event.Signal(); }));
254 ResumeAudioThread();
255
256 // AudioInputController will poll once every second, so wait at most a bit
257 // more than that for the callbacks.
258 FakeAudioInputStream::SetGlobalMutedState(true);
259 callback_event.TimedWait(base::TimeDelta::FromMilliseconds(1500));
260 FakeAudioInputStream::SetGlobalMutedState(false);
261 callback_event.TimedWait(base::TimeDelta::FromMilliseconds(1500));
262
263 CloseAudioController(controller.get());
264 }
265
266 TEST_F(AudioInputControllerTest, TestOnmutedCallbackInitiallyMuted) {
267 base::RunLoop run_loop;
268
269 MockAudioInputControllerEventHandler event_handler;
270 MockSyncWriter sync_writer;
271 scoped_refptr<AudioInputController> controller;
272 WaitableEvent callback_event(WaitableEvent::ResetPolicy::AUTOMATIC,
273 WaitableEvent::InitialState::NOT_SIGNALED);
274
275 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
276 kSampleRate, kBitsPerSample, kSamplesPerPacket);
277
278 SuspendAudioThread();
279 FakeAudioInputStream::SetGlobalMutedState(true);
280 controller = AudioInputController::Create(
281 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
282 AudioDeviceDescription::kDefaultDeviceId, false);
283 ASSERT_TRUE(controller.get());
284 EXPECT_CALL(event_handler, OnCreated(controller.get())).Times(Exactly(1));
285 EXPECT_CALL(event_handler, OnLog(controller.get(), _));
286 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
287 EXPECT_CALL(event_handler, OnMuted(controller.get(), true))
288 .WillOnce(InvokeWithoutArgs([&] { callback_event.Signal(); }));
289 EXPECT_CALL(event_handler, OnMuted(controller.get(), false))
290 .WillOnce(InvokeWithoutArgs([&] { callback_event.Signal(); }));
291 ResumeAudioThread();
292
293 // AudioInputController will poll once every second, so wait at most a bit
294 // more than that for the callbacks.
295 callback_event.TimedWait(base::TimeDelta::FromMilliseconds(1500));
296 FakeAudioInputStream::SetGlobalMutedState(false);
297 callback_event.TimedWait(base::TimeDelta::FromMilliseconds(1500));
298
299 CloseAudioController(controller.get());
300 }
301
226 } // namespace media 302 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698