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.
8 #include "content/public/common/content_client.h"
9 #include "content/public/renderer/content_renderer_client.h"
10 #include "content/public/renderer/key_system_info.h"
11 #include "content/renderer/media/crypto/key_systems.h"
12 #include "content/test/test_content_client.h"
13 #include "testing/gtest/include/gtest/gtest.h"
14 #include "third_party/WebKit/public/platform/WebString.h"
16 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
18 // Death tests are not always available, including on Android.
19 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that
20 // death tests are not available and NDEBUG is not defined.
21 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
22 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
23 EXPECT_DEBUG_DEATH(statement, regex)
26 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
27 do { statement; } while (false)
29 #include "base/logging.h"
30 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
31 LOG(WARNING) << "Death tests are not supported on this platform.\n" \
32 << "Statement '" #statement "' cannot be verified.";
33 #endif // defined(NDEBUG)
34 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
36 using WebKit::WebString;
38 // These are the (fake) key systems that are registered for these tests.
39 // kUsesAes uses the AesDecryptor like Clear Key.
40 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
41 static const char kUsesAes[] = "org.example.clear";
42 static const char kUsesAesParent[] = "org.example"; // Not registered.
43 static const char kExternal[] = "com.example.test";
44 static const char kExternalParent[] = "com.example";
46 static const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
47 static const char kUnprefixedClearKey[] = "org.w3.clearkey";
48 static const char kExternalClearKey[] = "org.chromium.externalclearkey";
50 static const char kAudioWebM[] = "audio/webm";
51 static const char kVideoWebM[] = "video/webm";
52 static const char kWebMAudioCodecs[] = "vorbis";
53 static const char kWebMVideoCodecs[] = "vorbis,vp8,vp8.0";
55 static const char kAudioFoo[] = "audio/foo";
56 static const char kVideoFoo[] = "video/foo";
57 static const char kFooAudioCodecs[] = "fooaudio";
58 static const char kFooVideoCodecs[] = "fooaudio,foovideo";
62 // Helper functions that handle the WebString conversion to simplify tests.
63 static std::string KeySystemNameForUMAUTF8(const std::string& key_system) {
64 return KeySystemNameForUMA(WebString::fromUTF8(key_system));
67 static bool IsConcreteSupportedKeySystemUTF8(const std::string& key_system) {
68 return IsConcreteSupportedKeySystem(WebString::fromUTF8(key_system));
71 class TestContentRendererClient : public ContentRendererClient {
72 virtual void AddKeySystems(
73 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
76 void TestContentRendererClient::AddKeySystems(
77 std::vector<content::KeySystemInfo>* key_systems) {
78 #if defined(OS_ANDROID)
79 static const uint8 kExternalUuid[16] = {
80 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
81 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF };
84 KeySystemInfo aes(kUsesAes);
86 aes.supported_types.push_back(std::make_pair(kAudioWebM, kWebMAudioCodecs));
87 aes.supported_types.push_back(std::make_pair(kVideoWebM, kWebMVideoCodecs));
89 aes.supported_types.push_back(std::make_pair(kAudioFoo, kFooAudioCodecs));
90 aes.supported_types.push_back(std::make_pair(kVideoFoo, kFooVideoCodecs));
92 aes.use_aes_decryptor = true;
94 key_systems->push_back(aes);
96 KeySystemInfo ext(kExternal);
98 ext.supported_types.push_back(std::make_pair(kAudioWebM, kWebMAudioCodecs));
99 ext.supported_types.push_back(std::make_pair(kVideoWebM, kWebMVideoCodecs));
101 ext.supported_types.push_back(std::make_pair(kAudioFoo, kFooAudioCodecs));
102 ext.supported_types.push_back(std::make_pair(kVideoFoo, kFooVideoCodecs));
104 ext.parent_key_system = kExternalParent;
106 #if defined(ENABLE_PEPPER_CDMS)
107 ext.pepper_type = "application/x-ppapi-external-cdm";
108 #elif defined(OS_ANDROID)
109 ext.uuid.assign(kExternalUuid, kExternalUuid + arraysize(kExternalUuid));
110 #endif // defined(ENABLE_PEPPER_CDMS)
112 key_systems->push_back(ext);
115 class KeySystemsTest : public testing::Test {
118 vp8_codec_.push_back("vp8");
120 vp80_codec_.push_back("vp8.0");
122 vorbis_codec_.push_back("vorbis");
124 vp8_and_vorbis_codecs_.push_back("vp8");
125 vp8_and_vorbis_codecs_.push_back("vorbis");
127 foovideo_codec_.push_back("foovideo");
129 foovideo_extended_codec_.push_back("foovideo.4D400C");
131 foovideo_dot_codec_.push_back("foovideo.");
133 fooaudio_codec_.push_back("fooaudio");
135 foovideo_and_fooaudio_codecs_.push_back("foovideo");
136 foovideo_and_fooaudio_codecs_.push_back("fooaudio");
138 unknown_codec_.push_back("unknown");
140 mixed_codecs_.push_back("vorbis");
141 mixed_codecs_.push_back("foovideo");
143 // KeySystems requires a valid ContentRendererClient and thus ContentClient.
144 // The TestContentClient is not available inside Death Tests on some
145 // platforms (see below). Therefore, always provide a TestContentClient.
146 // Explanation: When Death Tests fork, there is a valid ContentClient.
147 // However, when they launch a new process instead of forking, the global
148 // variable is not copied and for some reason TestContentClientInitializer
149 // does not get created to set the global variable in the new process.
150 SetContentClient(&test_content_client_);
151 SetRendererClientForTesting(&content_renderer_client_);
154 virtual ~KeySystemsTest() {
155 // Clear the use of content_client_, which was set in SetUp().
156 SetContentClient(NULL);
159 typedef std::vector<std::string> CodecVector;
161 const CodecVector& no_codecs() const { return no_codecs_; }
163 const CodecVector& vp8_codec() const { return vp8_codec_; }
164 const CodecVector& vp80_codec() const { return vp80_codec_; }
165 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
166 const CodecVector& vp8_and_vorbis_codecs() const {
167 return vp8_and_vorbis_codecs_;
170 const CodecVector& foovideo_codec() const { return foovideo_codec_; }
171 const CodecVector& foovideo_extended_codec() const {
172 return foovideo_extended_codec_;
174 const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
175 const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
176 const CodecVector& foovideo_and_fooaudio_codecs() const {
177 return foovideo_and_fooaudio_codecs_;
180 const CodecVector& unknown_codec() const { return unknown_codec_; }
182 const CodecVector& mixed_codecs() const { return mixed_codecs_; }
185 const CodecVector no_codecs_;
187 CodecVector vp8_codec_;
188 CodecVector vp80_codec_;
189 CodecVector vorbis_codec_;
190 CodecVector vp8_and_vorbis_codecs_;
192 CodecVector foovideo_codec_;
193 CodecVector foovideo_extended_codec_;
194 CodecVector foovideo_dot_codec_;
195 CodecVector fooaudio_codec_;
196 CodecVector foovideo_and_fooaudio_codecs_;
198 CodecVector unknown_codec_;
200 CodecVector mixed_codecs_;
202 TestContentClient test_content_client_;
203 TestContentRendererClient content_renderer_client_;
206 // TODO(ddorwin): Consider moving GetUUID() into these tests or moving
207 // GetPepperType() calls out to their own test.
209 // Clear Key is the only key system registered in content.
210 TEST_F(KeySystemsTest, ClearKey) {
211 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kPrefixedClearKey));
212 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
213 kVideoWebM, no_codecs(), kPrefixedClearKey));
215 EXPECT_EQ("ClearKey", KeySystemNameForUMAUTF8(kPrefixedClearKey));
217 // Not yet out from behind the vendor prefix.
218 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey));
219 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
220 kVideoWebM, no_codecs(), kUnprefixedClearKey));
221 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnprefixedClearKey));
224 // The key system is not registered and therefore is unrecognized.
225 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
226 static const char* const kUnrecognized = "org.example.unrecognized";
228 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kUnrecognized));
229 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
230 kVideoWebM, no_codecs(), kUnrecognized));
232 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnrecognized));
234 bool can_use = false;
235 EXPECT_DEBUG_DEATH_PORTABLE(
236 can_use = CanUseAesDecryptor(kUnrecognized),
237 "org.example.unrecognized is not a known concrete system");
238 EXPECT_FALSE(can_use);
240 #if defined(ENABLE_PEPPER_CDMS)
242 EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized),
243 "org.example.unrecognized is not a known concrete system");
244 EXPECT_TRUE(type.empty());
248 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
249 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kUsesAes));
250 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
251 kVideoWebM, no_codecs(), kUsesAes));
253 // No UMA value for this test key system.
254 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUsesAes));
256 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
257 #if defined(ENABLE_PEPPER_CDMS)
259 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
260 "org.example.clear is not Pepper-based");
261 EXPECT_TRUE(type.empty());
265 TEST_F(KeySystemsTest,
266 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1) {
267 // Valid video types.
268 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
269 kVideoWebM, vp8_codec(), kUsesAes));
270 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
271 kVideoWebM, vp80_codec(), kUsesAes));
272 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
273 kVideoWebM, vp8_and_vorbis_codecs(), kUsesAes));
274 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
275 kVideoWebM, vorbis_codec(), kUsesAes));
278 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
279 kVideoWebM, foovideo_codec(), kUsesAes));
280 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
281 kVideoWebM, unknown_codec(), kUsesAes));
282 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
283 kVideoWebM, mixed_codecs(), kUsesAes));
285 // Valid audio types.
286 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
287 kAudioWebM, no_codecs(), kUsesAes));
288 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
289 kAudioWebM, vorbis_codec(), kUsesAes));
292 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
293 kAudioWebM, vp8_codec(), kUsesAes));
294 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
295 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
298 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
299 kAudioWebM, fooaudio_codec(), kUsesAes));
302 // No parent is registered for UsesAes.
303 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
304 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kUsesAesParent));
305 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
306 kVideoWebM, no_codecs(), kUsesAesParent));
308 // The parent is not supported for most things.
309 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUsesAesParent));
311 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent),
312 "org.example is not a known concrete system");
313 EXPECT_FALSE(result);
314 #if defined(ENABLE_PEPPER_CDMS)
316 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
317 "org.example is not a known concrete system");
318 EXPECT_TRUE(type.empty());
322 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
324 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8("org.example.ClEaR"));
325 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
326 kVideoWebM, no_codecs(), "org.example.ClEaR"));
328 // TLDs are not allowed.
329 EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
330 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
331 kVideoWebM, no_codecs(), "org."));
332 EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
333 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
334 kVideoWebM, no_codecs(), "com"));
337 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example."));
338 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
339 kVideoWebM, no_codecs(), "org.example."));
342 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clea"));
343 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
344 kVideoWebM, no_codecs(), "org.example.clea"));
347 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clearz"));
348 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
349 kVideoWebM, no_codecs(), "org.example.clearz"));
351 // There are no child key systems for UsesAes.
352 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clear.foo"));
353 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
354 kVideoWebM, no_codecs(), "org.example.clear.foo"));
357 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
358 // These two should be true. See http://crbug.com/164303.
359 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
360 std::string(), no_codecs(), kUsesAes));
361 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
362 std::string(), no_codecs(), kUsesAesParent));
364 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
365 std::string(), no_codecs(), "org.example.foo"));
366 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
367 std::string(), no_codecs(), "org.example.clear.foo"));
370 // Tests the second registered container type.
371 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
372 TEST_F(KeySystemsTest,
373 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
374 // Valid video types.
375 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
376 kVideoFoo, no_codecs(), kUsesAes));
377 // The parent should be supported but is not. See http://crbug.com/164303.
378 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
379 kVideoFoo, no_codecs(), kUsesAesParent));
380 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
381 kVideoFoo, foovideo_codec(), kUsesAes));
382 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
383 kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
384 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
385 kVideoFoo, fooaudio_codec(), kUsesAes));
387 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
388 // They should really pass canPlayType().
389 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
390 kVideoFoo, foovideo_extended_codec(), kUsesAes));
392 // Invalid codec format.
393 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
394 kVideoFoo, foovideo_dot_codec(), kUsesAes));
396 // Non-container2 codec.
397 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
398 kVideoFoo, vp8_codec(), kUsesAes));
399 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
400 kVideoFoo, unknown_codec(), kUsesAes));
401 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
402 kVideoFoo, mixed_codecs(), kUsesAes));
404 // Valid audio types.
405 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
406 kAudioFoo, no_codecs(), kUsesAes));
407 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
408 kAudioFoo, fooaudio_codec(), kUsesAes));
411 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
412 kAudioFoo, foovideo_codec(), kUsesAes));
413 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
414 kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
416 // Non-container2 codec.
417 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
418 kAudioFoo, vorbis_codec(), kUsesAes));
422 // Non-AesDecryptor-based key system.
425 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
426 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kExternal));
427 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
428 kVideoWebM, no_codecs(), kExternal));
430 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
431 #if defined(ENABLE_PEPPER_CDMS)
432 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
433 #endif // defined(ENABLE_PEPPER_CDMS)
437 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
438 // The parent system is not a concrete system but is supported.
439 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kExternalParent));
440 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
441 kVideoWebM, no_codecs(), kExternalParent));
443 // The parent is not supported for most things.
444 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kExternalParent));
446 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
447 "com.example is not a known concrete system");
448 EXPECT_FALSE(result);
449 #if defined(ENABLE_PEPPER_CDMS)
451 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
452 "com.example is not a known concrete system");
453 EXPECT_TRUE(type.empty());
459 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
460 // Valid video types.
461 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
462 kVideoWebM, no_codecs(), kExternal));
463 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
464 kVideoWebM, vp8_codec(), kExternal));
465 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
466 kVideoWebM, vp80_codec(), kExternal));
467 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
468 kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
469 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
470 kVideoWebM, vorbis_codec(), kExternal));
472 // Valid video types - parent key system.
473 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
474 kVideoWebM, no_codecs(), kExternalParent));
475 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
476 kVideoWebM, vp8_codec(), kExternalParent));
477 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
478 kVideoWebM, vp80_codec(), kExternalParent));
479 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
480 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
481 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
482 kVideoWebM, vorbis_codec(), kExternalParent));
485 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
486 kVideoWebM, foovideo_codec(), kExternal));
487 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
488 kVideoWebM, unknown_codec(), kExternal));
489 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
490 kVideoWebM, mixed_codecs(), kExternal));
492 // Valid audio types.
493 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
494 kAudioWebM, no_codecs(), kExternal));
495 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
496 kAudioWebM, vorbis_codec(), kExternal));
498 // Valid audio types - parent key system.
499 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
500 kAudioWebM, no_codecs(), kExternalParent));
501 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
502 kAudioWebM, vorbis_codec(), kExternalParent));
505 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
506 kAudioWebM, vp8_codec(), kExternal));
507 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
508 kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
511 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
512 kAudioWebM, fooaudio_codec(), kExternal));
517 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
518 // Valid video types.
519 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
520 kVideoFoo, no_codecs(), kExternal));
521 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
522 kVideoFoo, foovideo_codec(), kExternal));
523 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
524 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
525 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
526 kVideoFoo, fooaudio_codec(), kExternal));
528 // Valid video types - parent key system.
529 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
530 kVideoFoo, no_codecs(), kExternalParent));
531 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
532 kVideoFoo, foovideo_codec(), kExternalParent));
533 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
534 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
535 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
536 kVideoFoo, fooaudio_codec(), kExternalParent));
538 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
539 // They should really pass canPlayType().
540 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
541 kVideoFoo, foovideo_extended_codec(), kExternal));
543 // Invalid codec format.
544 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
545 kVideoFoo, foovideo_dot_codec(), kExternal));
547 // Non-container2 codecs.
548 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
549 kVideoFoo, vp8_codec(), kExternal));
550 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
551 kVideoFoo, unknown_codec(), kExternal));
552 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
553 kVideoFoo, mixed_codecs(), kExternal));
555 // Valid audio types.
556 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
557 kAudioFoo, no_codecs(), kExternal));
558 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
559 kAudioFoo, fooaudio_codec(), kExternal));
561 // Valid audio types - parent key system.
562 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
563 kAudioFoo, no_codecs(), kExternalParent));
564 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
565 kAudioFoo, fooaudio_codec(), kExternalParent));
568 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
569 kAudioFoo, foovideo_codec(), kExternal));
570 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
571 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
573 // Non-container2 codec.
574 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
575 kAudioFoo, vorbis_codec(), kExternal));
578 #if defined(OS_ANDROID)
579 TEST_F(KeySystemsTest, GetUUID_RegisteredExternalDecryptor) {
580 std::vector<uint8> uuid = GetUUID(kExternal);
581 EXPECT_EQ(16u, uuid.size());
582 EXPECT_EQ(0xef, uuid[15]);
585 TEST_F(KeySystemsTest, GetUUID_RegisteredAesDecryptor) {
586 EXPECT_TRUE(GetUUID(kUsesAes).empty());
589 TEST_F(KeySystemsTest, GetUUID_Unrecognized) {
590 std::vector<uint8> uuid;
591 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(kExternalParent),
592 "com.example is not a known concrete system");
593 EXPECT_TRUE(uuid.empty());
595 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(""), " is not a concrete system");
596 EXPECT_TRUE(uuid.empty());
598 #endif // defined(OS_ANDROID)
600 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
601 EXPECT_EQ("ClearKey", KeySystemNameForUMAUTF8(kPrefixedClearKey));
602 // Unprefixed is not yet supported.
603 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnprefixedClearKey));
605 // External Clear Key never has a UMA name.
606 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kExternalClearKey));
608 #if defined(WIDEVINE_CDM_AVAILABLE)
609 const char* const kTestWidevineUmaName = "Widevine";
611 const char* const kTestWidevineUmaName = "Unknown";
613 EXPECT_EQ(kTestWidevineUmaName,
614 KeySystemNameForUMAUTF8("com.widevine.alpha"));
617 } // namespace content