summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-15 02:10:46 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-01-15 02:10:46 +0000
commite93e25629859d7d7f08428abd5bdad8a403515d4 (patch)
tree7226891aaed52aeed48922e8293ab05df72e42e1
parent86809eba59ca96feb557e98bbc5bdcf03c0c149b (diff)
downloadchromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.zip
chromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.tar.gz
chromium_src-e93e25629859d7d7f08428abd5bdad8a403515d4.tar.bz2
Replace MockFilterCallback with MockCallback and simplify unit tests.
We had a ton of unnecessarily duplicated code, most of which could be solved by introducing NewExpectedCallback(). BUG=none TEST=media_unittests Review URL: http://codereview.chromium.org/6350001 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@71537 0039d316-1c4b-4281-b951-d872f2087c98
-rw-r--r--chrome/renderer/media/audio_renderer_impl_unittest.cc28
-rw-r--r--media/base/composite_filter_unittest.cc125
-rw-r--r--media/base/mock_callback.cc29
-rw-r--r--media/base/mock_callback.h57
-rw-r--r--media/base/mock_filters.cc12
-rw-r--r--media/base/mock_filters.h51
-rw-r--r--media/filters/audio_renderer_base_unittest.cc63
-rw-r--r--media/filters/decoder_base_unittest.cc10
-rw-r--r--media/filters/ffmpeg_demuxer_unittest.cc45
-rw-r--r--media/filters/ffmpeg_video_decoder_unittest.cc35
-rw-r--r--media/filters/file_data_source_unittest.cc32
-rw-r--r--media/filters/video_renderer_base_unittest.cc50
-rw-r--r--media/media.gyp2
-rw-r--r--webkit/glue/media/buffered_data_source_unittest.cc16
-rw-r--r--webkit/glue/media/simple_data_source_unittest.cc45
15 files changed, 216 insertions, 384 deletions
diff --git a/chrome/renderer/media/audio_renderer_impl_unittest.cc b/chrome/renderer/media/audio_renderer_impl_unittest.cc
index 6dd3dc7..b5f80e6 100644
--- a/chrome/renderer/media/audio_renderer_impl_unittest.cc
+++ b/chrome/renderer/media/audio_renderer_impl_unittest.cc
@@ -1,14 +1,14 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/callback.h"
#include "base/process_util.h"
#include "chrome/common/render_messages.h"
#include "chrome/common/render_messages_params.h"
#include "chrome/renderer/media/audio_renderer_impl.h"
#include "media/base/data_buffer.h"
#include "media/base/media_format.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -32,8 +32,6 @@ class AudioRendererImplTest : public ::testing::Test {
CHECK(shared_mem_.CreateAnonymous(kSize));
// Setup expectations for initialization.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
decoder_ = new media::MockAudioDecoder();
// Associate media format with decoder
@@ -49,7 +47,7 @@ class AudioRendererImplTest : public ::testing::Test {
renderer_ = new AudioRendererImpl(filter_);
renderer_->set_host(&host_);
renderer_->set_message_loop(message_loop_.get());
- renderer_->Initialize(decoder_, callback_.NewCallback());
+ renderer_->Initialize(decoder_, media::NewExpectedCallback());
// Run pending tasks and simulate responding with a created audio stream.
message_loop_->RunAllPending();
@@ -72,8 +70,6 @@ class AudioRendererImplTest : public ::testing::Test {
scoped_refptr<AudioMessageFilter> filter_;
base::SharedMemory shared_mem_;
media::MockFilterHost host_;
- media::MockFilterCallback callback_;
- media::MockFilterCallback stop_callback_;
scoped_refptr<media::MockAudioDecoder> decoder_;
scoped_refptr<AudioRendererImpl> renderer_;
media::MediaFormat decoder_media_format_;
@@ -90,16 +86,14 @@ TEST_F(AudioRendererImplTest, SetPlaybackRate) {
renderer_->SetPlaybackRate(1.0f);
renderer_->SetPlaybackRate(0.0f);
- EXPECT_CALL(stop_callback_, OnFilterCallback());
- renderer_->Stop(stop_callback_.NewCallback());
+ renderer_->Stop(media::NewExpectedCallback());
message_loop_->RunAllPending();
}
TEST_F(AudioRendererImplTest, SetVolume) {
// Execute SetVolume() codepath to create an IPC message.
renderer_->SetVolume(0.5f);
- EXPECT_CALL(stop_callback_, OnFilterCallback());
- renderer_->Stop(stop_callback_.NewCallback());
+ renderer_->Stop(media::NewExpectedCallback());
message_loop_->RunAllPending();
}
@@ -113,8 +107,7 @@ TEST_F(AudioRendererImplTest, Stop) {
ViewMsg_AudioStreamState_Params::kPaused);
// Execute Stop() codepath to create an IPC message.
- EXPECT_CALL(stop_callback_, OnFilterCallback());
- renderer_->Stop(stop_callback_.NewCallback());
+ renderer_->Stop(media::NewExpectedCallback());
message_loop_->RunAllPending();
// Run AudioMessageFilter::Delegate methods, which can be executed after being
@@ -137,16 +130,14 @@ TEST_F(AudioRendererImplTest, DestroyedMessageLoop_SetPlaybackRate) {
renderer_->SetPlaybackRate(0.0f);
renderer_->SetPlaybackRate(1.0f);
renderer_->SetPlaybackRate(0.0f);
- EXPECT_CALL(stop_callback_, OnFilterCallback());
- renderer_->Stop(stop_callback_.NewCallback());
+ renderer_->Stop(media::NewExpectedCallback());
}
TEST_F(AudioRendererImplTest, DestroyedMessageLoop_SetVolume) {
// Kill the message loop and verify SetVolume() still works.
message_loop_.reset();
renderer_->SetVolume(0.5f);
- EXPECT_CALL(stop_callback_, OnFilterCallback());
- renderer_->Stop(stop_callback_.NewCallback());
+ renderer_->Stop(media::NewExpectedCallback());
}
TEST_F(AudioRendererImplTest, DestroyedMessageLoop_ConsumeAudioSamples) {
@@ -154,6 +145,5 @@ TEST_F(AudioRendererImplTest, DestroyedMessageLoop_ConsumeAudioSamples) {
message_loop_.reset();
scoped_refptr<media::Buffer> buffer(new media::DataBuffer(kSize));
renderer_->ConsumeAudioSamples(buffer);
- EXPECT_CALL(stop_callback_, OnFilterCallback());
- renderer_->Stop(stop_callback_.NewCallback());
+ renderer_->Stop(media::NewExpectedCallback());
}
diff --git a/media/base/composite_filter_unittest.cc b/media/base/composite_filter_unittest.cc
index fe757c3..4ce96c1 100644
--- a/media/base/composite_filter_unittest.cc
+++ b/media/base/composite_filter_unittest.cc
@@ -1,8 +1,9 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/base/composite_filter.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -209,9 +210,6 @@ void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call,
base::TimeDelta seek_time) {
InSequence seq;
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
-
bool is_parallel_call = (method_to_call == FLUSH);
ExpectFilterCall(method_to_call, filter_1_.get(), seek_time);
@@ -221,8 +219,8 @@ void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call,
}
// Make method call on the composite.
- DoFilterCall(method_to_call, composite_.get(), seek_time,
- mock_callback->NewCallback());
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ DoFilterCall(method_to_call, composite_.get(), seek_time, callback);
if (is_parallel_call) {
// Make sure both filters have their callbacks set.
@@ -243,7 +241,7 @@ void CompositeFilterTest::ExpectSuccess(MethodToCall method_to_call,
EXPECT_TRUE(filter_2_callback_ != NULL);
}
- EXPECT_CALL(*mock_callback, OnFilterCallback());
+ callback->ExpectRunAndDelete();
RunFilter2Callback();
}
@@ -271,15 +269,11 @@ void CompositeFilterTest::DoSeek(base::TimeDelta time) {
void CompositeFilterTest::ExpectInvalidStateFail(MethodToCall method_to_call,
base::TimeDelta seek_time) {
InSequence seq;
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_INVALID_STATE))
.WillOnce(Return());
- EXPECT_CALL(*mock_callback, OnFilterCallback());
- DoFilterCall(method_to_call, composite_, seek_time,
- mock_callback->NewCallback());
+ DoFilterCall(method_to_call, composite_, seek_time, NewExpectedCallback());
// Make sure that neither of the filters were called by
// verifying that the callback pointers weren't set.
@@ -364,15 +358,11 @@ TEST_F(CompositeFilterTest, TestPlay) {
DoPlay();
// At this point we are now in the kPlaying state.
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
// Try calling Play() again to make sure that we simply get a callback.
// We are already in the Play() state so there is no point calling the
// filters.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
-
- composite_->Play(mock_callback->NewCallback());
+ composite_->Play(NewExpectedCallback());
// Verify that neither of the filter callbacks were set.
EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
@@ -384,9 +374,7 @@ TEST_F(CompositeFilterTest, TestPlay) {
// At this point we should be in the kStopped state.
// Try calling Stop() again to make sure neither filter is called.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
-
- composite_->Stop(mock_callback->NewCallback());
+ composite_->Stop(NewExpectedCallback());
// Verify that neither of the filter callbacks were set.
EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
@@ -402,13 +390,11 @@ TEST_F(CompositeFilterTest, TestPlayErrors) {
SetupAndAdd2Filters();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
-
EXPECT_CALL(*filter_1_, Play(_));
// Call Play() on the composite.
- composite_->Play(mock_callback->NewCallback());
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ composite_->Play(callback);
EXPECT_CALL(*filter_2_, Play(_));
@@ -421,7 +407,7 @@ TEST_F(CompositeFilterTest, TestPlayErrors) {
// Expect error to be reported and "play done" callback to be called.
EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
- EXPECT_CALL(*mock_callback, OnFilterCallback());
+ callback->ExpectRunAndDelete();
// Run callback to indicate that |filter_2_|'s Play() has completed.
RunFilter2Callback();
@@ -441,9 +427,6 @@ TEST_F(CompositeFilterTest, TestPause) {
SetupAndAdd2Filters();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
-
// Try calling Pause() to make sure we get an error because we aren't in
// the playing state.
ExpectInvalidStateFail(PAUSE);
@@ -458,9 +441,7 @@ TEST_F(CompositeFilterTest, TestPause) {
// Try calling Pause() again to make sure that the filters aren't called
// because we are already in the paused state.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
-
- composite_->Pause(mock_callback->NewCallback());
+ composite_->Pause(NewExpectedCallback());
// Verify that neither of the filter callbacks were set.
EXPECT_EQ((FilterCallback*)NULL, filter_1_callback_);
@@ -488,13 +469,11 @@ TEST_F(CompositeFilterTest, TestPauseErrors) {
DoPlay();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
-
EXPECT_CALL(*filter_1_, Pause(_));
// Call Pause() on the composite.
- composite_->Pause(mock_callback->NewCallback());
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ composite_->Pause(callback);
// Simulate an error by calling SetError() on |filter_1_|'s FilterHost
// interface.
@@ -502,7 +481,7 @@ TEST_F(CompositeFilterTest, TestPauseErrors) {
// Expect error to be reported and "pause done" callback to be called.
EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
- EXPECT_CALL(*mock_callback, OnFilterCallback());
+ callback->ExpectRunAndDelete();
RunFilter1Callback();
@@ -524,9 +503,6 @@ TEST_F(CompositeFilterTest, TestFlush) {
SetupAndAdd2Filters();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
-
// Make sure Flush() works before calling Play().
DoFlush();
@@ -559,14 +535,12 @@ TEST_F(CompositeFilterTest, TestFlushErrors) {
SetupAndAdd2Filters();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
-
EXPECT_CALL(*filter_1_, Flush(_));
EXPECT_CALL(*filter_2_, Flush(_));
// Call Flush() on the composite.
- composite_->Flush(mock_callback->NewCallback());
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ composite_->Flush(callback);
// Simulate an error by calling SetError() on |filter_1_|'s FilterHost
// interface.
@@ -576,7 +550,7 @@ TEST_F(CompositeFilterTest, TestFlushErrors) {
// Expect error to be reported and "pause done" callback to be called.
EXPECT_CALL(*mock_filter_host_, SetError(PIPELINE_ERROR_OUT_OF_MEMORY));
- EXPECT_CALL(*mock_callback, OnFilterCallback());
+ callback->ExpectRunAndDelete();
RunFilter2Callback();
@@ -601,9 +575,6 @@ TEST_F(CompositeFilterTest, TestSeek) {
// Verify we can issue a Play() after the Seek().
DoPlay();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
-
// Try calling Seek() while playing to make sure we get an error.
ExpectInvalidStateFail(SEEK);
@@ -632,12 +603,11 @@ TEST_F(CompositeFilterTest, TestStop) {
// Test error during Stop() sequence.
SetupAndAdd2Filters();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
EXPECT_CALL(*filter_1_, Stop(_));
- composite_->Stop(mock_callback->NewCallback());
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ composite_->Stop(callback);
// Have |filter_1_| signal an error.
filter_1_->host()->SetError(PIPELINE_ERROR_READ);
@@ -646,7 +616,7 @@ TEST_F(CompositeFilterTest, TestStop) {
RunFilter1Callback();
- EXPECT_CALL(*mock_callback, OnFilterCallback());
+ callback->ExpectRunAndDelete();
RunFilter2Callback();
}
@@ -657,21 +627,17 @@ TEST_F(CompositeFilterTest, TestStopWhilePlayPending) {
SetupAndAdd2Filters();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>());
-
EXPECT_CALL(*filter_1_, Play(_));
- composite_->Play(mock_callback->NewCallback());
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ composite_->Play(callback);
// Note: Play() is pending on |filter_1_| right now.
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback_2(
- new StrictMock<MockFilterCallback>(false));
-
- EXPECT_CALL(*mock_callback, OnCallbackDestroyed());
+ EXPECT_CALL(*callback, Destructor());
- composite_->Stop(mock_callback_2->NewCallback());
+ callback = new StrictMock<MockCallback>();
+ composite_->Stop(callback);
EXPECT_CALL(*filter_1_, Stop(_));
@@ -683,7 +649,7 @@ TEST_F(CompositeFilterTest, TestStopWhilePlayPending) {
// Run |filter_1_|'s callback again to indicate Stop() has completed.
RunFilter1Callback();
- EXPECT_CALL(*mock_callback_2, OnFilterCallback());
+ callback->ExpectRunAndDelete();
// Run |filter_2_|'s callback to indicate Stop() has completed.
RunFilter2Callback();
@@ -695,22 +661,18 @@ TEST_F(CompositeFilterTest, TestStopWhileFlushPending) {
SetupAndAdd2Filters();
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>());
-
EXPECT_CALL(*filter_1_, Flush(_));
EXPECT_CALL(*filter_2_, Flush(_));
- composite_->Flush(mock_callback->NewCallback());
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ composite_->Flush(callback);
// Note: |filter_1_| and |filter_2_| have pending Flush() calls at this point.
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback_2(
- new StrictMock<MockFilterCallback>(false));
-
- EXPECT_CALL(*mock_callback, OnCallbackDestroyed());
+ EXPECT_CALL(*callback, Destructor());
- composite_->Stop(mock_callback_2->NewCallback());
+ callback = new StrictMock<MockCallback>();
+ composite_->Stop(callback);
// Run callback to indicate that |filter_1_|'s Flush() has completed.
RunFilter1Callback();
@@ -725,7 +687,7 @@ TEST_F(CompositeFilterTest, TestStopWhileFlushPending) {
// Run callback to indicate that |filter_1_|'s Stop() has completed.
RunFilter1Callback();
- EXPECT_CALL(*mock_callback_2, OnFilterCallback());
+ callback->ExpectRunAndDelete();
// Run callback to indicate that |filter_2_|'s Stop() has completed.
RunFilter2Callback();
@@ -767,33 +729,24 @@ TEST_F(CompositeFilterTest, TestEmptyComposite) {
composite_->set_host(mock_filter_host_.get());
- scoped_ptr<StrictMock<MockFilterCallback> > mock_callback(
- new StrictMock<MockFilterCallback>(false));
-
// Issue a Play() and expect no errors.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
- composite_->Play(mock_callback->NewCallback());
+ composite_->Play(NewExpectedCallback());
// Issue a Pause() and expect no errors.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
- composite_->Pause(mock_callback->NewCallback());
+ composite_->Pause(NewExpectedCallback());
// Issue a Flush() and expect no errors.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
- composite_->Flush(mock_callback->NewCallback());
+ composite_->Flush(NewExpectedCallback());
// Issue a Seek() and expect no errors.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
composite_->Seek(base::TimeDelta::FromSeconds(5),
- mock_callback->NewCallback());
+ NewExpectedCallback());
// Issue a Play() and expect no errors.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
- composite_->Play(mock_callback->NewCallback());
+ composite_->Play(NewExpectedCallback());
// Issue a Stop() and expect no errors.
- EXPECT_CALL(*mock_callback, OnFilterCallback());
- composite_->Stop(mock_callback->NewCallback());
+ composite_->Stop(NewExpectedCallback());
}
} // namespace media
diff --git a/media/base/mock_callback.cc b/media/base/mock_callback.cc
new file mode 100644
index 0000000..e948368
--- /dev/null
+++ b/media/base/mock_callback.cc
@@ -0,0 +1,29 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "media/base/mock_callback.h"
+
+using ::testing::_;
+using ::testing::StrictMock;
+
+namespace media {
+
+MockCallback::MockCallback() {}
+
+MockCallback::~MockCallback() {
+ Destructor();
+}
+
+void MockCallback::ExpectRunAndDelete() {
+ EXPECT_CALL(*this, RunWithParams(_));
+ EXPECT_CALL(*this, Destructor());
+}
+
+MockCallback* NewExpectedCallback() {
+ StrictMock<MockCallback>* callback = new StrictMock<MockCallback>();
+ callback->ExpectRunAndDelete();
+ return callback;
+}
+
+} // namespace media
diff --git a/media/base/mock_callback.h b/media/base/mock_callback.h
new file mode 100644
index 0000000..2aef84a
--- /dev/null
+++ b/media/base/mock_callback.h
@@ -0,0 +1,57 @@
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef MEDIA_BASE_MOCK_CALLBACK_H_
+#define MEDIA_BASE_MOCK_CALLBACK_H_
+
+#include "base/callback.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace media {
+
+// Helper class used to test that callbacks are executed.
+//
+// In most cases NewExpectedCallback() can be used but if need be you can
+// manually set expectations on an MockCallback object:
+//
+// StrictMock<MockCallback>* callback =
+// new StrictMock<MockCallback>();
+// EXPECT_CALL(*callback, RunWithParams(_));
+// EXPECT_CALL(*callback, Destructor());
+//
+// ...or the equivalent and less verbose:
+// StrictMock<MockCallback>* callback =
+// new StrictMock<MockCallback>();
+// callback->ExpectRunAndDelete();
+//
+// ...or if you don't care about verifying callback deletion:
+//
+// NiceMock<MockCallback>* callback =
+// new NiceMock<MockCallback>();
+// EXPECT_CALL(*callback, RunWithParams(_));
+class MockCallback : public CallbackRunner<Tuple0> {
+ public:
+ MockCallback();
+ virtual ~MockCallback();
+
+ MOCK_METHOD1(RunWithParams, void(const Tuple0& params));
+
+ // Can be used to verify the object is destroyed.
+ MOCK_METHOD0(Destructor, void());
+
+ // Convenience function to set expectations for the callback to execute and
+ // deleted.
+ void ExpectRunAndDelete();
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockCallback);
+};
+
+// Convenience function that automatically creates and sets an expectation for
+// the callback to run.
+MockCallback* NewExpectedCallback();
+
+} // namespace media
+
+#endif // MEDIA_BASE_MOCK_CALLBACK_H_
diff --git a/media/base/mock_filters.cc b/media/base/mock_filters.cc
index 39ed730..90df69b 100644
--- a/media/base/mock_filters.cc
+++ b/media/base/mock_filters.cc
@@ -6,18 +6,6 @@
namespace media {
-MockFilterCallback::MockFilterCallback() : run_destroy_callback_(true) {}
-
-MockFilterCallback::MockFilterCallback(bool run_destroy_callback) :
- run_destroy_callback_(run_destroy_callback) {
-}
-
-MockFilterCallback::~MockFilterCallback() {}
-
-FilterCallback* MockFilterCallback::NewCallback() {
- return new CallbackImpl(this, run_destroy_callback_);
-}
-
MockDataSource::MockDataSource() {}
MockDataSource::~MockDataSource() {}
diff --git a/media/base/mock_filters.h b/media/base/mock_filters.h
index 5f43356..45c1e29 100644
--- a/media/base/mock_filters.h
+++ b/media/base/mock_filters.h
@@ -15,7 +15,6 @@
#include <string>
-#include "base/callback.h"
#include "media/base/filters.h"
#include "media/base/filter_collection.h"
#include "media/base/video_frame.h"
@@ -44,56 +43,6 @@ class Destroyable : public MockClass {
DISALLOW_COPY_AND_ASSIGN(Destroyable);
};
-// Helper class used to test that callbacks are executed. It is recommend you
-// combine this class with StrictMock<> to verify that the callback is executed.
-// You can reuse the same instance of a MockFilterCallback many times since
-// gmock will track the number of times the methods are executed.
-class MockFilterCallback {
- public:
- MockFilterCallback();
- MockFilterCallback(bool run_destroy_callback);
- virtual ~MockFilterCallback();
-
- MOCK_METHOD0(OnCallbackDestroyed, void());
- MOCK_METHOD0(OnFilterCallback, void());
-
- // Helper method to create a new callback for this mock. The callback will
- // call OnFilterCallback() when executed and OnCallbackDestroyed() when
- // destroyed. Clients should use NiceMock<> or StrictMock<> depending on the
- // test.
- FilterCallback* NewCallback();
-
- private:
- // Private implementation of CallbackRunner used to trigger expectations on
- // MockFilterCallback.
- class CallbackImpl : public CallbackRunner<Tuple0> {
- public:
- explicit CallbackImpl(MockFilterCallback* mock_callback,
- bool run_destroy_callback)
- : mock_callback_(mock_callback),
- run_destroy_callback_(run_destroy_callback) {
- }
-
- virtual ~CallbackImpl() {
- if (run_destroy_callback_)
- mock_callback_->OnCallbackDestroyed();
- }
-
- virtual void RunWithParams(const Tuple0& params) {
- mock_callback_->OnFilterCallback();
- }
-
- private:
- MockFilterCallback* mock_callback_;
- bool run_destroy_callback_;
-
- DISALLOW_COPY_AND_ASSIGN(CallbackImpl);
- };
-
- bool run_destroy_callback_;
- DISALLOW_COPY_AND_ASSIGN(MockFilterCallback);
-};
-
class MockFilter : public Filter {
public:
MockFilter();
diff --git a/media/filters/audio_renderer_base_unittest.cc b/media/filters/audio_renderer_base_unittest.cc
index de4f3c6..ae8e515 100644
--- a/media/filters/audio_renderer_base_unittest.cc
+++ b/media/filters/audio_renderer_base_unittest.cc
@@ -1,10 +1,10 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/callback.h"
#include "base/stl_util-inl.h"
#include "media/base/data_buffer.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
#include "media/filters/audio_renderer_base.h"
@@ -70,9 +70,7 @@ class AudioRendererBaseTest : public ::testing::Test {
virtual ~AudioRendererBaseTest() {
// Expect a call into the subclass.
EXPECT_CALL(*renderer_, OnStop());
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- renderer_->Stop(callback_.NewCallback());
+ renderer_->Stop(NewExpectedCallback());
}
protected:
@@ -82,7 +80,6 @@ class AudioRendererBaseTest : public ::testing::Test {
scoped_refptr<MockAudioRendererBase> renderer_;
scoped_refptr<MockAudioDecoder> decoder_;
StrictMock<MockFilterHost> host_;
- StrictMock<MockFilterCallback> callback_;
MediaFormat decoder_media_format_;
// Number of asynchronous read requests sent to |decoder_|.
@@ -108,12 +105,8 @@ TEST_F(AudioRendererBaseTest, Initialize_Failed) {
// We expect to receive an error.
EXPECT_CALL(host_, SetError(PIPELINE_ERROR_INITIALIZATION_FAILED));
- // We expect our callback to be executed.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
// Initialize, we expect to have no reads.
- renderer_->Initialize(decoder_, callback_.NewCallback());
+ renderer_->Initialize(decoder_, NewExpectedCallback());
EXPECT_EQ(0u, pending_reads_);
}
@@ -124,26 +117,15 @@ TEST_F(AudioRendererBaseTest, Initialize_Successful) {
EXPECT_CALL(*renderer_, OnInitialize(_))
.WillOnce(Return(true));
- // After finishing initialization, we expect our callback to be executed.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
- // Verify the following expectations haven't run until we complete the reads.
- EXPECT_CALL(*renderer_, CheckPoint(0));
-
- MockFilterCallback seek_callback;
- EXPECT_CALL(seek_callback, OnFilterCallback());
- EXPECT_CALL(seek_callback, OnCallbackDestroyed());
-
// Initialize, we shouldn't have any reads.
- renderer_->Initialize(decoder_, callback_.NewCallback());
+ renderer_->Initialize(decoder_, NewExpectedCallback());
EXPECT_EQ(0u, pending_reads_);
- // Now seek to trigger prerolling.
- renderer_->Seek(base::TimeDelta(), seek_callback.NewCallback());
+ // Now seek to trigger prerolling, verifying the callback hasn't been
+ // executed yet.
+ EXPECT_CALL(*renderer_, CheckPoint(0));
+ renderer_->Seek(base::TimeDelta(), NewExpectedCallback());
EXPECT_EQ(kMaxQueueSize, pending_reads_);
-
- // Verify our seek callback hasn't been executed yet.
renderer_->CheckPoint(0);
// Now satisfy the read requests. Our callback should be executed after
@@ -163,26 +145,15 @@ TEST_F(AudioRendererBaseTest, OneCompleteReadCycle) {
EXPECT_CALL(*renderer_, OnInitialize(_))
.WillOnce(Return(true));
- // After finishing initialization, we expect our callback to be executed.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
- // Verify the following expectations haven't run until we complete the reads.
- EXPECT_CALL(*renderer_, CheckPoint(0));
-
- MockFilterCallback seek_callback;
- EXPECT_CALL(seek_callback, OnFilterCallback());
- EXPECT_CALL(seek_callback, OnCallbackDestroyed());
-
// Initialize, we shouldn't have any reads.
- renderer_->Initialize(decoder_, callback_.NewCallback());
+ renderer_->Initialize(decoder_, NewExpectedCallback());
EXPECT_EQ(0u, pending_reads_);
- // Now seek to trigger prerolling.
- renderer_->Seek(base::TimeDelta(), seek_callback.NewCallback());
+ // Now seek to trigger prerolling, verifying the callback hasn't been
+ // executed yet.
+ EXPECT_CALL(*renderer_, CheckPoint(0));
+ renderer_->Seek(base::TimeDelta(), NewExpectedCallback());
EXPECT_EQ(kMaxQueueSize, pending_reads_);
-
- // Verify our seek callback hasn't been executed yet.
renderer_->CheckPoint(0);
// Now satisfy the read requests. Our callback should be executed after
@@ -197,12 +168,8 @@ TEST_F(AudioRendererBaseTest, OneCompleteReadCycle) {
bytes_buffered += kDataSize;
}
- MockFilterCallback play_callback;
- EXPECT_CALL(play_callback, OnFilterCallback());
- EXPECT_CALL(play_callback, OnCallbackDestroyed());
-
// Then set the renderer to play state.
- renderer_->Play(play_callback.NewCallback());
+ renderer_->Play(NewExpectedCallback());
renderer_->SetPlaybackRate(1.0f);
EXPECT_EQ(1.0f, renderer_->GetPlaybackRate());
diff --git a/media/filters/decoder_base_unittest.cc b/media/filters/decoder_base_unittest.cc
index e4cec5d..2fefb56 100644
--- a/media/filters/decoder_base_unittest.cc
+++ b/media/filters/decoder_base_unittest.cc
@@ -4,6 +4,7 @@
#include <vector>
+#include "media/base/mock_callback.h"
#include "media/base/mock_filters.h"
#include "media/base/mock_task.h"
#include "media/filters/decoder_base.h"
@@ -121,15 +122,12 @@ TEST(DecoderBaseTest, FlowControl) {
decoder->set_consume_audio_samples_callback(
NewCallback(&read_callback, &MockDecoderCallback::OnReadComplete));
scoped_refptr<MockDemuxerStream> demuxer_stream(new MockDemuxerStream());
- StrictMock<MockFilterCallback> callback;
decoder->set_message_loop(&message_loop);
// Initailize.
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
EXPECT_CALL(*decoder, DoInitialize(NotNull(), NotNull(), NotNull()))
.WillOnce(Initialize());
- decoder->Initialize(demuxer_stream.get(), callback.NewCallback());
+ decoder->Initialize(demuxer_stream.get(), NewExpectedCallback());
message_loop.RunAllPending();
// Read.
@@ -157,9 +155,7 @@ TEST(DecoderBaseTest, FlowControl) {
// Stop.
EXPECT_CALL(*decoder, DoStop(_))
.WillOnce(WithArg<0>(InvokeRunnable()));
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
- decoder->Stop(callback.NewCallback());
+ decoder->Stop(NewExpectedCallback());
message_loop.RunAllPending();
}
diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc
index 97631d4..0bb21c0 100644
--- a/media/filters/ffmpeg_demuxer_unittest.cc
+++ b/media/filters/ffmpeg_demuxer_unittest.cc
@@ -1,12 +1,12 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <deque>
-#include "base/callback.h"
#include "base/threading/thread.h"
#include "media/base/filters.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_ffmpeg.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
@@ -113,9 +113,7 @@ class FFmpegDemuxerTest : public testing::Test {
virtual ~FFmpegDemuxerTest() {
// Call Stop() to shut down internal threads.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- demuxer_->Stop(callback_.NewCallback());
+ demuxer_->Stop(NewExpectedCallback());
// Finish up any remaining tasks.
message_loop_.RunAllPending();
@@ -140,17 +138,13 @@ class FFmpegDemuxerTest : public testing::Test {
void InitializeDemuxer() {
InitializeDemuxerMocks();
- // We expect a successful initialization.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
// Since we ignore data streams, the duration should be equal to the longest
// supported stream's duration (audio, in this case).
base::TimeDelta expected_duration =
base::TimeDelta::FromMicroseconds(kDurations[AV_STREAM_AUDIO]);
EXPECT_CALL(host_, SetDuration(expected_duration));
- demuxer_->Initialize(data_source_.get(), callback_.NewCallback());
+ demuxer_->Initialize(data_source_.get(), NewExpectedCallback());
message_loop_.RunAllPending();
}
@@ -158,7 +152,6 @@ class FFmpegDemuxerTest : public testing::Test {
scoped_refptr<FFmpegDemuxer> demuxer_;
scoped_refptr<StrictMock<MockDataSource> > data_source_;
StrictMock<MockFilterHost> host_;
- StrictMock<MockFilterCallback> callback_;
MessageLoop message_loop_;
// FFmpeg fixtures.
@@ -190,10 +183,8 @@ TEST_F(FFmpegDemuxerTest, Initialize_OpenFails) {
EXPECT_CALL(*MockFFmpeg::get(), AVOpenInputFile(_, _, NULL, 0, NULL))
.WillOnce(Return(-1));
EXPECT_CALL(host_, SetError(DEMUXER_ERROR_COULD_NOT_OPEN));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- demuxer_->Initialize(data_source_.get(), callback_.NewCallback());
+ demuxer_->Initialize(data_source_.get(), NewExpectedCallback());
message_loop_.RunAllPending();
}
@@ -205,10 +196,8 @@ TEST_F(FFmpegDemuxerTest, Initialize_ParseFails) {
.WillOnce(Return(AVERROR_IO));
EXPECT_CALL(*MockFFmpeg::get(), AVCloseInputFile(&format_context_));
EXPECT_CALL(host_, SetError(DEMUXER_ERROR_COULD_NOT_PARSE));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- demuxer_->Initialize(data_source_.get(), callback_.NewCallback());
+ demuxer_->Initialize(data_source_.get(), NewExpectedCallback());
message_loop_.RunAllPending();
}
@@ -219,11 +208,9 @@ TEST_F(FFmpegDemuxerTest, Initialize_NoStreams) {
InitializeDemuxerMocks();
}
EXPECT_CALL(host_, SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
format_context_.nb_streams = 0;
- demuxer_->Initialize(data_source_.get(), callback_.NewCallback());
+ demuxer_->Initialize(data_source_.get(), NewExpectedCallback());
message_loop_.RunAllPending();
}
@@ -234,12 +221,10 @@ TEST_F(FFmpegDemuxerTest, Initialize_DataStreamOnly) {
InitializeDemuxerMocks();
}
EXPECT_CALL(host_, SetError(DEMUXER_ERROR_NO_SUPPORTED_STREAMS));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
EXPECT_EQ(format_context_.streams[0], &streams_[AV_STREAM_DATA]);
format_context_.nb_streams = 1;
- demuxer_->Initialize(data_source_.get(), callback_.NewCallback());
+ demuxer_->Initialize(data_source_.get(), NewExpectedCallback());
message_loop_.RunAllPending();
}
@@ -447,9 +432,7 @@ TEST_F(FFmpegDemuxerTest, Seek) {
.WillOnce(Return(0));
// ...then our callback will be executed...
- StrictMock<MockFilterCallback> seek_callback;
- EXPECT_CALL(seek_callback, OnFilterCallback());
- EXPECT_CALL(seek_callback, OnCallbackDestroyed());
+ FilterCallback* seek_callback = NewExpectedCallback();
EXPECT_CALL(*MockFFmpeg::get(), CheckPoint(2));
// ...followed by two audio packet reads we'll trigger...
@@ -492,7 +475,7 @@ TEST_F(FFmpegDemuxerTest, Seek) {
// Issue a simple forward seek, which should discard queued packets.
demuxer_->Seek(base::TimeDelta::FromMicroseconds(kExpectedTimestamp),
- seek_callback.NewCallback());
+ seek_callback);
message_loop_.RunAllPending();
MockFFmpeg::get()->CheckPoint(2);
@@ -578,9 +561,7 @@ TEST_F(FFmpegDemuxerTest, Stop) {
ASSERT_TRUE(audio);
// Stop the demuxer.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- demuxer_->Stop(callback_.NewCallback());
+ demuxer_->Stop(NewExpectedCallback());
// Expect all calls in sequence.
InSequence s;
@@ -705,9 +686,7 @@ TEST_F(FFmpegDemuxerTest, ProtocolRead) {
// This read complete signal is generated when demuxer is stopped.
EXPECT_CALL(*demuxer, SignalReadCompleted(DataSource::kReadError));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- demuxer->Stop(callback_.NewCallback());
+ demuxer->Stop(NewExpectedCallback());
message_loop_.RunAllPending();
}
diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc
index 779a48f..3db54c0 100644
--- a/media/filters/ffmpeg_video_decoder_unittest.cc
+++ b/media/filters/ffmpeg_video_decoder_unittest.cc
@@ -1,14 +1,14 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <deque>
-#include "base/callback.h"
#include "base/singleton.h"
#include "base/string_util.h"
#include "media/base/data_buffer.h"
#include "media/base/filters.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_ffmpeg.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
@@ -160,16 +160,13 @@ class FFmpegVideoDecoderTest : public testing::Test {
}
virtual ~FFmpegVideoDecoderTest() {
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
// The presence of an event handler means we need to uninitialize.
if (engine_->event_handler_) {
EXPECT_CALL(*engine_, Uninitialize())
.WillOnce(EngineUninitialize(engine_));
}
- decoder_->Stop(callback_.NewCallback());
+ decoder_->Stop(NewExpectedCallback());
// Finish up any remaining tasks.
message_loop_.RunAllPending();
@@ -189,10 +186,7 @@ class FFmpegVideoDecoderTest : public testing::Test {
EXPECT_CALL(*engine_, Initialize(_, _, _, _))
.WillOnce(EngineInitialize(engine_, true));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
- decoder_->Initialize(demuxer_, callback_.NewCallback());
+ decoder_->Initialize(demuxer_, NewExpectedCallback());
message_loop_.RunAllPending();
}
// Fixture members.
@@ -203,7 +197,6 @@ class FFmpegVideoDecoderTest : public testing::Test {
scoped_refptr<DataBuffer> buffer_;
scoped_refptr<DataBuffer> end_of_stream_buffer_;
StrictMock<MockFilterHost> host_;
- StrictMock<MockFilterCallback> callback_;
MessageLoop message_loop_;
// FFmpeg fixtures.
@@ -235,10 +228,8 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_QueryInterfaceFails) {
EXPECT_CALL(*demuxer_, QueryInterface(AVStreamProvider::interface_id()))
.WillOnce(ReturnNull());
EXPECT_CALL(host_, SetError(PIPELINE_ERROR_DECODE));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- decoder_->Initialize(demuxer_, callback_.NewCallback());
+ decoder_->Initialize(demuxer_, NewExpectedCallback());
message_loop_.RunAllPending();
}
@@ -255,10 +246,7 @@ TEST_F(FFmpegVideoDecoderTest, Initialize_EngineFails) {
EXPECT_CALL(host_, SetError(PIPELINE_ERROR_DECODE));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
- decoder_->Initialize(demuxer_, callback_.NewCallback());
+ decoder_->Initialize(demuxer_, NewExpectedCallback());
message_loop_.RunAllPending();
}
@@ -494,19 +482,12 @@ TEST_F(FFmpegVideoDecoderTest, DoSeek) {
// Expect a flush.
EXPECT_CALL(*engine_, Flush())
.WillOnce(EngineFlush(engine_));
- StrictMock<MockFilterCallback> flush_done_cb;
- EXPECT_CALL(flush_done_cb, OnFilterCallback());
- EXPECT_CALL(flush_done_cb, OnCallbackDestroyed());
- decoder_->Flush(flush_done_cb.NewCallback());
+ decoder_->Flush(NewExpectedCallback());
// Expect Seek and verify the results.
EXPECT_CALL(*engine_, Seek())
.WillOnce(EngineSeek(engine_));
- StrictMock<MockFilterCallback> seek_done_cb;
- EXPECT_CALL(seek_done_cb, OnFilterCallback());
- EXPECT_CALL(seek_done_cb, OnCallbackDestroyed());
- decoder_->Seek(kZero, seek_done_cb.NewCallback());
-
+ decoder_->Seek(kZero, NewExpectedCallback());
EXPECT_TRUE(decoder_->pts_heap_.IsEmpty());
EXPECT_EQ(FFmpegVideoDecoder::kNormal, decoder_->state_);
diff --git a/media/filters/file_data_source_unittest.cc b/media/filters/file_data_source_unittest.cc
index b606feb..8e867be 100644
--- a/media/filters/file_data_source_unittest.cc
+++ b/media/filters/file_data_source_unittest.cc
@@ -1,14 +1,14 @@
-// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <string>
#include "base/base_paths.h"
-#include "base/callback.h"
#include "base/file_path.h"
#include "base/path_service.h"
#include "base/utf_string_conversions.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
#include "media/filters/file_data_source.h"
@@ -20,8 +20,7 @@ namespace {
class ReadCallbackHandler {
public:
- ReadCallbackHandler() {
- }
+ ReadCallbackHandler() {}
MOCK_METHOD1(ReadCallback, void(size_t size));
@@ -56,19 +55,14 @@ std::string TestFileURL() {
// Test that FileDataSource call the appropriate methods on its filter host.
TEST(FileDataSourceTest, OpenFile) {
StrictMock<MockFilterHost> host;
- StrictMock<MockFilterCallback> callback;
EXPECT_CALL(host, SetTotalBytes(10));
EXPECT_CALL(host, SetBufferedBytes(10));
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
scoped_refptr<FileDataSource> filter(new FileDataSource());
filter->set_host(&host);
- filter->Initialize(TestFileURL(), callback.NewCallback());
+ filter->Initialize(TestFileURL(), NewExpectedCallback());
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
- filter->Stop(callback.NewCallback());
+ filter->Stop(NewExpectedCallback());
}
// Use the mock filter host to directly call the Read and GetPosition methods.
@@ -78,11 +72,10 @@ TEST(FileDataSourceTest, ReadData) {
// Create our mock filter host and initialize the data source.
NiceMock<MockFilterHost> host;
- NiceMock<MockFilterCallback> callback;
scoped_refptr<FileDataSource> filter(new FileDataSource());
filter->set_host(&host);
- filter->Initialize(TestFileURL(), callback.NewCallback());
+ filter->Initialize(TestFileURL(), NewExpectedCallback());
EXPECT_TRUE(filter->GetSize(&size));
EXPECT_EQ(10, size);
@@ -104,24 +97,17 @@ TEST(FileDataSourceTest, ReadData) {
NewCallback(&handler, &ReadCallbackHandler::ReadCallback));
EXPECT_EQ('5', ten_bytes[0]);
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
- filter->Stop(callback.NewCallback());
+ filter->Stop(NewExpectedCallback());
}
// Test that FileDataSource does nothing on Seek().
TEST(FileDataSourceTest, Seek) {
- StrictMock<MockFilterCallback> callback;
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
const base::TimeDelta kZero;
scoped_refptr<FileDataSource> filter(new FileDataSource());
- filter->Seek(kZero, callback.NewCallback());
+ filter->Seek(kZero, NewExpectedCallback());
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
- filter->Stop(callback.NewCallback());
+ filter->Stop(NewExpectedCallback());
}
} // namespace media
diff --git a/media/filters/video_renderer_base_unittest.cc b/media/filters/video_renderer_base_unittest.cc
index ba7280ad..fae500e 100644
--- a/media/filters/video_renderer_base_unittest.cc
+++ b/media/filters/video_renderer_base_unittest.cc
@@ -1,12 +1,12 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/callback.h"
#include "base/stl_util-inl.h"
#include "media/base/callback.h"
#include "media/base/data_buffer.h"
#include "media/base/limits.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
#include "media/base/video_frame.h"
@@ -77,9 +77,7 @@ class VideoRendererBaseTest : public ::testing::Test {
.WillOnce(DoAll(OnStop(), Return()))
.RetiresOnSaturation();
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- renderer_->Stop(callback_.NewCallback());
+ renderer_->Stop(NewExpectedCallback());
}
protected:
@@ -90,7 +88,6 @@ class VideoRendererBaseTest : public ::testing::Test {
scoped_refptr<MockVideoRendererBase> renderer_;
scoped_refptr<MockVideoDecoder> decoder_;
StrictMock<MockFilterHost> host_;
- StrictMock<MockFilterCallback> callback_;
MediaFormat decoder_media_format_;
// Receives all the buffers that renderer had provided to |decoder_|.
@@ -120,12 +117,8 @@ TEST_F(VideoRendererBaseTest, Initialize_BadMediaFormat) {
// We expect to receive an error.
EXPECT_CALL(host_, SetError(PIPELINE_ERROR_INITIALIZATION_FAILED));
- // We expect our callback to be executed.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
// Initialize, we expect to have no reads.
- renderer_->Initialize(bad_decoder, callback_.NewCallback());
+ renderer_->Initialize(bad_decoder, NewExpectedCallback());
EXPECT_EQ(0u, read_queue_.size());
}
@@ -143,12 +136,8 @@ TEST_F(VideoRendererBaseTest, Initialize_Failed) {
// We expect to receive an error.
EXPECT_CALL(host_, SetError(PIPELINE_ERROR_INITIALIZATION_FAILED));
- // We expect our callback to be executed.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
// Initialize, we expect to have no reads.
- renderer_->Initialize(decoder_, callback_.NewCallback());
+ renderer_->Initialize(decoder_, NewExpectedCallback());
EXPECT_EQ(0u, read_queue_.size());
}
@@ -173,12 +162,8 @@ TEST_F(VideoRendererBaseTest, Initialize_Successful) {
EXPECT_CALL(*renderer_, OnInitialize(_))
.WillOnce(Return(true));
- // After finishing initialization, we expect our callback to be executed.
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
-
// Initialize, we shouldn't have any reads.
- renderer_->Initialize(decoder_, callback_.NewCallback());
+ renderer_->Initialize(decoder_, NewExpectedCallback());
EXPECT_EQ(0u, read_queue_.size());
// Verify the following expectations haven't run until we complete the reads.
@@ -187,12 +172,8 @@ TEST_F(VideoRendererBaseTest, Initialize_Successful) {
// We'll expect to get notified once due preroll completing.
EXPECT_CALL(*renderer_, OnFrameAvailable());
- MockFilterCallback seek_callback;
- EXPECT_CALL(seek_callback, OnFilterCallback());
- EXPECT_CALL(seek_callback, OnCallbackDestroyed());
-
// Now seek to trigger prerolling.
- renderer_->Seek(base::TimeDelta(), seek_callback.NewCallback());
+ renderer_->Seek(base::TimeDelta(), NewExpectedCallback());
// Verify our seek callback hasn't been executed yet.
renderer_->CheckPoint(0);
@@ -207,24 +188,13 @@ TEST_F(VideoRendererBaseTest, Initialize_Successful) {
decoder_->VideoFrameReady(frame);
}
- MockFilterCallback play_callback;
- EXPECT_CALL(play_callback, OnFilterCallback());
- EXPECT_CALL(play_callback, OnCallbackDestroyed());
-
- renderer_->Play(play_callback.NewCallback());
-
- StrictMock<MockFilterCallback> pause_callback;
- EXPECT_CALL(pause_callback, OnFilterCallback());
- EXPECT_CALL(pause_callback, OnCallbackDestroyed());
- renderer_->Pause(pause_callback.NewCallback());
+ renderer_->Play(NewExpectedCallback());
+ renderer_->Pause(NewExpectedCallback());
EXPECT_CALL(*decoder_, ProvidesBuffer())
.WillRepeatedly(Return(true));
- StrictMock<MockFilterCallback> flush_callback;
- EXPECT_CALL(flush_callback, OnFilterCallback());
- EXPECT_CALL(flush_callback, OnCallbackDestroyed());
- renderer_->Flush(flush_callback.NewCallback());
+ renderer_->Flush(NewExpectedCallback());
}
} // namespace media
diff --git a/media/media.gyp b/media/media.gyp
index dba8ad7..259a7a1 100644
--- a/media/media.gyp
+++ b/media/media.gyp
@@ -337,6 +337,8 @@
'sources': [
'audio/test_audio_input_controller_factory.cc',
'audio/test_audio_input_controller_factory.h',
+ 'base/mock_callback.cc',
+ 'base/mock_callback.h',
'base/mock_filter_host.cc',
'base/mock_filter_host.h',
'base/mock_filters.cc',
diff --git a/webkit/glue/media/buffered_data_source_unittest.cc b/webkit/glue/media/buffered_data_source_unittest.cc
index dcb11ec..df79485 100644
--- a/webkit/glue/media/buffered_data_source_unittest.cc
+++ b/webkit/glue/media/buffered_data_source_unittest.cc
@@ -1,10 +1,11 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include <algorithm>
#include "base/test/test_timeouts.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
#include "net/base/net_errors.h"
@@ -167,7 +168,6 @@ class BufferedDataSourceTest : public testing::Test {
ON_CALL(*loader_, Read(_, _, _ , _))
.WillByDefault(DeleteArg<3>());
- StrictMock<media::MockFilterCallback> callback;
ON_CALL(*loader_, instance_size())
.WillByDefault(Return(instance_size));
ON_CALL(*loader_, partial_response())
@@ -188,18 +188,13 @@ class BufferedDataSourceTest : public testing::Test {
} else {
EXPECT_CALL(host_, SetStreaming(true));
}
-
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
} else {
EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK));
EXPECT_CALL(*loader_, Stop());
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
}
// Actual initialization of the data source.
- data_source_->Initialize(url, callback.NewCallback());
+ data_source_->Initialize(url, media::NewExpectedCallback());
message_loop_->RunAllPending();
if (initialized_ok) {
@@ -220,10 +215,7 @@ class BufferedDataSourceTest : public testing::Test {
EXPECT_CALL(*loader_, Stop());
}
- StrictMock<media::MockFilterCallback> callback;
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
- data_source_->Stop(callback.NewCallback());
+ data_source_->Stop(media::NewExpectedCallback());
message_loop_->RunAllPending();
}
diff --git a/webkit/glue/media/simple_data_source_unittest.cc b/webkit/glue/media/simple_data_source_unittest.cc
index 55dc913..82acaad 100644
--- a/webkit/glue/media/simple_data_source_unittest.cc
+++ b/webkit/glue/media/simple_data_source_unittest.cc
@@ -1,9 +1,9 @@
-// Copyright (c) 2010 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "base/callback.h"
#include "media/base/filters.h"
+#include "media/base/mock_callback.h"
#include "media/base/mock_filter_host.h"
#include "media/base/mock_filters.h"
#include "net/base/net_errors.h"
@@ -59,7 +59,8 @@ class SimpleDataSourceTest : public testing::Test {
ignore_result(frame_.release());
}
- void InitializeDataSource(const char* url) {
+ void InitializeDataSource(const char* url,
+ media::MockCallback* callback) {
gurl_ = GURL(url);
frame_.reset(new NiceMock<MockWebFrame>());
@@ -72,9 +73,7 @@ class SimpleDataSourceTest : public testing::Test {
data_source_->set_host(&host_);
data_source_->SetURLLoaderForTest(url_loader_);
- InSequence s;
-
- data_source_->Initialize(url, callback_.NewCallback());
+ data_source_->Initialize(url, callback);
MessageLoop::current()->RunAllPending();
}
@@ -96,8 +95,6 @@ class SimpleDataSourceTest : public testing::Test {
InSequence s;
EXPECT_CALL(host_, SetTotalBytes(kDataSize));
EXPECT_CALL(host_, SetBufferedBytes(kDataSize));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
data_source_->didFinishLoading(NULL, 0);
@@ -108,8 +105,6 @@ class SimpleDataSourceTest : public testing::Test {
void RequestFailed() {
InSequence s;
EXPECT_CALL(host_, SetError(media::PIPELINE_ERROR_NETWORK));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
WebURLError error;
error.reason = net::ERR_FAILED;
@@ -120,11 +115,7 @@ class SimpleDataSourceTest : public testing::Test {
}
void DestroyDataSource() {
- StrictMock<media::MockFilterCallback> callback;
- EXPECT_CALL(callback, OnFilterCallback());
- EXPECT_CALL(callback, OnCallbackDestroyed());
-
- data_source_->Stop(callback.NewCallback());
+ data_source_->Stop(media::NewExpectedCallback());
MessageLoop::current()->RunAllPending();
data_source_ = NULL;
@@ -150,7 +141,6 @@ class SimpleDataSourceTest : public testing::Test {
NiceMock<MockWebURLLoader>* url_loader_;
scoped_refptr<SimpleDataSource> data_source_;
StrictMock<media::MockFilterHost> host_;
- StrictMock<media::MockFilterCallback> callback_;
scoped_ptr<NiceMock<MockWebFrame> > frame_;
char data_[kDataSize];
@@ -159,19 +149,19 @@ class SimpleDataSourceTest : public testing::Test {
};
TEST_F(SimpleDataSourceTest, InitializeHTTP) {
- InitializeDataSource(kHttpUrl);
+ InitializeDataSource(kHttpUrl, media::NewExpectedCallback());
RequestSucceeded(false);
DestroyDataSource();
}
TEST_F(SimpleDataSourceTest, InitializeHTTPS) {
- InitializeDataSource(kHttpsUrl);
+ InitializeDataSource(kHttpsUrl, media::NewExpectedCallback());
RequestSucceeded(false);
DestroyDataSource();
}
TEST_F(SimpleDataSourceTest, InitializeFile) {
- InitializeDataSource(kFileUrl);
+ InitializeDataSource(kFileUrl, media::NewExpectedCallback());
RequestSucceeded(true);
DestroyDataSource();
}
@@ -191,31 +181,34 @@ TEST_F(SimpleDataSourceTest, InitializeData) {
EXPECT_CALL(host_, SetLoaded(true));
EXPECT_CALL(host_, SetTotalBytes(sizeof(kDataUrlDecoded)));
EXPECT_CALL(host_, SetBufferedBytes(sizeof(kDataUrlDecoded)));
- EXPECT_CALL(callback_, OnFilterCallback());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
- data_source_->Initialize(kDataUrl, callback_.NewCallback());
+ data_source_->Initialize(kDataUrl, media::NewExpectedCallback());
MessageLoop::current()->RunAllPending();
DestroyDataSource();
}
TEST_F(SimpleDataSourceTest, RequestFailed) {
- InitializeDataSource(kHttpUrl);
+ InitializeDataSource(kHttpUrl, media::NewExpectedCallback());
RequestFailed();
DestroyDataSource();
}
TEST_F(SimpleDataSourceTest, StopWhenDownloading) {
- InitializeDataSource(kHttpUrl);
+ // The callback should be deleted, but not executed.
+ // TODO(scherkus): should this really be the behaviour? Seems strange...
+ StrictMock<media::MockCallback>* callback =
+ new StrictMock<media::MockCallback>();
+ EXPECT_CALL(*callback, Destructor());
+
+ InitializeDataSource(kHttpUrl, callback);
EXPECT_CALL(*url_loader_, cancel());
- EXPECT_CALL(callback_, OnCallbackDestroyed());
DestroyDataSource();
}
TEST_F(SimpleDataSourceTest, AsyncRead) {
- InitializeDataSource(kFileUrl);
+ InitializeDataSource(kFileUrl, media::NewExpectedCallback());
RequestSucceeded(true);
AsyncRead();
DestroyDataSource();