Chromoting: Fix connection failure strings to match Directory Service
[chromium-blink-merge.git] / media / base / key_systems_unittest.cc
blob07bc5ec3524b119cc02d4cd95f02213387714832
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[] = "org.example.clear";
39 const char kUsesAesParent[] = "org.example"; // Not registered.
40 const char kUseAesNameForUMA[] = "UseAes";
41 const char kExternal[] = "com.example.test";
42 const char kExternalParent[] = "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() final;
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) final;
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(
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(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 std::vector<KeySystemInfo>* key_systems) {
163 KeySystemInfo aes(kUsesAes);
164 aes.supported_codecs = EME_CODEC_WEBM_ALL;
165 aes.supported_codecs |= TEST_CODEC_FOO_ALL;
166 aes.supported_init_data_types = EME_INIT_DATA_TYPE_WEBM;
167 aes.use_aes_decryptor = true;
168 key_systems->push_back(aes);
171 void TestMediaClient::AddExternalKeySystem(
172 std::vector<KeySystemInfo>* key_systems) {
173 KeySystemInfo ext(kExternal);
174 ext.supported_codecs = EME_CODEC_WEBM_ALL;
175 ext.supported_codecs |= TEST_CODEC_FOO_ALL;
176 ext.supported_init_data_types = EME_INIT_DATA_TYPE_WEBM;
177 ext.parent_key_system = kExternalParent;
178 #if defined(ENABLE_PEPPER_CDMS)
179 ext.pepper_type = "application/x-ppapi-external-cdm";
180 #endif // defined(ENABLE_PEPPER_CDMS)
181 key_systems->push_back(ext);
184 // TODO(sandersd): Refactor. http://crbug.com/417444
185 class KeySystemsTest : public testing::Test {
186 protected:
187 KeySystemsTest() {
188 vp8_codec_.push_back("vp8");
190 vp80_codec_.push_back("vp8.0");
192 vp9_codec_.push_back("vp9");
194 vp90_codec_.push_back("vp9.0");
196 vorbis_codec_.push_back("vorbis");
198 vp8_and_vorbis_codecs_.push_back("vp8");
199 vp8_and_vorbis_codecs_.push_back("vorbis");
201 vp9_and_vorbis_codecs_.push_back("vp9");
202 vp9_and_vorbis_codecs_.push_back("vorbis");
204 foovideo_codec_.push_back("foovideo");
206 foovideo_extended_codec_.push_back("foovideo.4D400C");
208 foovideo_dot_codec_.push_back("foovideo.");
210 fooaudio_codec_.push_back("fooaudio");
212 foovideo_and_fooaudio_codecs_.push_back("foovideo");
213 foovideo_and_fooaudio_codecs_.push_back("fooaudio");
215 unknown_codec_.push_back("unknown");
217 mixed_codecs_.push_back("vorbis");
218 mixed_codecs_.push_back("foovideo");
220 SetMediaClient(&test_media_client_);
223 void SetUp() override {
224 AddContainerAndCodecMasksForTest();
227 ~KeySystemsTest() override {
228 // Clear the use of |test_media_client_|, which was set in SetUp().
229 SetMediaClient(nullptr);
232 void UpdateClientKeySystems() {
233 test_media_client_.SetKeySystemsUpdateNeeded();
234 test_media_client_.DisableExternalKeySystemSupport();
237 typedef std::vector<std::string> CodecVector;
239 const CodecVector& no_codecs() const { return no_codecs_; }
241 const CodecVector& vp8_codec() const { return vp8_codec_; }
242 const CodecVector& vp80_codec() const { return vp80_codec_; }
243 const CodecVector& vp9_codec() const { return vp9_codec_; }
244 const CodecVector& vp90_codec() const { return vp90_codec_; }
246 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
248 const CodecVector& vp8_and_vorbis_codecs() const {
249 return vp8_and_vorbis_codecs_;
251 const CodecVector& vp9_and_vorbis_codecs() const {
252 return vp9_and_vorbis_codecs_;
255 const CodecVector& foovideo_codec() const { return foovideo_codec_; }
256 const CodecVector& foovideo_extended_codec() const {
257 return foovideo_extended_codec_;
259 const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
260 const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
261 const CodecVector& foovideo_and_fooaudio_codecs() const {
262 return foovideo_and_fooaudio_codecs_;
265 const CodecVector& unknown_codec() const { return unknown_codec_; }
267 const CodecVector& mixed_codecs() const { return mixed_codecs_; }
269 private:
270 const CodecVector no_codecs_;
271 CodecVector vp8_codec_;
272 CodecVector vp80_codec_;
273 CodecVector vp9_codec_;
274 CodecVector vp90_codec_;
275 CodecVector vorbis_codec_;
276 CodecVector vp8_and_vorbis_codecs_;
277 CodecVector vp9_and_vorbis_codecs_;
279 CodecVector foovideo_codec_;
280 CodecVector foovideo_extended_codec_;
281 CodecVector foovideo_dot_codec_;
282 CodecVector fooaudio_codec_;
283 CodecVector foovideo_and_fooaudio_codecs_;
285 CodecVector unknown_codec_;
287 CodecVector mixed_codecs_;
289 TestMediaClient test_media_client_;
292 // TODO(ddorwin): Consider moving GetPepperType() calls out to their own test.
294 TEST_F(KeySystemsTest, EmptyKeySystem) {
295 EXPECT_FALSE(IsConcreteSupportedKeySystem(std::string()));
296 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
297 kVideoWebM, no_codecs(), std::string()));
298 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(std::string()));
301 // Clear Key is the only key system registered in content.
302 TEST_F(KeySystemsTest, ClearKey) {
303 EXPECT_TRUE(IsConcreteSupportedKeySystem(kClearKey));
304 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
305 kVideoWebM, no_codecs(), kClearKey));
307 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey));
309 // Prefixed Clear Key is not supported internally.
310 EXPECT_FALSE(IsConcreteSupportedKeySystem(kPrefixedClearKey));
311 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
312 kVideoWebM, no_codecs(), kPrefixedClearKey));
313 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey));
316 // The key system is not registered and therefore is unrecognized.
317 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
318 static const char* const kUnrecognized = "org.example.unrecognized";
320 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnrecognized));
321 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
322 kVideoWebM, no_codecs(), kUnrecognized));
324 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUnrecognized));
326 bool can_use = false;
327 EXPECT_DEBUG_DEATH_PORTABLE(
328 can_use = CanUseAesDecryptor(kUnrecognized),
329 "org.example.unrecognized is not a known concrete system");
330 EXPECT_FALSE(can_use);
332 #if defined(ENABLE_PEPPER_CDMS)
333 std::string type;
334 EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized),
335 "org.example.unrecognized is not a known concrete system");
336 EXPECT_TRUE(type.empty());
337 #endif
340 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
341 EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
342 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
343 kVideoWebM, no_codecs(), kUsesAes));
345 // No UMA value for this test key system.
346 EXPECT_EQ("UseAes", GetKeySystemNameForUMA(kUsesAes));
348 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
349 #if defined(ENABLE_PEPPER_CDMS)
350 std::string type;
351 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
352 "org.example.clear is not Pepper-based");
353 EXPECT_TRUE(type.empty());
354 #endif
357 TEST_F(KeySystemsTest,
358 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1) {
359 // Valid video types.
360 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
361 kVideoWebM, vp8_codec(), kUsesAes));
362 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
363 kVideoWebM, vp80_codec(), kUsesAes));
364 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
365 kVideoWebM, vp8_and_vorbis_codecs(), kUsesAes));
366 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
367 kVideoWebM, vp9_codec(), kUsesAes));
368 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
369 kVideoWebM, vp90_codec(), kUsesAes));
370 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
371 kVideoWebM, vp9_and_vorbis_codecs(), kUsesAes));
372 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
373 kVideoWebM, vorbis_codec(), kUsesAes));
375 // Non-Webm codecs.
376 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
377 kVideoWebM, foovideo_codec(), kUsesAes));
378 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
379 kVideoWebM, unknown_codec(), kUsesAes));
380 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
381 kVideoWebM, mixed_codecs(), kUsesAes));
383 // Valid audio types.
384 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
385 kAudioWebM, no_codecs(), kUsesAes));
386 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
387 kAudioWebM, vorbis_codec(), kUsesAes));
389 // Non-audio codecs.
390 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
391 kAudioWebM, vp8_codec(), kUsesAes));
392 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
393 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
394 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
395 kAudioWebM, vp9_codec(), kUsesAes));
396 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
397 kAudioWebM, vp9_and_vorbis_codecs(), kUsesAes));
399 // Non-Webm codec.
400 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
401 kAudioWebM, fooaudio_codec(), kUsesAes));
404 // No parent is registered for UsesAes.
405 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
406 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUsesAesParent));
407 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
408 kVideoWebM, no_codecs(), kUsesAesParent));
410 // The parent is not supported for most things.
411 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAesParent));
412 bool result = false;
413 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent),
414 "org.example is not a known concrete system");
415 EXPECT_FALSE(result);
416 #if defined(ENABLE_PEPPER_CDMS)
417 std::string type;
418 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
419 "org.example is not a known concrete system");
420 EXPECT_TRUE(type.empty());
421 #endif
424 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
425 // Case sensitive.
426 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.ClEaR"));
427 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
428 kVideoWebM, no_codecs(), "org.example.ClEaR"));
430 // TLDs are not allowed.
431 EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
432 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
433 kVideoWebM, no_codecs(), "org."));
434 EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
435 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
436 kVideoWebM, no_codecs(), "com"));
438 // Extra period.
439 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example."));
440 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
441 kVideoWebM, no_codecs(), "org.example."));
443 // Incomplete.
444 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clea"));
445 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
446 kVideoWebM, no_codecs(), "org.example.clea"));
448 // Extra character.
449 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clearz"));
450 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
451 kVideoWebM, no_codecs(), "org.example.clearz"));
453 // There are no child key systems for UsesAes.
454 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clear.foo"));
455 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
456 kVideoWebM, no_codecs(), "org.example.clear.foo"));
459 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
460 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
461 std::string(), no_codecs(), kUsesAes));
462 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
463 std::string(), no_codecs(), kUsesAesParent));
465 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
466 std::string(), no_codecs(), "org.example.foo"));
467 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
468 std::string(), no_codecs(), "org.example.clear.foo"));
471 // Tests the second registered container type.
472 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
473 TEST_F(KeySystemsTest,
474 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
475 // Valid video types.
476 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
477 kVideoFoo, no_codecs(), kUsesAes));
478 // The parent should be supported but is not. See http://crbug.com/164303.
479 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
480 kVideoFoo, no_codecs(), kUsesAesParent));
481 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
482 kVideoFoo, foovideo_codec(), kUsesAes));
483 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
484 kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
485 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
486 kVideoFoo, fooaudio_codec(), kUsesAes));
488 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
489 // They should really pass canPlayType().
490 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
491 kVideoFoo, foovideo_extended_codec(), kUsesAes));
493 // Invalid codec format.
494 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
495 kVideoFoo, foovideo_dot_codec(), kUsesAes));
497 // Non-container2 codec.
498 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
499 kVideoFoo, vp8_codec(), kUsesAes));
500 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
501 kVideoFoo, unknown_codec(), kUsesAes));
502 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
503 kVideoFoo, mixed_codecs(), kUsesAes));
505 // Valid audio types.
506 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
507 kAudioFoo, no_codecs(), kUsesAes));
508 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
509 kAudioFoo, fooaudio_codec(), kUsesAes));
511 // Non-audio codecs.
512 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
513 kAudioFoo, foovideo_codec(), kUsesAes));
514 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
515 kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
517 // Non-container2 codec.
518 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
519 kAudioFoo, vorbis_codec(), kUsesAes));
523 // Non-AesDecryptor-based key system.
526 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
527 EXPECT_TRUE(IsConcreteSupportedKeySystem(kExternal));
528 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
529 kVideoWebM, no_codecs(), kExternal));
531 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
532 #if defined(ENABLE_PEPPER_CDMS)
533 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
534 #endif // defined(ENABLE_PEPPER_CDMS)
537 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
538 // The parent system is not a concrete system but is supported.
539 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalParent));
540 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
541 kVideoWebM, no_codecs(), kExternalParent));
543 // The parent is not supported for most things.
544 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalParent));
545 bool result = false;
546 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
547 "com.example is not a known concrete system");
548 EXPECT_FALSE(result);
549 #if defined(ENABLE_PEPPER_CDMS)
550 std::string type;
551 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
552 "com.example is not a known concrete system");
553 EXPECT_TRUE(type.empty());
554 #endif
557 TEST_F(
558 KeySystemsTest,
559 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
560 // Valid video types.
561 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
562 kVideoWebM, no_codecs(), kExternal));
563 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
564 kVideoWebM, vp8_codec(), kExternal));
565 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
566 kVideoWebM, vp80_codec(), kExternal));
567 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
568 kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
569 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
570 kVideoWebM, vp9_codec(), kExternal));
571 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
572 kVideoWebM, vp90_codec(), kExternal));
573 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
574 kVideoWebM, vp9_and_vorbis_codecs(), kExternal));
575 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
576 kVideoWebM, vorbis_codec(), kExternal));
578 // Valid video types - parent key system.
579 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
580 kVideoWebM, no_codecs(), kExternalParent));
581 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
582 kVideoWebM, vp8_codec(), kExternalParent));
583 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
584 kVideoWebM, vp80_codec(), kExternalParent));
585 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
586 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
587 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
588 kVideoWebM, vp9_codec(), kExternalParent));
589 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
590 kVideoWebM, vp90_codec(), kExternalParent));
591 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
592 kVideoWebM, vp9_and_vorbis_codecs(), kExternalParent));
593 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
594 kVideoWebM, vorbis_codec(), kExternalParent));
596 // Non-Webm codecs.
597 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
598 kVideoWebM, foovideo_codec(), kExternal));
599 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
600 kVideoWebM, unknown_codec(), kExternal));
601 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
602 kVideoWebM, mixed_codecs(), kExternal));
604 // Valid audio types.
605 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
606 kAudioWebM, no_codecs(), kExternal));
607 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
608 kAudioWebM, vorbis_codec(), kExternal));
610 // Valid audio types - parent key system.
611 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
612 kAudioWebM, no_codecs(), kExternalParent));
613 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
614 kAudioWebM, vorbis_codec(), kExternalParent));
616 // Non-audio codecs.
617 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
618 kAudioWebM, vp8_codec(), kExternal));
619 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
620 kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
621 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
622 kAudioWebM, vp9_codec(), kExternal));
623 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
624 kAudioWebM, vp9_and_vorbis_codecs(), kExternal));
626 // Non-Webm codec.
627 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
628 kAudioWebM, fooaudio_codec(), kExternal));
631 TEST_F(
632 KeySystemsTest,
633 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
634 // Valid video types.
635 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
636 kVideoFoo, no_codecs(), kExternal));
637 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
638 kVideoFoo, foovideo_codec(), kExternal));
639 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
640 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
641 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
642 kVideoFoo, fooaudio_codec(), kExternal));
644 // Valid video types - parent key system.
645 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
646 kVideoFoo, no_codecs(), kExternalParent));
647 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
648 kVideoFoo, foovideo_codec(), kExternalParent));
649 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
650 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
651 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
652 kVideoFoo, fooaudio_codec(), kExternalParent));
654 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
655 // They should really pass canPlayType().
656 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
657 kVideoFoo, foovideo_extended_codec(), kExternal));
659 // Invalid codec format.
660 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
661 kVideoFoo, foovideo_dot_codec(), kExternal));
663 // Non-container2 codecs.
664 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
665 kVideoFoo, vp8_codec(), kExternal));
666 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
667 kVideoFoo, unknown_codec(), kExternal));
668 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
669 kVideoFoo, mixed_codecs(), kExternal));
671 // Valid audio types.
672 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
673 kAudioFoo, no_codecs(), kExternal));
674 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
675 kAudioFoo, fooaudio_codec(), kExternal));
677 // Valid audio types - parent key system.
678 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
679 kAudioFoo, no_codecs(), kExternalParent));
680 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
681 kAudioFoo, fooaudio_codec(), kExternalParent));
683 // Non-audio codecs.
684 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
685 kAudioFoo, foovideo_codec(), kExternal));
686 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
687 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
689 // Non-container2 codec.
690 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
691 kAudioFoo, vorbis_codec(), kExternal));
694 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
695 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey));
696 // Prefixed is not supported internally.
697 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kPrefixedClearKey));
699 // External Clear Key never has a UMA name.
700 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey));
703 TEST_F(KeySystemsTest, KeySystemsUpdate) {
704 EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
705 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
706 kVideoWebM, no_codecs(), kUsesAes));
707 EXPECT_TRUE(IsConcreteSupportedKeySystem(kExternal));
708 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
709 kVideoWebM, no_codecs(), kExternal));
711 UpdateClientKeySystems();
713 EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
714 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
715 kVideoWebM, no_codecs(), kUsesAes));
716 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternal));
717 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
718 kVideoWebM, no_codecs(), kExternal));
721 TEST_F(KeySystemsTest, PrefixedKeySystemsUpdate) {
722 EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
723 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
724 kVideoWebM, no_codecs(), kUsesAes));
725 EXPECT_TRUE(IsConcreteSupportedKeySystem(kExternal));
726 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
727 kVideoWebM, no_codecs(), kExternal));
729 UpdateClientKeySystems();
731 EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
732 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType(
733 kVideoWebM, no_codecs(), kUsesAes));
734 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternal));
735 EXPECT_FALSE(PrefixedIsSupportedKeySystemWithMediaMimeType(
736 kVideoWebM, no_codecs(), kExternal));
739 } // namespace media