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

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

Issue 8818012: Remove the AudioManager singleton. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Address comments from Avi Created 9 years 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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/environment.h" 6 #include "base/environment.h"
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/logging.h" 8 #include "base/logging.h"
9 #include "base/task.h" 9 #include "base/task.h"
10 #include "base/synchronization/waitable_event.h" 10 #include "base/synchronization/waitable_event.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
54 54
55 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes)); 55 MOCK_METHOD1(UpdatePendingBytes, void(uint32 bytes));
56 MOCK_METHOD2(Read, uint32(void* data, uint32 size)); 56 MOCK_METHOD2(Read, uint32(void* data, uint32 size));
57 MOCK_METHOD0(Close, void()); 57 MOCK_METHOD0(Close, void());
58 MOCK_METHOD0(DataReady, bool()); 58 MOCK_METHOD0(DataReady, bool());
59 59
60 private: 60 private:
61 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader); 61 DISALLOW_COPY_AND_ASSIGN(MockAudioOutputControllerSyncReader);
62 }; 62 };
63 63
64 static bool HasAudioOutputDevices() {
65 AudioManager* audio_man = AudioManager::GetAudioManager();
66 CHECK(audio_man);
67 return audio_man->HasAudioOutputDevices();
68 }
69
70 static bool IsRunningHeadless() { 64 static bool IsRunningHeadless() {
71 scoped_ptr<base::Environment> env(base::Environment::Create()); 65 scoped_ptr<base::Environment> env(base::Environment::Create());
72 if (env->HasVar("CHROME_HEADLESS")) 66 if (env->HasVar("CHROME_HEADLESS"))
73 return true; 67 return true;
74 return false; 68 return false;
75 } 69 }
76 70
77 ACTION_P(SignalEvent, event) { 71 ACTION_P(SignalEvent, event) {
78 event->Signal(); 72 event->Signal();
79 } 73 }
80 74
81 // Helper functions used to close audio controller. 75 // Helper functions used to close audio controller.
82 static void SignalClosedEvent(base::WaitableEvent* event) { 76 static void SignalClosedEvent(base::WaitableEvent* event) {
83 event->Signal(); 77 event->Signal();
84 } 78 }
85 79
86 // Closes AudioOutputController synchronously. 80 // Closes AudioOutputController synchronously.
87 static void CloseAudioController(AudioOutputController* controller) { 81 static void CloseAudioController(AudioOutputController* controller) {
88 base::WaitableEvent closed_event(true, false); 82 base::WaitableEvent closed_event(true, false);
89 controller->Close(base::Bind(&SignalClosedEvent, &closed_event)); 83 controller->Close(base::Bind(&SignalClosedEvent, &closed_event));
90 closed_event.Wait(); 84 closed_event.Wait();
91 } 85 }
92 86
93 TEST(AudioOutputControllerTest, CreateAndClose) { 87 TEST(AudioOutputControllerTest, CreateAndClose) {
94 if (!HasAudioOutputDevices() || IsRunningHeadless()) 88 if (IsRunningHeadless())
89 return;
90
91 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
92 if (!audio_manager->HasAudioOutputDevices())
95 return; 93 return;
96 94
97 MockAudioOutputControllerEventHandler event_handler; 95 MockAudioOutputControllerEventHandler event_handler;
98 96
99 EXPECT_CALL(event_handler, OnCreated(NotNull())) 97 EXPECT_CALL(event_handler, OnCreated(NotNull()))
100 .Times(1); 98 .Times(1);
101 EXPECT_CALL(event_handler, OnMoreData(NotNull(), _)); 99 EXPECT_CALL(event_handler, OnMoreData(NotNull(), _));
102 100
103 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 101 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
104 kSampleRate, kBitsPerSample, kSamplesPerPacket); 102 kSampleRate, kBitsPerSample, kSamplesPerPacket);
105 scoped_refptr<AudioOutputController> controller = 103 scoped_refptr<AudioOutputController> controller =
106 AudioOutputController::Create(&event_handler, params, kBufferCapacity); 104 AudioOutputController::Create(audio_manager.get(), &event_handler, params,
henrika (OOO until Aug 14) 2011/12/07 10:08:34 So much nicer to inject the manager here. All magi
105 kBufferCapacity);
107 ASSERT_TRUE(controller.get()); 106 ASSERT_TRUE(controller.get());
108 107
109 // Close the controller immediately. 108 // Close the controller immediately.
110 CloseAudioController(controller); 109 CloseAudioController(controller);
111 } 110 }
112 111
113 TEST(AudioOutputControllerTest, PlayAndClose) { 112 TEST(AudioOutputControllerTest, PlayAndClose) {
114 if (!HasAudioOutputDevices() || IsRunningHeadless()) 113 if (IsRunningHeadless())
114 return;
115
116 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
117 if (!audio_manager->HasAudioOutputDevices())
115 return; 118 return;
116 119
117 MockAudioOutputControllerEventHandler event_handler; 120 MockAudioOutputControllerEventHandler event_handler;
118 base::WaitableEvent event(false, false); 121 base::WaitableEvent event(false, false);
119 122
120 // If OnCreated is called then signal the event. 123 // If OnCreated is called then signal the event.
121 EXPECT_CALL(event_handler, OnCreated(NotNull())) 124 EXPECT_CALL(event_handler, OnCreated(NotNull()))
122 .WillOnce(SignalEvent(&event)); 125 .WillOnce(SignalEvent(&event));
123 126
124 // OnPlaying() will be called only once. 127 // OnPlaying() will be called only once.
125 EXPECT_CALL(event_handler, OnPlaying(NotNull())) 128 EXPECT_CALL(event_handler, OnPlaying(NotNull()))
126 .Times(Exactly(1)); 129 .Times(Exactly(1));
127 130
128 // If OnMoreData is called enough then signal the event. 131 // If OnMoreData is called enough then signal the event.
129 EXPECT_CALL(event_handler, OnMoreData(NotNull(), _)) 132 EXPECT_CALL(event_handler, OnMoreData(NotNull(), _))
130 .Times(AtLeast(10)) 133 .Times(AtLeast(10))
131 .WillRepeatedly(SignalEvent(&event)); 134 .WillRepeatedly(SignalEvent(&event));
132 135
133 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 136 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
134 kSampleRate, kBitsPerSample, kSamplesPerPacket); 137 kSampleRate, kBitsPerSample, kSamplesPerPacket);
135 scoped_refptr<AudioOutputController> controller = 138 scoped_refptr<AudioOutputController> controller =
136 AudioOutputController::Create(&event_handler, params, kBufferCapacity); 139 AudioOutputController::Create(audio_manager.get(), &event_handler, params,
140 kBufferCapacity);
137 ASSERT_TRUE(controller.get()); 141 ASSERT_TRUE(controller.get());
138 142
139 // Wait for OnCreated() to be called. 143 // Wait for OnCreated() to be called.
140 event.Wait(); 144 event.Wait();
141 145
142 controller->Play(); 146 controller->Play();
143 147
144 // Wait until the date is requested at least 10 times. 148 // Wait until the date is requested at least 10 times.
145 for (int i = 0; i < 10; i++) { 149 for (int i = 0; i < 10; i++) {
146 event.Wait(); 150 event.Wait();
147 uint8 buf[1]; 151 uint8 buf[1];
148 controller->EnqueueData(buf, 0); 152 controller->EnqueueData(buf, 0);
149 } 153 }
150 154
151 // Now stop the controller. 155 // Now stop the controller.
152 CloseAudioController(controller); 156 CloseAudioController(controller);
153 } 157 }
154 158
155 TEST(AudioOutputControllerTest, PlayAndCloseLowLatency) { 159 TEST(AudioOutputControllerTest, PlayAndCloseLowLatency) {
156 if (!HasAudioOutputDevices() || IsRunningHeadless()) 160 if (IsRunningHeadless())
161 return;
162
163 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
164 if (!audio_manager->HasAudioOutputDevices())
157 return; 165 return;
158 166
159 MockAudioOutputControllerEventHandler event_handler; 167 MockAudioOutputControllerEventHandler event_handler;
160 base::WaitableEvent event(false, false); 168 base::WaitableEvent event(false, false);
161 169
162 // If OnCreated is called then signal the event. 170 // If OnCreated is called then signal the event.
163 EXPECT_CALL(event_handler, OnCreated(NotNull())) 171 EXPECT_CALL(event_handler, OnCreated(NotNull()))
164 .WillOnce(SignalEvent(&event)); 172 .WillOnce(SignalEvent(&event));
165 173
166 // OnPlaying() will be called only once. 174 // OnPlaying() will be called only once.
167 EXPECT_CALL(event_handler, OnPlaying(NotNull())) 175 EXPECT_CALL(event_handler, OnPlaying(NotNull()))
168 .Times(Exactly(1)); 176 .Times(Exactly(1));
169 177
170 MockAudioOutputControllerSyncReader sync_reader; 178 MockAudioOutputControllerSyncReader sync_reader;
171 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) 179 EXPECT_CALL(sync_reader, UpdatePendingBytes(_))
172 .Times(AtLeast(10)); 180 .Times(AtLeast(10));
173 EXPECT_CALL(sync_reader, DataReady()) 181 EXPECT_CALL(sync_reader, DataReady())
174 .WillOnce(Return(false)) 182 .WillOnce(Return(false))
175 .WillOnce(Return(false)) 183 .WillOnce(Return(false))
176 .WillRepeatedly(Return(true)); 184 .WillRepeatedly(Return(true));
177 EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize)) 185 EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize))
178 .Times(AtLeast(10)) 186 .Times(AtLeast(10))
179 .WillRepeatedly(DoAll(SignalEvent(&event), 187 .WillRepeatedly(DoAll(SignalEvent(&event),
180 Return(4))); 188 Return(4)));
181 EXPECT_CALL(sync_reader, Close()); 189 EXPECT_CALL(sync_reader, Close());
182 190
183 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 191 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
184 kSampleRate, kBitsPerSample, kSamplesPerPacket); 192 kSampleRate, kBitsPerSample, kSamplesPerPacket);
185 scoped_refptr<AudioOutputController> controller = 193 scoped_refptr<AudioOutputController> controller =
186 AudioOutputController::CreateLowLatency(&event_handler, 194 AudioOutputController::CreateLowLatency(audio_manager.get(),
195 &event_handler,
187 params, 196 params,
188 &sync_reader); 197 &sync_reader);
189 ASSERT_TRUE(controller.get()); 198 ASSERT_TRUE(controller.get());
190 199
191 // Wait for OnCreated() to be called. 200 // Wait for OnCreated() to be called.
192 event.Wait(); 201 event.Wait();
193 202
194 controller->Play(); 203 controller->Play();
195 204
196 // Wait until the date is requested at least 10 times. 205 // Wait until the date is requested at least 10 times.
197 for (int i = 0; i < 10; i++) { 206 for (int i = 0; i < 10; i++) {
198 event.Wait(); 207 event.Wait();
199 uint8 buf[1]; 208 uint8 buf[1];
200 controller->EnqueueData(buf, 0); 209 controller->EnqueueData(buf, 0);
201 } 210 }
202 211
203 // Now stop the controller. 212 // Now stop the controller.
204 CloseAudioController(controller); 213 CloseAudioController(controller);
205 } 214 }
206 215
207 TEST(AudioOutputControllerTest, PlayPauseClose) { 216 TEST(AudioOutputControllerTest, PlayPauseClose) {
208 if (!HasAudioOutputDevices() || IsRunningHeadless()) 217 if (IsRunningHeadless())
218 return;
219
220 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
221 if (!audio_manager->HasAudioOutputDevices())
209 return; 222 return;
210 223
211 MockAudioOutputControllerEventHandler event_handler; 224 MockAudioOutputControllerEventHandler event_handler;
212 base::WaitableEvent event(false, false); 225 base::WaitableEvent event(false, false);
213 base::WaitableEvent pause_event(false, false); 226 base::WaitableEvent pause_event(false, false);
214 227
215 // If OnCreated is called then signal the event. 228 // If OnCreated is called then signal the event.
216 EXPECT_CALL(event_handler, OnCreated(NotNull())) 229 EXPECT_CALL(event_handler, OnCreated(NotNull()))
217 .Times(Exactly(1)) 230 .Times(Exactly(1))
218 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 231 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
219 232
220 // OnPlaying() will be called only once. 233 // OnPlaying() will be called only once.
221 EXPECT_CALL(event_handler, OnPlaying(NotNull())) 234 EXPECT_CALL(event_handler, OnPlaying(NotNull()))
222 .Times(Exactly(1)); 235 .Times(Exactly(1));
223 236
224 // If OnMoreData is called enough then signal the event. 237 // If OnMoreData is called enough then signal the event.
225 EXPECT_CALL(event_handler, OnMoreData(NotNull(), _)) 238 EXPECT_CALL(event_handler, OnMoreData(NotNull(), _))
226 .Times(AtLeast(10)) 239 .Times(AtLeast(10))
227 .WillRepeatedly(SignalEvent(&event)); 240 .WillRepeatedly(SignalEvent(&event));
228 241
229 // And then OnPaused() will be called. 242 // And then OnPaused() will be called.
230 EXPECT_CALL(event_handler, OnPaused(NotNull())) 243 EXPECT_CALL(event_handler, OnPaused(NotNull()))
231 .Times(Exactly(1)) 244 .Times(Exactly(1))
232 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal)); 245 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal));
233 246
234 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 247 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
235 kSampleRate, kBitsPerSample, kSamplesPerPacket); 248 kSampleRate, kBitsPerSample, kSamplesPerPacket);
236 scoped_refptr<AudioOutputController> controller = 249 scoped_refptr<AudioOutputController> controller =
237 AudioOutputController::Create(&event_handler, params, kBufferCapacity); 250 AudioOutputController::Create(audio_manager.get(), &event_handler, params,
251 kBufferCapacity);
238 ASSERT_TRUE(controller.get()); 252 ASSERT_TRUE(controller.get());
239 253
240 // Wait for OnCreated() to be called. 254 // Wait for OnCreated() to be called.
241 event.Wait(); 255 event.Wait();
242 256
243 controller->Play(); 257 controller->Play();
244 258
245 // Wait until the date is requested at least 10 times. 259 // Wait until the date is requested at least 10 times.
246 for (int i = 0; i < 10; i++) { 260 for (int i = 0; i < 10; i++) {
247 event.Wait(); 261 event.Wait();
248 uint8 buf[1]; 262 uint8 buf[1];
249 controller->EnqueueData(buf, 0); 263 controller->EnqueueData(buf, 0);
250 } 264 }
251 265
252 // And then wait for pause to complete. 266 // And then wait for pause to complete.
253 ASSERT_FALSE(pause_event.IsSignaled()); 267 ASSERT_FALSE(pause_event.IsSignaled());
254 controller->Pause(); 268 controller->Pause();
255 pause_event.Wait(); 269 pause_event.Wait();
256 270
257 // Now stop the controller. 271 // Now stop the controller.
258 CloseAudioController(controller); 272 CloseAudioController(controller);
259 } 273 }
260 274
261 TEST(AudioOutputControllerTest, PlayPauseCloseLowLatency) { 275 TEST(AudioOutputControllerTest, PlayPauseCloseLowLatency) {
262 if (!HasAudioOutputDevices() || IsRunningHeadless()) 276 if (IsRunningHeadless())
277 return;
278
279 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
280 if (!audio_manager->HasAudioOutputDevices())
263 return; 281 return;
264 282
265 MockAudioOutputControllerEventHandler event_handler; 283 MockAudioOutputControllerEventHandler event_handler;
266 base::WaitableEvent event(false, false); 284 base::WaitableEvent event(false, false);
267 base::WaitableEvent pause_event(false, false); 285 base::WaitableEvent pause_event(false, false);
268 286
269 // If OnCreated is called then signal the event. 287 // If OnCreated is called then signal the event.
270 EXPECT_CALL(event_handler, OnCreated(NotNull())) 288 EXPECT_CALL(event_handler, OnCreated(NotNull()))
271 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 289 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
272 290
273 // OnPlaying() will be called only once. 291 // OnPlaying() will be called only once.
274 EXPECT_CALL(event_handler, OnPlaying(NotNull())); 292 EXPECT_CALL(event_handler, OnPlaying(NotNull()));
275 293
276 MockAudioOutputControllerSyncReader sync_reader; 294 MockAudioOutputControllerSyncReader sync_reader;
277 EXPECT_CALL(sync_reader, UpdatePendingBytes(_)) 295 EXPECT_CALL(sync_reader, UpdatePendingBytes(_))
278 .Times(AtLeast(2)); 296 .Times(AtLeast(2));
279 EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize)) 297 EXPECT_CALL(sync_reader, Read(_, kHardwareBufferSize))
280 .WillRepeatedly(DoAll(SignalEvent(&event), 298 .WillRepeatedly(DoAll(SignalEvent(&event),
281 Return(4))); 299 Return(4)));
282 EXPECT_CALL(event_handler, OnPaused(NotNull())) 300 EXPECT_CALL(event_handler, OnPaused(NotNull()))
283 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal)); 301 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal));
284 EXPECT_CALL(sync_reader, Close()); 302 EXPECT_CALL(sync_reader, Close());
285 303
286 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 304 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
287 kSampleRate, kBitsPerSample, kSamplesPerPacket); 305 kSampleRate, kBitsPerSample, kSamplesPerPacket);
288 scoped_refptr<AudioOutputController> controller = 306 scoped_refptr<AudioOutputController> controller =
289 AudioOutputController::CreateLowLatency(&event_handler, 307 AudioOutputController::CreateLowLatency(audio_manager.get(),
308 &event_handler,
290 params, 309 params,
291 &sync_reader); 310 &sync_reader);
292 ASSERT_TRUE(controller.get()); 311 ASSERT_TRUE(controller.get());
293 312
294 // Wait for OnCreated() to be called. 313 // Wait for OnCreated() to be called.
295 event.Wait(); 314 event.Wait();
296 315
297 ASSERT_FALSE(pause_event.IsSignaled()); 316 ASSERT_FALSE(pause_event.IsSignaled());
298 controller->Play(); 317 controller->Play();
299 controller->Pause(); 318 controller->Pause();
300 pause_event.Wait(); 319 pause_event.Wait();
301 320
302 // Now stop the controller. 321 // Now stop the controller.
303 CloseAudioController(controller); 322 CloseAudioController(controller);
304 } 323 }
305 324
306 TEST(AudioOutputControllerTest, PlayPausePlay) { 325 TEST(AudioOutputControllerTest, PlayPausePlay) {
307 if (!HasAudioOutputDevices() || IsRunningHeadless()) 326 if (IsRunningHeadless())
327 return;
328
329 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
330 if (!audio_manager->HasAudioOutputDevices())
308 return; 331 return;
309 332
310 MockAudioOutputControllerEventHandler event_handler; 333 MockAudioOutputControllerEventHandler event_handler;
311 base::WaitableEvent event(false, false); 334 base::WaitableEvent event(false, false);
312 base::WaitableEvent pause_event(false, false); 335 base::WaitableEvent pause_event(false, false);
313 336
314 // If OnCreated is called then signal the event. 337 // If OnCreated is called then signal the event.
315 EXPECT_CALL(event_handler, OnCreated(NotNull())) 338 EXPECT_CALL(event_handler, OnCreated(NotNull()))
316 .Times(Exactly(1)) 339 .Times(Exactly(1))
317 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal)); 340 .WillOnce(InvokeWithoutArgs(&event, &base::WaitableEvent::Signal));
(...skipping 14 matching lines...) Expand all
332 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal)); 355 .WillOnce(InvokeWithoutArgs(&pause_event, &base::WaitableEvent::Signal));
333 356
334 // OnPlaying() will be called only once. 357 // OnPlaying() will be called only once.
335 EXPECT_CALL(event_handler, OnPlaying(NotNull())) 358 EXPECT_CALL(event_handler, OnPlaying(NotNull()))
336 .Times(Exactly(1)) 359 .Times(Exactly(1))
337 .RetiresOnSaturation(); 360 .RetiresOnSaturation();
338 361
339 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 362 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
340 kSampleRate, kBitsPerSample, kSamplesPerPacket); 363 kSampleRate, kBitsPerSample, kSamplesPerPacket);
341 scoped_refptr<AudioOutputController> controller = 364 scoped_refptr<AudioOutputController> controller =
342 AudioOutputController::Create(&event_handler, params, kBufferCapacity); 365 AudioOutputController::Create(audio_manager.get(), &event_handler, params,
366 kBufferCapacity);
343 ASSERT_TRUE(controller.get()); 367 ASSERT_TRUE(controller.get());
344 368
345 // Wait for OnCreated() to be called. 369 // Wait for OnCreated() to be called.
346 event.Wait(); 370 event.Wait();
347 371
348 controller->Play(); 372 controller->Play();
349 373
350 // Wait until the date is requested at least 10 times. 374 // Wait until the date is requested at least 10 times.
351 for (int i = 0; i < 10; i++) { 375 for (int i = 0; i < 10; i++) {
352 event.Wait(); 376 event.Wait();
(...skipping 14 matching lines...) Expand all
367 event.Wait(); 391 event.Wait();
368 uint8 buf[1]; 392 uint8 buf[1];
369 controller->EnqueueData(buf, 0); 393 controller->EnqueueData(buf, 0);
370 } 394 }
371 395
372 // Now stop the controller. 396 // Now stop the controller.
373 CloseAudioController(controller); 397 CloseAudioController(controller);
374 } 398 }
375 399
376 TEST(AudioOutputControllerTest, HardwareBufferTooLarge) { 400 TEST(AudioOutputControllerTest, HardwareBufferTooLarge) {
377 if (!HasAudioOutputDevices() || IsRunningHeadless()) 401 if (IsRunningHeadless())
402 return;
403
404 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
405 if (!audio_manager->HasAudioOutputDevices())
378 return; 406 return;
379 407
380 // Create an audio device with a very large hardware buffer size. 408 // Create an audio device with a very large hardware buffer size.
381 MockAudioOutputControllerEventHandler event_handler; 409 MockAudioOutputControllerEventHandler event_handler;
382 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 410 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
383 kSampleRate, kBitsPerSample, 411 kSampleRate, kBitsPerSample,
384 kSamplesPerPacket * 1000); 412 kSamplesPerPacket * 1000);
385 scoped_refptr<AudioOutputController> controller = 413 scoped_refptr<AudioOutputController> controller =
386 AudioOutputController::Create(&event_handler, params, 414 AudioOutputController::Create(audio_manager.get(), &event_handler, params,
387 kBufferCapacity); 415 kBufferCapacity);
388 416
389 // Use assert because we don't stop the device and assume we can't 417 // Use assert because we don't stop the device and assume we can't
390 // create one. 418 // create one.
391 ASSERT_FALSE(controller); 419 ASSERT_FALSE(controller);
392 } 420 }
393 421
394 TEST(AudioOutputControllerTest, CloseTwice) { 422 TEST(AudioOutputControllerTest, CloseTwice) {
395 if (!HasAudioOutputDevices() || IsRunningHeadless()) 423 if (IsRunningHeadless())
424 return;
425
426 scoped_refptr<AudioManager> audio_manager(AudioManager::Create());
427 if (!audio_manager->HasAudioOutputDevices())
396 return; 428 return;
397 429
398 MockAudioOutputControllerEventHandler event_handler; 430 MockAudioOutputControllerEventHandler event_handler;
399 base::WaitableEvent event(false, false); 431 base::WaitableEvent event(false, false);
400 432
401 // If OnCreated is called then signal the event. 433 // If OnCreated is called then signal the event.
402 EXPECT_CALL(event_handler, OnCreated(NotNull())) 434 EXPECT_CALL(event_handler, OnCreated(NotNull()))
403 .WillOnce(SignalEvent(&event)); 435 .WillOnce(SignalEvent(&event));
404 436
405 // One OnMoreData() is expected. 437 // One OnMoreData() is expected.
406 EXPECT_CALL(event_handler, OnMoreData(NotNull(), _)) 438 EXPECT_CALL(event_handler, OnMoreData(NotNull(), _))
407 .Times(AtLeast(1)) 439 .Times(AtLeast(1))
408 .WillRepeatedly(SignalEvent(&event)); 440 .WillRepeatedly(SignalEvent(&event));
409 441
410 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout, 442 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, kChannelLayout,
411 kSampleRate, kBitsPerSample, kSamplesPerPacket); 443 kSampleRate, kBitsPerSample, kSamplesPerPacket);
412 scoped_refptr<AudioOutputController> controller = 444 scoped_refptr<AudioOutputController> controller =
413 AudioOutputController::Create(&event_handler, params, kBufferCapacity); 445 AudioOutputController::Create(audio_manager.get(), &event_handler, params,
446 kBufferCapacity);
414 ASSERT_TRUE(controller.get()); 447 ASSERT_TRUE(controller.get());
415 448
416 // Wait for OnCreated() to be called. 449 // Wait for OnCreated() to be called.
417 event.Wait(); 450 event.Wait();
418 451
419 // Wait for OnMoreData() to be called. 452 // Wait for OnMoreData() to be called.
420 event.Wait(); 453 event.Wait();
421 454
422 base::WaitableEvent closed_event_1(true, false); 455 base::WaitableEvent closed_event_1(true, false);
423 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_1)); 456 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_1));
424 457
425 base::WaitableEvent closed_event_2(true, false); 458 base::WaitableEvent closed_event_2(true, false);
426 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_2)); 459 controller->Close(base::Bind(&SignalClosedEvent, &closed_event_2));
427 460
428 closed_event_1.Wait(); 461 closed_event_1.Wait();
429 closed_event_2.Wait(); 462 closed_event_2.Wait();
430 } 463 }
431 464
432 } // namespace media 465 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698