summaryrefslogtreecommitdiffstats
path: root/media/base/pipeline_unittest.cc
diff options
context:
space:
mode:
authoracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-08 23:41:06 +0000
committeracolwell@chromium.org <acolwell@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-08-08 23:41:06 +0000
commit6010e91c54fd2a0ff380bad292dd6fba27a3440e (patch)
tree9e1ab00938c16af60f90896fb4a91c6e6ce3d46e /media/base/pipeline_unittest.cc
parent267b106b58227e103791e5ff9177718310041f3e (diff)
downloadchromium_src-6010e91c54fd2a0ff380bad292dd6fba27a3440e.zip
chromium_src-6010e91c54fd2a0ff380bad292dd6fba27a3440e.tar.gz
chromium_src-6010e91c54fd2a0ff380bad292dd6fba27a3440e.tar.bz2
Fix Pipeline to properly handle errors during initialization.
BUG=None TESTS=PipelineTest.InitFailure_XXX Review URL: https://chromiumcodereview.appspot.com/10831214 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@150636 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/pipeline_unittest.cc')
-rw-r--r--media/base/pipeline_unittest.cc143
1 files changed, 131 insertions, 12 deletions
diff --git a/media/base/pipeline_unittest.cc b/media/base/pipeline_unittest.cc
index bd00361..a4a0588 100644
--- a/media/base/pipeline_unittest.cc
+++ b/media/base/pipeline_unittest.cc
@@ -135,7 +135,6 @@ class PipelineTest : public ::testing::Test {
EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
.WillOnce(DoAll(SetDemuxerProperties(duration),
RunPipelineStatusCB1()));
- EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f));
// Configure the demuxer to return the streams.
for (size_t i = 0; i < streams->size(); ++i) {
@@ -202,14 +201,6 @@ class PipelineTest : public ::testing::Test {
.WillOnce(DoAll(SaveArg<3>(&audio_time_cb_),
RunPipelineStatusCB1()));
}
- EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f));
- EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f));
-
- // Startup sequence.
- EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _))
- .WillOnce(RunPipelineStatusCB1());
- EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
- .WillOnce(RunClosure());
}
// Sets up expectations on the callback and initializes the pipeline. Called
@@ -217,6 +208,21 @@ class PipelineTest : public ::testing::Test {
void InitializePipeline(PipelineStatus start_status) {
EXPECT_CALL(callbacks_, OnStart(start_status));
+ if (start_status == PIPELINE_OK) {
+ EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f));
+
+ if (audio_stream_) {
+ EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f));
+ EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f));
+
+ // Startup sequence.
+ EXPECT_CALL(*mocks_->audio_renderer(), Preroll(base::TimeDelta(), _))
+ .WillOnce(RunPipelineStatusCB1());
+ EXPECT_CALL(*mocks_->audio_renderer(), Play(_))
+ .WillOnce(RunClosure());
+ }
+ }
+
pipeline_->Start(
mocks_->Create().Pass(),
base::Bind(&CallbackHelper::OnEnded, base::Unretained(&callbacks_)),
@@ -715,7 +721,7 @@ TEST_F(PipelineTest, ErrorDuringSeek) {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10));
+ InitializeDemuxer(&streams);
InitializeAudioDecoder(audio_stream());
InitializeAudioRenderer();
InitializePipeline(PIPELINE_OK);
@@ -771,7 +777,7 @@ TEST_F(PipelineTest, NoMessageDuringTearDownFromError) {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10));
+ InitializeDemuxer(&streams);
InitializeAudioDecoder(audio_stream());
InitializeAudioRenderer();
InitializePipeline(PIPELINE_OK);
@@ -856,7 +862,7 @@ TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) {
MockDemuxerStreamVector streams;
streams.push_back(audio_stream());
- InitializeDemuxer(&streams, base::TimeDelta::FromSeconds(10));
+ InitializeDemuxer(&streams);
InitializeAudioDecoder(audio_stream());
InitializeAudioRenderer();
InitializePipeline(PIPELINE_OK);
@@ -904,6 +910,119 @@ TEST_F(PipelineTest, AudioTimeUpdateDuringSeek) {
EXPECT_EQ(pipeline_->GetMediaTime(), new_time);
}
+TEST_F(PipelineTest, InitFailure_Demuxer) {
+ PipelineStatus expected_status = DEMUXER_ERROR_COULD_NOT_OPEN;
+ EXPECT_CALL(*mocks_->demuxer(), Initialize(_, _))
+ .WillOnce(RunPipelineStatusCB1WithStatus(expected_status));
+ EXPECT_CALL(*mocks_->demuxer(), Stop(_))
+ .WillOnce(RunClosure());
+ InitializePipeline(expected_status);
+ EXPECT_FALSE(pipeline_->IsInitialized());
+}
+
+TEST_F(PipelineTest, InitFailure_AudioDecoder) {
+ CreateAudioStream();
+ MockDemuxerStreamVector streams;
+ streams.push_back(audio_stream());
+
+ InitializeDemuxer(&streams);
+
+ PipelineStatus expected_status = PIPELINE_ERROR_DECODE;
+ scoped_refptr<DemuxerStream> stream = streams[0];
+ EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, _, _))
+ .WillOnce(RunPipelineStatusCB1WithStatus(expected_status));
+
+ EXPECT_CALL(*mocks_->demuxer(), Stop(_))
+ .WillOnce(RunClosure());
+
+ InitializePipeline(expected_status);
+ EXPECT_FALSE(pipeline_->IsInitialized());
+ EXPECT_FALSE(pipeline_->HasAudio());
+}
+
+TEST_F(PipelineTest, InitFailure_AudioRenderer) {
+ CreateAudioStream();
+ MockDemuxerStreamVector streams;
+ streams.push_back(audio_stream());
+
+ InitializeDemuxer(&streams);
+ InitializeAudioDecoder(audio_stream());
+
+ PipelineStatus expected_status = PIPELINE_ERROR_INITIALIZATION_FAILED;
+ EXPECT_CALL(*mocks_->audio_renderer(), Initialize(
+ scoped_refptr<AudioDecoder>(mocks_->audio_decoder()),
+ _, _, _, _, _, _))
+ .WillOnce(RunPipelineStatusCB1WithStatus(expected_status));
+
+ EXPECT_CALL(*mocks_->demuxer(), Stop(_))
+ .WillOnce(RunClosure());
+ EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
+ .WillOnce(RunClosure());
+
+ InitializePipeline(expected_status);
+ EXPECT_FALSE(pipeline_->IsInitialized());
+ EXPECT_TRUE(pipeline_->HasAudio());
+}
+
+TEST_F(PipelineTest, InitFailure_VideoDecoder) {
+ CreateAudioStream();
+ CreateVideoStream();
+ MockDemuxerStreamVector streams;
+ streams.push_back(audio_stream());
+ streams.push_back(video_stream());
+
+ InitializeDemuxer(&streams);
+ InitializeAudioDecoder(audio_stream());
+ InitializeAudioRenderer();
+
+ PipelineStatus expected_status = PIPELINE_ERROR_DECODE;
+ scoped_refptr<DemuxerStream> stream = streams[1];
+ EXPECT_CALL(*mocks_->video_decoder(),
+ Initialize(stream, _, _))
+ .WillOnce(RunPipelineStatusCB1WithStatus(expected_status));
+
+ EXPECT_CALL(*mocks_->demuxer(), Stop(_))
+ .WillOnce(RunClosure());
+ EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
+ .WillOnce(RunClosure());
+
+ InitializePipeline(expected_status);
+ EXPECT_FALSE(pipeline_->IsInitialized());
+ EXPECT_TRUE(pipeline_->HasAudio());
+ EXPECT_FALSE(pipeline_->HasVideo());
+}
+
+TEST_F(PipelineTest, InitFailure_VideoRenderer) {
+ CreateAudioStream();
+ CreateVideoStream();
+ MockDemuxerStreamVector streams;
+ streams.push_back(audio_stream());
+ streams.push_back(video_stream());
+
+ InitializeDemuxer(&streams);
+ InitializeAudioDecoder(audio_stream());
+ InitializeAudioRenderer();
+ InitializeVideoDecoder(video_stream());
+
+ PipelineStatus expected_status = PIPELINE_ERROR_INITIALIZATION_FAILED;
+ EXPECT_CALL(*mocks_->video_renderer(), Initialize(
+ scoped_refptr<VideoDecoder>(mocks_->video_decoder()),
+ _, _, _, _, _, _, _, _))
+ .WillOnce(RunPipelineStatusCB1WithStatus(expected_status));
+
+ EXPECT_CALL(*mocks_->demuxer(), Stop(_))
+ .WillOnce(RunClosure());
+ EXPECT_CALL(*mocks_->audio_renderer(), Stop(_))
+ .WillOnce(RunClosure());
+ EXPECT_CALL(*mocks_->video_renderer(), Stop(_))
+ .WillOnce(RunClosure());
+
+ InitializePipeline(expected_status);
+ EXPECT_FALSE(pipeline_->IsInitialized());
+ EXPECT_TRUE(pipeline_->HasAudio());
+ EXPECT_TRUE(pipeline_->HasVideo());
+}
+
class FlexibleCallbackRunner : public base::DelegateSimpleThread::Delegate {
public:
FlexibleCallbackRunner(base::TimeDelta delay, PipelineStatus status,