Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/at_exit.h" | |
| 6 #include "base/bind.h" | 5 #include "base/bind.h" |
| 7 #include "base/command_line.h" | |
| 8 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
| 10 #include "media/base/audio_decoder_config.h" | 8 #include "media/base/audio_decoder_config.h" |
| 11 #include "media/base/channel_layout.h" | 9 #include "media/base/channel_layout.h" |
| 12 #include "media/base/demuxer_stream_provider.h" | 10 #include "media/base/demuxer_stream_provider.h" |
| 13 #include "media/base/sample_format.h" | 11 #include "media/base/sample_format.h" |
| 14 #include "media/base/video_decoder_config.h" | 12 #include "media/base/video_decoder_config.h" |
| 15 #include "media/mojo/services/mojo_renderer_impl.h" | 13 #include "media/mojo/services/mojo_renderer_impl.h" |
| 16 #include "mojo/public/c/system/main.h" | |
| 17 #include "mojo/public/cpp/application/application_delegate.h" | 14 #include "mojo/public/cpp/application/application_delegate.h" |
| 18 #include "mojo/public/cpp/application/application_impl.h" | 15 #include "mojo/public/cpp/application/application_impl.h" |
| 19 #include "testing/gtest/include/gtest/gtest.h" | 16 #include "mojo/public/cpp/application/application_test_base.h" |
| 20 | 17 |
| 21 namespace { | 18 namespace { |
| 22 | 19 |
| 23 // This class is here to give the gtest class access to the | 20 // This class is here to give the gtest class access to the |
| 24 // mojo::ApplicationImpl so that the tests can connect to other applications. | 21 // mojo::ApplicationImpl so that the tests can connect to other applications. |
| 25 class MojoRendererTestHelper : public mojo::ApplicationDelegate { | 22 class MojoRendererTestHelper : public mojo::ApplicationDelegate { |
| 26 public: | 23 public: |
| 27 MojoRendererTestHelper() : application_impl_(NULL) {} | 24 MojoRendererTestHelper() : application_impl_(NULL) {} |
| 28 ~MojoRendererTestHelper() override {} | 25 ~MojoRendererTestHelper() override {} |
| 29 | 26 |
| 30 // ApplicationDelegate implementation. | 27 // ApplicationDelegate implementation. |
| 31 void Initialize(mojo::ApplicationImpl* app) override { | 28 void Initialize(mojo::ApplicationImpl* app) override { |
| 32 application_impl_ = app; | 29 application_impl_ = app; |
| 33 } | 30 } |
| 34 | 31 |
| 35 mojo::ApplicationImpl* application_impl() { return application_impl_; } | 32 mojo::ApplicationImpl* application_impl() { return application_impl_; } |
| 36 | 33 |
| 37 private: | 34 private: |
| 38 mojo::ApplicationImpl* application_impl_; | 35 mojo::ApplicationImpl* application_impl_; |
| 39 | 36 |
| 40 DISALLOW_COPY_AND_ASSIGN(MojoRendererTestHelper); | 37 DISALLOW_COPY_AND_ASSIGN(MojoRendererTestHelper); |
| 41 }; | 38 }; |
| 42 | 39 |
| 43 // TODO(tim): Reconcile this with mojo apptest framework when ready. | |
| 44 MojoRendererTestHelper* g_test_delegate = NULL; | |
| 45 | |
| 46 // TODO(tim): Make media::FakeDemuxerStream support audio and use that for the | 40 // TODO(tim): Make media::FakeDemuxerStream support audio and use that for the |
| 47 // DemuxerStream implementation instead. | 41 // DemuxerStream implementation instead. |
| 48 class FakeDemuxerStream : public media::DemuxerStreamProvider, | 42 class FakeDemuxerStream : public media::DemuxerStreamProvider, |
| 49 public media::DemuxerStream { | 43 public media::DemuxerStream { |
| 50 public: | 44 public: |
| 51 FakeDemuxerStream() {} | 45 FakeDemuxerStream() {} |
| 52 ~FakeDemuxerStream() override {} | 46 ~FakeDemuxerStream() override {} |
| 53 | 47 |
| 54 // media::Demuxer implementation. | 48 // media::Demuxer implementation. |
| 55 media::DemuxerStream* GetStream(media::DemuxerStream::Type type) override { | 49 media::DemuxerStream* GetStream(media::DemuxerStream::Type type) override { |
| 56 DCHECK_EQ(media::DemuxerStream::AUDIO, type); | 50 if (type == media::DemuxerStream::AUDIO) |
| 57 return this; | 51 return this; |
| 52 return nullptr; | |
|
DaleCurtis
2014/11/11 23:32:20
No Video? ~_~
xhwang
2014/11/12 00:29:08
Yep.. I felt this code needs some major refactorin
| |
| 58 } | 53 } |
| 59 media::DemuxerStreamProvider::Liveness GetLiveness() const override { | 54 media::DemuxerStreamProvider::Liveness GetLiveness() const override { |
| 60 return media::DemuxerStreamProvider::LIVENESS_UNKNOWN; | 55 return media::DemuxerStreamProvider::LIVENESS_UNKNOWN; |
| 61 } | 56 } |
| 62 | 57 |
| 63 // media::DemuxerStream implementation. | 58 // media::DemuxerStream implementation. |
| 64 void Read(const ReadCB& read_cb) override {} | 59 void Read(const ReadCB& read_cb) override {} |
| 65 | 60 |
| 66 media::AudioDecoderConfig audio_decoder_config() override { | 61 media::AudioDecoderConfig audio_decoder_config() override { |
| 67 media::AudioDecoderConfig config; | 62 media::AudioDecoderConfig config; |
| (...skipping 29 matching lines...) Expand all Loading... | |
| 97 } | 92 } |
| 98 | 93 |
| 99 private: | 94 private: |
| 100 DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStream); | 95 DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStream); |
| 101 }; | 96 }; |
| 102 | 97 |
| 103 } // namespace | 98 } // namespace |
| 104 | 99 |
| 105 namespace media { | 100 namespace media { |
| 106 | 101 |
| 107 class MojoRendererTest : public testing::Test { | 102 class MojoRendererTest : public mojo::test::ApplicationTestBase { |
| 108 public: | 103 public: |
| 109 MojoRendererTest() : service_provider_(NULL) {} | 104 MojoRendererTest() |
| 105 : ApplicationTestBase(mojo::Array<mojo::String>()), | |
| 106 service_provider_(NULL) {} | |
| 107 ~MojoRendererTest() override {} | |
| 108 | |
| 109 // ApplicationTestBase implementation. | |
| 110 mojo::ApplicationDelegate* GetApplicationDelegate() override { | |
| 111 return &mojo_renderer_test_helper_; | |
| 112 } | |
| 110 | 113 |
| 111 void SetUp() override { | 114 void SetUp() override { |
|
DaleCurtis
2014/11/11 23:32:20
It's unusual to have both a SetUp and a constructo
xhwang
2014/11/12 00:29:08
Following this example here:
https://github.com/do
DaleCurtis
2014/11/12 02:27:45
Sometimes you need to vend things that shouldn't b
| |
| 115 ApplicationTestBase::SetUp(); | |
| 112 demuxer_stream_provider_.reset(new FakeDemuxerStream()); | 116 demuxer_stream_provider_.reset(new FakeDemuxerStream()); |
| 113 service_provider_ = | 117 service_provider_ = |
| 114 g_test_delegate->application_impl() | 118 application_impl() |
| 115 ->ConnectToApplication("mojo:media_mojo_renderer_app") | 119 ->ConnectToApplication("mojo:mojo_media_renderer_app") |
| 116 ->GetServiceProvider(); | 120 ->GetServiceProvider(); |
| 117 } | 121 } |
| 118 | 122 |
| 119 mojo::ServiceProvider* service_provider() { return service_provider_; } | 123 mojo::ServiceProvider* service_provider() { return service_provider_; } |
| 120 DemuxerStreamProvider* stream_provider() { | 124 DemuxerStreamProvider* stream_provider() { |
| 121 return demuxer_stream_provider_.get(); | 125 return demuxer_stream_provider_.get(); |
| 122 } | 126 } |
| 123 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { | 127 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { |
| 124 return base::MessageLoop::current()->task_runner(); | 128 return base::MessageLoop::current()->task_runner(); |
| 125 } | 129 } |
| 126 | 130 |
| 127 private: | 131 private: |
| 132 MojoRendererTestHelper mojo_renderer_test_helper_; | |
| 128 scoped_ptr<DemuxerStreamProvider> demuxer_stream_provider_; | 133 scoped_ptr<DemuxerStreamProvider> demuxer_stream_provider_; |
| 129 mojo::ServiceProvider* service_provider_; | 134 mojo::ServiceProvider* service_provider_; |
| 130 | 135 |
| 131 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest); | 136 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest); |
| 132 }; | 137 }; |
| 133 | 138 |
| 134 void ErrorCallback(PipelineStatus* output, PipelineStatus status) { | 139 void ErrorCallback(PipelineStatus* output, PipelineStatus status) { |
| 135 *output = status; | 140 *output = status; |
| 136 } | 141 } |
| 137 | 142 |
| 138 // Tests that a MojoRendererImpl can successfully establish communication | 143 // Tests that a MojoRendererImpl can successfully establish communication |
| 139 // with a MojoRendererService and set up a MojoDemuxerStream | 144 // with a MojoRendererService and set up a MojoDemuxerStream |
| 140 // connection. The test also initializes a media::AudioRendererImpl which | 145 // connection. The test also initializes a media::AudioRendererImpl which |
| 141 // will error-out expectedly due to lack of support for decoder selection. | 146 // will error-out expectedly due to lack of support for decoder selection. |
| 142 TEST_F(MojoRendererTest, BasicInitialize) { | 147 TEST_F(MojoRendererTest, BasicInitialize) { |
| 143 MojoRendererImpl rimpl(task_runner(), service_provider()); | 148 MojoRendererImpl mojo_renderer_impl(task_runner(), service_provider()); |
| 144 PipelineStatus expected_error(PIPELINE_OK); | 149 PipelineStatus expected_error(PIPELINE_OK); |
| 145 rimpl.Initialize(stream_provider(), | 150 mojo_renderer_impl.Initialize( |
| 146 base::MessageLoop::current()->QuitClosure(), | 151 stream_provider(), base::MessageLoop::current()->QuitClosure(), |
| 147 media::StatisticsCB(), | 152 media::StatisticsCB(), base::Closure(), |
| 148 base::Closure(), | 153 base::Bind(&ErrorCallback, &expected_error), media::BufferingStateCB()); |
| 149 base::Bind(&ErrorCallback, &expected_error), | |
| 150 media::BufferingStateCB()); | |
| 151 base::MessageLoop::current()->Run(); | 154 base::MessageLoop::current()->Run(); |
| 152 | 155 |
| 153 // We expect an error during initialization because MojoRendererService | 156 // We expect an error during initialization because MojoRendererService |
| 154 // doesn't initialize any decoders, which causes an error. | 157 // doesn't initialize any decoders, which causes an error. |
| 155 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, expected_error); | 158 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, expected_error); |
| 156 } | 159 } |
| 157 | 160 |
| 158 } // namespace media | 161 } // namespace media |
| 159 | |
| 160 MojoResult MojoMain(MojoHandle shell_handle) { | |
| 161 base::CommandLine::Init(0, NULL); | |
| 162 #if !defined(COMPONENT_BUILD) | |
| 163 base::AtExitManager at_exit; | |
| 164 #endif | |
| 165 | |
| 166 // TODO(tim): Reconcile this with apptest framework when it is ready. | |
| 167 scoped_ptr<mojo::ApplicationDelegate> delegate(new MojoRendererTestHelper()); | |
| 168 g_test_delegate = static_cast<MojoRendererTestHelper*>(delegate.get()); | |
| 169 { | |
| 170 base::MessageLoop loop; | |
| 171 mojo::ApplicationImpl impl( | |
| 172 delegate.get(), | |
| 173 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); | |
| 174 | |
| 175 int argc = 0; | |
| 176 char** argv = NULL; | |
| 177 testing::InitGoogleTest(&argc, argv); | |
| 178 mojo_ignore_result(RUN_ALL_TESTS()); | |
| 179 } | |
| 180 | |
| 181 g_test_delegate = NULL; | |
| 182 delegate.reset(); | |
| 183 return MOJO_RESULT_OK; | |
| 184 } | |
| OLD | NEW |