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; |
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 protected: |
| 110 // ApplicationTestBase implementation. |
| 111 mojo::ApplicationDelegate* GetApplicationDelegate() override { |
| 112 return &mojo_renderer_test_helper_; |
| 113 } |
110 | 114 |
111 void SetUp() override { | 115 void SetUp() override { |
| 116 ApplicationTestBase::SetUp(); |
112 demuxer_stream_provider_.reset(new FakeDemuxerStream()); | 117 demuxer_stream_provider_.reset(new FakeDemuxerStream()); |
113 service_provider_ = | 118 service_provider_ = |
114 g_test_delegate->application_impl() | 119 application_impl() |
115 ->ConnectToApplication("mojo:media_mojo_renderer_app") | 120 ->ConnectToApplication("mojo:mojo_media_renderer_app") |
116 ->GetServiceProvider(); | 121 ->GetServiceProvider(); |
117 } | 122 } |
118 | 123 |
119 mojo::ServiceProvider* service_provider() { return service_provider_; } | 124 mojo::ServiceProvider* service_provider() { return service_provider_; } |
120 DemuxerStreamProvider* stream_provider() { | 125 DemuxerStreamProvider* stream_provider() { |
121 return demuxer_stream_provider_.get(); | 126 return demuxer_stream_provider_.get(); |
122 } | 127 } |
123 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { | 128 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { |
124 return base::MessageLoop::current()->task_runner(); | 129 return base::MessageLoop::current()->task_runner(); |
125 } | 130 } |
126 | 131 |
127 private: | 132 private: |
| 133 MojoRendererTestHelper mojo_renderer_test_helper_; |
128 scoped_ptr<DemuxerStreamProvider> demuxer_stream_provider_; | 134 scoped_ptr<DemuxerStreamProvider> demuxer_stream_provider_; |
129 mojo::ServiceProvider* service_provider_; | 135 mojo::ServiceProvider* service_provider_; |
130 | 136 |
131 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest); | 137 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest); |
132 }; | 138 }; |
133 | 139 |
134 void ErrorCallback(PipelineStatus* output, PipelineStatus status) { | 140 void ErrorCallback(PipelineStatus* output, PipelineStatus status) { |
135 *output = status; | 141 *output = status; |
136 } | 142 } |
137 | 143 |
138 // Tests that a MojoRendererImpl can successfully establish communication | 144 // Tests that a MojoRendererImpl can successfully establish communication |
139 // with a MojoRendererService and set up a MojoDemuxerStream | 145 // with a MojoRendererService and set up a MojoDemuxerStream |
140 // connection. The test also initializes a media::AudioRendererImpl which | 146 // connection. The test also initializes a media::AudioRendererImpl which |
141 // will error-out expectedly due to lack of support for decoder selection. | 147 // will error-out expectedly due to lack of support for decoder selection. |
142 TEST_F(MojoRendererTest, BasicInitialize) { | 148 TEST_F(MojoRendererTest, BasicInitialize) { |
143 MojoRendererImpl rimpl(task_runner(), service_provider()); | 149 MojoRendererImpl mojo_renderer_impl(task_runner(), service_provider()); |
144 PipelineStatus expected_error(PIPELINE_OK); | 150 PipelineStatus expected_error(PIPELINE_OK); |
145 rimpl.Initialize(stream_provider(), | 151 mojo_renderer_impl.Initialize( |
146 base::MessageLoop::current()->QuitClosure(), | 152 stream_provider(), base::MessageLoop::current()->QuitClosure(), |
147 media::StatisticsCB(), | 153 media::StatisticsCB(), base::Closure(), |
148 base::Closure(), | 154 base::Bind(&ErrorCallback, &expected_error), media::BufferingStateCB()); |
149 base::Bind(&ErrorCallback, &expected_error), | |
150 media::BufferingStateCB()); | |
151 base::MessageLoop::current()->Run(); | 155 base::MessageLoop::current()->Run(); |
152 | 156 |
153 // We expect an error during initialization because MojoRendererService | 157 // We expect an error during initialization because MojoRendererService |
154 // doesn't initialize any decoders, which causes an error. | 158 // doesn't initialize any decoders, which causes an error. |
155 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, expected_error); | 159 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, expected_error); |
156 } | 160 } |
157 | 161 |
158 } // namespace media | 162 } // 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 |