Store SupportedCodecs in KeySystemInfo and KeySystems.
[chromium-blink-merge.git] / content / renderer / media / crypto / key_systems_unittest.cc
bloba7f8b54ab9d7563bf15519c8f7e3cab19b88c8c5
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 "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)
24 #else
25 #if defined(NDEBUG)
26 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
27 do { statement; } while (false)
28 #else
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 namespace content {
38 using blink::WebString;
40 // These are the (fake) key systems that are registered for these tests.
41 // kUsesAes uses the AesDecryptor like Clear Key.
42 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
43 const char kUsesAes[] = "org.example.clear";
44 const char kUsesAesParent[] = "org.example"; // Not registered.
45 const char kExternal[] = "com.example.test";
46 const char kExternalParent[] = "com.example";
48 const char kClearKey[] = "org.w3.clearkey";
49 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
50 const char kExternalClearKey[] = "org.chromium.externalclearkey";
52 const char kAudioWebM[] = "audio/webm";
53 const char kVideoWebM[] = "video/webm";
54 const char kAudioFoo[] = "audio/foo";
55 const char kVideoFoo[] = "video/foo";
57 // Pick some arbitrary bit fields as long as they are not in conflict with the
58 // real ones.
59 enum TestCodec {
60 TEST_CODEC_FOO_AUDIO = 1 << 10, // An audio codec for foo container.
61 TEST_CODEC_FOO_AUDIO_ALL = TEST_CODEC_FOO_AUDIO,
62 TEST_CODEC_FOO_VIDEO = 1 << 11, // A video codec for foo container.
63 TEST_CODEC_FOO_VIDEO_ALL = TEST_CODEC_FOO_VIDEO,
64 TEST_CODEC_FOO_ALL = TEST_CODEC_FOO_AUDIO_ALL | TEST_CODEC_FOO_VIDEO_ALL
67 COMPILE_ASSERT((TEST_CODEC_FOO_ALL & EME_CODEC_ALL) == EME_CODEC_NONE,
68 test_codec_masks_should_only_use_invalid_codec_masks);
70 // Adds test container and codec masks.
71 // This function must be called after SetContentClient() is called.
72 // More details: AddXxxMask() will create KeySystems if it hasn't been created.
73 // During KeySystems's construction GetContentClient() will be used to add key
74 // systems. In test code, the content client is set by SetContentClient().
75 // Therefore, SetContentClient() must be called before this function to avoid
76 // access violation.
77 static void AddContainerAndCodecMasksForTest() {
78 // Since KeySystems is a singleton. Make sure we only add test container and
79 // codec masks once per process.
80 static bool is_test_masks_added = false;
82 if (is_test_masks_added)
83 return;
85 AddContainerMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL);
86 AddContainerMask("video/foo", TEST_CODEC_FOO_ALL);
87 AddCodecMask("fooaudio", TEST_CODEC_FOO_AUDIO);
88 AddCodecMask("foovideo", TEST_CODEC_FOO_VIDEO);
90 is_test_masks_added = true;
93 class TestContentRendererClient : public ContentRendererClient {
94 virtual void AddKeySystems(
95 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
98 void TestContentRendererClient::AddKeySystems(
99 std::vector<content::KeySystemInfo>* key_systems) {
100 KeySystemInfo aes(kUsesAes);
101 aes.supported_codecs = EME_CODEC_WEBM_ALL;
102 aes.supported_codecs |= TEST_CODEC_FOO_ALL;
103 aes.use_aes_decryptor = true;
104 key_systems->push_back(aes);
106 KeySystemInfo ext(kExternal);
107 ext.supported_codecs = EME_CODEC_WEBM_ALL;
108 ext.supported_codecs |= TEST_CODEC_FOO_ALL;
109 ext.parent_key_system = kExternalParent;
110 #if defined(ENABLE_PEPPER_CDMS)
111 ext.pepper_type = "application/x-ppapi-external-cdm";
112 #endif // defined(ENABLE_PEPPER_CDMS)
113 key_systems->push_back(ext);
116 class KeySystemsTest : public testing::Test {
117 protected:
118 KeySystemsTest() {
119 vp8_codec_.push_back("vp8");
121 vp80_codec_.push_back("vp8.0");
123 vorbis_codec_.push_back("vorbis");
125 vp8_and_vorbis_codecs_.push_back("vp8");
126 vp8_and_vorbis_codecs_.push_back("vorbis");
128 foovideo_codec_.push_back("foovideo");
130 foovideo_extended_codec_.push_back("foovideo.4D400C");
132 foovideo_dot_codec_.push_back("foovideo.");
134 fooaudio_codec_.push_back("fooaudio");
136 foovideo_and_fooaudio_codecs_.push_back("foovideo");
137 foovideo_and_fooaudio_codecs_.push_back("fooaudio");
139 unknown_codec_.push_back("unknown");
141 mixed_codecs_.push_back("vorbis");
142 mixed_codecs_.push_back("foovideo");
144 // KeySystems requires a valid ContentRendererClient and thus ContentClient.
145 // The TestContentClient is not available inside Death Tests on some
146 // platforms (see below). Therefore, always provide a TestContentClient.
147 // Explanation: When Death Tests fork, there is a valid ContentClient.
148 // However, when they launch a new process instead of forking, the global
149 // variable is not copied and for some reason TestContentClientInitializer
150 // does not get created to set the global variable in the new process.
151 SetContentClient(&test_content_client_);
152 SetRendererClientForTesting(&content_renderer_client_);
155 virtual void SetUp() OVERRIDE {
156 AddContainerAndCodecMasksForTest();
159 virtual ~KeySystemsTest() {
160 // Clear the use of content_client_, which was set in SetUp().
161 SetContentClient(NULL);
164 typedef std::vector<std::string> CodecVector;
166 const CodecVector& no_codecs() const { return no_codecs_; }
168 const CodecVector& vp8_codec() const { return vp8_codec_; }
169 const CodecVector& vp80_codec() const { return vp80_codec_; }
170 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
171 const CodecVector& vp8_and_vorbis_codecs() const {
172 return vp8_and_vorbis_codecs_;
175 const CodecVector& foovideo_codec() const { return foovideo_codec_; }
176 const CodecVector& foovideo_extended_codec() const {
177 return foovideo_extended_codec_;
179 const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
180 const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
181 const CodecVector& foovideo_and_fooaudio_codecs() const {
182 return foovideo_and_fooaudio_codecs_;
185 const CodecVector& unknown_codec() const { return unknown_codec_; }
187 const CodecVector& mixed_codecs() const { return mixed_codecs_; }
189 private:
190 const CodecVector no_codecs_;
192 CodecVector vp8_codec_;
193 CodecVector vp80_codec_;
194 CodecVector vorbis_codec_;
195 CodecVector vp8_and_vorbis_codecs_;
197 CodecVector foovideo_codec_;
198 CodecVector foovideo_extended_codec_;
199 CodecVector foovideo_dot_codec_;
200 CodecVector fooaudio_codec_;
201 CodecVector foovideo_and_fooaudio_codecs_;
203 CodecVector unknown_codec_;
205 CodecVector mixed_codecs_;
207 TestContentClient test_content_client_;
208 TestContentRendererClient content_renderer_client_;
211 // TODO(ddorwin): Consider moving GetPepperType() calls out to their own test.
213 TEST_F(KeySystemsTest, EmptyKeySystem) {
214 EXPECT_FALSE(IsConcreteSupportedKeySystem(std::string()));
215 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
216 kVideoWebM, no_codecs(), std::string()));
217 EXPECT_EQ("Unknown", KeySystemNameForUMA(std::string()));
220 // Clear Key is the only key system registered in content.
221 TEST_F(KeySystemsTest, ClearKey) {
222 EXPECT_TRUE(IsConcreteSupportedKeySystem(kClearKey));
223 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
224 kVideoWebM, no_codecs(), kClearKey));
226 EXPECT_EQ("ClearKey", KeySystemNameForUMA(kClearKey));
228 // Prefixed Clear Key is not supported internally.
229 EXPECT_FALSE(IsConcreteSupportedKeySystem(kPrefixedClearKey));
230 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
231 kVideoWebM, no_codecs(), kPrefixedClearKey));
232 EXPECT_EQ("Unknown", KeySystemNameForUMA(kPrefixedClearKey));
235 // The key system is not registered and therefore is unrecognized.
236 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
237 static const char* const kUnrecognized = "org.example.unrecognized";
239 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnrecognized));
240 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
241 kVideoWebM, no_codecs(), kUnrecognized));
243 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUnrecognized));
245 bool can_use = false;
246 EXPECT_DEBUG_DEATH_PORTABLE(
247 can_use = CanUseAesDecryptor(kUnrecognized),
248 "org.example.unrecognized is not a known concrete system");
249 EXPECT_FALSE(can_use);
251 #if defined(ENABLE_PEPPER_CDMS)
252 std::string type;
253 EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized),
254 "org.example.unrecognized is not a known concrete system");
255 EXPECT_TRUE(type.empty());
256 #endif
259 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
260 EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
261 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
262 kVideoWebM, no_codecs(), kUsesAes));
264 // No UMA value for this test key system.
265 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUsesAes));
267 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
268 #if defined(ENABLE_PEPPER_CDMS)
269 std::string type;
270 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
271 "org.example.clear is not Pepper-based");
272 EXPECT_TRUE(type.empty());
273 #endif
276 TEST_F(KeySystemsTest,
277 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1) {
278 // Valid video types.
279 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
280 kVideoWebM, vp8_codec(), kUsesAes));
281 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
282 kVideoWebM, vp80_codec(), kUsesAes));
283 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
284 kVideoWebM, vp8_and_vorbis_codecs(), kUsesAes));
285 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
286 kVideoWebM, vorbis_codec(), kUsesAes));
288 // Non-Webm codecs.
289 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
290 kVideoWebM, foovideo_codec(), kUsesAes));
291 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
292 kVideoWebM, unknown_codec(), kUsesAes));
293 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
294 kVideoWebM, mixed_codecs(), kUsesAes));
296 // Valid audio types.
297 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
298 kAudioWebM, no_codecs(), kUsesAes));
299 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
300 kAudioWebM, vorbis_codec(), kUsesAes));
302 // Non-audio codecs.
303 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
304 kAudioWebM, vp8_codec(), kUsesAes));
305 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
306 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
308 // Non-Webm codec.
309 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
310 kAudioWebM, fooaudio_codec(), kUsesAes));
313 // No parent is registered for UsesAes.
314 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
315 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUsesAesParent));
316 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
317 kVideoWebM, no_codecs(), kUsesAesParent));
319 // The parent is not supported for most things.
320 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUsesAesParent));
321 bool result = false;
322 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent),
323 "org.example is not a known concrete system");
324 EXPECT_FALSE(result);
325 #if defined(ENABLE_PEPPER_CDMS)
326 std::string type;
327 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
328 "org.example is not a known concrete system");
329 EXPECT_TRUE(type.empty());
330 #endif
333 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
334 // Case sensitive.
335 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.ClEaR"));
336 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
337 kVideoWebM, no_codecs(), "org.example.ClEaR"));
339 // TLDs are not allowed.
340 EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
341 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
342 kVideoWebM, no_codecs(), "org."));
343 EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
344 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
345 kVideoWebM, no_codecs(), "com"));
347 // Extra period.
348 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example."));
349 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
350 kVideoWebM, no_codecs(), "org.example."));
352 // Incomplete.
353 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clea"));
354 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
355 kVideoWebM, no_codecs(), "org.example.clea"));
357 // Extra character.
358 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clearz"));
359 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
360 kVideoWebM, no_codecs(), "org.example.clearz"));
362 // There are no child key systems for UsesAes.
363 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clear.foo"));
364 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
365 kVideoWebM, no_codecs(), "org.example.clear.foo"));
368 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
369 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
370 std::string(), no_codecs(), kUsesAes));
371 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
372 std::string(), no_codecs(), kUsesAesParent));
374 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
375 std::string(), no_codecs(), "org.example.foo"));
376 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
377 std::string(), no_codecs(), "org.example.clear.foo"));
380 // Tests the second registered container type.
381 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
382 TEST_F(KeySystemsTest,
383 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
384 // Valid video types.
385 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
386 kVideoFoo, no_codecs(), kUsesAes));
387 // The parent should be supported but is not. See http://crbug.com/164303.
388 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
389 kVideoFoo, no_codecs(), kUsesAesParent));
390 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
391 kVideoFoo, foovideo_codec(), kUsesAes));
392 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
393 kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
394 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
395 kVideoFoo, fooaudio_codec(), kUsesAes));
397 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
398 // They should really pass canPlayType().
399 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
400 kVideoFoo, foovideo_extended_codec(), kUsesAes));
402 // Invalid codec format.
403 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
404 kVideoFoo, foovideo_dot_codec(), kUsesAes));
406 // Non-container2 codec.
407 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
408 kVideoFoo, vp8_codec(), kUsesAes));
409 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
410 kVideoFoo, unknown_codec(), kUsesAes));
411 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
412 kVideoFoo, mixed_codecs(), kUsesAes));
414 // Valid audio types.
415 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
416 kAudioFoo, no_codecs(), kUsesAes));
417 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
418 kAudioFoo, fooaudio_codec(), kUsesAes));
420 // Non-audio codecs.
421 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
422 kAudioFoo, foovideo_codec(), kUsesAes));
423 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
424 kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
426 // Non-container2 codec.
427 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
428 kAudioFoo, vorbis_codec(), kUsesAes));
432 // Non-AesDecryptor-based key system.
435 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
436 EXPECT_TRUE(IsConcreteSupportedKeySystem(kExternal));
437 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
438 kVideoWebM, no_codecs(), kExternal));
440 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
441 #if defined(ENABLE_PEPPER_CDMS)
442 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
443 #endif // defined(ENABLE_PEPPER_CDMS)
447 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
448 // The parent system is not a concrete system but is supported.
449 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalParent));
450 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
451 kVideoWebM, no_codecs(), kExternalParent));
453 // The parent is not supported for most things.
454 EXPECT_EQ("Unknown", KeySystemNameForUMA(kExternalParent));
455 bool result = false;
456 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
457 "com.example is not a known concrete system");
458 EXPECT_FALSE(result);
459 #if defined(ENABLE_PEPPER_CDMS)
460 std::string type;
461 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
462 "com.example is not a known concrete system");
463 EXPECT_TRUE(type.empty());
464 #endif
467 TEST_F(
468 KeySystemsTest,
469 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
470 // Valid video types.
471 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
472 kVideoWebM, no_codecs(), kExternal));
473 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
474 kVideoWebM, vp8_codec(), kExternal));
475 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
476 kVideoWebM, vp80_codec(), kExternal));
477 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
478 kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
479 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
480 kVideoWebM, vorbis_codec(), kExternal));
482 // Valid video types - parent key system.
483 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
484 kVideoWebM, no_codecs(), kExternalParent));
485 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
486 kVideoWebM, vp8_codec(), kExternalParent));
487 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
488 kVideoWebM, vp80_codec(), kExternalParent));
489 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
490 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
491 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
492 kVideoWebM, vorbis_codec(), kExternalParent));
494 // Non-Webm codecs.
495 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
496 kVideoWebM, foovideo_codec(), kExternal));
497 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
498 kVideoWebM, unknown_codec(), kExternal));
499 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
500 kVideoWebM, mixed_codecs(), kExternal));
502 // Valid audio types.
503 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
504 kAudioWebM, no_codecs(), kExternal));
505 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
506 kAudioWebM, vorbis_codec(), kExternal));
508 // Valid audio types - parent key system.
509 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
510 kAudioWebM, no_codecs(), kExternalParent));
511 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
512 kAudioWebM, vorbis_codec(), kExternalParent));
514 // Non-audio codecs.
515 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
516 kAudioWebM, vp8_codec(), kExternal));
517 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
518 kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
520 // Non-Webm codec.
521 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
522 kAudioWebM, fooaudio_codec(), kExternal));
525 TEST_F(
526 KeySystemsTest,
527 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
528 // Valid video types.
529 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
530 kVideoFoo, no_codecs(), kExternal));
531 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
532 kVideoFoo, foovideo_codec(), kExternal));
533 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
534 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
535 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
536 kVideoFoo, fooaudio_codec(), kExternal));
538 // Valid video types - parent key system.
539 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
540 kVideoFoo, no_codecs(), kExternalParent));
541 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
542 kVideoFoo, foovideo_codec(), kExternalParent));
543 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
544 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
545 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
546 kVideoFoo, fooaudio_codec(), kExternalParent));
548 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
549 // They should really pass canPlayType().
550 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
551 kVideoFoo, foovideo_extended_codec(), kExternal));
553 // Invalid codec format.
554 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
555 kVideoFoo, foovideo_dot_codec(), kExternal));
557 // Non-container2 codecs.
558 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
559 kVideoFoo, vp8_codec(), kExternal));
560 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
561 kVideoFoo, unknown_codec(), kExternal));
562 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
563 kVideoFoo, mixed_codecs(), kExternal));
565 // Valid audio types.
566 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
567 kAudioFoo, no_codecs(), kExternal));
568 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
569 kAudioFoo, fooaudio_codec(), kExternal));
571 // Valid audio types - parent key system.
572 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
573 kAudioFoo, no_codecs(), kExternalParent));
574 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
575 kAudioFoo, fooaudio_codec(), kExternalParent));
577 // Non-audio codecs.
578 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
579 kAudioFoo, foovideo_codec(), kExternal));
580 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
581 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
583 // Non-container2 codec.
584 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
585 kAudioFoo, vorbis_codec(), kExternal));
588 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
589 EXPECT_EQ("ClearKey", KeySystemNameForUMA(kClearKey));
590 // Prefixed is not supported internally.
591 EXPECT_EQ("Unknown", KeySystemNameForUMA(kPrefixedClearKey));
593 // External Clear Key never has a UMA name.
594 EXPECT_EQ("Unknown", KeySystemNameForUMA(kExternalClearKey));
596 #if defined(WIDEVINE_CDM_AVAILABLE)
597 const char* const kTestWidevineUmaName = "Widevine";
598 #else
599 const char* const kTestWidevineUmaName = "Unknown";
600 #endif
601 EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha"));
604 } // namespace content