| 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 21 matching lines...) Expand all Loading... |
| 32 using ::testing::StrictMock; | 32 using ::testing::StrictMock; |
| 33 using ::testing::WithArg; | 33 using ::testing::WithArg; |
| 34 | 34 |
| 35 namespace media { | 35 namespace media { |
| 36 | 36 |
| 37 // Demuxer properties. | 37 // Demuxer properties. |
| 38 static const int kTotalBytes = 1024; | 38 static const int kTotalBytes = 1024; |
| 39 static const int kBufferedBytes = 1024; | 39 static const int kBufferedBytes = 1024; |
| 40 static const int kBitrate = 1234; | 40 static const int kBitrate = 1234; |
| 41 | 41 |
| 42 ACTION_P(InitializeDemuxerWithError, error) { | |
| 43 arg1.Run(error); | |
| 44 } | |
| 45 | |
| 46 ACTION_P(SetDemuxerProperties, duration) { | 42 ACTION_P(SetDemuxerProperties, duration) { |
| 47 arg0->SetTotalBytes(kTotalBytes); | 43 arg0->SetTotalBytes(kTotalBytes); |
| 48 arg0->SetDuration(duration); | 44 arg0->SetDuration(duration); |
| 49 } | 45 } |
| 50 | 46 |
| 51 ACTION_P(DisableAudioRenderer, pipeline) { | 47 ACTION(RunPipelineStatusCB1) { |
| 52 FilterHost* host = pipeline; | 48 arg1.Run(PIPELINE_OK); |
| 53 host->DisableAudioRenderer(); | 49 } |
| 50 |
| 51 ACTION_P(RunPipelineStatusCB1WithStatus, status) { |
| 52 arg1.Run(status); |
| 54 } | 53 } |
| 55 | 54 |
| 56 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 55 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
| 57 // also lets us test for missing callbacks. | 56 // also lets us test for missing callbacks. |
| 58 class CallbackHelper { | 57 class CallbackHelper { |
| 59 public: | 58 public: |
| 60 CallbackHelper() {} | 59 CallbackHelper() {} |
| 61 virtual ~CallbackHelper() {} | 60 virtual ~CallbackHelper() {} |
| 62 | 61 |
| 63 MOCK_METHOD1(OnStart, void(PipelineStatus)); | 62 MOCK_METHOD1(OnStart, void(PipelineStatus)); |
| (...skipping 29 matching lines...) Expand all Loading... |
| 93 } | 92 } |
| 94 | 93 |
| 95 virtual ~PipelineTest() { | 94 virtual ~PipelineTest() { |
| 96 if (!pipeline_->IsRunning()) { | 95 if (!pipeline_->IsRunning()) { |
| 97 return; | 96 return; |
| 98 } | 97 } |
| 99 | 98 |
| 100 // Shutdown sequence. | 99 // Shutdown sequence. |
| 101 if (pipeline_->IsInitialized()) { | 100 if (pipeline_->IsInitialized()) { |
| 102 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 101 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 103 .WillOnce(Invoke(&RunClosure)); | 102 .WillOnce(RunClosure()); |
| 104 | 103 |
| 105 if (audio_stream_) { | 104 if (audio_stream_) { |
| 106 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 105 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 107 .WillOnce(Invoke(&RunClosure)); | 106 .WillOnce(RunClosure()); |
| 108 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 107 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 109 .WillOnce(Invoke(&RunClosure)); | 108 .WillOnce(RunClosure()); |
| 110 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | 109 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) |
| 111 .WillOnce(Invoke(&RunClosure)); | 110 .WillOnce(RunClosure()); |
| 112 } | 111 } |
| 113 | 112 |
| 114 if (video_stream_) { | 113 if (video_stream_) { |
| 115 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) | 114 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) |
| 116 .WillOnce(Invoke(&RunClosure)); | 115 .WillOnce(RunClosure()); |
| 117 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) | 116 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) |
| 118 .WillOnce(Invoke(&RunClosure)); | 117 .WillOnce(RunClosure()); |
| 119 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) | 118 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) |
| 120 .WillOnce(Invoke(&RunClosure)); | 119 .WillOnce(RunClosure()); |
| 121 } | 120 } |
| 122 } | 121 } |
| 123 | 122 |
| 124 // Expect a stop callback if we were started. | 123 // Expect a stop callback if we were started. |
| 125 EXPECT_CALL(callbacks_, OnStop()); | 124 EXPECT_CALL(callbacks_, OnStop()); |
| 126 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, | 125 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, |
| 127 base::Unretained(&callbacks_))); | 126 base::Unretained(&callbacks_))); |
| 128 message_loop_.RunAllPending(); | 127 message_loop_.RunAllPending(); |
| 129 | 128 |
| 130 pipeline_ = NULL; | 129 pipeline_ = NULL; |
| 131 mocks_.reset(); | 130 mocks_.reset(); |
| 132 } | 131 } |
| 133 | 132 |
| 134 protected: | 133 protected: |
| 135 // Sets up expectations to allow the demuxer to initialize. | 134 // Sets up expectations to allow the demuxer to initialize. |
| 136 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; | 135 typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector; |
| 137 void InitializeDemuxer(MockDemuxerStreamVector* streams, | 136 void InitializeDemuxer(MockDemuxerStreamVector* streams, |
| 138 const base::TimeDelta& duration) { | 137 const base::TimeDelta& duration) { |
| 139 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 138 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
| 140 .WillOnce(DoAll(SetDemuxerProperties(duration), | 139 .WillOnce(DoAll(SetDemuxerProperties(duration), |
| 141 Invoke(&RunPipelineStatusCB2))); | 140 RunPipelineStatusCB1())); |
| 142 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); | 141 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); |
| 143 | 142 |
| 144 // Demuxer properties. | 143 // Demuxer properties. |
| 145 EXPECT_CALL(*mocks_->demuxer(), GetBitrate()) | 144 EXPECT_CALL(*mocks_->demuxer(), GetBitrate()) |
| 146 .WillRepeatedly(Return(kBitrate)); | 145 .WillRepeatedly(Return(kBitrate)); |
| 147 | 146 |
| 148 // Configure the demuxer to return the streams. | 147 // Configure the demuxer to return the streams. |
| 149 for (size_t i = 0; i < streams->size(); ++i) { | 148 for (size_t i = 0; i < streams->size(); ++i) { |
| 150 scoped_refptr<DemuxerStream> stream((*streams)[i]); | 149 scoped_refptr<DemuxerStream> stream((*streams)[i]); |
| 151 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) | 150 EXPECT_CALL(*mocks_->demuxer(), GetStream(stream->type())) |
| (...skipping 11 matching lines...) Expand all Loading... |
| 163 new StrictMock<MockDemuxerStream>(); | 162 new StrictMock<MockDemuxerStream>(); |
| 164 EXPECT_CALL(*stream, type()) | 163 EXPECT_CALL(*stream, type()) |
| 165 .WillRepeatedly(Return(type)); | 164 .WillRepeatedly(Return(type)); |
| 166 return stream; | 165 return stream; |
| 167 } | 166 } |
| 168 | 167 |
| 169 // Sets up expectations to allow the video decoder to initialize. | 168 // Sets up expectations to allow the video decoder to initialize. |
| 170 void InitializeVideoDecoder(const scoped_refptr<DemuxerStream>& stream) { | 169 void InitializeVideoDecoder(const scoped_refptr<DemuxerStream>& stream) { |
| 171 EXPECT_CALL(*mocks_->video_decoder(), | 170 EXPECT_CALL(*mocks_->video_decoder(), |
| 172 Initialize(stream, _, _)) | 171 Initialize(stream, _, _)) |
| 173 .WillOnce(Invoke(&RunPipelineStatusCB3)); | 172 .WillOnce(RunPipelineStatusCB1()); |
| 174 } | 173 } |
| 175 | 174 |
| 176 // Sets up expectations to allow the audio decoder to initialize. | 175 // Sets up expectations to allow the audio decoder to initialize. |
| 177 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { | 176 void InitializeAudioDecoder(const scoped_refptr<DemuxerStream>& stream) { |
| 178 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) | 177 EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _)) |
| 179 .WillOnce(Invoke(&RunPipelineStatusCB3)); | 178 .WillOnce(RunPipelineStatusCB1()); |
| 180 } | 179 } |
| 181 | 180 |
| 182 // Sets up expectations to allow the video renderer to initialize. | 181 // Sets up expectations to allow the video renderer to initialize. |
| 183 void InitializeVideoRenderer() { | 182 void InitializeVideoRenderer() { |
| 184 EXPECT_CALL(*mocks_->video_renderer(), SetHost(NotNull())); | 183 EXPECT_CALL(*mocks_->video_renderer(), SetHost(NotNull())); |
| 185 EXPECT_CALL(*mocks_->video_renderer(), Initialize( | 184 EXPECT_CALL(*mocks_->video_renderer(), Initialize( |
| 186 scoped_refptr<VideoDecoder>(mocks_->video_decoder()), _, _, _)) | 185 scoped_refptr<VideoDecoder>(mocks_->video_decoder()), _, _, _)) |
| 187 .WillOnce(Invoke(&RunPipelineStatusCB4)); | 186 .WillOnce(RunPipelineStatusCB1()); |
| 188 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); | 187 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); |
| 189 | 188 |
| 190 // Startup sequence. | 189 // Startup sequence. |
| 191 EXPECT_CALL(*mocks_->video_renderer(), | 190 EXPECT_CALL(*mocks_->video_renderer(), |
| 192 Seek(mocks_->demuxer()->GetStartTime(), _)) | 191 Seek(mocks_->demuxer()->GetStartTime(), _)) |
| 193 .WillOnce(Invoke(&RunPipelineStatusCB2)); | 192 .WillOnce(RunPipelineStatusCB1()); |
| 194 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 193 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
| 195 .WillOnce(Invoke(&RunClosure)); | 194 .WillOnce(RunClosure()); |
| 196 } | 195 } |
| 197 | 196 |
| 198 // Sets up expectations to allow the audio renderer to initialize. | 197 // Sets up expectations to allow the audio renderer to initialize. |
| 199 void InitializeAudioRenderer(bool disable_after_init_cb = false) { | 198 void InitializeAudioRenderer(bool disable_after_init_cb = false) { |
| 200 EXPECT_CALL(*mocks_->audio_renderer(), SetHost(NotNull())); | |
| 201 if (disable_after_init_cb) { | 199 if (disable_after_init_cb) { |
| 202 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 200 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( |
| 203 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _)) | 201 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), |
| 204 .WillOnce(DoAll(Invoke(&RunPipelineStatusCB4), | 202 _, _, _, _, _, _)) |
| 205 DisableAudioRenderer(pipeline_))); | 203 .WillOnce(DoAll(RunPipelineStatusCB1(), |
| 204 WithArg<5>(RunClosure()))); // |disabled_cb|. |
| 206 } else { | 205 } else { |
| 207 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( | 206 EXPECT_CALL(*mocks_->audio_renderer(), Initialize( |
| 208 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), _, _, _)) | 207 scoped_refptr<AudioDecoder>(mocks_->audio_decoder()), |
| 208 _, _, _, _, _, _)) |
| 209 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_), | 209 .WillOnce(DoAll(SaveArg<3>(&audio_time_cb_), |
| 210 Invoke(&RunPipelineStatusCB4))); | 210 RunPipelineStatusCB1())); |
| 211 } | 211 } |
| 212 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); | 212 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); |
| 213 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); | 213 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); |
| 214 | 214 |
| 215 // Startup sequence. | 215 // Startup sequence. |
| 216 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), _)) | 216 EXPECT_CALL(*mocks_->audio_renderer(), Seek(base::TimeDelta(), _)) |
| 217 .WillOnce(Invoke(&RunPipelineStatusCB2)); | 217 .WillOnce(RunPipelineStatusCB1()); |
| 218 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 218 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 219 .WillOnce(Invoke(&RunClosure)); | 219 .WillOnce(RunClosure()); |
| 220 } | 220 } |
| 221 | 221 |
| 222 // Sets up expectations on the callback and initializes the pipeline. Called | 222 // Sets up expectations on the callback and initializes the pipeline. Called |
| 223 // after tests have set expectations any filters they wish to use. | 223 // after tests have set expectations any filters they wish to use. |
| 224 void InitializePipeline(PipelineStatus start_status) { | 224 void InitializePipeline(PipelineStatus start_status) { |
| 225 EXPECT_CALL(callbacks_, OnStart(start_status)); | 225 EXPECT_CALL(callbacks_, OnStart(start_status)); |
| 226 | 226 |
| 227 pipeline_->Start( | 227 pipeline_->Start( |
| 228 mocks_->Create().Pass(), | 228 mocks_->Create().Pass(), |
| 229 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 229 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 244 return audio_stream_; | 244 return audio_stream_; |
| 245 } | 245 } |
| 246 | 246 |
| 247 MockDemuxerStream* video_stream() { | 247 MockDemuxerStream* video_stream() { |
| 248 return video_stream_; | 248 return video_stream_; |
| 249 } | 249 } |
| 250 | 250 |
| 251 void ExpectSeek(const base::TimeDelta& seek_time) { | 251 void ExpectSeek(const base::TimeDelta& seek_time) { |
| 252 // Every filter should receive a call to Seek(). | 252 // Every filter should receive a call to Seek(). |
| 253 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 253 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 254 .WillOnce(Invoke(&RunPipelineStatusCB2)); | 254 .WillOnce(RunPipelineStatusCB1()); |
| 255 | 255 |
| 256 if (audio_stream_) { | 256 if (audio_stream_) { |
| 257 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 257 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 258 .WillOnce(Invoke(&RunClosure)); | 258 .WillOnce(RunClosure()); |
| 259 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 259 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 260 .WillOnce(Invoke(&RunClosure)); | 260 .WillOnce(RunClosure()); |
| 261 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) | 261 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) |
| 262 .WillOnce(Invoke(&RunPipelineStatusCB2)); | 262 .WillOnce(RunPipelineStatusCB1()); |
| 263 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 263 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 264 .WillOnce(Invoke(&RunClosure)); | 264 .WillOnce(RunClosure()); |
| 265 } | 265 } |
| 266 | 266 |
| 267 if (video_stream_) { | 267 if (video_stream_) { |
| 268 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) | 268 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) |
| 269 .WillOnce(Invoke(&RunClosure)); | 269 .WillOnce(RunClosure()); |
| 270 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) | 270 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) |
| 271 .WillOnce(Invoke(&RunClosure)); | 271 .WillOnce(RunClosure()); |
| 272 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, _)) | 272 EXPECT_CALL(*mocks_->video_renderer(), Seek(seek_time, _)) |
| 273 .WillOnce(Invoke(&RunPipelineStatusCB2)); | 273 .WillOnce(RunPipelineStatusCB1()); |
| 274 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 274 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
| 275 .WillOnce(Invoke(&RunClosure)); | 275 .WillOnce(RunClosure()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 // We expect a successful seek callback. | 278 // We expect a successful seek callback. |
| 279 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 279 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| 280 } | 280 } |
| 281 | 281 |
| 282 void DoSeek(const base::TimeDelta& seek_time) { | 282 void DoSeek(const base::TimeDelta& seek_time) { |
| 283 pipeline_->Seek(seek_time, | 283 pipeline_->Seek(seek_time, |
| 284 base::Bind(&CallbackHelper::OnSeek, | 284 base::Bind(&CallbackHelper::OnSeek, |
| 285 base::Unretained(&callbacks_))); | 285 base::Unretained(&callbacks_))); |
| (...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 337 gfx::Size size(1, 1); | 337 gfx::Size size(1, 1); |
| 338 pipeline_->GetNaturalVideoSize(&size); | 338 pipeline_->GetNaturalVideoSize(&size); |
| 339 EXPECT_EQ(0, size.width()); | 339 EXPECT_EQ(0, size.width()); |
| 340 EXPECT_EQ(0, size.height()); | 340 EXPECT_EQ(0, size.height()); |
| 341 } | 341 } |
| 342 | 342 |
| 343 TEST_F(PipelineTest, NeverInitializes) { | 343 TEST_F(PipelineTest, NeverInitializes) { |
| 344 // Don't execute the callback passed into Initialize(). | 344 // Don't execute the callback passed into Initialize(). |
| 345 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)); | 345 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)); |
| 346 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 346 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 347 .WillOnce(Invoke(&RunClosure)); | 347 .WillOnce(RunClosure()); |
| 348 | 348 |
| 349 // This test hangs during initialization by never calling | 349 // This test hangs during initialization by never calling |
| 350 // InitializationComplete(). StrictMock<> will ensure that the callback is | 350 // InitializationComplete(). StrictMock<> will ensure that the callback is |
| 351 // never executed. | 351 // never executed. |
| 352 pipeline_->Start( | 352 pipeline_->Start( |
| 353 mocks_->Create().Pass(), | 353 mocks_->Create().Pass(), |
| 354 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 354 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
| 355 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 355 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
| 356 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); | 356 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); |
| 357 message_loop_.RunAllPending(); | 357 message_loop_.RunAllPending(); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 375 collection.Pass(), | 375 collection.Pass(), |
| 376 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 376 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
| 377 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 377 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
| 378 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); | 378 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); |
| 379 message_loop_.RunAllPending(); | 379 message_loop_.RunAllPending(); |
| 380 EXPECT_FALSE(pipeline_->IsInitialized()); | 380 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 381 } | 381 } |
| 382 | 382 |
| 383 TEST_F(PipelineTest, URLNotFound) { | 383 TEST_F(PipelineTest, URLNotFound) { |
| 384 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 384 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
| 385 .WillOnce(InitializeDemuxerWithError(PIPELINE_ERROR_URL_NOT_FOUND)); | 385 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_URL_NOT_FOUND)); |
| 386 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 386 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 387 .WillOnce(Invoke(&RunClosure)); | 387 .WillOnce(RunClosure()); |
| 388 | 388 |
| 389 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); | 389 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); |
| 390 EXPECT_FALSE(pipeline_->IsInitialized()); | 390 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 391 } | 391 } |
| 392 | 392 |
| 393 TEST_F(PipelineTest, NoStreams) { | 393 TEST_F(PipelineTest, NoStreams) { |
| 394 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 394 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
| 395 .WillOnce(Invoke(&RunPipelineStatusCB2)); | 395 .WillOnce(RunPipelineStatusCB1()); |
| 396 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 396 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 397 .WillOnce(Invoke(&RunClosure)); | 397 .WillOnce(RunClosure()); |
| 398 | 398 |
| 399 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); | 399 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); |
| 400 EXPECT_FALSE(pipeline_->IsInitialized()); | 400 EXPECT_FALSE(pipeline_->IsInitialized()); |
| 401 } | 401 } |
| 402 | 402 |
| 403 TEST_F(PipelineTest, AudioStream) { | 403 TEST_F(PipelineTest, AudioStream) { |
| 404 CreateAudioStream(); | 404 CreateAudioStream(); |
| 405 MockDemuxerStreamVector streams; | 405 MockDemuxerStreamVector streams; |
| 406 streams.push_back(audio_stream()); | 406 streams.push_back(audio_stream()); |
| 407 | 407 |
| (...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 571 InitializeAudioDecoder(audio_stream()); | 571 InitializeAudioDecoder(audio_stream()); |
| 572 InitializeAudioRenderer(); | 572 InitializeAudioRenderer(); |
| 573 InitializeVideoDecoder(video_stream()); | 573 InitializeVideoDecoder(video_stream()); |
| 574 InitializeVideoRenderer(); | 574 InitializeVideoRenderer(); |
| 575 | 575 |
| 576 InitializePipeline(PIPELINE_OK); | 576 InitializePipeline(PIPELINE_OK); |
| 577 EXPECT_TRUE(pipeline_->IsInitialized()); | 577 EXPECT_TRUE(pipeline_->IsInitialized()); |
| 578 EXPECT_TRUE(pipeline_->HasAudio()); | 578 EXPECT_TRUE(pipeline_->HasAudio()); |
| 579 EXPECT_TRUE(pipeline_->HasVideo()); | 579 EXPECT_TRUE(pipeline_->HasVideo()); |
| 580 | 580 |
| 581 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(1.0f)) | 581 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); |
| 582 .WillOnce(DisableAudioRenderer(pipeline_)); | 582 pipeline_->OnAudioDisabled(); |
| 583 EXPECT_CALL(*mocks_->demuxer(), | |
| 584 OnAudioRendererDisabled()); | |
| 585 | |
| 586 mocks_->audio_renderer()->SetPlaybackRate(1.0f); | |
| 587 | 583 |
| 588 // Verify that ended event is fired when video ends. | 584 // Verify that ended event is fired when video ends. |
| 589 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 585 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 590 .WillOnce(Return(true)); | 586 .WillOnce(Return(true)); |
| 591 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 587 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 592 FilterHost* host = pipeline_; | 588 FilterHost* host = pipeline_; |
| 593 host->NotifyEnded(); | 589 host->NotifyEnded(); |
| 594 } | 590 } |
| 595 | 591 |
| 596 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { | 592 TEST_F(PipelineTest, DisableAudioRendererDuringInit) { |
| (...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 722 | 718 |
| 723 // Signal end of video stream and make sure OnEnded() callback occurs. | 719 // Signal end of video stream and make sure OnEnded() callback occurs. |
| 724 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 720 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
| 725 .WillOnce(Return(true)); | 721 .WillOnce(Return(true)); |
| 726 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 722 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 727 .WillOnce(Return(true)); | 723 .WillOnce(Return(true)); |
| 728 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 724 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 729 host->NotifyEnded(); | 725 host->NotifyEnded(); |
| 730 } | 726 } |
| 731 | 727 |
| 732 void SendReadErrorToCB(::testing::Unused, const PipelineStatusCB& cb) { | |
| 733 cb.Run(PIPELINE_ERROR_READ); | |
| 734 } | |
| 735 | |
| 736 TEST_F(PipelineTest, ErrorDuringSeek) { | 728 TEST_F(PipelineTest, ErrorDuringSeek) { |
| 737 CreateAudioStream(); | 729 CreateAudioStream(); |
| 738 MockDemuxerStreamVector streams; | 730 MockDemuxerStreamVector streams; |
| 739 streams.push_back(audio_stream()); | 731 streams.push_back(audio_stream()); |
| 740 | 732 |
| 741 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | 733 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); |
| 742 InitializeAudioDecoder(audio_stream()); | 734 InitializeAudioDecoder(audio_stream()); |
| 743 InitializeAudioRenderer(); | 735 InitializeAudioRenderer(); |
| 744 InitializePipeline(PIPELINE_OK); | 736 InitializePipeline(PIPELINE_OK); |
| 745 | 737 |
| 746 float playback_rate = 1.0f; | 738 float playback_rate = 1.0f; |
| 747 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | 739 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); |
| 748 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | 740 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); |
| 749 pipeline_->SetPlaybackRate(playback_rate); | 741 pipeline_->SetPlaybackRate(playback_rate); |
| 750 message_loop_.RunAllPending(); | 742 message_loop_.RunAllPending(); |
| 751 | 743 |
| 752 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 744 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 753 | 745 |
| 754 // Seek() isn't called as the demuxer errors out first. | 746 // Seek() isn't called as the demuxer errors out first. |
| 755 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 747 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 756 .WillOnce(Invoke(&RunClosure)); | 748 .WillOnce(RunClosure()); |
| 757 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 749 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 758 .WillOnce(Invoke(&RunClosure)); | 750 .WillOnce(RunClosure()); |
| 759 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | 751 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) |
| 760 .WillOnce(Invoke(&RunClosure)); | 752 .WillOnce(RunClosure()); |
| 761 | 753 |
| 762 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 754 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 763 .WillOnce(Invoke(&SendReadErrorToCB)); | 755 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ)); |
| 764 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 756 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 765 .WillOnce(Invoke(&RunClosure)); | 757 .WillOnce(RunClosure()); |
| 766 | 758 |
| 767 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, | 759 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, |
| 768 base::Unretained(&callbacks_))); | 760 base::Unretained(&callbacks_))); |
| 769 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | 761 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); |
| 770 message_loop_.RunAllPending(); | 762 message_loop_.RunAllPending(); |
| 771 } | 763 } |
| 772 | 764 |
| 773 // Invoked function OnError. This asserts that the pipeline does not enqueue | 765 // Invoked function OnError. This asserts that the pipeline does not enqueue |
| 774 // non-teardown related tasks while tearing down. | 766 // non-teardown related tasks while tearing down. |
| 775 static void TestNoCallsAfterError( | 767 static void TestNoCallsAfterError( |
| (...skipping 26 matching lines...) Expand all Loading... |
| 802 // Trigger additional requests on the pipeline during tear down from error. | 794 // Trigger additional requests on the pipeline during tear down from error. |
| 803 base::Callback<void(PipelineStatus)> cb = base::Bind( | 795 base::Callback<void(PipelineStatus)> cb = base::Bind( |
| 804 &TestNoCallsAfterError, pipeline_, &message_loop_); | 796 &TestNoCallsAfterError, pipeline_, &message_loop_); |
| 805 ON_CALL(callbacks_, OnError(_)) | 797 ON_CALL(callbacks_, OnError(_)) |
| 806 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run)); | 798 .WillByDefault(Invoke(&cb, &base::Callback<void(PipelineStatus)>::Run)); |
| 807 | 799 |
| 808 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 800 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 809 | 801 |
| 810 // Seek() isn't called as the demuxer errors out first. | 802 // Seek() isn't called as the demuxer errors out first. |
| 811 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 803 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 812 .WillOnce(Invoke(&RunClosure)); | 804 .WillOnce(RunClosure()); |
| 813 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 805 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 814 .WillOnce(Invoke(&RunClosure)); | 806 .WillOnce(RunClosure()); |
| 815 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | 807 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) |
| 816 .WillOnce(Invoke(&RunClosure)); | 808 .WillOnce(RunClosure()); |
| 817 | 809 |
| 818 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 810 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 819 .WillOnce(Invoke(&SendReadErrorToCB)); | 811 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ)); |
| 820 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 812 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 821 .WillOnce(Invoke(&RunClosure)); | 813 .WillOnce(RunClosure()); |
| 822 | 814 |
| 823 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, | 815 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, |
| 824 base::Unretained(&callbacks_))); | 816 base::Unretained(&callbacks_))); |
| 825 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | 817 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); |
| 826 message_loop_.RunAllPending(); | 818 message_loop_.RunAllPending(); |
| 827 } | 819 } |
| 828 | 820 |
| 829 TEST_F(PipelineTest, StartTimeIsZero) { | 821 TEST_F(PipelineTest, StartTimeIsZero) { |
| 830 CreateVideoStream(); | 822 CreateVideoStream(); |
| 831 MockDemuxerStreamVector streams; | 823 MockDemuxerStreamVector streams; |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 896 base::TimeDelta::FromMilliseconds(500)); | 888 base::TimeDelta::FromMilliseconds(500)); |
| 897 | 889 |
| 898 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 890 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 899 | 891 |
| 900 // Arrange to trigger a time update while the demuxer is in the middle of | 892 // Arrange to trigger a time update while the demuxer is in the middle of |
| 901 // seeking. This update should be ignored by the pipeline and the clock should | 893 // seeking. This update should be ignored by the pipeline and the clock should |
| 902 // not get updated. | 894 // not get updated. |
| 903 base::Closure closure = base::Bind(&RunTimeCB, audio_time_cb_, 300, 700); | 895 base::Closure closure = base::Bind(&RunTimeCB, audio_time_cb_, 300, 700); |
| 904 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 896 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 905 .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run), | 897 .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run), |
| 906 Invoke(&RunPipelineStatusCB2))); | 898 RunPipelineStatusCB1())); |
| 907 | 899 |
| 908 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 900 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 909 .WillOnce(Invoke(&RunClosure)); | 901 .WillOnce(RunClosure()); |
| 910 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 902 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 911 .WillOnce(Invoke(&RunClosure)); | 903 .WillOnce(RunClosure()); |
| 912 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) | 904 EXPECT_CALL(*mocks_->audio_renderer(), Seek(seek_time, _)) |
| 913 .WillOnce(Invoke(&RunPipelineStatusCB2)); | 905 .WillOnce(RunPipelineStatusCB1()); |
| 914 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 906 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 915 .WillOnce(Invoke(&RunClosure)); | 907 .WillOnce(RunClosure()); |
| 916 | 908 |
| 917 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 909 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| 918 DoSeek(seek_time); | 910 DoSeek(seek_time); |
| 919 | 911 |
| 920 EXPECT_EQ(pipeline_->GetCurrentTime(), seek_time); | 912 EXPECT_EQ(pipeline_->GetCurrentTime(), seek_time); |
| 921 | 913 |
| 922 // Now that the seek is complete, verify that time updates advance the current | 914 // Now that the seek is complete, verify that time updates advance the current |
| 923 // time. | 915 // time. |
| 924 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); | 916 base::TimeDelta new_time = seek_time + base::TimeDelta::FromMilliseconds(100); |
| 925 audio_time_cb_.Run(new_time, new_time); | 917 audio_time_cb_.Run(new_time, new_time); |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 974 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); | 966 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); |
| 975 } | 967 } |
| 976 | 968 |
| 977 // Test that different-thread, some-delay callback (the expected common case) | 969 // Test that different-thread, some-delay callback (the expected common case) |
| 978 // works correctly. | 970 // works correctly. |
| 979 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 971 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
| 980 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 972 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
| 981 } | 973 } |
| 982 | 974 |
| 983 } // namespace media | 975 } // namespace media |
| OLD | NEW |