diff options
Diffstat (limited to 'media/base/pipeline_impl_unittest.cc')
-rw-r--r-- | media/base/pipeline_impl_unittest.cc | 73 |
1 files changed, 61 insertions, 12 deletions
diff --git a/media/base/pipeline_impl_unittest.cc b/media/base/pipeline_impl_unittest.cc index 43a113c..082f926 100644 --- a/media/base/pipeline_impl_unittest.cc +++ b/media/base/pipeline_impl_unittest.cc @@ -5,6 +5,8 @@ #include <string> #include "base/platform_thread.h" +#include "base/time.h" +#include "base/waitable_event.h" #include "media/base/pipeline_impl.h" #include "media/base/media_format.h" #include "media/base/filters.h" @@ -17,19 +19,20 @@ using media::FilterFactoryCollection; using media::FilterHost; using media::MediaFormat; using media::PipelineImpl; -using media::TypeFilterFactory; +using media::FilterFactoryImpl1; class TestDataSource : public media::DataSource { public: - static bool Create(const MediaFormat* media_format, - TestDataSource** filter_out) { - *filter_out = new TestDataSource(); - return true; + static FilterFactory* CreateFactory(bool hang_in_init) { + return new FilterFactoryImpl1<TestDataSource, bool>(hang_in_init); } virtual void Stop() {} // This filter will hang in initialization because it never calls // FilterHost::InitializationComplete virtual bool Initialize(const std::string& uri) { + if (!hang_in_init_) { + host_->InitializationComplete(); + } return true; } virtual const MediaFormat* GetMediaFormat() { @@ -47,14 +50,60 @@ class TestDataSource : public media::DataSource { virtual bool GetSize(int64* size_out) { return 0; } + + protected: + bool hang_in_init_; + friend class media::FilterFactoryImpl1<TestDataSource, bool>; + explicit TestDataSource(bool hang_in_init) : hang_in_init_(hang_in_init) {} + ~TestDataSource() {} + + DISALLOW_COPY_AND_ASSIGN(TestDataSource); +}; + + +class InitWaiter : public base::WaitableEvent { + public: + InitWaiter() + : WaitableEvent(true, false), + callback_success_status_(false) {} + void InitializationComplete(bool success) { + callback_success_status_ = success; + Signal(); + } + bool HasBeenCalled() { return IsSignaled(); } + bool CallbackSuccessStatus() { return callback_success_status_; } + Callback1<bool>::Type* NewInitCallback() { + return NewCallback(this, &InitWaiter::InitializationComplete); + } + void Reset() { + base::WaitableEvent::Reset(); + callback_success_status_ = false; + } + + private: + bool callback_success_status_; + + DISALLOW_COPY_AND_ASSIGN(InitWaiter); }; + TEST(PipelineImplTest, Basic) { - std::string uri("test.mov"); - PipelineImpl pipeline; - scoped_refptr<FilterFactoryCollection> f = new FilterFactoryCollection(); - f->AddFactory(new TypeFilterFactory<TestDataSource>); - pipeline.Start(f, uri, NULL); - PlatformThread::Sleep(10); - pipeline.Stop(); + std::string url("test.mov"); + PipelineImpl p; + InitWaiter w; + p.Start(TestDataSource::CreateFactory(true), url, w.NewInitCallback()); + w.TimedWait(base::TimeDelta::FromSeconds(1)); + EXPECT_FALSE(w.HasBeenCalled()); + EXPECT_FALSE(p.IsInitialized()); + EXPECT_TRUE(media::PIPELINE_OK == p.GetError()); + p.Stop(); + + w.Reset(); + p.Start(TestDataSource::CreateFactory(false), url, w.NewInitCallback()); + w.TimedWait(base::TimeDelta::FromSeconds(1)); + EXPECT_TRUE(w.HasBeenCalled()); + EXPECT_FALSE(w.CallbackSuccessStatus()); + EXPECT_FALSE(p.IsInitialized()); + EXPECT_FALSE(media::PIPELINE_OK == p.GetError()); + p.Stop(); } |