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.h" | 7 #include "base/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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 83 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
84 kSampleRate, kBitsPerSample, kSamplesPerPacket); | 84 kSampleRate, kBitsPerSample, kSamplesPerPacket); |
85 scoped_refptr<AudioInputController> controller = | 85 scoped_refptr<AudioInputController> controller = |
86 AudioInputController::Create(audio_manager.get(), &event_handler, params); | 86 AudioInputController::Create(audio_manager.get(), &event_handler, params); |
87 ASSERT_TRUE(controller.get()); | 87 ASSERT_TRUE(controller.get()); |
88 | 88 |
89 // Wait for OnCreated() to fire. | 89 // Wait for OnCreated() to fire. |
90 message_loop_.Run(); | 90 message_loop_.Run(); |
91 | 91 |
92 // Close the AudioInputController synchronously. | 92 // Close the AudioInputController synchronously. |
93 CloseAudioController(controller); | 93 CloseAudioController(controller.get()); |
94 } | 94 } |
95 | 95 |
96 // Test a normal call sequence of create, record and close. | 96 // Test a normal call sequence of create, record and close. |
97 TEST_F(AudioInputControllerTest, RecordAndClose) { | 97 TEST_F(AudioInputControllerTest, RecordAndClose) { |
98 MockAudioInputControllerEventHandler event_handler; | 98 MockAudioInputControllerEventHandler event_handler; |
99 int count = 0; | 99 int count = 0; |
100 | 100 |
101 // OnCreated() will be called once. | 101 // OnCreated() will be called once. |
102 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 102 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
103 .Times(Exactly(1)); | 103 .Times(Exactly(1)); |
(...skipping 17 matching lines...) Expand all Loading... |
121 AudioInputController::Create(audio_manager.get(), &event_handler, params); | 121 AudioInputController::Create(audio_manager.get(), &event_handler, params); |
122 ASSERT_TRUE(controller.get()); | 122 ASSERT_TRUE(controller.get()); |
123 | 123 |
124 // Start recording and trigger one OnRecording() call. | 124 // Start recording and trigger one OnRecording() call. |
125 controller->Record(); | 125 controller->Record(); |
126 | 126 |
127 // Record and wait until ten OnData() callbacks are received. | 127 // Record and wait until ten OnData() callbacks are received. |
128 message_loop_.Run(); | 128 message_loop_.Run(); |
129 | 129 |
130 // Close the AudioInputController synchronously. | 130 // Close the AudioInputController synchronously. |
131 CloseAudioController(controller); | 131 CloseAudioController(controller.get()); |
132 } | 132 } |
133 | 133 |
134 // Test that the AudioInputController reports an error when the input stream | 134 // Test that the AudioInputController reports an error when the input stream |
135 // stops without an OnClose() callback. This can happen when the underlying | 135 // stops without an OnClose() callback. This can happen when the underlying |
136 // audio layer stops feeding data as a result of a removed microphone device. | 136 // audio layer stops feeding data as a result of a removed microphone device. |
137 TEST_F(AudioInputControllerTest, RecordAndError) { | 137 TEST_F(AudioInputControllerTest, RecordAndError) { |
138 MockAudioInputControllerEventHandler event_handler; | 138 MockAudioInputControllerEventHandler event_handler; |
139 int count = 0; | 139 int count = 0; |
140 | 140 |
141 // OnCreated() will be called once. | 141 // OnCreated() will be called once. |
(...skipping 30 matching lines...) Expand all Loading... |
172 | 172 |
173 // Record and wait until ten OnData() callbacks are received. | 173 // Record and wait until ten OnData() callbacks are received. |
174 message_loop_.Run(); | 174 message_loop_.Run(); |
175 | 175 |
176 // Stop the stream and verify that OnError() is posted. | 176 // Stop the stream and verify that OnError() is posted. |
177 AudioInputStream* stream = controller->stream_for_testing(); | 177 AudioInputStream* stream = controller->stream_for_testing(); |
178 stream->Stop(); | 178 stream->Stop(); |
179 message_loop_.Run(); | 179 message_loop_.Run(); |
180 | 180 |
181 // Close the AudioInputController synchronously. | 181 // Close the AudioInputController synchronously. |
182 CloseAudioController(controller); | 182 CloseAudioController(controller.get()); |
183 } | 183 } |
184 | 184 |
185 // Test that AudioInputController rejects insanely large packet sizes. | 185 // Test that AudioInputController rejects insanely large packet sizes. |
186 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) { | 186 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) { |
187 // Create an audio device with a very large packet size. | 187 // Create an audio device with a very large packet size. |
188 MockAudioInputControllerEventHandler event_handler; | 188 MockAudioInputControllerEventHandler event_handler; |
189 | 189 |
190 // OnCreated() shall not be called in this test. | 190 // OnCreated() shall not be called in this test. |
191 EXPECT_CALL(event_handler, OnCreated(NotNull())) | 191 EXPECT_CALL(event_handler, OnCreated(NotNull())) |
192 .Times(Exactly(0)); | 192 .Times(Exactly(0)); |
193 | 193 |
194 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); | 194 scoped_ptr<AudioManager> audio_manager(AudioManager::Create()); |
195 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, | 195 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, |
196 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); | 196 kSampleRate, kBitsPerSample, kSamplesPerPacket * 1000); |
197 scoped_refptr<AudioInputController> controller = | 197 scoped_refptr<AudioInputController> controller = |
198 AudioInputController::Create(audio_manager.get(), &event_handler, params); | 198 AudioInputController::Create(audio_manager.get(), &event_handler, params); |
199 ASSERT_FALSE(controller); | 199 ASSERT_FALSE(controller.get()); |
200 } | 200 } |
201 | 201 |
202 // Test calling AudioInputController::Close multiple times. | 202 // Test calling AudioInputController::Close multiple times. |
203 TEST_F(AudioInputControllerTest, CloseTwice) { | 203 TEST_F(AudioInputControllerTest, CloseTwice) { |
204 MockAudioInputControllerEventHandler event_handler; | 204 MockAudioInputControllerEventHandler event_handler; |
205 | 205 |
206 // OnRecording() will be called only once. | 206 // OnRecording() will be called only once. |
207 EXPECT_CALL(event_handler, OnCreated(NotNull())); | 207 EXPECT_CALL(event_handler, OnCreated(NotNull())); |
208 | 208 |
209 // OnRecording() will be called only once. | 209 // OnRecording() will be called only once. |
(...skipping 10 matching lines...) Expand all Loading... |
220 controller->Record(); | 220 controller->Record(); |
221 | 221 |
222 controller->Close(base::MessageLoop::QuitClosure()); | 222 controller->Close(base::MessageLoop::QuitClosure()); |
223 base::MessageLoop::current()->Run(); | 223 base::MessageLoop::current()->Run(); |
224 | 224 |
225 controller->Close(base::MessageLoop::QuitClosure()); | 225 controller->Close(base::MessageLoop::QuitClosure()); |
226 base::MessageLoop::current()->Run(); | 226 base::MessageLoop::current()->Run(); |
227 } | 227 } |
228 | 228 |
229 } // namespace media | 229 } // namespace media |
OLD | NEW |