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()->IsSupportedCodecCombination(
81 key_system
, EmeMediaType::VIDEO
, mime_type
, codecs
);
84 static bool IsSupportedKeySystemWithAudioMimeType(
85 const std::string
& mime_type
,
86 const std::vector
<std::string
>& codecs
,
87 const std::string
& key_system
) {
88 return KeySystems::GetInstance()->IsSupportedCodecCombination(
89 key_system
, EmeMediaType::AUDIO
, mime_type
, codecs
);
92 // Adds test container and codec masks.
93 // This function must be called after SetMediaClient() if a MediaClient will be
95 // More details: AddXxxMask() will create KeySystems if it hasn't been created.
96 // During KeySystems's construction GetMediaClient() will be used to add key
97 // systems. In test code, the MediaClient is set by SetMediaClient().
98 // Therefore, SetMediaClient() must be called before this function to make sure
99 // MediaClient in effect when constructing KeySystems.
100 static void AddContainerAndCodecMasksForTest() {
101 // Since KeySystems is a singleton. Make sure we only add test container and
102 // codec masks once per process.
103 static bool is_test_masks_added
= false;
105 if (is_test_masks_added
)
108 AddContainerMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL
);
109 AddContainerMask("video/foo", TEST_CODEC_FOO_ALL
);
110 AddCodecMask(EmeMediaType::AUDIO
, "fooaudio", TEST_CODEC_FOO_AUDIO
);
111 AddCodecMask(EmeMediaType::VIDEO
, "foovideo", TEST_CODEC_FOO_VIDEO
);
113 is_test_masks_added
= true;
116 class TestMediaClient
: public MediaClient
{
119 ~TestMediaClient() override
;
121 // MediaClient implementation.
122 void AddKeySystemsInfoForUMA(
123 std::vector
<KeySystemInfoForUMA
>* key_systems_info_for_uma
) final
;
124 bool IsKeySystemsUpdateNeeded() final
;
125 void AddSupportedKeySystems(
126 std::vector
<KeySystemInfo
>* key_systems_info
) override
;
128 // Helper function to test the case where IsKeySystemsUpdateNeeded() is true
129 // after AddSupportedKeySystems() is called.
130 void SetKeySystemsUpdateNeeded();
132 // Helper function to disable "kExternal" key system support so that we can
133 // test the key system update case.
134 void DisableExternalKeySystemSupport();
137 void AddUsesAesKeySystem(const std::string
& name
,
138 std::vector
<KeySystemInfo
>* key_systems_info
);
139 void AddExternalKeySystem(
140 std::vector
<KeySystemInfo
>* key_systems_info
);
143 bool is_update_needed_
;
144 bool supports_external_key_system_
;
147 TestMediaClient::TestMediaClient()
148 : is_update_needed_(true), supports_external_key_system_(true) {
151 TestMediaClient::~TestMediaClient() {
154 void TestMediaClient::AddKeySystemsInfoForUMA(
155 std::vector
<KeySystemInfoForUMA
>* key_systems_info_for_uma
) {
156 key_systems_info_for_uma
->push_back(
157 media::KeySystemInfoForUMA(kUsesAes
, kUseAesNameForUMA
, false));
158 key_systems_info_for_uma
->push_back(
159 media::KeySystemInfoForUMA(kExternal
, kExternalNameForUMA
, true));
162 bool TestMediaClient::IsKeySystemsUpdateNeeded() {
163 return is_update_needed_
;
166 void TestMediaClient::AddSupportedKeySystems(
167 std::vector
<KeySystemInfo
>* key_systems
) {
168 DCHECK(is_update_needed_
);
170 AddUsesAesKeySystem(kUsesAes
, key_systems
);
172 if (supports_external_key_system_
)
173 AddExternalKeySystem(key_systems
);
175 is_update_needed_
= false;
178 void TestMediaClient::SetKeySystemsUpdateNeeded() {
179 is_update_needed_
= true;
182 void TestMediaClient::DisableExternalKeySystemSupport() {
183 supports_external_key_system_
= false;
186 void TestMediaClient::AddUsesAesKeySystem(
187 const std::string
& name
,
188 std::vector
<KeySystemInfo
>* key_systems
) {
189 KeySystemInfo system
;
190 system
.key_system
= name
;
191 system
.supported_codecs
= EME_CODEC_WEBM_ALL
;
192 system
.supported_codecs
|= TEST_CODEC_FOO_ALL
;
193 system
.supported_init_data_types
= kInitDataTypeMaskWebM
;
194 system
.max_audio_robustness
= EmeRobustness::EMPTY
;
195 system
.max_video_robustness
= EmeRobustness::EMPTY
;
196 system
.persistent_license_support
= EmeSessionTypeSupport::NOT_SUPPORTED
;
197 system
.persistent_release_message_support
=
198 EmeSessionTypeSupport::NOT_SUPPORTED
;
199 system
.persistent_state_support
= EmeFeatureSupport::NOT_SUPPORTED
;
200 system
.distinctive_identifier_support
= EmeFeatureSupport::NOT_SUPPORTED
;
201 system
.use_aes_decryptor
= true;
202 key_systems
->push_back(system
);
205 void TestMediaClient::AddExternalKeySystem(
206 std::vector
<KeySystemInfo
>* key_systems
) {
208 ext
.key_system
= kExternal
;
209 ext
.supported_codecs
= EME_CODEC_WEBM_ALL
;
210 ext
.supported_codecs
|= TEST_CODEC_FOO_ALL
;
211 ext
.supported_init_data_types
= kInitDataTypeMaskWebM
;
212 ext
.max_audio_robustness
= EmeRobustness::EMPTY
;
213 ext
.max_video_robustness
= EmeRobustness::EMPTY
;
214 ext
.persistent_license_support
= EmeSessionTypeSupport::SUPPORTED
;
215 ext
.persistent_release_message_support
= EmeSessionTypeSupport::NOT_SUPPORTED
;
216 ext
.persistent_state_support
= EmeFeatureSupport::ALWAYS_ENABLED
;
217 ext
.distinctive_identifier_support
= EmeFeatureSupport::ALWAYS_ENABLED
;
218 ext
.parent_key_system
= kExternalParent
;
219 #if defined(ENABLE_PEPPER_CDMS)
220 ext
.pepper_type
= "application/x-ppapi-external-cdm";
221 #endif // defined(ENABLE_PEPPER_CDMS)
222 key_systems
->push_back(ext
);
225 class PotentiallySupportedNamesTestMediaClient
: public TestMediaClient
{
226 void AddSupportedKeySystems(
227 std::vector
<KeySystemInfo
>* key_systems_info
) final
;
230 void PotentiallySupportedNamesTestMediaClient::AddSupportedKeySystems(
231 std::vector
<KeySystemInfo
>* key_systems
) {
232 // org.w3.clearkey is automatically registered.
233 AddUsesAesKeySystem("com.widevine.alpha", key_systems
);
234 AddUsesAesKeySystem("org.chromium.externalclearkey", key_systems
);
235 AddUsesAesKeySystem("org.chromium.externalclearkey.something", key_systems
);
236 AddUsesAesKeySystem("com.chromecast.something", key_systems
);
237 AddUsesAesKeySystem("x-something", key_systems
);
240 class KeySystemsPotentiallySupportedNamesTest
: public testing::Test
{
242 KeySystemsPotentiallySupportedNamesTest() {
243 SetMediaClient(&test_media_client_
);
246 ~KeySystemsPotentiallySupportedNamesTest() override
{
247 // Clear the use of |test_media_client_|, which was set in SetUp().
248 SetMediaClient(nullptr);
252 PotentiallySupportedNamesTestMediaClient test_media_client_
;
255 class KeySystemsTest
: public testing::Test
{
258 vp8_codec_
.push_back("vp8");
260 vp80_codec_
.push_back("vp8.0");
262 vp9_codec_
.push_back("vp9");
264 vp90_codec_
.push_back("vp9.0");
266 vorbis_codec_
.push_back("vorbis");
268 vp8_and_vorbis_codecs_
.push_back("vp8");
269 vp8_and_vorbis_codecs_
.push_back("vorbis");
271 vp9_and_vorbis_codecs_
.push_back("vp9");
272 vp9_and_vorbis_codecs_
.push_back("vorbis");
274 foovideo_codec_
.push_back("foovideo");
276 foovideo_extended_codec_
.push_back("foovideo.4D400C");
278 foovideo_dot_codec_
.push_back("foovideo.");
280 fooaudio_codec_
.push_back("fooaudio");
282 foovideo_and_fooaudio_codecs_
.push_back("foovideo");
283 foovideo_and_fooaudio_codecs_
.push_back("fooaudio");
285 unknown_codec_
.push_back("unknown");
287 mixed_codecs_
.push_back("vorbis");
288 mixed_codecs_
.push_back("foovideo");
290 SetMediaClient(&test_media_client_
);
293 void SetUp() override
{
294 AddContainerAndCodecMasksForTest();
297 ~KeySystemsTest() override
{
298 // Clear the use of |test_media_client_|, which was set in SetUp().
299 SetMediaClient(nullptr);
302 void UpdateClientKeySystems() {
303 test_media_client_
.SetKeySystemsUpdateNeeded();
304 test_media_client_
.DisableExternalKeySystemSupport();
307 typedef std::vector
<std::string
> CodecVector
;
309 const CodecVector
& no_codecs() const { return no_codecs_
; }
311 const CodecVector
& vp8_codec() const { return vp8_codec_
; }
312 const CodecVector
& vp80_codec() const { return vp80_codec_
; }
313 const CodecVector
& vp9_codec() const { return vp9_codec_
; }
314 const CodecVector
& vp90_codec() const { return vp90_codec_
; }
316 const CodecVector
& vorbis_codec() const { return vorbis_codec_
; }
318 const CodecVector
& vp8_and_vorbis_codecs() const {
319 return vp8_and_vorbis_codecs_
;
321 const CodecVector
& vp9_and_vorbis_codecs() const {
322 return vp9_and_vorbis_codecs_
;
325 const CodecVector
& foovideo_codec() const { return foovideo_codec_
; }
326 const CodecVector
& foovideo_extended_codec() const {
327 return foovideo_extended_codec_
;
329 const CodecVector
& foovideo_dot_codec() const { return foovideo_dot_codec_
; }
330 const CodecVector
& fooaudio_codec() const { return fooaudio_codec_
; }
331 const CodecVector
& foovideo_and_fooaudio_codecs() const {
332 return foovideo_and_fooaudio_codecs_
;
335 const CodecVector
& unknown_codec() const { return unknown_codec_
; }
337 const CodecVector
& mixed_codecs() const { return mixed_codecs_
; }
340 const CodecVector no_codecs_
;
341 CodecVector vp8_codec_
;
342 CodecVector vp80_codec_
;
343 CodecVector vp9_codec_
;
344 CodecVector vp90_codec_
;
345 CodecVector vorbis_codec_
;
346 CodecVector vp8_and_vorbis_codecs_
;
347 CodecVector vp9_and_vorbis_codecs_
;
349 CodecVector foovideo_codec_
;
350 CodecVector foovideo_extended_codec_
;
351 CodecVector foovideo_dot_codec_
;
352 CodecVector fooaudio_codec_
;
353 CodecVector foovideo_and_fooaudio_codecs_
;
355 CodecVector unknown_codec_
;
357 CodecVector mixed_codecs_
;
359 TestMediaClient test_media_client_
;
362 // TODO(ddorwin): Consider moving GetPepperType() calls out to their own test.
364 TEST_F(KeySystemsTest
, EmptyKeySystem
) {
365 EXPECT_FALSE(IsSupportedKeySystem(std::string()));
366 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(std::string()));
369 // Clear Key is the only key system registered in content.
370 TEST_F(KeySystemsTest
, ClearKey
) {
371 EXPECT_TRUE(IsSupportedKeySystem(kClearKey
));
372 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
373 kVideoWebM
, no_codecs(), kClearKey
));
375 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey
));
377 // Prefixed Clear Key is not supported internally.
378 EXPECT_FALSE(IsSupportedKeySystem(kPrefixedClearKey
));
379 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey
));
382 TEST_F(KeySystemsTest
, ClearKeyWithInitDataType
) {
383 EXPECT_TRUE(IsSupportedKeySystem(kClearKey
));
385 IsSupportedKeySystemWithInitDataType(kClearKey
, EmeInitDataType::WEBM
));
387 IsSupportedKeySystemWithInitDataType(kClearKey
, EmeInitDataType::KEYIDS
));
389 // All other InitDataTypes are not supported.
390 EXPECT_FALSE(IsSupportedKeySystemWithInitDataType(kClearKey
,
391 EmeInitDataType::UNKNOWN
));
394 // The key system is not registered and therefore is unrecognized.
395 TEST_F(KeySystemsTest
, Basic_UnrecognizedKeySystem
) {
396 static const char* const kUnrecognized
= "x-org.example.unrecognized";
398 EXPECT_FALSE(IsSupportedKeySystem(kUnrecognized
));
400 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUnrecognized
));
402 bool can_use
= false;
403 EXPECT_DEBUG_DEATH_PORTABLE(
404 can_use
= CanUseAesDecryptor(kUnrecognized
),
405 "x-org.example.unrecognized is not a known concrete system");
406 EXPECT_FALSE(can_use
);
408 #if defined(ENABLE_PEPPER_CDMS)
411 type
= GetPepperType(kUnrecognized
),
412 "x-org.example.unrecognized is not a known concrete system");
413 EXPECT_TRUE(type
.empty());
417 TEST_F(KeySystemsTest
, Basic_UsesAesDecryptor
) {
418 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
419 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
420 kVideoWebM
, no_codecs(), kUsesAes
));
422 // No UMA value for this test key system.
423 EXPECT_EQ("UseAes", GetKeySystemNameForUMA(kUsesAes
));
425 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes
));
426 #if defined(ENABLE_PEPPER_CDMS)
428 EXPECT_DEBUG_DEATH(type
= GetPepperType(kUsesAes
),
429 "x-org.example.clear is not Pepper-based");
430 EXPECT_TRUE(type
.empty());
434 TEST_F(KeySystemsTest
,
435 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1
) {
436 // Valid video types.
437 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
438 kVideoWebM
, vp8_codec(), kUsesAes
));
439 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
440 kVideoWebM
, vp80_codec(), kUsesAes
));
441 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
442 kVideoWebM
, vp9_codec(), kUsesAes
));
443 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
444 kVideoWebM
, vp90_codec(), kUsesAes
));
446 // Audio in a video container.
447 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
448 kVideoWebM
, vp8_and_vorbis_codecs(), kUsesAes
));
449 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
450 kVideoWebM
, vp9_and_vorbis_codecs(), kUsesAes
));
451 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
452 kVideoWebM
, vorbis_codec(), kUsesAes
));
455 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
456 kVideoWebM
, foovideo_codec(), kUsesAes
));
457 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
458 kVideoWebM
, unknown_codec(), kUsesAes
));
459 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
460 kVideoWebM
, mixed_codecs(), kUsesAes
));
462 // Valid audio types.
463 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
464 kAudioWebM
, no_codecs(), kUsesAes
));
465 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
466 kAudioWebM
, vorbis_codec(), kUsesAes
));
469 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
470 kAudioWebM
, vp8_codec(), kUsesAes
));
471 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
472 kAudioWebM
, vp8_and_vorbis_codecs(), kUsesAes
));
473 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
474 kAudioWebM
, vp9_codec(), kUsesAes
));
475 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
476 kAudioWebM
, vp9_and_vorbis_codecs(), kUsesAes
));
479 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
480 kAudioWebM
, fooaudio_codec(), kUsesAes
));
483 // No parent is registered for UsesAes.
484 TEST_F(KeySystemsTest
, Parent_NoParentRegistered
) {
485 EXPECT_FALSE(IsSupportedKeySystem(kUsesAesParent
));
487 // The parent is not supported for most things.
488 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAesParent
));
490 EXPECT_DEBUG_DEATH_PORTABLE(result
= CanUseAesDecryptor(kUsesAesParent
),
491 "x-org.example is not a known concrete system");
492 EXPECT_FALSE(result
);
493 #if defined(ENABLE_PEPPER_CDMS)
495 EXPECT_DEBUG_DEATH(type
= GetPepperType(kUsesAesParent
),
496 "x-org.example is not a known concrete system");
497 EXPECT_TRUE(type
.empty());
501 TEST_F(KeySystemsTest
, IsSupportedKeySystem_InvalidVariants
) {
503 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.ClEaR"));
505 // TLDs are not allowed.
506 EXPECT_FALSE(IsSupportedKeySystem("org."));
507 EXPECT_FALSE(IsSupportedKeySystem("com"));
510 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clear."));
511 EXPECT_FALSE(IsSupportedKeySystem("x-org.example."));
514 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clea"));
517 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clearz"));
519 // There are no child key systems for UsesAes.
520 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clear.foo"));
523 TEST_F(KeySystemsTest
, IsSupportedKeySystemWithMediaMimeType_NoType
) {
524 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
525 std::string(), no_codecs(), kUsesAes
));
526 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
527 std::string(), no_codecs(), kUsesAesParent
));
529 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(std::string(), no_codecs(),
530 "x-org.example.foo"));
531 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
532 std::string(), no_codecs(), "x-org.example.clear.foo"));
535 // Tests the second registered container type.
536 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
537 TEST_F(KeySystemsTest
,
538 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2
) {
539 // Valid video types.
540 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
541 kVideoFoo
, no_codecs(), kUsesAes
));
542 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
543 kVideoFoo
, foovideo_codec(), kUsesAes
));
545 // Audio in a video container.
546 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
547 kVideoFoo
, foovideo_and_fooaudio_codecs(), kUsesAes
));
548 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
549 kVideoFoo
, fooaudio_codec(), kUsesAes
));
551 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
552 // They should really pass canPlayType().
553 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
554 kVideoFoo
, foovideo_extended_codec(), kUsesAes
));
556 // Invalid codec format.
557 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
558 kVideoFoo
, foovideo_dot_codec(), kUsesAes
));
560 // Non-container2 codec.
561 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
562 kVideoFoo
, vp8_codec(), kUsesAes
));
563 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
564 kVideoFoo
, unknown_codec(), kUsesAes
));
565 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
566 kVideoFoo
, mixed_codecs(), kUsesAes
));
568 // Valid audio types.
569 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
570 kAudioFoo
, no_codecs(), kUsesAes
));
571 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
572 kAudioFoo
, fooaudio_codec(), kUsesAes
));
575 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
576 kAudioFoo
, foovideo_codec(), kUsesAes
));
577 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
578 kAudioFoo
, foovideo_and_fooaudio_codecs(), kUsesAes
));
580 // Non-container2 codec.
581 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
582 kAudioFoo
, vorbis_codec(), kUsesAes
));
586 // Non-AesDecryptor-based key system.
589 TEST_F(KeySystemsTest
, Basic_ExternalDecryptor
) {
590 EXPECT_TRUE(IsSupportedKeySystem(kExternal
));
591 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
592 kVideoWebM
, no_codecs(), kExternal
));
594 EXPECT_FALSE(CanUseAesDecryptor(kExternal
));
595 #if defined(ENABLE_PEPPER_CDMS)
596 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal
));
597 #endif // defined(ENABLE_PEPPER_CDMS)
600 TEST_F(KeySystemsTest
, Parent_ParentRegistered
) {
601 // Unprefixed has no parent key system support.
602 EXPECT_FALSE(IsSupportedKeySystem(kExternalParent
));
603 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
604 kVideoWebM
, no_codecs(), kExternalParent
));
606 // The parent is not supported for most things.
607 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalParent
));
609 EXPECT_DEBUG_DEATH_PORTABLE(result
= CanUseAesDecryptor(kExternalParent
),
610 "x-com.example is not a known concrete system");
611 EXPECT_FALSE(result
);
612 #if defined(ENABLE_PEPPER_CDMS)
614 EXPECT_DEBUG_DEATH(type
= GetPepperType(kExternalParent
),
615 "x-com.example is not a known concrete system");
616 EXPECT_TRUE(type
.empty());
622 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1
) {
623 // Valid video types.
624 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
625 kVideoWebM
, no_codecs(), kExternal
));
626 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
627 kVideoWebM
, vp8_codec(), kExternal
));
628 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
629 kVideoWebM
, vp80_codec(), kExternal
));
630 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
631 kVideoWebM
, vp9_codec(), kExternal
));
632 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
633 kVideoWebM
, vp90_codec(), kExternal
));
635 // Audio in a video container.
636 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
637 kVideoWebM
, vp8_and_vorbis_codecs(), kExternal
));
638 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
639 kVideoWebM
, vp9_and_vorbis_codecs(), kExternal
));
640 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
641 kVideoWebM
, vorbis_codec(), kExternal
));
643 // Valid video types - parent key system.
644 // Prefixed has parent key system support.
645 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
646 kVideoWebM
, no_codecs(), kExternalParent
));
647 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
648 kVideoWebM
, vp8_codec(), kExternalParent
));
649 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
650 kVideoWebM
, vp80_codec(), kExternalParent
));
651 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
652 kVideoWebM
, vp8_and_vorbis_codecs(), kExternalParent
));
653 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
654 kVideoWebM
, vp9_codec(), kExternalParent
));
655 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
656 kVideoWebM
, vp90_codec(), kExternalParent
));
657 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
658 kVideoWebM
, vp9_and_vorbis_codecs(), kExternalParent
));
659 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
660 kVideoWebM
, vorbis_codec(), kExternalParent
));
663 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
664 kVideoWebM
, foovideo_codec(), kExternal
));
665 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
666 kVideoWebM
, unknown_codec(), kExternal
));
667 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
668 kVideoWebM
, mixed_codecs(), kExternal
));
670 // Valid audio types.
671 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
672 kAudioWebM
, no_codecs(), kExternal
));
673 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
674 kAudioWebM
, vorbis_codec(), kExternal
));
676 // Valid audio types - parent key system.
677 // Prefixed has parent key system support.
678 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
679 kAudioWebM
, no_codecs(), kExternalParent
));
680 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
681 kAudioWebM
, vorbis_codec(), kExternalParent
));
684 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
685 kAudioWebM
, vp8_codec(), kExternal
));
686 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
687 kAudioWebM
, vp8_and_vorbis_codecs(), kExternal
));
688 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
689 kAudioWebM
, vp9_codec(), kExternal
));
690 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
691 kAudioWebM
, vp9_and_vorbis_codecs(), kExternal
));
694 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
695 kAudioWebM
, fooaudio_codec(), kExternal
));
700 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2
) {
701 // Valid video types.
702 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
703 kVideoFoo
, no_codecs(), kExternal
));
704 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
705 kVideoFoo
, foovideo_codec(), kExternal
));
707 // Audio in a video container.
708 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
709 kVideoFoo
, foovideo_and_fooaudio_codecs(), kExternal
));
710 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
711 kVideoFoo
, fooaudio_codec(), kExternal
));
713 // Valid video types - parent key system.
714 // Prefixed has parent key system support.
715 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
716 kVideoFoo
, no_codecs(), kExternalParent
));
717 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
718 kVideoFoo
, foovideo_codec(), kExternalParent
));
719 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
720 kVideoFoo
, foovideo_and_fooaudio_codecs(), kExternalParent
));
721 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
722 kVideoFoo
, fooaudio_codec(), kExternalParent
));
724 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
725 // They should really pass canPlayType().
726 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
727 kVideoFoo
, foovideo_extended_codec(), kExternal
));
729 // Invalid codec format.
730 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
731 kVideoFoo
, foovideo_dot_codec(), kExternal
));
733 // Non-container2 codecs.
734 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
735 kVideoFoo
, vp8_codec(), kExternal
));
736 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
737 kVideoFoo
, unknown_codec(), kExternal
));
738 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
739 kVideoFoo
, mixed_codecs(), kExternal
));
741 // Valid audio types.
742 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
743 kAudioFoo
, no_codecs(), kExternal
));
744 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
745 kAudioFoo
, fooaudio_codec(), kExternal
));
747 // Valid audio types - parent key system.
748 // Prefixed has parent key system support.
749 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
750 kAudioFoo
, no_codecs(), kExternalParent
));
751 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
752 kAudioFoo
, fooaudio_codec(), kExternalParent
));
755 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
756 kAudioFoo
, foovideo_codec(), kExternal
));
757 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
758 kAudioFoo
, foovideo_and_fooaudio_codecs(), kExternal
));
760 // Non-container2 codec.
761 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
762 kAudioFoo
, vorbis_codec(), kExternal
));
765 TEST_F(KeySystemsTest
, KeySystemNameForUMA
) {
766 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey
));
767 // Prefixed is not supported internally.
768 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey
));
770 // External Clear Key never has a UMA name.
771 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey
));
774 TEST_F(KeySystemsTest
, KeySystemsUpdate
) {
775 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
776 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
777 kVideoWebM
, no_codecs(), kUsesAes
));
778 EXPECT_TRUE(IsSupportedKeySystem(kExternal
));
779 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
780 kVideoWebM
, no_codecs(), kExternal
));
782 UpdateClientKeySystems();
784 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
785 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
786 kVideoWebM
, no_codecs(), kUsesAes
));
787 EXPECT_FALSE(IsSupportedKeySystem(kExternal
));
790 TEST_F(KeySystemsTest
, PrefixedKeySystemsUpdate
) {
791 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
792 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
793 kVideoWebM
, no_codecs(), kUsesAes
));
794 EXPECT_TRUE(IsSupportedKeySystem(kExternal
));
795 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
796 kVideoWebM
, no_codecs(), kExternal
));
798 UpdateClientKeySystems();
800 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes
));
801 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
802 kVideoWebM
, no_codecs(), kUsesAes
));
803 EXPECT_FALSE(IsSupportedKeySystem(kExternal
));
804 EXPECT_FALSE(PrefixedIsSupportedKeySystemWithMediaMimeType(
805 kVideoWebM
, no_codecs(), kExternal
));
808 TEST_F(KeySystemsPotentiallySupportedNamesTest
, PotentiallySupportedNames
) {
809 EXPECT_FALSE(IsSupportedKeySystem("org.w3"));
810 EXPECT_FALSE(IsSupportedKeySystem("org.w3."));
811 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearke"));
812 EXPECT_TRUE(IsSupportedKeySystem("org.w3.clearkey"));
813 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkeys"));
815 EXPECT_FALSE(IsSupportedKeySystem("com.widevine"));
816 EXPECT_FALSE(IsSupportedKeySystem("com.widevine."));
817 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph"));
818 EXPECT_TRUE(IsSupportedKeySystem("com.widevine.alpha"));
819 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.beta"));
820 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphabeta"));
821 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.beta"));
823 EXPECT_FALSE(IsSupportedKeySystem("org.chromium"));
824 EXPECT_FALSE(IsSupportedKeySystem("org.chromium."));
825 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke"));
826 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey"));
827 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeys"));
828 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey."));
829 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey.something"));
831 IsSupportedKeySystem("org.chromium.externalclearkey.something.else"));
832 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.other"));
833 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.other"));
835 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast"));
836 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast."));
837 EXPECT_TRUE(IsSupportedKeySystem("com.chromecast.something"));
838 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else"));
839 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other"));
841 EXPECT_FALSE(IsSupportedKeySystem("x-"));
842 EXPECT_TRUE(IsSupportedKeySystem("x-something"));
843 EXPECT_FALSE(IsSupportedKeySystem("x-something.else"));
844 EXPECT_FALSE(IsSupportedKeySystem("x-other"));