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

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

Issue 10834266: Fold Pipeline initialization failure tests added in r150636 into PipelineTeardownTest. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src
Patch Set: add video to seek tests Created 8 years, 4 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 | « no previous file | 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.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 860 matching lines...) Expand 10 before | Expand all | Expand 10 after
871 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); 871 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time);
872 872
873 // Now that the seek is complete, verify that time updates advance the current 873 // Now that the seek is complete, verify that time updates advance the current
874 // time. 874 // time.
875 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); 875 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100);
876 audio_time_cb_.Run(new_time, new_time); 876 audio_time_cb_.Run(new_time, new_time);
877 877
878 EXPECT_EQ(pipeline_->GetMediaTime(), new_time); 878 EXPECT_EQ(pipeline_->GetMediaTime(), new_time);
879 } 879 }
880 880
881 TEST_F(PipelineTest, InitFailure_Demuxer) {
882 PipelineStatus expected_status = DEMUXER_ERROR_COULD_NOT_OPEN;
883 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
884 .WillOnce(RunPipelineStatusCBWithStatus(expected_status));
885 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
886 .WillOnce(RunClosure());
887 InitializePipeline(expected_status);
888 }
889
890 TEST_F(PipelineTest, InitFailure_AudioDecoder) {
891 CreateAudioStream();
892 MockDemuxerStreamVector streams;
893 streams.push_back(audio_stream());
894
895 InitializeDemuxer(&streams);
896
897 PipelineStatus expected_status = PIPELINE_ERROR_DECODE;
898 scoped_refptr<DemuxerStream> stream = streams[0];
899 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _))
900 .WillOnce(RunPipelineStatusCBWithStatus(expected_status));
901
902 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
903 .WillOnce(RunClosure());
904
905 InitializePipeline(expected_status);
906 EXPECT_FALSE(pipeline_->HasAudio());
907 }
908
909 TEST_F(PipelineTest, InitFailure_AudioRenderer) {
910 CreateAudioStream();
911 MockDemuxerStreamVector streams;
912 streams.push_back(audio_stream());
913
914 InitializeDemuxer(&streams);
915 InitializeAudioDecoder(audio_stream());
916
917 PipelineStatus expected_status = PIPELINE_ERROR_INITIALIZATION_FAILED;
918 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(
919 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()),
920 _, _, _, _, _, _))
921 .WillOnce(RunPipelineStatusCBWithStatus(expected_status));
922
923 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
924 .WillOnce(RunClosure());
925 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
926 .WillOnce(RunClosure());
927
928 InitializePipeline(expected_status);
929 EXPECT_TRUE(pipeline_->HasAudio());
930 }
931
932 TEST_F(PipelineTest, InitFailure_VideoDecoder) {
933 CreateAudioStream();
934 CreateVideoStream();
935 MockDemuxerStreamVector streams;
936 streams.push_back(audio_stream());
937 streams.push_back(video_stream());
938
939 InitializeDemuxer(&streams);
940 InitializeAudioDecoder(audio_stream());
941 InitializeAudioRenderer();
942
943 PipelineStatus expected_status = PIPELINE_ERROR_DECODE;
944 scoped_refptr<DemuxerStream> stream = streams[1];
945 EXPECT_CALL(*mocks_->video_decoder(),
946 Initialize(stream, _, _))
947 .WillOnce(RunPipelineStatusCBWithStatus(expected_status));
948
949 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
950 .WillOnce(RunClosure());
951 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
952 .WillOnce(RunClosure());
953
954 InitializePipeline(expected_status);
955 EXPECT_TRUE(pipeline_->HasAudio());
956 EXPECT_FALSE(pipeline_->HasVideo());
957 }
958
959 TEST_F(PipelineTest, InitFailure_VideoRenderer) {
960 CreateAudioStream();
961 CreateVideoStream();
962 MockDemuxerStreamVector streams;
963 streams.push_back(audio_stream());
964 streams.push_back(video_stream());
965
966 InitializeDemuxer(&streams);
967 InitializeAudioDecoder(audio_stream());
968 InitializeAudioRenderer();
969 InitializeVideoDecoder(video_stream());
970
971 PipelineStatus expected_status = PIPELINE_ERROR_INITIALIZATION_FAILED;
972 EXPECT_CALL(*mocks_->video_renderer(), Initialize(
973 scoped_refptr<VideoDecoder>(mocks_->video_decoder()),
974 _, _, _, _, _, _, _, _))
975 .WillOnce(RunPipelineStatusCBWithStatus(expected_status));
976
977 EXPECT_CALL(*mocks_->demuxer(), Stop(_))
978 .WillOnce(RunClosure());
979 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
980 .WillOnce(RunClosure());
981 EXPECT_CALL(*mocks_->video_renderer(), Stop(_))
982 .WillOnce(RunClosure());
983
984 InitializePipeline(expected_status);
985 EXPECT_TRUE(pipeline_->HasAudio());
986 EXPECT_TRUE(pipeline_->HasVideo());
987 }
988
989 class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate { 881 class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate {
990 public: 882 public:
991 FlexibleCallbackRunner(base::TimeDelta delay, PipelineStatus status, 883 FlexibleCallbackRunner(base::TimeDelta delay, PipelineStatus status,
992 const PipelineStatusCB& status_cb) 884 const PipelineStatusCB& status_cb)
993 : delay_(delay), 885 : delay_(delay),
994 status_(status), 886 status_(status),
995 status_cb_(status_cb) { 887 status_cb_(status_cb) {
996 if (delay_ < base::TimeDelta()) { 888 if (delay_ < base::TimeDelta()) {
997 status_cb_.Run(status_); 889 status_cb_.Run(status_);
998 return; 890 return;
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
1035 927
1036 // Test that different-thread, some-delay callback (the expected common case) 928 // Test that different-thread, some-delay callback (the expected common case)
1037 // works correctly. 929 // works correctly.
1038 TEST(PipelineStatusNotificationTest, DelayedCallback) { 930 TEST(PipelineStatusNotificationTest, DelayedCallback) {
1039 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); 931 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20));
1040 } 932 }
1041 933
1042 class PipelineTeardownTest : public PipelineTest { 934 class PipelineTeardownTest : public PipelineTest {
1043 public: 935 public:
1044 enum TeardownState { 936 enum TeardownState {
937 kInitDemuxer,
938 kInitAudioDecoder,
939 kInitAudioRenderer,
940 kInitVideoDecoder,
941 kInitVideoRenderer,
1045 kPausing, 942 kPausing,
1046 kFlushing, 943 kFlushing,
1047 kSeeking, 944 kSeeking,
1048 kPrerolling, 945 kPrerolling,
1049 kStarting, 946 kStarting,
1050 kPlaying, 947 kPlaying,
1051 }; 948 };
1052 949
1053 enum StopOrError { 950 enum StopOrError {
1054 kStop, 951 kStop,
1055 kError, 952 kError,
1056 }; 953 };
1057 954
1058 PipelineTeardownTest() { 955 PipelineTeardownTest() {}
1059 CreateAudioStream(); 956 virtual ~PipelineTeardownTest() {}
1060 MockDemuxerStreamVector streams;
1061 streams.push_back(audio_stream());
1062
1063 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000));
1064 InitializeAudioDecoder(audio_stream());
1065 InitializeAudioRenderer();
1066 InitializePipeline(PIPELINE_OK);
1067 }
1068 957
1069 void RunTest(TeardownState state, StopOrError stop_or_error) { 958 void RunTest(TeardownState state, StopOrError stop_or_error) {
1070 InSequence s;
1071 switch (state) { 959 switch (state) {
960 case kInitDemuxer:
961 case kInitAudioDecoder:
962 case kInitAudioRenderer:
963 case kInitVideoDecoder:
964 case kInitVideoRenderer:
965 DoInitialize(state, stop_or_error);
966 break;
967
1072 case kPausing: 968 case kPausing:
1073 case kFlushing: 969 case kFlushing:
1074 case kSeeking: 970 case kSeeking:
1075 case kPrerolling: 971 case kPrerolling:
1076 case kStarting: 972 case kStarting: {
973 DoInitialize(state, stop_or_error);
974
975 InSequence s;
1077 if (stop_or_error == kStop) { 976 if (stop_or_error == kStop) {
1078 ExpectSeekStop(state); 977 ExpectSeekStop(state);
1079 } else { 978 } else {
1080 ExpectSeekError(state); 979 ExpectSeekError(state);
1081 } 980 }
1082 DoSeek(); 981 DoSeek();
1083 break; 982 break;
983 }
1084 984
1085 case kPlaying: 985 case kPlaying: {
986 DoInitialize(state, stop_or_error);
987
988 InSequence s;
1086 if (stop_or_error == kStop) { 989 if (stop_or_error == kStop) {
1087 ExpectStop(); 990 ExpectStop();
1088 DoStop(); 991 DoStop();
1089 } else { 992 } else {
1090 ExpectPlaybackError(); 993 ExpectPlaybackError();
1091 DoPlaybackError(); 994 DoPlaybackError();
1092 } 995 }
1093 break; 996 break;
997 }
1094 } 998 }
1095 } 999 }
1096 1000
1097 private: 1001 private:
1098 // TODO(scherkus): We do radically different things whether teardown is 1002 // TODO(scherkus): We do radically different things whether teardown is
1099 // invoked via stop vs error. The teardown path should be the same, 1003 // invoked via stop vs error. The teardown path should be the same,
1100 // see http://crbug.com/110228 1004 // see http://crbug.com/110228
1005 void DoInitialize(TeardownState state, StopOrError stop_or_error) {
1006 PipelineStatus expected_status =
1007 SetInitializeExpectations(state, stop_or_error);
1008
1009 EXPECT_CALL(callbacks_, OnStart(expected_status));
1010 pipeline_->Start(
1011 mocks_->Create().Pass(),
1012 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
1013 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)),
1014 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)));
1015 message_loop_.RunAllPending();
1016 }
1017
1018 PipelineStatus SetInitializeExpectations(TeardownState state,
1019 StopOrError stop_or_error) {
1020 PipelineStatus status = PIPELINE_OK;
1021 base::Closure stop_cb = base::Bind(
1022 &CallbackHelper::OnStop, base::Unretained(&callbacks_));
1023
1024 if (state == kInitDemuxer) {
1025 if (stop_or_error == kStop) {
1026 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
1027 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB()));
1028 EXPECT_CALL(callbacks_, OnStop());
1029 } else {
1030 status = DEMUXER_ERROR_COULD_NOT_OPEN;
1031 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
1032 .WillOnce(RunPipelineStatusCBWithStatus(status));
1033 }
1034
1035 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure());
1036 return status;
1037 }
1038
1039 CreateAudioStream();
1040 CreateVideoStream();
1041 MockDemuxerStreamVector streams;
1042 streams.push_back(audio_stream());
1043 streams.push_back(video_stream());
1044 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000));
1045
1046 if (state == kInitAudioDecoder) {
1047 if (stop_or_error == kStop) {
1048 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(_, _, _))
1049 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB()));
1050 EXPECT_CALL(callbacks_, OnStop());
1051 } else {
1052 status = PIPELINE_ERROR_DECODE;
1053 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(_, _, _))
1054 .WillOnce(RunPipelineStatusCBWithStatus(status));
1055 }
1056
1057 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure());
1058 return status;
1059 }
1060
1061 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(_, _, _))
1062 .WillOnce(RunPipelineStatusCB());
1063
1064 if (state == kInitAudioRenderer) {
1065 if (stop_or_error == kStop) {
1066 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _))
1067 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB()));
1068 EXPECT_CALL(callbacks_, OnStop());
1069 } else {
1070 status = PIPELINE_ERROR_INITIALIZATION_FAILED;
1071 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _))
1072 .WillOnce(RunPipelineStatusCBWithStatus(status));
1073 }
1074
1075 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure());
1076 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure());
1077 return status;
1078 }
1079
1080 EXPECT_CALL(*mocks_->audio_renderer(), Initialize(_, _, _, _, _, _, _))
1081 .WillOnce(RunPipelineStatusCB());
1082
1083 if (state == kInitVideoDecoder) {
1084 if (stop_or_error == kStop) {
1085 EXPECT_CALL(*mocks_->video_decoder(), Initialize(_, _, _))
1086 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB()));
1087 EXPECT_CALL(callbacks_, OnStop());
1088 } else {
1089 status = PIPELINE_ERROR_DECODE;
1090 EXPECT_CALL(*mocks_->video_decoder(), Initialize(_, _, _))
1091 .WillOnce(RunPipelineStatusCBWithStatus(status));
1092 }
1093
1094 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure());
1095 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure());
1096 return status;
1097 }
1098
1099 EXPECT_CALL(*mocks_->video_decoder(), Initialize(_, _, _))
1100 .WillOnce(RunPipelineStatusCB());
1101
1102 if (state == kInitVideoRenderer) {
1103 if (stop_or_error == kStop) {
1104 EXPECT_CALL(*mocks_->video_renderer(),
1105 Initialize(_, _, _, _, _, _, _, _, _))
1106 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB()));
1107 EXPECT_CALL(callbacks_, OnStop());
1108 } else {
1109 status = PIPELINE_ERROR_INITIALIZATION_FAILED;
1110 EXPECT_CALL(*mocks_->video_renderer(),
1111 Initialize(_, _, _, _, _, _, _, _, _))
1112 .WillOnce(RunPipelineStatusCBWithStatus(status));
1113 }
1114
1115 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure());
1116 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure());
1117 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure());
1118 return status;
1119 }
1120
1121 EXPECT_CALL(*mocks_->video_renderer(),
1122 Initialize(_, _, _, _, _, _, _, _, _))
1123 .WillOnce(RunPipelineStatusCB());
1124
1125 // If we get here it's a successful initialization.
1126 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f));
1127 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f));
1128 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f));
1129
1130 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f));
1131
1132 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _))
1133 .WillOnce(RunPipelineStatusCB());
1134 EXPECT_CALL(*mocks_->video_renderer(), Preroll(base::TimeDelta(), _))
1135 .WillOnce(RunPipelineStatusCB());
1136
1137 EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
1138 .WillOnce(RunClosure());
1139 EXPECT_CALL(*mocks_->video_renderer(), Play(_))
1140 .WillOnce(RunClosure());
1141
1142 return status;
1143 }
1144
1101 void ExpectSeekStop(TeardownState state) { 1145 void ExpectSeekStop(TeardownState state) {
1102 base::Closure stop_cb = base::Bind( 1146 base::Closure stop_cb = base::Bind(
1103 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); 1147 &CallbackHelper::OnStop, base::Unretained(&callbacks_));
1104 1148
1105 if (state == kPausing) { 1149 if (state == kPausing) {
1106 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) 1150 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_))
1107 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); 1151 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure()));
1108 } else { 1152 } else {
1109 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); 1153 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure());
1110 } 1154 }
1111 1155
1156 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure());
1157
1112 if (state == kFlushing) { 1158 if (state == kFlushing) {
1113 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) 1159 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_))
1114 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); 1160 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure()));
1115 } else { 1161 } else {
1116 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); 1162 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure());
1117 } 1163 }
1118 1164
1165 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure());
1166
1119 if (state == kSeeking) { 1167 if (state == kSeeking) {
1120 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) 1168 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _))
1121 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); 1169 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB()));
1122 } else { 1170 } else {
1123 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) 1171 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _))
1124 .WillOnce(RunPipelineStatusCB()); 1172 .WillOnce(RunPipelineStatusCB());
1125 } 1173 }
1126 1174
1127 if (state == kPrerolling) { 1175 if (state == kPrerolling) {
1128 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) 1176 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _))
1129 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB())); 1177 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB()));
1130 } else { 1178 } else {
1131 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) 1179 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _))
1132 .WillOnce(RunPipelineStatusCB()); 1180 .WillOnce(RunPipelineStatusCB());
1133 } 1181 }
1134 1182
1183 EXPECT_CALL(*mocks_->video_renderer(), Preroll(_, _))
1184 .WillOnce(RunPipelineStatusCB());
1185
1135 if (state == kStarting) { 1186 if (state == kStarting) {
1136 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) 1187 EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
1137 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); 1188 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure()));
1138 } else { 1189 } else {
1139 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)).WillOnce(RunClosure()); 1190 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)).WillOnce(RunClosure());
1140 } 1191 }
1141 1192
1193 EXPECT_CALL(*mocks_->video_renderer(), Play(_)).WillOnce(RunClosure());
1194
1142 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); 1195 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK));
1143 ExpectStop(); 1196 ExpectStop();
1144 } 1197 }
1145 1198
1146 void ExpectSeekError(TeardownState state) { 1199 void ExpectSeekError(TeardownState state) {
1147 SetSeekErrorExpectations(state); 1200 SetSeekErrorExpectations(state);
1148 1201
1149 // Executed after the error is raised. 1202 // Executed after the error is raised.
1150 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); 1203 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ));
1151 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); 1204 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure());
1152 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); 1205 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure());
1206 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure());
1153 } 1207 }
1154 1208
1155 void SetSeekErrorExpectations(TeardownState state) { 1209 void SetSeekErrorExpectations(TeardownState state) {
1156 if (state == kPausing) { 1210 if (state == kPausing) {
1157 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) 1211 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_))
1158 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), 1212 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ),
1159 RunClosure())); 1213 RunClosure()));
1214 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure());
1160 return; 1215 return;
1161 } 1216 }
1162 1217
1163 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); 1218 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure());
1219 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure());
1164 1220
1165 if (state == kFlushing) { 1221 if (state == kFlushing) {
1166 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) 1222 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_))
1167 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), 1223 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ),
1168 RunClosure())); 1224 RunClosure()));
1225 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure());
1169 return; 1226 return;
1170 } 1227 }
1171 1228
1172 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); 1229 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure());
1230 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure());
1173 1231
1174 if (state == kSeeking) { 1232 if (state == kSeeking) {
1175 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) 1233 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _))
1176 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ)); 1234 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ));
1177 return; 1235 return;
1178 } 1236 }
1179 1237
1180 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) 1238 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _))
1181 .WillOnce(RunPipelineStatusCB()); 1239 .WillOnce(RunPipelineStatusCB());
1182 1240
1183 if (state == kPrerolling) { 1241 if (state == kPrerolling) {
1184 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) 1242 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _))
1185 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ)); 1243 .WillOnce(RunPipelineStatusCBWithStatus(PIPELINE_ERROR_READ));
1186 return; 1244 return;
1187 } 1245 }
1188 1246
1189 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) 1247 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _))
1190 .WillOnce(RunPipelineStatusCB()); 1248 .WillOnce(RunPipelineStatusCB());
1249 EXPECT_CALL(*mocks_->video_renderer(), Preroll(_, _))
1250 .WillOnce(RunPipelineStatusCB());
1191 1251
1192 if (state == kStarting) { 1252 if (state == kStarting) {
1193 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) 1253 EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
1194 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), 1254 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ),
1195 RunClosure())); 1255 RunClosure()));
1256 EXPECT_CALL(*mocks_->video_renderer(), Play(_)).WillOnce(RunClosure());
1196 return; 1257 return;
1197 } 1258 }
1198 1259
1199 NOTREACHED() << "Unexpected TeardownState: " << state; 1260 NOTREACHED() << "Unexpected TeardownState: " << state;
1200 } 1261 }
1201 1262
1202 void ExpectStop() { 1263 void ExpectStop() {
1203 // TODO(scherkus): Don't pause+flush, see http://crbug.com/110228 1264 // TODO(scherkus): Don't pause+flush, see http://crbug.com/110228
1204 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); 1265 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure());
1266 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure());
1205 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); 1267 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure());
1268 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure());
1206 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); 1269 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure());
1207 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); 1270 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure());
1271 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure());
1208 1272
1209 EXPECT_CALL(callbacks_, OnStop()); 1273 EXPECT_CALL(callbacks_, OnStop());
1210 } 1274 }
1211 1275
1212 void ExpectPlaybackError() { 1276 void ExpectPlaybackError() {
1213 // TODO(scherkus): Don't pause+flush, see http://crbug.com/110228 1277 // TODO(scherkus): Don't pause+flush, see http://crbug.com/110228
1214 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); 1278 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure());
1279 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)).WillOnce(RunClosure());
1215 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); 1280 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure());
1281 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)).WillOnce(RunClosure());
1216 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); 1282 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure());
1217 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); 1283 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure());
1284 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)).WillOnce(RunClosure());
1218 1285
1219 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); 1286 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ));
1220 } 1287 }
1221 1288
1222 void DoSeek() { 1289 void DoSeek() {
1223 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( 1290 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind(
1224 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); 1291 &CallbackHelper::OnSeek, base::Unretained(&callbacks_)));
1225 message_loop_.RunAllPending(); 1292 message_loop_.RunAllPending();
1226 } 1293 }
1227 1294
1228 void DoStop() { 1295 void DoStop() {
1229 pipeline_->Stop(base::Bind( 1296 pipeline_->Stop(base::Bind(
1230 &CallbackHelper::OnStop, base::Unretained(&callbacks_))); 1297 &CallbackHelper::OnStop, base::Unretained(&callbacks_)));
1231 message_loop_.RunAllPending(); 1298 message_loop_.RunAllPending();
1232 } 1299 }
1233 1300
1234 void DoPlaybackError() { 1301 void DoPlaybackError() {
1235 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); 1302 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ);
1236 message_loop_.RunAllPending(); 1303 message_loop_.RunAllPending();
1237 } 1304 }
1238 1305
1239 DISALLOW_COPY_AND_ASSIGN(PipelineTeardownTest); 1306 DISALLOW_COPY_AND_ASSIGN(PipelineTeardownTest);
1240 }; 1307 };
1241 1308
1242 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \ 1309 #define INSTANTIATE_TEARDOWN_TEST(stop_or_error, state) \
1243 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \ 1310 TEST_F(PipelineTeardownTest, stop_or_error##_##state) { \
1244 RunTest(k##state, k##stop_or_error); \ 1311 RunTest(k##state, k##stop_or_error); \
1245 } 1312 }
1246 1313
1314 INSTANTIATE_TEARDOWN_TEST(Stop, InitDemuxer);
1315 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioDecoder);
1316 INSTANTIATE_TEARDOWN_TEST(Stop, InitAudioRenderer);
1317 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoDecoder);
1318 INSTANTIATE_TEARDOWN_TEST(Stop, InitVideoRenderer);
1247 INSTANTIATE_TEARDOWN_TEST(Stop, Pausing); 1319 INSTANTIATE_TEARDOWN_TEST(Stop, Pausing);
1248 INSTANTIATE_TEARDOWN_TEST(Stop, Flushing); 1320 INSTANTIATE_TEARDOWN_TEST(Stop, Flushing);
1249 INSTANTIATE_TEARDOWN_TEST(Stop, Seeking); 1321 INSTANTIATE_TEARDOWN_TEST(Stop, Seeking);
1250 INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling); 1322 INSTANTIATE_TEARDOWN_TEST(Stop, Prerolling);
1251 INSTANTIATE_TEARDOWN_TEST(Stop, Starting); 1323 INSTANTIATE_TEARDOWN_TEST(Stop, Starting);
1252 INSTANTIATE_TEARDOWN_TEST(Stop, Playing); 1324 INSTANTIATE_TEARDOWN_TEST(Stop, Playing);
1253 1325
1326 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer);
1327 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioDecoder);
1328 INSTANTIATE_TEARDOWN_TEST(Error, InitAudioRenderer);
1329 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoDecoder);
1330 INSTANTIATE_TEARDOWN_TEST(Error, InitVideoRenderer);
1254 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); 1331 INSTANTIATE_TEARDOWN_TEST(Error, Pausing);
1255 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); 1332 INSTANTIATE_TEARDOWN_TEST(Error, Flushing);
1256 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); 1333 INSTANTIATE_TEARDOWN_TEST(Error, Seeking);
1257 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); 1334 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling);
1258 INSTANTIATE_TEARDOWN_TEST(Error, Starting); 1335 INSTANTIATE_TEARDOWN_TEST(Error, Starting);
1259 INSTANTIATE_TEARDOWN_TEST(Error, Playing); 1336 INSTANTIATE_TEARDOWN_TEST(Error, Playing);
1260 1337
1261 } // namespace media 1338 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698