| 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 |
| 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 NULL); |
| 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 14 matching lines...) Expand all Loading... |
| 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. |
| 122 scoped_refptr<AudioInputController> controller = | 126 scoped_refptr<AudioInputController> controller = |
| 123 AudioInputController::Create(audio_manager.get(), &event_handler, params, | 127 AudioInputController::Create(audio_manager.get(), |
| 124 AudioManagerBase::kDefaultDeviceId); | 128 &event_handler, |
| 129 params, |
| 130 AudioManagerBase::kDefaultDeviceId, |
| 131 NULL); |
| 125 ASSERT_TRUE(controller.get()); | 132 ASSERT_TRUE(controller.get()); |
| 126 | 133 |
| 127 // Start recording and trigger one OnRecording() call. | 134 // Start recording and trigger one OnRecording() call. |
| 128 controller->Record(); | 135 controller->Record(); |
| 129 | 136 |
| 130 // Record and wait until ten OnData() callbacks are received. | 137 // Record and wait until ten OnData() callbacks are received. |
| 131 message_loop_.Run(); | 138 message_loop_.Run(); |
| 132 | 139 |
| 133 // Close the AudioInputController synchronously. | 140 // Close the AudioInputController synchronously. |
| 134 CloseAudioController(controller.get()); | 141 CloseAudioController(controller.get()); |
| (...skipping 25 matching lines...) Expand all Loading... |
| 160 EXPECT_CALL(event_handler, OnError(NotNull())) | 167 EXPECT_CALL(event_handler, OnError(NotNull())) |
| 161 .Times(Exactly(1)) | 168 .Times(Exactly(1)) |
| 162 .WillOnce(QuitMessageLoop(&message_loop_)); | 169 .WillOnce(QuitMessageLoop(&message_loop_)); |
| 163 | 170 |
| 164 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 171 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 165 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 172 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
| 166 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 173 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
| 167 | 174 |
| 168 // Creating the AudioInputController should render an OnCreated() call. | 175 // Creating the AudioInputController should render an OnCreated() call. |
| 169 scoped_refptr<AudioInputController> controller = | 176 scoped_refptr<AudioInputController> controller = |
| 170 AudioInputController::Create(audio_manager.get(), &event_handler, params, | 177 AudioInputController::Create(audio_manager.get(), |
| 171 AudioManagerBase::kDefaultDeviceId); | 178 &event_handler, |
| 179 params, |
| 180 AudioManagerBase::kDefaultDeviceId, |
| 181 NULL); |
| 172 ASSERT_TRUE(controller.get()); | 182 ASSERT_TRUE(controller.get()); |
| 173 | 183 |
| 174 // Start recording and trigger one OnRecording() call. | 184 // Start recording and trigger one OnRecording() call. |
| 175 controller->Record(); | 185 controller->Record(); |
| 176 | 186 |
| 177 // Record and wait until ten OnData() callbacks are received. | 187 // Record and wait until ten OnData() callbacks are received. |
| 178 message_loop_.Run(); | 188 message_loop_.Run(); |
| 179 | 189 |
| 180 // Stop the stream and verify that OnError() is posted. | 190 // Stop the stream and verify that OnError() is posted. |
| 181 AudioInputStream* stream = controller->stream_for_testing(); | 191 AudioInputStream* stream = controller->stream_for_testing(); |
| 182 stream->Stop(); | 192 stream->Stop(); |
| 183 message_loop_.Run(); | 193 message_loop_.Run(); |
| 184 | 194 |
| 185 // Close the AudioInputController synchronously. | 195 // Close the AudioInputController synchronously. |
| 186 CloseAudioController(controller.get()); | 196 CloseAudioController(controller.get()); |
| 187 } | 197 } |
| 188 | 198 |
| 189 // Test that AudioInputController rejects insanely large packet sizes. | 199 // Test that AudioInputController rejects insanely large packet sizes. |
| 190 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) { | 200 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) { |
| 191 // Create an audio device with a very large packet size. | 201 // Create an audio device with a very large packet size. |
| 192 MockAudioInputControllerEventHandler event_handler; | 202 MockAudioInputControllerEventHandler event_handler; |
| 193 | 203 |
| 194 // OnCreated() shall not be called in this test. | 204 // OnCreated() shall not be called in this test. |
| 195 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 205 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
| 196 .Times(Exactly(0)); | 206 .Times(Exactly(0)); |
| 197 | 207 |
| 198 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 208 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
| 199 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 209 AudioParameters params(AudioParameters::AUDIO_FAKE, |
| 200 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); | 210 kChannelLayout, |
| 211 kSampleRate, |
| 212 kBitsPerSample, |
| 213 kSamplesPerPacket * 1000); |
| 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 NULL); |
| 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, |
| 220 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 236 kChannelLayout, |
| 237 kSampleRate, |
| 238 kBitsPerSample, |
| 239 kSamplesPerPacket); |
| 221 scoped_refptr<AudioInputController> controller = | 240 scoped_refptr<AudioInputController> controller = |
| 222 AudioInputController::Create(audio_manager.get(), &event_handler, params, | 241 AudioInputController::Create(audio_manager.get(), |
| 223 AudioManagerBase::kDefaultDeviceId); | 242 &event_handler, |
| 243 params, |
| 244 AudioManagerBase::kDefaultDeviceId, |
| 245 NULL); |
| 224 ASSERT_TRUE(controller.get()); | 246 ASSERT_TRUE(controller.get()); |
| 225 | 247 |
| 226 controller->Record(); | 248 controller->Record(); |
| 227 | 249 |
| 228 controller->Close(base::MessageLoop::QuitClosure()); | 250 controller->Close(base::MessageLoop::QuitClosure()); |
| 229 base::MessageLoop::current()->Run(); | 251 base::MessageLoop::current()->Run(); |
| 230 | 252 |
| 231 controller->Close(base::MessageLoop::QuitClosure()); | 253 controller->Close(base::MessageLoop::QuitClosure()); |
| 232 base::MessageLoop::current()->Run(); | 254 base::MessageLoop::current()->Run(); |
| 233 } | 255 } |
| 234 | 256 |
| 235 } // namespace media | 257 } // namespace media |
| OLD | NEW |