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

Side by Side Diff: media/renderers/video_renderer_impl_unittest.cc

Issue 2352253002: Added MediaSourceState unit test. (Closed)
Patch Set: Return OnNewConfigs cb result from the AppendData helper Created 4 years, 2 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 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 <utility> 8 #include <utility>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 26 matching lines...) Expand all
37 using ::testing::AnyNumber; 37 using ::testing::AnyNumber;
38 using ::testing::Invoke; 38 using ::testing::Invoke;
39 using ::testing::Mock; 39 using ::testing::Mock;
40 using ::testing::NiceMock; 40 using ::testing::NiceMock;
41 using ::testing::Return; 41 using ::testing::Return;
42 using ::testing::SaveArg; 42 using ::testing::SaveArg;
43 using ::testing::StrictMock; 43 using ::testing::StrictMock;
44 44
45 namespace media { 45 namespace media {
46 46
47 ACTION_P(RunClosure, closure) { 47 MATCHER_P(HasTimestampMatcher, ms, "") {
48 closure.Run();
49 }
50
51 MATCHER_P(HasTimestamp, ms, "") {
52 *result_listener << "has timestamp " << arg->timestamp().InMilliseconds(); 48 *result_listener << "has timestamp " << arg->timestamp().InMilliseconds();
53 return arg->timestamp().InMilliseconds() == ms; 49 return arg->timestamp().InMilliseconds() == ms;
54 } 50 }
55 51
56 class VideoRendererImplTest : public testing::Test { 52 class VideoRendererImplTest : public testing::Test {
57 public: 53 public:
58 VideoRendererImplTest() 54 VideoRendererImplTest()
59 : tick_clock_(new base::SimpleTestTickClock()), 55 : tick_clock_(new base::SimpleTestTickClock()),
60 decoder_(new NiceMock<MockVideoDecoder>()), 56 decoder_(new NiceMock<MockVideoDecoder>()),
61 demuxer_stream_(DemuxerStream::VIDEO) { 57 demuxer_stream_(DemuxerStream::VIDEO) {
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
290 }; 286 };
291 void BasicUnderflowTest(UnderflowTestType type) { 287 void BasicUnderflowTest(UnderflowTestType type) {
292 InitializeWithLowDelay(type == UnderflowTestType::LOW_DELAY); 288 InitializeWithLowDelay(type == UnderflowTestType::LOW_DELAY);
293 if (type == UnderflowTestType::CANT_READ_WITHOUT_STALLING) 289 if (type == UnderflowTestType::CANT_READ_WITHOUT_STALLING)
294 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false)); 290 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false));
295 291
296 QueueFrames("0 30 60 90"); 292 QueueFrames("0 30 60 90");
297 293
298 { 294 {
299 WaitableMessageLoopEvent event; 295 WaitableMessageLoopEvent event;
300 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 296 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
301 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) 297 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
302 .WillOnce(RunClosure(event.GetClosure())); 298 .WillOnce(RunClosure(event.GetClosure()));
303 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 299 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
304 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 300 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
305 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 301 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
306 StartPlayingFrom(0); 302 StartPlayingFrom(0);
307 event.RunAndWait(); 303 event.RunAndWait();
308 Mock::VerifyAndClearExpectations(&mock_cb_); 304 Mock::VerifyAndClearExpectations(&mock_cb_);
309 } 305 }
310 306
311 renderer_->OnTimeStateChanged(true); 307 renderer_->OnTimeStateChanged(true);
312 308
313 // Advance time slightly, but enough to exceed the duration of the last 309 // Advance time slightly, but enough to exceed the duration of the last
314 // frame. 310 // frame.
315 // Frames should be dropped and we should NOT signal having nothing. 311 // Frames should be dropped and we should NOT signal having nothing.
316 { 312 {
317 SCOPED_TRACE("Waiting for frame drops"); 313 SCOPED_TRACE("Waiting for frame drops");
318 WaitableMessageLoopEvent event; 314 WaitableMessageLoopEvent event;
319 315
320 // Note: Starting the TimeSource will cause the old VideoRendererImpl to 316 // Note: Starting the TimeSource will cause the old VideoRendererImpl to
321 // start rendering frames on its own thread, so the first frame may be 317 // start rendering frames on its own thread, so the first frame may be
322 // received. 318 // received.
323 time_source_.StartTicking(); 319 time_source_.StartTicking();
324 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(30))).Times(0); 320 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(30))).Times(0);
325 321
326 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))).Times(0); 322 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(60))).Times(0);
327 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90))) 323 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(90)))
328 .WillOnce(RunClosure(event.GetClosure())); 324 .WillOnce(RunClosure(event.GetClosure()));
329 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 325 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
330 AdvanceTimeInMs(91); 326 AdvanceTimeInMs(91);
331 327
332 event.RunAndWait(); 328 event.RunAndWait();
333 Mock::VerifyAndClearExpectations(&mock_cb_); 329 Mock::VerifyAndClearExpectations(&mock_cb_);
334 } 330 }
335 331
336 // Advance time more. Now we should signal having nothing. And put 332 // Advance time more. Now we should signal having nothing. And put
337 // the last frame up for display. 333 // the last frame up for display.
(...skipping 27 matching lines...) Expand all
365 } 361 }
366 362
367 void UnderflowRecoveryTest(UnderflowTestType type) { 363 void UnderflowRecoveryTest(UnderflowTestType type) {
368 InitializeWithLowDelay(type == UnderflowTestType::LOW_DELAY); 364 InitializeWithLowDelay(type == UnderflowTestType::LOW_DELAY);
369 if (type == UnderflowTestType::CANT_READ_WITHOUT_STALLING) 365 if (type == UnderflowTestType::CANT_READ_WITHOUT_STALLING)
370 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false)); 366 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false));
371 367
372 QueueFrames("0 20 40 60"); 368 QueueFrames("0 20 40 60");
373 { 369 {
374 WaitableMessageLoopEvent event; 370 WaitableMessageLoopEvent event;
375 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 371 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
376 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) 372 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
377 .WillOnce(RunClosure(event.GetClosure())); 373 .WillOnce(RunClosure(event.GetClosure()));
378 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 374 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
379 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 375 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
380 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 376 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
381 StartPlayingFrom(0); 377 StartPlayingFrom(0);
382 event.RunAndWait(); 378 event.RunAndWait();
383 Mock::VerifyAndClearExpectations(&mock_cb_); 379 Mock::VerifyAndClearExpectations(&mock_cb_);
384 } 380 }
385 381
386 renderer_->OnTimeStateChanged(true); 382 renderer_->OnTimeStateChanged(true);
387 time_source_.StartTicking(); 383 time_source_.StartTicking();
388 384
389 // Advance time, this should cause have nothing to be signaled. 385 // Advance time, this should cause have nothing to be signaled.
390 { 386 {
391 SCOPED_TRACE("Waiting for BUFFERING_HAVE_NOTHING"); 387 SCOPED_TRACE("Waiting for BUFFERING_HAVE_NOTHING");
392 WaitableMessageLoopEvent event; 388 WaitableMessageLoopEvent event;
393 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) 389 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING))
394 .WillOnce(RunClosure(event.GetClosure())); 390 .WillOnce(RunClosure(event.GetClosure()));
395 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(20))).Times(1); 391 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(20))).Times(1);
396 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 392 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
397 AdvanceTimeInMs(20); 393 AdvanceTimeInMs(20);
398 event.RunAndWait(); 394 event.RunAndWait();
399 Mock::VerifyAndClearExpectations(&mock_cb_); 395 Mock::VerifyAndClearExpectations(&mock_cb_);
400 } 396 }
401 397
402 AdvanceTimeInMs(59); 398 AdvanceTimeInMs(59);
403 EXPECT_EQ(3u, renderer_->frames_queued_for_testing()); 399 EXPECT_EQ(3u, renderer_->frames_queued_for_testing());
404 time_source_.StopTicking(); 400 time_source_.StopTicking();
405 renderer_->OnTimeStateChanged(false); 401 renderer_->OnTimeStateChanged(false);
406 EXPECT_EQ(0u, renderer_->frames_queued_for_testing()); 402 EXPECT_EQ(0u, renderer_->frames_queued_for_testing());
407 ASSERT_TRUE(IsReadPending()); 403 ASSERT_TRUE(IsReadPending());
408 404
409 // Queue some frames, satisfy reads, and make sure expired frames are gone 405 // Queue some frames, satisfy reads, and make sure expired frames are gone
410 // when the renderer paints the first frame. 406 // when the renderer paints the first frame.
411 { 407 {
412 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH"); 408 SCOPED_TRACE("Waiting for BUFFERING_HAVE_ENOUGH");
413 WaitableMessageLoopEvent event; 409 WaitableMessageLoopEvent event;
414 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(80))).Times(1); 410 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(80))).Times(1);
415 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 411 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
416 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) 412 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
417 .WillOnce(RunClosure(event.GetClosure())); 413 .WillOnce(RunClosure(event.GetClosure()));
418 if (type == UnderflowTestType::NORMAL) 414 if (type == UnderflowTestType::NORMAL)
419 QueueFrames("80 100 120 140 160"); 415 QueueFrames("80 100 120 140 160");
420 else 416 else
421 QueueFrames("40 60 80 90"); 417 QueueFrames("40 60 80 90");
422 SatisfyPendingDecode(); 418 SatisfyPendingDecode();
423 event.RunAndWait(); 419 event.RunAndWait();
424 } 420 }
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
503 } 499 }
504 500
505 TEST_F(VideoRendererImplTest, Initialize) { 501 TEST_F(VideoRendererImplTest, Initialize) {
506 Initialize(); 502 Initialize();
507 Destroy(); 503 Destroy();
508 } 504 }
509 505
510 TEST_F(VideoRendererImplTest, InitializeAndStartPlayingFrom) { 506 TEST_F(VideoRendererImplTest, InitializeAndStartPlayingFrom) {
511 Initialize(); 507 Initialize();
512 QueueFrames("0 10 20 30"); 508 QueueFrames("0 10 20 30");
513 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 509 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
514 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 510 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
515 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 511 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
516 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 512 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
517 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 513 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
518 StartPlayingFrom(0); 514 StartPlayingFrom(0);
519 Destroy(); 515 Destroy();
520 } 516 }
521 517
522 TEST_F(VideoRendererImplTest, InitializeAndEndOfStream) { 518 TEST_F(VideoRendererImplTest, InitializeAndEndOfStream) {
523 Initialize(); 519 Initialize();
(...skipping 15 matching lines...) Expand all
539 } 535 }
540 536
541 TEST_F(VideoRendererImplTest, DestroyWhileInitializing) { 537 TEST_F(VideoRendererImplTest, DestroyWhileInitializing) {
542 CallInitialize(NewExpectedStatusCB(PIPELINE_ERROR_ABORT), false, PIPELINE_OK); 538 CallInitialize(NewExpectedStatusCB(PIPELINE_ERROR_ABORT), false, PIPELINE_OK);
543 Destroy(); 539 Destroy();
544 } 540 }
545 541
546 TEST_F(VideoRendererImplTest, DestroyWhileFlushing) { 542 TEST_F(VideoRendererImplTest, DestroyWhileFlushing) {
547 Initialize(); 543 Initialize();
548 QueueFrames("0 10 20 30"); 544 QueueFrames("0 10 20 30");
549 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 545 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
550 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 546 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
551 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 547 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
552 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 548 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
553 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 549 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
554 StartPlayingFrom(0); 550 StartPlayingFrom(0);
555 renderer_->Flush(NewExpectedClosure()); 551 renderer_->Flush(NewExpectedClosure());
556 Destroy(); 552 Destroy();
557 } 553 }
558 554
559 TEST_F(VideoRendererImplTest, Play) { 555 TEST_F(VideoRendererImplTest, Play) {
560 Initialize(); 556 Initialize();
561 QueueFrames("0 10 20 30"); 557 QueueFrames("0 10 20 30");
562 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 558 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
563 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 559 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
564 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 560 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
565 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 561 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
566 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 562 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
567 StartPlayingFrom(0); 563 StartPlayingFrom(0);
568 Destroy(); 564 Destroy();
569 } 565 }
570 566
571 TEST_F(VideoRendererImplTest, FlushWithNothingBuffered) { 567 TEST_F(VideoRendererImplTest, FlushWithNothingBuffered) {
572 Initialize(); 568 Initialize();
(...skipping 10 matching lines...) Expand all
583 static void VideoRendererImplTest_FlushDoneCB(VideoRendererImplTest* test, 579 static void VideoRendererImplTest_FlushDoneCB(VideoRendererImplTest* test,
584 VideoRenderer* renderer, 580 VideoRenderer* renderer,
585 const base::Closure& success_cb) { 581 const base::Closure& success_cb) {
586 test->QueueFrames("0 10 20 30"); 582 test->QueueFrames("0 10 20 30");
587 renderer->StartPlayingFrom(base::TimeDelta::FromSeconds(0)); 583 renderer->StartPlayingFrom(base::TimeDelta::FromSeconds(0));
588 success_cb.Run(); 584 success_cb.Run();
589 } 585 }
590 586
591 TEST_F(VideoRendererImplTest, FlushCallbackNoLock) { 587 TEST_F(VideoRendererImplTest, FlushCallbackNoLock) {
592 Initialize(); 588 Initialize();
593 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 589 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
594 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 590 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
595 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 591 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
596 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 592 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
597 StartPlayingFrom(0); 593 StartPlayingFrom(0);
598 WaitableMessageLoopEvent event; 594 WaitableMessageLoopEvent event;
599 renderer_->Flush( 595 renderer_->Flush(
600 base::Bind(&VideoRendererImplTest_FlushDoneCB, base::Unretained(this), 596 base::Bind(&VideoRendererImplTest_FlushDoneCB, base::Unretained(this),
601 base::Unretained(renderer_.get()), event.GetClosure())); 597 base::Unretained(renderer_.get()), event.GetClosure()));
602 event.RunAndWait(); 598 event.RunAndWait();
603 Destroy(); 599 Destroy();
(...skipping 30 matching lines...) Expand all
634 QueueFrames("error"); 630 QueueFrames("error");
635 EXPECT_CALL(mock_cb_, OnError(PIPELINE_ERROR_DECODE)); 631 EXPECT_CALL(mock_cb_, OnError(PIPELINE_ERROR_DECODE));
636 StartPlayingFrom(0); 632 StartPlayingFrom(0);
637 Destroy(); 633 Destroy();
638 } 634 }
639 635
640 TEST_F(VideoRendererImplTest, StartPlayingFrom_Exact) { 636 TEST_F(VideoRendererImplTest, StartPlayingFrom_Exact) {
641 Initialize(); 637 Initialize();
642 QueueFrames("50 60 70 80 90"); 638 QueueFrames("50 60 70 80 90");
643 639
644 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))); 640 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(60)));
645 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 641 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
646 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 642 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
647 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 643 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
648 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 644 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
649 StartPlayingFrom(60); 645 StartPlayingFrom(60);
650 Destroy(); 646 Destroy();
651 } 647 }
652 648
653 TEST_F(VideoRendererImplTest, StartPlayingFrom_RightBefore) { 649 TEST_F(VideoRendererImplTest, StartPlayingFrom_RightBefore) {
654 Initialize(); 650 Initialize();
655 QueueFrames("50 60 70 80 90"); 651 QueueFrames("50 60 70 80 90");
656 652
657 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(50))); 653 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(50)));
658 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 654 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
659 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 655 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
660 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 656 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
661 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 657 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
662 StartPlayingFrom(59); 658 StartPlayingFrom(59);
663 Destroy(); 659 Destroy();
664 } 660 }
665 661
666 TEST_F(VideoRendererImplTest, StartPlayingFrom_RightAfter) { 662 TEST_F(VideoRendererImplTest, StartPlayingFrom_RightAfter) {
667 Initialize(); 663 Initialize();
668 QueueFrames("50 60 70 80 90"); 664 QueueFrames("50 60 70 80 90");
669 665
670 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(60))); 666 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(60)));
671 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 667 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
672 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 668 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
673 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 669 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
674 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 670 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
675 StartPlayingFrom(61); 671 StartPlayingFrom(61);
676 Destroy(); 672 Destroy();
677 } 673 }
678 674
679 TEST_F(VideoRendererImplTest, StartPlayingFrom_LowDelay) { 675 TEST_F(VideoRendererImplTest, StartPlayingFrom_LowDelay) {
680 // In low-delay mode only one frame is required to finish preroll. But frames 676 // In low-delay mode only one frame is required to finish preroll. But frames
681 // prior to the start time will not be used. 677 // prior to the start time will not be used.
682 InitializeWithLowDelay(true); 678 InitializeWithLowDelay(true);
683 QueueFrames("0 10"); 679 QueueFrames("0 10");
684 680
685 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))); 681 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(10)));
686 // Expect some amount of have enough/nothing due to only requiring one frame. 682 // Expect some amount of have enough/nothing due to only requiring one frame.
687 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) 683 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
688 .Times(AnyNumber()); 684 .Times(AnyNumber());
689 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) 685 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING))
690 .Times(AnyNumber()); 686 .Times(AnyNumber());
691 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 687 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
692 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 688 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
693 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 689 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
694 StartPlayingFrom(10); 690 StartPlayingFrom(10);
695 691
696 QueueFrames("20"); 692 QueueFrames("20");
697 SatisfyPendingDecode(); 693 SatisfyPendingDecode();
698 694
699 renderer_->OnTimeStateChanged(true); 695 renderer_->OnTimeStateChanged(true);
700 time_source_.StartTicking(); 696 time_source_.StartTicking();
701 697
702 WaitableMessageLoopEvent event; 698 WaitableMessageLoopEvent event;
703 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(20))) 699 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(20)))
704 .WillOnce(RunClosure(event.GetClosure())); 700 .WillOnce(RunClosure(event.GetClosure()));
705 AdvanceTimeInMs(20); 701 AdvanceTimeInMs(20);
706 event.RunAndWait(); 702 event.RunAndWait();
707 703
708 Destroy(); 704 Destroy();
709 } 705 }
710 706
711 // Verify that a late decoder response doesn't break invariants in the renderer. 707 // Verify that a late decoder response doesn't break invariants in the renderer.
712 TEST_F(VideoRendererImplTest, DestroyDuringOutstandingRead) { 708 TEST_F(VideoRendererImplTest, DestroyDuringOutstandingRead) {
713 Initialize(); 709 Initialize();
714 QueueFrames("0 10 20 30"); 710 QueueFrames("0 10 20 30");
715 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 711 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
716 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 712 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
717 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 713 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
718 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 714 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
719 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 715 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
720 StartPlayingFrom(0); 716 StartPlayingFrom(0);
721 717
722 // Check that there is an outstanding Read() request. 718 // Check that there is an outstanding Read() request.
723 EXPECT_TRUE(IsReadPending()); 719 EXPECT_TRUE(IsReadPending());
724 720
725 Destroy(); 721 Destroy();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 758 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
763 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 759 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
764 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 760 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
765 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 761 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
766 EXPECT_CALL(mock_cb_, OnEnded()).Times(0); 762 EXPECT_CALL(mock_cb_, OnEnded()).Times(0);
767 763
768 { 764 {
769 SCOPED_TRACE("Waiting for first frame to be painted."); 765 SCOPED_TRACE("Waiting for first frame to be painted.");
770 WaitableMessageLoopEvent event; 766 WaitableMessageLoopEvent event;
771 767
772 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))) 768 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)))
773 .WillOnce(RunClosure(event.GetClosure())); 769 .WillOnce(RunClosure(event.GetClosure()));
774 StartPlayingFrom(0); 770 StartPlayingFrom(0);
775 771
776 EXPECT_TRUE(IsReadPending()); 772 EXPECT_TRUE(IsReadPending());
777 SatisfyPendingDecodeWithEndOfStream(); 773 SatisfyPendingDecodeWithEndOfStream();
778 774
779 event.RunAndWait(); 775 event.RunAndWait();
780 } 776 }
781 777
782 Destroy(); 778 Destroy();
783 } 779 }
784 780
785 // Verifies that the sink is stopped after rendering the first frame if 781 // Verifies that the sink is stopped after rendering the first frame if
786 // playback has started. 782 // playback has started.
787 TEST_F(VideoRendererImplTest, RenderingStopsAfterOneFrameWithEOS) { 783 TEST_F(VideoRendererImplTest, RenderingStopsAfterOneFrameWithEOS) {
788 InitializeWithLowDelay(true); 784 InitializeWithLowDelay(true);
789 QueueFrames("0"); 785 QueueFrames("0");
790 786
791 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))).Times(1); 787 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0))).Times(1);
792 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 788 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
793 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 789 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
794 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 790 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
795 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 791 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
796 792
797 { 793 {
798 SCOPED_TRACE("Waiting for sink to stop."); 794 SCOPED_TRACE("Waiting for sink to stop.");
799 WaitableMessageLoopEvent event; 795 WaitableMessageLoopEvent event;
800 796
801 null_video_sink_->set_stop_cb(event.GetClosure()); 797 null_video_sink_->set_stop_cb(event.GetClosure());
(...skipping 21 matching lines...) Expand all
823 // zero value, once we have some decoded frames they should be overwritten. 819 // zero value, once we have some decoded frames they should be overwritten.
824 PipelineStatistics last_pipeline_statistics; 820 PipelineStatistics last_pipeline_statistics;
825 last_pipeline_statistics.video_frames_dropped = 1; 821 last_pipeline_statistics.video_frames_dropped = 1;
826 { 822 {
827 WaitableMessageLoopEvent event; 823 WaitableMessageLoopEvent event;
828 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) 824 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
829 .WillOnce(RunClosure(event.GetClosure())); 825 .WillOnce(RunClosure(event.GetClosure()));
830 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)) 826 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_))
831 .Times(4) 827 .Times(4)
832 .WillRepeatedly(SaveArg<0>(&last_pipeline_statistics)); 828 .WillRepeatedly(SaveArg<0>(&last_pipeline_statistics));
833 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 829 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
834 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 830 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
835 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 831 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
836 StartPlayingFrom(0); 832 StartPlayingFrom(0);
837 event.RunAndWait(); 833 event.RunAndWait();
838 Mock::VerifyAndClearExpectations(&mock_cb_); 834 Mock::VerifyAndClearExpectations(&mock_cb_);
839 } 835 }
840 836
841 // Four calls to update statistics should have been made, each reporting a 837 // Four calls to update statistics should have been made, each reporting a
842 // single decoded frame and one frame worth of memory usage. No dropped frames 838 // single decoded frame and one frame worth of memory usage. No dropped frames
843 // should be reported later since we're in background rendering mode. These 839 // should be reported later since we're in background rendering mode. These
(...skipping 11 matching lines...) Expand all
855 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)) 851 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING))
856 .Times(testing::AtMost(1)); 852 .Times(testing::AtMost(1));
857 renderer_->OnTimeStateChanged(true); 853 renderer_->OnTimeStateChanged(true);
858 time_source_.StartTicking(); 854 time_source_.StartTicking();
859 855
860 // Suspend all future callbacks and synthetically advance the media time, 856 // Suspend all future callbacks and synthetically advance the media time,
861 // because this is a background render, we won't underflow by waiting until 857 // because this is a background render, we won't underflow by waiting until
862 // a pending read is ready. 858 // a pending read is ready.
863 null_video_sink_->set_background_render(true); 859 null_video_sink_->set_background_render(true);
864 AdvanceTimeInMs(91); 860 AdvanceTimeInMs(91);
865 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(90))); 861 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(90)));
866 WaitForPendingDecode(); 862 WaitForPendingDecode();
867 SatisfyPendingDecodeWithEndOfStream(); 863 SatisfyPendingDecodeWithEndOfStream();
868 864
869 AdvanceTimeInMs(30); 865 AdvanceTimeInMs(30);
870 WaitForEnded(); 866 WaitForEnded();
871 Destroy(); 867 Destroy();
872 } 868 }
873 869
874 // Tests the case where underflow evicts all frames before EOS. 870 // Tests the case where underflow evicts all frames before EOS.
875 TEST_F(VideoRendererImplTest, UnderflowEvictionBeforeEOS) { 871 TEST_F(VideoRendererImplTest, UnderflowEvictionBeforeEOS) {
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after
911 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 907 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
912 WaitForEnded(); 908 WaitForEnded();
913 Destroy(); 909 Destroy();
914 } 910 }
915 911
916 TEST_F(VideoRendererImplTest, StartPlayingFromThenFlushThenEOS) { 912 TEST_F(VideoRendererImplTest, StartPlayingFromThenFlushThenEOS) {
917 Initialize(); 913 Initialize();
918 QueueFrames("0 30 60 90"); 914 QueueFrames("0 30 60 90");
919 915
920 WaitableMessageLoopEvent event; 916 WaitableMessageLoopEvent event;
921 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 917 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
922 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) 918 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
923 .WillOnce(RunClosure(event.GetClosure())); 919 .WillOnce(RunClosure(event.GetClosure()));
924 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 920 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
925 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 921 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
926 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 922 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
927 StartPlayingFrom(0); 923 StartPlayingFrom(0);
928 event.RunAndWait(); 924 event.RunAndWait();
929 925
930 // Cycle ticking so that we get a non-null reference time. 926 // Cycle ticking so that we get a non-null reference time.
931 time_source_.StartTicking(); 927 time_source_.StartTicking();
(...skipping 16 matching lines...) Expand all
948 Initialize(); 944 Initialize();
949 // !CanReadWithoutStalling() puts the renderer in state BUFFERING_HAVE_ENOUGH 945 // !CanReadWithoutStalling() puts the renderer in state BUFFERING_HAVE_ENOUGH
950 // after the first frame. 946 // after the first frame.
951 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false)); 947 ON_CALL(*decoder_, CanReadWithoutStalling()).WillByDefault(Return(false));
952 // Set background rendering to simulate the first couple of Render() calls 948 // Set background rendering to simulate the first couple of Render() calls
953 // by VFC. 949 // by VFC.
954 null_video_sink_->set_background_render(true); 950 null_video_sink_->set_background_render(true);
955 QueueFrames("0 10 20"); 951 QueueFrames("0 10 20");
956 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)) 952 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH))
957 .Times(testing::AtMost(1)); 953 .Times(testing::AtMost(1));
958 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 954 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
959 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 955 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
960 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 956 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
961 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 957 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
962 StartPlayingFrom(0); 958 StartPlayingFrom(0);
963 959
964 renderer_->OnTimeStateChanged(true); 960 renderer_->OnTimeStateChanged(true);
965 time_source_.StartTicking(); 961 time_source_.StartTicking();
966 962
967 WaitableMessageLoopEvent event; 963 WaitableMessageLoopEvent event;
968 // Frame "10" should not have been expired. 964 // Frame "10" should not have been expired.
969 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))) 965 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(10)))
970 .WillOnce(RunClosure(event.GetClosure())); 966 .WillOnce(RunClosure(event.GetClosure()));
971 AdvanceTimeInMs(10); 967 AdvanceTimeInMs(10);
972 event.RunAndWait(); 968 event.RunAndWait();
973 969
974 Destroy(); 970 Destroy();
975 } 971 }
976 972
977 TEST_F(VideoRendererImplTest, NaturalSizeChange) { 973 TEST_F(VideoRendererImplTest, NaturalSizeChange) {
978 Initialize(); 974 Initialize();
979 975
(...skipping 17 matching lines...) Expand all
997 gfx::Rect(initial_size), initial_size, 993 gfx::Rect(initial_size), initial_size,
998 base::TimeDelta::FromMilliseconds(30))); 994 base::TimeDelta::FromMilliseconds(30)));
999 995
1000 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 996 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
1001 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 997 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
1002 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 998 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
1003 999
1004 { 1000 {
1005 // Callback is fired for the first frame. 1001 // Callback is fired for the first frame.
1006 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(initial_size)); 1002 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(initial_size));
1007 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 1003 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
1008 StartPlayingFrom(0); 1004 StartPlayingFrom(0);
1009 renderer_->OnTimeStateChanged(true); 1005 renderer_->OnTimeStateChanged(true);
1010 time_source_.StartTicking(); 1006 time_source_.StartTicking();
1011 } 1007 }
1012 { 1008 {
1013 // Callback should be fired once when switching to the larger size. 1009 // Callback should be fired once when switching to the larger size.
1014 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(larger_size)); 1010 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(larger_size));
1015 WaitableMessageLoopEvent event; 1011 WaitableMessageLoopEvent event;
1016 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))) 1012 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(10)))
1017 .WillOnce(RunClosure(event.GetClosure())); 1013 .WillOnce(RunClosure(event.GetClosure()));
1018 AdvanceTimeInMs(10); 1014 AdvanceTimeInMs(10);
1019 event.RunAndWait(); 1015 event.RunAndWait();
1020 } 1016 }
1021 { 1017 {
1022 // Called is not fired because frame size does not change. 1018 // Called is not fired because frame size does not change.
1023 WaitableMessageLoopEvent event; 1019 WaitableMessageLoopEvent event;
1024 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(20))) 1020 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(20)))
1025 .WillOnce(RunClosure(event.GetClosure())); 1021 .WillOnce(RunClosure(event.GetClosure()));
1026 AdvanceTimeInMs(10); 1022 AdvanceTimeInMs(10);
1027 event.RunAndWait(); 1023 event.RunAndWait();
1028 } 1024 }
1029 { 1025 {
1030 // Callback is fired once when switching to the larger size. 1026 // Callback is fired once when switching to the larger size.
1031 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(initial_size)); 1027 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(initial_size));
1032 WaitableMessageLoopEvent event; 1028 WaitableMessageLoopEvent event;
1033 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(30))) 1029 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(30)))
1034 .WillOnce(RunClosure(event.GetClosure())); 1030 .WillOnce(RunClosure(event.GetClosure()));
1035 AdvanceTimeInMs(10); 1031 AdvanceTimeInMs(10);
1036 event.RunAndWait(); 1032 event.RunAndWait();
1037 } 1033 }
1038 1034
1039 Destroy(); 1035 Destroy();
1040 } 1036 }
1041 1037
1042 TEST_F(VideoRendererImplTest, OpacityChange) { 1038 TEST_F(VideoRendererImplTest, OpacityChange) {
1043 Initialize(); 1039 Initialize();
(...skipping 19 matching lines...) Expand all
1063 gfx::Rect(frame_size), frame_size, 1059 gfx::Rect(frame_size), frame_size,
1064 base::TimeDelta::FromMilliseconds(30))); 1060 base::TimeDelta::FromMilliseconds(30)));
1065 1061
1066 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 1062 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
1067 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 1063 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
1068 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(frame_size)).Times(1); 1064 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(frame_size)).Times(1);
1069 1065
1070 { 1066 {
1071 // Callback is fired for the first frame. 1067 // Callback is fired for the first frame.
1072 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(false)); 1068 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(false));
1073 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 1069 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
1074 StartPlayingFrom(0); 1070 StartPlayingFrom(0);
1075 renderer_->OnTimeStateChanged(true); 1071 renderer_->OnTimeStateChanged(true);
1076 time_source_.StartTicking(); 1072 time_source_.StartTicking();
1077 } 1073 }
1078 { 1074 {
1079 // Callback is not fired because opacity does not change. 1075 // Callback is not fired because opacity does not change.
1080 WaitableMessageLoopEvent event; 1076 WaitableMessageLoopEvent event;
1081 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(10))) 1077 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(10)))
1082 .WillOnce(RunClosure(event.GetClosure())); 1078 .WillOnce(RunClosure(event.GetClosure()));
1083 AdvanceTimeInMs(10); 1079 AdvanceTimeInMs(10);
1084 event.RunAndWait(); 1080 event.RunAndWait();
1085 } 1081 }
1086 { 1082 {
1087 // Called is fired when opacity changes. 1083 // Called is fired when opacity changes.
1088 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(true)); 1084 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(true));
1089 WaitableMessageLoopEvent event; 1085 WaitableMessageLoopEvent event;
1090 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(20))) 1086 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(20)))
1091 .WillOnce(RunClosure(event.GetClosure())); 1087 .WillOnce(RunClosure(event.GetClosure()));
1092 AdvanceTimeInMs(10); 1088 AdvanceTimeInMs(10);
1093 event.RunAndWait(); 1089 event.RunAndWait();
1094 } 1090 }
1095 { 1091 {
1096 // Callback is not fired because opacity does not change. 1092 // Callback is not fired because opacity does not change.
1097 WaitableMessageLoopEvent event; 1093 WaitableMessageLoopEvent event;
1098 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(30))) 1094 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(30)))
1099 .WillOnce(RunClosure(event.GetClosure())); 1095 .WillOnce(RunClosure(event.GetClosure()));
1100 AdvanceTimeInMs(10); 1096 AdvanceTimeInMs(10);
1101 event.RunAndWait(); 1097 event.RunAndWait();
1102 } 1098 }
1103 1099
1104 Destroy(); 1100 Destroy();
1105 } 1101 }
1106 1102
1107 class VideoRendererImplAsyncAddFrameReadyTest : public VideoRendererImplTest { 1103 class VideoRendererImplAsyncAddFrameReadyTest : public VideoRendererImplTest {
1108 public: 1104 public:
1109 VideoRendererImplAsyncAddFrameReadyTest() { 1105 VideoRendererImplAsyncAddFrameReadyTest() {
1110 std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_memory_buffer_pool( 1106 std::unique_ptr<GpuMemoryBufferVideoFramePool> gpu_memory_buffer_pool(
1111 new MockGpuMemoryBufferVideoFramePool(&frame_ready_cbs_)); 1107 new MockGpuMemoryBufferVideoFramePool(&frame_ready_cbs_));
1112 renderer_->SetGpuMemoryBufferVideoForTesting( 1108 renderer_->SetGpuMemoryBufferVideoForTesting(
1113 std::move(gpu_memory_buffer_pool)); 1109 std::move(gpu_memory_buffer_pool));
1114 } 1110 }
1115 1111
1116 protected: 1112 protected:
1117 std::vector<base::Closure> frame_ready_cbs_; 1113 std::vector<base::Closure> frame_ready_cbs_;
1118 }; 1114 };
1119 1115
1120 TEST_F(VideoRendererImplAsyncAddFrameReadyTest, InitializeAndStartPlayingFrom) { 1116 TEST_F(VideoRendererImplAsyncAddFrameReadyTest, InitializeAndStartPlayingFrom) {
1121 Initialize(); 1117 Initialize();
1122 QueueFrames("0 10 20 30"); 1118 QueueFrames("0 10 20 30");
1123 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestamp(0))); 1119 EXPECT_CALL(mock_cb_, FrameReceived(HasTimestampMatcher(0)));
1124 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); 1120 EXPECT_CALL(mock_cb_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH));
1125 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber()); 1121 EXPECT_CALL(mock_cb_, OnStatisticsUpdate(_)).Times(AnyNumber());
1126 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1); 1122 EXPECT_CALL(mock_cb_, OnVideoNaturalSizeChange(_)).Times(1);
1127 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1); 1123 EXPECT_CALL(mock_cb_, OnVideoOpacityChange(_)).Times(1);
1128 StartPlayingFrom(0); 1124 StartPlayingFrom(0);
1129 ASSERT_EQ(1u, frame_ready_cbs_.size()); 1125 ASSERT_EQ(1u, frame_ready_cbs_.size());
1130 1126
1131 uint32_t frame_ready_index = 0; 1127 uint32_t frame_ready_index = 0;
1132 while (frame_ready_index < frame_ready_cbs_.size()) { 1128 while (frame_ready_index < frame_ready_cbs_.size()) {
1133 frame_ready_cbs_[frame_ready_index++].Run(); 1129 frame_ready_cbs_[frame_ready_index++].Run();
1134 base::RunLoop().RunUntilIdle(); 1130 base::RunLoop().RunUntilIdle();
1135 } 1131 }
1136 Destroy(); 1132 Destroy();
1137 } 1133 }
1138 1134
1139 TEST_F(VideoRendererImplAsyncAddFrameReadyTest, WeakFactoryDiscardsOneFrame) { 1135 TEST_F(VideoRendererImplAsyncAddFrameReadyTest, WeakFactoryDiscardsOneFrame) {
1140 Initialize(); 1136 Initialize();
1141 QueueFrames("0 10 20 30"); 1137 QueueFrames("0 10 20 30");
1142 StartPlayingFrom(0); 1138 StartPlayingFrom(0);
1143 Flush(); 1139 Flush();
1144 ASSERT_EQ(1u, frame_ready_cbs_.size()); 1140 ASSERT_EQ(1u, frame_ready_cbs_.size());
1145 // This frame will be discarded. 1141 // This frame will be discarded.
1146 frame_ready_cbs_.front().Run(); 1142 frame_ready_cbs_.front().Run();
1147 Destroy(); 1143 Destroy();
1148 } 1144 }
1149 1145
1150 } // namespace media 1146 } // namespace media
OLDNEW
« media/filters/media_source_state_unittest.cc ('K') | « media/filters/media_source_state_unittest.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698