1 // Copyright 2013 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.
5 // TODO(sandersd): Refactor to remove recomputed codec arrays, and generally
6 // shorten and improve coverage.
7 // - http://crbug.com/417444
8 // - http://crbug.com/457438
9 // TODO(sandersd): Add tests to cover codec vectors with empty items.
10 // http://crbug.com/417461
15 #include "base/logging.h"
16 #include "media/base/eme_constants.h"
17 #include "media/base/key_system_info.h"
18 #include "media/base/key_systems.h"
19 #include "media/base/media_client.h"
20 #include "testing/gtest/include/gtest/gtest.h"
22 // Death tests are not always available, including on Android.
23 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that
24 // death tests are not available and NDEBUG is not defined.
25 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
26 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
27 EXPECT_DEBUG_DEATH(statement, regex)
30 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
31 do { statement; } while (false)
33 #include "base/logging.h"
34 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
35 LOG(WARNING) << "Death tests are not supported on this platform.\n" \
36 << "Statement '" #statement "' cannot be verified.";
37 #endif // defined(NDEBUG)
38 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
42 // These are the (fake) key systems that are registered for these tests.
43 // kUsesAes uses the AesDecryptor like Clear Key.
44 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
45 const char kUsesAes
[] = "x-org.example.clear";
46 const char kUsesAesParent
[] = "x-org.example"; // Not registered.
47 const char kUseAesNameForUMA
[] = "UseAes";
48 const char kExternal
[] = "x-com.example.test";
49 const char kExternalParent
[] = "x-com.example";
50 const char kExternalNameForUMA
[] = "External";
52 const char kClearKey
[] = "org.w3.clearkey";
53 const char kPrefixedClearKey
[] = "webkit-org.w3.clearkey";
54 const char kExternalClearKey
[] = "org.chromium.externalclearkey";
56 const char kAudioWebM
[] = "audio/webm";
57 const char kVideoWebM
[] = "video/webm";
58 const char kAudioFoo
[] = "audio/foo";
59 const char kVideoFoo
[] = "video/foo";
61 // Pick some arbitrary bit fields as long as they are not in conflict with the
64 TEST_CODEC_FOO_AUDIO
= 1 << 10, // An audio codec for foo container.
65 TEST_CODEC_FOO_AUDIO_ALL
= TEST_CODEC_FOO_AUDIO
,
66 TEST_CODEC_FOO_VIDEO
= 1 << 11, // A video codec for foo container.
67 TEST_CODEC_FOO_VIDEO_ALL
= TEST_CODEC_FOO_VIDEO
,
68 TEST_CODEC_FOO_ALL
= TEST_CODEC_FOO_AUDIO_ALL
| TEST_CODEC_FOO_VIDEO_ALL
71 static_assert((TEST_CODEC_FOO_ALL
& EME_CODEC_ALL
) == EME_CODEC_NONE
,
72 "test codec masks should only use invalid codec masks");
74 // Adapt IsSupportedKeySystemWithMediaMimeType() to the new API,
75 // IsSupportedCodecCombination().
76 static bool IsSupportedKeySystemWithMediaMimeType(
77 const std::string
& mime_type
,
78 const std::vector
<std::string
>& codecs
,
79 const std::string
& key_system
) {
80 return (KeySystems::GetInstance()->GetContentTypeConfigRule(
81 key_system
, EmeMediaType::VIDEO
, mime_type
, codecs
) !=
82 EmeConfigRule::NOT_SUPPORTED
);
85 static bool IsSupportedKeySystemWithAudioMimeType(
86 const std::string
& mime_type
,
87 const std::vector
<std::string
>& codecs
,
88 const std::string
& key_system
) {
89 return (KeySystems::GetInstance()->GetContentTypeConfigRule(
90 key_system
, EmeMediaType::AUDIO
, mime_type
, codecs
) !=
91 EmeConfigRule::NOT_SUPPORTED
);
94 // Adds test container and codec masks.
95 // This function must be called after SetMediaClient() if a MediaClient will be
97 // More details: AddXxxMask() will create KeySystems if it hasn't been created.
98 // During KeySystems's construction GetMediaClient() will be used to add key
99 // systems. In test code, the MediaClient is set by SetMediaClient().
100 // Therefore, SetMediaClient() must be called before this function to make sure
101 // MediaClient in effect when constructing KeySystems.
102 static void AddContainerAndCodecMasksForTest() {
103 // Since KeySystems is a singleton. Make sure we only add test container and
104 // codec masks once per process.
105 static bool is_test_masks_added
= false;
107 if (is_test_masks_added
)
110 AddContainerMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL
);
111 AddContainerMask("video/foo", TEST_CODEC_FOO_ALL
);
112 AddCodecMask(EmeMediaType::AUDIO
, "fooaudio", TEST_CODEC_FOO_AUDIO
);
113 AddCodecMask(EmeMediaType::VIDEO
, "foovideo", TEST_CODEC_FOO_VIDEO
);
115 is_test_masks_added
= true;
118 class TestMediaClient
: public MediaClient
{
121 ~TestMediaClient() override
;
123 // MediaClient implementation.
124 void AddKeySystemsInfoForUMA(
125 std::vector
<KeySystemInfoForUMA
>* key_systems_info_for_uma
) final
;
126 bool IsKeySystemsUpdateNeeded() final
;
127 void AddSupportedKeySystems(
128 std::vector
<KeySystemInfo
>* key_systems_info
) override
;
130 // Helper function to test the case where IsKeySystemsUpdateNeeded() is true
131 // after AddSupportedKeySystems() is called.
132 void SetKeySystemsUpdateNeeded();
134 // Helper function to disable "kExternal" key system support so that we can
135 // test the key system update case.
136 void DisableExternalKeySystemSupport();
139 void AddUsesAesKeySystem(const std::string
& name
,
140 std::vector
<KeySystemInfo
>* key_systems_info
);
141 void AddExternalKeySystem(
142 std::vector
<KeySystemInfo
>* key_systems_info
);
145 bool is_update_needed_
;
146 bool supports_external_key_system_
;
149 TestMediaClient::TestMediaClient()
150 : is_update_needed_(true), supports_external_key_system_(true) {
153 TestMediaClient::~TestMediaClient() {
156 void TestMediaClient::AddKeySystemsInfoForUMA(
157 std::vector
<KeySystemInfoForUMA
>* key_systems_info_for_uma
) {
158 key_systems_info_for_uma
->push_back(
159 media::KeySystemInfoForUMA(kUsesAes
, kUseAesNameForUMA
, false));
160 key_systems_info_for_uma
->push_back(
161 media::KeySystemInfoForUMA(kExternal
, kExternalNameForUMA
, true));
164 bool TestMediaClient::IsKeySystemsUpdateNeeded() {
165 return is_update_needed_
;
168 void TestMediaClient::AddSupportedKeySystems(
169 std::vector
<KeySystemInfo
>* key_systems
) {
170 DCHECK(is_update_needed_
);
172 AddUsesAesKeySystem(kUsesAes
, key_systems
);
174 if (supports_external_key_system_
)
175 AddExternalKeySystem(key_systems
);
177 is_update_needed_
= false;
180 void TestMediaClient::SetKeySystemsUpdateNeeded() {
181 is_update_needed_
= true;
184 void TestMediaClient::DisableExternalKeySystemSupport() {
185 supports_external_key_system_
= false;
188 void TestMediaClient::AddUsesAesKeySystem(
189 const std::string
& name
,
190 std::vector
<KeySystemInfo
>* key_systems
) {
191 KeySystemInfo system
;
192 system
.key_system
= name
;
193 system
.supported_codecs
= EME_CODEC_WEBM_ALL
;
194 system
.supported_codecs
|= TEST_CODEC_FOO_ALL
;
195 system
.supported_init_data_types
= kInitDataTypeMaskWebM
;
196 system
.max_audio_robustness
= EmeRobustness::EMPTY
;
197 system
.max_video_robustness
= EmeRobustness::EMPTY
;
198 system
.persistent_license_support
= EmeSessionTypeSupport::NOT_SUPPORTED
;
199 system
.persistent_release_message_support
=
200 EmeSessionTypeSupport::NOT_SUPPORTED
;
201 system
.persistent_state_support
= EmeFeatureSupport::NOT_SUPPORTED
;
202 system
.distinctive_identifier_support
= EmeFeatureSupport::NOT_SUPPORTED
;
203 system
.use_aes_decryptor
= true;
204 key_systems
->push_back(system
);
207 void TestMediaClient::AddExternalKeySystem(
208 std::vector
<KeySystemInfo
>* key_systems
) {
210 ext
.key_system
= kExternal
;
211 ext
.supported_codecs
= EME_CODEC_WEBM_ALL
;
212 ext
.supported_codecs
|= TEST_CODEC_FOO_ALL
;
213 ext
.supported_init_data_types
= kInitDataTypeMaskWebM
;
214 ext
.max_audio_robustness
= EmeRobustness::EMPTY
;
215 ext
.max_video_robustness
= EmeRobustness::EMPTY
;
216 ext
.persistent_license_support
= EmeSessionTypeSupport::SUPPORTED
;
217 ext
.persistent_release_message_support
= EmeSessionTypeSupport::NOT_SUPPORTED
;
218 ext
.persistent_state_support
= EmeFeatureSupport::ALWAYS_ENABLED
;
219 ext
.distinctive_identifier_support
= EmeFeatureSupport::ALWAYS_ENABLED
;
220 ext
.parent_key_system
= kExternalParent
;
221 #if defined(ENABLE_PEPPER_CDMS)
222 ext
.pepper_type
= "application/x-ppapi-external-cdm";
223 #endif // defined(ENABLE_PEPPER_CDMS)
224 key_systems
->push_back(ext
);
227 class PotentiallySupportedNamesTestMediaClient
: public TestMediaClient
{
228 void AddSupportedKeySystems(
229 std::vector
<KeySystemInfo
>* key_systems_info
) final
;
232 void PotentiallySupportedNamesTestMediaClient::AddSupportedKeySystems(
233 std::vector
<KeySystemInfo
>* key_systems
) {
234 // org.w3.clearkey is automatically registered.
235 AddUsesAesKeySystem("com.widevine.alpha", key_systems
);
236 AddUsesAesKeySystem("org.chromium.externalclearkey", key_systems
);
237 AddUsesAesKeySystem("org.chromium.externalclearkey.something", key_systems
);
238 AddUsesAesKeySystem("com.chromecast.something", key_systems
);
239 AddUsesAesKeySystem("x-something", key_systems
);
242 class KeySystemsPotentiallySupportedNamesTest
: public testing::Test
{
244 KeySystemsPotentiallySupportedNamesTest() {
245 SetMediaClient(&test_media_client_
);
248 ~KeySystemsPotentiallySupportedNamesTest() override
{
249 // Clear the use of |test_media_client_|, which was set in SetUp().
250 SetMediaClient(nullptr);
254 PotentiallySupportedNamesTestMediaClient test_media_client_
;
257 class KeySystemsTest
: public testing::Test
{
260 vp8_codec_
.push_back("vp8");
262 vp80_codec_
.push_back("vp8.0");
264 vp9_codec_
.push_back("vp9");
266 vp90_codec_
.push_back("vp9.0");
268 vorbis_codec_
.push_back("vorbis");
270 vp8_and_vorbis_codecs_
.push_back("vp8");
271 vp8_and_vorbis_codecs_
.push_back("vorbis");
273 vp9_and_vorbis_codecs_
.push_back("vp9");
274 vp9_and_vorbis_codecs_
.push_back("vorbis");
276 foovideo_codec_
.push_back("foovideo");
278 foovideo_extended_codec_
.push_back("foovideo.4D400C");
280 foovideo_dot_codec_
.push_back("foovideo.");
282 fooaudio_codec_
.push_back("fooaudio");
284 foovideo_and_fooaudio_codecs_
.push_back("foovideo");
285 foovideo_and_fooaudio_codecs_
.push_back("fooaudio");
287 unknown_codec_
.push_back("unknown");
289 mixed_codecs_
.push_back("vorbis");
290 mixed_codecs_
.push_back("foovideo");
292 SetMediaClient(&test_media_client_
);
295 void SetUp() override
{
296 AddContainerAndCodecMasksForTest();
299 ~KeySystemsTest() override
{
300 // Clear the use of |test_media_client_|, which was set in SetUp().
301 SetMediaClient(nullptr);
304 void UpdateClientKeySystems() {
305 test_media_client_
.SetKeySystemsUpdateNeeded();
306 test_media_client_
.DisableExternalKeySystemSupport();
309 typedef std::vector
<std::string
> CodecVector
;
311 const CodecVector
& no_codecs() const { return no_codecs_
; }
313 const CodecVector
& vp8_codec() const { return vp8_codec_
; }
314 const CodecVector
& vp80_codec() const { return vp80_codec_
; }
315 const CodecVector
& vp9_codec() const { return vp9_codec_
; }
316 const CodecVector
& vp90_codec() const { return vp90_codec_
; }
318 const CodecVector
& vorbis_codec() const { return vorbis_codec_
; }
320 const CodecVector
& vp8_and_vorbis_codecs() const {
321 return vp8_and_vorbis_codecs_
;
323 const CodecVector
& vp9_and_vorbis_codecs() const {
324 return vp9_and_vorbis_codecs_
;
327 const CodecVector
& foovideo_codec() const { return foovideo_codec_
; }
328 const CodecVector
& foovideo_extended_codec() const {
329 return foovideo_extended_codec_
;
331 const CodecVector
& foovideo_dot_codec() const { return foovideo_dot_codec_
; }
332 const CodecVector
& fooaudio_codec() const { return fooaudio_codec_
; }
333 const CodecVector
& foovideo_and_fooaudio_codecs() const {
334 return foovideo_and_fooaudio_codecs_
;
337 const CodecVector
& unknown_codec() const { return unknown_codec_
; }
339 const CodecVector
& mixed_codecs() const { return mixed_codecs_
; }
342 const CodecVector no_codecs_
;
343 CodecVector vp8_codec_
;
344 CodecVector vp80_codec_
;
345 CodecVector vp9_codec_
;
346 CodecVector vp90_codec_
;
347 CodecVector vorbis_codec_
;
348 CodecVector vp8_and_vorbis_codecs_
;
349 CodecVector vp9_and_vorbis_codecs_
;
351 CodecVector foovideo_codec_
;
352 CodecVector foovideo_extended_codec_
;
353 CodecVector foovideo_dot_codec_
;
354 CodecVector fooaudio_codec_
;
355 CodecVector foovideo_and_fooaudio_codecs_
;
357 CodecVector unknown_codec_
;
359 CodecVector mixed_codecs_
;
361 TestMediaClient test_media_client_
;
364 // TODO(ddorwin): Consider moving GetPepperType() calls out to their own test.
366 TEST_F(KeySystemsTest
, EmptyKeySystem
) {
367 EXPECT_FALSE(IsSupportedKeySystem(std::string()));
368 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(std::string()));
371 // Clear Key is the only key system registered in content.
372 TEST_F(KeySystemsTest
, ClearKey
) {
373 EXPECT_TRUE(IsSupportedKeySystem(kClearKey
));
374 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
375 kVideoWebM
, no_codecs(), kClearKey
));
377 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey
));
379 // Prefixed Clear Key is not supported internally.
380 EXPECT_FALSE(IsSupportedKeySystem(kPrefixedClearKey
));
381 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey
));
384 TEST_F(KeySystemsTest
, ClearKeyWithInitDataType
) {
385 EXPECT_TRUE(IsSupportedKeySystem(kClearKey
));
387 IsSupportedKeySystemWithInitDataType(kClearKey
, EmeInitDataType::WEBM
));
389 IsSupportedKeySystemWithInitDataType(kClearKey
, EmeInitDataType::KEYIDS
));
391 // All other InitDataTypes are not supported.
392 EXPECT_FALSE(IsSupportedKeySystemWithInitDataType(kClearKey
,
393 EmeInitDataType::UNKNOWN
));
396 // The key system is not registered and therefore is unrecognized.
397 TEST_F(KeySystemsTest
, Basic_UnrecognizedKeySystem
) {
398 static const char* const kUnrecognized
= "x-org.example.unrecognized";
400 EXPECT_FALSE(IsSupportedKeySystem(kUnrecognized
));
402 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUnrecognized
));
404 bool can_use
= false;
405 EXPECT_DEBUG_DEATH_PORTABLE(
406 can_use
= CanUseAesDecryptor(kUnrecognized
),
407 "x-org.example.unrecognized is not a known concrete system");
408 EXPECT_FALSE(can_use
);
410 #if defined(ENABLE_PEPPER_CDMS)
413 type
= GetPepperType(kUnrecognized
),
414 "x-org.example.unrecognized is not a known concrete system");
415 EXPECT_TRUE(type
.empty());
419 TEST_F(KeySystemsTest
, Basic_UsesAesDecryptor
) {
420 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
421 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
422 kVideoWebM
, no_codecs(), kUsesAes
));
424 // No UMA value for this test key system.
425 EXPECT_EQ("UseAes", GetKeySystemNameForUMA(kUsesAes
));
427 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes
));
428 #if defined(ENABLE_PEPPER_CDMS)
430 EXPECT_DEBUG_DEATH(type
= GetPepperType(kUsesAes
),
431 "x-org.example.clear is not Pepper-based");
432 EXPECT_TRUE(type
.empty());
436 TEST_F(KeySystemsTest
,
437 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1
) {
438 // Valid video types.
439 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
440 kVideoWebM
, vp8_codec(), kUsesAes
));
441 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
442 kVideoWebM
, vp80_codec(), kUsesAes
));
443 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
444 kVideoWebM
, vp9_codec(), kUsesAes
));
445 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
446 kVideoWebM
, vp90_codec(), kUsesAes
));
448 // Audio in a video container.
449 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
450 kVideoWebM
, vp8_and_vorbis_codecs(), kUsesAes
));
451 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
452 kVideoWebM
, vp9_and_vorbis_codecs(), kUsesAes
));
453 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
454 kVideoWebM
, vorbis_codec(), kUsesAes
));
457 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
458 kVideoWebM
, foovideo_codec(), kUsesAes
));
459 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
460 kVideoWebM
, unknown_codec(), kUsesAes
));
461 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
462 kVideoWebM
, mixed_codecs(), kUsesAes
));
464 // Valid audio types.
465 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
466 kAudioWebM
, no_codecs(), kUsesAes
));
467 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
468 kAudioWebM
, vorbis_codec(), kUsesAes
));
471 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
472 kAudioWebM
, vp8_codec(), kUsesAes
));
473 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
474 kAudioWebM
, vp8_and_vorbis_codecs(), kUsesAes
));
475 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
476 kAudioWebM
, vp9_codec(), kUsesAes
));
477 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
478 kAudioWebM
, vp9_and_vorbis_codecs(), kUsesAes
));
481 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
482 kAudioWebM
, fooaudio_codec(), kUsesAes
));
485 // No parent is registered for UsesAes.
486 TEST_F(KeySystemsTest
, Parent_NoParentRegistered
) {
487 EXPECT_FALSE(IsSupportedKeySystem(kUsesAesParent
));
489 // The parent is not supported for most things.
490 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAesParent
));
492 EXPECT_DEBUG_DEATH_PORTABLE(result
= CanUseAesDecryptor(kUsesAesParent
),
493 "x-org.example is not a known concrete system");
494 EXPECT_FALSE(result
);
495 #if defined(ENABLE_PEPPER_CDMS)
497 EXPECT_DEBUG_DEATH(type
= GetPepperType(kUsesAesParent
),
498 "x-org.example is not a known concrete system");
499 EXPECT_TRUE(type
.empty());
503 TEST_F(KeySystemsTest
, IsSupportedKeySystem_InvalidVariants
) {
505 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.ClEaR"));
507 // TLDs are not allowed.
508 EXPECT_FALSE(IsSupportedKeySystem("org."));
509 EXPECT_FALSE(IsSupportedKeySystem("com"));
512 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clear."));
513 EXPECT_FALSE(IsSupportedKeySystem("x-org.example."));
516 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clea"));
519 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clearz"));
521 // There are no child key systems for UsesAes.
522 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clear.foo"));
525 TEST_F(KeySystemsTest
, IsSupportedKeySystemWithMediaMimeType_NoType
) {
526 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
527 std::string(), no_codecs(), kUsesAes
));
528 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
529 std::string(), no_codecs(), kUsesAesParent
));
531 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(std::string(), no_codecs(),
532 "x-org.example.foo"));
533 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
534 std::string(), no_codecs(), "x-org.example.clear.foo"));
537 // Tests the second registered container type.
538 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
539 TEST_F(KeySystemsTest
,
540 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2
) {
541 // Valid video types.
542 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
543 kVideoFoo
, no_codecs(), kUsesAes
));
544 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
545 kVideoFoo
, foovideo_codec(), kUsesAes
));
547 // Audio in a video container.
548 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
549 kVideoFoo
, foovideo_and_fooaudio_codecs(), kUsesAes
));
550 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
551 kVideoFoo
, fooaudio_codec(), kUsesAes
));
553 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
554 // They should really pass canPlayType().
555 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
556 kVideoFoo
, foovideo_extended_codec(), kUsesAes
));
558 // Invalid codec format.
559 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
560 kVideoFoo
, foovideo_dot_codec(), kUsesAes
));
562 // Non-container2 codec.
563 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
564 kVideoFoo
, vp8_codec(), kUsesAes
));
565 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
566 kVideoFoo
, unknown_codec(), kUsesAes
));
567 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
568 kVideoFoo
, mixed_codecs(), kUsesAes
));
570 // Valid audio types.
571 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
572 kAudioFoo
, no_codecs(), kUsesAes
));
573 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
574 kAudioFoo
, fooaudio_codec(), kUsesAes
));
577 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
578 kAudioFoo
, foovideo_codec(), kUsesAes
));
579 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
580 kAudioFoo
, foovideo_and_fooaudio_codecs(), kUsesAes
));
582 // Non-container2 codec.
583 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
584 kAudioFoo
, vorbis_codec(), kUsesAes
));
588 // Non-AesDecryptor-based key system.
591 TEST_F(KeySystemsTest
, Basic_ExternalDecryptor
) {
592 EXPECT_TRUE(IsSupportedKeySystem(kExternal
));
593 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
594 kVideoWebM
, no_codecs(), kExternal
));
596 EXPECT_FALSE(CanUseAesDecryptor(kExternal
));
597 #if defined(ENABLE_PEPPER_CDMS)
598 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal
));
599 #endif // defined(ENABLE_PEPPER_CDMS)
602 TEST_F(KeySystemsTest
, Parent_ParentRegistered
) {
603 // Unprefixed has no parent key system support.
604 EXPECT_FALSE(IsSupportedKeySystem(kExternalParent
));
605 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
606 kVideoWebM
, no_codecs(), kExternalParent
));
608 // The parent is not supported for most things.
609 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalParent
));
611 EXPECT_DEBUG_DEATH_PORTABLE(result
= CanUseAesDecryptor(kExternalParent
),
612 "x-com.example is not a known concrete system");
613 EXPECT_FALSE(result
);
614 #if defined(ENABLE_PEPPER_CDMS)
616 EXPECT_DEBUG_DEATH(type
= GetPepperType(kExternalParent
),
617 "x-com.example is not a known concrete system");
618 EXPECT_TRUE(type
.empty());
624 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1
) {
625 // Valid video types.
626 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
627 kVideoWebM
, no_codecs(), kExternal
));
628 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
629 kVideoWebM
, vp8_codec(), kExternal
));
630 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
631 kVideoWebM
, vp80_codec(), kExternal
));
632 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
633 kVideoWebM
, vp9_codec(), kExternal
));
634 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
635 kVideoWebM
, vp90_codec(), kExternal
));
637 // Audio in a video container.
638 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
639 kVideoWebM
, vp8_and_vorbis_codecs(), kExternal
));
640 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
641 kVideoWebM
, vp9_and_vorbis_codecs(), kExternal
));
642 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
643 kVideoWebM
, vorbis_codec(), kExternal
));
645 // Valid video types - parent key system.
646 // Prefixed has parent key system support.
647 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
648 kVideoWebM
, no_codecs(), kExternalParent
));
649 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
650 kVideoWebM
, vp8_codec(), kExternalParent
));
651 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
652 kVideoWebM
, vp80_codec(), kExternalParent
));
653 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
654 kVideoWebM
, vp8_and_vorbis_codecs(), kExternalParent
));
655 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
656 kVideoWebM
, vp9_codec(), kExternalParent
));
657 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
658 kVideoWebM
, vp90_codec(), kExternalParent
));
659 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
660 kVideoWebM
, vp9_and_vorbis_codecs(), kExternalParent
));
661 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
662 kVideoWebM
, vorbis_codec(), kExternalParent
));
665 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
666 kVideoWebM
, foovideo_codec(), kExternal
));
667 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
668 kVideoWebM
, unknown_codec(), kExternal
));
669 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
670 kVideoWebM
, mixed_codecs(), kExternal
));
672 // Valid audio types.
673 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
674 kAudioWebM
, no_codecs(), kExternal
));
675 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
676 kAudioWebM
, vorbis_codec(), kExternal
));
678 // Valid audio types - parent key system.
679 // Prefixed has parent key system support.
680 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
681 kAudioWebM
, no_codecs(), kExternalParent
));
682 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
683 kAudioWebM
, vorbis_codec(), kExternalParent
));
686 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
687 kAudioWebM
, vp8_codec(), kExternal
));
688 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
689 kAudioWebM
, vp8_and_vorbis_codecs(), kExternal
));
690 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
691 kAudioWebM
, vp9_codec(), kExternal
));
692 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
693 kAudioWebM
, vp9_and_vorbis_codecs(), kExternal
));
696 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
697 kAudioWebM
, fooaudio_codec(), kExternal
));
702 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2
) {
703 // Valid video types.
704 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
705 kVideoFoo
, no_codecs(), kExternal
));
706 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
707 kVideoFoo
, foovideo_codec(), kExternal
));
709 // Audio in a video container.
710 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
711 kVideoFoo
, foovideo_and_fooaudio_codecs(), kExternal
));
712 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
713 kVideoFoo
, fooaudio_codec(), kExternal
));
715 // Valid video types - parent key system.
716 // Prefixed has parent key system support.
717 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
718 kVideoFoo
, no_codecs(), kExternalParent
));
719 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
720 kVideoFoo
, foovideo_codec(), kExternalParent
));
721 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
722 kVideoFoo
, foovideo_and_fooaudio_codecs(), kExternalParent
));
723 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
724 kVideoFoo
, fooaudio_codec(), kExternalParent
));
726 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
727 // They should really pass canPlayType().
728 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
729 kVideoFoo
, foovideo_extended_codec(), kExternal
));
731 // Invalid codec format.
732 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
733 kVideoFoo
, foovideo_dot_codec(), kExternal
));
735 // Non-container2 codecs.
736 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
737 kVideoFoo
, vp8_codec(), kExternal
));
738 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
739 kVideoFoo
, unknown_codec(), kExternal
));
740 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
741 kVideoFoo
, mixed_codecs(), kExternal
));
743 // Valid audio types.
744 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
745 kAudioFoo
, no_codecs(), kExternal
));
746 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
747 kAudioFoo
, fooaudio_codec(), kExternal
));
749 // Valid audio types - parent key system.
750 // Prefixed has parent key system support.
751 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
752 kAudioFoo
, no_codecs(), kExternalParent
));
753 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
754 kAudioFoo
, fooaudio_codec(), kExternalParent
));
757 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
758 kAudioFoo
, foovideo_codec(), kExternal
));
759 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
760 kAudioFoo
, foovideo_and_fooaudio_codecs(), kExternal
));
762 // Non-container2 codec.
763 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
764 kAudioFoo
, vorbis_codec(), kExternal
));
767 TEST_F(KeySystemsTest
, KeySystemNameForUMA
) {
768 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey
));
769 // Prefixed is not supported internally.
770 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey
));
772 // External Clear Key never has a UMA name.
773 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey
));
776 TEST_F(KeySystemsTest
, KeySystemsUpdate
) {
777 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
778 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
779 kVideoWebM
, no_codecs(), kUsesAes
));
780 EXPECT_TRUE(IsSupportedKeySystem(kExternal
));
781 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
782 kVideoWebM
, no_codecs(), kExternal
));
784 UpdateClientKeySystems();
786 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
787 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
788 kVideoWebM
, no_codecs(), kUsesAes
));
789 EXPECT_FALSE(IsSupportedKeySystem(kExternal
));
792 TEST_F(KeySystemsTest
, PrefixedKeySystemsUpdate
) {
793 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
794 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
795 kVideoWebM
, no_codecs(), kUsesAes
));
796 EXPECT_TRUE(IsSupportedKeySystem(kExternal
));
797 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
798 kVideoWebM
, no_codecs(), kExternal
));
800 UpdateClientKeySystems();
802 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
803 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
804 kVideoWebM
, no_codecs(), kUsesAes
));
805 EXPECT_FALSE(IsSupportedKeySystem(kExternal
));
806 EXPECT_FALSE(PrefixedIsSupportedKeySystemWithMediaMimeType(
807 kVideoWebM
, no_codecs(), kExternal
));
810 TEST_F(KeySystemsPotentiallySupportedNamesTest
, PotentiallySupportedNames
) {
811 EXPECT_FALSE(IsSupportedKeySystem("org.w3"));
812 EXPECT_FALSE(IsSupportedKeySystem("org.w3."));
813 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearke"));
814 EXPECT_TRUE(IsSupportedKeySystem("org.w3.clearkey"));
815 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkeys"));
817 EXPECT_FALSE(IsSupportedKeySystem("com.widevine"));
818 EXPECT_FALSE(IsSupportedKeySystem("com.widevine."));
819 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph"));
820 EXPECT_TRUE(IsSupportedKeySystem("com.widevine.alpha"));
821 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.beta"));
822 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphabeta"));
823 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.beta"));
825 EXPECT_FALSE(IsSupportedKeySystem("org.chromium"));
826 EXPECT_FALSE(IsSupportedKeySystem("org.chromium."));
827 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke"));
828 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey"));
829 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeys"));
830 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey."));
831 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey.something"));
833 IsSupportedKeySystem("org.chromium.externalclearkey.something.else"));
834 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.other"));
835 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.other"));
837 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast"));
838 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast."));
839 EXPECT_TRUE(IsSupportedKeySystem("com.chromecast.something"));
840 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else"));
841 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other"));
843 EXPECT_FALSE(IsSupportedKeySystem("x-"));
844 EXPECT_TRUE(IsSupportedKeySystem("x-something"));
845 EXPECT_FALSE(IsSupportedKeySystem("x-something.else"));
846 EXPECT_FALSE(IsSupportedKeySystem("x-other"));