Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(512)

Side by Side Diff: media/audio/audio_input_controller_unittest.cc

Issue 2702323002: Move AudioDebugFileWriter from content/ to media/. (Closed)
Patch Set: Code review, unit test fix and rebase. Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/bind.h" 5 #include "base/bind.h"
6 #include "base/macros.h" 6 #include "base/macros.h"
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "base/synchronization/waitable_event.h" 9 #include "base/synchronization/waitable_event.h"
10 #include "base/test/test_timeouts.h" 10 #include "base/test/test_timeouts.h"
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 126
127 MockAudioInputControllerEventHandler event_handler; 127 MockAudioInputControllerEventHandler event_handler;
128 MockSyncWriter sync_writer; 128 MockSyncWriter sync_writer;
129 scoped_refptr<AudioInputController> controller; 129 scoped_refptr<AudioInputController> controller;
130 130
131 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, 131 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
132 kSampleRate, kBitsPerSample, kSamplesPerPacket); 132 kSampleRate, kBitsPerSample, kSamplesPerPacket);
133 133
134 SuspendAudioThread(); 134 SuspendAudioThread();
135 controller = AudioInputController::Create( 135 controller = AudioInputController::Create(
136 audio_manager_.get(), &event_handler, &sync_writer, nullptr, nullptr, 136 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
137 params, AudioDeviceDescription::kDefaultDeviceId, false); 137 AudioDeviceDescription::kDefaultDeviceId, false, audio_task_runner());
138 ASSERT_TRUE(controller.get()); 138 ASSERT_TRUE(controller.get());
139 EXPECT_CALL(event_handler, OnCreated(controller.get())).Times(Exactly(1)); 139 EXPECT_CALL(event_handler, OnCreated(controller.get())).Times(Exactly(1));
140 EXPECT_CALL(event_handler, OnLog(controller.get(), _)); 140 EXPECT_CALL(event_handler, OnLog(controller.get(), _));
141 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1)); 141 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
142 ResumeAudioThread(); 142 ResumeAudioThread();
143 143
144 CloseAudioController(controller.get()); 144 CloseAudioController(controller.get());
145 145
146 audio_thread_.FlushForTesting(); 146 audio_thread_.FlushForTesting();
147 } 147 }
(...skipping 15 matching lines...) Expand all
163 CheckCountAndPostQuitTask(&count, 10, message_loop_.task_runner())); 163 CheckCountAndPostQuitTask(&count, 10, message_loop_.task_runner()));
164 164
165 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber()); 165 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber());
166 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1)); 166 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
167 167
168 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, 168 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
169 kSampleRate, kBitsPerSample, kSamplesPerPacket); 169 kSampleRate, kBitsPerSample, kSamplesPerPacket);
170 170
171 // Creating the AudioInputController should render an OnCreated() call. 171 // Creating the AudioInputController should render an OnCreated() call.
172 scoped_refptr<AudioInputController> controller = AudioInputController::Create( 172 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
173 audio_manager_.get(), &event_handler, &sync_writer, nullptr, nullptr, 173 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
174 params, AudioDeviceDescription::kDefaultDeviceId, false); 174 AudioDeviceDescription::kDefaultDeviceId, false, audio_task_runner());
175 ASSERT_TRUE(controller.get()); 175 ASSERT_TRUE(controller.get());
176 176
177 controller->Record(); 177 controller->Record();
178 178
179 // Record and wait until ten Write() callbacks are received. 179 // Record and wait until ten Write() callbacks are received.
180 base::RunLoop().Run(); 180 base::RunLoop().Run();
181 CloseAudioController(controller.get()); 181 CloseAudioController(controller.get());
182 } 182 }
183 183
184 // Test that AudioInputController rejects insanely large packet sizes. 184 // Test that AudioInputController rejects insanely large packet sizes.
185 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) { 185 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) {
186 // Create an audio device with a very large packet size. 186 // Create an audio device with a very large packet size.
187 MockAudioInputControllerEventHandler event_handler; 187 MockAudioInputControllerEventHandler event_handler;
188 MockSyncWriter sync_writer; 188 MockSyncWriter sync_writer;
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())).Times(Exactly(0)); 191 EXPECT_CALL(event_handler, OnCreated(NotNull())).Times(Exactly(0));
192 192
193 AudioParameters params(AudioParameters::AUDIO_FAKE, 193 AudioParameters params(AudioParameters::AUDIO_FAKE,
194 kChannelLayout, 194 kChannelLayout,
195 kSampleRate, 195 kSampleRate,
196 kBitsPerSample, 196 kBitsPerSample,
197 kSamplesPerPacket * 1000); 197 kSamplesPerPacket * 1000);
198 scoped_refptr<AudioInputController> controller = AudioInputController::Create( 198 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
199 audio_manager_.get(), &event_handler, &sync_writer, nullptr, nullptr, 199 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
200 params, AudioDeviceDescription::kDefaultDeviceId, false); 200 AudioDeviceDescription::kDefaultDeviceId, false, audio_task_runner());
201 ASSERT_FALSE(controller.get()); 201 ASSERT_FALSE(controller.get());
202 } 202 }
203 203
204 // Test calling AudioInputController::Close multiple times. 204 // Test calling AudioInputController::Close multiple times.
205 TEST_F(AudioInputControllerTest, CloseTwice) { 205 TEST_F(AudioInputControllerTest, CloseTwice) {
206 MockAudioInputControllerEventHandler event_handler; 206 MockAudioInputControllerEventHandler event_handler;
207 MockSyncWriter sync_writer; 207 MockSyncWriter sync_writer;
208 208
209 // OnCreated() will be called only once. 209 // OnCreated() will be called only once.
210 EXPECT_CALL(event_handler, OnCreated(NotNull())).Times(Exactly(1)); 210 EXPECT_CALL(event_handler, OnCreated(NotNull())).Times(Exactly(1));
211 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber()); 211 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber());
212 // This callback should still only be called once. 212 // This callback should still only be called once.
213 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1)); 213 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
214 214
215 AudioParameters params(AudioParameters::AUDIO_FAKE, 215 AudioParameters params(AudioParameters::AUDIO_FAKE,
216 kChannelLayout, 216 kChannelLayout,
217 kSampleRate, 217 kSampleRate,
218 kBitsPerSample, 218 kBitsPerSample,
219 kSamplesPerPacket); 219 kSamplesPerPacket);
220 scoped_refptr<AudioInputController> controller = AudioInputController::Create( 220 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
221 audio_manager_.get(), &event_handler, &sync_writer, nullptr, nullptr, 221 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
222 params, AudioDeviceDescription::kDefaultDeviceId, false); 222 AudioDeviceDescription::kDefaultDeviceId, false, audio_task_runner());
223 ASSERT_TRUE(controller.get()); 223 ASSERT_TRUE(controller.get());
224 224
225 controller->Record(); 225 controller->Record();
226 226
227 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); 227 controller->Close(base::MessageLoop::QuitWhenIdleClosure());
228 base::RunLoop().Run(); 228 base::RunLoop().Run();
229 229
230 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); 230 controller->Close(base::MessageLoop::QuitWhenIdleClosure());
231 base::RunLoop().Run(); 231 base::RunLoop().Run();
232 } 232 }
233 233
234 } // namespace media 234 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.cc ('k') | media/audio/test_audio_input_controller_factory.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698