Enable right clicking on the applist doodle web contents and log the data.
[chromium-blink-merge.git] / media / base / key_systems_unittest.cc
blob7f8d27c1f52b4af256939f535aededaf9606d774
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 #include <string>
6 #include <vector>
8 #include "base/logging.h"
9 #include "media/base/eme_constants.h"
10 #include "media/base/key_system_info.h"
11 #include "media/base/key_systems.h"
12 #include "media/base/media_client.h"
13 #include "testing/gtest/include/gtest/gtest.h"
15 // Death tests are not always available, including on Android.
16 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that
17 // death tests are not available and NDEBUG is not defined.
18 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
19 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
20 EXPECT_DEBUG_DEATH(statement, regex)
21 #else
22 #if defined(NDEBUG)
23 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
24 do { statement; } while (false)
25 #else
26 #include "base/logging.h"
27 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
28 LOG(WARNING) << "Death tests are not supported on this platform.\n" \
29 << "Statement '" #statement "' cannot be verified.";
30 #endif // defined(NDEBUG)
31 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
33 namespace media {
35 // These are the (fake) key systems that are registered for these tests.
36 // kUsesAes uses the AesDecryptor like Clear Key.
37 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
38 const char kUsesAes[] = "x-org.example.clear";
39 const char kUsesAesParent[] = "x-org.example"; // Not registered.
40 const char kUseAesNameForUMA[] = "UseAes";
41 const char kExternal[] = "x-com.example.test";
42 const char kExternalParent[] = "x-com.example";
43 const char kExternalNameForUMA[] = "External";
45 const char kClearKey[] = "org.w3.clearkey";
46 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
47 const char kExternalClearKey[] = "org.chromium.externalclearkey";
49 const char kAudioWebM[] = "audio/webm";
50 const char kVideoWebM[] = "video/webm";
51 const char kAudioFoo[] = "audio/foo";
52 const char kVideoFoo[] = "video/foo";
54 // Pick some arbitrary bit fields as long as they are not in conflict with the
55 // real ones.
56 enum TestCodec {
57 TEST_CODEC_FOO_AUDIO = 1 << 10, // An audio codec for foo container.
58 TEST_CODEC_FOO_AUDIO_ALL = TEST_CODEC_FOO_AUDIO,
59 TEST_CODEC_FOO_VIDEO = 1 << 11, // A video codec for foo container.
60 TEST_CODEC_FOO_VIDEO_ALL = TEST_CODEC_FOO_VIDEO,
61 TEST_CODEC_FOO_ALL = TEST_CODEC_FOO_AUDIO_ALL | TEST_CODEC_FOO_VIDEO_ALL
64 static_assert((TEST_CODEC_FOO_ALL & EME_CODEC_ALL) == EME_CODEC_NONE,
65 "test codec masks should only use invalid codec masks");
67 // Adds test container and codec masks.
68 // This function must be called after SetMediaClient() if a MediaClient will be
69 // provided.
70 // More details: AddXxxMask() will create KeySystems if it hasn't been created.
71 // During KeySystems's construction GetMediaClient() will be used to add key
72 // systems. In test code, the MediaClient is set by SetMediaClient().
73 // Therefore, SetMediaClient() must be called before this function to make sure
74 // MediaClient in effect when constructing KeySystems.
75 static void AddContainerAndCodecMasksForTest() {
76 // Since KeySystems is a singleton. Make sure we only add test container and
77 // codec masks once per process.
78 static bool is_test_masks_added = false;
80 if (is_test_masks_added)
81 return;
83 AddContainerMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL);
84 AddContainerMask("video/foo", TEST_CODEC_FOO_ALL);
85 AddCodecMask("fooaudio", TEST_CODEC_FOO_AUDIO);
86 AddCodecMask("foovideo", TEST_CODEC_FOO_VIDEO);
88 is_test_masks_added = true;
91 class TestMediaClient : public MediaClient {
92 public:
93 TestMediaClient();
94 ~TestMediaClient() override;
96 // MediaClient implementation.
97 void AddKeySystemsInfoForUMA(
98 std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) final;
99 bool IsKeySystemsUpdateNeeded() final;
100 void AddSupportedKeySystems(
101 std::vector<KeySystemInfo>* key_systems_info) override;
103 // Helper function to test the case where IsKeySystemsUpdateNeeded() is true
104 // after AddSupportedKeySystems() is called.
105 void SetKeySystemsUpdateNeeded();
107 // Helper function to disable "kExternal" key system support so that we can
108 // test the key system update case.
109 void DisableExternalKeySystemSupport();
111 protected:
112 void AddUsesAesKeySystem(const std::string& name,
113 std::vector<KeySystemInfo>* key_systems_info);
114 void AddExternalKeySystem(
115 std::vector<KeySystemInfo>* key_systems_info);
117 private:
118 bool is_update_needed_;
119 bool supports_external_key_system_;
122 TestMediaClient::TestMediaClient()
123 : is_update_needed_(true), supports_external_key_system_(true) {
126 TestMediaClient::~TestMediaClient() {
129 void TestMediaClient::AddKeySystemsInfoForUMA(
130 std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) {
131 key_systems_info_for_uma->push_back(
132 media::KeySystemInfoForUMA(kUsesAes, kUseAesNameForUMA, false));
133 key_systems_info_for_uma->push_back(
134 media::KeySystemInfoForUMA(kExternal, kExternalNameForUMA, true));
137 bool TestMediaClient::IsKeySystemsUpdateNeeded() {
138 return is_update_needed_;
141 void TestMediaClient::AddSupportedKeySystems(
142 std::vector<KeySystemInfo>* key_systems) {
143 DCHECK(is_update_needed_);
145 AddUsesAesKeySystem(kUsesAes, key_systems);
147 if (supports_external_key_system_)
148 AddExternalKeySystem(key_systems);
150 is_update_needed_ = false;
153 void TestMediaClient::SetKeySystemsUpdateNeeded() {
154 is_update_needed_ = true;
157 void TestMediaClient::DisableExternalKeySystemSupport() {
158 supports_external_key_system_ = false;
161 void TestMediaClient::AddUsesAesKeySystem(
162 const std::string& name,
163 std::vector<KeySystemInfo>* key_systems) {
164 KeySystemInfo system;
165 system.key_system = name;
166 system.supported_codecs = EME_CODEC_WEBM_ALL;
167 system.supported_codecs |= TEST_CODEC_FOO_ALL;
168 system.supported_init_data_types = EME_INIT_DATA_TYPE_WEBM;
169 system.persistent_license_support = EME_SESSION_TYPE_NOT_SUPPORTED;
170 system.persistent_release_message_support = EME_SESSION_TYPE_NOT_SUPPORTED;
171 system.persistent_state_support = EME_FEATURE_NOT_SUPPORTED;
172 system.distinctive_identifier_support = EME_FEATURE_NOT_SUPPORTED;
173 system.use_aes_decryptor = true;
174 key_systems->push_back(system);
177 void TestMediaClient::AddExternalKeySystem(
178 std::vector<KeySystemInfo>* key_systems) {
179 KeySystemInfo ext;
180 ext.key_system = kExternal;
181 ext.supported_codecs = EME_CODEC_WEBM_ALL;
182 ext.supported_codecs |= TEST_CODEC_FOO_ALL;
183 ext.supported_init_data_types = EME_INIT_DATA_TYPE_WEBM;
184 ext.persistent_license_support = EME_SESSION_TYPE_SUPPORTED;
185 ext.persistent_release_message_support = EME_SESSION_TYPE_NOT_SUPPORTED;
186 ext.persistent_state_support = EME_FEATURE_ALWAYS_ENABLED;
187 ext.distinctive_identifier_support = EME_FEATURE_ALWAYS_ENABLED;
188 ext.parent_key_system = kExternalParent;
189 #if defined(ENABLE_PEPPER_CDMS)
190 ext.pepper_type = "application/x-ppapi-external-cdm";
191 #endif // defined(ENABLE_PEPPER_CDMS)
192 key_systems->push_back(ext);
195 class PotentiallySupportedNamesTestMediaClient : public TestMediaClient {
196 void AddSupportedKeySystems(
197 std::vector<KeySystemInfo>* key_systems_info) final;
200 void PotentiallySupportedNamesTestMediaClient::AddSupportedKeySystems(
201 std::vector<KeySystemInfo>* key_systems) {
202 // org.w3.clearkey is automatically registered.
203 AddUsesAesKeySystem("com.widevine.alpha", key_systems);
204 AddUsesAesKeySystem("org.chromium.externalclearkey", key_systems);
205 AddUsesAesKeySystem("org.chromium.externalclearkey.something", key_systems);
206 AddUsesAesKeySystem("com.chromecast.something", key_systems);
207 AddUsesAesKeySystem("x-something", key_systems);
210 class KeySystemsPotentiallySupportedNamesTest : public testing::Test {
211 protected:
212 KeySystemsPotentiallySupportedNamesTest() {
213 SetMediaClient(&test_media_client_);
216 ~KeySystemsPotentiallySupportedNamesTest() override {
217 // Clear the use of |test_media_client_|, which was set in SetUp().
218 SetMediaClient(nullptr);
221 private:
222 PotentiallySupportedNamesTestMediaClient test_media_client_;
225 // TODO(sandersd): Refactor. http://crbug.com/417444
226 class KeySystemsTest : public testing::Test {
227 protected:
228 KeySystemsTest() {
229 vp8_codec_.push_back("vp8");
231 vp80_codec_.push_back("vp8.0");
233 vp9_codec_.push_back("vp9");
235 vp90_codec_.push_back("vp9.0");
237 vorbis_codec_.push_back("vorbis");
239 vp8_and_vorbis_codecs_.push_back("vp8");
240 vp8_and_vorbis_codecs_.push_back("vorbis");
242 vp9_and_vorbis_codecs_.push_back("vp9");
243 vp9_and_vorbis_codecs_.push_back("vorbis");
245 foovideo_codec_.push_back("foovideo");
247 foovideo_extended_codec_.push_back("foovideo.4D400C");
249 foovideo_dot_codec_.push_back("foovideo.");
251 fooaudio_codec_.push_back("fooaudio");
253 foovideo_and_fooaudio_codecs_.push_back("foovideo");
254 foovideo_and_fooaudio_codecs_.push_back("fooaudio");
256 unknown_codec_.push_back("unknown");
258 mixed_codecs_.push_back("vorbis");
259 mixed_codecs_.push_back("foovideo");
261 SetMediaClient(&test_media_client_);
264 void SetUp() override {
265 AddContainerAndCodecMasksForTest();
268 ~KeySystemsTest() override {
269 // Clear the use of |test_media_client_|, which was set in SetUp().
270 SetMediaClient(nullptr);
273 void UpdateClientKeySystems() {
274 test_media_client_.SetKeySystemsUpdateNeeded();
275 test_media_client_.DisableExternalKeySystemSupport();
278 typedef std::vector<std::string> CodecVector;
280 const CodecVector& no_codecs() const { return no_codecs_; }
282 const CodecVector& vp8_codec() const { return vp8_codec_; }
283 const CodecVector& vp80_codec() const { return vp80_codec_; }
284 const CodecVector& vp9_codec() const { return vp9_codec_; }
285 const CodecVector& vp90_codec() const { return vp90_codec_; }
287 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
289 const CodecVector& vp8_and_vorbis_codecs() const {
290 return vp8_and_vorbis_codecs_;
292 const CodecVector& vp9_and_vorbis_codecs() const {
293 return vp9_and_vorbis_codecs_;
296 const CodecVector& foovideo_codec() const { return foovideo_codec_; }
297 const CodecVector& foovideo_extended_codec() const {
298 return foovideo_extended_codec_;
300 const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
301 const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
302 const CodecVector& foovideo_and_fooaudio_codecs() const {
303 return foovideo_and_fooaudio_codecs_;
306 const CodecVector& unknown_codec() const { return unknown_codec_; }
308 const CodecVector& mixed_codecs() const { return mixed_codecs_; }
310 private:
311 const CodecVector no_codecs_;
312 CodecVector vp8_codec_;
313 CodecVector vp80_codec_;
314 CodecVector vp9_codec_;
315 CodecVector vp90_codec_;
316 CodecVector vorbis_codec_;
317 CodecVector vp8_and_vorbis_codecs_;
318 CodecVector vp9_and_vorbis_codecs_;
320 CodecVector foovideo_codec_;
321 CodecVector foovideo_extended_codec_;
322 CodecVector foovideo_dot_codec_;
323 CodecVector fooaudio_codec_;
324 CodecVector foovideo_and_fooaudio_codecs_;
326 CodecVector unknown_codec_;
328 CodecVector mixed_codecs_;
330 TestMediaClient test_media_client_;
333 // TODO(ddorwin): Consider moving GetPepperType() calls out to their own test.
335 TEST_F(KeySystemsTest, EmptyKeySystem) {
336 EXPECT_FALSE(IsSupportedKeySystem(std::string()));
337 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
338 kVideoWebM, no_codecs(), std::string()));
339 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(std::string()));
342 // Clear Key is the only key system registered in content.
343 TEST_F(KeySystemsTest, ClearKey) {
344 EXPECT_TRUE(IsSupportedKeySystem(kClearKey));
345 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
346 kVideoWebM, no_codecs(), kClearKey));
348 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey));
350 // Prefixed Clear Key is not supported internally.
351 EXPECT_FALSE(IsSupportedKeySystem(kPrefixedClearKey));
352 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
353 kVideoWebM, no_codecs(), kPrefixedClearKey));
354 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey));
357 // The key system is not registered and therefore is unrecognized.
358 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
359 static const char* const kUnrecognized = "x-org.example.unrecognized";
361 EXPECT_FALSE(IsSupportedKeySystem(kUnrecognized));
362 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
363 kVideoWebM, no_codecs(), kUnrecognized));
365 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUnrecognized));
367 bool can_use = false;
368 EXPECT_DEBUG_DEATH_PORTABLE(
369 can_use = CanUseAesDecryptor(kUnrecognized),
370 "x-org.example.unrecognized is not a known concrete system");
371 EXPECT_FALSE(can_use);
373 #if defined(ENABLE_PEPPER_CDMS)
374 std::string type;
375 EXPECT_DEBUG_DEATH(
376 type = GetPepperType(kUnrecognized),
377 "x-org.example.unrecognized is not a known concrete system");
378 EXPECT_TRUE(type.empty());
379 #endif
382 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
383 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
384 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
385 kVideoWebM, no_codecs(), kUsesAes));
387 // No UMA value for this test key system.
388 EXPECT_EQ("UseAes", GetKeySystemNameForUMA(kUsesAes));
390 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
391 #if defined(ENABLE_PEPPER_CDMS)
392 std::string type;
393 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
394 "x-org.example.clear is not Pepper-based");
395 EXPECT_TRUE(type.empty());
396 #endif
399 TEST_F(KeySystemsTest,
400 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1) {
401 // Valid video types.
402 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
403 kVideoWebM, vp8_codec(), kUsesAes));
404 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
405 kVideoWebM, vp80_codec(), kUsesAes));
406 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
407 kVideoWebM, vp8_and_vorbis_codecs(), kUsesAes));
408 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
409 kVideoWebM, vp9_codec(), kUsesAes));
410 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
411 kVideoWebM, vp90_codec(), kUsesAes));
412 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
413 kVideoWebM, vp9_and_vorbis_codecs(), kUsesAes));
414 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
415 kVideoWebM, vorbis_codec(), kUsesAes));
417 // Non-Webm codecs.
418 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
419 kVideoWebM, foovideo_codec(), kUsesAes));
420 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
421 kVideoWebM, unknown_codec(), kUsesAes));
422 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
423 kVideoWebM, mixed_codecs(), kUsesAes));
425 // Valid audio types.
426 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
427 kAudioWebM, no_codecs(), kUsesAes));
428 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
429 kAudioWebM, vorbis_codec(), kUsesAes));
431 // Non-audio codecs.
432 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
433 kAudioWebM, vp8_codec(), kUsesAes));
434 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
435 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
436 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
437 kAudioWebM, vp9_codec(), kUsesAes));
438 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
439 kAudioWebM, vp9_and_vorbis_codecs(), kUsesAes));
441 // Non-Webm codec.
442 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
443 kAudioWebM, fooaudio_codec(), kUsesAes));
446 // No parent is registered for UsesAes.
447 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
448 EXPECT_FALSE(IsSupportedKeySystem(kUsesAesParent));
449 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
450 kVideoWebM, no_codecs(), kUsesAesParent));
452 // The parent is not supported for most things.
453 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAesParent));
454 bool result = false;
455 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent),
456 "x-org.example is not a known concrete system");
457 EXPECT_FALSE(result);
458 #if defined(ENABLE_PEPPER_CDMS)
459 std::string type;
460 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
461 "x-org.example is not a known concrete system");
462 EXPECT_TRUE(type.empty());
463 #endif
466 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
467 // Case sensitive.
468 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.ClEaR"));
469 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(),
470 "x-org.example.ClEaR"));
472 // TLDs are not allowed.
473 EXPECT_FALSE(IsSupportedKeySystem("org."));
474 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
475 kVideoWebM, no_codecs(), "org."));
476 EXPECT_FALSE(IsSupportedKeySystem("com"));
477 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
478 kVideoWebM, no_codecs(), "com"));
480 // Extra period.
481 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clear."));
482 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(),
483 "x-org.example.clear."));
484 EXPECT_FALSE(IsSupportedKeySystem("x-org.example."));
485 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(),
486 "x-org.example."));
488 // Incomplete.
489 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clea"));
490 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(),
491 "x-org.example.clea"));
493 // Extra character.
494 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clearz"));
495 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(),
496 "x-org.example.clearz"));
498 // There are no child key systems for UsesAes.
499 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clear.foo"));
500 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
501 kVideoWebM, no_codecs(), "x-org.example.clear.foo"));
504 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
505 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
506 std::string(), no_codecs(), kUsesAes));
507 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
508 std::string(), no_codecs(), kUsesAesParent));
510 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(std::string(), no_codecs(),
511 "x-org.example.foo"));
512 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
513 std::string(), no_codecs(), "x-org.example.clear.foo"));
516 // Tests the second registered container type.
517 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
518 TEST_F(KeySystemsTest,
519 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
520 // Valid video types.
521 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
522 kVideoFoo, no_codecs(), kUsesAes));
523 // The parent should be supported but is not. See http://crbug.com/164303.
524 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
525 kVideoFoo, no_codecs(), kUsesAesParent));
526 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
527 kVideoFoo, foovideo_codec(), kUsesAes));
528 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
529 kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
530 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
531 kVideoFoo, fooaudio_codec(), kUsesAes));
533 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
534 // They should really pass canPlayType().
535 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
536 kVideoFoo, foovideo_extended_codec(), kUsesAes));
538 // Invalid codec format.
539 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
540 kVideoFoo, foovideo_dot_codec(), kUsesAes));
542 // Non-container2 codec.
543 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
544 kVideoFoo, vp8_codec(), kUsesAes));
545 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
546 kVideoFoo, unknown_codec(), kUsesAes));
547 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
548 kVideoFoo, mixed_codecs(), kUsesAes));
550 // Valid audio types.
551 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
552 kAudioFoo, no_codecs(), kUsesAes));
553 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
554 kAudioFoo, fooaudio_codec(), kUsesAes));
556 // Non-audio codecs.
557 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
558 kAudioFoo, foovideo_codec(), kUsesAes));
559 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
560 kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
562 // Non-container2 codec.
563 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
564 kAudioFoo, vorbis_codec(), kUsesAes));
568 // Non-AesDecryptor-based key system.
571 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
572 EXPECT_TRUE(IsSupportedKeySystem(kExternal));
573 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
574 kVideoWebM, no_codecs(), kExternal));
576 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
577 #if defined(ENABLE_PEPPER_CDMS)
578 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
579 #endif // defined(ENABLE_PEPPER_CDMS)
582 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
583 // The parent system is not a concrete system but is supported.
584 EXPECT_FALSE(IsSupportedKeySystem(kExternalParent));
585 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
586 kVideoWebM, no_codecs(), kExternalParent));
587 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
588 kVideoWebM, no_codecs(), kExternalParent));
590 // The parent is not supported for most things.
591 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalParent));
592 bool result = false;
593 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
594 "x-com.example is not a known concrete system");
595 EXPECT_FALSE(result);
596 #if defined(ENABLE_PEPPER_CDMS)
597 std::string type;
598 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
599 "x-com.example is not a known concrete system");
600 EXPECT_TRUE(type.empty());
601 #endif
604 TEST_F(
605 KeySystemsTest,
606 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
607 // Valid video types.
608 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
609 kVideoWebM, no_codecs(), kExternal));
610 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
611 kVideoWebM, vp8_codec(), kExternal));
612 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
613 kVideoWebM, vp80_codec(), kExternal));
614 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
615 kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
616 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
617 kVideoWebM, vp9_codec(), kExternal));
618 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
619 kVideoWebM, vp90_codec(), kExternal));
620 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
621 kVideoWebM, vp9_and_vorbis_codecs(), kExternal));
622 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
623 kVideoWebM, vorbis_codec(), kExternal));
625 // Valid video types - parent key system.
626 // Unprefixed has no parent key system support.
627 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
628 kVideoWebM, no_codecs(), kExternalParent));
629 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
630 kVideoWebM, vp8_codec(), kExternalParent));
631 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
632 kVideoWebM, vp80_codec(), kExternalParent));
633 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
634 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
635 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
636 kVideoWebM, vp9_codec(), kExternalParent));
637 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
638 kVideoWebM, vp90_codec(), kExternalParent));
639 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
640 kVideoWebM, vp9_and_vorbis_codecs(), kExternalParent));
641 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
642 kVideoWebM, vorbis_codec(), kExternalParent));
643 // Prefixed has parent key system support.
644 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
645 kVideoWebM, no_codecs(), kExternalParent));
646 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
647 kVideoWebM, vp8_codec(), kExternalParent));
648 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
649 kVideoWebM, vp80_codec(), kExternalParent));
650 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
651 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
652 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
653 kVideoWebM, vp9_codec(), kExternalParent));
654 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
655 kVideoWebM, vp90_codec(), kExternalParent));
656 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
657 kVideoWebM, vp9_and_vorbis_codecs(), kExternalParent));
658 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
659 kVideoWebM, vorbis_codec(), kExternalParent));
661 // Non-Webm codecs.
662 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
663 kVideoWebM, foovideo_codec(), kExternal));
664 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
665 kVideoWebM, unknown_codec(), kExternal));
666 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
667 kVideoWebM, mixed_codecs(), kExternal));
669 // Valid audio types.
670 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
671 kAudioWebM, no_codecs(), kExternal));
672 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
673 kAudioWebM, vorbis_codec(), kExternal));
675 // Valid audio types - parent key system.
676 // Unprefixed has no parent key system support.
677 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
678 kAudioWebM, no_codecs(), kExternalParent));
679 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
680 kAudioWebM, vorbis_codec(), kExternalParent));
681 // Prefixed has parent key system support.
682 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
683 kAudioWebM, no_codecs(), kExternalParent));
684 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
685 kAudioWebM, vorbis_codec(), kExternalParent));
687 // Non-audio codecs.
688 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
689 kAudioWebM, vp8_codec(), kExternal));
690 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
691 kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
692 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
693 kAudioWebM, vp9_codec(), kExternal));
694 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
695 kAudioWebM, vp9_and_vorbis_codecs(), kExternal));
697 // Non-Webm codec.
698 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
699 kAudioWebM, fooaudio_codec(), kExternal));
702 TEST_F(
703 KeySystemsTest,
704 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
705 // Valid video types.
706 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
707 kVideoFoo, no_codecs(), kExternal));
708 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
709 kVideoFoo, foovideo_codec(), kExternal));
710 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
711 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
712 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
713 kVideoFoo, fooaudio_codec(), kExternal));
715 // Valid video types - parent key system.
716 // Unprefixed has no parent key system support.
717 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
718 kVideoFoo, no_codecs(), kExternalParent));
719 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
720 kVideoFoo, foovideo_codec(), kExternalParent));
721 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
722 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
723 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
724 kVideoFoo, fooaudio_codec(), kExternalParent));
725 // Prefixed has parent key system support.
726 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
727 kVideoFoo, no_codecs(), kExternalParent));
728 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
729 kVideoFoo, foovideo_codec(), kExternalParent));
730 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
731 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
732 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
733 kVideoFoo, fooaudio_codec(), kExternalParent));
735 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
736 // They should really pass canPlayType().
737 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
738 kVideoFoo, foovideo_extended_codec(), kExternal));
740 // Invalid codec format.
741 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
742 kVideoFoo, foovideo_dot_codec(), kExternal));
744 // Non-container2 codecs.
745 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
746 kVideoFoo, vp8_codec(), kExternal));
747 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
748 kVideoFoo, unknown_codec(), kExternal));
749 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
750 kVideoFoo, mixed_codecs(), kExternal));
752 // Valid audio types.
753 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
754 kAudioFoo, no_codecs(), kExternal));
755 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
756 kAudioFoo, fooaudio_codec(), kExternal));
758 // Valid audio types - parent key system.
759 // Unprefixed has no parent key system support.
760 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
761 kAudioFoo, no_codecs(), kExternalParent));
762 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
763 kAudioFoo, fooaudio_codec(), kExternalParent));
764 // Prefixed has parent key system support.
765 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
766 kAudioFoo, no_codecs(), kExternalParent));
767 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
768 kAudioFoo, fooaudio_codec(), kExternalParent));
770 // Non-audio codecs.
771 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
772 kAudioFoo, foovideo_codec(), kExternal));
773 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
774 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
776 // Non-container2 codec.
777 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
778 kAudioFoo, vorbis_codec(), kExternal));
781 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
782 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey));
783 // Prefixed is not supported internally.
784 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey));
786 // External Clear Key never has a UMA name.
787 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey));
790 TEST_F(KeySystemsTest, KeySystemsUpdate) {
791 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
792 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
793 kVideoWebM, no_codecs(), kUsesAes));
794 EXPECT_TRUE(IsSupportedKeySystem(kExternal));
795 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
796 kVideoWebM, no_codecs(), kExternal));
798 UpdateClientKeySystems();
800 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
801 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
802 kVideoWebM, no_codecs(), kUsesAes));
803 EXPECT_FALSE(IsSupportedKeySystem(kExternal));
804 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
805 kVideoWebM, no_codecs(), kExternal));
808 TEST_F(KeySystemsTest, PrefixedKeySystemsUpdate) {
809 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
810 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
811 kVideoWebM, no_codecs(), kUsesAes));
812 EXPECT_TRUE(IsSupportedKeySystem(kExternal));
813 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
814 kVideoWebM, no_codecs(), kExternal));
816 UpdateClientKeySystems();
818 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
819 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
820 kVideoWebM, no_codecs(), kUsesAes));
821 EXPECT_FALSE(IsSupportedKeySystem(kExternal));
822 EXPECT_FALSE(PrefixedIsSupportedKeySystemWithMediaMimeType(
823 kVideoWebM, no_codecs(), kExternal));
826 TEST_F(KeySystemsPotentiallySupportedNamesTest, PotentiallySupportedNames) {
827 EXPECT_FALSE(IsSupportedKeySystem("org.w3"));
828 EXPECT_FALSE(IsSupportedKeySystem("org.w3."));
829 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearke"));
830 EXPECT_TRUE(IsSupportedKeySystem("org.w3.clearkey"));
831 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkeys"));
833 EXPECT_FALSE(IsSupportedKeySystem("com.widevine"));
834 EXPECT_FALSE(IsSupportedKeySystem("com.widevine."));
835 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph"));
836 EXPECT_TRUE(IsSupportedKeySystem("com.widevine.alpha"));
837 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.beta"));
838 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphabeta"));
839 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.beta"));
841 EXPECT_FALSE(IsSupportedKeySystem("org.chromium"));
842 EXPECT_FALSE(IsSupportedKeySystem("org.chromium."));
843 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke"));
844 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey"));
845 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeys"));
846 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey."));
847 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey.something"));
848 EXPECT_FALSE(
849 IsSupportedKeySystem("org.chromium.externalclearkey.something.else"));
850 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.other"));
851 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.other"));
853 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast"));
854 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast."));
855 EXPECT_TRUE(IsSupportedKeySystem("com.chromecast.something"));
856 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else"));
857 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other"));
859 EXPECT_FALSE(IsSupportedKeySystem("x-"));
860 EXPECT_TRUE(IsSupportedKeySystem("x-something"));
861 EXPECT_FALSE(IsSupportedKeySystem("x-something.else"));
862 EXPECT_FALSE(IsSupportedKeySystem("x-other"));
865 } // namespace media