| 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 194 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 205 base::Unretained(this))); | 205 base::Unretained(this))); |
| 206 } | 206 } |
| 207 | 207 |
| 208 // Sets up expectations on the callback and initializes the pipeline. Called | 208 // Sets up expectations on the callback and initializes the pipeline. Called |
| 209 // after tests have set expectations any filters they wish to use. | 209 // after tests have set expectations any filters they wish to use. |
| 210 void StartPipelineAndExpect(PipelineStatus start_status) { | 210 void StartPipelineAndExpect(PipelineStatus start_status) { |
| 211 EXPECT_CALL(callbacks_, OnStart(start_status)); | 211 EXPECT_CALL(callbacks_, OnStart(start_status)); |
| 212 | 212 |
| 213 if (start_status == PIPELINE_OK) { | 213 if (start_status == PIPELINE_OK) { |
| 214 EXPECT_CALL(callbacks_, OnMetadata(_)).WillOnce(SaveArg<0>(&metadata_)); | 214 EXPECT_CALL(callbacks_, OnMetadata(_)).WillOnce(SaveArg<0>(&metadata_)); |
| 215 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0f)); | 215 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0)); |
| 216 EXPECT_CALL(*renderer_, SetVolume(1.0f)); | 216 EXPECT_CALL(*renderer_, SetVolume(1.0f)); |
| 217 EXPECT_CALL(*renderer_, StartPlayingFrom(start_time_)) | 217 EXPECT_CALL(*renderer_, StartPlayingFrom(start_time_)) |
| 218 .WillOnce(SetBufferingState(&buffering_state_cb_, | 218 .WillOnce(SetBufferingState(&buffering_state_cb_, |
| 219 BUFFERING_HAVE_ENOUGH)); | 219 BUFFERING_HAVE_ENOUGH)); |
| 220 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 220 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
| 221 } | 221 } |
| 222 | 222 |
| 223 StartPipeline(); | 223 StartPipeline(); |
| 224 message_loop_.RunUntilIdle(); | 224 message_loop_.RunUntilIdle(); |
| 225 } | 225 } |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 333 |
| 334 // Test that playback controls methods no-op when the pipeline hasn't been | 334 // Test that playback controls methods no-op when the pipeline hasn't been |
| 335 // started. | 335 // started. |
| 336 TEST_F(PipelineTest, NotStarted) { | 336 TEST_F(PipelineTest, NotStarted) { |
| 337 const base::TimeDelta kZero; | 337 const base::TimeDelta kZero; |
| 338 | 338 |
| 339 EXPECT_FALSE(pipeline_->IsRunning()); | 339 EXPECT_FALSE(pipeline_->IsRunning()); |
| 340 | 340 |
| 341 // Setting should still work. | 341 // Setting should still work. |
| 342 EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); | 342 EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); |
| 343 pipeline_->SetPlaybackRate(-1.0f); | 343 pipeline_->SetPlaybackRate(-1.0); |
| 344 EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); | 344 EXPECT_EQ(0.0f, pipeline_->GetPlaybackRate()); |
| 345 pipeline_->SetPlaybackRate(1.0f); | 345 pipeline_->SetPlaybackRate(1.0); |
| 346 EXPECT_EQ(1.0f, pipeline_->GetPlaybackRate()); | 346 EXPECT_EQ(1.0f, pipeline_->GetPlaybackRate()); |
| 347 | 347 |
| 348 // Setting should still work. | 348 // Setting should still work. |
| 349 EXPECT_EQ(1.0f, pipeline_->GetVolume()); | 349 EXPECT_EQ(1.0f, pipeline_->GetVolume()); |
| 350 pipeline_->SetVolume(-1.0f); | 350 pipeline_->SetVolume(-1.0f); |
| 351 EXPECT_EQ(1.0f, pipeline_->GetVolume()); | 351 EXPECT_EQ(1.0f, pipeline_->GetVolume()); |
| 352 pipeline_->SetVolume(0.0f); | 352 pipeline_->SetVolume(0.0f); |
| 353 EXPECT_EQ(0.0f, pipeline_->GetVolume()); | 353 EXPECT_EQ(0.0f, pipeline_->GetVolume()); |
| 354 | 354 |
| 355 EXPECT_TRUE(kZero == pipeline_->GetMediaTime()); | 355 EXPECT_TRUE(kZero == pipeline_->GetMediaTime()); |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 636 | 636 |
| 637 TEST_F(PipelineTest, ErrorDuringSeek) { | 637 TEST_F(PipelineTest, ErrorDuringSeek) { |
| 638 CreateAudioStream(); | 638 CreateAudioStream(); |
| 639 MockDemuxerStreamVector streams; | 639 MockDemuxerStreamVector streams; |
| 640 streams.push_back(audio_stream()); | 640 streams.push_back(audio_stream()); |
| 641 | 641 |
| 642 SetDemuxerExpectations(&streams); | 642 SetDemuxerExpectations(&streams); |
| 643 SetRendererExpectations(); | 643 SetRendererExpectations(); |
| 644 StartPipelineAndExpect(PIPELINE_OK); | 644 StartPipelineAndExpect(PIPELINE_OK); |
| 645 | 645 |
| 646 float playback_rate = 1.0f; | 646 double playback_rate = 1.0; |
| 647 EXPECT_CALL(*renderer_, SetPlaybackRate(playback_rate)); | 647 EXPECT_CALL(*renderer_, SetPlaybackRate(playback_rate)); |
| 648 pipeline_->SetPlaybackRate(playback_rate); | 648 pipeline_->SetPlaybackRate(playback_rate); |
| 649 message_loop_.RunUntilIdle(); | 649 message_loop_.RunUntilIdle(); |
| 650 | 650 |
| 651 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); | 651 base::TimeDelta seek_time = base::TimeDelta::FromSeconds(5); |
| 652 | 652 |
| 653 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); | 653 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_NOTHING)); |
| 654 EXPECT_CALL(*renderer_, Flush(_)) | 654 EXPECT_CALL(*renderer_, Flush(_)) |
| 655 .WillOnce(DoAll(SetBufferingState(&buffering_state_cb_, | 655 .WillOnce(DoAll(SetBufferingState(&buffering_state_cb_, |
| 656 BUFFERING_HAVE_NOTHING), | 656 BUFFERING_HAVE_NOTHING), |
| (...skipping 14 matching lines...) Expand all Loading... |
| 671 static void TestNoCallsAfterError( | 671 static void TestNoCallsAfterError( |
| 672 Pipeline* pipeline, base::MessageLoop* message_loop, | 672 Pipeline* pipeline, base::MessageLoop* message_loop, |
| 673 PipelineStatus /* status */) { | 673 PipelineStatus /* status */) { |
| 674 CHECK(pipeline); | 674 CHECK(pipeline); |
| 675 CHECK(message_loop); | 675 CHECK(message_loop); |
| 676 | 676 |
| 677 // When we get to this stage, the message loop should be empty. | 677 // When we get to this stage, the message loop should be empty. |
| 678 EXPECT_TRUE(message_loop->IsIdleForTesting()); | 678 EXPECT_TRUE(message_loop->IsIdleForTesting()); |
| 679 | 679 |
| 680 // Make calls on pipeline after error has occurred. | 680 // Make calls on pipeline after error has occurred. |
| 681 pipeline->SetPlaybackRate(0.5f); | 681 pipeline->SetPlaybackRate(0.5); |
| 682 pipeline->SetVolume(0.5f); | 682 pipeline->SetVolume(0.5f); |
| 683 | 683 |
| 684 // No additional tasks should be queued as a result of these calls. | 684 // No additional tasks should be queued as a result of these calls. |
| 685 EXPECT_TRUE(message_loop->IsIdleForTesting()); | 685 EXPECT_TRUE(message_loop->IsIdleForTesting()); |
| 686 } | 686 } |
| 687 | 687 |
| 688 TEST_F(PipelineTest, NoMessageDuringTearDownFromError) { | 688 TEST_F(PipelineTest, NoMessageDuringTearDownFromError) { |
| 689 CreateAudioStream(); | 689 CreateAudioStream(); |
| 690 MockDemuxerStreamVector streams; | 690 MockDemuxerStreamVector streams; |
| 691 streams.push_back(audio_stream()); | 691 streams.push_back(audio_stream()); |
| (...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 873 return status; | 873 return status; |
| 874 } | 874 } |
| 875 | 875 |
| 876 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _, _)) | 876 EXPECT_CALL(*renderer_, Initialize(_, _, _, _, _, _, _, _)) |
| 877 .WillOnce(DoAll(SaveArg<3>(&buffering_state_cb_), | 877 .WillOnce(DoAll(SaveArg<3>(&buffering_state_cb_), |
| 878 PostCallback<1>(PIPELINE_OK))); | 878 PostCallback<1>(PIPELINE_OK))); |
| 879 | 879 |
| 880 EXPECT_CALL(callbacks_, OnMetadata(_)); | 880 EXPECT_CALL(callbacks_, OnMetadata(_)); |
| 881 | 881 |
| 882 // If we get here it's a successful initialization. | 882 // If we get here it's a successful initialization. |
| 883 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0f)); | 883 EXPECT_CALL(*renderer_, SetPlaybackRate(0.0)); |
| 884 EXPECT_CALL(*renderer_, SetVolume(1.0f)); | 884 EXPECT_CALL(*renderer_, SetVolume(1.0f)); |
| 885 EXPECT_CALL(*renderer_, StartPlayingFrom(base::TimeDelta())) | 885 EXPECT_CALL(*renderer_, StartPlayingFrom(base::TimeDelta())) |
| 886 .WillOnce(SetBufferingState(&buffering_state_cb_, | 886 .WillOnce(SetBufferingState(&buffering_state_cb_, |
| 887 BUFFERING_HAVE_ENOUGH)); | 887 BUFFERING_HAVE_ENOUGH)); |
| 888 | 888 |
| 889 if (status == PIPELINE_OK) | 889 if (status == PIPELINE_OK) |
| 890 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); | 890 EXPECT_CALL(callbacks_, OnBufferingStateChange(BUFFERING_HAVE_ENOUGH)); |
| 891 | 891 |
| 892 return status; | 892 return status; |
| 893 } | 893 } |
| (...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1005 | 1005 |
| 1006 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); | 1006 INSTANTIATE_TEARDOWN_TEST(Error, InitDemuxer); |
| 1007 INSTANTIATE_TEARDOWN_TEST(Error, InitRenderer); | 1007 INSTANTIATE_TEARDOWN_TEST(Error, InitRenderer); |
| 1008 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); | 1008 INSTANTIATE_TEARDOWN_TEST(Error, Flushing); |
| 1009 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); | 1009 INSTANTIATE_TEARDOWN_TEST(Error, Seeking); |
| 1010 INSTANTIATE_TEARDOWN_TEST(Error, Playing); | 1010 INSTANTIATE_TEARDOWN_TEST(Error, Playing); |
| 1011 | 1011 |
| 1012 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); | 1012 INSTANTIATE_TEARDOWN_TEST(ErrorAndStop, Playing); |
| 1013 | 1013 |
| 1014 } // namespace media | 1014 } // namespace media |
| OLD | NEW |