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.
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "media/base/eme_constants.h"
12 #include "media/base/key_systems.h"
13 #include "media/base/media_permission.h"
14 #include "media/blink/key_system_config_selector.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h"
17 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h"
18 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
19 #include "third_party/WebKit/public/platform/WebString.h"
26 const char kSupported
[] = "supported";
27 const char kRecommendIdentifier
[] = "recommend_identifier";
28 const char kRequireIdentifier
[] = "require_identifier";
29 const char kUnsupported
[] = "unsupported";
31 // TODO(sandersd): Audio and video variants (doesn't matter for now because the
32 // checks are in KeySystems).
33 const char kSupportedContainer
[] = "video/webm";
34 const char kUnsupportedContainer
[] = "video/foo";
36 // TODO(sandersd): Extended codec variants (requires proprietary codec support).
37 const char kSupportedCodec
[] = "vp8";
38 const char kUnsupportedCodec
[] = "foo";
39 const char kUnsupportedCodecs
[] = "vp8,foo";
40 const char kSupportedCodecs
[] = "vp8,vp8";
42 const char kDefaultSecurityOrigin
[] = "https://example.com/";
44 class FakeKeySystems
: public KeySystems
{
46 ~FakeKeySystems() override
{
49 bool IsSupportedKeySystem(const std::string
& key_system
) const override
{
50 if (key_system
== kSupported
)
55 // TODO(sandersd): Move implementation into KeySystemConfigSelector?
56 bool IsSupportedInitDataType(const std::string
& key_system
,
57 EmeInitDataType init_data_type
) const override
{
58 switch (init_data_type
) {
59 case EmeInitDataType::UNKNOWN
:
61 case EmeInitDataType::WEBM
:
62 return (init_data_types
& kInitDataTypeMaskWebM
) != 0;
63 case EmeInitDataType::CENC
:
64 return (init_data_types
& kInitDataTypeMaskCenc
) != 0;
65 case EmeInitDataType::KEYIDS
:
66 return (init_data_types
& kInitDataTypeMaskKeyIds
) != 0;
72 bool IsSupportedCodecCombination(
73 const std::string
& key_system
,
74 EmeMediaType media_type
,
75 const std::string
& container_mime_type
,
76 const std::vector
<std::string
>& codecs
) const override
{
77 if (container_mime_type
== kUnsupportedContainer
)
79 DCHECK_EQ(kSupportedContainer
, container_mime_type
);
80 for (const std::string
& codec
: codecs
) {
81 if (codec
== kUnsupportedCodec
)
83 DCHECK_EQ(kSupportedCodec
, codec
);
88 EmeConfigRule
GetRobustnessConfigRule(
89 const std::string
& key_system
,
90 EmeMediaType media_type
,
91 const std::string
& requested_robustness
) const override
{
92 if (requested_robustness
== kUnsupported
)
93 return EmeConfigRule::NOT_SUPPORTED
;
94 if (requested_robustness
== kRequireIdentifier
)
95 return EmeConfigRule::IDENTIFIER_REQUIRED
;
96 if (requested_robustness
== kRecommendIdentifier
)
97 return EmeConfigRule::IDENTIFIER_RECOMMENDED
;
98 if (requested_robustness
== kSupported
)
99 return EmeConfigRule::SUPPORTED
;
101 return EmeConfigRule::NOT_SUPPORTED
;
104 EmeSessionTypeSupport
GetPersistentLicenseSessionSupport(
105 const std::string
& key_system
) const override
{
106 return persistent_license
;
109 EmeSessionTypeSupport
GetPersistentReleaseMessageSessionSupport(
110 const std::string
& key_system
) const override
{
111 return persistent_release_message
;
114 EmeFeatureSupport
GetPersistentStateSupport(
115 const std::string
& key_system
) const override
{
116 return persistent_state
;
119 EmeFeatureSupport
GetDistinctiveIdentifierSupport(
120 const std::string
& key_system
) const override
{
121 return distinctive_identifier
;
124 InitDataTypeMask init_data_types
= kInitDataTypeMaskNone
;
126 // INVALID so that they must be set in any test that needs them.
127 EmeSessionTypeSupport persistent_license
= EME_SESSION_TYPE_INVALID
;
128 EmeSessionTypeSupport persistent_release_message
= EME_SESSION_TYPE_INVALID
;
130 // Every test implicitly requires these, so they must be set. They are set to
131 // values that are likely to cause tests to fail if they are accidentally
132 // depended on. Test cases explicitly depending on them should set them, as
133 // the default values may be changed.
134 EmeFeatureSupport persistent_state
= EME_FEATURE_NOT_SUPPORTED
;
135 EmeFeatureSupport distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
138 class FakeMediaPermission
: public MediaPermission
{
140 void HasPermission(Type type
,
141 const GURL
& security_origin
,
142 const PermissionStatusCB
& permission_status_cb
) override
{
143 permission_status_cb
.Run(is_granted
);
146 void RequestPermission(
148 const GURL
& security_origin
,
149 const PermissionStatusCB
& permission_status_cb
) override
{
151 permission_status_cb
.Run(is_granted
);
155 bool is_granted
= false;
160 class KeySystemConfigSelectorTest
: public testing::Test
{
162 KeySystemConfigSelectorTest()
163 : key_systems_(new FakeKeySystems()),
164 media_permission_(new FakeMediaPermission()) {}
166 void SelectConfig() {
167 media_permission_
->requests
= 0;
168 succeeded_count_
= 0;
169 not_supported_count_
= 0;
170 KeySystemConfigSelector(key_systems_
.get(), media_permission_
.get())
171 .SelectConfig(key_system_
, configs_
, security_origin_
,
172 base::Bind(&KeySystemConfigSelectorTest::OnSucceeded
,
173 base::Unretained(this)),
174 base::Bind(&KeySystemConfigSelectorTest::OnNotSupported
,
175 base::Unretained(this)));
178 bool SelectConfigReturnsConfig() {
180 EXPECT_EQ(0, media_permission_
->requests
);
181 EXPECT_EQ(1, succeeded_count_
);
182 EXPECT_EQ(0, not_supported_count_
);
183 return (succeeded_count_
!= 0);
186 bool SelectConfigReturnsError() {
188 EXPECT_EQ(0, media_permission_
->requests
);
189 EXPECT_EQ(0, succeeded_count_
);
190 EXPECT_EQ(1, not_supported_count_
);
191 return (not_supported_count_
!= 0);
194 bool SelectConfigRequestsPermissionAndReturnsConfig() {
196 EXPECT_EQ(1, media_permission_
->requests
);
197 EXPECT_EQ(1, succeeded_count_
);
198 EXPECT_EQ(0, not_supported_count_
);
199 return (media_permission_
->requests
!= 0 && succeeded_count_
!= 0);
202 bool SelectConfigRequestsPermissionAndReturnsError() {
204 EXPECT_EQ(1, media_permission_
->requests
);
205 EXPECT_EQ(0, succeeded_count_
);
206 EXPECT_EQ(1, not_supported_count_
);
207 return (media_permission_
->requests
!= 0 && not_supported_count_
!= 0);
210 void OnSucceeded(const blink::WebMediaKeySystemConfiguration
& result
) {
215 void OnNotSupported(const blink::WebString
&) { not_supported_count_
++; }
217 scoped_ptr
<FakeKeySystems
> key_systems_
;
218 scoped_ptr
<FakeMediaPermission
> media_permission_
;
220 // Held values for the call to SelectConfig().
221 blink::WebString key_system_
= blink::WebString::fromUTF8(kSupported
);
222 std::vector
<blink::WebMediaKeySystemConfiguration
> configs_
;
223 blink::WebSecurityOrigin security_origin_
=
224 blink::WebSecurityOrigin::createFromString(kDefaultSecurityOrigin
);
226 // Holds the last successful accumulated configuration.
227 blink::WebMediaKeySystemConfiguration config_
;
229 int succeeded_count_
;
230 int not_supported_count_
;
232 DISALLOW_COPY_AND_ASSIGN(KeySystemConfigSelectorTest
);
237 TEST_F(KeySystemConfigSelectorTest
, NoConfigs
) {
238 ASSERT_TRUE(SelectConfigReturnsError());
241 // Most of the tests below assume that an empty config is valid.
242 TEST_F(KeySystemConfigSelectorTest
, EmptyConfig
) {
243 configs_
.push_back(blink::WebMediaKeySystemConfiguration());
245 ASSERT_TRUE(SelectConfigReturnsConfig());
246 EXPECT_TRUE(config_
.label
.isNull());
247 EXPECT_TRUE(config_
.initDataTypes
.isEmpty());
248 EXPECT_TRUE(config_
.audioCapabilities
.isEmpty());
249 EXPECT_TRUE(config_
.videoCapabilities
.isEmpty());
250 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
251 config_
.distinctiveIdentifier
);
252 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
253 config_
.persistentState
);
254 ASSERT_EQ(1u, config_
.sessionTypes
.size());
255 EXPECT_EQ(blink::WebEncryptedMediaSessionType::Temporary
,
256 config_
.sessionTypes
[0]);
259 TEST_F(KeySystemConfigSelectorTest
, Label
) {
260 blink::WebMediaKeySystemConfiguration config
;
261 config
.label
= "foo";
262 configs_
.push_back(config
);
264 ASSERT_TRUE(SelectConfigReturnsConfig());
265 EXPECT_EQ("foo", config_
.label
);
269 // Empty is not tested because the empty check is in Blink.
271 TEST_F(KeySystemConfigSelectorTest
, KeySystem_NonAscii
) {
272 key_system_
= "\xde\xad\xbe\xef";
273 configs_
.push_back(blink::WebMediaKeySystemConfiguration());
274 ASSERT_TRUE(SelectConfigReturnsError());
277 TEST_F(KeySystemConfigSelectorTest
, KeySystem_Unsupported
) {
278 key_system_
= kUnsupported
;
279 configs_
.push_back(blink::WebMediaKeySystemConfiguration());
280 ASSERT_TRUE(SelectConfigReturnsError());
283 // --- initDataTypes ---
285 TEST_F(KeySystemConfigSelectorTest
, InitDataTypes_Empty
) {
286 blink::WebMediaKeySystemConfiguration config
;
287 config
.hasInitDataTypes
= true;
288 configs_
.push_back(config
);
290 ASSERT_TRUE(SelectConfigReturnsError());
293 TEST_F(KeySystemConfigSelectorTest
, InitDataTypes_NoneSupported
) {
294 key_systems_
->init_data_types
= kInitDataTypeMaskWebM
;
296 std::vector
<blink::WebEncryptedMediaInitDataType
> init_data_types
;
297 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Unknown
);
298 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Cenc
);
300 blink::WebMediaKeySystemConfiguration config
;
301 config
.hasInitDataTypes
= true;
302 config
.initDataTypes
= init_data_types
;
303 configs_
.push_back(config
);
305 ASSERT_TRUE(SelectConfigReturnsError());
308 TEST_F(KeySystemConfigSelectorTest
, InitDataTypes_SubsetSupported
) {
309 key_systems_
->init_data_types
= kInitDataTypeMaskWebM
;
311 std::vector
<blink::WebEncryptedMediaInitDataType
> init_data_types
;
312 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Unknown
);
313 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Cenc
);
314 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Webm
);
316 blink::WebMediaKeySystemConfiguration config
;
317 config
.hasInitDataTypes
= true;
318 config
.initDataTypes
= init_data_types
;
319 configs_
.push_back(config
);
321 ASSERT_TRUE(SelectConfigReturnsConfig());
322 ASSERT_EQ(1u, config_
.initDataTypes
.size());
323 EXPECT_EQ(blink::WebEncryptedMediaInitDataType::Webm
,
324 config_
.initDataTypes
[0]);
327 // --- distinctiveIdentifier ---
329 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_Default
) {
330 key_systems_
->distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
332 blink::WebMediaKeySystemConfiguration config
;
333 config
.distinctiveIdentifier
=
334 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
335 configs_
.push_back(config
);
337 ASSERT_TRUE(SelectConfigReturnsConfig());
338 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
339 config_
.distinctiveIdentifier
);
342 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_Forced
) {
343 media_permission_
->is_granted
= true;
344 key_systems_
->distinctive_identifier
= EME_FEATURE_ALWAYS_ENABLED
;
346 blink::WebMediaKeySystemConfiguration config
;
347 config
.distinctiveIdentifier
=
348 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
349 configs_
.push_back(config
);
351 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
352 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
353 config_
.distinctiveIdentifier
);
356 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_Blocked
) {
357 key_systems_
->distinctive_identifier
= EME_FEATURE_NOT_SUPPORTED
;
359 blink::WebMediaKeySystemConfiguration config
;
360 config
.distinctiveIdentifier
=
361 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
362 configs_
.push_back(config
);
364 ASSERT_TRUE(SelectConfigReturnsError());
367 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_RequestsPermission
) {
368 media_permission_
->is_granted
= true;
369 key_systems_
->distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
371 blink::WebMediaKeySystemConfiguration config
;
372 config
.distinctiveIdentifier
=
373 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
374 configs_
.push_back(config
);
376 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
377 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
378 config_
.distinctiveIdentifier
);
381 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_RespectsPermission
) {
382 media_permission_
->is_granted
= false;
383 key_systems_
->distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
385 blink::WebMediaKeySystemConfiguration config
;
386 config
.distinctiveIdentifier
=
387 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
388 configs_
.push_back(config
);
390 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsError());
393 // --- persistentState ---
395 TEST_F(KeySystemConfigSelectorTest
, PersistentState_Default
) {
396 key_systems_
->persistent_state
= EME_FEATURE_REQUESTABLE
;
398 blink::WebMediaKeySystemConfiguration config
;
399 config
.persistentState
=
400 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
401 configs_
.push_back(config
);
403 ASSERT_TRUE(SelectConfigReturnsConfig());
404 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
405 config_
.persistentState
);
408 TEST_F(KeySystemConfigSelectorTest
, PersistentState_Forced
) {
409 key_systems_
->persistent_state
= EME_FEATURE_ALWAYS_ENABLED
;
411 blink::WebMediaKeySystemConfiguration config
;
412 config
.persistentState
=
413 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
414 configs_
.push_back(config
);
416 ASSERT_TRUE(SelectConfigReturnsConfig());
417 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
418 config_
.persistentState
);
421 TEST_F(KeySystemConfigSelectorTest
, PersistentState_Blocked
) {
422 key_systems_
->persistent_state
= EME_FEATURE_ALWAYS_ENABLED
;
424 blink::WebMediaKeySystemConfiguration config
;
425 config
.persistentState
=
426 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
;
427 configs_
.push_back(config
);
429 ASSERT_TRUE(SelectConfigReturnsError());
432 // --- sessionTypes ---
434 TEST_F(KeySystemConfigSelectorTest
, SessionTypes_Empty
) {
435 blink::WebMediaKeySystemConfiguration config
;
436 config
.hasSessionTypes
= true;
437 configs_
.push_back(config
);
439 ASSERT_TRUE(SelectConfigReturnsConfig());
440 EXPECT_TRUE(config_
.sessionTypes
.isEmpty());
443 TEST_F(KeySystemConfigSelectorTest
, SessionTypes_SubsetSupported
) {
444 // Allow persistent state, as it would be required to be successful.
445 key_systems_
->persistent_state
= EME_FEATURE_REQUESTABLE
;
446 key_systems_
->persistent_license
= EME_SESSION_TYPE_NOT_SUPPORTED
;
448 std::vector
<blink::WebEncryptedMediaSessionType
> session_types
;
449 session_types
.push_back(blink::WebEncryptedMediaSessionType::Temporary
);
450 session_types
.push_back(
451 blink::WebEncryptedMediaSessionType::PersistentLicense
);
453 blink::WebMediaKeySystemConfiguration config
;
454 config
.hasSessionTypes
= true;
455 config
.sessionTypes
= session_types
;
456 configs_
.push_back(config
);
458 ASSERT_TRUE(SelectConfigReturnsError());
461 TEST_F(KeySystemConfigSelectorTest
, SessionTypes_AllSupported
) {
462 // Allow persistent state, and expect it to be required.
463 key_systems_
->persistent_state
= EME_FEATURE_REQUESTABLE
;
464 key_systems_
->persistent_license
= EME_SESSION_TYPE_SUPPORTED
;
466 std::vector
<blink::WebEncryptedMediaSessionType
> session_types
;
467 session_types
.push_back(blink::WebEncryptedMediaSessionType::Temporary
);
468 session_types
.push_back(
469 blink::WebEncryptedMediaSessionType::PersistentLicense
);
471 blink::WebMediaKeySystemConfiguration config
;
472 config
.persistentState
=
473 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
474 config
.hasSessionTypes
= true;
475 config
.sessionTypes
= session_types
;
476 configs_
.push_back(config
);
478 ASSERT_TRUE(SelectConfigReturnsConfig());
479 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
480 config_
.persistentState
);
481 ASSERT_EQ(2u, config_
.sessionTypes
.size());
482 EXPECT_EQ(blink::WebEncryptedMediaSessionType::Temporary
,
483 config_
.sessionTypes
[0]);
484 EXPECT_EQ(blink::WebEncryptedMediaSessionType::PersistentLicense
,
485 config_
.sessionTypes
[1]);
488 TEST_F(KeySystemConfigSelectorTest
, SessionTypes_PermissionCanBeRequired
) {
489 media_permission_
->is_granted
= true;
490 key_systems_
->distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
491 key_systems_
->persistent_state
= EME_FEATURE_REQUESTABLE
;
492 key_systems_
->persistent_license
= EME_SESSION_TYPE_SUPPORTED_WITH_IDENTIFIER
;
494 std::vector
<blink::WebEncryptedMediaSessionType
> session_types
;
495 session_types
.push_back(
496 blink::WebEncryptedMediaSessionType::PersistentLicense
);
498 blink::WebMediaKeySystemConfiguration config
;
499 config
.distinctiveIdentifier
=
500 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
501 config
.persistentState
=
502 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
503 config
.hasSessionTypes
= true;
504 config
.sessionTypes
= session_types
;
505 configs_
.push_back(config
);
507 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
508 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
509 config_
.distinctiveIdentifier
);
512 // --- videoCapabilities ---
514 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_Empty
) {
515 blink::WebMediaKeySystemConfiguration config
;
516 config
.hasVideoCapabilities
= true;
517 configs_
.push_back(config
);
519 ASSERT_TRUE(SelectConfigReturnsError());
522 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_NoneSupported
) {
523 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(2);
524 video_capabilities
[0].contentType
= "a";
525 video_capabilities
[0].mimeType
= kUnsupportedContainer
;
526 video_capabilities
[1].contentType
= "b";
527 video_capabilities
[1].mimeType
= kSupportedContainer
;
528 video_capabilities
[1].codecs
= kUnsupportedCodec
;
530 blink::WebMediaKeySystemConfiguration config
;
531 config
.hasVideoCapabilities
= true;
532 config
.videoCapabilities
= video_capabilities
;
533 configs_
.push_back(config
);
535 ASSERT_TRUE(SelectConfigReturnsError());
538 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_SubsetSupported
) {
539 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(2);
540 video_capabilities
[0].contentType
= "a";
541 video_capabilities
[0].mimeType
= kUnsupportedContainer
;
542 video_capabilities
[1].contentType
= "b";
543 video_capabilities
[1].mimeType
= kSupportedContainer
;
545 blink::WebMediaKeySystemConfiguration config
;
546 config
.hasVideoCapabilities
= true;
547 config
.videoCapabilities
= video_capabilities
;
548 configs_
.push_back(config
);
550 ASSERT_TRUE(SelectConfigReturnsConfig());
551 ASSERT_EQ(1u, config_
.videoCapabilities
.size());
552 EXPECT_EQ("b", config_
.videoCapabilities
[0].contentType
);
553 EXPECT_EQ(kSupportedContainer
, config_
.videoCapabilities
[0].mimeType
);
556 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_AllSupported
) {
557 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(2);
558 video_capabilities
[0].contentType
= "a";
559 video_capabilities
[0].mimeType
= kSupportedContainer
;
560 video_capabilities
[1].contentType
= "b";
561 video_capabilities
[1].mimeType
= kSupportedContainer
;
562 video_capabilities
[1].codecs
= kSupportedCodecs
;
564 blink::WebMediaKeySystemConfiguration config
;
565 config
.hasVideoCapabilities
= true;
566 config
.videoCapabilities
= video_capabilities
;
567 configs_
.push_back(config
);
569 ASSERT_TRUE(SelectConfigReturnsConfig());
570 ASSERT_EQ(2u, config_
.videoCapabilities
.size());
571 EXPECT_EQ("a", config_
.videoCapabilities
[0].contentType
);
572 EXPECT_EQ("b", config_
.videoCapabilities
[1].contentType
);
575 TEST_F(KeySystemConfigSelectorTest
,
576 VideoCapabilities_Codecs_SubsetSupported
) {
577 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
578 video_capabilities
[0].contentType
= "a";
579 video_capabilities
[0].mimeType
= kSupportedContainer
;
580 video_capabilities
[0].codecs
= kUnsupportedCodecs
;
582 blink::WebMediaKeySystemConfiguration config
;
583 config
.hasVideoCapabilities
= true;
584 config
.videoCapabilities
= video_capabilities
;
585 configs_
.push_back(config
);
587 ASSERT_TRUE(SelectConfigReturnsError());
590 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_Codecs_AllSupported
) {
591 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
592 video_capabilities
[0].contentType
= "a";
593 video_capabilities
[0].mimeType
= kSupportedContainer
;
594 video_capabilities
[0].codecs
= kSupportedCodecs
;
596 blink::WebMediaKeySystemConfiguration config
;
597 config
.hasVideoCapabilities
= true;
598 config
.videoCapabilities
= video_capabilities
;
599 configs_
.push_back(config
);
601 ASSERT_TRUE(SelectConfigReturnsConfig());
602 ASSERT_EQ(1u, config_
.videoCapabilities
.size());
603 EXPECT_EQ(kSupportedCodecs
, config_
.videoCapabilities
[0].codecs
);
606 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_Robustness_Supported
) {
607 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
608 video_capabilities
[0].contentType
= "a";
609 video_capabilities
[0].mimeType
= kSupportedContainer
;
610 video_capabilities
[0].robustness
= kSupported
;
612 blink::WebMediaKeySystemConfiguration config
;
613 config
.hasVideoCapabilities
= true;
614 config
.videoCapabilities
= video_capabilities
;
615 configs_
.push_back(config
);
617 ASSERT_TRUE(SelectConfigReturnsConfig());
618 ASSERT_EQ(1u, config_
.videoCapabilities
.size());
619 EXPECT_EQ(kSupported
, config_
.videoCapabilities
[0].robustness
);
622 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_Robustness_Unsupported
) {
623 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
624 video_capabilities
[0].contentType
= "a";
625 video_capabilities
[0].mimeType
= kSupportedContainer
;
626 video_capabilities
[0].robustness
= kUnsupported
;
628 blink::WebMediaKeySystemConfiguration config
;
629 config
.hasVideoCapabilities
= true;
630 config
.videoCapabilities
= video_capabilities
;
631 configs_
.push_back(config
);
633 ASSERT_TRUE(SelectConfigReturnsError());
636 TEST_F(KeySystemConfigSelectorTest
,
637 VideoCapabilities_Robustness_PermissionCanBeRequired
) {
638 media_permission_
->is_granted
= true;
639 key_systems_
->distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
641 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
642 video_capabilities
[0].contentType
= "a";
643 video_capabilities
[0].mimeType
= kSupportedContainer
;
644 video_capabilities
[0].robustness
= kRequireIdentifier
;
646 blink::WebMediaKeySystemConfiguration config
;
647 config
.hasVideoCapabilities
= true;
648 config
.videoCapabilities
= video_capabilities
;
649 configs_
.push_back(config
);
651 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
652 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
653 config_
.distinctiveIdentifier
);
656 TEST_F(KeySystemConfigSelectorTest
,
657 VideoCapabilities_Robustness_PermissionCanBeRecommended
) {
658 media_permission_
->is_granted
= false;
659 key_systems_
->distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
661 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
662 video_capabilities
[0].contentType
= "a";
663 video_capabilities
[0].mimeType
= kSupportedContainer
;
664 video_capabilities
[0].robustness
= kRecommendIdentifier
;
666 blink::WebMediaKeySystemConfiguration config
;
667 config
.hasVideoCapabilities
= true;
668 config
.videoCapabilities
= video_capabilities
;
669 configs_
.push_back(config
);
671 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
672 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
673 config_
.distinctiveIdentifier
);
676 // --- audioCapabilities ---
677 // These are handled by the same code as |videoCapabilities|, so only minimal
678 // additional testing is done.
680 TEST_F(KeySystemConfigSelectorTest
, AudioCapabilities_SubsetSupported
) {
681 std::vector
<blink::WebMediaKeySystemMediaCapability
> audio_capabilities(2);
682 audio_capabilities
[0].contentType
= "a";
683 audio_capabilities
[0].mimeType
= kUnsupportedContainer
;
684 audio_capabilities
[1].contentType
= "b";
685 audio_capabilities
[1].mimeType
= kSupportedContainer
;
687 blink::WebMediaKeySystemConfiguration config
;
688 config
.hasAudioCapabilities
= true;
689 config
.audioCapabilities
= audio_capabilities
;
690 configs_
.push_back(config
);
692 ASSERT_TRUE(SelectConfigReturnsConfig());
693 ASSERT_EQ(1u, config_
.audioCapabilities
.size());
694 EXPECT_EQ("b", config_
.audioCapabilities
[0].contentType
);
695 EXPECT_EQ(kSupportedContainer
, config_
.audioCapabilities
[0].mimeType
);
698 // --- Multiple configurations ---
700 TEST_F(KeySystemConfigSelectorTest
, Configurations_AllSupported
) {
701 blink::WebMediaKeySystemConfiguration config
;
703 configs_
.push_back(config
);
705 configs_
.push_back(config
);
707 ASSERT_TRUE(SelectConfigReturnsConfig());
708 ASSERT_EQ("a", config_
.label
);
711 TEST_F(KeySystemConfigSelectorTest
, Configurations_SubsetSupported
) {
712 blink::WebMediaKeySystemConfiguration config1
;
714 config1
.hasInitDataTypes
= true;
715 configs_
.push_back(config1
);
717 blink::WebMediaKeySystemConfiguration config2
;
719 configs_
.push_back(config2
);
721 ASSERT_TRUE(SelectConfigReturnsConfig());
722 ASSERT_EQ("b", config_
.label
);
725 TEST_F(KeySystemConfigSelectorTest
,
726 Configurations_FirstRequiresPermission_Allowed
) {
727 media_permission_
->is_granted
= true;
728 key_systems_
->distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
730 blink::WebMediaKeySystemConfiguration config1
;
732 config1
.distinctiveIdentifier
=
733 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
734 configs_
.push_back(config1
);
736 blink::WebMediaKeySystemConfiguration config2
;
738 configs_
.push_back(config2
);
740 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
741 ASSERT_EQ("a", config_
.label
);
744 TEST_F(KeySystemConfigSelectorTest
,
745 Configurations_FirstRequiresPermission_Rejected
) {
746 media_permission_
->is_granted
= false;
747 key_systems_
->distinctive_identifier
= EME_FEATURE_REQUESTABLE
;
749 blink::WebMediaKeySystemConfiguration config1
;
751 config1
.distinctiveIdentifier
=
752 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
753 configs_
.push_back(config1
);
755 blink::WebMediaKeySystemConfiguration config2
;
757 configs_
.push_back(config2
);
759 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
760 ASSERT_EQ("b", config_
.label
);