| OLD | NEW |
| 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 "base/basictypes.h" | 5 #include "base/basictypes.h" |
| 6 #include "base/bind.h" | 6 #include "base/bind.h" |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "base/synchronization/waitable_event.h" | 8 #include "base/synchronization/waitable_event.h" |
| 9 #include "base/test/test_timeouts.h" | 9 #include "base/test/test_timeouts.h" |
| 10 #include "media/audio/audio_input_controller.h" | 10 #include "media/audio/audio_input_controller.h" |
| 11 #include "media/audio/audio_manager_base.h" | 11 #include "media/audio/audio_manager_base.h" |
| 12 #include "testing/gmock/include/gmock/gmock.h" | 12 #include "testing/gmock/include/gmock/gmock.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
| 14 | 14 |
| 15 using ::testing::_; | 15 using ::testing::_; |
| 16 using ::testing::AtLeast; | 16 using ::testing::AtLeast; |
| 17 using ::testing::Exactly; | 17 using ::testing::Exactly; |
| 18 using ::testing::InvokeWithoutArgs; | 18 using ::testing::InvokeWithoutArgs; |
| 19 using ::testing::NotNull; | 19 using ::testing::NotNull; |
| 20 | 20 |
| 21 namespace media { | 21 namespace media { |
| 22 | 22 |
| 23 static const int kSampleRate = AudioParameters::kAudioCDSampleRate; | 23 static const int kSampleRate = AudioParameters::kAudioCDSampleRate; |
| 24 static const int kBitsPerSample = 16; | 24 static const int kBitsPerSample = 16; |
| 25 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; | 25 static const ChannelLayout kChannelLayout = CHANNEL_LAYOUT_STEREO; |
| 26 static const int kSamplesPerPacket = kSampleRate / 10; | 26 static const int kSamplesPerPacket = kSampleRate / 10; |
| 27 | 27 |
| 28 // Posts base::MessageLoop::QuitClosure() on specified message loop. | 28 // Posts base::MessageLoop::QuitWhenIdleClosure() on specified message loop. |
| 29 ACTION_P(QuitMessageLoop, loop_or_proxy) { | 29 ACTION_P(QuitMessageLoop, loop_or_proxy) { |
| 30 loop_or_proxy->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 30 loop_or_proxy->PostTask(FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 31 } | 31 } |
| 32 | 32 |
| 33 // Posts base::MessageLoop::QuitClosure() on specified message loop after a | 33 // Posts base::MessageLoop::QuitWhenIdleClosure() on specified message loop |
| 34 // certain number of calls given by |limit|. | 34 // after a certain number of calls given by |limit|. |
| 35 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop_or_proxy) { | 35 ACTION_P3(CheckCountAndPostQuitTask, count, limit, loop_or_proxy) { |
| 36 if (++*count >= limit) { | 36 if (++*count >= limit) { |
| 37 loop_or_proxy->PostTask(FROM_HERE, base::MessageLoop::QuitClosure()); | 37 loop_or_proxy->PostTask(FROM_HERE, |
| 38 base::MessageLoop::QuitWhenIdleClosure()); |
| 38 } | 39 } |
| 39 } | 40 } |
| 40 | 41 |
| 41 // Closes AudioOutputController synchronously. | 42 // Closes AudioOutputController synchronously. |
| 42 static void CloseAudioController(AudioInputController* controller) { | 43 static void CloseAudioController(AudioInputController* controller) { |
| 43 controller->Close(base::MessageLoop::QuitClosure()); | 44 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 44 base::MessageLoop::current()->Run(); | 45 base::MessageLoop::current()->Run(); |
| 45 } | 46 } |
| 46 | 47 |
| 47 class MockAudioInputControllerEventHandler | 48 class MockAudioInputControllerEventHandler |
| 48 : public AudioInputController::EventHandler { | 49 : public AudioInputController::EventHandler { |
| 49 public: | 50 public: |
| 50 MockAudioInputControllerEventHandler() {} | 51 MockAudioInputControllerEventHandler() {} |
| 51 | 52 |
| 52 MOCK_METHOD1(OnCreated, void(AudioInputController* controller)); | 53 MOCK_METHOD1(OnCreated, void(AudioInputController* controller)); |
| 53 MOCK_METHOD1(OnRecording, void(AudioInputController* controller)); | 54 MOCK_METHOD1(OnRecording, void(AudioInputController* controller)); |
| (...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 scoped_refptr<AudioInputController> controller = | 248 scoped_refptr<AudioInputController> controller = |
| 248 AudioInputController::Create(audio_manager.get(), | 249 AudioInputController::Create(audio_manager.get(), |
| 249 &event_handler, | 250 &event_handler, |
| 250 params, | 251 params, |
| 251 AudioManagerBase::kDefaultDeviceId, | 252 AudioManagerBase::kDefaultDeviceId, |
| 252 NULL); | 253 NULL); |
| 253 ASSERT_TRUE(controller.get()); | 254 ASSERT_TRUE(controller.get()); |
| 254 | 255 |
| 255 controller->Record(); | 256 controller->Record(); |
| 256 | 257 |
| 257 controller->Close(base::MessageLoop::QuitClosure()); | 258 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 258 base::MessageLoop::current()->Run(); | 259 base::MessageLoop::current()->Run(); |
| 259 | 260 |
| 260 controller->Close(base::MessageLoop::QuitClosure()); | 261 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); |
| 261 base::MessageLoop::current()->Run(); | 262 base::MessageLoop::current()->Run(); |
| 262 } | 263 } |
| 263 | 264 |
| 264 } // namespace media | 265 } // namespace media |
| OLD | NEW |