Chromium Code Reviews| Index: media/filters/pipeline_integration_test.cc |
| diff --git a/media/filters/pipeline_integration_test.cc b/media/filters/pipeline_integration_test.cc |
| index beb9bd063de134a767fa461fb1fdad82f3488402..f4cd1426a9669b1d090fa0e1e04f54b7780d33f4 100644 |
| --- a/media/filters/pipeline_integration_test.cc |
| +++ b/media/filters/pipeline_integration_test.cc |
| @@ -12,6 +12,7 @@ |
| #include "media/base/cdm_callback_promise.h" |
| #include "media/base/cdm_context.h" |
| #include "media/base/decoder_buffer.h" |
| +#include "media/base/media.h" |
| #include "media/base/media_keys.h" |
| #include "media/base/media_switches.h" |
| #include "media/base/test_data_util.h" |
| @@ -21,6 +22,13 @@ |
| #include "media/filters/renderer_impl.h" |
| #include "testing/gmock/include/gmock/gmock.h" |
| +#if defined(MOJO_RENDERER) |
| +#include "media/mojo/services/mojo_renderer_impl.h" |
| +#include "mojo/public/cpp/application/application_impl.h" |
| +#include "mojo/public/cpp/application/application_test_base.h" |
| +#include "mojo/public/cpp/application/connect.h" |
| +#endif |
| + |
| using testing::_; |
| using testing::AnyNumber; |
| using testing::AtLeast; |
| @@ -557,9 +565,62 @@ class MockMediaSource { |
| base::TimeDelta last_timestamp_offset_; |
| }; |
| -class PipelineIntegrationTest |
| - : public testing::Test, |
| - public PipelineIntegrationTestBase { |
| +#if defined(MOJO_RENDERER) |
| +class PipelineIntegrationTestHost : public mojo::test::ApplicationTestBase, |
| + public PipelineIntegrationTestBase { |
| + public: |
| + virtual ~PipelineIntegrationTestHost() { |
| + // MessageLoop is already dead here... so we can't Stop() the pipeline here. |
| + CHECK(!pipeline_->IsRunning()); |
| + }; |
| + |
| + virtual void SetUp() override { |
| + ApplicationTestBase::SetUp(); |
| + |
| + // TODO(dalecurtis): For some reason this isn't done... |
| + if (!CommandLine::InitializedForCurrentProcess()) { |
| + CommandLine::Init(0, NULL); |
| + media::InitializeMediaLibraryForTesting(); |
| + } |
| + |
| + // Creating the service provider will create a message loop which we need |
| + // to share... |
| + service_provider_ = application_impl() |
| + ->ConnectToApplication("mojo:media") |
| + ->GetServiceProvider(); |
| + |
| + CHECK(base::MessageLoop::current()); |
| + Initialize(base::MessageLoop::current()); |
| + } |
| + |
| + protected: |
| + scoped_ptr<Renderer> CreateRenderer() override { |
| + mojo::MediaRendererPtr mojo_media_renderer; |
| + mojo::ConnectToService(service_provider_, &mojo_media_renderer); |
| + return make_scoped_ptr(new MojoRendererImpl(message_loop_->task_runner(), |
| + mojo_media_renderer.Pass())); |
| + } |
| + |
| + private: |
| + mojo::ServiceProvider* service_provider_; |
| +}; |
| +#else |
| +class PipelineIntegrationTestHost : public testing::Test, |
| + public PipelineIntegrationTestBase { |
| + public: |
| + virtual ~PipelineIntegrationTestHost() { |
| + if (pipeline_->IsRunning()) |
| + Stop(); |
| + }; |
| + |
| + virtual void SetUp() override { Initialize(&test_message_loop_); } |
| + |
| + private: |
| + base::MessageLoop test_message_loop_; |
| +}; |
| +#endif |
|
xhwang
2014/12/15 22:22:39
Neat!
I thought about putting mojo related code
|
| + |
| +class PipelineIntegrationTest : public PipelineIntegrationTestHost { |
| public: |
| void StartPipelineWithMediaSource(MockMediaSource* source) { |
| EXPECT_CALL(*source, InitSegmentReceived()).Times(AtLeast(1)); |
| @@ -583,7 +644,7 @@ class PipelineIntegrationTest |
| base::Unretained(this)), |
| base::Closure(), base::Bind(&PipelineIntegrationTest::OnAddTextTrack, |
| base::Unretained(this))); |
| - message_loop_.Run(); |
| + message_loop_->Run(); |
| EXPECT_EQ(PIPELINE_OK, pipeline_status_); |
| } |
| @@ -628,7 +689,7 @@ class PipelineIntegrationTest |
| base::Bind(&FakeEncryptedMedia::OnEncryptedMediaInitData, |
| base::Unretained(encrypted_media))); |
| - message_loop_.Run(); |
| + message_loop_->Run(); |
| EXPECT_EQ(PIPELINE_OK, pipeline_status_); |
| } |
| @@ -670,6 +731,10 @@ TEST_F(PipelineIntegrationTest, BasicPlayback) { |
| Play(); |
| ASSERT_TRUE(WaitUntilOnEnded()); |
| + |
| + // TODO(dalecurtis): Have to add this to every test since the MessageLoop dies |
| + // before ~PipelineIntegrationTest(Base|Host|Etc). |
| + Stop(); |
| } |
| TEST_F(PipelineIntegrationTest, BasicPlaybackOpusOgg) { |
| @@ -916,7 +981,7 @@ TEST_F(PipelineIntegrationTest, |
| source.EndOfStream(); |
| - message_loop_.Run(); |
| + message_loop_->Run(); |
| EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_); |
| EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |
| @@ -1170,7 +1235,7 @@ TEST_F(PipelineIntegrationTest, |
| source.EndOfStream(); |
| - message_loop_.Run(); |
| + message_loop_->Run(); |
| EXPECT_EQ(PIPELINE_ERROR_DECODE, pipeline_status_); |
| EXPECT_EQ(1u, pipeline_->GetBufferedTimeRanges().size()); |