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