Change blimp README to use Markdown.
[chromium-blink-merge.git] / media / base / key_systems_unittest.cc
blobb97852d132f87e41a0de773221ce720b15a858d8
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
12 #include <string>
13 #include <vector>
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 namespace media {
24 // These are the (fake) key systems that are registered for these tests.
25 // kUsesAes uses the AesDecryptor like Clear Key.
26 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
27 const char kUsesAes[] = "x-org.example.clear";
28 const char kUsesAesParent[] = "x-org.example"; // Not registered.
29 const char kUseAesNameForUMA[] = "UseAes";
30 const char kExternal[] = "x-com.example.test";
31 const char kExternalParent[] = "x-com.example";
32 const char kExternalNameForUMA[] = "External";
34 const char kClearKey[] = "org.w3.clearkey";
35 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
36 const char kExternalClearKey[] = "org.chromium.externalclearkey";
38 const char kAudioWebM[] = "audio/webm";
39 const char kVideoWebM[] = "video/webm";
40 const char kAudioFoo[] = "audio/foo";
41 const char kVideoFoo[] = "video/foo";
43 // Pick some arbitrary bit fields as long as they are not in conflict with the
44 // real ones.
45 enum TestCodec {
46 TEST_CODEC_FOO_AUDIO = 1 << 10, // An audio codec for foo container.
47 TEST_CODEC_FOO_AUDIO_ALL = TEST_CODEC_FOO_AUDIO,
48 TEST_CODEC_FOO_VIDEO = 1 << 11, // A video codec for foo container.
49 TEST_CODEC_FOO_VIDEO_ALL = TEST_CODEC_FOO_VIDEO,
50 TEST_CODEC_FOO_ALL = TEST_CODEC_FOO_AUDIO_ALL | TEST_CODEC_FOO_VIDEO_ALL
53 static_assert((TEST_CODEC_FOO_ALL & EME_CODEC_ALL) == EME_CODEC_NONE,
54 "test codec masks should only use invalid codec masks");
56 // Adapt IsSupportedKeySystemWithMediaMimeType() to the new API,
57 // IsSupportedCodecCombination().
58 static bool IsSupportedKeySystemWithMediaMimeType(
59 const std::string& mime_type,
60 const std::vector<std::string>& codecs,
61 const std::string& key_system) {
62 return (KeySystems::GetInstance()->GetContentTypeConfigRule(
63 key_system, EmeMediaType::VIDEO, mime_type, codecs) !=
64 EmeConfigRule::NOT_SUPPORTED);
67 static bool IsSupportedKeySystemWithAudioMimeType(
68 const std::string& mime_type,
69 const std::vector<std::string>& codecs,
70 const std::string& key_system) {
71 return (KeySystems::GetInstance()->GetContentTypeConfigRule(
72 key_system, EmeMediaType::AUDIO, mime_type, codecs) !=
73 EmeConfigRule::NOT_SUPPORTED);
76 // Adds test container and codec masks.
77 // This function must be called after SetMediaClient() if a MediaClient will be
78 // provided.
79 // More details: AddXxxMask() will create KeySystems if it hasn't been created.
80 // During KeySystems's construction GetMediaClient() will be used to add key
81 // systems. In test code, the MediaClient is set by SetMediaClient().
82 // Therefore, SetMediaClient() must be called before this function to make sure
83 // MediaClient in effect when constructing KeySystems.
84 static void AddContainerAndCodecMasksForTest() {
85 // Since KeySystems is a singleton. Make sure we only add test container and
86 // codec masks once per process.
87 static bool is_test_masks_added = false;
89 if (is_test_masks_added)
90 return;
92 AddContainerMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL);
93 AddContainerMask("video/foo", TEST_CODEC_FOO_ALL);
94 AddCodecMask(EmeMediaType::AUDIO, "fooaudio", TEST_CODEC_FOO_AUDIO);
95 AddCodecMask(EmeMediaType::VIDEO, "foovideo", TEST_CODEC_FOO_VIDEO);
97 is_test_masks_added = true;
100 class TestMediaClient : public MediaClient {
101 public:
102 TestMediaClient();
103 ~TestMediaClient() override;
105 // MediaClient implementation.
106 void AddKeySystemsInfoForUMA(
107 std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) final;
108 bool IsKeySystemsUpdateNeeded() final;
109 void AddSupportedKeySystems(
110 std::vector<KeySystemInfo>* key_systems_info) override;
111 void RecordRapporURL(const std::string& metric, const GURL& url) final;
113 // Helper function to test the case where IsKeySystemsUpdateNeeded() is true
114 // after AddSupportedKeySystems() is called.
115 void SetKeySystemsUpdateNeeded();
117 // Helper function to disable "kExternal" key system support so that we can
118 // test the key system update case.
119 void DisableExternalKeySystemSupport();
121 protected:
122 void AddUsesAesKeySystem(const std::string& name,
123 std::vector<KeySystemInfo>* key_systems_info);
124 void AddExternalKeySystem(
125 std::vector<KeySystemInfo>* key_systems_info);
127 private:
128 bool is_update_needed_;
129 bool supports_external_key_system_;
132 TestMediaClient::TestMediaClient()
133 : is_update_needed_(true), supports_external_key_system_(true) {
136 TestMediaClient::~TestMediaClient() {
139 void TestMediaClient::AddKeySystemsInfoForUMA(
140 std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) {
141 key_systems_info_for_uma->push_back(
142 media::KeySystemInfoForUMA(kUsesAes, kUseAesNameForUMA, false));
143 key_systems_info_for_uma->push_back(
144 media::KeySystemInfoForUMA(kExternal, kExternalNameForUMA, true));
147 bool TestMediaClient::IsKeySystemsUpdateNeeded() {
148 return is_update_needed_;
151 void TestMediaClient::AddSupportedKeySystems(
152 std::vector<KeySystemInfo>* key_systems) {
153 DCHECK(is_update_needed_);
155 AddUsesAesKeySystem(kUsesAes, key_systems);
157 if (supports_external_key_system_)
158 AddExternalKeySystem(key_systems);
160 is_update_needed_ = false;
163 void TestMediaClient::RecordRapporURL(const std::string& /* metric */,
164 const GURL& /* url */) {
165 NOTIMPLEMENTED();
168 void TestMediaClient::SetKeySystemsUpdateNeeded() {
169 is_update_needed_ = true;
172 void TestMediaClient::DisableExternalKeySystemSupport() {
173 supports_external_key_system_ = false;
176 void TestMediaClient::AddUsesAesKeySystem(
177 const std::string& name,
178 std::vector<KeySystemInfo>* key_systems) {
179 KeySystemInfo system;
180 system.key_system = name;
181 system.supported_codecs = EME_CODEC_WEBM_ALL;
182 system.supported_codecs |= TEST_CODEC_FOO_ALL;
183 system.supported_init_data_types = kInitDataTypeMaskWebM;
184 system.max_audio_robustness = EmeRobustness::EMPTY;
185 system.max_video_robustness = EmeRobustness::EMPTY;
186 system.persistent_license_support = EmeSessionTypeSupport::NOT_SUPPORTED;
187 system.persistent_release_message_support =
188 EmeSessionTypeSupport::NOT_SUPPORTED;
189 system.persistent_state_support = EmeFeatureSupport::NOT_SUPPORTED;
190 system.distinctive_identifier_support = EmeFeatureSupport::NOT_SUPPORTED;
191 system.use_aes_decryptor = true;
192 key_systems->push_back(system);
195 void TestMediaClient::AddExternalKeySystem(
196 std::vector<KeySystemInfo>* key_systems) {
197 KeySystemInfo ext;
198 ext.key_system = kExternal;
199 ext.supported_codecs = EME_CODEC_WEBM_ALL;
200 ext.supported_codecs |= TEST_CODEC_FOO_ALL;
201 ext.supported_init_data_types = kInitDataTypeMaskWebM;
202 ext.max_audio_robustness = EmeRobustness::EMPTY;
203 ext.max_video_robustness = EmeRobustness::EMPTY;
204 ext.persistent_license_support = EmeSessionTypeSupport::SUPPORTED;
205 ext.persistent_release_message_support = EmeSessionTypeSupport::NOT_SUPPORTED;
206 ext.persistent_state_support = EmeFeatureSupport::ALWAYS_ENABLED;
207 ext.distinctive_identifier_support = EmeFeatureSupport::ALWAYS_ENABLED;
208 ext.parent_key_system = kExternalParent;
209 #if defined(ENABLE_PEPPER_CDMS)
210 ext.pepper_type = "application/x-ppapi-external-cdm";
211 #endif // defined(ENABLE_PEPPER_CDMS)
212 key_systems->push_back(ext);
215 class PotentiallySupportedNamesTestMediaClient : public TestMediaClient {
216 void AddSupportedKeySystems(
217 std::vector<KeySystemInfo>* key_systems_info) final;
220 void PotentiallySupportedNamesTestMediaClient::AddSupportedKeySystems(
221 std::vector<KeySystemInfo>* key_systems) {
222 // org.w3.clearkey is automatically registered.
223 AddUsesAesKeySystem("com.widevine.alpha", key_systems);
224 AddUsesAesKeySystem("org.chromium.externalclearkey", key_systems);
225 AddUsesAesKeySystem("org.chromium.externalclearkey.something", key_systems);
226 AddUsesAesKeySystem("com.chromecast.something", key_systems);
227 AddUsesAesKeySystem("x-something", key_systems);
230 class KeySystemsPotentiallySupportedNamesTest : public testing::Test {
231 protected:
232 KeySystemsPotentiallySupportedNamesTest() {
233 SetMediaClient(&test_media_client_);
236 ~KeySystemsPotentiallySupportedNamesTest() override {
237 // Clear the use of |test_media_client_|, which was set in SetUp().
238 SetMediaClient(nullptr);
241 private:
242 PotentiallySupportedNamesTestMediaClient test_media_client_;
245 class KeySystemsTest : public testing::Test {
246 protected:
247 KeySystemsTest() {
248 vp8_codec_.push_back("vp8");
250 vp80_codec_.push_back("vp8.0");
252 vp9_codec_.push_back("vp9");
254 vp90_codec_.push_back("vp9.0");
256 vorbis_codec_.push_back("vorbis");
258 vp8_and_vorbis_codecs_.push_back("vp8");
259 vp8_and_vorbis_codecs_.push_back("vorbis");
261 vp9_and_vorbis_codecs_.push_back("vp9");
262 vp9_and_vorbis_codecs_.push_back("vorbis");
264 foovideo_codec_.push_back("foovideo");
266 foovideo_extended_codec_.push_back("foovideo.4D400C");
268 foovideo_dot_codec_.push_back("foovideo.");
270 fooaudio_codec_.push_back("fooaudio");
272 foovideo_and_fooaudio_codecs_.push_back("foovideo");
273 foovideo_and_fooaudio_codecs_.push_back("fooaudio");
275 unknown_codec_.push_back("unknown");
277 mixed_codecs_.push_back("vorbis");
278 mixed_codecs_.push_back("foovideo");
280 SetMediaClient(&test_media_client_);
283 void SetUp() override {
284 AddContainerAndCodecMasksForTest();
287 ~KeySystemsTest() override {
288 // Clear the use of |test_media_client_|, which was set in SetUp().
289 SetMediaClient(nullptr);
292 void UpdateClientKeySystems() {
293 test_media_client_.SetKeySystemsUpdateNeeded();
294 test_media_client_.DisableExternalKeySystemSupport();
297 typedef std::vector<std::string> CodecVector;
299 const CodecVector& no_codecs() const { return no_codecs_; }
301 const CodecVector& vp8_codec() const { return vp8_codec_; }
302 const CodecVector& vp80_codec() const { return vp80_codec_; }
303 const CodecVector& vp9_codec() const { return vp9_codec_; }
304 const CodecVector& vp90_codec() const { return vp90_codec_; }
306 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
308 const CodecVector& vp8_and_vorbis_codecs() const {
309 return vp8_and_vorbis_codecs_;
311 const CodecVector& vp9_and_vorbis_codecs() const {
312 return vp9_and_vorbis_codecs_;
315 const CodecVector& foovideo_codec() const { return foovideo_codec_; }
316 const CodecVector& foovideo_extended_codec() const {
317 return foovideo_extended_codec_;
319 const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
320 const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
321 const CodecVector& foovideo_and_fooaudio_codecs() const {
322 return foovideo_and_fooaudio_codecs_;
325 const CodecVector& unknown_codec() const { return unknown_codec_; }
327 const CodecVector& mixed_codecs() const { return mixed_codecs_; }
329 private:
330 const CodecVector no_codecs_;
331 CodecVector vp8_codec_;
332 CodecVector vp80_codec_;
333 CodecVector vp9_codec_;
334 CodecVector vp90_codec_;
335 CodecVector vorbis_codec_;
336 CodecVector vp8_and_vorbis_codecs_;
337 CodecVector vp9_and_vorbis_codecs_;
339 CodecVector foovideo_codec_;
340 CodecVector foovideo_extended_codec_;
341 CodecVector foovideo_dot_codec_;
342 CodecVector fooaudio_codec_;
343 CodecVector foovideo_and_fooaudio_codecs_;
345 CodecVector unknown_codec_;
347 CodecVector mixed_codecs_;
349 TestMediaClient test_media_client_;
352 // TODO(ddorwin): Consider moving GetPepperType() calls out to their own test.
354 TEST_F(KeySystemsTest, EmptyKeySystem) {
355 EXPECT_FALSE(IsSupportedKeySystem(std::string()));
356 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(std::string()));
359 // Clear Key is the only key system registered in content.
360 TEST_F(KeySystemsTest, ClearKey) {
361 EXPECT_TRUE(IsSupportedKeySystem(kClearKey));
362 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
363 kVideoWebM, no_codecs(), kClearKey));
365 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey));
367 // Prefixed Clear Key is not supported internally.
368 EXPECT_FALSE(IsSupportedKeySystem(kPrefixedClearKey));
369 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey));
372 TEST_F(KeySystemsTest, ClearKeyWithInitDataType) {
373 EXPECT_TRUE(IsSupportedKeySystem(kClearKey));
374 EXPECT_TRUE(
375 IsSupportedKeySystemWithInitDataType(kClearKey, EmeInitDataType::WEBM));
376 EXPECT_TRUE(
377 IsSupportedKeySystemWithInitDataType(kClearKey, EmeInitDataType::KEYIDS));
379 // All other InitDataTypes are not supported.
380 EXPECT_FALSE(IsSupportedKeySystemWithInitDataType(kClearKey,
381 EmeInitDataType::UNKNOWN));
384 // The key system is not registered and therefore is unrecognized.
385 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
386 static const char* const kUnrecognized = "x-org.example.unrecognized";
388 EXPECT_FALSE(IsSupportedKeySystem(kUnrecognized));
390 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUnrecognized));
391 EXPECT_FALSE(CanUseAesDecryptor(kUnrecognized));
393 #if defined(ENABLE_PEPPER_CDMS)
394 std::string type;
395 EXPECT_DEBUG_DEATH(
396 type = GetPepperType(kUnrecognized),
397 "x-org.example.unrecognized is not a known concrete system");
398 EXPECT_TRUE(type.empty());
399 #endif
402 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
403 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
404 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
405 kVideoWebM, no_codecs(), kUsesAes));
407 // No UMA value for this test key system.
408 EXPECT_EQ("UseAes", GetKeySystemNameForUMA(kUsesAes));
410 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
411 #if defined(ENABLE_PEPPER_CDMS)
412 std::string type;
413 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
414 "x-org.example.clear is not Pepper-based");
415 EXPECT_TRUE(type.empty());
416 #endif
419 TEST_F(KeySystemsTest,
420 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1) {
421 // Valid video types.
422 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
423 kVideoWebM, vp8_codec(), kUsesAes));
424 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
425 kVideoWebM, vp80_codec(), kUsesAes));
426 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
427 kVideoWebM, vp9_codec(), kUsesAes));
428 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
429 kVideoWebM, vp90_codec(), kUsesAes));
431 // Audio in a video container.
432 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
433 kVideoWebM, vp8_and_vorbis_codecs(), kUsesAes));
434 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
435 kVideoWebM, vp9_and_vorbis_codecs(), kUsesAes));
436 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
437 kVideoWebM, vorbis_codec(), kUsesAes));
439 // Non-Webm codecs.
440 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
441 kVideoWebM, foovideo_codec(), kUsesAes));
442 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
443 kVideoWebM, unknown_codec(), kUsesAes));
444 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
445 kVideoWebM, mixed_codecs(), kUsesAes));
447 // Valid audio types.
448 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
449 kAudioWebM, no_codecs(), kUsesAes));
450 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
451 kAudioWebM, vorbis_codec(), kUsesAes));
453 // Non-audio codecs.
454 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
455 kAudioWebM, vp8_codec(), kUsesAes));
456 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
457 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
458 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
459 kAudioWebM, vp9_codec(), kUsesAes));
460 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
461 kAudioWebM, vp9_and_vorbis_codecs(), kUsesAes));
463 // Non-Webm codec.
464 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
465 kAudioWebM, fooaudio_codec(), kUsesAes));
468 // No parent is registered for UsesAes.
469 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
470 EXPECT_FALSE(IsSupportedKeySystem(kUsesAesParent));
472 // The parent is not supported for most things.
473 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAesParent));
474 EXPECT_FALSE(CanUseAesDecryptor(kUsesAesParent));
476 #if defined(ENABLE_PEPPER_CDMS)
477 std::string type;
478 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
479 "x-org.example is not a known concrete system");
480 EXPECT_TRUE(type.empty());
481 #endif
484 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
485 // Case sensitive.
486 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.ClEaR"));
488 // TLDs are not allowed.
489 EXPECT_FALSE(IsSupportedKeySystem("org."));
490 EXPECT_FALSE(IsSupportedKeySystem("com"));
492 // Extra period.
493 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clear."));
494 EXPECT_FALSE(IsSupportedKeySystem("x-org.example."));
496 // Incomplete.
497 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clea"));
499 // Extra character.
500 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clearz"));
502 // There are no child key systems for UsesAes.
503 EXPECT_FALSE(IsSupportedKeySystem("x-org.example.clear.foo"));
506 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
507 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
508 std::string(), no_codecs(), kUsesAes));
509 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
510 std::string(), no_codecs(), kUsesAesParent));
512 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(std::string(), no_codecs(),
513 "x-org.example.foo"));
514 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
515 std::string(), no_codecs(), "x-org.example.clear.foo"));
518 // Tests the second registered container type.
519 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
520 TEST_F(KeySystemsTest,
521 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
522 // Valid video types.
523 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
524 kVideoFoo, no_codecs(), kUsesAes));
525 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
526 kVideoFoo, foovideo_codec(), kUsesAes));
528 // Audio in a video container.
529 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
530 kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
531 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
532 kVideoFoo, fooaudio_codec(), kUsesAes));
534 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
535 // They should really pass canPlayType().
536 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
537 kVideoFoo, foovideo_extended_codec(), kUsesAes));
539 // Invalid codec format.
540 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
541 kVideoFoo, foovideo_dot_codec(), kUsesAes));
543 // Non-container2 codec.
544 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
545 kVideoFoo, vp8_codec(), kUsesAes));
546 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
547 kVideoFoo, unknown_codec(), kUsesAes));
548 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
549 kVideoFoo, mixed_codecs(), kUsesAes));
551 // Valid audio types.
552 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
553 kAudioFoo, no_codecs(), kUsesAes));
554 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
555 kAudioFoo, fooaudio_codec(), kUsesAes));
557 // Non-audio codecs.
558 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
559 kAudioFoo, foovideo_codec(), kUsesAes));
560 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
561 kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
563 // Non-container2 codec.
564 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
565 kAudioFoo, vorbis_codec(), kUsesAes));
569 // Non-AesDecryptor-based key system.
572 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
573 EXPECT_TRUE(IsSupportedKeySystem(kExternal));
574 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
575 kVideoWebM, no_codecs(), kExternal));
577 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
578 #if defined(ENABLE_PEPPER_CDMS)
579 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
580 #endif // defined(ENABLE_PEPPER_CDMS)
583 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
584 // Unprefixed has no parent key system support.
585 EXPECT_FALSE(IsSupportedKeySystem(kExternalParent));
586 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
587 kVideoWebM, no_codecs(), kExternalParent));
589 // The parent is not supported for most things.
590 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalParent));
591 EXPECT_FALSE(CanUseAesDecryptor(kExternalParent));
593 #if defined(ENABLE_PEPPER_CDMS)
594 std::string type;
595 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
596 "x-com.example is not a known concrete system");
597 EXPECT_TRUE(type.empty());
598 #endif
601 TEST_F(
602 KeySystemsTest,
603 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
604 // Valid video types.
605 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
606 kVideoWebM, no_codecs(), kExternal));
607 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
608 kVideoWebM, vp8_codec(), kExternal));
609 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
610 kVideoWebM, vp80_codec(), kExternal));
611 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
612 kVideoWebM, vp9_codec(), kExternal));
613 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
614 kVideoWebM, vp90_codec(), kExternal));
616 // Audio in a video container.
617 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
618 kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
619 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
620 kVideoWebM, vp9_and_vorbis_codecs(), kExternal));
621 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
622 kVideoWebM, vorbis_codec(), kExternal));
624 // Valid video types - parent key system.
625 // Prefixed has parent key system support.
626 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
627 kVideoWebM, no_codecs(), kExternalParent));
628 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
629 kVideoWebM, vp8_codec(), kExternalParent));
630 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
631 kVideoWebM, vp80_codec(), kExternalParent));
632 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
633 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
634 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
635 kVideoWebM, vp9_codec(), kExternalParent));
636 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
637 kVideoWebM, vp90_codec(), kExternalParent));
638 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
639 kVideoWebM, vp9_and_vorbis_codecs(), kExternalParent));
640 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
641 kVideoWebM, vorbis_codec(), kExternalParent));
643 // Non-Webm codecs.
644 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
645 kVideoWebM, foovideo_codec(), kExternal));
646 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
647 kVideoWebM, unknown_codec(), kExternal));
648 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
649 kVideoWebM, mixed_codecs(), kExternal));
651 // Valid audio types.
652 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
653 kAudioWebM, no_codecs(), kExternal));
654 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
655 kAudioWebM, vorbis_codec(), kExternal));
657 // Valid audio types - parent key system.
658 // Prefixed has parent key system support.
659 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
660 kAudioWebM, no_codecs(), kExternalParent));
661 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
662 kAudioWebM, vorbis_codec(), kExternalParent));
664 // Non-audio codecs.
665 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
666 kAudioWebM, vp8_codec(), kExternal));
667 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
668 kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
669 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
670 kAudioWebM, vp9_codec(), kExternal));
671 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
672 kAudioWebM, vp9_and_vorbis_codecs(), kExternal));
674 // Non-Webm codec.
675 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
676 kAudioWebM, fooaudio_codec(), kExternal));
679 TEST_F(
680 KeySystemsTest,
681 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
682 // Valid video types.
683 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
684 kVideoFoo, no_codecs(), kExternal));
685 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
686 kVideoFoo, foovideo_codec(), kExternal));
688 // Audio in a video container.
689 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
690 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
691 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
692 kVideoFoo, fooaudio_codec(), kExternal));
694 // Valid video types - parent key system.
695 // Prefixed has parent key system support.
696 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
697 kVideoFoo, no_codecs(), kExternalParent));
698 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
699 kVideoFoo, foovideo_codec(), kExternalParent));
700 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
701 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
702 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
703 kVideoFoo, fooaudio_codec(), kExternalParent));
705 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
706 // They should really pass canPlayType().
707 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
708 kVideoFoo, foovideo_extended_codec(), kExternal));
710 // Invalid codec format.
711 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
712 kVideoFoo, foovideo_dot_codec(), kExternal));
714 // Non-container2 codecs.
715 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
716 kVideoFoo, vp8_codec(), kExternal));
717 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
718 kVideoFoo, unknown_codec(), kExternal));
719 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
720 kVideoFoo, mixed_codecs(), kExternal));
722 // Valid audio types.
723 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
724 kAudioFoo, no_codecs(), kExternal));
725 EXPECT_TRUE(IsSupportedKeySystemWithAudioMimeType(
726 kAudioFoo, fooaudio_codec(), kExternal));
728 // Valid audio types - parent key system.
729 // Prefixed has parent key system support.
730 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
731 kAudioFoo, no_codecs(), kExternalParent));
732 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
733 kAudioFoo, fooaudio_codec(), kExternalParent));
735 // Non-audio codecs.
736 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
737 kAudioFoo, foovideo_codec(), kExternal));
738 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
739 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
741 // Non-container2 codec.
742 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
743 kAudioFoo, vorbis_codec(), kExternal));
746 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
747 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey));
748 // Prefixed is not supported internally.
749 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey));
751 // External Clear Key never has a UMA name.
752 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey));
755 TEST_F(KeySystemsTest, KeySystemsUpdate) {
756 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
757 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
758 kVideoWebM, no_codecs(), kUsesAes));
759 EXPECT_TRUE(IsSupportedKeySystem(kExternal));
760 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
761 kVideoWebM, no_codecs(), kExternal));
763 UpdateClientKeySystems();
765 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
766 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
767 kVideoWebM, no_codecs(), kUsesAes));
768 EXPECT_FALSE(IsSupportedKeySystem(kExternal));
771 TEST_F(KeySystemsTest, PrefixedKeySystemsUpdate) {
772 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
773 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
774 kVideoWebM, no_codecs(), kUsesAes));
775 EXPECT_TRUE(IsSupportedKeySystem(kExternal));
776 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
777 kVideoWebM, no_codecs(), kExternal));
779 UpdateClientKeySystems();
781 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
782 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
783 kVideoWebM, no_codecs(), kUsesAes));
784 EXPECT_FALSE(IsSupportedKeySystem(kExternal));
785 EXPECT_FALSE(PrefixedIsSupportedKeySystemWithMediaMimeType(
786 kVideoWebM, no_codecs(), kExternal));
789 TEST_F(KeySystemsPotentiallySupportedNamesTest, PotentiallySupportedNames) {
790 EXPECT_FALSE(IsSupportedKeySystem("org.w3"));
791 EXPECT_FALSE(IsSupportedKeySystem("org.w3."));
792 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearke"));
793 EXPECT_TRUE(IsSupportedKeySystem("org.w3.clearkey"));
794 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkeys"));
796 EXPECT_FALSE(IsSupportedKeySystem("com.widevine"));
797 EXPECT_FALSE(IsSupportedKeySystem("com.widevine."));
798 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph"));
799 EXPECT_TRUE(IsSupportedKeySystem("com.widevine.alpha"));
800 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.beta"));
801 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphabeta"));
802 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.beta"));
804 EXPECT_FALSE(IsSupportedKeySystem("org.chromium"));
805 EXPECT_FALSE(IsSupportedKeySystem("org.chromium."));
806 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke"));
807 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey"));
808 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeys"));
809 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey."));
810 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey.something"));
811 EXPECT_FALSE(
812 IsSupportedKeySystem("org.chromium.externalclearkey.something.else"));
813 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.other"));
814 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.other"));
816 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast"));
817 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast."));
818 EXPECT_TRUE(IsSupportedKeySystem("com.chromecast.something"));
819 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else"));
820 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other"));
822 EXPECT_FALSE(IsSupportedKeySystem("x-"));
823 EXPECT_TRUE(IsSupportedKeySystem("x-something"));
824 EXPECT_FALSE(IsSupportedKeySystem("x-something.else"));
825 EXPECT_FALSE(IsSupportedKeySystem("x-other"));
828 } // namespace media