Chromium Code Reviews| Index: media/base/pipeline_unittest.cc |
| diff --git a/media/base/pipeline_unittest.cc b/media/base/pipeline_unittest.cc |
| index bd00361c47959848dbf2c66e8ff21d59480b0ed5..221f6e7f79f9379b7767826397b236d555f39aa1 100644 |
| --- a/media/base/pipeline_unittest.cc |
| +++ b/media/base/pipeline_unittest.cc |
| @@ -41,6 +41,14 @@ ACTION_P(SetDemuxerProperties, duration) { |
| arg0->SetDuration(duration); |
| } |
| +ACTION_P2(Stop, pipeline, stop_cb) { |
| + pipeline->Stop(stop_cb); |
| +} |
| + |
| +ACTION_P2(SetError, pipeline, status) { |
| + pipeline->SetErrorForTesting(status); |
| +} |
| + |
| ACTION(RunPipelineStatusCB1) { |
|
Ami GONE FROM CHROMIUM
2012/08/08 17:21:08
FWIW, this is a dup of RunPipelineStatusCB in mock
scherkus (not reviewing)
2012/08/08 22:14:29
you're living in the past, man!!! see http://crrev
|
| arg1.Run(PIPELINE_OK); |
| } |
| @@ -98,6 +106,8 @@ class PipelineTest : public ::testing::Test { |
| EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| .WillOnce(RunClosure()); |
| + // TODO(scherkus): Don't pause+flush on shutdown, |
| + // see http://crbug.com/110228 |
| if (audio_stream_) { |
| EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| .WillOnce(RunClosure()); |
| @@ -283,6 +293,17 @@ class PipelineTest : public ::testing::Test { |
| EXPECT_EQ(seek_time, pipeline_->GetMediaTime()); |
| } |
| + void SetupShutdownTest() { |
|
Ami GONE FROM CHROMIUM
2012/08/08 17:21:08
I can't tell from this impl, nor from the name, wh
scherkus (not reviewing)
2012/08/08 22:14:29
Done.
|
| + CreateAudioStream(); |
| + MockDemuxerStreamVector streams; |
| + streams.push_back(audio_stream()); |
| + |
| + InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000)); |
| + InitializeAudioDecoder(audio_stream()); |
| + InitializeAudioRenderer(); |
| + InitializePipeline(PIPELINE_OK); |
| + } |
| + |
| // Fixture members. |
| StrictMock<CallbackHelper> callbacks_; |
| MessageLoop message_loop_; |
| @@ -464,6 +485,243 @@ TEST_F(PipelineTest, Seek) { |
| DoSeek(expected); |
| } |
| +TEST_F(PipelineTest, Stop_DuringStart) { |
| + base::Closure stop_cb = base::Bind( |
| + &CallbackHelper::OnStop, base::Unretained(&callbacks_)); |
| + |
| + EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
| + .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunPipelineStatusCB1())); |
| + |
| + // Stop sequence. |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| + .WillOnce(RunClosure()); |
| + EXPECT_CALL(callbacks_, OnStop()); |
| + |
| + InitializePipeline(PIPELINE_OK); |
| +} |
| + |
| +TEST_F(PipelineTest, Stop_DuringPause) { |
|
Ami GONE FROM CHROMIUM
2012/08/08 17:21:08
Stop_During{Pause,Flush,Seek} look like they can b
|
| + SetupShutdownTest(); |
| + base::Closure stop_cb = base::Bind( |
| + &CallbackHelper::OnStop, base::Unretained(&callbacks_)); |
| + |
| + InSequence s; |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| + .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); |
| + |
| + // We complete seeks before stopping. |
| + // TODO(scherkus): We should be able to stop in any state. |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) |
| + .WillOnce(RunPipelineStatusCB1()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) |
| + .WillOnce(RunPipelineStatusCB1()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Play(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| + |
| + // Stop sequence. |
| + // TODO(scherkus): Don't pause+flush on shutdown, see http://crbug.com/110228 |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(callbacks_, OnStop()); |
| + |
| + pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( |
| + &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +TEST_F(PipelineTest, Stop_DuringFlush) { |
| + SetupShutdownTest(); |
| + base::Closure stop_cb = base::Bind( |
| + &CallbackHelper::OnStop, base::Unretained(&callbacks_)); |
| + |
| + InSequence s; |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| + .WillOnce(DoAll(Stop(pipeline_, stop_cb), RunClosure())); |
| + |
| + // We complete seeks before stopping. |
| + // TODO(scherkus): We should be able to stop in any state. |
| + EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) |
| + .WillOnce(RunPipelineStatusCB1()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) |
| + .WillOnce(RunPipelineStatusCB1()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Play(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| + |
| + // Stop sequence. |
| + // TODO(scherkus): Don't pause+flush on shutdown, see http://crbug.com/110228 |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(callbacks_, OnStop()); |
| + |
| + pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( |
| + &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +TEST_F(PipelineTest, Stop_DuringSeek) { |
| + SetupShutdownTest(); |
| + base::Closure stop_cb = base::Bind( |
| + &CallbackHelper::OnStop, base::Unretained(&callbacks_)); |
| + |
| + InSequence s; |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) |
| + .WillOnce(DoAll(Stop(pipeline_, stop_cb), |
| + RunPipelineStatusCB1WithStatus(PIPELINE_OK))); |
| + |
| + // We complete seeks before stopping. |
| + // TODO(scherkus): We should be able to stop in any state. |
| + EXPECT_CALL(*mocks_->audio_renderer(), Preroll(_, _)) |
| + .WillOnce(RunPipelineStatusCB1()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Play(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(callbacks_, OnSeek(PIPELINE_OK)); |
| + |
| + // Stop sequence. |
| + // TODO(scherkus): Don't pause+flush on shutdown, see http://crbug.com/110228 |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(callbacks_, OnStop()); |
| + |
| + pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( |
| + &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +TEST_F(PipelineTest, Stop_DuringPlayback) { |
| + SetupShutdownTest(); |
| + |
| + InSequence s; |
| + |
| + // Stop sequence. |
| + // TODO(scherkus): Don't pause+flush on shutdown, see http://crbug.com/110228 |
|
Ami GONE FROM CHROMIUM
2012/08/08 17:21:08
Can you pull out this stanza into a helper ExpectP
|
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(callbacks_, OnStop()); |
| + |
| + pipeline_->Stop(base::Bind( |
| + &CallbackHelper::OnStop, base::Unretained(&callbacks_))); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +TEST_F(PipelineTest, Error_DuringStart) { |
| + EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _)) |
| + .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ)); |
| + |
| + // Stop sequence. |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| + .WillOnce(RunClosure()); |
| + |
| + // Start callback should fire with error but nothing else. |
| + InitializePipeline(PIPELINE_ERROR_READ); |
| +} |
| + |
| +TEST_F(PipelineTest, Error_DuringPause) { |
| + SetupShutdownTest(); |
| + |
| + InSequence s; |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)) |
| + .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), RunClosure())); |
| + |
| + EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); |
| + |
| + // Stop sequence. |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + |
| + pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( |
| + &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +TEST_F(PipelineTest, Error_DuringFlush) { |
| + SetupShutdownTest(); |
| + |
| + InSequence s; |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)) |
| + .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), RunClosure())); |
| + |
| + EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); |
| + |
| + // Stop sequence. |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + |
| + pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( |
| + &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +TEST_F(PipelineTest, Error_DuringSeek) { |
| + SetupShutdownTest(); |
| + |
| + InSequence s; |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Seek(_, _)) |
| + .WillOnce(RunPipelineStatusCB1WithStatus(PIPELINE_ERROR_READ)); |
| + |
| + EXPECT_CALL(callbacks_, OnSeek(PIPELINE_ERROR_READ)); |
| + |
| + // Stop sequence. |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + |
| + pipeline_->Seek(base::TimeDelta::FromSeconds(10), base::Bind( |
| + &CallbackHelper::OnSeek, base::Unretained(&callbacks_))); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +TEST_F(PipelineTest, Error_DuringPlayback) { |
| + SetupShutdownTest(); |
| + |
| + InSequence s; |
| + |
| + // Stop sequence. |
| + // TODO(scherkus): Don't pause+flush on shutdown, see http://crbug.com/110228 |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + |
| + EXPECT_CALL(callbacks_, OnError(PIPELINE_ERROR_READ)); |
| + |
| + pipeline_->SetErrorForTesting(PIPELINE_ERROR_READ); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| +TEST_F(PipelineTest, Error_DuringStop) { |
| + SetupShutdownTest(); |
| + |
| + InSequence s; |
| + |
| + // Stop sequence. |
| + // TODO(scherkus): Don't pause+flush on shutdown, see http://crbug.com/110228 |
| + EXPECT_CALL(*mocks_->audio_renderer(), Pause(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Flush(_)).WillOnce(RunClosure()); |
| + EXPECT_CALL(*mocks_->demuxer(), Stop(_)) |
| + .WillOnce(DoAll(SetError(pipeline_, PIPELINE_ERROR_READ), RunClosure())); |
| + EXPECT_CALL(*mocks_->audio_renderer(), Stop(_)).WillOnce(RunClosure()); |
| + |
| + // No error callback should fire. |
| + EXPECT_CALL(callbacks_, OnStop()); |
| + |
| + pipeline_->Stop(base::Bind( |
| + &CallbackHelper::OnStop, base::Unretained(&callbacks_))); |
| + message_loop_.RunAllPending(); |
| +} |
| + |
| TEST_F(PipelineTest, SetVolume) { |
| CreateAudioStream(); |
| MockDemuxerStreamVector streams; |