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
= EmeSessionTypeSupport::INVALID
;
128 EmeSessionTypeSupport persistent_release_message
=
129 EmeSessionTypeSupport::INVALID
;
131 // Every test implicitly requires these, so they must be set. They are set to
132 // values that are likely to cause tests to fail if they are accidentally
133 // depended on. Test cases explicitly depending on them should set them, as
134 // the default values may be changed.
135 EmeFeatureSupport persistent_state
= EmeFeatureSupport::NOT_SUPPORTED
;
136 EmeFeatureSupport distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
139 class FakeMediaPermission
: public MediaPermission
{
141 void HasPermission(Type type
,
142 const GURL
& security_origin
,
143 const PermissionStatusCB
& permission_status_cb
) override
{
144 permission_status_cb
.Run(is_granted
);
147 void RequestPermission(
149 const GURL
& security_origin
,
150 const PermissionStatusCB
& permission_status_cb
) override
{
152 permission_status_cb
.Run(is_granted
);
156 bool is_granted
= false;
161 class KeySystemConfigSelectorTest
: public testing::Test
{
163 KeySystemConfigSelectorTest()
164 : key_systems_(new FakeKeySystems()),
165 media_permission_(new FakeMediaPermission()) {}
167 void SelectConfig() {
168 media_permission_
->requests
= 0;
169 succeeded_count_
= 0;
170 not_supported_count_
= 0;
171 KeySystemConfigSelector(key_systems_
.get(), media_permission_
.get())
172 .SelectConfig(key_system_
, configs_
, security_origin_
,
173 base::Bind(&KeySystemConfigSelectorTest::OnSucceeded
,
174 base::Unretained(this)),
175 base::Bind(&KeySystemConfigSelectorTest::OnNotSupported
,
176 base::Unretained(this)));
179 bool SelectConfigReturnsConfig() {
181 EXPECT_EQ(0, media_permission_
->requests
);
182 EXPECT_EQ(1, succeeded_count_
);
183 EXPECT_EQ(0, not_supported_count_
);
184 return (succeeded_count_
!= 0);
187 bool SelectConfigReturnsError() {
189 EXPECT_EQ(0, media_permission_
->requests
);
190 EXPECT_EQ(0, succeeded_count_
);
191 EXPECT_EQ(1, not_supported_count_
);
192 return (not_supported_count_
!= 0);
195 bool SelectConfigRequestsPermissionAndReturnsConfig() {
197 EXPECT_EQ(1, media_permission_
->requests
);
198 EXPECT_EQ(1, succeeded_count_
);
199 EXPECT_EQ(0, not_supported_count_
);
200 return (media_permission_
->requests
!= 0 && succeeded_count_
!= 0);
203 bool SelectConfigRequestsPermissionAndReturnsError() {
205 EXPECT_EQ(1, media_permission_
->requests
);
206 EXPECT_EQ(0, succeeded_count_
);
207 EXPECT_EQ(1, not_supported_count_
);
208 return (media_permission_
->requests
!= 0 && not_supported_count_
!= 0);
211 void OnSucceeded(const blink::WebMediaKeySystemConfiguration
& result
) {
216 void OnNotSupported(const blink::WebString
&) { not_supported_count_
++; }
218 scoped_ptr
<FakeKeySystems
> key_systems_
;
219 scoped_ptr
<FakeMediaPermission
> media_permission_
;
221 // Held values for the call to SelectConfig().
222 blink::WebString key_system_
= blink::WebString::fromUTF8(kSupported
);
223 std::vector
<blink::WebMediaKeySystemConfiguration
> configs_
;
224 blink::WebSecurityOrigin security_origin_
=
225 blink::WebSecurityOrigin::createFromString(kDefaultSecurityOrigin
);
227 // Holds the last successful accumulated configuration.
228 blink::WebMediaKeySystemConfiguration config_
;
230 int succeeded_count_
;
231 int not_supported_count_
;
233 DISALLOW_COPY_AND_ASSIGN(KeySystemConfigSelectorTest
);
238 TEST_F(KeySystemConfigSelectorTest
, NoConfigs
) {
239 ASSERT_TRUE(SelectConfigReturnsError());
242 // Most of the tests below assume that an empty config is valid.
243 TEST_F(KeySystemConfigSelectorTest
, EmptyConfig
) {
244 configs_
.push_back(blink::WebMediaKeySystemConfiguration());
246 ASSERT_TRUE(SelectConfigReturnsConfig());
247 EXPECT_TRUE(config_
.label
.isNull());
248 EXPECT_TRUE(config_
.initDataTypes
.isEmpty());
249 EXPECT_TRUE(config_
.audioCapabilities
.isEmpty());
250 EXPECT_TRUE(config_
.videoCapabilities
.isEmpty());
251 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
252 config_
.distinctiveIdentifier
);
253 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
254 config_
.persistentState
);
255 ASSERT_EQ(1u, config_
.sessionTypes
.size());
256 EXPECT_EQ(blink::WebEncryptedMediaSessionType::Temporary
,
257 config_
.sessionTypes
[0]);
260 TEST_F(KeySystemConfigSelectorTest
, Label
) {
261 blink::WebMediaKeySystemConfiguration config
;
262 config
.label
= "foo";
263 configs_
.push_back(config
);
265 ASSERT_TRUE(SelectConfigReturnsConfig());
266 EXPECT_EQ("foo", config_
.label
);
270 // Empty is not tested because the empty check is in Blink.
272 TEST_F(KeySystemConfigSelectorTest
, KeySystem_NonAscii
) {
273 key_system_
= "\xde\xad\xbe\xef";
274 configs_
.push_back(blink::WebMediaKeySystemConfiguration());
275 ASSERT_TRUE(SelectConfigReturnsError());
278 TEST_F(KeySystemConfigSelectorTest
, KeySystem_Unsupported
) {
279 key_system_
= kUnsupported
;
280 configs_
.push_back(blink::WebMediaKeySystemConfiguration());
281 ASSERT_TRUE(SelectConfigReturnsError());
284 // --- initDataTypes ---
286 TEST_F(KeySystemConfigSelectorTest
, InitDataTypes_Empty
) {
287 blink::WebMediaKeySystemConfiguration config
;
288 config
.hasInitDataTypes
= true;
289 configs_
.push_back(config
);
291 ASSERT_TRUE(SelectConfigReturnsError());
294 TEST_F(KeySystemConfigSelectorTest
, InitDataTypes_NoneSupported
) {
295 key_systems_
->init_data_types
= kInitDataTypeMaskWebM
;
297 std::vector
<blink::WebEncryptedMediaInitDataType
> init_data_types
;
298 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Unknown
);
299 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Cenc
);
301 blink::WebMediaKeySystemConfiguration config
;
302 config
.hasInitDataTypes
= true;
303 config
.initDataTypes
= init_data_types
;
304 configs_
.push_back(config
);
306 ASSERT_TRUE(SelectConfigReturnsError());
309 TEST_F(KeySystemConfigSelectorTest
, InitDataTypes_SubsetSupported
) {
310 key_systems_
->init_data_types
= kInitDataTypeMaskWebM
;
312 std::vector
<blink::WebEncryptedMediaInitDataType
> init_data_types
;
313 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Unknown
);
314 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Cenc
);
315 init_data_types
.push_back(blink::WebEncryptedMediaInitDataType::Webm
);
317 blink::WebMediaKeySystemConfiguration config
;
318 config
.hasInitDataTypes
= true;
319 config
.initDataTypes
= init_data_types
;
320 configs_
.push_back(config
);
322 ASSERT_TRUE(SelectConfigReturnsConfig());
323 ASSERT_EQ(1u, config_
.initDataTypes
.size());
324 EXPECT_EQ(blink::WebEncryptedMediaInitDataType::Webm
,
325 config_
.initDataTypes
[0]);
328 // --- distinctiveIdentifier ---
330 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_Default
) {
331 key_systems_
->distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
333 blink::WebMediaKeySystemConfiguration config
;
334 config
.distinctiveIdentifier
=
335 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
336 configs_
.push_back(config
);
338 ASSERT_TRUE(SelectConfigReturnsConfig());
339 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
340 config_
.distinctiveIdentifier
);
343 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_Forced
) {
344 media_permission_
->is_granted
= true;
345 key_systems_
->distinctive_identifier
= EmeFeatureSupport::ALWAYS_ENABLED
;
347 blink::WebMediaKeySystemConfiguration config
;
348 config
.distinctiveIdentifier
=
349 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
350 configs_
.push_back(config
);
352 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
353 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
354 config_
.distinctiveIdentifier
);
357 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_Blocked
) {
358 key_systems_
->distinctive_identifier
= EmeFeatureSupport::NOT_SUPPORTED
;
360 blink::WebMediaKeySystemConfiguration config
;
361 config
.distinctiveIdentifier
=
362 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
363 configs_
.push_back(config
);
365 ASSERT_TRUE(SelectConfigReturnsError());
368 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_RequestsPermission
) {
369 media_permission_
->is_granted
= true;
370 key_systems_
->distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
372 blink::WebMediaKeySystemConfiguration config
;
373 config
.distinctiveIdentifier
=
374 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
375 configs_
.push_back(config
);
377 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
378 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
379 config_
.distinctiveIdentifier
);
382 TEST_F(KeySystemConfigSelectorTest
, DistinctiveIdentifier_RespectsPermission
) {
383 media_permission_
->is_granted
= false;
384 key_systems_
->distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
386 blink::WebMediaKeySystemConfiguration config
;
387 config
.distinctiveIdentifier
=
388 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
389 configs_
.push_back(config
);
391 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsError());
394 // --- persistentState ---
396 TEST_F(KeySystemConfigSelectorTest
, PersistentState_Default
) {
397 key_systems_
->persistent_state
= EmeFeatureSupport::REQUESTABLE
;
399 blink::WebMediaKeySystemConfiguration config
;
400 config
.persistentState
=
401 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
402 configs_
.push_back(config
);
404 ASSERT_TRUE(SelectConfigReturnsConfig());
405 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
406 config_
.persistentState
);
409 TEST_F(KeySystemConfigSelectorTest
, PersistentState_Forced
) {
410 key_systems_
->persistent_state
= EmeFeatureSupport::ALWAYS_ENABLED
;
412 blink::WebMediaKeySystemConfiguration config
;
413 config
.persistentState
=
414 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
415 configs_
.push_back(config
);
417 ASSERT_TRUE(SelectConfigReturnsConfig());
418 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
419 config_
.persistentState
);
422 TEST_F(KeySystemConfigSelectorTest
, PersistentState_Blocked
) {
423 key_systems_
->persistent_state
= EmeFeatureSupport::ALWAYS_ENABLED
;
425 blink::WebMediaKeySystemConfiguration config
;
426 config
.persistentState
=
427 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
;
428 configs_
.push_back(config
);
430 ASSERT_TRUE(SelectConfigReturnsError());
433 // --- sessionTypes ---
435 TEST_F(KeySystemConfigSelectorTest
, SessionTypes_Empty
) {
436 blink::WebMediaKeySystemConfiguration config
;
437 config
.hasSessionTypes
= true;
438 configs_
.push_back(config
);
440 ASSERT_TRUE(SelectConfigReturnsConfig());
441 EXPECT_TRUE(config_
.sessionTypes
.isEmpty());
444 TEST_F(KeySystemConfigSelectorTest
, SessionTypes_SubsetSupported
) {
445 // Allow persistent state, as it would be required to be successful.
446 key_systems_
->persistent_state
= EmeFeatureSupport::REQUESTABLE
;
447 key_systems_
->persistent_license
= EmeSessionTypeSupport::NOT_SUPPORTED
;
449 std::vector
<blink::WebEncryptedMediaSessionType
> session_types
;
450 session_types
.push_back(blink::WebEncryptedMediaSessionType::Temporary
);
451 session_types
.push_back(
452 blink::WebEncryptedMediaSessionType::PersistentLicense
);
454 blink::WebMediaKeySystemConfiguration config
;
455 config
.hasSessionTypes
= true;
456 config
.sessionTypes
= session_types
;
457 configs_
.push_back(config
);
459 ASSERT_TRUE(SelectConfigReturnsError());
462 TEST_F(KeySystemConfigSelectorTest
, SessionTypes_AllSupported
) {
463 // Allow persistent state, and expect it to be required.
464 key_systems_
->persistent_state
= EmeFeatureSupport::REQUESTABLE
;
465 key_systems_
->persistent_license
= EmeSessionTypeSupport::SUPPORTED
;
467 std::vector
<blink::WebEncryptedMediaSessionType
> session_types
;
468 session_types
.push_back(blink::WebEncryptedMediaSessionType::Temporary
);
469 session_types
.push_back(
470 blink::WebEncryptedMediaSessionType::PersistentLicense
);
472 blink::WebMediaKeySystemConfiguration config
;
473 config
.persistentState
=
474 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
475 config
.hasSessionTypes
= true;
476 config
.sessionTypes
= session_types
;
477 configs_
.push_back(config
);
479 ASSERT_TRUE(SelectConfigReturnsConfig());
480 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
481 config_
.persistentState
);
482 ASSERT_EQ(2u, config_
.sessionTypes
.size());
483 EXPECT_EQ(blink::WebEncryptedMediaSessionType::Temporary
,
484 config_
.sessionTypes
[0]);
485 EXPECT_EQ(blink::WebEncryptedMediaSessionType::PersistentLicense
,
486 config_
.sessionTypes
[1]);
489 TEST_F(KeySystemConfigSelectorTest
, SessionTypes_PermissionCanBeRequired
) {
490 media_permission_
->is_granted
= true;
491 key_systems_
->distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
492 key_systems_
->persistent_state
= EmeFeatureSupport::REQUESTABLE
;
493 key_systems_
->persistent_license
=
494 EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER
;
496 std::vector
<blink::WebEncryptedMediaSessionType
> session_types
;
497 session_types
.push_back(
498 blink::WebEncryptedMediaSessionType::PersistentLicense
);
500 blink::WebMediaKeySystemConfiguration config
;
501 config
.distinctiveIdentifier
=
502 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
503 config
.persistentState
=
504 blink::WebMediaKeySystemConfiguration::Requirement::Optional
;
505 config
.hasSessionTypes
= true;
506 config
.sessionTypes
= session_types
;
507 configs_
.push_back(config
);
509 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
510 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
511 config_
.distinctiveIdentifier
);
514 // --- videoCapabilities ---
516 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_Empty
) {
517 blink::WebMediaKeySystemConfiguration config
;
518 config
.hasVideoCapabilities
= true;
519 configs_
.push_back(config
);
521 ASSERT_TRUE(SelectConfigReturnsError());
524 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_NoneSupported
) {
525 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(2);
526 video_capabilities
[0].contentType
= "a";
527 video_capabilities
[0].mimeType
= kUnsupportedContainer
;
528 video_capabilities
[1].contentType
= "b";
529 video_capabilities
[1].mimeType
= kSupportedContainer
;
530 video_capabilities
[1].codecs
= kUnsupportedCodec
;
532 blink::WebMediaKeySystemConfiguration config
;
533 config
.hasVideoCapabilities
= true;
534 config
.videoCapabilities
= video_capabilities
;
535 configs_
.push_back(config
);
537 ASSERT_TRUE(SelectConfigReturnsError());
540 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_SubsetSupported
) {
541 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(2);
542 video_capabilities
[0].contentType
= "a";
543 video_capabilities
[0].mimeType
= kUnsupportedContainer
;
544 video_capabilities
[1].contentType
= "b";
545 video_capabilities
[1].mimeType
= kSupportedContainer
;
547 blink::WebMediaKeySystemConfiguration config
;
548 config
.hasVideoCapabilities
= true;
549 config
.videoCapabilities
= video_capabilities
;
550 configs_
.push_back(config
);
552 ASSERT_TRUE(SelectConfigReturnsConfig());
553 ASSERT_EQ(1u, config_
.videoCapabilities
.size());
554 EXPECT_EQ("b", config_
.videoCapabilities
[0].contentType
);
555 EXPECT_EQ(kSupportedContainer
, config_
.videoCapabilities
[0].mimeType
);
558 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_AllSupported
) {
559 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(2);
560 video_capabilities
[0].contentType
= "a";
561 video_capabilities
[0].mimeType
= kSupportedContainer
;
562 video_capabilities
[1].contentType
= "b";
563 video_capabilities
[1].mimeType
= kSupportedContainer
;
564 video_capabilities
[1].codecs
= kSupportedCodecs
;
566 blink::WebMediaKeySystemConfiguration config
;
567 config
.hasVideoCapabilities
= true;
568 config
.videoCapabilities
= video_capabilities
;
569 configs_
.push_back(config
);
571 ASSERT_TRUE(SelectConfigReturnsConfig());
572 ASSERT_EQ(2u, config_
.videoCapabilities
.size());
573 EXPECT_EQ("a", config_
.videoCapabilities
[0].contentType
);
574 EXPECT_EQ("b", config_
.videoCapabilities
[1].contentType
);
577 TEST_F(KeySystemConfigSelectorTest
,
578 VideoCapabilities_Codecs_SubsetSupported
) {
579 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
580 video_capabilities
[0].contentType
= "a";
581 video_capabilities
[0].mimeType
= kSupportedContainer
;
582 video_capabilities
[0].codecs
= kUnsupportedCodecs
;
584 blink::WebMediaKeySystemConfiguration config
;
585 config
.hasVideoCapabilities
= true;
586 config
.videoCapabilities
= video_capabilities
;
587 configs_
.push_back(config
);
589 ASSERT_TRUE(SelectConfigReturnsError());
592 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_Codecs_AllSupported
) {
593 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
594 video_capabilities
[0].contentType
= "a";
595 video_capabilities
[0].mimeType
= kSupportedContainer
;
596 video_capabilities
[0].codecs
= kSupportedCodecs
;
598 blink::WebMediaKeySystemConfiguration config
;
599 config
.hasVideoCapabilities
= true;
600 config
.videoCapabilities
= video_capabilities
;
601 configs_
.push_back(config
);
603 ASSERT_TRUE(SelectConfigReturnsConfig());
604 ASSERT_EQ(1u, config_
.videoCapabilities
.size());
605 EXPECT_EQ(kSupportedCodecs
, config_
.videoCapabilities
[0].codecs
);
608 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_Robustness_Supported
) {
609 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
610 video_capabilities
[0].contentType
= "a";
611 video_capabilities
[0].mimeType
= kSupportedContainer
;
612 video_capabilities
[0].robustness
= kSupported
;
614 blink::WebMediaKeySystemConfiguration config
;
615 config
.hasVideoCapabilities
= true;
616 config
.videoCapabilities
= video_capabilities
;
617 configs_
.push_back(config
);
619 ASSERT_TRUE(SelectConfigReturnsConfig());
620 ASSERT_EQ(1u, config_
.videoCapabilities
.size());
621 EXPECT_EQ(kSupported
, config_
.videoCapabilities
[0].robustness
);
624 TEST_F(KeySystemConfigSelectorTest
, VideoCapabilities_Robustness_Unsupported
) {
625 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
626 video_capabilities
[0].contentType
= "a";
627 video_capabilities
[0].mimeType
= kSupportedContainer
;
628 video_capabilities
[0].robustness
= kUnsupported
;
630 blink::WebMediaKeySystemConfiguration config
;
631 config
.hasVideoCapabilities
= true;
632 config
.videoCapabilities
= video_capabilities
;
633 configs_
.push_back(config
);
635 ASSERT_TRUE(SelectConfigReturnsError());
638 TEST_F(KeySystemConfigSelectorTest
,
639 VideoCapabilities_Robustness_PermissionCanBeRequired
) {
640 media_permission_
->is_granted
= true;
641 key_systems_
->distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
643 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
644 video_capabilities
[0].contentType
= "a";
645 video_capabilities
[0].mimeType
= kSupportedContainer
;
646 video_capabilities
[0].robustness
= kRequireIdentifier
;
648 blink::WebMediaKeySystemConfiguration config
;
649 config
.hasVideoCapabilities
= true;
650 config
.videoCapabilities
= video_capabilities
;
651 configs_
.push_back(config
);
653 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
654 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required
,
655 config_
.distinctiveIdentifier
);
658 TEST_F(KeySystemConfigSelectorTest
,
659 VideoCapabilities_Robustness_PermissionCanBeRecommended
) {
660 media_permission_
->is_granted
= false;
661 key_systems_
->distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
663 std::vector
<blink::WebMediaKeySystemMediaCapability
> video_capabilities(1);
664 video_capabilities
[0].contentType
= "a";
665 video_capabilities
[0].mimeType
= kSupportedContainer
;
666 video_capabilities
[0].robustness
= kRecommendIdentifier
;
668 blink::WebMediaKeySystemConfiguration config
;
669 config
.hasVideoCapabilities
= true;
670 config
.videoCapabilities
= video_capabilities
;
671 configs_
.push_back(config
);
673 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
674 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed
,
675 config_
.distinctiveIdentifier
);
678 // --- audioCapabilities ---
679 // These are handled by the same code as |videoCapabilities|, so only minimal
680 // additional testing is done.
682 TEST_F(KeySystemConfigSelectorTest
, AudioCapabilities_SubsetSupported
) {
683 std::vector
<blink::WebMediaKeySystemMediaCapability
> audio_capabilities(2);
684 audio_capabilities
[0].contentType
= "a";
685 audio_capabilities
[0].mimeType
= kUnsupportedContainer
;
686 audio_capabilities
[1].contentType
= "b";
687 audio_capabilities
[1].mimeType
= kSupportedContainer
;
689 blink::WebMediaKeySystemConfiguration config
;
690 config
.hasAudioCapabilities
= true;
691 config
.audioCapabilities
= audio_capabilities
;
692 configs_
.push_back(config
);
694 ASSERT_TRUE(SelectConfigReturnsConfig());
695 ASSERT_EQ(1u, config_
.audioCapabilities
.size());
696 EXPECT_EQ("b", config_
.audioCapabilities
[0].contentType
);
697 EXPECT_EQ(kSupportedContainer
, config_
.audioCapabilities
[0].mimeType
);
700 // --- Multiple configurations ---
702 TEST_F(KeySystemConfigSelectorTest
, Configurations_AllSupported
) {
703 blink::WebMediaKeySystemConfiguration config
;
705 configs_
.push_back(config
);
707 configs_
.push_back(config
);
709 ASSERT_TRUE(SelectConfigReturnsConfig());
710 ASSERT_EQ("a", config_
.label
);
713 TEST_F(KeySystemConfigSelectorTest
, Configurations_SubsetSupported
) {
714 blink::WebMediaKeySystemConfiguration config1
;
716 config1
.hasInitDataTypes
= true;
717 configs_
.push_back(config1
);
719 blink::WebMediaKeySystemConfiguration config2
;
721 configs_
.push_back(config2
);
723 ASSERT_TRUE(SelectConfigReturnsConfig());
724 ASSERT_EQ("b", config_
.label
);
727 TEST_F(KeySystemConfigSelectorTest
,
728 Configurations_FirstRequiresPermission_Allowed
) {
729 media_permission_
->is_granted
= true;
730 key_systems_
->distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
732 blink::WebMediaKeySystemConfiguration config1
;
734 config1
.distinctiveIdentifier
=
735 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
736 configs_
.push_back(config1
);
738 blink::WebMediaKeySystemConfiguration config2
;
740 configs_
.push_back(config2
);
742 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
743 ASSERT_EQ("a", config_
.label
);
746 TEST_F(KeySystemConfigSelectorTest
,
747 Configurations_FirstRequiresPermission_Rejected
) {
748 media_permission_
->is_granted
= false;
749 key_systems_
->distinctive_identifier
= EmeFeatureSupport::REQUESTABLE
;
751 blink::WebMediaKeySystemConfiguration config1
;
753 config1
.distinctiveIdentifier
=
754 blink::WebMediaKeySystemConfiguration::Requirement::Required
;
755 configs_
.push_back(config1
);
757 blink::WebMediaKeySystemConfiguration config2
;
759 configs_
.push_back(config2
);
761 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
762 ASSERT_EQ("b", config_
.label
);