| 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/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/stl_util.h" | 9 #include "base/stl_util.h" |
| 10 #include "base/test/simple_test_tick_clock.h" | 10 #include "base/test/simple_test_tick_clock.h" |
| (...skipping 20 matching lines...) Expand all Loading... |
| 31 using ::testing::InvokeWithoutArgs; | 31 using ::testing::InvokeWithoutArgs; |
| 32 using ::testing::Mock; | 32 using ::testing::Mock; |
| 33 using ::testing::NotNull; | 33 using ::testing::NotNull; |
| 34 using ::testing::Return; | 34 using ::testing::Return; |
| 35 using ::testing::SaveArg; | 35 using ::testing::SaveArg; |
| 36 using ::testing::StrictMock; | 36 using ::testing::StrictMock; |
| 37 using ::testing::WithArg; | 37 using ::testing::WithArg; |
| 38 | 38 |
| 39 namespace media { | 39 namespace media { |
| 40 | 40 |
| 41 const int kTotalBytes = 1024; | |
| 42 | |
| 43 ACTION_P(SetDemuxerProperties, duration) { | 41 ACTION_P(SetDemuxerProperties, duration) { |
| 44 arg0->SetDuration(duration); | 42 arg0->SetDuration(duration); |
| 45 } | 43 } |
| 46 | 44 |
| 47 ACTION_P2(Stop, pipeline, stop_cb) { | 45 ACTION_P2(Stop, pipeline, stop_cb) { |
| 48 pipeline->Stop(stop_cb); | 46 pipeline->Stop(stop_cb); |
| 49 } | 47 } |
| 50 | 48 |
| 51 ACTION_P2(SetError, pipeline, status) { | 49 ACTION_P2(SetError, pipeline, status) { |
| 52 pipeline->SetErrorForTesting(status); | 50 pipeline->SetErrorForTesting(status); |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 210 | 208 |
| 211 // Startup sequence. | 209 // Startup sequence. |
| 212 EXPECT_CALL(*audio_renderer_, Preroll(base::TimeDelta(), _)) | 210 EXPECT_CALL(*audio_renderer_, Preroll(base::TimeDelta(), _)) |
| 213 .WillOnce(RunCallback<1>(PIPELINE_OK)); | 211 .WillOnce(RunCallback<1>(PIPELINE_OK)); |
| 214 EXPECT_CALL(*audio_renderer_, Play(_)) | 212 EXPECT_CALL(*audio_renderer_, Play(_)) |
| 215 .WillOnce(RunClosure<0>()); | 213 .WillOnce(RunClosure<0>()); |
| 216 } | 214 } |
| 217 EXPECT_CALL(callbacks_, OnPrerollCompleted()); | 215 EXPECT_CALL(callbacks_, OnPrerollCompleted()); |
| 218 } | 216 } |
| 219 | 217 |
| 220 // HACK: This is required to test the time range code now that DemuxerHost | |
| 221 // does not include SetTotalBytes(). The test cases that depend on this will | |
| 222 // be moved out of pipeline_unittest when Pipeline stops implementing | |
| 223 // DataSourceHost, see http://crbug.com/122071. | |
| 224 DataSourceHost* host = pipeline_.get(); | |
| 225 host->SetTotalBytes(kTotalBytes); | |
| 226 | |
| 227 pipeline_->Start( | 218 pipeline_->Start( |
| 228 filter_collection_.Pass(), | 219 filter_collection_.Pass(), |
| 229 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), | 220 base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)), |
| 230 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), | 221 base::Bind(&CallbackHelper::OnError, base::Unretained(&callbacks_)), |
| 231 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), | 222 base::Bind(&CallbackHelper::OnStart, base::Unretained(&callbacks_)), |
| 232 base::Bind(&CallbackHelper::OnMetadata, base::Unretained(&callbacks_)), | 223 base::Bind(&CallbackHelper::OnMetadata, base::Unretained(&callbacks_)), |
| 233 base::Bind(&CallbackHelper::OnPrerollCompleted, | 224 base::Bind(&CallbackHelper::OnPrerollCompleted, |
| 234 base::Unretained(&callbacks_)), | 225 base::Unretained(&callbacks_)), |
| 235 base::Bind(&CallbackHelper::OnDurationChange, | 226 base::Bind(&CallbackHelper::OnDurationChange, |
| 236 base::Unretained(&callbacks_))); | 227 base::Unretained(&callbacks_))); |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 // Setting should still work. | 361 // Setting should still work. |
| 371 EXPECT_EQ(1.0f, pipeline_->GetVolume()); | 362 EXPECT_EQ(1.0f, pipeline_->GetVolume()); |
| 372 pipeline_->SetVolume(-1.0f); | 363 pipeline_->SetVolume(-1.0f); |
| 373 EXPECT_EQ(1.0f, pipeline_->GetVolume()); | 364 EXPECT_EQ(1.0f, pipeline_->GetVolume()); |
| 374 pipeline_->SetVolume(0.0f); | 365 pipeline_->SetVolume(0.0f); |
| 375 EXPECT_EQ(0.0f, pipeline_->GetVolume()); | 366 EXPECT_EQ(0.0f, pipeline_->GetVolume()); |
| 376 | 367 |
| 377 EXPECT_TRUE(kZero == pipeline_->GetMediaTime()); | 368 EXPECT_TRUE(kZero == pipeline_->GetMediaTime()); |
| 378 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); | 369 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); |
| 379 EXPECT_TRUE(kZero == pipeline_->GetMediaDuration()); | 370 EXPECT_TRUE(kZero == pipeline_->GetMediaDuration()); |
| 380 | |
| 381 EXPECT_EQ(0, pipeline_->GetTotalBytes()); | |
| 382 } | 371 } |
| 383 | 372 |
| 384 TEST_F(PipelineTest, NeverInitializes) { | 373 TEST_F(PipelineTest, NeverInitializes) { |
| 385 // Don't execute the callback passed into Initialize(). | 374 // Don't execute the callback passed into Initialize(). |
| 386 EXPECT_CALL(*demuxer_, Initialize(_, _, _)); | 375 EXPECT_CALL(*demuxer_, Initialize(_, _, _)); |
| 387 | 376 |
| 388 // This test hangs during initialization by never calling | 377 // This test hangs during initialization by never calling |
| 389 // InitializationComplete(). StrictMock<> will ensure that the callback is | 378 // InitializationComplete(). StrictMock<> will ensure that the callback is |
| 390 // never executed. | 379 // never executed. |
| 391 pipeline_->Start( | 380 pipeline_->Start( |
| (...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 551 MockDemuxerStreamVector streams; | 540 MockDemuxerStreamVector streams; |
| 552 streams.push_back(video_stream()); | 541 streams.push_back(video_stream()); |
| 553 | 542 |
| 554 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 543 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 555 InitializeDemuxer(&streams, kDuration); | 544 InitializeDemuxer(&streams, kDuration); |
| 556 InitializeVideoRenderer(video_stream()); | 545 InitializeVideoRenderer(video_stream()); |
| 557 | 546 |
| 558 InitializePipeline(PIPELINE_OK); | 547 InitializePipeline(PIPELINE_OK); |
| 559 EXPECT_EQ(kDuration.ToInternalValue(), | 548 EXPECT_EQ(kDuration.ToInternalValue(), |
| 560 pipeline_->GetMediaDuration().ToInternalValue()); | 549 pipeline_->GetMediaDuration().ToInternalValue()); |
| 561 EXPECT_EQ(kTotalBytes, pipeline_->GetTotalBytes()); | |
| 562 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 550 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 563 } | 551 } |
| 564 | 552 |
| 565 TEST_F(PipelineTest, GetBufferedTimeRanges) { | 553 TEST_F(PipelineTest, GetBufferedTimeRanges) { |
| 566 CreateVideoStream(); | 554 CreateVideoStream(); |
| 567 MockDemuxerStreamVector streams; | 555 MockDemuxerStreamVector streams; |
| 568 streams.push_back(video_stream()); | 556 streams.push_back(video_stream()); |
| 569 | 557 |
| 570 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); | 558 const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100); |
| 571 InitializeDemuxer(&streams, kDuration); | 559 InitializeDemuxer(&streams, kDuration); |
| 572 InitializeVideoRenderer(video_stream()); | 560 InitializeVideoRenderer(video_stream()); |
| 573 | 561 |
| 574 InitializePipeline(PIPELINE_OK); | 562 InitializePipeline(PIPELINE_OK); |
| 575 | 563 |
| 576 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); | 564 EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size()); |
| 577 | 565 |
| 578 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 566 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 579 pipeline_->AddBufferedByteRange(0, kTotalBytes / 8); | 567 pipeline_->AddBufferedTimeRange(base::TimeDelta(), kDuration / 8); |
| 580 EXPECT_TRUE(pipeline_->DidLoadingProgress()); | 568 EXPECT_TRUE(pipeline_->DidLoadingProgress()); |
| 581 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 569 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 582 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); | 570 EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
| 583 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); | 571 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); |
| 584 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0)); | 572 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0)); |
| 585 pipeline_->AddBufferedTimeRange(base::TimeDelta(), kDuration / 8); | |
| 586 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); | |
| 587 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0)); | |
| 588 | 573 |
| 589 base::TimeDelta kSeekTime = kDuration / 2; | 574 base::TimeDelta kSeekTime = kDuration / 2; |
| 590 ExpectSeek(kSeekTime); | 575 ExpectSeek(kSeekTime); |
| 591 DoSeek(kSeekTime); | 576 DoSeek(kSeekTime); |
| 592 | 577 |
| 593 EXPECT_TRUE(pipeline_->DidLoadingProgress()); | |
| 594 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | 578 EXPECT_FALSE(pipeline_->DidLoadingProgress()); |
| 595 pipeline_->AddBufferedByteRange(kTotalBytes / 2, | |
| 596 kTotalBytes / 2 + kTotalBytes / 8); | |
| 597 EXPECT_TRUE(pipeline_->DidLoadingProgress()); | |
| 598 EXPECT_FALSE(pipeline_->DidLoadingProgress()); | |
| 599 EXPECT_EQ(2u, pipeline_->GetBufferedTimeRanges().size()); | |
| 600 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); | |
| 601 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0)); | |
| 602 EXPECT_EQ(kDuration / 2, pipeline_->GetBufferedTimeRanges().start(1)); | |
| 603 EXPECT_EQ(kDuration / 2 + kDuration / 8, | |
| 604 pipeline_->GetBufferedTimeRanges().end(1)); | |
| 605 | |
| 606 pipeline_->AddBufferedTimeRange(kDuration / 4, 3 * kDuration / 8); | |
| 607 EXPECT_EQ(base::TimeDelta(), pipeline_->GetBufferedTimeRanges().start(0)); | |
| 608 EXPECT_EQ(kDuration / 8, pipeline_->GetBufferedTimeRanges().end(0)); | |
| 609 EXPECT_EQ(kDuration / 4, pipeline_->GetBufferedTimeRanges().start(1)); | |
| 610 EXPECT_EQ(3* kDuration / 8, pipeline_->GetBufferedTimeRanges().end(1)); | |
| 611 EXPECT_EQ(kDuration / 2, pipeline_->GetBufferedTimeRanges().start(2)); | |
| 612 EXPECT_EQ(kDuration / 2 + kDuration / 8, | |
| 613 pipeline_->GetBufferedTimeRanges().end(2)); | |
| 614 } | 579 } |
| 615 | 580 |
| 616 TEST_F(PipelineTest, DisableAudioRenderer) { | 581 TEST_F(PipelineTest, DisableAudioRenderer) { |
| 617 CreateAudioStream(); | 582 CreateAudioStream(); |
| 618 CreateVideoStream(); | 583 CreateVideoStream(); |
| 619 MockDemuxerStreamVector streams; | 584 MockDemuxerStreamVector streams; |
| 620 streams.push_back(audio_stream()); | 585 streams.push_back(audio_stream()); |
| 621 streams.push_back(video_stream()); | 586 streams.push_back(video_stream()); |
| 622 | 587 |
| 623 InitializeDemuxer(&streams); | 588 InitializeDemuxer(&streams); |
| (...skipping 645 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1269 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); | 1234 INSTANTIATE_TEARDOWN_TEST(Error, Pausing); |
| 1270 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1235 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
| 1271 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1236 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
| 1272 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); | 1237 INSTANTIATE_TEARDOWN_TEST(Error, Prerolling); |
| 1273 INSTANTIATE_TEARDOWN_TEST(Error, Starting); | 1238 INSTANTIATE_TEARDOWN_TEST(Error, Starting); |
| 1274 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1239 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
| 1275 | 1240 |
| 1276 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); | 1241 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); |
| 1277 | 1242 |
| 1278 } // namespace media | 1243 } // namespace media |
| OLD | NEW |