Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 <vector> | 5 #include <vector> |
| 6 | 6 |
| 7 #include "base/bind.h" | 7 #include "base/bind.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/threading/simple_thread.h" | 10 #include "base/threading/simple_thread.h" |
| (...skipping 557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 568 | 568 |
| 569 InitializePipeline(PIPELINE_OK); | 569 InitializePipeline(PIPELINE_OK); |
| 570 EXPECT_TRUE(pipeline_->IsInitialized()); | 570 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 571 EXPECT_TRUE(pipeline_->HasAudio()); | 571 EXPECT_TRUE(pipeline_->HasAudio()); |
| 572 EXPECT_TRUE(pipeline_->HasVideo()); | 572 EXPECT_TRUE(pipeline_->HasVideo()); |
| 573 | 573 |
| 574 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); | 574 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); |
| 575 pipeline_->OnAudioDisabled(); | 575 pipeline_->OnAudioDisabled(); |
| 576 | 576 |
| 577 // Verify that ended event is fired when video ends. | 577 // Verify that ended event is fired when video ends. |
| 578 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | |
| 579 .WillOnce(Return(true)); | |
| 580 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 578 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 581 pipeline_->OnRendererEnded(); | 579 pipeline_->OnVideoRendererEnded(); |
| 582 } | 580 } |
| 583 | 581 |
| 584 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { | 582 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { |
| 585 CreateAudioStream(); | 583 CreateAudioStream(); |
| 586 CreateVideoStream(); | 584 CreateVideoStream(); |
| 587 MockDemuxerStreamVector streams; | 585 MockDemuxerStreamVector streams; |
| 588 streams.push_back(audio_stream()); | 586 streams.push_back(audio_stream()); |
| 589 streams.push_back(video_stream()); | 587 streams.push_back(video_stream()); |
| 590 | 588 |
| 591 InitializeDemuxer(&streams); | 589 InitializeDemuxer(&streams); |
| 592 InitializeAudioDecoder(audio_stream()); | 590 InitializeAudioDecoder(audio_stream()); |
| 593 InitializeAudioRenderer(true); | 591 InitializeAudioRenderer(true); |
| 594 InitializeVideoDecoder(video_stream()); | 592 InitializeVideoDecoder(video_stream()); |
| 595 InitializeVideoRenderer(); | 593 InitializeVideoRenderer(); |
| 596 | 594 |
| 597 EXPECT_CALL(*mocks_->demuxer(), | 595 EXPECT_CALL(*mocks_->demuxer(), |
| 598 OnAudioRendererDisabled()); | 596 OnAudioRendererDisabled()); |
| 599 | 597 |
| 600 InitializePipeline(PIPELINE_OK); | 598 InitializePipeline(PIPELINE_OK); |
| 601 EXPECT_TRUE(pipeline_->IsInitialized()); | 599 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 602 EXPECT_FALSE(pipeline_->HasAudio()); | 600 EXPECT_FALSE(pipeline_->HasAudio()); |
| 603 EXPECT_TRUE(pipeline_->HasVideo()); | 601 EXPECT_TRUE(pipeline_->HasVideo()); |
| 604 | 602 |
| 605 // Verify that ended event is fired when video ends. | 603 // Verify that ended event is fired when video ends. |
| 606 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | |
| 607 .WillOnce(Return(true)); | |
| 608 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 604 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 609 pipeline_->OnRendererEnded(); | 605 pipeline_->OnVideoRendererEnded(); |
| 610 } | 606 } |
| 611 | 607 |
| 612 TEST_F(PipelineTest, EndedCallback) { | 608 TEST_F(PipelineTest, EndedCallback) { |
| 613 CreateAudioStream(); | 609 CreateAudioStream(); |
| 614 CreateVideoStream(); | 610 CreateVideoStream(); |
| 615 MockDemuxerStreamVector streams; | 611 MockDemuxerStreamVector streams; |
| 616 streams.push_back(audio_stream()); | 612 streams.push_back(audio_stream()); |
| 617 streams.push_back(video_stream()); | 613 streams.push_back(video_stream()); |
| 618 | 614 |
| 619 InitializeDemuxer(&streams); | 615 InitializeDemuxer(&streams); |
| 620 InitializeAudioDecoder(audio_stream()); | 616 InitializeAudioDecoder(audio_stream()); |
| 621 InitializeAudioRenderer(); | 617 InitializeAudioRenderer(); |
| 622 InitializeVideoDecoder(video_stream()); | 618 InitializeVideoDecoder(video_stream()); |
| 623 InitializeVideoRenderer(); | 619 InitializeVideoRenderer(); |
| 624 InitializePipeline(PIPELINE_OK); | 620 InitializePipeline(PIPELINE_OK); |
| 625 | 621 |
| 626 // Due to short circuit evaluation we only need to test a subset of cases. | 622 // The ended callback shouldn't run until both renderers have ended. |
|
Ami GONE FROM CHROMIUM
2012/08/08 21:48:26
Does this test fail if you move the EXPECT_CALL in
scherkus (not reviewing)
2012/08/08 22:28:34
Fails if you move it down a line but not up. Testi
| |
| 627 InSequence s; | 623 pipeline_->OnAudioRendererEnded(); |
| 628 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | |
| 629 .WillOnce(Return(false)); | |
| 630 pipeline_->OnRendererEnded(); | |
| 631 | 624 |
| 632 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | |
| 633 .WillOnce(Return(true)); | |
| 634 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | |
| 635 .WillOnce(Return(false)); | |
| 636 pipeline_->OnRendererEnded(); | |
| 637 | |
| 638 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | |
| 639 .WillOnce(Return(true)); | |
| 640 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | |
| 641 .WillOnce(Return(true)); | |
| 642 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 625 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 643 pipeline_->OnRendererEnded(); | 626 pipeline_->OnVideoRendererEnded(); |
| 644 } | 627 } |
| 645 | 628 |
| 646 // Static function & time variable used to simulate changes in wallclock time. | 629 // Static function & time variable used to simulate changes in wallclock time. |
| 647 static int64 g_static_clock_time; | 630 static int64 g_static_clock_time; |
| 648 static base::Time StaticClockFunction() { | 631 static base::Time StaticClockFunction() { |
| 649 return base::Time::FromInternalValue(g_static_clock_time); | 632 return base::Time::FromInternalValue(g_static_clock_time); |
| 650 } | 633 } |
| 651 | 634 |
| 652 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { | 635 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { |
| 653 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); | 636 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); |
| (...skipping 27 matching lines...) Expand all Loading... | |
| 681 InSequence s; | 664 InSequence s; |
| 682 | 665 |
| 683 // Verify that the clock doesn't advance since it hasn't been started by | 666 // Verify that the clock doesn't advance since it hasn't been started by |
| 684 // a time update from the audio stream. | 667 // a time update from the audio stream. |
| 685 int64 start_time = pipeline_->GetMediaTime().ToInternalValue(); | 668 int64 start_time = pipeline_->GetMediaTime().ToInternalValue(); |
| 686 g_static_clock_time += | 669 g_static_clock_time += |
| 687 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); | 670 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); |
| 688 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time); | 671 EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time); |
| 689 | 672 |
| 690 // Signal end of audio stream. | 673 // Signal end of audio stream. |
| 691 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 674 pipeline_->OnAudioRendererEnded(); |
| 692 .WillOnce(Return(true)); | |
| 693 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | |
| 694 .WillOnce(Return(false)); | |
| 695 pipeline_->OnRendererEnded(); | |
| 696 message_loop_.RunAllPending(); | 675 message_loop_.RunAllPending(); |
| 697 | 676 |
| 698 // Verify that the clock advances. | 677 // Verify that the clock advances. |
| 699 start_time = pipeline_->GetMediaTime().ToInternalValue(); | 678 start_time = pipeline_->GetMediaTime().ToInternalValue(); |
| 700 g_static_clock_time += | 679 g_static_clock_time += |
| 701 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); | 680 base::TimeDelta::FromMilliseconds(100).ToInternalValue(); |
| 702 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time); | 681 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time); |
| 703 | 682 |
| 704 // Signal end of video stream and make sure OnEnded() callback occurs. | 683 // Signal end of video stream and make sure OnEnded() callback occurs. |
| 705 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | |
| 706 .WillOnce(Return(true)); | |
| 707 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | |
| 708 .WillOnce(Return(true)); | |
| 709 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 684 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 710 pipeline_->OnRendererEnded(); | 685 pipeline_->OnVideoRendererEnded(); |
| 711 } | 686 } |
| 712 | 687 |
| 713 TEST_F(PipelineTest, ErrorDuringSeek) { | 688 TEST_F(PipelineTest, ErrorDuringSeek) { |
| 714 CreateAudioStream(); | 689 CreateAudioStream(); |
| 715 MockDemuxerStreamVector streams; | 690 MockDemuxerStreamVector streams; |
| 716 streams.push_back(audio_stream()); | 691 streams.push_back(audio_stream()); |
| 717 | 692 |
| 718 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 693 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); |
| 719 InitializeAudioDecoder(audio_stream()); | 694 InitializeAudioDecoder(audio_stream()); |
| 720 InitializeAudioRenderer(); | 695 InitializeAudioRenderer(); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 951 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); | 926 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); |
| 952 } | 927 } |
| 953 | 928 |
| 954 // Test that different-thread, some-delay callback (the expected common case) | 929 // Test that different-thread, some-delay callback (the expected common case) |
| 955 // works correctly. | 930 // works correctly. |
| 956 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 931 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
| 957 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 932 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
| 958 } | 933 } |
| 959 | 934 |
| 960 } // namespace media | 935 } // namespace media |
| OLD | NEW |