1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
|
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "media/remoting/renderer_controller.h"
#include "base/callback.h"
#include "base/memory/ptr_util.h"
#include "base/message_loop/message_loop.h"
#include "base/run_loop.h"
#include "media/base/audio_decoder_config.h"
#include "media/base/cdm_config.h"
#include "media/base/limits.h"
#include "media/base/media_util.h"
#include "media/base/test_helpers.h"
#include "media/base/video_decoder_config.h"
#include "media/remoting/fake_remoter.h"
#include "media/remoting/remoting_cdm.h"
#include "mojo/public/cpp/bindings/strong_binding.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace media {
namespace remoting {
namespace {
constexpr mojom::RemotingSinkCapabilities kAllCapabilities =
mojom::RemotingSinkCapabilities::CONTENT_DECRYPTION_AND_RENDERING;
PipelineMetadata DefaultMetadata() {
PipelineMetadata data;
data.has_audio = true;
data.has_video = true;
data.video_decoder_config = TestVideoConfig::Normal();
return data;
}
PipelineMetadata EncryptedMetadata() {
PipelineMetadata data;
data.has_audio = true;
data.has_video = true;
data.video_decoder_config = TestVideoConfig::NormalEncrypted();
return data;
}
} // namespace
class RendererControllerTest : public ::testing::Test,
public MediaObserverClient {
public:
RendererControllerTest() {}
~RendererControllerTest() override {}
void TearDown() final { RunUntilIdle(); }
static void RunUntilIdle() { base::RunLoop().RunUntilIdle(); }
// MediaObserverClient implementation.
void SwitchRenderer(bool disable_pipeline_auto_suspend) override {
is_rendering_remotely_ = controller_->remote_rendering_started();
disable_pipeline_suspend_ = disable_pipeline_auto_suspend;
}
void ActivateViewportIntersectionMonitoring(bool activate) override {
activate_viewport_intersection_monitoring_ = activate;
}
void CreateCdm(bool is_remoting) { is_remoting_cdm_ = is_remoting; }
base::MessageLoop message_loop_;
protected:
std::unique_ptr<RendererController> controller_;
bool is_rendering_remotely_ = false;
bool is_remoting_cdm_ = false;
bool activate_viewport_intersection_monitoring_ = false;
bool disable_pipeline_suspend_ = false;
private:
DISALLOW_COPY_AND_ASSIGN(RendererControllerTest);
};
TEST_F(RendererControllerTest, ToggleRendererOnFullscreenChange) {
EXPECT_FALSE(is_rendering_remotely_);
const scoped_refptr<SharedSession> shared_session =
FakeRemoterFactory::CreateSharedSession(false);
controller_ = base::MakeUnique<RendererController>(shared_session);
controller_->SetClient(this);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_FALSE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
shared_session->OnSinkAvailable(kAllCapabilities);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_TRUE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
controller_->OnEnteredFullscreen();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnMetadataChanged(DefaultMetadata());
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnRemotePlaybackDisabled(false);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnPlaying();
RunUntilIdle();
EXPECT_TRUE(is_rendering_remotely_); // All requirements now satisfied.
EXPECT_TRUE(disable_pipeline_suspend_);
// Leaving fullscreen should shut down remoting.
controller_->OnExitedFullscreen();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_FALSE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
}
TEST_F(RendererControllerTest, ToggleRendererOnSinkCapabilities) {
EXPECT_FALSE(is_rendering_remotely_);
const scoped_refptr<SharedSession> shared_session =
FakeRemoterFactory::CreateSharedSession(false);
controller_ = base::MakeUnique<RendererController>(shared_session);
controller_->SetClient(this);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnMetadataChanged(DefaultMetadata());
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnRemotePlaybackDisabled(false);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnPlaying();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnEnteredFullscreen();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_FALSE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
// An available sink that does not support remote rendering should not cause
// the controller to toggle remote rendering on.
shared_session->OnSinkAvailable(mojom::RemotingSinkCapabilities::NONE);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
shared_session->OnSinkGone(); // Bye-bye useless sink!
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_FALSE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
// A sink that *does* support remote rendering *does* cause the controller to
// toggle remote rendering on.
shared_session->OnSinkAvailable(kAllCapabilities);
RunUntilIdle();
EXPECT_TRUE(is_rendering_remotely_);
EXPECT_TRUE(activate_viewport_intersection_monitoring_);
EXPECT_TRUE(disable_pipeline_suspend_);
controller_->OnExitedFullscreen();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_FALSE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
}
TEST_F(RendererControllerTest, ToggleRendererOnDisableChange) {
EXPECT_FALSE(is_rendering_remotely_);
const scoped_refptr<SharedSession> shared_session =
FakeRemoterFactory::CreateSharedSession(false);
controller_ = base::MakeUnique<RendererController>(shared_session);
controller_->SetClient(this);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnRemotePlaybackDisabled(true);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
shared_session->OnSinkAvailable(kAllCapabilities);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_TRUE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
controller_->OnMetadataChanged(DefaultMetadata());
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnEnteredFullscreen();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnRemotePlaybackDisabled(false);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnPlaying();
RunUntilIdle();
EXPECT_TRUE(is_rendering_remotely_); // All requirements now satisfied.
EXPECT_TRUE(activate_viewport_intersection_monitoring_);
EXPECT_TRUE(disable_pipeline_suspend_);
// If the page disables remote playback (e.g., by setting the
// disableRemotePlayback attribute), this should shut down remoting.
controller_->OnRemotePlaybackDisabled(true);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_FALSE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
}
TEST_F(RendererControllerTest, StartFailed) {
EXPECT_FALSE(is_rendering_remotely_);
const scoped_refptr<SharedSession> shared_session =
FakeRemoterFactory::CreateSharedSession(true);
controller_ = base::MakeUnique<RendererController>(shared_session);
controller_->SetClient(this);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
shared_session->OnSinkAvailable(kAllCapabilities);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_TRUE(activate_viewport_intersection_monitoring_);
EXPECT_FALSE(disable_pipeline_suspend_);
controller_->OnEnteredFullscreen();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnMetadataChanged(DefaultMetadata());
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnRemotePlaybackDisabled(false);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnPlaying();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_FALSE(disable_pipeline_suspend_);
}
TEST_F(RendererControllerTest, EncryptedWithRemotingCdm) {
EXPECT_FALSE(is_rendering_remotely_);
controller_ = base::MakeUnique<RendererController>(
FakeRemoterFactory::CreateSharedSession(false));
controller_->SetClient(this);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnMetadataChanged(EncryptedMetadata());
controller_->OnRemotePlaybackDisabled(false);
controller_->OnPlaying();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
const scoped_refptr<SharedSession> cdm_shared_session =
FakeRemoterFactory::CreateSharedSession(false);
std::unique_ptr<RemotingCdmController> cdm_controller =
base::MakeUnique<RemotingCdmController>(cdm_shared_session);
cdm_shared_session->OnSinkAvailable(kAllCapabilities);
cdm_controller->ShouldCreateRemotingCdm(
base::Bind(&RendererControllerTest::CreateCdm, base::Unretained(this)));
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_TRUE(is_remoting_cdm_);
// Create a RemotingCdm with |cdm_controller|.
const scoped_refptr<RemotingCdm> remoting_cdm = new RemotingCdm(
std::string(), GURL(), CdmConfig(), SessionMessageCB(), SessionClosedCB(),
SessionKeysChangeCB(), SessionExpirationUpdateCB(), CdmCreatedCB(),
std::move(cdm_controller));
std::unique_ptr<RemotingCdmContext> remoting_cdm_context =
base::MakeUnique<RemotingCdmContext>(remoting_cdm.get());
controller_->OnSetCdm(remoting_cdm_context.get());
RunUntilIdle();
EXPECT_TRUE(is_rendering_remotely_);
// For encrypted contents, entering/exiting full screen has no effect.
controller_->OnEnteredFullscreen();
RunUntilIdle();
EXPECT_TRUE(is_rendering_remotely_);
controller_->OnExitedFullscreen();
RunUntilIdle();
EXPECT_TRUE(is_rendering_remotely_);
EXPECT_NE(SharedSession::SESSION_PERMANENTLY_STOPPED,
controller_->session()->state());
cdm_shared_session->OnSinkGone();
RunUntilIdle();
EXPECT_EQ(SharedSession::SESSION_PERMANENTLY_STOPPED,
controller_->session()->state());
// Don't switch renderer in this case. Still using the remoting renderer to
// show the failure interstitial.
EXPECT_TRUE(is_rendering_remotely_);
}
TEST_F(RendererControllerTest, EncryptedWithLocalCdm) {
EXPECT_FALSE(is_rendering_remotely_);
const scoped_refptr<SharedSession> initial_shared_session =
FakeRemoterFactory::CreateSharedSession(false);
controller_ = base::MakeUnique<RendererController>(initial_shared_session);
controller_->SetClient(this);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
initial_shared_session->OnSinkAvailable(kAllCapabilities);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnEnteredFullscreen();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnMetadataChanged(EncryptedMetadata());
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnRemotePlaybackDisabled(false);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnPlaying();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
const scoped_refptr<SharedSession> cdm_shared_session =
FakeRemoterFactory::CreateSharedSession(true);
std::unique_ptr<RemotingCdmController> cdm_controller =
base::MakeUnique<RemotingCdmController>(cdm_shared_session);
cdm_shared_session->OnSinkAvailable(kAllCapabilities);
cdm_controller->ShouldCreateRemotingCdm(
base::Bind(&RendererControllerTest::CreateCdm, base::Unretained(this)));
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_FALSE(is_remoting_cdm_);
}
TEST_F(RendererControllerTest, EncryptedWithFailedRemotingCdm) {
EXPECT_FALSE(is_rendering_remotely_);
controller_ = base::MakeUnique<RendererController>(
FakeRemoterFactory::CreateSharedSession(false));
controller_->SetClient(this);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnEnteredFullscreen();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnMetadataChanged(EncryptedMetadata());
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnRemotePlaybackDisabled(false);
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
controller_->OnPlaying();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
const scoped_refptr<SharedSession> cdm_shared_session =
FakeRemoterFactory::CreateSharedSession(false);
std::unique_ptr<RemotingCdmController> cdm_controller =
base::MakeUnique<RemotingCdmController>(cdm_shared_session);
cdm_shared_session->OnSinkAvailable(kAllCapabilities);
cdm_controller->ShouldCreateRemotingCdm(
base::Bind(&RendererControllerTest::CreateCdm, base::Unretained(this)));
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_TRUE(is_remoting_cdm_);
cdm_shared_session->OnSinkGone();
RunUntilIdle();
EXPECT_FALSE(is_rendering_remotely_);
EXPECT_NE(SharedSession::SESSION_PERMANENTLY_STOPPED,
controller_->session()->state());
const scoped_refptr<RemotingCdm> remoting_cdm = new RemotingCdm(
std::string(), GURL(), CdmConfig(), SessionMessageCB(), SessionClosedCB(),
SessionKeysChangeCB(), SessionExpirationUpdateCB(), CdmCreatedCB(),
std::move(cdm_controller));
std::unique_ptr<RemotingCdmContext> remoting_cdm_context =
base::MakeUnique<RemotingCdmContext>(remoting_cdm.get());
controller_->OnSetCdm(remoting_cdm_context.get());
RunUntilIdle();
// Switch to using the remoting renderer, even when the remoting CDM session
// was already terminated, to show the failure interstitial.
EXPECT_TRUE(is_rendering_remotely_);
EXPECT_EQ(SharedSession::SESSION_PERMANENTLY_STOPPED,
controller_->session()->state());
}
} // namespace remoting
} // namespace media
|