| 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" |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 76 TEST_F(AudioInputControllerTest, CreateAndClose) { | 76 TEST_F(AudioInputControllerTest, CreateAndClose) { |
| 77 MockAudioInputControllerEventHandler event_handler; | 77 MockAudioInputControllerEventHandler event_handler; |
| 78 | 78 |
| 79 // OnCreated() will be posted once. | 79 // OnCreated() will be posted once. |
| 80 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 80 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 81 .WillOnce(QuitMessageLoop(&message_loop_)); | 81 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 82 | 82 |
| 83 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 83 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 84 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 84 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 85 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 85 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 86 scoped_ptr<KeyPressMonitor> key_press_monitor(new KeyPressMonitor()); |
| 86 scoped_refptr<AudioInputController> controller = | 87 scoped_refptr<AudioInputController> controller = |
| 87 AudioInputController::Create(audio_manager.get(), &event_handler, params, | 88 AudioInputController::Create(audio_manager.get(), |
| 88 AudioManagerBase::kDefaultDeviceId); | 89 &event_handler, |
| 90 params, |
| 91 AudioManagerBase::kDefaultDeviceId, |
| 92 key_press_monitor.get()); |
| 89 ASSERT_TRUE(controller.get()); | 93 ASSERT_TRUE(controller.get()); |
| 90 | 94 |
| 91 // Wait for OnCreated() to fire. | 95 // Wait for OnCreated() to fire. |
| 92 message_loop_.Run(); | 96 message_loop_.Run(); |
| 93 | 97 |
| 94 // Close the AudioInputController synchronously. | 98 // Close the AudioInputController synchronously. |
| 95 CloseAudioController(controller.get()); | 99 CloseAudioController(controller.get()); |
| 96 } | 100 } |
| 97 | 101 |
| 98 // Test a normal call sequence of create, record and close. | 102 // Test a normal call sequence of create, record and close. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 112 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _)) | 116 EXPECT_CALL(event_handler, OnData(NotNull(), NotNull(), _)) |
| 113 .Times(AtLeast(10)) | 117 .Times(AtLeast(10)) |
| 114 .WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, | 118 .WillRepeatedly(CheckCountAndPostQuitTask(&count, 10, |
| 115 message_loop_.message_loop_proxy())); | 119 message_loop_.message_loop_proxy())); |
| 116 | 120 |
| 117 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 121 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 118 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 122 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 119 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 123 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 120 | 124 |
| 121 // Creating the AudioInputController should render an OnCreated() call. | 125 // Creating the AudioInputController should render an OnCreated() call. |
| 126 scoped_ptr<KeyPressMonitor> key_press_monitor(new KeyPressMonitor()); |
| 122 scoped_refptr<AudioInputController> controller = | 127 scoped_refptr<AudioInputController> controller = |
| 123 AudioInputController::Create(audio_manager.get(), &event_handler, params, | 128 AudioInputController::Create(audio_manager.get(), |
| 124 AudioManagerBase::kDefaultDeviceId); | 129 &event_handler, |
| 130 params, |
| 131 AudioManagerBase::kDefaultDeviceId, |
| 132 key_press_monitor.get()); |
| 125 ASSERT_TRUE(controller.get()); | 133 ASSERT_TRUE(controller.get()); |
| 126 | 134 |
| 127 // Start recording and trigger one OnRecording() call. | 135 // Start recording and trigger one OnRecording() call. |
| 128 controller->Record(); | 136 controller->Record(); |
| 129 | 137 |
| 130 // Record and wait until ten OnData() callbacks are received. | 138 // Record and wait until ten OnData() callbacks are received. |
| 131 message_loop_.Run(); | 139 message_loop_.Run(); |
| 132 | 140 |
| 133 // Close the AudioInputController synchronously. | 141 // Close the AudioInputController synchronously. |
| 134 CloseAudioController(controller.get()); | 142 CloseAudioController(controller.get()); |
| (...skipping 24 matching lines...) Expand all Loading... |
| 159 // controller is in a recording state. | 167 // controller is in a recording state. |
| 160 EXPECT_CALL(event_handler, OnError(NotNull())) | 168 EXPECT_CALL(event_handler, OnError(NotNull())) |
| 161 .Times(Exactly(1)) | 169 .Times(Exactly(1)) |
| 162 .WillOnce(QuitMessageLoop(&message_loop_)); | 170 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 163 | 171 |
| 164 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 172 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 165 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 173 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 166 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 174 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 167 | 175 |
| 168 // Creating the AudioInputController should render an OnCreated() call. | 176 // Creating the AudioInputController should render an OnCreated() call. |
| 177 scoped_ptr<KeyPressMonitor> key_press_monitor(new KeyPressMonitor()); |
| 169 scoped_refptr<AudioInputController> controller = | 178 scoped_refptr<AudioInputController> controller = |
| 170 AudioInputController::Create(audio_manager.get(), &event_handler, params, | 179 AudioInputController::Create(audio_manager.get(), |
| 171 AudioManagerBase::kDefaultDeviceId); | 180 &event_handler, |
| 181 params, |
| 182 AudioManagerBase::kDefaultDeviceId, |
| 183 key_press_monitor.get()); |
| 172 ASSERT_TRUE(controller.get()); | 184 ASSERT_TRUE(controller.get()); |
| 173 | 185 |
| 174 // Start recording and trigger one OnRecording() call. | 186 // Start recording and trigger one OnRecording() call. |
| 175 controller->Record(); | 187 controller->Record(); |
| 176 | 188 |
| 177 // Record and wait until ten OnData() callbacks are received. | 189 // Record and wait until ten OnData() callbacks are received. |
| 178 message_loop_.Run(); | 190 message_loop_.Run(); |
| 179 | 191 |
| 180 // Stop the stream and verify that OnError() is posted. | 192 // Stop the stream and verify that OnError() is posted. |
| 181 AudioInputStream* stream = controller->stream_for_testing(); | 193 AudioInputStream* stream = controller->stream_for_testing(); |
| 182 stream->Stop(); | 194 stream->Stop(); |
| 183 message_loop_.Run(); | 195 message_loop_.Run(); |
| 184 | 196 |
| 185 // Close the AudioInputController synchronously. | 197 // Close the AudioInputController synchronously. |
| 186 CloseAudioController(controller.get()); | 198 CloseAudioController(controller.get()); |
| 187 } | 199 } |
| 188 | 200 |
| 189 // Test that AudioInputController rejects insanely large packet sizes. | 201 // Test that AudioInputController rejects insanely large packet sizes. |
| 190 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) { | 202 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) { |
| 191 // Create an audio device with a very large packet size. | 203 // Create an audio device with a very large packet size. |
| 192 MockAudioInputControllerEventHandler event_handler; | 204 MockAudioInputControllerEventHandler event_handler; |
| 193 | 205 |
| 194 // OnCreated() shall not be called in this test. | 206 // OnCreated() shall not be called in this test. |
| 195 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 207 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 196 .Times(Exactly(0)); | 208 .Times(Exactly(0)); |
| 197 | 209 |
| 198 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 210 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 199 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 211 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 200 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); | 212 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); |
| 213 scoped_ptr<KeyPressMonitor> key_press_monitor(new KeyPressMonitor()); |
| 201 scoped_refptr<AudioInputController> controller = | 214 scoped_refptr<AudioInputController> controller = |
| 202 AudioInputController::Create(audio_manager.get(), &event_handler, params, | 215 AudioInputController::Create(audio_manager.get(), |
| 203 AudioManagerBase::kDefaultDeviceId); | 216 &event_handler, |
| 217 params, |
| 218 AudioManagerBase::kDefaultDeviceId, |
| 219 key_press_monitor.get()); |
| 204 ASSERT_FALSE(controller.get()); | 220 ASSERT_FALSE(controller.get()); |
| 205 } | 221 } |
| 206 | 222 |
| 207 // Test calling AudioInputController::Close multiple times. | 223 // Test calling AudioInputController::Close multiple times. |
| 208 TEST_F(AudioInputControllerTest, CloseTwice) { | 224 TEST_F(AudioInputControllerTest, CloseTwice) { |
| 209 MockAudioInputControllerEventHandler event_handler; | 225 MockAudioInputControllerEventHandler event_handler; |
| 210 | 226 |
| 211 // OnRecording() will be called only once. | 227 // OnRecording() will be called only once. |
| 212 EXPECT_CALL(event_handler, OnCreated(NotNull())); | 228 EXPECT_CALL(event_handler, OnCreated(NotNull())); |
| 213 | 229 |
| 214 // OnRecording() will be called only once. | 230 // OnRecording() will be called only once. |
| 215 EXPECT_CALL(event_handler, OnRecording(NotNull())) | 231 EXPECT_CALL(event_handler, OnRecording(NotNull())) |
| 216 .Times(Exactly(1)); | 232 .Times(Exactly(1)); |
| 217 | 233 |
| 218 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 234 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 219 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 235 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 220 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 236 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 237 scoped_ptr<KeyPressMonitor> key_press_monitor(new KeyPressMonitor()); |
| 221 scoped_refptr<AudioInputController> controller = | 238 scoped_refptr<AudioInputController> controller = |
| 222 AudioInputController::Create(audio_manager.get(), &event_handler, params, | 239 AudioInputController::Create(audio_manager.get(), |
| 223 AudioManagerBase::kDefaultDeviceId); | 240 &event_handler, |
| 241 params, |
| 242 AudioManagerBase::kDefaultDeviceId, |
| 243 key_press_monitor.get()); |
| 224 ASSERT_TRUE(controller.get()); | 244 ASSERT_TRUE(controller.get()); |
| 225 | 245 |
| 226 controller->Record(); | 246 controller->Record(); |
| 227 | 247 |
| 228 controller->Close(base::MessageLoop::QuitClosure()); | 248 controller->Close(base::MessageLoop::QuitClosure()); |
| 229 base::MessageLoop::current()->Run(); | 249 base::MessageLoop::current()->Run(); |
| 230 | 250 |
| 231 controller->Close(base::MessageLoop::QuitClosure()); | 251 controller->Close(base::MessageLoop::QuitClosure()); |
| 232 base::MessageLoop::current()->Run(); | 252 base::MessageLoop::current()->Run(); |
| 233 } | 253 } |
| 234 | 254 |
| 235 } // namespace media | 255 } // namespace media |
| OLD | NEW |