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

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

Issue 2621993002: Makes AudioOutputProxy -> AudioOutputDispatcher reference weak. (Closed)
Patch Set: adds CreateStreamProxy Created 3 years, 11 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 <stdint.h> 5 #include <stdint.h>
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 9
10 #include "base/memory/ptr_util.h" 10 #include "base/memory/ptr_util.h"
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 204
205 // Basic Open() and Close() test. 205 // Basic Open() and Close() test.
206 void OpenAndClose(AudioOutputDispatcher* dispatcher) { 206 void OpenAndClose(AudioOutputDispatcher* dispatcher) {
207 MockAudioOutputStream stream(&manager_, params_); 207 MockAudioOutputStream stream(&manager_, params_);
208 208
209 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 209 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
210 .WillOnce(Return(&stream)); 210 .WillOnce(Return(&stream));
211 EXPECT_CALL(stream, Open()) 211 EXPECT_CALL(stream, Open())
212 .WillOnce(Return(true)); 212 .WillOnce(Return(true));
213 213
214 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); 214 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
215 EXPECT_TRUE(proxy->Open()); 215 EXPECT_TRUE(proxy->Open());
216 CloseAndWaitForCloseTimer(proxy, &stream); 216 CloseAndWaitForCloseTimer(proxy, &stream);
217 } 217 }
218 218
219 // Creates a stream, and then calls Start() and Stop(). 219 // Creates a stream, and then calls Start() and Stop().
220 void StartAndStop(AudioOutputDispatcher* dispatcher) { 220 void StartAndStop(AudioOutputDispatcher* dispatcher) {
221 MockAudioOutputStream stream(&manager_, params_); 221 MockAudioOutputStream stream(&manager_, params_);
222 222
223 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 223 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
224 .WillOnce(Return(&stream)); 224 .WillOnce(Return(&stream));
225 EXPECT_CALL(stream, Open()) 225 EXPECT_CALL(stream, Open())
226 .WillOnce(Return(true)); 226 .WillOnce(Return(true));
227 EXPECT_CALL(stream, SetVolume(_)) 227 EXPECT_CALL(stream, SetVolume(_))
228 .Times(1); 228 .Times(1);
229 229
230 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); 230 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
231 EXPECT_TRUE(proxy->Open()); 231 EXPECT_TRUE(proxy->Open());
232 232
233 proxy->Start(&callback_); 233 proxy->Start(&callback_);
234 OnStart(); 234 OnStart();
235 proxy->Stop(); 235 proxy->Stop();
236 236
237 CloseAndWaitForCloseTimer(proxy, &stream); 237 CloseAndWaitForCloseTimer(proxy, &stream);
238 EXPECT_TRUE(stream.stop_called()); 238 EXPECT_TRUE(stream.stop_called());
239 EXPECT_TRUE(stream.start_called()); 239 EXPECT_TRUE(stream.start_called());
240 } 240 }
241 241
242 // Verify that the stream is closed after Stop() is called. 242 // Verify that the stream is closed after Stop() is called.
243 void CloseAfterStop(AudioOutputDispatcher* dispatcher) { 243 void CloseAfterStop(AudioOutputDispatcher* dispatcher) {
244 MockAudioOutputStream stream(&manager_, params_); 244 MockAudioOutputStream stream(&manager_, params_);
245 245
246 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 246 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
247 .WillOnce(Return(&stream)); 247 .WillOnce(Return(&stream));
248 EXPECT_CALL(stream, Open()) 248 EXPECT_CALL(stream, Open())
249 .WillOnce(Return(true)); 249 .WillOnce(Return(true));
250 EXPECT_CALL(stream, SetVolume(_)) 250 EXPECT_CALL(stream, SetVolume(_))
251 .Times(1); 251 .Times(1);
252 252
253 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); 253 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
254 EXPECT_TRUE(proxy->Open()); 254 EXPECT_TRUE(proxy->Open());
255 255
256 proxy->Start(&callback_); 256 proxy->Start(&callback_);
257 OnStart(); 257 OnStart();
258 proxy->Stop(); 258 proxy->Stop();
259 259
260 // Wait for the close timer to fire after StopStream(). 260 // Wait for the close timer to fire after StopStream().
261 WaitForCloseTimer(&stream); 261 WaitForCloseTimer(&stream);
262 proxy->Close(); 262 proxy->Close();
263 EXPECT_TRUE(stream.stop_called()); 263 EXPECT_TRUE(stream.stop_called());
264 EXPECT_TRUE(stream.start_called()); 264 EXPECT_TRUE(stream.start_called());
265 } 265 }
266 266
267 // Create two streams, but don't start them. Only one device must be opened. 267 // Create two streams, but don't start them. Only one device must be opened.
268 void TwoStreams(AudioOutputDispatcher* dispatcher) { 268 void TwoStreams(AudioOutputDispatcher* dispatcher) {
269 MockAudioOutputStream stream(&manager_, params_); 269 MockAudioOutputStream stream(&manager_, params_);
270 270
271 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 271 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
272 .WillOnce(Return(&stream)); 272 .WillOnce(Return(&stream));
273 EXPECT_CALL(stream, Open()) 273 EXPECT_CALL(stream, Open())
274 .WillOnce(Return(true)); 274 .WillOnce(Return(true));
275 275
276 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); 276 AudioOutputProxy* proxy1 = dispatcher->CreateStreamProxy();
277 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); 277 AudioOutputProxy* proxy2 = dispatcher->CreateStreamProxy();
278 EXPECT_TRUE(proxy1->Open()); 278 EXPECT_TRUE(proxy1->Open());
279 EXPECT_TRUE(proxy2->Open()); 279 EXPECT_TRUE(proxy2->Open());
280 proxy1->Close(); 280 proxy1->Close();
281 CloseAndWaitForCloseTimer(proxy2, &stream); 281 CloseAndWaitForCloseTimer(proxy2, &stream);
282 EXPECT_FALSE(stream.stop_called()); 282 EXPECT_FALSE(stream.stop_called());
283 EXPECT_FALSE(stream.start_called()); 283 EXPECT_FALSE(stream.start_called());
284 } 284 }
285 285
286 // Open() method failed. 286 // Open() method failed.
287 void OpenFailed(AudioOutputDispatcher* dispatcher) { 287 void OpenFailed(AudioOutputDispatcher* dispatcher) {
288 MockAudioOutputStream stream(&manager_, params_); 288 MockAudioOutputStream stream(&manager_, params_);
289 289
290 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 290 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
291 .WillOnce(Return(&stream)); 291 .WillOnce(Return(&stream));
292 EXPECT_CALL(stream, Open()) 292 EXPECT_CALL(stream, Open())
293 .WillOnce(Return(false)); 293 .WillOnce(Return(false));
294 EXPECT_CALL(stream, Close()) 294 EXPECT_CALL(stream, Close())
295 .Times(1); 295 .Times(1);
296 296
297 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); 297 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
298 EXPECT_FALSE(proxy->Open()); 298 EXPECT_FALSE(proxy->Open());
299 proxy->Close(); 299 proxy->Close();
300 EXPECT_FALSE(stream.stop_called()); 300 EXPECT_FALSE(stream.stop_called());
301 EXPECT_FALSE(stream.start_called()); 301 EXPECT_FALSE(stream.start_called());
302 } 302 }
303 303
304 void CreateAndWait(AudioOutputDispatcher* dispatcher) { 304 void CreateAndWait(AudioOutputDispatcher* dispatcher) {
305 MockAudioOutputStream stream(&manager_, params_); 305 MockAudioOutputStream stream(&manager_, params_);
306 306
307 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 307 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
308 .WillOnce(Return(&stream)); 308 .WillOnce(Return(&stream));
309 EXPECT_CALL(stream, Open()) 309 EXPECT_CALL(stream, Open())
310 .WillOnce(Return(true)); 310 .WillOnce(Return(true));
311 311
312 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); 312 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
313 EXPECT_TRUE(proxy->Open()); 313 EXPECT_TRUE(proxy->Open());
314 314
315 WaitForCloseTimer(&stream); 315 WaitForCloseTimer(&stream);
316 proxy->Close(); 316 proxy->Close();
317 EXPECT_FALSE(stream.stop_called()); 317 EXPECT_FALSE(stream.stop_called());
318 EXPECT_FALSE(stream.start_called()); 318 EXPECT_FALSE(stream.start_called());
319 } 319 }
320 320
321 void OneStream_TwoPlays(AudioOutputDispatcher* dispatcher) { 321 void OneStream_TwoPlays(AudioOutputDispatcher* dispatcher) {
322 MockAudioOutputStream stream(&manager_, params_); 322 MockAudioOutputStream stream(&manager_, params_);
323 323
324 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 324 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
325 .WillOnce(Return(&stream)); 325 .WillOnce(Return(&stream));
326 326
327 EXPECT_CALL(stream, Open()) 327 EXPECT_CALL(stream, Open())
328 .WillOnce(Return(true)); 328 .WillOnce(Return(true));
329 EXPECT_CALL(stream, SetVolume(_)) 329 EXPECT_CALL(stream, SetVolume(_))
330 .Times(2); 330 .Times(2);
331 331
332 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); 332 AudioOutputProxy* proxy1 = dispatcher->CreateStreamProxy();
333 EXPECT_TRUE(proxy1->Open()); 333 EXPECT_TRUE(proxy1->Open());
334 334
335 proxy1->Start(&callback_); 335 proxy1->Start(&callback_);
336 OnStart(); 336 OnStart();
337 proxy1->Stop(); 337 proxy1->Stop();
338 338
339 // The stream should now be idle and get reused by |proxy2|. 339 // The stream should now be idle and get reused by |proxy2|.
340 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); 340 AudioOutputProxy* proxy2 = dispatcher->CreateStreamProxy();
341 EXPECT_TRUE(proxy2->Open()); 341 EXPECT_TRUE(proxy2->Open());
342 proxy2->Start(&callback_); 342 proxy2->Start(&callback_);
343 OnStart(); 343 OnStart();
344 proxy2->Stop(); 344 proxy2->Stop();
345 345
346 proxy1->Close(); 346 proxy1->Close();
347 CloseAndWaitForCloseTimer(proxy2, &stream); 347 CloseAndWaitForCloseTimer(proxy2, &stream);
348 EXPECT_TRUE(stream.stop_called()); 348 EXPECT_TRUE(stream.stop_called());
349 EXPECT_TRUE(stream.start_called()); 349 EXPECT_TRUE(stream.start_called());
350 } 350 }
351 351
352 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) { 352 void TwoStreams_BothPlaying(AudioOutputDispatcher* dispatcher) {
353 MockAudioOutputStream stream1(&manager_, params_); 353 MockAudioOutputStream stream1(&manager_, params_);
354 MockAudioOutputStream stream2(&manager_, params_); 354 MockAudioOutputStream stream2(&manager_, params_);
355 355
356 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 356 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
357 .WillOnce(Return(&stream1)) 357 .WillOnce(Return(&stream1))
358 .WillOnce(Return(&stream2)); 358 .WillOnce(Return(&stream2));
359 359
360 EXPECT_CALL(stream1, Open()) 360 EXPECT_CALL(stream1, Open())
361 .WillOnce(Return(true)); 361 .WillOnce(Return(true));
362 EXPECT_CALL(stream1, SetVolume(_)) 362 EXPECT_CALL(stream1, SetVolume(_))
363 .Times(1); 363 .Times(1);
364 364
365 EXPECT_CALL(stream2, Open()) 365 EXPECT_CALL(stream2, Open())
366 .WillOnce(Return(true)); 366 .WillOnce(Return(true));
367 EXPECT_CALL(stream2, SetVolume(_)) 367 EXPECT_CALL(stream2, SetVolume(_))
368 .Times(1); 368 .Times(1);
369 369
370 AudioOutputProxy* proxy1 = new AudioOutputProxy(dispatcher); 370 AudioOutputProxy* proxy1 = dispatcher->CreateStreamProxy();
371 AudioOutputProxy* proxy2 = new AudioOutputProxy(dispatcher); 371 AudioOutputProxy* proxy2 = dispatcher->CreateStreamProxy();
372 EXPECT_TRUE(proxy1->Open()); 372 EXPECT_TRUE(proxy1->Open());
373 EXPECT_TRUE(proxy2->Open()); 373 EXPECT_TRUE(proxy2->Open());
374 374
375 proxy1->Start(&callback_); 375 proxy1->Start(&callback_);
376 proxy2->Start(&callback_); 376 proxy2->Start(&callback_);
377 OnStart(); 377 OnStart();
378 proxy1->Stop(); 378 proxy1->Stop();
379 CloseAndWaitForCloseTimer(proxy1, &stream1); 379 CloseAndWaitForCloseTimer(proxy1, &stream1);
380 380
381 proxy2->Stop(); 381 proxy2->Stop();
382 CloseAndWaitForCloseTimer(proxy2, &stream2); 382 CloseAndWaitForCloseTimer(proxy2, &stream2);
383 383
384 EXPECT_TRUE(stream1.stop_called()); 384 EXPECT_TRUE(stream1.stop_called());
385 EXPECT_TRUE(stream1.start_called()); 385 EXPECT_TRUE(stream1.start_called());
386 EXPECT_TRUE(stream2.stop_called()); 386 EXPECT_TRUE(stream2.stop_called());
387 EXPECT_TRUE(stream2.start_called()); 387 EXPECT_TRUE(stream2.start_called());
388 } 388 }
389 389
390 void StartFailed(AudioOutputDispatcher* dispatcher) { 390 void StartFailed(AudioOutputDispatcher* dispatcher) {
391 MockAudioOutputStream stream(&manager_, params_); 391 MockAudioOutputStream stream(&manager_, params_);
392 392
393 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 393 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
394 .WillOnce(Return(&stream)); 394 .WillOnce(Return(&stream));
395 EXPECT_CALL(stream, Open()) 395 EXPECT_CALL(stream, Open())
396 .WillOnce(Return(true)); 396 .WillOnce(Return(true));
397 397
398 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher); 398 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
399 EXPECT_TRUE(proxy->Open()); 399 EXPECT_TRUE(proxy->Open());
400 400
401 WaitForCloseTimer(&stream); 401 WaitForCloseTimer(&stream);
402 402
403 // |stream| is closed at this point. Start() should reopen it again. 403 // |stream| is closed at this point. Start() should reopen it again.
404 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 404 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
405 .Times(2) 405 .Times(2)
406 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL))); 406 .WillRepeatedly(Return(reinterpret_cast<AudioOutputStream*>(NULL)));
407 407
408 EXPECT_CALL(callback_, OnError(_)) 408 EXPECT_CALL(callback_, OnError(_))
409 .Times(2); 409 .Times(2);
410 410
411 proxy->Start(&callback_); 411 proxy->Start(&callback_);
412 412
413 // Double Start() in the error case should be allowed since it's possible a 413 // Double Start() in the error case should be allowed since it's possible a
414 // callback may not have had time to process the OnError() in between. 414 // callback may not have had time to process the OnError() in between.
415 proxy->Stop(); 415 proxy->Stop();
416 proxy->Start(&callback_); 416 proxy->Start(&callback_);
417 417
418 Mock::VerifyAndClear(&callback_); 418 Mock::VerifyAndClear(&callback_);
419 419
420 proxy->Close(); 420 proxy->Close();
421 } 421 }
422 422
423 void DispatcherDestroyed_BeforeOpen(
424 std::unique_ptr<AudioOutputDispatcher> dispatcher) {
425 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)).Times(0);
426 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
427 dispatcher.reset();
428 EXPECT_FALSE(proxy->Open());
429 proxy->Close();
430 }
431
432 void DispatcherDestroyed_BeforeStart(
433 std::unique_ptr<AudioOutputDispatcher> dispatcher) {
434 MockAudioOutputStream stream(&manager_, params_);
435 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
436 .WillOnce(Return(&stream));
437 EXPECT_CALL(stream, Open()).WillOnce(Return(true));
438 EXPECT_CALL(stream, Close()).Times(1);
439 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
440 EXPECT_TRUE(proxy->Open());
441
442 EXPECT_CALL(callback_, OnError(_)).Times(1);
443 dispatcher.reset();
444 proxy->Start(&callback_);
445 proxy->Stop();
446 proxy->Close();
447 }
448
449 void DispatcherDestroyed_BeforeStop(
450 std::unique_ptr<AudioOutputDispatcher> dispatcher) {
451 MockAudioOutputStream stream(&manager_, params_);
452 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
453 .WillOnce(Return(&stream));
454 EXPECT_CALL(stream, Open()).WillOnce(Return(true));
455 EXPECT_CALL(stream, Close()).Times(1);
456 EXPECT_CALL(stream, SetVolume(_)).Times(1);
457
458 AudioOutputProxy* proxy = dispatcher->CreateStreamProxy();
459 EXPECT_TRUE(proxy->Open());
460 proxy->Start(&callback_);
461 dispatcher.reset();
462 proxy->Stop();
463 proxy->Close();
464 }
465
423 base::MessageLoop message_loop_; 466 base::MessageLoop message_loop_;
424 std::unique_ptr<AudioOutputDispatcherImpl> dispatcher_impl_; 467 std::unique_ptr<AudioOutputDispatcherImpl> dispatcher_impl_;
425 MockAudioManager manager_; 468 MockAudioManager manager_;
426 MockAudioSourceCallback callback_; 469 MockAudioSourceCallback callback_;
427 AudioParameters params_; 470 AudioParameters params_;
428 }; 471 };
429 472
430 class AudioOutputResamplerTest : public AudioOutputProxyTest { 473 class AudioOutputResamplerTest : public AudioOutputProxyTest {
431 public: 474 public:
432 void TearDown() override { AudioOutputProxyTest::TearDown(); } 475 void TearDown() override { AudioOutputProxyTest::TearDown(); }
(...skipping 17 matching lines...) Expand all
450 base::TimeDelta::FromMilliseconds(kStartRunTimeMs)); 493 base::TimeDelta::FromMilliseconds(kStartRunTimeMs));
451 run_loop.Run(); 494 run_loop.Run();
452 } 495 }
453 496
454 protected: 497 protected:
455 AudioParameters resampler_params_; 498 AudioParameters resampler_params_;
456 std::unique_ptr<AudioOutputResampler> resampler_; 499 std::unique_ptr<AudioOutputResampler> resampler_;
457 }; 500 };
458 501
459 TEST_F(AudioOutputProxyTest, CreateAndClose) { 502 TEST_F(AudioOutputProxyTest, CreateAndClose) {
460 AudioOutputProxy* proxy = new AudioOutputProxy(dispatcher_impl_.get()); 503 AudioOutputProxy* proxy = dispatcher_impl_->CreateStreamProxy();
461 proxy->Close(); 504 proxy->Close();
462 } 505 }
463 506
464 TEST_F(AudioOutputResamplerTest, CreateAndClose) { 507 TEST_F(AudioOutputResamplerTest, CreateAndClose) {
465 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); 508 AudioOutputProxy* proxy = resampler_->CreateStreamProxy();
466 proxy->Close(); 509 proxy->Close();
467 } 510 }
468 511
469 TEST_F(AudioOutputProxyTest, OpenAndClose) { 512 TEST_F(AudioOutputProxyTest, OpenAndClose) {
470 OpenAndClose(dispatcher_impl_.get()); 513 OpenAndClose(dispatcher_impl_.get());
471 } 514 }
472 515
473 TEST_F(AudioOutputResamplerTest, OpenAndClose) { 516 TEST_F(AudioOutputResamplerTest, OpenAndClose) {
474 OpenAndClose(resampler_.get()); 517 OpenAndClose(resampler_.get());
475 } 518 }
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
535 578
536 // Start() method failed. 579 // Start() method failed.
537 TEST_F(AudioOutputProxyTest, StartFailed) { 580 TEST_F(AudioOutputProxyTest, StartFailed) {
538 StartFailed(dispatcher_impl_.get()); 581 StartFailed(dispatcher_impl_.get());
539 } 582 }
540 583
541 TEST_F(AudioOutputResamplerTest, StartFailed) { 584 TEST_F(AudioOutputResamplerTest, StartFailed) {
542 StartFailed(resampler_.get()); 585 StartFailed(resampler_.get());
543 } 586 }
544 587
588 TEST_F(AudioOutputProxyTest, DispatcherDestroyed_BeforeOpen) {
589 DispatcherDestroyed_BeforeOpen(std::move(dispatcher_impl_));
590 }
591
592 TEST_F(AudioOutputResamplerTest, DispatcherDestroyed_BeforeOpen) {
593 DispatcherDestroyed_BeforeOpen(std::move(resampler_));
594 }
595
596 TEST_F(AudioOutputProxyTest, DispatcherDestroyed_BeforeStart) {
597 DispatcherDestroyed_BeforeStart(std::move(dispatcher_impl_));
598 }
599
600 TEST_F(AudioOutputResamplerTest, DispatcherDestroyed_BeforeStart) {
601 DispatcherDestroyed_BeforeStart(std::move(resampler_));
602 }
603
604 TEST_F(AudioOutputProxyTest, DispatcherDestroyed_BeforeStop) {
605 DispatcherDestroyed_BeforeStop(std::move(dispatcher_impl_));
606 }
607
608 TEST_F(AudioOutputResamplerTest, DispatcherDestroyed_BeforeStop) {
609 DispatcherDestroyed_BeforeStop(std::move(resampler_));
610 }
611
545 // Simulate AudioOutputStream::Create() failure with a low latency stream and 612 // Simulate AudioOutputStream::Create() failure with a low latency stream and
546 // ensure AudioOutputResampler falls back to the high latency path. 613 // ensure AudioOutputResampler falls back to the high latency path.
547 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) { 614 TEST_F(AudioOutputResamplerTest, LowLatencyCreateFailedFallback) {
548 MockAudioOutputStream stream(&manager_, params_); 615 MockAudioOutputStream stream(&manager_, params_);
549 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 616 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
550 .Times(2) 617 .Times(2)
551 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL))) 618 .WillOnce(Return(static_cast<AudioOutputStream*>(NULL)))
552 .WillRepeatedly(Return(&stream)); 619 .WillRepeatedly(Return(&stream));
553 EXPECT_CALL(stream, Open()) 620 EXPECT_CALL(stream, Open())
554 .WillOnce(Return(true)); 621 .WillOnce(Return(true));
555 622
556 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); 623 AudioOutputProxy* proxy = resampler_->CreateStreamProxy();
557 EXPECT_TRUE(proxy->Open()); 624 EXPECT_TRUE(proxy->Open());
558 CloseAndWaitForCloseTimer(proxy, &stream); 625 CloseAndWaitForCloseTimer(proxy, &stream);
559 } 626 }
560 627
561 // Simulate AudioOutputStream::Open() failure with a low latency stream and 628 // Simulate AudioOutputStream::Open() failure with a low latency stream and
562 // ensure AudioOutputResampler falls back to the high latency path. 629 // ensure AudioOutputResampler falls back to the high latency path.
563 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) { 630 TEST_F(AudioOutputResamplerTest, LowLatencyOpenFailedFallback) {
564 MockAudioOutputStream failed_stream(&manager_, params_); 631 MockAudioOutputStream failed_stream(&manager_, params_);
565 MockAudioOutputStream okay_stream(&manager_, params_); 632 MockAudioOutputStream okay_stream(&manager_, params_);
566 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 633 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
567 .Times(2) 634 .Times(2)
568 .WillOnce(Return(&failed_stream)) 635 .WillOnce(Return(&failed_stream))
569 .WillRepeatedly(Return(&okay_stream)); 636 .WillRepeatedly(Return(&okay_stream));
570 EXPECT_CALL(failed_stream, Open()) 637 EXPECT_CALL(failed_stream, Open())
571 .WillOnce(Return(false)); 638 .WillOnce(Return(false));
572 EXPECT_CALL(failed_stream, Close()) 639 EXPECT_CALL(failed_stream, Close())
573 .Times(1); 640 .Times(1);
574 EXPECT_CALL(okay_stream, Open()) 641 EXPECT_CALL(okay_stream, Open())
575 .WillOnce(Return(true)); 642 .WillOnce(Return(true));
576 643
577 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); 644 AudioOutputProxy* proxy = resampler_->CreateStreamProxy();
578 EXPECT_TRUE(proxy->Open()); 645 EXPECT_TRUE(proxy->Open());
579 CloseAndWaitForCloseTimer(proxy, &okay_stream); 646 CloseAndWaitForCloseTimer(proxy, &okay_stream);
580 } 647 }
581 648
582 // Simulate failures to open both the low latency and the fallback high latency 649 // Simulate failures to open both the low latency and the fallback high latency
583 // stream and ensure AudioOutputResampler falls back to a fake stream. 650 // stream and ensure AudioOutputResampler falls back to a fake stream.
584 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) { 651 TEST_F(AudioOutputResamplerTest, HighLatencyFallbackFailed) {
585 MockAudioOutputStream okay_stream(&manager_, params_); 652 MockAudioOutputStream okay_stream(&manager_, params_);
586 653
587 // Only Windows has a high latency output driver that is not the same as the low 654 // Only Windows has a high latency output driver that is not the same as the low
(...skipping 16 matching lines...) Expand all
604 testing::Property(&AudioParameters::sample_rate, 671 testing::Property(&AudioParameters::sample_rate,
605 params_.sample_rate()), 672 params_.sample_rate()),
606 testing::Property(&AudioParameters::frames_per_buffer, 673 testing::Property(&AudioParameters::frames_per_buffer,
607 params_.frames_per_buffer())), 674 params_.frames_per_buffer())),
608 _, _)) 675 _, _))
609 .Times(1) 676 .Times(1)
610 .WillOnce(Return(&okay_stream)); 677 .WillOnce(Return(&okay_stream));
611 EXPECT_CALL(okay_stream, Open()) 678 EXPECT_CALL(okay_stream, Open())
612 .WillOnce(Return(true)); 679 .WillOnce(Return(true));
613 680
614 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); 681 AudioOutputProxy* proxy = resampler_->CreateStreamProxy();
615 EXPECT_TRUE(proxy->Open()); 682 EXPECT_TRUE(proxy->Open());
616 CloseAndWaitForCloseTimer(proxy, &okay_stream); 683 CloseAndWaitForCloseTimer(proxy, &okay_stream);
617 } 684 }
618 685
619 // Simulate failures to open both the low latency, the fallback high latency 686 // Simulate failures to open both the low latency, the fallback high latency
620 // stream, and the fake audio output stream and ensure AudioOutputResampler 687 // stream, and the fake audio output stream and ensure AudioOutputResampler
621 // terminates normally. 688 // terminates normally.
622 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) { 689 TEST_F(AudioOutputResamplerTest, AllFallbackFailed) {
623 // Only Windows has a high latency output driver that is not the same as the low 690 // Only Windows has a high latency output driver that is not the same as the low
624 // latency path. 691 // latency path.
625 #if defined(OS_WIN) 692 #if defined(OS_WIN)
626 static const int kFallbackCount = 3; 693 static const int kFallbackCount = 3;
627 #else 694 #else
628 static const int kFallbackCount = 2; 695 static const int kFallbackCount = 2;
629 #endif 696 #endif
630 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 697 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
631 .Times(kFallbackCount) 698 .Times(kFallbackCount)
632 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); 699 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL)));
633 700
634 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); 701 AudioOutputProxy* proxy = resampler_->CreateStreamProxy();
635 EXPECT_FALSE(proxy->Open()); 702 EXPECT_FALSE(proxy->Open());
636 proxy->Close(); 703 proxy->Close();
637 } 704 }
638 705
639 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls 706 // Simulate an eventual OpenStream() failure; i.e. successful OpenStream() calls
640 // eventually followed by one which fails; root cause of http://crbug.com/150619 707 // eventually followed by one which fails; root cause of http://crbug.com/150619
641 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) { 708 TEST_F(AudioOutputResamplerTest, LowLatencyOpenEventuallyFails) {
642 MockAudioOutputStream stream1(&manager_, params_); 709 MockAudioOutputStream stream1(&manager_, params_);
643 MockAudioOutputStream stream2(&manager_, params_); 710 MockAudioOutputStream stream2(&manager_, params_);
644 711
645 // Setup the mock such that all three streams are successfully created. 712 // Setup the mock such that all three streams are successfully created.
646 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _)) 713 EXPECT_CALL(manager(), MakeAudioOutputStream(_, _, _))
647 .WillOnce(Return(&stream1)) 714 .WillOnce(Return(&stream1))
648 .WillOnce(Return(&stream2)) 715 .WillOnce(Return(&stream2))
649 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL))); 716 .WillRepeatedly(Return(static_cast<AudioOutputStream*>(NULL)));
650 717
651 // Stream1 should be able to successfully open and start. 718 // Stream1 should be able to successfully open and start.
652 EXPECT_CALL(stream1, Open()) 719 EXPECT_CALL(stream1, Open())
653 .WillOnce(Return(true)); 720 .WillOnce(Return(true));
654 EXPECT_CALL(stream1, SetVolume(_)) 721 EXPECT_CALL(stream1, SetVolume(_))
655 .Times(1); 722 .Times(1);
656 723
657 // Stream2 should also be able to successfully open and start. 724 // Stream2 should also be able to successfully open and start.
658 EXPECT_CALL(stream2, Open()) 725 EXPECT_CALL(stream2, Open())
659 .WillOnce(Return(true)); 726 .WillOnce(Return(true));
660 EXPECT_CALL(stream2, SetVolume(_)) 727 EXPECT_CALL(stream2, SetVolume(_))
661 .Times(1); 728 .Times(1);
662 729
663 // Open and start the first proxy and stream. 730 // Open and start the first proxy and stream.
664 AudioOutputProxy* proxy1 = new AudioOutputProxy(resampler_.get()); 731 AudioOutputProxy* proxy1 = resampler_->CreateStreamProxy();
665 EXPECT_TRUE(proxy1->Open()); 732 EXPECT_TRUE(proxy1->Open());
666 proxy1->Start(&callback_); 733 proxy1->Start(&callback_);
667 OnStart(); 734 OnStart();
668 735
669 // Open and start the second proxy and stream. 736 // Open and start the second proxy and stream.
670 AudioOutputProxy* proxy2 = new AudioOutputProxy(resampler_.get()); 737 AudioOutputProxy* proxy2 = resampler_->CreateStreamProxy();
671 EXPECT_TRUE(proxy2->Open()); 738 EXPECT_TRUE(proxy2->Open());
672 proxy2->Start(&callback_); 739 proxy2->Start(&callback_);
673 OnStart(); 740 OnStart();
674 741
675 // Attempt to open the third stream which should fail. 742 // Attempt to open the third stream which should fail.
676 AudioOutputProxy* proxy3 = new AudioOutputProxy(resampler_.get()); 743 AudioOutputProxy* proxy3 = resampler_->CreateStreamProxy();
677 EXPECT_FALSE(proxy3->Open()); 744 EXPECT_FALSE(proxy3->Open());
678 proxy3->Close(); 745 proxy3->Close();
679 746
680 // Perform the required Stop()/Close() shutdown dance for each proxy. Under 747 // Perform the required Stop()/Close() shutdown dance for each proxy. Under
681 // the hood each proxy should correctly call CloseStream() if OpenStream() 748 // the hood each proxy should correctly call CloseStream() if OpenStream()
682 // succeeded or not. 749 // succeeded or not.
683 proxy2->Stop(); 750 proxy2->Stop();
684 CloseAndWaitForCloseTimer(proxy2, &stream2); 751 CloseAndWaitForCloseTimer(proxy2, &stream2);
685 752
686 proxy1->Stop(); 753 proxy1->Stop();
(...skipping 25 matching lines...) Expand all
712 MakeAudioOutputStream( 779 MakeAudioOutputStream(
713 AllOf(testing::Property(&AudioParameters::format, 780 AllOf(testing::Property(&AudioParameters::format,
714 AudioParameters::AUDIO_FAKE), 781 AudioParameters::AUDIO_FAKE),
715 testing::Property(&AudioParameters::sample_rate, 782 testing::Property(&AudioParameters::sample_rate,
716 params_.sample_rate()), 783 params_.sample_rate()),
717 testing::Property(&AudioParameters::frames_per_buffer, 784 testing::Property(&AudioParameters::frames_per_buffer,
718 params_.frames_per_buffer())), 785 params_.frames_per_buffer())),
719 _, _)) 786 _, _))
720 .WillOnce(Return(&fake_stream)); 787 .WillOnce(Return(&fake_stream));
721 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true)); 788 EXPECT_CALL(fake_stream, Open()).WillOnce(Return(true));
722 AudioOutputProxy* proxy = new AudioOutputProxy(resampler_.get()); 789 AudioOutputProxy* proxy = resampler_->CreateStreamProxy();
723 EXPECT_TRUE(proxy->Open()); 790 EXPECT_TRUE(proxy->Open());
724 CloseAndWaitForCloseTimer(proxy, &fake_stream); 791 CloseAndWaitForCloseTimer(proxy, &fake_stream);
725 792
726 // Once all proxies have been closed, AudioOutputResampler will start the 793 // Once all proxies have been closed, AudioOutputResampler will start the
727 // reinitialization timer and execute it after the close delay elapses. 794 // reinitialization timer and execute it after the close delay elapses.
728 base::RunLoop run_loop; 795 base::RunLoop run_loop;
729 message_loop_.task_runner()->PostDelayedTask( 796 message_loop_.task_runner()->PostDelayedTask(
730 FROM_HERE, run_loop.QuitClosure(), 797 FROM_HERE, run_loop.QuitClosure(),
731 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs)); 798 base::TimeDelta::FromMilliseconds(2 * kTestCloseDelayMs));
732 run_loop.Run(); 799 run_loop.Run();
733 800
734 // Verify a non-fake stream can be created. 801 // Verify a non-fake stream can be created.
735 MockAudioOutputStream real_stream(&manager_, params_); 802 MockAudioOutputStream real_stream(&manager_, params_);
736 EXPECT_CALL(manager(), 803 EXPECT_CALL(manager(),
737 MakeAudioOutputStream( 804 MakeAudioOutputStream(
738 testing::Property(&AudioParameters::format, 805 testing::Property(&AudioParameters::format,
739 testing::Ne(AudioParameters::AUDIO_FAKE)), 806 testing::Ne(AudioParameters::AUDIO_FAKE)),
740 _, _)) 807 _, _))
741 .WillOnce(Return(&real_stream)); 808 .WillOnce(Return(&real_stream));
742 809
743 // Stream1 should be able to successfully open and start. 810 // Stream1 should be able to successfully open and start.
744 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true)); 811 EXPECT_CALL(real_stream, Open()).WillOnce(Return(true));
745 proxy = new AudioOutputProxy(resampler_.get()); 812 proxy = resampler_->CreateStreamProxy();
746 EXPECT_TRUE(proxy->Open()); 813 EXPECT_TRUE(proxy->Open());
747 CloseAndWaitForCloseTimer(proxy, &real_stream); 814 CloseAndWaitForCloseTimer(proxy, &real_stream);
748 } 815 }
749 816
750 } // namespace media 817 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698