summaryrefslogtreecommitdiffstats
path: root/media
diff options
context:
space:
mode:
authorscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 00:16:06 +0000
committerscherkus@chromium.org <scherkus@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-09 00:16:06 +0000
commitd3ae70d1a35c3112bb4809396a536da8135a32df (patch)
tree2e032c1c58f31187063b177c2d75f98ee4a84ad2 /media
parent83548cfb4900fa35d3f34a88340f10d2bcce74fc (diff)
downloadchromium_src-d3ae70d1a35c3112bb4809396a536da8135a32df.zip
chromium_src-d3ae70d1a35c3112bb4809396a536da8135a32df.tar.gz
chromium_src-d3ae70d1a35c3112bb4809396a536da8135a32df.tar.bz2
Added new gmock-based MockFilterHost and deprecated the old one.
Updated FileDataSource tests to use the new MockFilterHost as a proof of concept, also because my pipeline refactoring completely broke the test. BUG=16008 TEST=FileDataSourceTest.* should pass Review URL: http://codereview.chromium.org/149350 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20219 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media')
-rw-r--r--media/base/mock_filter_host.h37
-rw-r--r--media/filters/ffmpeg_demuxer_unittest.cc5
-rw-r--r--media/filters/ffmpeg_video_decoder_unittest.cc6
-rw-r--r--media/filters/file_data_source.h14
-rw-r--r--media/filters/file_data_source_unittest.cc69
5 files changed, 66 insertions, 65 deletions
diff --git a/media/base/mock_filter_host.h b/media/base/mock_filter_host.h
index d6fde0b..3cc5860 100644
--- a/media/base/mock_filter_host.h
+++ b/media/base/mock_filter_host.h
@@ -1,11 +1,13 @@
// Copyright (c) 2009 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.
-
-// The corresponding FilterHost implementation for MockPipeline. Maintains a
-// reference to the parent MockPipeline and a reference to the Filter its
-// hosting. Common usage is to check if the hosted filter has initialized by
-// calling IsInitialized().
+//
+// A FilterHost implementation based on gmock. Combined with setting a message
+// loop on a filter, permits single-threaded testing of filters without
+// requiring a pipeline.
+//
+// TODO(scherkus): Remove old_mocks::MockFilterHost as soon as other tests have
+// transitioned over to the new gmock-based MockFilterHost.
#ifndef MEDIA_BASE_MOCK_FILTER_HOST_H_
#define MEDIA_BASE_MOCK_FILTER_HOST_H_
@@ -19,10 +21,33 @@
#include "media/base/filters.h"
#include "media/base/media_format.h"
#include "media/base/mock_pipeline.h"
+#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
+class MockFilterHost : public FilterHost {
+ public:
+ MockFilterHost() {}
+
+ // FilterHost implementation.
+ MOCK_METHOD0(InitializationComplete, void());
+ MOCK_METHOD1(Error, void(PipelineError error));
+ MOCK_CONST_METHOD0(GetTime, base::TimeDelta());
+ MOCK_METHOD1(SetTime, void(base::TimeDelta time));
+ MOCK_METHOD1(SetDuration, void(base::TimeDelta duration));
+ MOCK_METHOD1(SetBufferedTime, void(base::TimeDelta buffered_time));
+ MOCK_METHOD1(SetTotalBytes, void(int64 total_bytes));
+ MOCK_METHOD1(SetBufferedBytes, void(int64 buffered_bytes));
+ MOCK_METHOD2(SetVideoSize, void(size_t width, size_t height));
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockFilterHost);
+};
+
+namespace old_mocks {
+
+// This version is deprecated.
template <class Filter>
class MockFilterHost : public FilterHost {
public:
@@ -121,6 +146,8 @@ class MockFilterHost : public FilterHost {
DISALLOW_COPY_AND_ASSIGN(MockFilterHost);
};
+} // namespace old_mocks
+
} // namespace media
#endif // MEDIA_BASE_MOCK_FILTER_HOST_H_
diff --git a/media/filters/ffmpeg_demuxer_unittest.cc b/media/filters/ffmpeg_demuxer_unittest.cc
index 96e1d85..606b6b4 100644
--- a/media/filters/ffmpeg_demuxer_unittest.cc
+++ b/media/filters/ffmpeg_demuxer_unittest.cc
@@ -71,7 +71,8 @@ class FFmpegDemuxerTest : public testing::Test {
// Prepare a filter host and data source for the demuxer.
pipeline_.reset(new MockPipeline());
- filter_host_.reset(new MockFilterHost<Demuxer>(pipeline_.get(), demuxer_));
+ filter_host_.reset(new old_mocks::MockFilterHost<Demuxer>(pipeline_.get(),
+ demuxer_));
data_source_ = new StrictMock<MockDataSource>();
// Initialize FFmpeg fixtures.
@@ -148,7 +149,7 @@ class FFmpegDemuxerTest : public testing::Test {
scoped_refptr<FilterFactory> factory_;
scoped_refptr<FFmpegDemuxer> demuxer_;
scoped_ptr<MockPipeline> pipeline_;
- scoped_ptr<MockFilterHost<Demuxer> > filter_host_;
+ scoped_ptr<old_mocks::MockFilterHost<Demuxer> > filter_host_;
scoped_refptr<StrictMock<MockDataSource> > data_source_;
MessageLoop message_loop_;
diff --git a/media/filters/ffmpeg_video_decoder_unittest.cc b/media/filters/ffmpeg_video_decoder_unittest.cc
index 1c2b39a..8e82ebc 100644
--- a/media/filters/ffmpeg_video_decoder_unittest.cc
+++ b/media/filters/ffmpeg_video_decoder_unittest.cc
@@ -85,8 +85,8 @@ class FFmpegVideoDecoderTest : public testing::Test {
// Prepare a filter host, pipeline and demuxer for the video decoder.
pipeline_.reset(new MockPipeline());
- filter_host_.reset(new MockFilterHost<VideoDecoder>(pipeline_.get(),
- decoder_));
+ filter_host_.reset(
+ new old_mocks::MockFilterHost<VideoDecoder>(pipeline_.get(), decoder_));
demuxer_ = new MockFFmpegDemuxerStream();
// Initialize FFmpeg fixtures.
@@ -121,7 +121,7 @@ class FFmpegVideoDecoderTest : public testing::Test {
scoped_refptr<FilterFactory> factory_;
scoped_refptr<FFmpegVideoDecoder> decoder_;
scoped_ptr<MockPipeline> pipeline_;
- scoped_ptr<MockFilterHost<VideoDecoder> > filter_host_;
+ scoped_ptr<old_mocks::MockFilterHost<VideoDecoder> > filter_host_;
scoped_refptr<MockFFmpegDemuxerStream> demuxer_;
scoped_refptr<DataBuffer> buffer_;
scoped_refptr<DataBuffer> end_of_stream_buffer_;
diff --git a/media/filters/file_data_source.h b/media/filters/file_data_source.h
index e93c662..e58e4aa 100644
--- a/media/filters/file_data_source.h
+++ b/media/filters/file_data_source.h
@@ -9,14 +9,12 @@
#include "base/lock.h"
#include "media/base/filters.h"
+#include "testing/gtest/include/gtest/gtest_prod.h"
namespace media {
// Basic data source that treats the URL as a file path, and uses the file
// system to read data for a media pipeline.
-// TODO(ralph): We will add a pure virtual interface so that the chrome
-// media player delegate can give us the file handle, bytes downloaded so far,
-// and file size.
class FileDataSource : public DataSource {
public:
// Public method to get a filter factory for the FileDataSource.
@@ -37,11 +35,17 @@ class FileDataSource : public DataSource {
virtual bool IsSeekable();
private:
+ // Only allow factories and tests to create this object.
+ //
+ // TODO(scherkus): I'm getting tired of these factories getting in the way
+ // of my tests!!!
+ FRIEND_TEST(FileDataSourceTest, OpenFile);
+ FRIEND_TEST(FileDataSourceTest, ReadData);
friend class FilterFactoryImpl0<FileDataSource>;
FileDataSource();
virtual ~FileDataSource();
- // File handle. Null if not initialized or an error occurs.
+ // File handle. NULL if not initialized or an error occurs.
FILE* file_;
// Size of the file in bytes.
@@ -53,7 +57,7 @@ class FileDataSource : public DataSource {
// Critical section that protects all of the DataSource methods to prevent
// a Stop from happening while in the middle of a file I/O operation.
// TODO(ralphl): Ideally this would use asynchronous I/O or we will know
- // that we will block for a short period of time in reads. Othewise, we can
+ // that we will block for a short period of time in reads. Otherwise, we can
// hang the pipeline Stop.
Lock lock_;
diff --git a/media/filters/file_data_source_unittest.cc b/media/filters/file_data_source_unittest.cc
index 8ef1b4b..5b9157a 100644
--- a/media/filters/file_data_source_unittest.cc
+++ b/media/filters/file_data_source_unittest.cc
@@ -6,34 +6,14 @@
#include "base/base_paths.h"
#include "base/file_path.h"
-#include "base/file_util.h"
#include "base/string_util.h"
-#include "base/task.h"
-#include "base/waitable_event.h"
-#include "media/base/buffers.h"
-#include "media/base/pipeline_impl.h"
-#include "media/base/media_format.h"
-#include "media/base/filters.h"
-#include "media/base/factory.h"
-#include "media/base/filter_host.h"
#include "media/base/mock_filter_host.h"
-#include "media/base/mock_pipeline.h"
#include "media/filters/file_data_source.h"
-#include "media/base/mock_media_filters.h"
-#include "testing/gtest/include/gtest/gtest.h"
-using media::FileDataSource;
-using media::FilterFactory;
-using media::FilterFactoryCollection;
-using media::MediaFormat;
-using media::MockFilterHost;
-using media::MockPipeline;
-using media::PipelineImpl;
-using media::old_mocks::InitializationHelper;
-using media::old_mocks::MockFilterConfig;
-using media::old_mocks::MockFilterFactory;
+using ::testing::NiceMock;
+using ::testing::StrictMock;
-namespace {
+namespace media {
// Returns a path to the test file which contains the string "0123456789"
// without the quotes or any trailing space or null termination. The file lives
@@ -55,42 +35,29 @@ std::string TestFileURL() {
#endif
}
-} // namespace
-
-// Use the "real" pipeline to open the file.
+// Test that FileDataSource call the appropriate methods on its filter host.
TEST(FileDataSourceTest, OpenFile) {
- PipelineImpl pipeline;
- MockFilterConfig config;
- config.has_video = false;
- scoped_refptr<FilterFactoryCollection> c = new FilterFactoryCollection();
- c->AddFactory(FileDataSource::CreateFactory());
- c->AddFactory(new MockFilterFactory(&config));
- InitializationHelper h;
- h.Start(&pipeline, c, TestFileURL());
- EXPECT_EQ(pipeline.GetTotalBytes(), 10);
- EXPECT_EQ(pipeline.GetBufferedBytes(), 10);
- pipeline.Stop();
+ StrictMock<MockFilterHost> host;
+ EXPECT_CALL(host, SetTotalBytes(10));
+ EXPECT_CALL(host, SetBufferedBytes(10));
+ EXPECT_CALL(host, InitializationComplete());
+
+ scoped_refptr<FileDataSource> filter = new FileDataSource();
+ filter->SetFilterHost(&host);
+ EXPECT_TRUE(filter->Initialize(TestFileURL()));
}
// Use the mock filter host to directly call the Read and GetPosition methods.
TEST(FileDataSourceTest, ReadData) {
- MediaFormat url_format;
int64 position;
int64 size;
uint8 ten_bytes[10];
- std::string url = TestFileURL();
- url_format.SetAsString(MediaFormat::kMimeType, media::mime_type::kURL);
- url_format.SetAsString(MediaFormat::kURL, url);
- // Create our data source.
- scoped_refptr<FilterFactory> factory = FileDataSource::CreateFactory();
- FileDataSource* filter = factory->Create<FileDataSource>(url_format);
- EXPECT_TRUE(filter);
-
- // Create our mock pipeline and filter host and initialize the data source.
- MockPipeline pipeline;
- MockFilterHost<FileDataSource> mock_host(&pipeline, filter);
- EXPECT_TRUE(filter->Initialize(url));
+ // Create our mock filter host and initialize the data source.
+ NiceMock<MockFilterHost> host;
+ scoped_refptr<FileDataSource> filter = new FileDataSource();
+ filter->SetFilterHost(&host);
+ EXPECT_TRUE(filter->Initialize(TestFileURL()));
EXPECT_TRUE(filter->GetSize(&size));
EXPECT_EQ(10, size);
@@ -112,3 +79,5 @@ TEST(FileDataSourceTest, ReadData) {
EXPECT_TRUE(filter->GetPosition(&position));
EXPECT_EQ(10, position);
}
+
+} // namespace media