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

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

Issue 2885173002: Make AudioDebugFileWriter create its own file worker thread. (Closed)
Patch Set: Remove useless include Created 3 years, 7 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
« no previous file with comments | « media/audio/audio_input_controller.cc ('k') | media/audio/audio_manager.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "media/audio/audio_input_controller.h" 5 #include "media/audio/audio_input_controller.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "base/memory/ptr_util.h" 8 #include "base/memory/ptr_util.h"
9 #include "base/message_loop/message_loop.h" 9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after
121 MockAudioInputControllerEventHandler event_handler; 121 MockAudioInputControllerEventHandler event_handler;
122 MockSyncWriter sync_writer; 122 MockSyncWriter sync_writer;
123 scoped_refptr<AudioInputController> controller; 123 scoped_refptr<AudioInputController> controller;
124 124
125 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, 125 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
126 kSampleRate, kBitsPerSample, kSamplesPerPacket); 126 kSampleRate, kBitsPerSample, kSamplesPerPacket);
127 127
128 SuspendAudioThread(); 128 SuspendAudioThread();
129 controller = AudioInputController::Create( 129 controller = AudioInputController::Create(
130 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params, 130 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
131 AudioDeviceDescription::kDefaultDeviceId, false, audio_task_runner()); 131 AudioDeviceDescription::kDefaultDeviceId, false);
132 ASSERT_TRUE(controller.get()); 132 ASSERT_TRUE(controller.get());
133 EXPECT_CALL(event_handler, OnCreated(controller.get())).Times(Exactly(1)); 133 EXPECT_CALL(event_handler, OnCreated(controller.get())).Times(Exactly(1));
134 EXPECT_CALL(event_handler, OnLog(controller.get(), _)); 134 EXPECT_CALL(event_handler, OnLog(controller.get(), _));
135 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1)); 135 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
136 ResumeAudioThread(); 136 ResumeAudioThread();
137 137
138 CloseAudioController(controller.get()); 138 CloseAudioController(controller.get());
139 } 139 }
140 140
141 // Test a normal call sequence of create, record and close. 141 // Test a normal call sequence of create, record and close.
(...skipping 14 matching lines...) Expand all
156 156
157 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber()); 157 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber());
158 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1)); 158 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
159 159
160 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout, 160 AudioParameters params(AudioParameters::AUDIO_FAKE, kChannelLayout,
161 kSampleRate, kBitsPerSample, kSamplesPerPacket); 161 kSampleRate, kBitsPerSample, kSamplesPerPacket);
162 162
163 // Creating the AudioInputController should render an OnCreated() call. 163 // Creating the AudioInputController should render an OnCreated() call.
164 scoped_refptr<AudioInputController> controller = AudioInputController::Create( 164 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
165 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params, 165 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
166 AudioDeviceDescription::kDefaultDeviceId, false, audio_task_runner()); 166 AudioDeviceDescription::kDefaultDeviceId, false);
167 ASSERT_TRUE(controller.get()); 167 ASSERT_TRUE(controller.get());
168 168
169 controller->Record(); 169 controller->Record();
170 170
171 // Record and wait until ten Write() callbacks are received. 171 // Record and wait until ten Write() callbacks are received.
172 base::RunLoop().Run(); 172 base::RunLoop().Run();
173 CloseAudioController(controller.get()); 173 CloseAudioController(controller.get());
174 } 174 }
175 175
176 // Test that AudioInputController rejects insanely large packet sizes. 176 // Test that AudioInputController rejects insanely large packet sizes.
177 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) { 177 TEST_F(AudioInputControllerTest, SamplesPerPacketTooLarge) {
178 // Create an audio device with a very large packet size. 178 // Create an audio device with a very large packet size.
179 MockAudioInputControllerEventHandler event_handler; 179 MockAudioInputControllerEventHandler event_handler;
180 MockSyncWriter sync_writer; 180 MockSyncWriter sync_writer;
181 181
182 // OnCreated() shall not be called in this test. 182 // OnCreated() shall not be called in this test.
183 EXPECT_CALL(event_handler, OnCreated(NotNull())).Times(Exactly(0)); 183 EXPECT_CALL(event_handler, OnCreated(NotNull())).Times(Exactly(0));
184 184
185 AudioParameters params(AudioParameters::AUDIO_FAKE, 185 AudioParameters params(AudioParameters::AUDIO_FAKE,
186 kChannelLayout, 186 kChannelLayout,
187 kSampleRate, 187 kSampleRate,
188 kBitsPerSample, 188 kBitsPerSample,
189 kSamplesPerPacket * 1000); 189 kSamplesPerPacket * 1000);
190 scoped_refptr<AudioInputController> controller = AudioInputController::Create( 190 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
191 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params, 191 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
192 AudioDeviceDescription::kDefaultDeviceId, false, audio_task_runner()); 192 AudioDeviceDescription::kDefaultDeviceId, false);
193 ASSERT_FALSE(controller.get()); 193 ASSERT_FALSE(controller.get());
194 } 194 }
195 195
196 // Test calling AudioInputController::Close multiple times. 196 // Test calling AudioInputController::Close multiple times.
197 TEST_F(AudioInputControllerTest, CloseTwice) { 197 TEST_F(AudioInputControllerTest, CloseTwice) {
198 MockAudioInputControllerEventHandler event_handler; 198 MockAudioInputControllerEventHandler event_handler;
199 MockSyncWriter sync_writer; 199 MockSyncWriter sync_writer;
200 200
201 // OnCreated() will be called only once. 201 // OnCreated() will be called only once.
202 EXPECT_CALL(event_handler, OnCreated(NotNull())).Times(Exactly(1)); 202 EXPECT_CALL(event_handler, OnCreated(NotNull())).Times(Exactly(1));
203 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber()); 203 EXPECT_CALL(event_handler, OnLog(_, _)).Times(AnyNumber());
204 // This callback should still only be called once. 204 // This callback should still only be called once.
205 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1)); 205 EXPECT_CALL(sync_writer, Close()).Times(Exactly(1));
206 206
207 AudioParameters params(AudioParameters::AUDIO_FAKE, 207 AudioParameters params(AudioParameters::AUDIO_FAKE,
208 kChannelLayout, 208 kChannelLayout,
209 kSampleRate, 209 kSampleRate,
210 kBitsPerSample, 210 kBitsPerSample,
211 kSamplesPerPacket); 211 kSamplesPerPacket);
212 scoped_refptr<AudioInputController> controller = AudioInputController::Create( 212 scoped_refptr<AudioInputController> controller = AudioInputController::Create(
213 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params, 213 audio_manager_.get(), &event_handler, &sync_writer, nullptr, params,
214 AudioDeviceDescription::kDefaultDeviceId, false, audio_task_runner()); 214 AudioDeviceDescription::kDefaultDeviceId, false);
215 ASSERT_TRUE(controller.get()); 215 ASSERT_TRUE(controller.get());
216 216
217 controller->Record(); 217 controller->Record();
218 218
219 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); 219 controller->Close(base::MessageLoop::QuitWhenIdleClosure());
220 base::RunLoop().Run(); 220 base::RunLoop().Run();
221 221
222 controller->Close(base::MessageLoop::QuitWhenIdleClosure()); 222 controller->Close(base::MessageLoop::QuitWhenIdleClosure());
223 base::RunLoop().Run(); 223 base::RunLoop().Run();
224 } 224 }
225 225
226 } // namespace media 226 } // namespace media
OLDNEW
« no previous file with comments | « media/audio/audio_input_controller.cc ('k') | media/audio/audio_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698