From cef6492128ea70329523cbcf5d4c204660090857 Mon Sep 17 00:00:00 2001 From: "scherkus@chromium.org" Date: Thu, 16 Jul 2009 01:26:40 +0000 Subject: Adding callback support to media filter Initialize() and Seek(). Also includes unit tests for AudioRendererBase and VideoRendererBase. I had to rollback my first attempt at this change. Original review: http://codereview.chromium.org/155469 BUG=16014,16031 TEST=media_unittests, layout tests Review URL: http://codereview.chromium.org/155608 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20836 0039d316-1c4b-4281-b951-d872f2087c98 --- media/base/pipeline_impl_unittest.cc | 71 +++++++++++++++++++----------------- 1 file changed, 37 insertions(+), 34 deletions(-) (limited to 'media/base/pipeline_impl_unittest.cc') diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index b673cfb..d6bd285 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -14,7 +14,9 @@ #include "testing/gtest/include/gtest/gtest.h" using ::testing::DoAll; +using ::testing::Invoke; using ::testing::Mock; +using ::testing::NotNull; using ::testing::Return; using ::testing::StrictMock; @@ -63,9 +65,8 @@ class PipelineImplTest : public ::testing::Test { protected: // Sets up expectations to allow the data source to initialize. void InitializeDataSource() { - EXPECT_CALL(*mocks_->data_source(), Initialize("")) - .WillOnce(DoAll(InitializationComplete(mocks_->data_source()), - Return(true))); + EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); EXPECT_CALL(*mocks_->data_source(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->data_source(), Stop()); } @@ -73,9 +74,9 @@ class PipelineImplTest : public ::testing::Test { // Sets up expectations to allow the demuxer to initialize. typedef std::vector MockDemuxerStreamVector; void InitializeDemuxer(MockDemuxerStreamVector* streams) { - EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source())) - .WillOnce(DoAll(InitializationComplete(mocks_->demuxer()), - Return(true))); + EXPECT_CALL(*mocks_->demuxer(), + Initialize(mocks_->data_source(), NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) .WillRepeatedly(Return(streams->size())); EXPECT_CALL(*mocks_->demuxer(), SetPlaybackRate(0.0f)); @@ -91,36 +92,34 @@ class PipelineImplTest : public ::testing::Test { // Sets up expectations to allow the video decoder to initialize. void InitializeVideoDecoder(MockDemuxerStream* stream) { - EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream)) - .WillOnce(DoAll(InitializationComplete(mocks_->video_decoder()), - Return(true))); + EXPECT_CALL(*mocks_->video_decoder(), Initialize(stream, NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); EXPECT_CALL(*mocks_->video_decoder(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->video_decoder(), Stop()); } // Sets up expectations to allow the audio decoder to initialize. void InitializeAudioDecoder(MockDemuxerStream* stream) { - EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream)) - .WillOnce(DoAll(InitializationComplete(mocks_->audio_decoder()), - Return(true))); + EXPECT_CALL(*mocks_->audio_decoder(), Initialize(stream, NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); EXPECT_CALL(*mocks_->audio_decoder(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->audio_decoder(), Stop()); } // Sets up expectations to allow the video renderer to initialize. void InitializeVideoRenderer() { - EXPECT_CALL(*mocks_->video_renderer(), Initialize(mocks_->video_decoder())) - .WillOnce(DoAll(InitializationComplete(mocks_->video_renderer()), - Return(true))); + EXPECT_CALL(*mocks_->video_renderer(), + Initialize(mocks_->video_decoder(), NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); EXPECT_CALL(*mocks_->video_renderer(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->video_renderer(), Stop()); } // Sets up expectations to allow the audio renderer to initialize. void InitializeAudioRenderer() { - EXPECT_CALL(*mocks_->audio_renderer(), Initialize(mocks_->audio_decoder())) - .WillOnce(DoAll(InitializationComplete(mocks_->audio_renderer()), - Return(true))); + EXPECT_CALL(*mocks_->audio_renderer(), + Initialize(mocks_->audio_decoder(), NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); EXPECT_CALL(*mocks_->audio_renderer(), SetPlaybackRate(0.0f)); EXPECT_CALL(*mocks_->audio_renderer(), SetVolume(1.0f)); EXPECT_CALL(*mocks_->audio_renderer(), Stop()); @@ -201,8 +200,8 @@ TEST_F(PipelineImplTest, NotStarted) { } TEST_F(PipelineImplTest, NeverInitializes) { - EXPECT_CALL(*mocks_->data_source(), Initialize("")) - .WillOnce(Return(true)); + EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) + .WillOnce(Invoke(&DestroyFilterCallback)); EXPECT_CALL(*mocks_->data_source(), Stop()); // This test hangs during initialization by never calling @@ -233,10 +232,10 @@ TEST_F(PipelineImplTest, RequiredFilterMissing) { } TEST_F(PipelineImplTest, URLNotFound) { - EXPECT_CALL(*mocks_->data_source(), Initialize("")) + EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) .WillOnce(DoAll(Error(mocks_->data_source(), PIPELINE_ERROR_URL_NOT_FOUND), - Return(false))); + Invoke(&RunFilterCallback))); EXPECT_CALL(*mocks_->data_source(), Stop()); InitializePipeline(); @@ -247,14 +246,12 @@ TEST_F(PipelineImplTest, URLNotFound) { TEST_F(PipelineImplTest, NoStreams) { // Manually set these expecations because SetPlaybackRate() is not called if // we cannot fully initialize the pipeline. - EXPECT_CALL(*mocks_->data_source(), Initialize("")) - .WillOnce(DoAll(InitializationComplete(mocks_->data_source()), - Return(true))); + EXPECT_CALL(*mocks_->data_source(), Initialize("", NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); EXPECT_CALL(*mocks_->data_source(), Stop()); - EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source())) - .WillOnce(DoAll(InitializationComplete(mocks_->demuxer()), - Return(true))); + EXPECT_CALL(*mocks_->demuxer(), Initialize(mocks_->data_source(), NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); EXPECT_CALL(*mocks_->demuxer(), GetNumberOfStreams()) .WillRepeatedly(Return(0)); EXPECT_CALL(*mocks_->demuxer(), Stop()); @@ -341,12 +338,18 @@ TEST_F(PipelineImplTest, Seek) { // Every filter should receive a call to Seek(). base::TimeDelta expected = base::TimeDelta::FromSeconds(2000); - EXPECT_CALL(*mocks_->data_source(), Seek(expected)); - EXPECT_CALL(*mocks_->demuxer(), Seek(expected)); - EXPECT_CALL(*mocks_->audio_decoder(), Seek(expected)); - EXPECT_CALL(*mocks_->audio_renderer(), Seek(expected)); - EXPECT_CALL(*mocks_->video_decoder(), Seek(expected)); - EXPECT_CALL(*mocks_->video_renderer(), Seek(expected)); + EXPECT_CALL(*mocks_->data_source(), Seek(expected, NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); + EXPECT_CALL(*mocks_->demuxer(), Seek(expected, NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); + EXPECT_CALL(*mocks_->audio_decoder(), Seek(expected, NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); + EXPECT_CALL(*mocks_->audio_renderer(), Seek(expected, NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); + EXPECT_CALL(*mocks_->video_decoder(), Seek(expected, NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); + EXPECT_CALL(*mocks_->video_renderer(), Seek(expected, NotNull())) + .WillOnce(Invoke(&RunFilterCallback)); // We expect a successful seek callback. EXPECT_CALL(callbacks_, OnSeek()); -- cgit v1.1