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

Side by Side Diff: media/base/pipeline_unittest.cc

Issue 294133003: Extract media::Clock::IsPlaying() into media::Pipeline::ClockState enum. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fixes + rebase Created 6 years, 7 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 | Annotate | Revision Log
« no previous file with comments | « media/base/pipeline.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 <vector> 5 #include <vector>
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/stl_util.h" 9 #include "base/stl_util.h"
10 #include "base/test/simple_test_tick_clock.h" 10 #include "base/test/simple_test_tick_clock.h"
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
589 589
590 AddTextStream(); 590 AddTextStream();
591 591
592 // The ended callback shouldn't run until all renderers have ended. 592 // The ended callback shouldn't run until all renderers have ended.
593 pipeline_->OnAudioRendererEnded(); 593 pipeline_->OnAudioRendererEnded();
594 message_loop_.RunUntilIdle(); 594 message_loop_.RunUntilIdle();
595 595
596 pipeline_->OnVideoRendererEnded(); 596 pipeline_->OnVideoRendererEnded();
597 message_loop_.RunUntilIdle(); 597 message_loop_.RunUntilIdle();
598 598
599 EXPECT_CALL(*audio_renderer_, StopRendering());
599 EXPECT_CALL(callbacks_, OnEnded()); 600 EXPECT_CALL(callbacks_, OnEnded());
600 text_stream()->SendEosNotification(); 601 text_stream()->SendEosNotification();
601 message_loop_.RunUntilIdle(); 602 message_loop_.RunUntilIdle();
602 } 603 }
603 604
604 TEST_F(PipelineTest, AudioStreamShorterThanVideo) { 605 TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
605 base::TimeDelta duration = base::TimeDelta::FromSeconds(10); 606 base::TimeDelta duration = base::TimeDelta::FromSeconds(10);
606 607
607 CreateAudioStream(); 608 CreateAudioStream();
608 CreateVideoStream(); 609 CreateVideoStream();
(...skipping 29 matching lines...) Expand all
638 // Signal end of audio stream. 639 // Signal end of audio stream.
639 pipeline_->OnAudioRendererEnded(); 640 pipeline_->OnAudioRendererEnded();
640 message_loop_.RunUntilIdle(); 641 message_loop_.RunUntilIdle();
641 642
642 // Verify that the clock advances. 643 // Verify that the clock advances.
643 start_time = pipeline_->GetMediaTime().ToInternalValue(); 644 start_time = pipeline_->GetMediaTime().ToInternalValue();
644 test_tick_clock_.Advance(base::TimeDelta::FromMilliseconds(100)); 645 test_tick_clock_.Advance(base::TimeDelta::FromMilliseconds(100));
645 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time); 646 EXPECT_GT(pipeline_->GetMediaTime().ToInternalValue(), start_time);
646 647
647 // Signal end of video stream and make sure OnEnded() callback occurs. 648 // Signal end of video stream and make sure OnEnded() callback occurs.
649 EXPECT_CALL(*audio_renderer_, StopRendering());
648 EXPECT_CALL(callbacks_, OnEnded()); 650 EXPECT_CALL(callbacks_, OnEnded());
649 pipeline_->OnVideoRendererEnded(); 651 pipeline_->OnVideoRendererEnded();
650 } 652 }
651 653
652 TEST_F(PipelineTest, ErrorDuringSeek) { 654 TEST_F(PipelineTest, ErrorDuringSeek) {
653 CreateAudioStream(); 655 CreateAudioStream();
654 MockDemuxerStreamVector streams; 656 MockDemuxerStreamVector streams;
655 streams.push_back(audio_stream()); 657 streams.push_back(audio_stream());
656 658
657 InitializeDemuxer(&streams); 659 InitializeDemuxer(&streams);
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
851 pipeline->Stop(base::Bind(&DeletePipeline, base::Passed(&pipeline_))); 853 pipeline->Stop(base::Bind(&DeletePipeline, base::Passed(&pipeline_)));
852 message_loop_.RunUntilIdle(); 854 message_loop_.RunUntilIdle();
853 } 855 }
854 856
855 class PipelineTeardownTest : public PipelineTest { 857 class PipelineTeardownTest : public PipelineTest {
856 public: 858 public:
857 enum TeardownState { 859 enum TeardownState {
858 kInitDemuxer, 860 kInitDemuxer,
859 kInitAudioRenderer, 861 kInitAudioRenderer,
860 kInitVideoRenderer, 862 kInitVideoRenderer,
861 kPausing,
862 kFlushing, 863 kFlushing,
863 kSeeking, 864 kSeeking,
864 kPrerolling, 865 kPrerolling,
865 kPlaying, 866 kPlaying,
866 }; 867 };
867 868
868 enum StopOrError { 869 enum StopOrError {
869 kStop, 870 kStop,
870 kError, 871 kError,
871 kErrorAndStop, 872 kErrorAndStop,
872 }; 873 };
873 874
874 PipelineTeardownTest() {} 875 PipelineTeardownTest() {}
875 virtual ~PipelineTeardownTest() {} 876 virtual ~PipelineTeardownTest() {}
876 877
877 void RunTest(TeardownState state, StopOrError stop_or_error) { 878 void RunTest(TeardownState state, StopOrError stop_or_error) {
878 switch (state) { 879 switch (state) {
879 case kInitDemuxer: 880 case kInitDemuxer:
880 case kInitAudioRenderer: 881 case kInitAudioRenderer:
881 case kInitVideoRenderer: 882 case kInitVideoRenderer:
882 DoInitialize(state, stop_or_error); 883 DoInitialize(state, stop_or_error);
883 break; 884 break;
884 885
885 case kPausing:
886 case kFlushing: 886 case kFlushing:
887 case kSeeking: 887 case kSeeking:
888 case kPrerolling: 888 case kPrerolling:
889 DoInitialize(state, stop_or_error); 889 DoInitialize(state, stop_or_error);
890 DoSeek(state, stop_or_error); 890 DoSeek(state, stop_or_error);
891 break; 891 break;
892 892
893 case kPlaying: 893 case kPlaying:
894 DoInitialize(state, stop_or_error); 894 DoInitialize(state, stop_or_error);
895 DoStopOrError(stop_or_error); 895 DoStopOrError(stop_or_error);
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after
1028 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); 1028 &CallbackHelper::OnSeek, base::Unretained(&callbacks_)));
1029 message_loop_.RunUntilIdle(); 1029 message_loop_.RunUntilIdle();
1030 } 1030 }
1031 1031
1032 PipelineStatus SetSeekExpectations(TeardownState state, 1032 PipelineStatus SetSeekExpectations(TeardownState state,
1033 StopOrError stop_or_error) { 1033 StopOrError stop_or_error) {
1034 PipelineStatus status = PIPELINE_OK; 1034 PipelineStatus status = PIPELINE_OK;
1035 base::Closure stop_cb = base::Bind( 1035 base::Closure stop_cb = base::Bind(
1036 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); 1036 &CallbackHelper::OnStop, base::Unretained(&callbacks_));
1037 1037
1038 if (state == kPausing) {
1039 if (stop_or_error == kStop) {
1040 EXPECT_CALL(*audio_renderer_, StopRendering())
1041 .WillOnce(Stop(pipeline_.get(), stop_cb));
1042 } else {
1043 status = PIPELINE_ERROR_READ;
1044 EXPECT_CALL(*audio_renderer_, StopRendering())
1045 .WillOnce(SetError(pipeline_.get(), status));
1046 }
1047
1048 return status;
1049 }
1050
1051 EXPECT_CALL(*audio_renderer_, StopRendering()); 1038 EXPECT_CALL(*audio_renderer_, StopRendering());
1052 1039
1053 if (state == kFlushing) { 1040 if (state == kFlushing) {
1054 if (stop_or_error == kStop) { 1041 if (stop_or_error == kStop) {
1055 EXPECT_CALL(*audio_renderer_, Flush(_)) 1042 EXPECT_CALL(*audio_renderer_, Flush(_))
1056 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), RunClosure<0>())); 1043 .WillOnce(DoAll(Stop(pipeline_.get(), stop_cb), RunClosure<0>()));
1057 } else { 1044 } else {
1058 status = PIPELINE_ERROR_READ; 1045 status = PIPELINE_ERROR_READ;
1059 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce( 1046 EXPECT_CALL(*audio_renderer_, Flush(_)).WillOnce(
1060 DoAll(SetError(pipeline_.get(), status), RunClosure<0>())); 1047 DoAll(SetError(pipeline_.get(), status), RunClosure<0>()));
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1145 }; 1132 };
1146 1133
1147 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ 1134 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \
1148 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ 1135 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \
1149 RunTest(k##state, k##stop_or_error); \ 1136 RunTest(k##state, k##stop_or_error); \
1150 } 1137 }
1151 1138
1152 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer); 1139 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer);
1153 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioRenderer); 1140 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioRenderer);
1154 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoRenderer); 1141 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoRenderer);
1155 INSTANTIATE_TEARDOWN_TEST(Stop, Pausing);
1156 INSTANTIATE_TEARDOWN_TEST(Stop, Flushing); 1142 INSTANTIATE_TEARDOWN_TEST(Stop, Flushing);
1157 INSTANTIATE_TEARDOWN_TEST(Stop, Seeking); 1143 INSTANTIATE_TEARDOWN_TEST(Stop, Seeking);
1158 INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling); 1144 INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling);
1159 INSTANTIATE_TEARDOWN_TEST(Stop, Playing); 1145 INSTANTIATE_TEARDOWN_TEST(Stop, Playing);
1160 1146
1161 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); 1147 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer);
1162 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer); 1148 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer);
1163 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer); 1149 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer);
1164 INSTANTIATE_TEARDOWN_TEST(Error, Pausing);
1165 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); 1150 INSTANTIATE_TEARDOWN_TEST(Error, Flushing);
1166 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 1151 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1167 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); 1152 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling);
1168 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 1153 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1169 1154
1170 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); 1155 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing);
1171 1156
1172 } // namespace media 1157 } // namespace media
OLDNEW
« no previous file with comments | « media/base/pipeline.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698