Instrument first / non-first SSL_do_handshake and X509Certificate::CreateFromDERCertChain
[chromium-blink-merge.git] / media / mojo / services / media_renderer_apptest.cc
blob99d60ec5eff2fd471c12e25db8371a2d349266a4
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.
5 #include "base/bind.h"
6 #include "base/message_loop/message_loop.h"
7 #include "base/run_loop.h"
8 #include "media/base/audio_decoder_config.h"
9 #include "media/base/channel_layout.h"
10 #include "media/base/demuxer_stream_provider.h"
11 #include "media/base/sample_format.h"
12 #include "media/base/video_decoder_config.h"
13 #include "media/mojo/services/mojo_renderer_impl.h"
14 #include "mojo/public/cpp/application/application_delegate.h"
15 #include "mojo/public/cpp/application/application_impl.h"
16 #include "mojo/public/cpp/application/application_test_base.h"
17 #include "mojo/public/cpp/application/connect.h"
19 namespace {
21 // This class is here to give the gtest class access to the
22 // mojo::ApplicationImpl so that the tests can connect to other applications.
23 class MojoRendererTestHelper : public mojo::ApplicationDelegate {
24 public:
25 MojoRendererTestHelper() : application_impl_(NULL) {}
26 ~MojoRendererTestHelper() override {}
28 // ApplicationDelegate implementation.
29 void Initialize(mojo::ApplicationImpl* app) override {
30 application_impl_ = app;
33 mojo::ApplicationImpl* application_impl() { return application_impl_; }
35 private:
36 mojo::ApplicationImpl* application_impl_;
38 DISALLOW_COPY_AND_ASSIGN(MojoRendererTestHelper);
41 // TODO(tim): Make media::FakeDemuxerStream support audio and use that for the
42 // DemuxerStream implementation instead.
43 class FakeDemuxerStream : public media::DemuxerStreamProvider,
44 public media::DemuxerStream {
45 public:
46 FakeDemuxerStream() {}
47 ~FakeDemuxerStream() override {}
49 // media::Demuxer implementation.
50 media::DemuxerStream* GetStream(media::DemuxerStream::Type type) override {
51 if (type == media::DemuxerStream::AUDIO)
52 return this;
53 return nullptr;
56 // media::DemuxerStream implementation.
57 void Read(const ReadCB& read_cb) override {}
59 media::AudioDecoderConfig audio_decoder_config() override {
60 media::AudioDecoderConfig config;
61 config.Initialize(media::kCodecAAC,
62 media::kSampleFormatU8,
63 media::CHANNEL_LAYOUT_SURROUND,
64 48000,
65 NULL,
67 false,
68 false,
69 base::TimeDelta(),
70 0);
71 return config;
74 media::VideoDecoderConfig video_decoder_config() override {
75 NOTREACHED();
76 return media::VideoDecoderConfig();
79 media::DemuxerStream::Type type() const override {
80 return media::DemuxerStream::AUDIO;
83 void EnableBitstreamConverter() override {}
85 bool SupportsConfigChanges() override { return true; }
87 media::VideoRotation video_rotation() override {
88 NOTREACHED();
89 return media::VIDEO_ROTATION_0;
92 private:
93 DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStream);
96 } // namespace
98 namespace media {
100 class MojoRendererTest : public mojo::test::ApplicationTestBase {
101 public:
102 MojoRendererTest() : service_provider_(NULL) {}
103 ~MojoRendererTest() override {}
105 protected:
106 // ApplicationTestBase implementation.
107 mojo::ApplicationDelegate* GetApplicationDelegate() override {
108 return &mojo_renderer_test_helper_;
111 void SetUp() override {
112 ApplicationTestBase::SetUp();
113 demuxer_stream_provider_.reset(new FakeDemuxerStream());
114 service_provider_ =
115 application_impl()
116 ->ConnectToApplication("mojo:media")
117 ->GetServiceProvider();
120 mojo::MediaRendererPtr CreateMediaRenderer() {
121 mojo::MediaRendererPtr mojo_media_renderer;
122 mojo::ConnectToService(service_provider_,
123 &mojo_media_renderer);
124 return mojo_media_renderer.Pass();
127 DemuxerStreamProvider* stream_provider() {
128 return demuxer_stream_provider_.get();
130 scoped_refptr<base::SingleThreadTaskRunner> task_runner() {
131 return base::MessageLoop::current()->task_runner();
134 private:
135 MojoRendererTestHelper mojo_renderer_test_helper_;
136 scoped_ptr<DemuxerStreamProvider> demuxer_stream_provider_;
137 mojo::ServiceProvider* service_provider_;
139 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest);
142 void ErrorCallback(PipelineStatus* output, PipelineStatus status) {
143 *output = status;
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 mojo_renderer_impl(task_runner(), CreateMediaRenderer());
152 PipelineStatus expected_error(PIPELINE_OK);
153 mojo_renderer_impl.Initialize(
154 stream_provider(), base::MessageLoop::current()->QuitClosure(),
155 media::StatisticsCB(), media::BufferingStateCB(),
156 media::Renderer::PaintCB(), base::Closure(),
157 base::Bind(&ErrorCallback, &expected_error));
158 base::MessageLoop::current()->Run();
159 EXPECT_EQ(PIPELINE_OK, expected_error);
162 } // namespace media