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

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

Issue 10918098: Introduce AudioOutputResampler for browser side resampling. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Unittests! Bugs! Created 8 years, 3 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 <string> 5 #include <string>
6 6
7 #include "base/message_loop.h" 7 #include "base/message_loop.h"
8 #include "base/message_loop_proxy.h" 8 #include "base/message_loop_proxy.h"
9 #include "base/threading/platform_thread.h" 9 #include "base/threading/platform_thread.h"
10 #include "media/audio/audio_output_dispatcher_impl.h" 10 #include "media/audio/audio_output_dispatcher_impl.h"
11 #include "media/audio/audio_output_proxy.h" 11 #include "media/audio/audio_output_proxy.h"
12 #include "media/audio/audio_output_resampler.h"
12 #include "media/audio/audio_manager.h" 13 #include "media/audio/audio_manager.h"
13 #include "testing/gmock/include/gmock/gmock.h" 14 #include "testing/gmock/include/gmock/gmock.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 16
16 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float, 17 // TODO(dalecurtis): Temporarily disabled while switching pipeline to use float,
17 // http://crbug.com/114700 18 // http://crbug.com/114700
18 #if defined(ENABLE_AUDIO_MIXER) 19 #if defined(ENABLE_AUDIO_MIXER)
19 #include "media/audio/audio_output_mixer.h" 20 #include "media/audio/audio_output_mixer.h"
20 #endif 21 #endif
21 22
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after
108 void InitDispatcher(base::TimeDelta close_delay) { 109 void InitDispatcher(base::TimeDelta close_delay) {
109 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR, 110 AudioParameters params(AudioParameters::AUDIO_PCM_LINEAR,
110 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024); 111 CHANNEL_LAYOUT_STEREO, 44100, 16, 1024);
111 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(), 112 dispatcher_impl_ = new AudioOutputDispatcherImpl(&manager(),
112 params, 113 params,
113 close_delay); 114 close_delay);
114 #if defined(ENABLE_AUDIO_MIXER) 115 #if defined(ENABLE_AUDIO_MIXER)
115 mixer_ = new AudioOutputMixer(&manager(), params, close_delay); 116 mixer_ = new AudioOutputMixer(&manager(), params, close_delay);
116 #endif 117 #endif
117 118
119 AudioParameters out_params(AudioParameters::AUDIO_PCM_LINEAR,
120 CHANNEL_LAYOUT_STEREO, 48000, 16, 128);
121 resampler_ = new AudioOutputResampler(
122 &manager(), params, out_params, close_delay);
123
118 // Necessary to know how long the dispatcher will wait before posting 124 // Necessary to know how long the dispatcher will wait before posting
119 // StopStreamTask. 125 // StopStreamTask.
120 pause_delay_ = dispatcher_impl_->pause_delay_; 126 pause_delay_ = dispatcher_impl_->pause_delay_;
121 } 127 }
122 128
123 MockAudioManager& manager() { 129 MockAudioManager& manager() {
124 return manager_; 130 return manager_;
125 } 131 }
126 132
127 // Wait for the close timer to fire. 133 // Wait for the close timer to fire.
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 .WillOnce(Return(false)); 245 .WillOnce(Return(false));
240 EXPECT_CALL(stream, Close()) 246 EXPECT_CALL(stream, Close())
241 .Times(1); 247 .Times(1);
242 248
243 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); 249 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
244 EXPECT_FALSE(proxy->Open()); 250 EXPECT_FALSE(proxy->Open());
245 proxy->Close(); 251 proxy->Close();
246 WaitForCloseTimer(kTestCloseDelayMs); 252 WaitForCloseTimer(kTestCloseDelayMs);
247 } 253 }
248 254
255 void CreateAndWait(AudioOutputDispatcher* dispatcher) {
256 MockAudioOutputStream stream;
257
258 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
259 .WillOnce(Return(&stream));
260 EXPECT_CALL(stream, Open())
261 .WillOnce(Return(true));
262 EXPECT_CALL(stream, Close())
263 .Times(1);
264
265 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher);
266 EXPECT_TRUE(proxy->Open());
267
268 // Simulate a delay.
269 base::PlatformThread::Sleep(
270 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
271 message_loop_.RunAllPending();
272
273 // Verify expectation before calling Close().
274 Mock::VerifyAndClear(&stream);
275
276 proxy->Close();
277 }
278
279 void TwoStreams_OnePlaying(AudioOutputDispatcher* dispatcher) {
280 MockAudioOutputStream stream1;
281 MockAudioOutputStream stream2;
282
283 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
284
285 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
286 .WillOnce(Return(&stream1))
287 .WillOnce(Return(&stream2));
288
289 EXPECT_CALL(stream1, Open())
290 .WillOnce(Return(true));
291 EXPECT_CALL(stream1, Start(_))
292 .Times(1);
293 EXPECT_CALL(stream1, SetVolume(_))
294 .Times(1);
295 EXPECT_CALL(stream1, Stop())
296 .Times(1);
297 EXPECT_CALL(stream1, Close())
298 .Times(1);
299
300 EXPECT_CALL(stream2, Open())
301 .WillOnce(Return(true));
302 EXPECT_CALL(stream2, Close())
303 .Times(1);
304
305 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher);
306 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher);
307 EXPECT_TRUE(proxy1->Open());
308 EXPECT_TRUE(proxy2->Open());
309
310 proxy1->Start(&callback_);
311 message_loop_.RunAllPending();
312 proxy1->Stop();
313
314 proxy1->Close();
315 proxy2->Close();
316 }
317
318 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) {
319 MockAudioOutputStream stream1;
320 MockAudioOutputStream stream2;
321
322 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
323
324 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
325 .WillOnce(Return(&stream1))
326 .WillOnce(Return(&stream2));
327
328 EXPECT_CALL(stream1, Open())
329 .WillOnce(Return(true));
330 EXPECT_CALL(stream1, Start(_))
331 .Times(1);
332 EXPECT_CALL(stream1, SetVolume(_))
333 .Times(1);
334 EXPECT_CALL(stream1, Stop())
335 .Times(1);
336 EXPECT_CALL(stream1, Close())
337 .Times(1);
338
339 EXPECT_CALL(stream2, Open())
340 .WillOnce(Return(true));
341 EXPECT_CALL(stream2, Start(_))
342 .Times(1);
343 EXPECT_CALL(stream2, SetVolume(_))
344 .Times(1);
345 EXPECT_CALL(stream2, Stop())
346 .Times(1);
347 EXPECT_CALL(stream2, Close())
348 .Times(1);
349
350 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher);
351 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher);
352 EXPECT_TRUE(proxy1->Open());
353 EXPECT_TRUE(proxy2->Open());
354
355 proxy1->Start(&callback_);
356 proxy2->Start(&callback_);
357 proxy1->Stop();
358 proxy2->Stop();
359
360 proxy1->Close();
361 proxy2->Close();
362 }
363
364 void StartFailed(AudioOutputDispatcher* dispatcher) {
365 MockAudioOutputStream stream;
366
367 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
368 .WillOnce(Return(&stream));
369 EXPECT_CALL(stream, Open())
370 .WillOnce(Return(true));
371 EXPECT_CALL(stream, Close())
372 .Times(1);
373
374 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
375 EXPECT_TRUE(proxy->Open());
376
377 // Simulate a delay.
378 base::PlatformThread::Sleep(
379 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
380 message_loop_.RunAllPending();
381
382 // Verify expectation before calling Close().
383 Mock::VerifyAndClear(&stream);
384
385 // |stream| is closed at this point. Start() should reopen it again.
386 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
387 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
388
389 EXPECT_CALL(callback_, OnError(_, _))
390 .Times(1);
391
392 proxy->Start(&callback_);
393
394 Mock::VerifyAndClear(&callback_);
395
396 proxy->Close();
397 }
398
249 MessageLoop message_loop_; 399 MessageLoop message_loop_;
250 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_; 400 scoped_refptr<AudioOutputDispatcherImpl> dispatcher_impl_;
251 #if defined(ENABLE_AUDIO_MIXER) 401 #if defined(ENABLE_AUDIO_MIXER)
252 scoped_refptr<AudioOutputMixer> mixer_; 402 scoped_refptr<AudioOutputMixer> mixer_;
253 #endif 403 #endif
404 scoped_refptr<AudioOutputResampler> resampler_;
254 base::TimeDelta pause_delay_; 405 base::TimeDelta pause_delay_;
255 MockAudioManager manager_; 406 MockAudioManager manager_;
256 MockAudioSourceCallback callback_; 407 MockAudioSourceCallback callback_;
257 }; 408 };
258 409
259 TEST_F(AudioOutputProxyTest, CreateAndClose) { 410 TEST_F(AudioOutputProxyTest, CreateAndClose) {
260 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_); 411 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
261 proxy->Close(); 412 proxy->Close();
262 } 413 }
263 414
264 #if defined(ENABLE_AUDIO_MIXER) 415 #if defined(ENABLE_AUDIO_MIXER)
265 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) { 416 TEST_F(AudioOutputProxyTest, CreateAndClose_Mixer) {
266 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_); 417 AudioOutputProxy* proxy = new AudioOutputProxy(mixer_);
267 proxy->Close(); 418 proxy->Close();
268 } 419 }
269 #endif 420 #endif
270 421
422 TEST_F(AudioOutputProxyTest, CreateAndClose_Resampler) {
423 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_);
424 proxy->Close();
425 }
426
271 TEST_F(AudioOutputProxyTest, OpenAndClose) { 427 TEST_F(AudioOutputProxyTest, OpenAndClose) {
272 OpenAndClose(dispatcher_impl_); 428 OpenAndClose(dispatcher_impl_);
273 } 429 }
274 430
275 #if defined(ENABLE_AUDIO_MIXER) 431 #if defined(ENABLE_AUDIO_MIXER)
276 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) { 432 TEST_F(AudioOutputProxyTest, OpenAndClose_Mixer) {
277 OpenAndClose(mixer_); 433 OpenAndClose(mixer_);
278 } 434 }
279 #endif 435 #endif
280 436
437 TEST_F(AudioOutputProxyTest, OpenAndClose_Resampler) {
438 OpenAndClose(resampler_);
439 }
440
281 // Create a stream, and verify that it is closed after kTestCloseDelayMs. 441 // Create a stream, and verify that it is closed after kTestCloseDelayMs.
282 // if it doesn't start playing. 442 // if it doesn't start playing.
283 TEST_F(AudioOutputProxyTest, CreateAndWait) { 443 TEST_F(AudioOutputProxyTest, CreateAndWait) {
284 MockAudioOutputStream stream; 444 CreateAndWait(dispatcher_impl_);
445 }
285 446
286 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 447 // Create a stream, and verify that it is closed after kTestCloseDelayMs.
287 .WillOnce(Return(&stream)); 448 // if it doesn't start playing.
288 EXPECT_CALL(stream, Open()) 449 TEST_F(AudioOutputProxyTest, CreateAndWait_Resampler) {
289 .WillOnce(Return(true)); 450 CreateAndWait(resampler_);
290 EXPECT_CALL(stream, Close())
291 .Times(1);
292
293 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
294 EXPECT_TRUE(proxy->Open());
295
296 // Simulate a delay.
297 base::PlatformThread::Sleep(
298 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
299 message_loop_.RunAllPending();
300
301 // Verify expectation before calling Close().
302 Mock::VerifyAndClear(&stream);
303
304 proxy->Close();
305 } 451 }
306 452
307 TEST_F(AudioOutputProxyTest, StartAndStop) { 453 TEST_F(AudioOutputProxyTest, StartAndStop) {
308 StartAndStop(dispatcher_impl_); 454 StartAndStop(dispatcher_impl_);
309 } 455 }
310 456
311 #if defined(ENABLE_AUDIO_MIXER) 457 #if defined(ENABLE_AUDIO_MIXER)
312 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) { 458 TEST_F(AudioOutputProxyTest, StartAndStop_Mixer) {
313 StartAndStop(mixer_); 459 StartAndStop(mixer_);
314 } 460 }
315 #endif 461 #endif
316 462
463 TEST_F(AudioOutputProxyTest, StartAndStop_Resampler) {
464 StartAndStop(resampler_);
465 }
466
317 TEST_F(AudioOutputProxyTest, CloseAfterStop) { 467 TEST_F(AudioOutputProxyTest, CloseAfterStop) {
318 CloseAfterStop(dispatcher_impl_); 468 CloseAfterStop(dispatcher_impl_);
319 } 469 }
320 470
321 #if defined(ENABLE_AUDIO_MIXER) 471 #if defined(ENABLE_AUDIO_MIXER)
322 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) { 472 TEST_F(AudioOutputProxyTest, CloseAfterStop_Mixer) {
323 CloseAfterStop(mixer_); 473 CloseAfterStop(mixer_);
324 } 474 }
325 #endif 475 #endif
326 476
477 TEST_F(AudioOutputProxyTest, CloseAfterStop_Resampler) {
478 CloseAfterStop(resampler_);
479 }
480
327 TEST_F(AudioOutputProxyTest, TwoStreams) { 481 TEST_F(AudioOutputProxyTest, TwoStreams) {
328 TwoStreams(dispatcher_impl_); 482 TwoStreams(dispatcher_impl_);
329 } 483 }
330 484
331 #if defined(ENABLE_AUDIO_MIXER) 485 #if defined(ENABLE_AUDIO_MIXER)
332 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) { 486 TEST_F(AudioOutputProxyTest, TwoStreams_Mixer) {
333 TwoStreams(mixer_); 487 TwoStreams(mixer_);
334 } 488 }
335 #endif 489 #endif
336 490
491 TEST_F(AudioOutputProxyTest, TwoStreams_Resampler) {
492 TwoStreams(resampler_);
493 }
494
337 // Two streams: verify that second stream is allocated when the first 495 // Two streams: verify that second stream is allocated when the first
338 // starts playing. 496 // starts playing.
339 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) { 497 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying) {
340 MockAudioOutputStream stream1; 498 TwoStreams_OnePlaying(dispatcher_impl_);
341 MockAudioOutputStream stream2;
342
343 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
344
345 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
346 .WillOnce(Return(&stream1))
347 .WillOnce(Return(&stream2));
348
349 EXPECT_CALL(stream1, Open())
350 .WillOnce(Return(true));
351 EXPECT_CALL(stream1, Start(_))
352 .Times(1);
353 EXPECT_CALL(stream1, SetVolume(_))
354 .Times(1);
355 EXPECT_CALL(stream1, Stop())
356 .Times(1);
357 EXPECT_CALL(stream1, Close())
358 .Times(1);
359
360 EXPECT_CALL(stream2, Open())
361 .WillOnce(Return(true));
362 EXPECT_CALL(stream2, Close())
363 .Times(1);
364
365 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_);
366 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_);
367 EXPECT_TRUE(proxy1->Open());
368 EXPECT_TRUE(proxy2->Open());
369
370 proxy1->Start(&callback_);
371 message_loop_.RunAllPending();
372 proxy1->Stop();
373
374 proxy1->Close();
375 proxy2->Close();
376 } 499 }
377 500
378 #if defined(ENABLE_AUDIO_MIXER) 501 #if defined(ENABLE_AUDIO_MIXER)
379 // Two streams: verify that only one device will be created. 502 // Two streams: verify that only one device will be created.
380 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) { 503 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Mixer) {
381 MockAudioOutputStream stream; 504 MockAudioOutputStream stream;
382 505
383 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); 506 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
384 507
385 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 508 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
(...skipping 17 matching lines...) Expand all
403 526
404 proxy1->Start(&callback_); 527 proxy1->Start(&callback_);
405 proxy1->Stop(); 528 proxy1->Stop();
406 529
407 proxy1->Close(); 530 proxy1->Close();
408 proxy2->Close(); 531 proxy2->Close();
409 WaitForCloseTimer(kTestCloseDelayMs); 532 WaitForCloseTimer(kTestCloseDelayMs);
410 } 533 }
411 #endif 534 #endif
412 535
536 TEST_F(AudioOutputProxyTest, TwoStreams_OnePlaying_Resampler) {
537 TwoStreams_OnePlaying(resampler_);
538 }
539
413 // Two streams, both are playing. Dispatcher should not open a third stream. 540 // Two streams, both are playing. Dispatcher should not open a third stream.
414 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) { 541 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying) {
415 MockAudioOutputStream stream1; 542 TwoStreams_BothPlaying(dispatcher_impl_);
416 MockAudioOutputStream stream2;
417
418 InitDispatcher(base::TimeDelta::FromSeconds(kTestBigCloseDelaySeconds));
419
420 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
421 .WillOnce(Return(&stream1))
422 .WillOnce(Return(&stream2));
423
424 EXPECT_CALL(stream1, Open())
425 .WillOnce(Return(true));
426 EXPECT_CALL(stream1, Start(_))
427 .Times(1);
428 EXPECT_CALL(stream1, SetVolume(_))
429 .Times(1);
430 EXPECT_CALL(stream1, Stop())
431 .Times(1);
432 EXPECT_CALL(stream1, Close())
433 .Times(1);
434
435 EXPECT_CALL(stream2, Open())
436 .WillOnce(Return(true));
437 EXPECT_CALL(stream2, Start(_))
438 .Times(1);
439 EXPECT_CALL(stream2, SetVolume(_))
440 .Times(1);
441 EXPECT_CALL(stream2, Stop())
442 .Times(1);
443 EXPECT_CALL(stream2, Close())
444 .Times(1);
445
446 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher_impl_);
447 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher_impl_);
448 EXPECT_TRUE(proxy1->Open());
449 EXPECT_TRUE(proxy2->Open());
450
451 proxy1->Start(&callback_);
452 proxy2->Start(&callback_);
453 proxy1->Stop();
454 proxy2->Stop();
455
456 proxy1->Close();
457 proxy2->Close();
458 } 543 }
459 544
460 #if defined(ENABLE_AUDIO_MIXER) 545 #if defined(ENABLE_AUDIO_MIXER)
461 // Two streams, both are playing. Still have to use single device. 546 // Two streams, both are playing. Still have to use single device.
462 // Also verifies that every proxy stream gets its own pending_bytes. 547 // Also verifies that every proxy stream gets its own pending_bytes.
463 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) { 548 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Mixer) {
464 MockAudioOutputStream stream; 549 MockAudioOutputStream stream;
465 550
466 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs)); 551 InitDispatcher(base::TimeDelta::FromMilliseconds(kTestCloseDelayMs));
467 552
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
515 mixer_->OnMoreData(buf2, sizeof(buf2), AudioBuffersState(4, 0)); 600 mixer_->OnMoreData(buf2, sizeof(buf2), AudioBuffersState(4, 0));
516 proxy1->Stop(); 601 proxy1->Stop();
517 proxy2->Stop(); 602 proxy2->Stop();
518 603
519 proxy1->Close(); 604 proxy1->Close();
520 proxy2->Close(); 605 proxy2->Close();
521 WaitForCloseTimer(kTestCloseDelayMs); 606 WaitForCloseTimer(kTestCloseDelayMs);
522 } 607 }
523 #endif 608 #endif
524 609
610 TEST_F(AudioOutputProxyTest, TwoStreams_BothPlaying_Resampler) {
611 TwoStreams_BothPlaying(resampler_);
612 }
613
525 TEST_F(AudioOutputProxyTest, OpenFailed) { 614 TEST_F(AudioOutputProxyTest, OpenFailed) {
526 OpenFailed(dispatcher_impl_); 615 OpenFailed(dispatcher_impl_);
527 } 616 }
528 617
529 #if defined(ENABLE_AUDIO_MIXER) 618 #if defined(ENABLE_AUDIO_MIXER)
530 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) { 619 TEST_F(AudioOutputProxyTest, OpenFailed_Mixer) {
531 OpenFailed(mixer_); 620 OpenFailed(mixer_);
532 } 621 }
533 #endif 622 #endif
534 623
624 TEST_F(AudioOutputProxyTest, OpenFailed_Resampler) {
625 OpenFailed(resampler_);
626 }
627
535 // Start() method failed. 628 // Start() method failed.
536 TEST_F(AudioOutputProxyTest, StartFailed) { 629 TEST_F(AudioOutputProxyTest, StartFailed) {
537 MockAudioOutputStream stream; 630 StartFailed(dispatcher_impl_);
538
539 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
540 .WillOnce(Return(&stream));
541 EXPECT_CALL(stream, Open())
542 .WillOnce(Return(true));
543 EXPECT_CALL(stream, Close())
544 .Times(1);
545
546 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_);
547 EXPECT_TRUE(proxy->Open());
548
549 // Simulate a delay.
550 base::PlatformThread::Sleep(
551 base::TimeDelta::FromMilliseconds(kTestCloseDelayMs) * 2);
552 message_loop_.RunAllPending();
553
554 // Verify expectation before calling Close().
555 Mock::VerifyAndClear(&stream);
556
557 // |stream| is closed at this point. Start() should reopen it again.
558 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
559 .WillOnce(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
560
561 EXPECT_CALL(callback_, OnError(_, _))
562 .Times(1);
563
564 proxy->Start(&callback_);
565
566 Mock::VerifyAndClear(&callback_);
567
568 proxy->Close();
569 } 631 }
570 632
571 #if defined(ENABLE_AUDIO_MIXER) 633 #if defined(ENABLE_AUDIO_MIXER)
572 // Start() method failed. 634 // Start() method failed.
573 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) { 635 TEST_F(AudioOutputProxyTest, StartFailed_Mixer) {
574 MockAudioOutputStream stream; 636 MockAudioOutputStream stream;
575 637
576 EXPECT_CALL(manager(), MakeAudioOutputStream(_)) 638 EXPECT_CALL(manager(), MakeAudioOutputStream(_))
577 .WillOnce(Return(&stream)); 639 .WillOnce(Return(&stream));
578 EXPECT_CALL(stream, Open()) 640 EXPECT_CALL(stream, Open())
(...skipping 28 matching lines...) Expand all
607 669
608 proxy2->Start(&callback_); 670 proxy2->Start(&callback_);
609 671
610 Mock::VerifyAndClear(&callback_); 672 Mock::VerifyAndClear(&callback_);
611 673
612 proxy2->Close(); 674 proxy2->Close();
613 WaitForCloseTimer(kTestCloseDelayMs); 675 WaitForCloseTimer(kTestCloseDelayMs);
614 } 676 }
615 #endif 677 #endif
616 678
679 TEST_F(AudioOutputProxyTest, StartFailed_Resampler) {
680 StartFailed(resampler_);
681 }
682
617 } // namespace media 683 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698