Chromium Code Reviews| 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.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 virtual ~MojoRendererTestHelper() {} | |
| 29 | |
| 30 // ApplicationDelegate implementation. | |
| 31 virtual 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 FakeDemuxer : public media::Demuxer, | |
|
scherkus (not reviewing)
2014/09/09 20:35:33
when xhwang@'s DemuxerStreamProvider CL lands, you
tim (not reviewing)
2014/09/10 23:08:31
Well, FDS requires considerable work to support au
| |
| 49 public media::DemuxerStream { | |
| 50 public: | |
| 51 FakeDemuxer() {} | |
| 52 virtual ~FakeDemuxer() {} | |
| 53 | |
| 54 // media::Demuxer implementation. | |
| 55 virtual void Initialize(media::DemuxerHost* host, | |
| 56 const media::PipelineStatusCB& status_cb, | |
| 57 bool enable_text_tracks) OVERRIDE {} | |
| 58 | |
| 59 virtual void Seek(base::TimeDelta time, | |
| 60 const media::PipelineStatusCB& status_cb) OVERRIDE {} | |
| 61 | |
| 62 virtual void Stop() OVERRIDE {} | |
| 63 | |
| 64 virtual media::DemuxerStream* GetStream( | |
| 65 media::DemuxerStream::Type type) OVERRIDE { | |
| 66 DCHECK_EQ(media::DemuxerStream::AUDIO, type); | |
| 67 return this; | |
| 68 } | |
| 69 | |
| 70 virtual base::Time GetTimelineOffset() const OVERRIDE { | |
| 71 return base::Time(); | |
| 72 } | |
| 73 | |
| 74 virtual media::Demuxer::Liveness GetLiveness() const OVERRIDE { | |
| 75 return media::Demuxer::LIVENESS_UNKNOWN; | |
| 76 } | |
| 77 | |
| 78 // media::DemuxerStream implementation. | |
| 79 virtual void Read(const ReadCB& read_cb) OVERRIDE {} | |
| 80 | |
| 81 virtual media::AudioDecoderConfig audio_decoder_config() OVERRIDE { | |
| 82 media::AudioDecoderConfig config; | |
| 83 config.Initialize(media::kCodecAAC, media::kSampleFormatU8, | |
| 84 media::CHANNEL_LAYOUT_SURROUND, 48000, NULL, 0, | |
| 85 false, false, base::TimeDelta(), 0); | |
| 86 return config; | |
| 87 } | |
| 88 | |
| 89 virtual media::VideoDecoderConfig video_decoder_config() OVERRIDE { | |
| 90 NOTREACHED(); | |
| 91 return media::VideoDecoderConfig(); | |
| 92 } | |
| 93 | |
| 94 virtual media::DemuxerStream::Type type() OVERRIDE { | |
| 95 return media::DemuxerStream::AUDIO; | |
| 96 } | |
| 97 | |
| 98 virtual void EnableBitstreamConverter() OVERRIDE {} | |
| 99 | |
| 100 virtual bool SupportsConfigChanges() OVERRIDE { | |
| 101 return true; | |
| 102 } | |
| 103 | |
| 104 virtual media::VideoRotation video_rotation() OVERRIDE { | |
| 105 NOTREACHED(); | |
| 106 return media::VIDEO_ROTATION_0; | |
| 107 } | |
| 108 | |
| 109 private: | |
| 110 DISALLOW_COPY_AND_ASSIGN(FakeDemuxer); | |
| 111 }; | |
| 112 | |
| 113 } // namespace | |
| 114 | |
| 115 namespace media { | |
| 116 | |
| 117 class MojoRendererTest : public testing::Test { | |
| 118 public: | |
| 119 MojoRendererTest() : service_provider_(NULL) {} | |
| 120 | |
| 121 virtual void SetUp() OVERRIDE { | |
| 122 demuxer_.reset(new FakeDemuxer()); | |
| 123 service_provider_ = | |
| 124 g_test_delegate->application_impl()->ConnectToApplication( | |
| 125 "mojo:media_mojo_renderer_app")->GetServiceProvider(); | |
| 126 } | |
| 127 | |
| 128 mojo::ServiceProvider* service_provider() { return service_provider_; } | |
| 129 media::Demuxer* demuxer() { return demuxer_.get(); } | |
|
scherkus (not reviewing)
2014/09/09 20:35:33
remove media:: here and everywhere else
tim (not reviewing)
2014/09/10 23:08:31
Done.
| |
| 130 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { | |
| 131 return base::MessageLoop::current()->task_runner(); | |
| 132 } | |
| 133 | |
| 134 private: | |
| 135 scoped_ptr<media::Demuxer> demuxer_; | |
| 136 mojo::ServiceProvider* service_provider_; | |
| 137 | |
| 138 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest); | |
| 139 }; | |
| 140 | |
| 141 void ErrorCallback(media::PipelineStatus* output, | |
| 142 media::PipelineStatus status) { | |
| 143 *output = status; | |
| 144 } | |
| 145 | |
| 146 // Tests that a MojoRendererImpl can successfully establish communication | |
| 147 // with a MojoRendererService and set up a MojoDemuxerStream | |
| 148 // connection. The test also initializes a media::AudioRendererImpl which | |
| 149 // will error-out expectedly due to lack of support for decoder selection. | |
| 150 TEST_F(MojoRendererTest, BasicInitialize) { | |
| 151 MojoRendererImpl rimpl(task_runner(), demuxer(), service_provider()); | |
| 152 PipelineStatus expected_error(PIPELINE_OK); | |
| 153 rimpl.Initialize(base::MessageLoop::current()->QuitClosure(), | |
| 154 media::StatisticsCB(), | |
| 155 base::Closure(), | |
| 156 base::Bind(&ErrorCallback, &expected_error), | |
| 157 media::BufferingStateCB(), | |
| 158 media::Renderer::TimeDeltaCB()); | |
| 159 base::MessageLoop::current()->Run(); | |
| 160 | |
| 161 // We expect an error during initialization because MojoRendererService | |
| 162 // doesn't initialize any decoders, which causes an error. | |
| 163 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, expected_error); | |
| 164 } | |
| 165 | |
| 166 } // namespace media | |
| 167 | |
| 168 MojoResult MojoMain(MojoHandle shell_handle) { | |
| 169 base::CommandLine::Init(0, NULL); | |
| 170 #if !defined(COMPONENT_BUILD) | |
| 171 base::AtExitManager at_exit; | |
| 172 #endif | |
| 173 | |
| 174 // TODO(tim): Reconcile this with apptest framework when it is ready. | |
| 175 scoped_ptr<mojo::ApplicationDelegate> delegate(new MojoRendererTestHelper()); | |
| 176 g_test_delegate = static_cast<MojoRendererTestHelper*>(delegate.get()); | |
| 177 { | |
| 178 base::MessageLoop loop; | |
| 179 mojo::ApplicationImpl impl(delegate.get(), | |
| 180 mojo::MakeScopedHandle(mojo::MessagePipeHandle(shell_handle))); | |
| 181 | |
| 182 int argc = 0; | |
| 183 char** argv = NULL; | |
| 184 testing::InitGoogleTest(&argc, argv); | |
| 185 mojo_ignore_result(RUN_ALL_TESTS()); | |
| 186 } | |
| 187 | |
| 188 g_test_delegate = NULL; | |
| 189 delegate.reset(); | |
| 190 return MOJO_RESULT_OK; | |
| 191 } | |
| OLD | NEW |