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 24 matching lines...) Expand all Loading... | |
| 35 // Demuxer properties. | 35 // Demuxer properties. |
| 36 static const int kTotalBytes = 1024; | 36 static const int kTotalBytes = 1024; |
| 37 static const int kBufferedBytes = 1024; | 37 static const int kBufferedBytes = 1024; |
| 38 static const int kBitrate = 1234; | 38 static const int kBitrate = 1234; |
| 39 | 39 |
| 40 ACTION_P(SetDemuxerProperties, duration) { | 40 ACTION_P(SetDemuxerProperties, duration) { |
| 41 arg0->SetTotalBytes(kTotalBytes); | 41 arg0->SetTotalBytes(kTotalBytes); |
| 42 arg0->SetDuration(duration); | 42 arg0->SetDuration(duration); |
| 43 } | 43 } |
| 44 | 44 |
| 45 ACTION_P2(Stop, pipeline, stop_cb) { | |
| 46 pipeline->Stop(stop_cb); | |
| 47 } | |
| 48 | |
| 49 ACTION_P2(SetError, pipeline, status) { | |
| 50 pipeline->SetErrorForTesting(status); | |
| 51 } | |
| 52 | |
| 45 ACTION(RunPipelineStatusCB1) { | 53 ACTION(RunPipelineStatusCB1) { |
| 46 arg1.Run(PIPELINE_OK); | 54 arg1.Run(PIPELINE_OK); |
| 47 } | 55 } |
| 48 | 56 |
| 49 ACTION_P(RunPipelineStatusCB1WithStatus, status) { | 57 ACTION_P(RunPipelineStatusCB1WithStatus, status) { |
| 50 arg1.Run(status); | 58 arg1.Run(status); |
| 51 } | 59 } |
| 52 | 60 |
| 53 // Used for setting expectations on pipeline callbacks. Using a StrictMock | 61 // Used for setting expectations on pipeline callbacks. Using a StrictMock |
| 54 // also lets us test for missing callbacks. | 62 // also lets us test for missing callbacks. |
| (...skipping 28 matching lines...) Expand all Loading... | |
| 83 // streams. | 91 // streams. |
| 84 DemuxerStream* null_pointer = NULL; | 92 DemuxerStream* null_pointer = NULL; |
| 85 EXPECT_CALL(*mocks_->demuxer(), GetStream(_)) | 93 EXPECT_CALL(*mocks_->demuxer(), GetStream(_)) |
| 86 .WillRepeatedly(Return(null_pointer)); | 94 .WillRepeatedly(Return(null_pointer)); |
| 87 | 95 |
| 88 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) | 96 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) |
| 89 .WillRepeatedly(Return(base::TimeDelta())); | 97 .WillRepeatedly(Return(base::TimeDelta())); |
| 90 } | 98 } |
| 91 | 99 |
| 92 virtual ~PipelineTest() { | 100 virtual ~PipelineTest() { |
| 93 if (!pipeline_->IsRunning()) { | |
| 94 return; | |
| 95 } | |
| 96 | |
| 97 // Shutdown sequence. | 101 // Shutdown sequence. |
| 98 if (pipeline_->IsInitialized()) { | 102 if (pipeline_->IsRunning()) { |
| 99 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 103 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 100 .WillOnce(RunClosure()); | 104 .WillOnce(RunClosure()); |
| 101 | 105 |
| 102 if (audio_stream_) { | 106 if (audio_stream_) { |
| 103 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | |
|
scherkus (not reviewing)
2012/07/28 02:26:07
Note lack of Pause/Flush prior to Stop!
| |
| 104 .WillOnce(RunClosure()); | |
| 105 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | |
| 106 .WillOnce(RunClosure()); | |
| 107 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | 107 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) |
| 108 .WillOnce(RunClosure()); | 108 .WillOnce(RunClosure()); |
| 109 } | 109 } |
| 110 | 110 |
| 111 if (video_stream_) { | 111 if (video_stream_) { |
| 112 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) | |
| 113 .WillOnce(RunClosure()); | |
| 114 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) | |
| 115 .WillOnce(RunClosure()); | |
| 116 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) | 112 EXPECT_CALL(*mocks_->video_renderer(), Stop(_)) |
| 117 .WillOnce(RunClosure()); | 113 .WillOnce(RunClosure()); |
| 118 } | 114 } |
| 119 } | 115 } |
| 120 | 116 |
| 121 // Expect a stop callback if we were started. | 117 // Stop() callbacks are always executed regardless of run state. |
| 122 EXPECT_CALL(callbacks_, OnStop()); | 118 EXPECT_CALL(callbacks_, OnStop()); |
| 123 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, | 119 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, |
| 124 base::Unretained(&callbacks_))); | 120 base::Unretained(&callbacks_))); |
| 125 message_loop_.RunAllPending(); | 121 message_loop_.RunAllPending(); |
| 126 | 122 |
| 127 pipeline_ = NULL; | 123 pipeline_ = NULL; |
| 128 mocks_.reset(); | 124 mocks_.reset(); |
| 129 } | 125 } |
| 130 | 126 |
| 131 protected: | 127 protected: |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 } | 239 } |
| 244 | 240 |
| 245 MockDemuxerStream* video_stream() { | 241 MockDemuxerStream* video_stream() { |
| 246 return video_stream_; | 242 return video_stream_; |
| 247 } | 243 } |
| 248 | 244 |
| 249 void ExpectSeek(const base::TimeDelta& seek_time) { | 245 void ExpectSeek(const base::TimeDelta& seek_time) { |
| 250 // Every filter should receive a call to Seek(). | 246 // Every filter should receive a call to Seek(). |
| 251 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 247 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 252 .WillOnce(RunPipelineStatusCB1()); | 248 .WillOnce(RunPipelineStatusCB1()); |
| 249 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(_)); | |
| 253 | 250 |
| 254 if (audio_stream_) { | 251 if (audio_stream_) { |
| 255 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 252 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 256 .WillOnce(RunClosure()); | 253 .WillOnce(RunClosure()); |
| 257 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 254 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 258 .WillOnce(RunClosure()); | 255 .WillOnce(RunClosure()); |
| 259 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) | 256 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) |
| 260 .WillOnce(RunPipelineStatusCB1()); | 257 .WillOnce(RunPipelineStatusCB1()); |
| 258 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(_)); | |
| 259 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(_)); | |
|
scherkus (not reviewing)
2012/07/28 02:26:07
note new calls to SPR/SV()
| |
| 261 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 260 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 262 .WillOnce(RunClosure()); | 261 .WillOnce(RunClosure()); |
| 263 } | 262 } |
| 264 | 263 |
| 265 if (video_stream_) { | 264 if (video_stream_) { |
| 266 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) | 265 EXPECT_CALL(*mocks_->video_renderer(), Pause(_)) |
| 267 .WillOnce(RunClosure()); | 266 .WillOnce(RunClosure()); |
| 268 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) | 267 EXPECT_CALL(*mocks_->video_renderer(), Flush(_)) |
| 269 .WillOnce(RunClosure()); | 268 .WillOnce(RunClosure()); |
| 270 EXPECT_CALL(*mocks_->video_renderer(), Preroll(seek_time, _)) | 269 EXPECT_CALL(*mocks_->video_renderer(), Preroll(seek_time, _)) |
| 271 .WillOnce(RunPipelineStatusCB1()); | 270 .WillOnce(RunPipelineStatusCB1()); |
| 271 EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(_)); | |
| 272 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) | 272 EXPECT_CALL(*mocks_->video_renderer(), Play(_)) |
| 273 .WillOnce(RunClosure()); | 273 .WillOnce(RunClosure()); |
| 274 } | 274 } |
| 275 | 275 |
| 276 // We expect a successful seek callback. | 276 // We expect a successful seek callback. |
| 277 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 277 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| 278 } | 278 } |
| 279 | 279 |
| 280 void DoSeek(const base::TimeDelta& seek_time) { | 280 void DoSeek(const base::TimeDelta& seek_time) { |
| 281 pipeline_->Seek(seek_time, | 281 pipeline_->Seek(seek_time, |
| 282 base::Bind(&CallbackHelper::OnSeek, | 282 base::Bind(&CallbackHelper::OnSeek, |
| 283 base::Unretained(&callbacks_))); | 283 base::Unretained(&callbacks_))); |
| 284 | 284 |
| 285 // We expect the time to be updated only after the seek has completed. | 285 // We expect the time to be updated only after the seek has completed. |
| 286 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); | 286 EXPECT_NE(seek_time, pipeline_->GetMediaTime()); |
| 287 message_loop_.RunAllPending(); | 287 message_loop_.RunAllPending(); |
| 288 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); | 288 EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); |
| 289 } | 289 } |
| 290 | 290 |
| 291 void SetupErrorTest() { | |
| 292 CreateAudioStream(); | |
| 293 MockDemuxerStreamVector streams; | |
| 294 streams.push_back(audio_stream()); | |
| 295 | |
| 296 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | |
| 297 InitializeAudioDecoder(audio_stream()); | |
| 298 InitializeAudioRenderer(); | |
| 299 InitializePipeline(PIPELINE_OK); | |
| 300 } | |
| 301 | |
| 291 // Fixture members. | 302 // Fixture members. |
| 292 StrictMock<CallbackHelper> callbacks_; | 303 StrictMock<CallbackHelper> callbacks_; |
| 293 MessageLoop message_loop_; | 304 MessageLoop message_loop_; |
| 294 scoped_refptr<Pipeline> pipeline_; | 305 scoped_refptr<Pipeline> pipeline_; |
| 295 scoped_ptr<media::MockFilterCollection> mocks_; | 306 scoped_ptr<media::MockFilterCollection> mocks_; |
| 296 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; | 307 scoped_refptr<StrictMock<MockDemuxerStream> > audio_stream_; |
| 297 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; | 308 scoped_refptr<StrictMock<MockDemuxerStream> > video_stream_; |
| 298 AudioRenderer::TimeCB audio_time_cb_; | 309 AudioRenderer::TimeCB audio_time_cb_; |
| 299 | 310 |
| 300 private: | 311 private: |
| 301 DISALLOW_COPY_AND_ASSIGN(PipelineTest); | 312 DISALLOW_COPY_AND_ASSIGN(PipelineTest); |
| 302 }; | 313 }; |
| 303 | 314 |
| 304 // Test that playback controls methods no-op when the pipeline hasn't been | 315 // Test that playback controls methods no-op when the pipeline hasn't been |
| 305 // started. | 316 // started. |
| 306 TEST_F(PipelineTest, NotStarted) { | 317 TEST_F(PipelineTest, NotStarted) { |
| 307 const base::TimeDelta kZero; | 318 const base::TimeDelta kZero; |
| 308 | 319 |
| 309 EXPECT_FALSE(pipeline_->IsRunning()); | 320 EXPECT_FALSE(pipeline_->IsRunning()); |
| 310 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 311 EXPECT_FALSE(pipeline_->HasAudio()); | 321 EXPECT_FALSE(pipeline_->HasAudio()); |
| 312 EXPECT_FALSE(pipeline_->HasVideo()); | 322 EXPECT_FALSE(pipeline_->HasVideo()); |
| 313 | 323 |
| 314 // Setting should still work. | 324 // Setting should still work. |
| 315 EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); | 325 EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); |
| 316 pipeline_->SetPlaybackRate(-1.0f); | 326 pipeline_->SetPlaybackRate(-1.0f); |
| 317 EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); | 327 EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); |
| 318 pipeline_->SetPlaybackRate(1.0f); | 328 pipeline_->SetPlaybackRate(1.0f); |
| 319 EXPECT_EQ(1.0f, pipeline_->GetPlaybackRate()); | 329 EXPECT_EQ(1.0f, pipeline_->GetPlaybackRate()); |
| 320 | 330 |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 331 | 341 |
| 332 EXPECT_EQ(0, pipeline_->GetTotalBytes()); | 342 EXPECT_EQ(0, pipeline_->GetTotalBytes()); |
| 333 | 343 |
| 334 // Should always get set to zero. | 344 // Should always get set to zero. |
| 335 gfx::Size size(1, 1); | 345 gfx::Size size(1, 1); |
| 336 pipeline_->GetNaturalVideoSize(&size); | 346 pipeline_->GetNaturalVideoSize(&size); |
| 337 EXPECT_EQ(0, size.width()); | 347 EXPECT_EQ(0, size.width()); |
| 338 EXPECT_EQ(0, size.height()); | 348 EXPECT_EQ(0, size.height()); |
| 339 } | 349 } |
| 340 | 350 |
| 341 TEST_F(PipelineTest, NeverInitializes) { | |
|
scherkus (not reviewing)
2012/07/28 02:26:07
this test hangs with the new pipeline because insi
acolwell GONE FROM CHROMIUM
2012/07/30 18:33:10
Doesn't this essentially test the case where the p
| |
| 342 // Don't execute the callback passed into Initialize(). | |
| 343 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)); | |
| 344 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 345 .WillOnce(RunClosure()); | |
| 346 | |
| 347 // This test hangs during initialization by never calling | |
| 348 // InitializationComplete(). StrictMock<> will ensure that the callback is | |
| 349 // never executed. | |
| 350 pipeline_->Start( | |
| 351 mocks_->Create().Pass(), | |
| 352 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | |
| 353 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | |
| 354 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); | |
| 355 message_loop_.RunAllPending(); | |
| 356 | |
| 357 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 358 | |
| 359 // Because our callback will get executed when the test tears down, we'll | |
| 360 // verify that nothing has been called, then set our expectation for the call | |
| 361 // made during tear down. | |
| 362 Mock::VerifyAndClear(&callbacks_); | |
| 363 EXPECT_CALL(callbacks_, OnStart(PIPELINE_OK)); | |
| 364 } | |
| 365 | |
| 366 TEST_F(PipelineTest, RequiredFilterMissing) { | 351 TEST_F(PipelineTest, RequiredFilterMissing) { |
| 367 // Create a filter collection with missing filter. | 352 // Create a filter collection with missing filter. |
| 368 scoped_ptr<FilterCollection> collection(mocks_->Create()); | 353 scoped_ptr<FilterCollection> collection(mocks_->Create()); |
| 369 collection->SetDemuxer(NULL); | 354 collection->SetDemuxer(NULL); |
| 370 | 355 |
| 371 EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); | 356 EXPECT_CALL(callbacks_, OnStart(PIPELINE_ERROR_REQUIRED_FILTER_MISSING)); |
| 372 pipeline_->Start( | 357 pipeline_->Start( |
| 373 collection.Pass(), | 358 collection.Pass(), |
| 374 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 359 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
| 375 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 360 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
| 376 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); | 361 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_))); |
| 377 message_loop_.RunAllPending(); | 362 message_loop_.RunAllPending(); |
| 378 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 379 } | 363 } |
| 380 | 364 |
| 381 TEST_F(PipelineTest, URLNotFound) { | 365 TEST_F(PipelineTest, URLNotFound) { |
| 382 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 366 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
| 383 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_URL_NOT_FOUND)); | 367 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_URL_NOT_FOUND)); |
| 384 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 368 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 385 .WillOnce(RunClosure()); | 369 .WillOnce(RunClosure()); |
| 386 | 370 |
| 387 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); | 371 InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND); |
| 388 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 389 } | 372 } |
| 390 | 373 |
| 391 TEST_F(PipelineTest, NoStreams) { | 374 TEST_F(PipelineTest, NoStreams) { |
| 392 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | 375 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
| 393 .WillOnce(RunPipelineStatusCB1()); | 376 .WillOnce(RunPipelineStatusCB1()); |
| 394 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | 377 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| 395 .WillOnce(RunClosure()); | 378 .WillOnce(RunClosure()); |
| 396 | 379 |
| 397 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); | 380 InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER); |
| 398 EXPECT_FALSE(pipeline_->IsInitialized()); | |
| 399 } | 381 } |
| 400 | 382 |
| 401 TEST_F(PipelineTest, AudioStream) { | 383 TEST_F(PipelineTest, AudioStream) { |
| 402 CreateAudioStream(); | 384 CreateAudioStream(); |
| 403 MockDemuxerStreamVector streams; | 385 MockDemuxerStreamVector streams; |
| 404 streams.push_back(audio_stream()); | 386 streams.push_back(audio_stream()); |
| 405 | 387 |
| 406 InitializeDemuxer(&streams); | 388 InitializeDemuxer(&streams); |
| 407 InitializeAudioDecoder(audio_stream()); | 389 InitializeAudioDecoder(audio_stream()); |
| 408 InitializeAudioRenderer(); | 390 InitializeAudioRenderer(); |
| 409 | 391 |
| 410 InitializePipeline(PIPELINE_OK); | 392 InitializePipeline(PIPELINE_OK); |
| 411 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 412 EXPECT_TRUE(pipeline_->HasAudio()); | 393 EXPECT_TRUE(pipeline_->HasAudio()); |
| 413 EXPECT_FALSE(pipeline_->HasVideo()); | 394 EXPECT_FALSE(pipeline_->HasVideo()); |
| 414 } | 395 } |
| 415 | 396 |
| 416 TEST_F(PipelineTest, VideoStream) { | 397 TEST_F(PipelineTest, VideoStream) { |
| 417 CreateVideoStream(); | 398 CreateVideoStream(); |
| 418 MockDemuxerStreamVector streams; | 399 MockDemuxerStreamVector streams; |
| 419 streams.push_back(video_stream()); | 400 streams.push_back(video_stream()); |
| 420 | 401 |
| 421 InitializeDemuxer(&streams); | 402 InitializeDemuxer(&streams); |
| 422 InitializeVideoDecoder(video_stream()); | 403 InitializeVideoDecoder(video_stream()); |
| 423 InitializeVideoRenderer(); | 404 InitializeVideoRenderer(); |
| 424 | 405 |
| 425 InitializePipeline(PIPELINE_OK); | 406 InitializePipeline(PIPELINE_OK); |
| 426 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 427 EXPECT_FALSE(pipeline_->HasAudio()); | 407 EXPECT_FALSE(pipeline_->HasAudio()); |
| 428 EXPECT_TRUE(pipeline_->HasVideo()); | 408 EXPECT_TRUE(pipeline_->HasVideo()); |
| 429 } | 409 } |
| 430 | 410 |
| 431 TEST_F(PipelineTest, AudioVideoStream) { | 411 TEST_F(PipelineTest, AudioVideoStream) { |
| 432 CreateAudioStream(); | 412 CreateAudioStream(); |
| 433 CreateVideoStream(); | 413 CreateVideoStream(); |
| 434 MockDemuxerStreamVector streams; | 414 MockDemuxerStreamVector streams; |
| 435 streams.push_back(audio_stream()); | 415 streams.push_back(audio_stream()); |
| 436 streams.push_back(video_stream()); | 416 streams.push_back(video_stream()); |
| 437 | 417 |
| 438 InitializeDemuxer(&streams); | 418 InitializeDemuxer(&streams); |
| 439 InitializeAudioDecoder(audio_stream()); | 419 InitializeAudioDecoder(audio_stream()); |
| 440 InitializeAudioRenderer(); | 420 InitializeAudioRenderer(); |
| 441 InitializeVideoDecoder(video_stream()); | 421 InitializeVideoDecoder(video_stream()); |
| 442 InitializeVideoRenderer(); | 422 InitializeVideoRenderer(); |
| 443 | 423 |
| 444 InitializePipeline(PIPELINE_OK); | 424 InitializePipeline(PIPELINE_OK); |
| 445 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 446 EXPECT_TRUE(pipeline_->HasAudio()); | 425 EXPECT_TRUE(pipeline_->HasAudio()); |
| 447 EXPECT_TRUE(pipeline_->HasVideo()); | 426 EXPECT_TRUE(pipeline_->HasVideo()); |
| 448 } | 427 } |
| 449 | 428 |
| 450 TEST_F(PipelineTest, Seek) { | 429 TEST_F(PipelineTest, Seek) { |
| 451 CreateAudioStream(); | 430 CreateAudioStream(); |
| 452 CreateVideoStream(); | 431 CreateVideoStream(); |
| 453 MockDemuxerStreamVector streams; | 432 MockDemuxerStreamVector streams; |
| 454 streams.push_back(audio_stream()); | 433 streams.push_back(audio_stream()); |
| 455 streams.push_back(video_stream()); | 434 streams.push_back(video_stream()); |
| 456 | 435 |
| 457 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); | 436 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); |
| 458 InitializeAudioDecoder(audio_stream()); | 437 InitializeAudioDecoder(audio_stream()); |
| 459 InitializeAudioRenderer(); | 438 InitializeAudioRenderer(); |
| 460 InitializeVideoDecoder(video_stream()); | 439 InitializeVideoDecoder(video_stream()); |
| 461 InitializeVideoRenderer(); | 440 InitializeVideoRenderer(); |
| 462 | 441 |
| 463 // Initialize then seek! | 442 // Initialize then seek! |
| 464 InitializePipeline(PIPELINE_OK); | 443 InitializePipeline(PIPELINE_OK); |
| 465 | 444 |
| 466 // Every filter should receive a call to Seek(). | 445 // Every filter should receive a call to Seek(). |
| 467 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); | 446 base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); |
| 468 ExpectSeek(expected); | 447 ExpectSeek(expected); |
| 469 DoSeek(expected); | 448 DoSeek(expected); |
| 470 } | 449 } |
| 471 | 450 |
| 451 TEST_F(PipelineTest, Stop_DuringStart) { | |
| 452 base::Closure stop_cb = base::Bind( | |
| 453 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); | |
| 454 | |
| 455 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | |
| 456 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB1())); | |
| 457 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 458 .WillOnce(RunClosure()); | |
| 459 | |
| 460 // Start and stop callback should fire. | |
| 461 EXPECT_CALL(callbacks_, OnStop()); | |
| 462 InitializePipeline(PIPELINE_OK); | |
| 463 } | |
| 464 | |
| 465 TEST_F(PipelineTest, Stop_DuringPause) { | |
| 466 SetupErrorTest(); | |
| 467 base::Closure stop_cb = base::Bind( | |
| 468 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); | |
| 469 | |
| 470 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | |
| 471 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); | |
| 472 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 473 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 474 | |
| 475 // Seek and stop callbacks should fire. | |
| 476 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | |
| 477 EXPECT_CALL(callbacks_, OnStop()); | |
| 478 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( | |
| 479 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); | |
| 480 message_loop_.RunAllPending(); | |
| 481 } | |
| 482 | |
| 483 TEST_F(PipelineTest, Stop_DuringFlush) { | |
| 484 SetupErrorTest(); | |
| 485 base::Closure stop_cb = base::Bind( | |
| 486 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); | |
| 487 | |
| 488 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); | |
| 489 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | |
| 490 .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); | |
| 491 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 492 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 493 | |
| 494 // Seek and stop callbacks should fire. | |
| 495 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | |
| 496 EXPECT_CALL(callbacks_, OnStop()); | |
| 497 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( | |
| 498 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); | |
| 499 message_loop_.RunAllPending(); | |
| 500 } | |
| 501 | |
| 502 TEST_F(PipelineTest, Stop_DuringSeek) { | |
| 503 SetupErrorTest(); | |
| 504 base::Closure stop_cb = base::Bind( | |
| 505 &CallbackHelper::OnStop, base::Unretained(&callbacks_)); | |
| 506 | |
| 507 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); | |
| 508 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); | |
| 509 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) | |
| 510 .WillOnce(DoAll(Stop(pipeline_, stop_cb), | |
| 511 RunPipelineStatusCB1WithStatus(PIPELINE_OK))); | |
| 512 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) | |
| 513 .WillOnce(RunPipelineStatusCB1()); | |
| 514 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 515 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 516 | |
| 517 // Seek and stop callbacks should fire. | |
| 518 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | |
| 519 EXPECT_CALL(callbacks_, OnStop()); | |
| 520 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( | |
| 521 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); | |
| 522 message_loop_.RunAllPending(); | |
| 523 } | |
| 524 | |
| 525 TEST_F(PipelineTest, Stop_DuringPlayback) { | |
| 526 SetupErrorTest(); | |
| 527 | |
| 528 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 529 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 530 | |
| 531 // Stop callback should fire but nothing else. | |
| 532 EXPECT_CALL(callbacks_, OnStop()); | |
| 533 pipeline_->Stop(base::Bind( | |
| 534 &CallbackHelper::OnStop, base::Unretained(&callbacks_))); | |
| 535 message_loop_.RunAllPending(); | |
| 536 } | |
| 537 | |
| 538 TEST_F(PipelineTest, Error_DuringStart) { | |
| 539 EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) | |
| 540 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ)); | |
| 541 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 542 .WillOnce(RunClosure()); | |
| 543 | |
| 544 // Start callback should fire with error but nothing else. | |
| 545 InitializePipeline(PIPELINE_ERROR_READ); | |
| 546 } | |
| 547 | |
| 548 TEST_F(PipelineTest, Error_DuringPause) { | |
| 549 SetupErrorTest(); | |
| 550 | |
| 551 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | |
| 552 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), RunClosure())); | |
| 553 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 554 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 555 | |
| 556 // Seek callback should fire with error but nothing else. | |
| 557 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | |
| 558 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( | |
| 559 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); | |
| 560 message_loop_.RunAllPending(); | |
| 561 } | |
| 562 | |
| 563 TEST_F(PipelineTest, Error_DuringFlush) { | |
| 564 SetupErrorTest(); | |
| 565 | |
| 566 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); | |
| 567 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | |
| 568 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), RunClosure())); | |
| 569 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 570 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 571 | |
| 572 // Seek callback should fire with error but nothing else. | |
| 573 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | |
| 574 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( | |
| 575 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); | |
| 576 message_loop_.RunAllPending(); | |
| 577 } | |
| 578 | |
| 579 TEST_F(PipelineTest, Error_DuringSeek) { | |
| 580 SetupErrorTest(); | |
| 581 | |
| 582 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); | |
| 583 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); | |
| 584 EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) | |
| 585 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ)); | |
| 586 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 587 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 588 | |
| 589 // Seek callback fire with error but nothing else. | |
| 590 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | |
| 591 pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( | |
| 592 &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); | |
| 593 message_loop_.RunAllPending(); | |
| 594 } | |
| 595 | |
| 596 TEST_F(PipelineTest, Error_DuringPlayback) { | |
| 597 SetupErrorTest(); | |
| 598 | |
| 599 EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); | |
| 600 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 601 | |
| 602 // Error callback should fire but nothing else. | |
| 603 EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); | |
| 604 pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); | |
| 605 message_loop_.RunAllPending(); | |
| 606 } | |
| 607 | |
| 608 TEST_F(PipelineTest, Error_DuringStop) { | |
| 609 SetupErrorTest(); | |
| 610 | |
| 611 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 612 .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), RunClosure())); | |
| 613 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); | |
| 614 | |
| 615 // No error callback should fire. | |
| 616 EXPECT_CALL(callbacks_, OnStop()); | |
| 617 pipeline_->Stop(base::Bind(&CallbackHelper::OnStop, | |
| 618 base::Unretained(&callbacks_))); | |
| 619 message_loop_.RunAllPending(); | |
| 620 } | |
| 621 | |
| 472 TEST_F(PipelineTest, SetVolume) { | 622 TEST_F(PipelineTest, SetVolume) { |
| 473 CreateAudioStream(); | 623 CreateAudioStream(); |
| 474 MockDemuxerStreamVector streams; | 624 MockDemuxerStreamVector streams; |
| 475 streams.push_back(audio_stream()); | 625 streams.push_back(audio_stream()); |
| 476 | 626 |
| 477 InitializeDemuxer(&streams); | 627 InitializeDemuxer(&streams); |
| 478 InitializeAudioDecoder(audio_stream()); | 628 InitializeAudioDecoder(audio_stream()); |
| 479 InitializeAudioRenderer(); | 629 InitializeAudioRenderer(); |
| 480 | 630 |
| 481 // The audio renderer should receive a call to SetVolume(). | 631 // The audio renderer should receive a call to SetVolume(). |
| 482 float expected = 0.5f; | 632 float expected = 0.5f; |
| 483 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); | 633 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(expected)); |
| 484 | 634 |
| 485 // Initialize then set volume! | 635 // Initialize then set volume! |
| 486 InitializePipeline(PIPELINE_OK); | 636 InitializePipeline(PIPELINE_OK); |
| 487 pipeline_->SetVolume(expected); | 637 pipeline_->SetVolume(expected); |
| 488 } | 638 } |
| 489 | 639 |
| 490 TEST_F(PipelineTest, Properties) { | 640 TEST_F(PipelineTest, Properties) { |
| 491 CreateVideoStream(); | 641 CreateVideoStream(); |
| 492 MockDemuxerStreamVector streams; | 642 MockDemuxerStreamVector streams; |
| 493 streams.push_back(video_stream()); | 643 streams.push_back(video_stream()); |
| 494 | 644 |
| 495 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 645 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 496 InitializeDemuxer(&streams, kDuration); | 646 InitializeDemuxer(&streams, kDuration); |
| 497 InitializeVideoDecoder(video_stream()); | 647 InitializeVideoDecoder(video_stream()); |
| 498 InitializeVideoRenderer(); | 648 InitializeVideoRenderer(); |
| 499 | 649 |
| 500 InitializePipeline(PIPELINE_OK); | 650 InitializePipeline(PIPELINE_OK); |
| 501 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 502 EXPECT_EQ(kDuration.ToInternalValue(), | 651 EXPECT_EQ(kDuration.ToInternalValue(), |
| 503 pipeline_->GetMediaDuration().ToInternalValue()); | 652 pipeline_->GetMediaDuration().ToInternalValue()); |
| 504 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); | 653 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); |
| 505 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 654 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 506 } | 655 } |
| 507 | 656 |
| 508 TEST_F(PipelineTest, GetBufferedTimeRanges) { | 657 TEST_F(PipelineTest, GetBufferedTimeRanges) { |
| 509 CreateVideoStream(); | 658 CreateVideoStream(); |
| 510 MockDemuxerStreamVector streams; | 659 MockDemuxerStreamVector streams; |
| 511 streams.push_back(video_stream()); | 660 streams.push_back(video_stream()); |
| 512 | 661 |
| 513 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 662 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 514 InitializeDemuxer(&streams, kDuration); | 663 InitializeDemuxer(&streams, kDuration); |
| 515 InitializeVideoDecoder(video_stream()); | 664 InitializeVideoDecoder(video_stream()); |
| 516 InitializeVideoRenderer(); | 665 InitializeVideoRenderer(); |
| 517 | 666 |
| 518 InitializePipeline(PIPELINE_OK); | 667 InitializePipeline(PIPELINE_OK); |
| 519 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 520 | 668 |
| 521 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); | 669 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); |
| 522 | 670 |
| 523 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 671 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 524 pipeline_->AddBufferedByteRange(0, kTotalBytes / 8); | 672 pipeline_->AddBufferedByteRange(0, kTotalBytes / 8); |
| 525 EXPECT_TRUE(pipeline_->DidLoadingProgress()); | 673 EXPECT_TRUE(pipeline_->DidLoadingProgress()); |
| 526 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 674 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 527 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); | 675 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
| 528 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); | 676 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); |
| 529 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0)); | 677 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0)); |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 565 streams.push_back(audio_stream()); | 713 streams.push_back(audio_stream()); |
| 566 streams.push_back(video_stream()); | 714 streams.push_back(video_stream()); |
| 567 | 715 |
| 568 InitializeDemuxer(&streams); | 716 InitializeDemuxer(&streams); |
| 569 InitializeAudioDecoder(audio_stream()); | 717 InitializeAudioDecoder(audio_stream()); |
| 570 InitializeAudioRenderer(); | 718 InitializeAudioRenderer(); |
| 571 InitializeVideoDecoder(video_stream()); | 719 InitializeVideoDecoder(video_stream()); |
| 572 InitializeVideoRenderer(); | 720 InitializeVideoRenderer(); |
| 573 | 721 |
| 574 InitializePipeline(PIPELINE_OK); | 722 InitializePipeline(PIPELINE_OK); |
| 575 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 576 EXPECT_TRUE(pipeline_->HasAudio()); | 723 EXPECT_TRUE(pipeline_->HasAudio()); |
| 577 EXPECT_TRUE(pipeline_->HasVideo()); | 724 EXPECT_TRUE(pipeline_->HasVideo()); |
| 578 | 725 |
| 579 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); | 726 EXPECT_CALL(*mocks_->demuxer(), OnAudioRendererDisabled()); |
| 580 pipeline_->OnAudioDisabled(); | 727 pipeline_->OnAudioDisabled(); |
| 581 | 728 |
| 582 // Verify that ended event is fired when video ends. | 729 // Verify that ended event is fired when video ends. |
| 583 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 730 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 584 .WillOnce(Return(true)); | 731 .WillOnce(Return(true)); |
| 585 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 732 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| (...skipping 10 matching lines...) Expand all Loading... | |
| 596 InitializeDemuxer(&streams); | 743 InitializeDemuxer(&streams); |
| 597 InitializeAudioDecoder(audio_stream()); | 744 InitializeAudioDecoder(audio_stream()); |
| 598 InitializeAudioRenderer(true); | 745 InitializeAudioRenderer(true); |
| 599 InitializeVideoDecoder(video_stream()); | 746 InitializeVideoDecoder(video_stream()); |
| 600 InitializeVideoRenderer(); | 747 InitializeVideoRenderer(); |
| 601 | 748 |
| 602 EXPECT_CALL(*mocks_->demuxer(), | 749 EXPECT_CALL(*mocks_->demuxer(), |
| 603 OnAudioRendererDisabled()); | 750 OnAudioRendererDisabled()); |
| 604 | 751 |
| 605 InitializePipeline(PIPELINE_OK); | 752 InitializePipeline(PIPELINE_OK); |
| 606 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 607 EXPECT_FALSE(pipeline_->HasAudio()); | 753 EXPECT_FALSE(pipeline_->HasAudio()); |
| 608 EXPECT_TRUE(pipeline_->HasVideo()); | 754 EXPECT_TRUE(pipeline_->HasVideo()); |
| 609 | 755 |
| 610 // Verify that ended event is fired when video ends. | 756 // Verify that ended event is fired when video ends. |
| 611 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 757 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 612 .WillOnce(Return(true)); | 758 .WillOnce(Return(true)); |
| 613 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 759 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 614 pipeline_->OnRendererEnded(); | 760 pipeline_->OnRendererEnded(); |
| 615 } | 761 } |
| 616 | 762 |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 708 | 854 |
| 709 // Signal end of video stream and make sure OnEnded() callback occurs. | 855 // Signal end of video stream and make sure OnEnded() callback occurs. |
| 710 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) | 856 EXPECT_CALL(*mocks_->audio_renderer(), HasEnded()) |
| 711 .WillOnce(Return(true)); | 857 .WillOnce(Return(true)); |
| 712 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) | 858 EXPECT_CALL(*mocks_->video_renderer(), HasEnded()) |
| 713 .WillOnce(Return(true)); | 859 .WillOnce(Return(true)); |
| 714 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); | 860 EXPECT_CALL(callbacks_, OnEnded(PIPELINE_OK)); |
| 715 pipeline_->OnRendererEnded(); | 861 pipeline_->OnRendererEnded(); |
| 716 } | 862 } |
| 717 | 863 |
| 718 TEST_F(PipelineTest, ErrorDuringSeek) { | |
|
scherkus (not reviewing)
2012/07/28 02:26:07
test moved up above
| |
| 719 CreateAudioStream(); | |
| 720 MockDemuxerStreamVector streams; | |
| 721 streams.push_back(audio_stream()); | |
| 722 | |
| 723 InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10)); | |
| 724 InitializeAudioDecoder(audio_stream()); | |
| 725 InitializeAudioRenderer(); | |
| 726 InitializePipeline(PIPELINE_OK); | |
| 727 | |
| 728 float playback_rate = 1.0f; | |
| 729 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | |
| 730 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | |
| 731 pipeline_->SetPlaybackRate(playback_rate); | |
| 732 message_loop_.RunAllPending(); | |
| 733 | |
| 734 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | |
| 735 | |
| 736 // Seek() isn't called as the demuxer errors out first. | |
| 737 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | |
| 738 .WillOnce(RunClosure()); | |
| 739 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | |
| 740 .WillOnce(RunClosure()); | |
| 741 EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)) | |
| 742 .WillOnce(RunClosure()); | |
| 743 | |
| 744 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | |
| 745 .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ)); | |
| 746 EXPECT_CALL(*mocks_->demuxer(), Stop(_)) | |
| 747 .WillOnce(RunClosure()); | |
| 748 | |
| 749 pipeline_->Seek(seek_time, base::Bind(&CallbackHelper::OnSeek, | |
| 750 base::Unretained(&callbacks_))); | |
| 751 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); | |
| 752 message_loop_.RunAllPending(); | |
| 753 } | |
| 754 | |
| 755 // Invoked function OnError. This asserts that the pipeline does not enqueue | 864 // Invoked function OnError. This asserts that the pipeline does not enqueue |
| 756 // non-teardown related tasks while tearing down. | 865 // non-teardown related tasks while tearing down. |
| 757 static void TestNoCallsAfterError( | 866 static void TestNoCallsAfterError( |
| 758 Pipeline* pipeline, MessageLoop* message_loop, | 867 Pipeline* pipeline, MessageLoop* message_loop, |
| 759 PipelineStatus /* status */) { | 868 PipelineStatus /* status */) { |
| 760 CHECK(pipeline); | 869 CHECK(pipeline); |
| 761 CHECK(message_loop); | 870 CHECK(message_loop); |
| 762 | 871 |
| 763 // When we get to this stage, the message loop should be empty. | 872 // When we get to this stage, the message loop should be empty. |
| 764 message_loop->AssertIdle(); | 873 message_loop->AssertIdle(); |
| (...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 812 CreateVideoStream(); | 921 CreateVideoStream(); |
| 813 MockDemuxerStreamVector streams; | 922 MockDemuxerStreamVector streams; |
| 814 streams.push_back(video_stream()); | 923 streams.push_back(video_stream()); |
| 815 | 924 |
| 816 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 925 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 817 InitializeDemuxer(&streams, kDuration); | 926 InitializeDemuxer(&streams, kDuration); |
| 818 InitializeVideoDecoder(video_stream()); | 927 InitializeVideoDecoder(video_stream()); |
| 819 InitializeVideoRenderer(); | 928 InitializeVideoRenderer(); |
| 820 | 929 |
| 821 InitializePipeline(PIPELINE_OK); | 930 InitializePipeline(PIPELINE_OK); |
| 822 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 823 EXPECT_FALSE(pipeline_->HasAudio()); | 931 EXPECT_FALSE(pipeline_->HasAudio()); |
| 824 EXPECT_TRUE(pipeline_->HasVideo()); | 932 EXPECT_TRUE(pipeline_->HasVideo()); |
| 825 | 933 |
| 826 EXPECT_EQ(base::TimeDelta(), pipeline_->GetMediaTime()); | 934 EXPECT_EQ(base::TimeDelta(), pipeline_->GetMediaTime()); |
| 827 } | 935 } |
| 828 | 936 |
| 829 TEST_F(PipelineTest, StartTimeIsNonZero) { | 937 TEST_F(PipelineTest, StartTimeIsNonZero) { |
| 830 const base::TimeDelta kStartTime = base::TimeDelta::FromSeconds(4); | 938 const base::TimeDelta kStartTime = base::TimeDelta::FromSeconds(4); |
| 831 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 939 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 832 | 940 |
| 833 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) | 941 EXPECT_CALL(*mocks_->demuxer(), GetStartTime()) |
| 834 .WillRepeatedly(Return(kStartTime)); | 942 .WillRepeatedly(Return(kStartTime)); |
| 835 | 943 |
| 836 CreateVideoStream(); | 944 CreateVideoStream(); |
| 837 MockDemuxerStreamVector streams; | 945 MockDemuxerStreamVector streams; |
| 838 streams.push_back(video_stream()); | 946 streams.push_back(video_stream()); |
| 839 | 947 |
| 840 InitializeDemuxer(&streams, kDuration); | 948 InitializeDemuxer(&streams, kDuration); |
| 841 InitializeVideoDecoder(video_stream()); | 949 InitializeVideoDecoder(video_stream()); |
| 842 InitializeVideoRenderer(); | 950 InitializeVideoRenderer(); |
| 843 | 951 |
| 844 InitializePipeline(PIPELINE_OK); | 952 InitializePipeline(PIPELINE_OK); |
| 845 EXPECT_TRUE(pipeline_->IsInitialized()); | |
| 846 EXPECT_FALSE(pipeline_->HasAudio()); | 953 EXPECT_FALSE(pipeline_->HasAudio()); |
| 847 EXPECT_TRUE(pipeline_->HasVideo()); | 954 EXPECT_TRUE(pipeline_->HasVideo()); |
| 848 | 955 |
| 849 EXPECT_EQ(kStartTime, pipeline_->GetMediaTime()); | 956 EXPECT_EQ(kStartTime, pipeline_->GetMediaTime()); |
| 850 } | 957 } |
| 851 | 958 |
| 852 static void RunTimeCB(const AudioRenderer::TimeCB& time_cb, | 959 static void RunTimeCB(const AudioRenderer::TimeCB& time_cb, |
| 853 int time_in_ms, | 960 int time_in_ms, |
| 854 int max_time_in_ms) { | 961 int max_time_in_ms) { |
| 855 time_cb.Run(base::TimeDelta::FromMilliseconds(time_in_ms), | 962 time_cb.Run(base::TimeDelta::FromMilliseconds(time_in_ms), |
| (...skipping 23 matching lines...) Expand all Loading... | |
| 879 | 986 |
| 880 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 987 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 881 | 988 |
| 882 // Arrange to trigger a time update while the demuxer is in the middle of | 989 // Arrange to trigger a time update while the demuxer is in the middle of |
| 883 // seeking. This update should be ignored by the pipeline and the clock should | 990 // seeking. This update should be ignored by the pipeline and the clock should |
| 884 // not get updated. | 991 // not get updated. |
| 885 base::Closure closure = base::Bind(&RunTimeCB, audio_time_cb_, 300, 700); | 992 base::Closure closure = base::Bind(&RunTimeCB, audio_time_cb_, 300, 700); |
| 886 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) | 993 EXPECT_CALL(*mocks_->demuxer(), Seek(seek_time, _)) |
| 887 .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run), | 994 .WillOnce(DoAll(InvokeWithoutArgs(&closure, &base::Closure::Run), |
| 888 RunPipelineStatusCB1())); | 995 RunPipelineStatusCB1())); |
| 996 EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(playback_rate)); | |
| 889 | 997 |
| 890 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) | 998 EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| 891 .WillOnce(RunClosure()); | 999 .WillOnce(RunClosure()); |
| 892 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) | 1000 EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| 893 .WillOnce(RunClosure()); | 1001 .WillOnce(RunClosure()); |
| 894 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) | 1002 EXPECT_CALL(*mocks_->audio_renderer(), Preroll(seek_time, _)) |
| 895 .WillOnce(RunPipelineStatusCB1()); | 1003 .WillOnce(RunPipelineStatusCB1()); |
| 1004 EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(playback_rate)); | |
| 1005 EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(_)); | |
| 896 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) | 1006 EXPECT_CALL(*mocks_->audio_renderer(), Play(_)) |
| 897 .WillOnce(RunClosure()); | 1007 .WillOnce(RunClosure()); |
| 898 | 1008 |
| 899 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); | 1009 EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| 900 DoSeek(seek_time); | 1010 DoSeek(seek_time); |
| 901 | 1011 |
| 902 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); | 1012 EXPECT_EQ(pipeline_->GetMediaTime(), seek_time); |
| 903 | 1013 |
| 904 // Now that the seek is complete, verify that time updates advance the current | 1014 // Now that the seek is complete, verify that time updates advance the current |
| 905 // time. | 1015 // time. |
| (...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 956 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); | 1066 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(0)); |
| 957 } | 1067 } |
| 958 | 1068 |
| 959 // Test that different-thread, some-delay callback (the expected common case) | 1069 // Test that different-thread, some-delay callback (the expected common case) |
| 960 // works correctly. | 1070 // works correctly. |
| 961 TEST(PipelineStatusNotificationTest, DelayedCallback) { | 1071 TEST(PipelineStatusNotificationTest, DelayedCallback) { |
| 962 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); | 1072 TestPipelineStatusNotification(base::TimeDelta::FromMilliseconds(20)); |
| 963 } | 1073 } |
| 964 | 1074 |
| 965 } // namespace media | 1075 } // namespace media |
| OLD | NEW |