| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "base/at_exit.h" | |
| 6 #include "base/bind.h" | |
| 7 #include "base/command_line.h" | |
| 8 #include "base/message_loop/message_loop.h" | |
| 9 #include "base/run_loop.h" | |
| 10 #include "media/base/audio_decoder_config.h" | |
| 11 #include "media/base/channel_layout.h" | |
| 12 #include "media/base/demuxer_stream_provider.h" | |
| 13 #include "media/base/sample_format.h" | |
| 14 #include "media/base/video_decoder_config.h" | |
| 15 #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" | |
| 18 #include "mojo/public/cpp/application/application_impl.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | |
| 20 | |
| 21 namespace { | |
| 22 | |
| 23 // This class is here to give the gtest class access to the | |
| 24 // mojo::ApplicationImpl so that the tests can connect to other applications. | |
| 25 class MojoRendererTestHelper : public mojo::ApplicationDelegate { | |
| 26 public: | |
| 27 MojoRendererTestHelper() : application_impl_(NULL) {} | |
| 28 ~MojoRendererTestHelper() override {} | |
| 29 | |
| 30 // ApplicationDelegate implementation. | |
| 31 void Initialize(mojo::ApplicationImpl* app) override { | |
| 32 application_impl_ = app; | |
| 33 } | |
| 34 | |
| 35 mojo::ApplicationImpl* application_impl() { return application_impl_; } | |
| 36 | |
| 37 private: | |
| 38 mojo::ApplicationImpl* application_impl_; | |
| 39 | |
| 40 DISALLOW_COPY_AND_ASSIGN(MojoRendererTestHelper); | |
| 41 }; | |
| 42 | |
| 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 | |
| 47 // DemuxerStream implementation instead. | |
| 48 class FakeDemuxerStream : public media::DemuxerStreamProvider, | |
| 49 public media::DemuxerStream { | |
| 50 public: | |
| 51 FakeDemuxerStream() {} | |
| 52 ~FakeDemuxerStream() override {} | |
| 53 | |
| 54 // media::Demuxer implementation. | |
| 55 media::DemuxerStream* GetStream(media::DemuxerStream::Type type) override { | |
| 56 DCHECK_EQ(media::DemuxerStream::AUDIO, type); | |
| 57 return this; | |
| 58 } | |
| 59 media::DemuxerStreamProvider::Liveness GetLiveness() const override { | |
| 60 return media::DemuxerStreamProvider::LIVENESS_UNKNOWN; | |
| 61 } | |
| 62 | |
| 63 // media::DemuxerStream implementation. | |
| 64 void Read(const ReadCB& read_cb) override {} | |
| 65 | |
| 66 media::AudioDecoderConfig audio_decoder_config() override { | |
| 67 media::AudioDecoderConfig config; | |
| 68 config.Initialize(media::kCodecAAC, | |
| 69 media::kSampleFormatU8, | |
| 70 media::CHANNEL_LAYOUT_SURROUND, | |
| 71 48000, | |
| 72 NULL, | |
| 73 0, | |
| 74 false, | |
| 75 false, | |
| 76 base::TimeDelta(), | |
| 77 0); | |
| 78 return config; | |
| 79 } | |
| 80 | |
| 81 media::VideoDecoderConfig video_decoder_config() override { | |
| 82 NOTREACHED(); | |
| 83 return media::VideoDecoderConfig(); | |
| 84 } | |
| 85 | |
| 86 media::DemuxerStream::Type type() override { | |
| 87 return media::DemuxerStream::AUDIO; | |
| 88 } | |
| 89 | |
| 90 void EnableBitstreamConverter() override {} | |
| 91 | |
| 92 bool SupportsConfigChanges() override { return true; } | |
| 93 | |
| 94 media::VideoRotation video_rotation() override { | |
| 95 NOTREACHED(); | |
| 96 return media::VIDEO_ROTATION_0; | |
| 97 } | |
| 98 | |
| 99 private: | |
| 100 DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStream); | |
| 101 }; | |
| 102 | |
| 103 } // namespace | |
| 104 | |
| 105 namespace media { | |
| 106 | |
| 107 class MojoRendererTest : public testing::Test { | |
| 108 public: | |
| 109 MojoRendererTest() : service_provider_(NULL) {} | |
| 110 | |
| 111 void SetUp() override { | |
| 112 demuxer_stream_provider_.reset(new FakeDemuxerStream()); | |
| 113 service_provider_ = | |
| 114 g_test_delegate->application_impl() | |
| 115 ->ConnectToApplication("mojo:media_mojo_renderer_app") | |
| 116 ->GetServiceProvider(); | |
| 117 } | |
| 118 | |
| 119 mojo::ServiceProvider* service_provider() { return service_provider_; } | |
| 120 DemuxerStreamProvider* stream_provider() { | |
| 121 return demuxer_stream_provider_.get(); | |
| 122 } | |
| 123 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { | |
| 124 return base::MessageLoop::current()->task_runner(); | |
| 125 } | |
| 126 | |
| 127 private: | |
| 128 scoped_ptr<DemuxerStreamProvider> demuxer_stream_provider_; | |
| 129 mojo::ServiceProvider* service_provider_; | |
| 130 | |
| 131 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest); | |
| 132 }; | |
| 133 | |
| 134 void ErrorCallback(PipelineStatus* output, PipelineStatus status) { | |
| 135 *output = status; | |
| 136 } | |
| 137 | |
| 138 // Tests that a MojoRendererImpl can successfully establish communication | |
| 139 // with a MojoRendererService and set up a MojoDemuxerStream | |
| 140 // connection. The test also initializes a media::AudioRendererImpl which | |
| 141 // will error-out expectedly due to lack of support for decoder selection. | |
| 142 TEST_F(MojoRendererTest, BasicInitialize) { | |
| 143 MojoRendererImpl rimpl(task_runner(), service_provider()); | |
| 144 PipelineStatus expected_error(PIPELINE_OK); | |
| 145 rimpl.Initialize(stream_provider(), | |
| 146 base::MessageLoop::current()->QuitClosure(), | |
| 147 media::StatisticsCB(), | |
| 148 base::Closure(), | |
| 149 base::Bind(&ErrorCallback, &expected_error), | |
| 150 media::BufferingStateCB()); | |
| 151 base::MessageLoop::current()->Run(); | |
| 152 | |
| 153 // We expect an error during initialization because MojoRendererService | |
| 154 // doesn't initialize any decoders, which causes an error. | |
| 155 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, expected_error); | |
| 156 } | |
| 157 | |
| 158 } // 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 |