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

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

Issue 2551963002: media: Rename media_mojo_shell_unittests to media_service_unittests (Closed)
Patch Set: Created 4 years 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') | media/mojo/services/media_service_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2015 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 <stdint.h>
6
7 #include <memory>
8 #include <utility>
9
10 #include "base/bind.h"
11 #include "base/callback.h"
12 #include "base/macros.h"
13 #include "base/run_loop.h"
14 #include "media/base/cdm_config.h"
15 #include "media/base/mock_filters.h"
16 #include "media/base/test_helpers.h"
17 #include "media/mojo/clients/mojo_demuxer_stream_impl.h"
18 #include "media/mojo/common/media_type_converters.h"
19 #include "media/mojo/interfaces/content_decryption_module.mojom.h"
20 #include "media/mojo/interfaces/decryptor.mojom.h"
21 #include "media/mojo/interfaces/interface_factory.mojom.h"
22 #include "media/mojo/interfaces/media_service.mojom.h"
23 #include "media/mojo/interfaces/renderer.mojom.h"
24 #include "mojo/public/cpp/bindings/associated_binding.h"
25 #include "mojo/public/cpp/bindings/interface_request.h"
26 #include "services/service_manager/public/cpp/interface_registry.h"
27 #include "services/service_manager/public/cpp/service_test.h"
28 #include "testing/gmock/include/gmock/gmock.h"
29
30 using testing::Exactly;
31 using testing::Invoke;
32 using testing::InvokeWithoutArgs;
33 using testing::StrictMock;
34
35 namespace media {
36 namespace {
37
38 #if defined(ENABLE_MOJO_CDM)
39 const char kClearKeyKeySystem[] = "org.w3.clearkey";
40 const char kInvalidKeySystem[] = "invalid.key.system";
41 #endif
42 const char kSecurityOrigin[] = "http://foo.com";
43
44 class MockRendererClient : public mojom::RendererClient {
45 public:
46 MockRendererClient() {}
47 ~MockRendererClient() override {}
48
49 // mojom::RendererClient implementation.
50 MOCK_METHOD3(OnTimeUpdate,
51 void(base::TimeDelta time,
52 base::TimeDelta max_time,
53 base::TimeTicks capture_time));
54 MOCK_METHOD1(OnBufferingStateChange, void(BufferingState state));
55 MOCK_METHOD0(OnEnded, void());
56 MOCK_METHOD0(OnError, void());
57 MOCK_METHOD1(OnVideoOpacityChange, void(bool opaque));
58 MOCK_METHOD1(OnVideoNaturalSizeChange, void(const gfx::Size& size));
59 MOCK_METHOD1(OnStatisticsUpdate,
60 void(const media::PipelineStatistics& stats));
61 MOCK_METHOD0(OnWaitingForDecryptionKey, void());
62 MOCK_METHOD1(OnDurationChange, void(base::TimeDelta duration));
63
64 private:
65 DISALLOW_COPY_AND_ASSIGN(MockRendererClient);
66 };
67
68 class MediaServiceTest : public service_manager::test::ServiceTest {
69 public:
70 MediaServiceTest()
71 : ServiceTest("media_mojo_shell_unittests"),
72 renderer_client_binding_(&renderer_client_),
73 video_stream_(DemuxerStream::VIDEO) {}
74 ~MediaServiceTest() override {}
75
76 void SetUp() override {
77 ServiceTest::SetUp();
78
79 connection_ = connector()->Connect("media");
80 media::mojom::MediaServicePtr media_service;
81 connection_->GetInterface(&media_service);
82
83 auto registry =
84 base::MakeUnique<service_manager::InterfaceRegistry>(std::string());
85 service_manager::mojom::InterfaceProviderPtr interfaces;
86 registry->Bind(GetProxy(&interfaces), service_manager::Identity(),
87 service_manager::InterfaceProviderSpec(),
88 service_manager::Identity(),
89 service_manager::InterfaceProviderSpec());
90
91 media_service->CreateInterfaceFactory(mojo::GetProxy(&interface_factory_),
92 std::move(interfaces));
93
94 run_loop_.reset(new base::RunLoop());
95 }
96
97 // MOCK_METHOD* doesn't support move only types. Work around this by having
98 // an extra method.
99 MOCK_METHOD2(OnCdmInitializedInternal, void(bool result, int cdm_id));
100 void OnCdmInitialized(mojom::CdmPromiseResultPtr result,
101 int cdm_id,
102 mojom::DecryptorPtr decryptor) {
103 OnCdmInitializedInternal(result->success, cdm_id);
104 }
105
106 void InitializeCdm(const std::string& key_system,
107 bool expected_result,
108 int cdm_id) {
109 interface_factory_->CreateCdm(mojo::GetProxy(&cdm_));
110
111 EXPECT_CALL(*this, OnCdmInitializedInternal(expected_result, cdm_id))
112 .Times(Exactly(1))
113 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit));
114 cdm_->Initialize(key_system, kSecurityOrigin,
115 mojom::CdmConfig::From(CdmConfig()),
116 base::Bind(&MediaServiceTest::OnCdmInitialized,
117 base::Unretained(this)));
118 }
119
120 MOCK_METHOD1(OnRendererInitialized, void(bool));
121
122 void InitializeRenderer(const VideoDecoderConfig& video_config,
123 bool expected_result) {
124 interface_factory_->CreateRenderer(std::string(),
125 mojo::GetProxy(&renderer_));
126
127 video_stream_.set_video_decoder_config(video_config);
128
129 mojom::DemuxerStreamPtr video_stream_proxy;
130 mojo_video_stream_.reset(new MojoDemuxerStreamImpl(
131 &video_stream_, GetProxy(&video_stream_proxy)));
132
133 mojom::RendererClientAssociatedPtrInfo client_ptr_info;
134 renderer_client_binding_.Bind(&client_ptr_info,
135 renderer_.associated_group());
136
137 EXPECT_CALL(*this, OnRendererInitialized(expected_result))
138 .Times(Exactly(1))
139 .WillOnce(InvokeWithoutArgs(run_loop_.get(), &base::RunLoop::Quit));
140 renderer_->Initialize(std::move(client_ptr_info), nullptr,
141 std::move(video_stream_proxy), base::nullopt,
142 base::nullopt,
143 base::Bind(&MediaServiceTest::OnRendererInitialized,
144 base::Unretained(this)));
145 }
146
147 MOCK_METHOD0(ConnectionClosed, void());
148
149 protected:
150 std::unique_ptr<service_manager::Connection> connection_;
151 std::unique_ptr<base::RunLoop> run_loop_;
152
153 mojom::InterfaceFactoryPtr interface_factory_;
154 mojom::ContentDecryptionModulePtr cdm_;
155 mojom::RendererPtr renderer_;
156
157 StrictMock<MockRendererClient> renderer_client_;
158 mojo::AssociatedBinding<mojom::RendererClient> renderer_client_binding_;
159
160 StrictMock<MockDemuxerStream> video_stream_;
161 std::unique_ptr<MojoDemuxerStreamImpl> mojo_video_stream_;
162
163 private:
164 DISALLOW_COPY_AND_ASSIGN(MediaServiceTest);
165 };
166
167 } // namespace
168
169 // Note: base::RunLoop::RunUntilIdle() does not work well in these tests because
170 // even when the loop is idle, we may still have pending events in the pipe.
171
172 #if defined(ENABLE_MOJO_CDM)
173 TEST_F(MediaServiceTest, InitializeCdm_Success) {
174 InitializeCdm(kClearKeyKeySystem, true, 1);
175 run_loop_->Run();
176 }
177
178 TEST_F(MediaServiceTest, InitializeCdm_InvalidKeySystem) {
179 InitializeCdm(kInvalidKeySystem, false, 0);
180 run_loop_->Run();
181 }
182 #endif // defined(ENABLE_MOJO_CDM)
183
184 #if defined(ENABLE_MOJO_RENDERER)
185 // Sometimes fails on Linux. http://crbug.com/594977
186 #if defined(OS_LINUX)
187 #define MAYBE_InitializeRenderer_Success DISABLED_InitializeRenderer_Success
188 #else
189 #define MAYBE_InitializeRenderer_Success InitializeRenderer_Success
190 #endif
191
192 TEST_F(MediaServiceTest, MAYBE_InitializeRenderer_Success) {
193 InitializeRenderer(TestVideoConfig::Normal(), true);
194 run_loop_->Run();
195 }
196
197 TEST_F(MediaServiceTest, InitializeRenderer_InvalidConfig) {
198 InitializeRenderer(TestVideoConfig::Invalid(), false);
199 run_loop_->Run();
200 }
201 #endif // defined(ENABLE_MOJO_RENDERER)
202
203 TEST_F(MediaServiceTest, Lifetime) {
204 connection_->SetConnectionLostClosure(
205 base::Bind(&MediaServiceTest::ConnectionClosed, base::Unretained(this)));
206
207 // Disconnecting CDM and Renderer services doesn't terminate the app.
208 cdm_.reset();
209 renderer_.reset();
210
211 // Disconnecting InterfaceFactory service should terminate the app, which will
212 // close the connection.
213 EXPECT_CALL(*this, ConnectionClosed())
214 .Times(Exactly(1))
215 .WillOnce(Invoke(run_loop_.get(), &base::RunLoop::Quit));
216 interface_factory_.reset();
217
218 run_loop_->Run();
219 }
220
221 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/services/BUILD.gn ('k') | media/mojo/services/media_service_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698