Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(10)

Side by Side Diff: media/mojo/services/renderer_unittest.cc

Issue 709923003: Use ApplicationTestBase for MojoRendererTest. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/mojo/services/BUILD.gn ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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" 5 #include "base/at_exit.h"
6 #include "base/bind.h" 6 #include "base/bind.h"
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/message_loop/message_loop.h" 8 #include "base/message_loop/message_loop.h"
9 #include "base/run_loop.h" 9 #include "base/run_loop.h"
10 #include "media/base/audio_decoder_config.h" 10 #include "media/base/audio_decoder_config.h"
11 #include "media/base/channel_layout.h" 11 #include "media/base/channel_layout.h"
12 #include "media/base/demuxer_stream_provider.h" 12 #include "media/base/demuxer_stream_provider.h"
13 #include "media/base/sample_format.h" 13 #include "media/base/sample_format.h"
14 #include "media/base/video_decoder_config.h" 14 #include "media/base/video_decoder_config.h"
15 #include "media/mojo/services/mojo_renderer_impl.h" 15 #include "media/mojo/services/mojo_renderer_impl.h"
16 #include "mojo/public/c/system/main.h" 16 #include "mojo/public/c/system/main.h"
17 #include "mojo/public/cpp/application/application_delegate.h" 17 #include "mojo/public/cpp/application/application_delegate.h"
18 #include "mojo/public/cpp/application/application_impl.h" 18 #include "mojo/public/cpp/application/application_impl.h"
19 #include "testing/gtest/include/gtest/gtest.h" 19 #include "mojo/public/cpp/application/application_test_base.h"
20 20
21 namespace { 21 namespace {
22 22
23 // This class is here to give the gtest class access to the 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. 24 // mojo::ApplicationImpl so that the tests can connect to other applications.
25 class MojoRendererTestHelper : public mojo::ApplicationDelegate { 25 class MojoRendererTestHelper : public mojo::ApplicationDelegate {
26 public: 26 public:
27 MojoRendererTestHelper() : application_impl_(NULL) {} 27 MojoRendererTestHelper() : application_impl_(NULL) {}
28 ~MojoRendererTestHelper() override {} 28 ~MojoRendererTestHelper() override {}
29 29
30 // ApplicationDelegate implementation. 30 // ApplicationDelegate implementation.
31 void Initialize(mojo::ApplicationImpl* app) override { 31 void Initialize(mojo::ApplicationImpl* app) override {
32 application_impl_ = app; 32 application_impl_ = app;
33 } 33 }
34 34
35 mojo::ApplicationImpl* application_impl() { return application_impl_; } 35 mojo::ApplicationImpl* application_impl() { return application_impl_; }
36 36
37 private: 37 private:
38 mojo::ApplicationImpl* application_impl_; 38 mojo::ApplicationImpl* application_impl_;
39 39
40 DISALLOW_COPY_AND_ASSIGN(MojoRendererTestHelper); 40 DISALLOW_COPY_AND_ASSIGN(MojoRendererTestHelper);
41 }; 41 };
42 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 43 // TODO(tim): Make media::FakeDemuxerStream support audio and use that for the
47 // DemuxerStream implementation instead. 44 // DemuxerStream implementation instead.
48 class FakeDemuxerStream : public media::DemuxerStreamProvider, 45 class FakeDemuxerStream : public media::DemuxerStreamProvider,
49 public media::DemuxerStream { 46 public media::DemuxerStream {
50 public: 47 public:
51 FakeDemuxerStream() {} 48 FakeDemuxerStream() {}
52 ~FakeDemuxerStream() override {} 49 ~FakeDemuxerStream() override {}
53 50
54 // media::Demuxer implementation. 51 // media::Demuxer implementation.
55 media::DemuxerStream* GetStream(media::DemuxerStream::Type type) override { 52 media::DemuxerStream* GetStream(media::DemuxerStream::Type type) override {
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
97 } 94 }
98 95
99 private: 96 private:
100 DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStream); 97 DISALLOW_COPY_AND_ASSIGN(FakeDemuxerStream);
101 }; 98 };
102 99
103 } // namespace 100 } // namespace
104 101
105 namespace media { 102 namespace media {
106 103
107 class MojoRendererTest : public testing::Test { 104 class MojoRendererTest : public mojo::test::ApplicationTestBase {
108 public: 105 public:
109 MojoRendererTest() : service_provider_(NULL) {} 106 MojoRendererTest()
107 : ApplicationTestBase(mojo::Array<mojo::String>()),
108 service_provider_(NULL) {}
109 ~MojoRendererTest() override {}
110
111 // ApplicationTestBase implementation.
112 mojo::ApplicationDelegate* GetApplicationDelegate() override {
113 return &mojo_renderer_test_helper_;
114 }
110 115
111 void SetUp() override { 116 void SetUp() override {
112 demuxer_stream_provider_.reset(new FakeDemuxerStream()); 117 demuxer_stream_provider_.reset(new FakeDemuxerStream());
118 ApplicationTestBase::SetUp();
DaleCurtis 2014/11/10 21:03:30 Why not first?
113 service_provider_ = 119 service_provider_ =
114 g_test_delegate->application_impl() 120 application_impl()
115 ->ConnectToApplication("mojo:media_mojo_renderer_app") 121 ->ConnectToApplication("mojo:media_mojo_renderer_app")
116 ->GetServiceProvider(); 122 ->GetServiceProvider();
117 } 123 }
118 124
119 mojo::ServiceProvider* service_provider() { return service_provider_; } 125 mojo::ServiceProvider* service_provider() { return service_provider_; }
120 DemuxerStreamProvider* stream_provider() { 126 DemuxerStreamProvider* stream_provider() {
121 return demuxer_stream_provider_.get(); 127 return demuxer_stream_provider_.get();
122 } 128 }
123 scoped_refptr<base::SingleThreadTaskRunner> task_runner() { 129 scoped_refptr<base::SingleThreadTaskRunner> task_runner() {
124 return base::MessageLoop::current()->task_runner(); 130 return base::MessageLoop::current()->task_runner();
125 } 131 }
126 132
127 private: 133 private:
134 MojoRendererTestHelper mojo_renderer_test_helper_;
128 scoped_ptr<DemuxerStreamProvider> demuxer_stream_provider_; 135 scoped_ptr<DemuxerStreamProvider> demuxer_stream_provider_;
129 mojo::ServiceProvider* service_provider_; 136 mojo::ServiceProvider* service_provider_;
130 137
131 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest); 138 DISALLOW_COPY_AND_ASSIGN(MojoRendererTest);
132 }; 139 };
133 140
134 void ErrorCallback(PipelineStatus* output, PipelineStatus status) { 141 void ErrorCallback(PipelineStatus* output, PipelineStatus status) {
135 *output = status; 142 *output = status;
136 } 143 }
137 144
(...skipping 11 matching lines...) Expand all
149 base::Bind(&ErrorCallback, &expected_error), 156 base::Bind(&ErrorCallback, &expected_error),
150 media::BufferingStateCB()); 157 media::BufferingStateCB());
151 base::MessageLoop::current()->Run(); 158 base::MessageLoop::current()->Run();
152 159
153 // We expect an error during initialization because MojoRendererService 160 // We expect an error during initialization because MojoRendererService
154 // doesn't initialize any decoders, which causes an error. 161 // doesn't initialize any decoders, which causes an error.
155 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, expected_error); 162 EXPECT_EQ(PIPELINE_ERROR_COULD_NOT_RENDER, expected_error);
156 } 163 }
157 164
158 } // namespace media 165 } // 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 }
OLDNEW
« no previous file with comments | « media/mojo/services/BUILD.gn ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698