summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-12 04:50:09 +0000
committerxhwang@chromium.org <xhwang@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-12 04:50:09 +0000
commit2b74405f80258edcad57fb93ef84f513a824ea9d (patch)
treedb5fe1294bb9744ff7837788a300015bea0d9268
parent8c2efc2eeb20a03ea58e03d636c4f4b017afffaa (diff)
downloadchromium_src-2b74405f80258edcad57fb93ef84f513a824ea9d.zip
chromium_src-2b74405f80258edcad57fb93ef84f513a824ea9d.tar.gz
chromium_src-2b74405f80258edcad57fb93ef84f513a824ea9d.tar.bz2
Some cleanup in PipelineTest.
Do not call Pipeline::On{Audio|Video}RendererEnded() because it's pipeline's implementation detail and will go away. Instead, let the mock renderers call the ended_cb. Also rename several helper functions to reflect what they really do. BUG=392259 TEST=All current tests pass. Review URL: https://codereview.chromium.org/388763003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@282798 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--media/base/pipeline_unittest.cc144
1 files changed, 74 insertions, 70 deletions
diff --git a/media/base/pipeline_unittest.cc b/media/base/pipeline_unittest.cc
index 17da202..2685b8e 100644
--- a/media/base/pipeline_unittest.cc
+++ b/media/base/pipeline_unittest.cc
@@ -105,8 +105,8 @@ class PipelineTest : public ::testing::Test {
scoped_ptr<TextRenderer> text_renderer(text_renderer_);
filter_collection_->SetTextRenderer(text_renderer.Pass());
- // InitializeDemuxer() adds overriding expectations for expected non-NULL
- // streams.
+ // SetDemuxerExpectations() adds overriding expectations for expected
+ // non-NULL streams.
DemuxerStream* null_pointer = NULL;
EXPECT_CALL(*demuxer_, GetStream(_))
.WillRepeatedly(Return(null_pointer));
@@ -141,8 +141,8 @@ class PipelineTest : public ::testing::Test {
protected:
// Sets up expectations to allow the demuxer to initialize.
typedef std::vector<MockDemuxerStream*> MockDemuxerStreamVector;
- void InitializeDemuxer(MockDemuxerStreamVector* streams,
- const base::TimeDelta& duration) {
+ void SetDemuxerExpectations(MockDemuxerStreamVector* streams,
+ const base::TimeDelta& duration) {
EXPECT_CALL(callbacks_, OnDurationChange());
EXPECT_CALL(*demuxer_, Initialize(_, _, _))
.WillOnce(DoAll(SetDemuxerProperties(duration),
@@ -156,9 +156,9 @@ class PipelineTest : public ::testing::Test {
}
}
- void InitializeDemuxer(MockDemuxerStreamVector* streams) {
+ void SetDemuxerExpectations(MockDemuxerStreamVector* streams) {
// Initialize with a default non-zero duration.
- InitializeDemuxer(streams, base::TimeDelta::FromSeconds(10));
+ SetDemuxerExpectations(streams, base::TimeDelta::FromSeconds(10));
}
scoped_ptr<StrictMock<MockDemuxerStream> > CreateStream(
@@ -169,17 +169,19 @@ class PipelineTest : public ::testing::Test {
}
// Sets up expectations to allow the video renderer to initialize.
- void InitializeVideoRenderer(DemuxerStream* stream) {
+ void SetVideoRendererExpectations(DemuxerStream* stream) {
EXPECT_CALL(*video_renderer_, Initialize(stream, _, _, _, _, _, _, _, _, _))
.WillOnce(DoAll(SaveArg<5>(&video_buffering_state_cb_),
+ SaveArg<6>(&video_ended_cb_),
RunCallback<2>(PIPELINE_OK)));
}
// Sets up expectations to allow the audio renderer to initialize.
- void InitializeAudioRenderer(DemuxerStream* stream) {
+ void SetAudioRendererExpectations(DemuxerStream* stream) {
EXPECT_CALL(*audio_renderer_, Initialize(stream, _, _, _, _, _, _))
.WillOnce(DoAll(SaveArg<3>(&audio_time_cb_),
SaveArg<4>(&audio_buffering_state_cb_),
+ SaveArg<5>(&audio_ended_cb_),
RunCallback<1>(PIPELINE_OK)));
}
@@ -192,7 +194,7 @@ class PipelineTest : public ::testing::Test {
// Sets up expectations on the callback and initializes the pipeline. Called
// after tests have set expectations any filters they wish to use.
- void InitializePipeline(PipelineStatus start_status) {
+ void StartPipeline(PipelineStatus start_status) {
EXPECT_CALL(callbacks_, OnStart(start_status));
if (start_status == PIPELINE_OK) {
@@ -340,6 +342,8 @@ class PipelineTest : public ::testing::Test {
AudioRenderer::TimeCB audio_time_cb_;
BufferingStateCB audio_buffering_state_cb_;
BufferingStateCB video_buffering_state_cb_;
+ base::Closure audio_ended_cb_;
+ base::Closure video_ended_cb_;
VideoDecoderConfig video_decoder_config_;
PipelineMetadata metadata_;
@@ -406,7 +410,7 @@ TEST_F(PipelineTest, URLNotFound) {
EXPECT_CALL(*demuxer_, Stop(_))
.WillOnce(RunClosure<0>());
- InitializePipeline(PIPELINE_ERROR_URL_NOT_FOUND);
+ StartPipeline(PIPELINE_ERROR_URL_NOT_FOUND);
}
TEST_F(PipelineTest, NoStreams) {
@@ -415,7 +419,7 @@ TEST_F(PipelineTest, NoStreams) {
EXPECT_CALL(*demuxer_, Stop(_))
.WillOnce(RunClosure<0>());
- InitializePipeline(PIPELINE_ERROR_COULD_NOT_RENDER);
+ StartPipeline(PIPELINE_ERROR_COULD_NOT_RENDER);
}
TEST_F(PipelineTest, AudioStream) {
@@ -423,10 +427,10 @@ TEST_F(PipelineTest, AudioStream) {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
EXPECT_TRUE(metadata_.has_audio);
EXPECT_FALSE(metadata_.has_video);
}
@@ -436,10 +440,10 @@ TEST_F(PipelineTest, VideoStream) {
MockDemuxerStreamVector streams;
streams.push_back(video_stream());
- InitializeDemuxer(&streams);
- InitializeVideoRenderer(video_stream());
+ SetDemuxerExpectations(&streams);
+ SetVideoRendererExpectations(video_stream());
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
EXPECT_FALSE(metadata_.has_audio);
EXPECT_TRUE(metadata_.has_video);
}
@@ -451,11 +455,11 @@ TEST_F(PipelineTest, AudioVideoStream) {
streams.push_back(audio_stream());
streams.push_back(video_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
- InitializeVideoRenderer(video_stream());
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
+ SetVideoRendererExpectations(video_stream());
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
EXPECT_TRUE(metadata_.has_audio);
EXPECT_TRUE(metadata_.has_video);
}
@@ -466,10 +470,10 @@ TEST_F(PipelineTest, VideoTextStream) {
MockDemuxerStreamVector streams;
streams.push_back(video_stream());
- InitializeDemuxer(&streams);
- InitializeVideoRenderer(video_stream());
+ SetDemuxerExpectations(&streams);
+ SetVideoRendererExpectations(video_stream());
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
EXPECT_FALSE(metadata_.has_audio);
EXPECT_TRUE(metadata_.has_video);
@@ -485,11 +489,11 @@ TEST_F(PipelineTest, VideoAudioTextStream) {
streams.push_back(video_stream());
streams.push_back(audio_stream());
- InitializeDemuxer(&streams);
- InitializeVideoRenderer(video_stream());
- InitializeAudioRenderer(audio_stream());
+ SetDemuxerExpectations(&streams);
+ SetVideoRendererExpectations(video_stream());
+ SetAudioRendererExpectations(audio_stream());
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
EXPECT_TRUE(metadata_.has_audio);
EXPECT_TRUE(metadata_.has_video);
@@ -505,12 +509,12 @@ TEST_F(PipelineTest, Seek) {
streams.push_back(audio_stream());
streams.push_back(video_stream());
- InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000));
- InitializeAudioRenderer(audio_stream());
- InitializeVideoRenderer(video_stream());
+ SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000));
+ SetAudioRendererExpectations(audio_stream());
+ SetVideoRendererExpectations(video_stream());
// Initialize then seek!
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
message_loop_.RunUntilIdle();
@@ -525,15 +529,15 @@ TEST_F(PipelineTest, SetVolume) {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
// The audio renderer should receive a call to SetVolume().
float expected = 0.5f;
EXPECT_CALL(*audio_renderer_, SetVolume(expected));
// Initialize then set volume!
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
pipeline_->SetVolume(expected);
}
@@ -543,10 +547,10 @@ TEST_F(PipelineTest, Properties) {
streams.push_back(video_stream());
const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
- InitializeDemuxer(&streams, kDuration);
- InitializeVideoRenderer(video_stream());
+ SetDemuxerExpectations(&streams, kDuration);
+ SetVideoRendererExpectations(video_stream());
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
EXPECT_EQ(kDuration.ToInternalValue(),
pipeline_->GetMediaDuration().ToInternalValue());
EXPECT_FALSE(pipeline_->DidLoadingProgress());
@@ -558,10 +562,10 @@ TEST_F(PipelineTest, GetBufferedTimeRanges) {
streams.push_back(video_stream());
const base::TimeDelta kDuration = base::TimeDelta::FromSeconds(100);
- InitializeDemuxer(&streams, kDuration);
- InitializeVideoRenderer(video_stream());
+ SetDemuxerExpectations(&streams, kDuration);
+ SetVideoRendererExpectations(video_stream());
- InitializePipeline(PIPELINE_OK);
+ StartPipeline(PIPELINE_OK);
EXPECT_EQ(0u, pipeline_->GetBufferedTimeRanges().size());
@@ -588,18 +592,18 @@ TEST_F(PipelineTest, EndedCallback) {
streams.push_back(audio_stream());
streams.push_back(video_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
- InitializeVideoRenderer(video_stream());
- InitializePipeline(PIPELINE_OK);
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
+ SetVideoRendererExpectations(video_stream());
+ StartPipeline(PIPELINE_OK);
AddTextStream();
// The ended callback shouldn't run until all renderers have ended.
- pipeline_->OnAudioRendererEnded();
+ audio_ended_cb_.Run();
message_loop_.RunUntilIdle();
- pipeline_->OnVideoRendererEnded();
+ video_ended_cb_.Run();
message_loop_.RunUntilIdle();
EXPECT_CALL(*audio_renderer_, StopRendering());
@@ -621,10 +625,10 @@ TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
pipeline_->SetTimeDeltaInterpolatorForTesting(
new TimeDeltaInterpolator(&test_tick_clock_));
- InitializeDemuxer(&streams, duration);
- InitializeAudioRenderer(audio_stream());
- InitializeVideoRenderer(video_stream());
- InitializePipeline(PIPELINE_OK);
+ SetDemuxerExpectations(&streams, duration);
+ SetAudioRendererExpectations(audio_stream());
+ SetVideoRendererExpectations(video_stream());
+ StartPipeline(PIPELINE_OK);
EXPECT_EQ(0, pipeline_->GetMediaTime().ToInternalValue());
@@ -642,7 +646,7 @@ TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
EXPECT_EQ(pipeline_->GetMediaTime().ToInternalValue(), start_time);
// Signal end of audio stream.
- pipeline_->OnAudioRendererEnded();
+ audio_ended_cb_.Run();
message_loop_.RunUntilIdle();
// Verify that the clock advances.
@@ -653,7 +657,7 @@ TEST_F(PipelineTest, AudioStreamShorterThanVideo) {
// Signal end of video stream and make sure OnEnded() callback occurs.
EXPECT_CALL(*audio_renderer_, StopRendering());
EXPECT_CALL(callbacks_, OnEnded());
- pipeline_->OnVideoRendererEnded();
+ video_ended_cb_.Run();
}
TEST_F(PipelineTest, ErrorDuringSeek) {
@@ -661,9 +665,9 @@ TEST_F(PipelineTest, ErrorDuringSeek) {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
- InitializePipeline(PIPELINE_OK);
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
+ StartPipeline(PIPELINE_OK);
float playback_rate = 1.0f;
EXPECT_CALL(*audio_renderer_, SetPlaybackRate(playback_rate));
@@ -716,9 +720,9 @@ TEST_F(PipelineTest, NoMessageDuringTearDownFromError) {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
- InitializePipeline(PIPELINE_OK);
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
+ StartPipeline(PIPELINE_OK);
// Trigger additional requests on the pipeline during tear down from error.
base::Callback<void(PipelineStatus)> cb = base::Bind(
@@ -760,9 +764,9 @@ TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
- InitializePipeline(PIPELINE_OK);
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
+ StartPipeline(PIPELINE_OK);
float playback_rate = 1.0f;
EXPECT_CALL(*audio_renderer_, SetPlaybackRate(playback_rate));
@@ -818,9 +822,9 @@ TEST_F(PipelineTest, DeleteAfterStop) {
CreateAudioStream();
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
- InitializePipeline(PIPELINE_OK);
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
+ StartPipeline(PIPELINE_OK);
ExpectStop();
@@ -836,10 +840,10 @@ TEST_F(PipelineTest, Underflow) {
streams.push_back(audio_stream());
streams.push_back(video_stream());
- InitializeDemuxer(&streams);
- InitializeAudioRenderer(audio_stream());
- InitializeVideoRenderer(video_stream());
- InitializePipeline(PIPELINE_OK);
+ SetDemuxerExpectations(&streams);
+ SetAudioRendererExpectations(audio_stream());
+ SetVideoRendererExpectations(video_stream());
+ StartPipeline(PIPELINE_OK);
// Simulate underflow.
EXPECT_CALL(*audio_renderer_, StopRendering());
@@ -941,7 +945,7 @@ class PipelineTeardownTest : public PipelineTest {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
streams.push_back(video_stream());
- InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(3000));
+ SetDemuxerExpectations(&streams, base::TimeDelta::FromSeconds(3000));
if (state == kInitAudioRenderer) {
if (stop_or_error == kStop) {