Standardize usage of virtual/override/final specifiers.
[chromium-blink-merge.git] / content / renderer / media / crypto / key_systems_unittest.cc
blobd7c980dd17f72735804e1ccf3356d09b5275f4cf
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/renderer/media/crypto/key_systems.h"
11 #include "content/test/test_content_client.h"
12 #include "media/base/eme_constants.h"
13 #include "media/base/key_system_info.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/platform/WebString.h"
17 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
19 // Death tests are not always available, including on Android.
20 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that
21 // death tests are not available and NDEBUG is not defined.
22 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
23 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
24 EXPECT_DEBUG_DEATH(statement, regex)
25 #else
26 #if defined(NDEBUG)
27 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
28 do { statement; } while (false)
29 #else
30 #include "base/logging.h"
31 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \
32 LOG(WARNING) << "Death tests are not supported on this platform.\n" \
33 << "Statement '" #statement "' cannot be verified.";
34 #endif // defined(NDEBUG)
35 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID)
37 namespace content {
39 using blink::WebString;
40 using media::KeySystemInfo;
42 // These are the (fake) key systems that are registered for these tests.
43 // kUsesAes uses the AesDecryptor like Clear Key.
44 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
45 const char kUsesAes[] = "org.example.clear";
46 const char kUsesAesParent[] = "org.example"; // Not registered.
47 const char kExternal[] = "com.example.test";
48 const char kExternalParent[] = "com.example";
50 const char kClearKey[] = "org.w3.clearkey";
51 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
52 const char kExternalClearKey[] = "org.chromium.externalclearkey";
54 const char kAudioWebM[] = "audio/webm";
55 const char kVideoWebM[] = "video/webm";
56 const char kAudioFoo[] = "audio/foo";
57 const char kVideoFoo[] = "video/foo";
59 // Pick some arbitrary bit fields as long as they are not in conflict with the
60 // real ones.
61 enum TestCodec {
62 TEST_CODEC_FOO_AUDIO = 1 << 10, // An audio codec for foo container.
63 TEST_CODEC_FOO_AUDIO_ALL = TEST_CODEC_FOO_AUDIO,
64 TEST_CODEC_FOO_VIDEO = 1 << 11, // A video codec for foo container.
65 TEST_CODEC_FOO_VIDEO_ALL = TEST_CODEC_FOO_VIDEO,
66 TEST_CODEC_FOO_ALL = TEST_CODEC_FOO_AUDIO_ALL | TEST_CODEC_FOO_VIDEO_ALL
69 COMPILE_ASSERT((TEST_CODEC_FOO_ALL & media::EME_CODEC_ALL) ==
70 media::EME_CODEC_NONE,
71 test_codec_masks_should_only_use_invalid_codec_masks);
73 // Adds test container and codec masks.
74 // This function must be called after SetContentClient() is called.
75 // More details: AddXxxMask() will create KeySystems if it hasn't been created.
76 // During KeySystems's construction GetContentClient() will be used to add key
77 // systems. In test code, the content client is set by SetContentClient().
78 // Therefore, SetContentClient() must be called before this function to avoid
79 // access violation.
80 static void AddContainerAndCodecMasksForTest() {
81 // Since KeySystems is a singleton. Make sure we only add test container and
82 // codec masks once per process.
83 static bool is_test_masks_added = false;
85 if (is_test_masks_added)
86 return;
88 AddContainerMask("audio/foo", TEST_CODEC_FOO_AUDIO_ALL);
89 AddContainerMask("video/foo", TEST_CODEC_FOO_ALL);
90 AddCodecMask("fooaudio", TEST_CODEC_FOO_AUDIO);
91 AddCodecMask("foovideo", TEST_CODEC_FOO_VIDEO);
93 is_test_masks_added = true;
96 class TestContentRendererClient : public ContentRendererClient {
97 void AddKeySystems(std::vector<media::KeySystemInfo>* key_systems) override;
100 void TestContentRendererClient::AddKeySystems(
101 std::vector<media::KeySystemInfo>* key_systems) {
102 KeySystemInfo aes(kUsesAes);
103 aes.supported_codecs = media::EME_CODEC_WEBM_ALL;
104 aes.supported_codecs |= TEST_CODEC_FOO_ALL;
105 aes.supported_init_data_types = media::EME_INIT_DATA_TYPE_WEBM;
106 aes.use_aes_decryptor = true;
107 key_systems->push_back(aes);
109 KeySystemInfo ext(kExternal);
110 ext.supported_codecs = media::EME_CODEC_WEBM_ALL;
111 ext.supported_codecs |= TEST_CODEC_FOO_ALL;
112 ext.supported_init_data_types = media::EME_INIT_DATA_TYPE_WEBM;
113 ext.parent_key_system = kExternalParent;
114 #if defined(ENABLE_PEPPER_CDMS)
115 ext.pepper_type = "application/x-ppapi-external-cdm";
116 #endif // defined(ENABLE_PEPPER_CDMS)
117 key_systems->push_back(ext);
120 // TODO(sandersd): Refactor. http://crbug.com/417444
121 class KeySystemsTest : public testing::Test {
122 protected:
123 KeySystemsTest() {
124 vp8_codec_.push_back("vp8");
126 vp80_codec_.push_back("vp8.0");
128 vp9_codec_.push_back("vp9");
130 vp90_codec_.push_back("vp9.0");
132 vorbis_codec_.push_back("vorbis");
134 vp8_and_vorbis_codecs_.push_back("vp8");
135 vp8_and_vorbis_codecs_.push_back("vorbis");
137 vp9_and_vorbis_codecs_.push_back("vp9");
138 vp9_and_vorbis_codecs_.push_back("vorbis");
140 foovideo_codec_.push_back("foovideo");
142 foovideo_extended_codec_.push_back("foovideo.4D400C");
144 foovideo_dot_codec_.push_back("foovideo.");
146 fooaudio_codec_.push_back("fooaudio");
148 foovideo_and_fooaudio_codecs_.push_back("foovideo");
149 foovideo_and_fooaudio_codecs_.push_back("fooaudio");
151 unknown_codec_.push_back("unknown");
153 mixed_codecs_.push_back("vorbis");
154 mixed_codecs_.push_back("foovideo");
156 // KeySystems requires a valid ContentRendererClient and thus ContentClient.
157 // The TestContentClient is not available inside Death Tests on some
158 // platforms (see below). Therefore, always provide a TestContentClient.
159 // Explanation: When Death Tests fork, there is a valid ContentClient.
160 // However, when they launch a new process instead of forking, the global
161 // variable is not copied and for some reason TestContentClientInitializer
162 // does not get created to set the global variable in the new process.
163 SetContentClient(&test_content_client_);
164 SetRendererClientForTesting(&content_renderer_client_);
167 void SetUp() override { AddContainerAndCodecMasksForTest(); }
169 ~KeySystemsTest() override {
170 // Clear the use of content_client_, which was set in SetUp().
171 SetContentClient(NULL);
174 typedef std::vector<std::string> CodecVector;
176 const CodecVector& no_codecs() const { return no_codecs_; }
178 const CodecVector& vp8_codec() const { return vp8_codec_; }
179 const CodecVector& vp80_codec() const { return vp80_codec_; }
180 const CodecVector& vp9_codec() const { return vp9_codec_; }
181 const CodecVector& vp90_codec() const { return vp90_codec_; }
183 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
185 const CodecVector& vp8_and_vorbis_codecs() const {
186 return vp8_and_vorbis_codecs_;
188 const CodecVector& vp9_and_vorbis_codecs() const {
189 return vp9_and_vorbis_codecs_;
192 const CodecVector& foovideo_codec() const { return foovideo_codec_; }
193 const CodecVector& foovideo_extended_codec() const {
194 return foovideo_extended_codec_;
196 const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
197 const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
198 const CodecVector& foovideo_and_fooaudio_codecs() const {
199 return foovideo_and_fooaudio_codecs_;
202 const CodecVector& unknown_codec() const { return unknown_codec_; }
204 const CodecVector& mixed_codecs() const { return mixed_codecs_; }
206 private:
207 const CodecVector no_codecs_;
208 CodecVector vp8_codec_;
209 CodecVector vp80_codec_;
210 CodecVector vp9_codec_;
211 CodecVector vp90_codec_;
212 CodecVector vorbis_codec_;
213 CodecVector vp8_and_vorbis_codecs_;
214 CodecVector vp9_and_vorbis_codecs_;
216 CodecVector foovideo_codec_;
217 CodecVector foovideo_extended_codec_;
218 CodecVector foovideo_dot_codec_;
219 CodecVector fooaudio_codec_;
220 CodecVector foovideo_and_fooaudio_codecs_;
222 CodecVector unknown_codec_;
224 CodecVector mixed_codecs_;
226 TestContentClient test_content_client_;
227 TestContentRendererClient content_renderer_client_;
230 // TODO(ddorwin): Consider moving GetPepperType() calls out to their own test.
232 TEST_F(KeySystemsTest, EmptyKeySystem) {
233 EXPECT_FALSE(IsConcreteSupportedKeySystem(std::string()));
234 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
235 kVideoWebM, no_codecs(), std::string()));
236 EXPECT_EQ("Unknown", KeySystemNameForUMA(std::string()));
239 // Clear Key is the only key system registered in content.
240 TEST_F(KeySystemsTest, ClearKey) {
241 EXPECT_TRUE(IsConcreteSupportedKeySystem(kClearKey));
242 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
243 kVideoWebM, no_codecs(), kClearKey));
245 EXPECT_EQ("ClearKey", KeySystemNameForUMA(kClearKey));
247 // Prefixed Clear Key is not supported internally.
248 EXPECT_FALSE(IsConcreteSupportedKeySystem(kPrefixedClearKey));
249 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
250 kVideoWebM, no_codecs(), kPrefixedClearKey));
251 EXPECT_EQ("Unknown", KeySystemNameForUMA(kPrefixedClearKey));
254 // The key system is not registered and therefore is unrecognized.
255 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
256 static const char* const kUnrecognized = "org.example.unrecognized";
258 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnrecognized));
259 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
260 kVideoWebM, no_codecs(), kUnrecognized));
262 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUnrecognized));
264 bool can_use = false;
265 EXPECT_DEBUG_DEATH_PORTABLE(
266 can_use = CanUseAesDecryptor(kUnrecognized),
267 "org.example.unrecognized is not a known concrete system");
268 EXPECT_FALSE(can_use);
270 #if defined(ENABLE_PEPPER_CDMS)
271 std::string type;
272 EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized),
273 "org.example.unrecognized is not a known concrete system");
274 EXPECT_TRUE(type.empty());
275 #endif
278 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
279 EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
280 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
281 kVideoWebM, no_codecs(), kUsesAes));
283 // No UMA value for this test key system.
284 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUsesAes));
286 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
287 #if defined(ENABLE_PEPPER_CDMS)
288 std::string type;
289 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
290 "org.example.clear is not Pepper-based");
291 EXPECT_TRUE(type.empty());
292 #endif
295 TEST_F(KeySystemsTest,
296 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1) {
297 // Valid video types.
298 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
299 kVideoWebM, vp8_codec(), kUsesAes));
300 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
301 kVideoWebM, vp80_codec(), kUsesAes));
302 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
303 kVideoWebM, vp8_and_vorbis_codecs(), kUsesAes));
304 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
305 kVideoWebM, vp9_codec(), kUsesAes));
306 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
307 kVideoWebM, vp90_codec(), kUsesAes));
308 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
309 kVideoWebM, vp9_and_vorbis_codecs(), kUsesAes));
310 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
311 kVideoWebM, vorbis_codec(), kUsesAes));
313 // Non-Webm codecs.
314 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
315 kVideoWebM, foovideo_codec(), kUsesAes));
316 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
317 kVideoWebM, unknown_codec(), kUsesAes));
318 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
319 kVideoWebM, mixed_codecs(), kUsesAes));
321 // Valid audio types.
322 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
323 kAudioWebM, no_codecs(), kUsesAes));
324 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
325 kAudioWebM, vorbis_codec(), kUsesAes));
327 // Non-audio codecs.
328 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
329 kAudioWebM, vp8_codec(), kUsesAes));
330 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
331 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
332 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
333 kAudioWebM, vp9_codec(), kUsesAes));
334 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
335 kAudioWebM, vp9_and_vorbis_codecs(), kUsesAes));
337 // Non-Webm codec.
338 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
339 kAudioWebM, fooaudio_codec(), kUsesAes));
342 // No parent is registered for UsesAes.
343 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
344 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUsesAesParent));
345 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
346 kVideoWebM, no_codecs(), kUsesAesParent));
348 // The parent is not supported for most things.
349 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUsesAesParent));
350 bool result = false;
351 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent),
352 "org.example is not a known concrete system");
353 EXPECT_FALSE(result);
354 #if defined(ENABLE_PEPPER_CDMS)
355 std::string type;
356 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
357 "org.example is not a known concrete system");
358 EXPECT_TRUE(type.empty());
359 #endif
362 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
363 // Case sensitive.
364 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.ClEaR"));
365 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
366 kVideoWebM, no_codecs(), "org.example.ClEaR"));
368 // TLDs are not allowed.
369 EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
370 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
371 kVideoWebM, no_codecs(), "org."));
372 EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
373 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
374 kVideoWebM, no_codecs(), "com"));
376 // Extra period.
377 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example."));
378 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
379 kVideoWebM, no_codecs(), "org.example."));
381 // Incomplete.
382 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clea"));
383 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
384 kVideoWebM, no_codecs(), "org.example.clea"));
386 // Extra character.
387 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clearz"));
388 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
389 kVideoWebM, no_codecs(), "org.example.clearz"));
391 // There are no child key systems for UsesAes.
392 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clear.foo"));
393 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
394 kVideoWebM, no_codecs(), "org.example.clear.foo"));
397 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
398 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
399 std::string(), no_codecs(), kUsesAes));
400 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
401 std::string(), no_codecs(), kUsesAesParent));
403 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
404 std::string(), no_codecs(), "org.example.foo"));
405 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
406 std::string(), no_codecs(), "org.example.clear.foo"));
409 // Tests the second registered container type.
410 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
411 TEST_F(KeySystemsTest,
412 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
413 // Valid video types.
414 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
415 kVideoFoo, no_codecs(), kUsesAes));
416 // The parent should be supported but is not. See http://crbug.com/164303.
417 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
418 kVideoFoo, no_codecs(), kUsesAesParent));
419 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
420 kVideoFoo, foovideo_codec(), kUsesAes));
421 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
422 kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
423 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
424 kVideoFoo, fooaudio_codec(), kUsesAes));
426 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
427 // They should really pass canPlayType().
428 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
429 kVideoFoo, foovideo_extended_codec(), kUsesAes));
431 // Invalid codec format.
432 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
433 kVideoFoo, foovideo_dot_codec(), kUsesAes));
435 // Non-container2 codec.
436 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
437 kVideoFoo, vp8_codec(), kUsesAes));
438 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
439 kVideoFoo, unknown_codec(), kUsesAes));
440 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
441 kVideoFoo, mixed_codecs(), kUsesAes));
443 // Valid audio types.
444 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
445 kAudioFoo, no_codecs(), kUsesAes));
446 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
447 kAudioFoo, fooaudio_codec(), kUsesAes));
449 // Non-audio codecs.
450 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
451 kAudioFoo, foovideo_codec(), kUsesAes));
452 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
453 kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
455 // Non-container2 codec.
456 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
457 kAudioFoo, vorbis_codec(), kUsesAes));
461 // Non-AesDecryptor-based key system.
464 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
465 EXPECT_TRUE(IsConcreteSupportedKeySystem(kExternal));
466 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
467 kVideoWebM, no_codecs(), kExternal));
469 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
470 #if defined(ENABLE_PEPPER_CDMS)
471 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
472 #endif // defined(ENABLE_PEPPER_CDMS)
476 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
477 // The parent system is not a concrete system but is supported.
478 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalParent));
479 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
480 kVideoWebM, no_codecs(), kExternalParent));
482 // The parent is not supported for most things.
483 EXPECT_EQ("Unknown", KeySystemNameForUMA(kExternalParent));
484 bool result = false;
485 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
486 "com.example is not a known concrete system");
487 EXPECT_FALSE(result);
488 #if defined(ENABLE_PEPPER_CDMS)
489 std::string type;
490 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
491 "com.example is not a known concrete system");
492 EXPECT_TRUE(type.empty());
493 #endif
496 TEST_F(
497 KeySystemsTest,
498 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
499 // Valid video types.
500 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
501 kVideoWebM, no_codecs(), kExternal));
502 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
503 kVideoWebM, vp8_codec(), kExternal));
504 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
505 kVideoWebM, vp80_codec(), kExternal));
506 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
507 kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
508 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
509 kVideoWebM, vp9_codec(), kExternal));
510 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
511 kVideoWebM, vp90_codec(), kExternal));
512 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
513 kVideoWebM, vp9_and_vorbis_codecs(), kExternal));
514 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
515 kVideoWebM, vorbis_codec(), kExternal));
517 // Valid video types - parent key system.
518 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
519 kVideoWebM, no_codecs(), kExternalParent));
520 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
521 kVideoWebM, vp8_codec(), kExternalParent));
522 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
523 kVideoWebM, vp80_codec(), kExternalParent));
524 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
525 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
526 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
527 kVideoWebM, vp9_codec(), kExternalParent));
528 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
529 kVideoWebM, vp90_codec(), kExternalParent));
530 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
531 kVideoWebM, vp9_and_vorbis_codecs(), kExternalParent));
532 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
533 kVideoWebM, vorbis_codec(), kExternalParent));
535 // Non-Webm codecs.
536 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
537 kVideoWebM, foovideo_codec(), kExternal));
538 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
539 kVideoWebM, unknown_codec(), kExternal));
540 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
541 kVideoWebM, mixed_codecs(), kExternal));
543 // Valid audio types.
544 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
545 kAudioWebM, no_codecs(), kExternal));
546 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
547 kAudioWebM, vorbis_codec(), kExternal));
549 // Valid audio types - parent key system.
550 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
551 kAudioWebM, no_codecs(), kExternalParent));
552 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
553 kAudioWebM, vorbis_codec(), kExternalParent));
555 // Non-audio codecs.
556 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
557 kAudioWebM, vp8_codec(), kExternal));
558 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
559 kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
560 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
561 kAudioWebM, vp9_codec(), kExternal));
562 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
563 kAudioWebM, vp9_and_vorbis_codecs(), kExternal));
565 // Non-Webm codec.
566 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
567 kAudioWebM, fooaudio_codec(), kExternal));
570 TEST_F(
571 KeySystemsTest,
572 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
573 // Valid video types.
574 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
575 kVideoFoo, no_codecs(), kExternal));
576 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
577 kVideoFoo, foovideo_codec(), kExternal));
578 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
579 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
580 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
581 kVideoFoo, fooaudio_codec(), kExternal));
583 // Valid video types - parent key system.
584 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
585 kVideoFoo, no_codecs(), kExternalParent));
586 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
587 kVideoFoo, foovideo_codec(), kExternalParent));
588 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
589 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
590 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
591 kVideoFoo, fooaudio_codec(), kExternalParent));
593 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
594 // They should really pass canPlayType().
595 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
596 kVideoFoo, foovideo_extended_codec(), kExternal));
598 // Invalid codec format.
599 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
600 kVideoFoo, foovideo_dot_codec(), kExternal));
602 // Non-container2 codecs.
603 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
604 kVideoFoo, vp8_codec(), kExternal));
605 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
606 kVideoFoo, unknown_codec(), kExternal));
607 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
608 kVideoFoo, mixed_codecs(), kExternal));
610 // Valid audio types.
611 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
612 kAudioFoo, no_codecs(), kExternal));
613 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
614 kAudioFoo, fooaudio_codec(), kExternal));
616 // Valid audio types - parent key system.
617 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
618 kAudioFoo, no_codecs(), kExternalParent));
619 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
620 kAudioFoo, fooaudio_codec(), kExternalParent));
622 // Non-audio codecs.
623 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
624 kAudioFoo, foovideo_codec(), kExternal));
625 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
626 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
628 // Non-container2 codec.
629 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
630 kAudioFoo, vorbis_codec(), kExternal));
633 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
634 EXPECT_EQ("ClearKey", KeySystemNameForUMA(kClearKey));
635 // Prefixed is not supported internally.
636 EXPECT_EQ("Unknown", KeySystemNameForUMA(kPrefixedClearKey));
638 // External Clear Key never has a UMA name.
639 EXPECT_EQ("Unknown", KeySystemNameForUMA(kExternalClearKey));
641 #if defined(WIDEVINE_CDM_AVAILABLE)
642 const char* const kTestWidevineUmaName = "Widevine";
643 #else
644 const char* const kTestWidevineUmaName = "Unknown";
645 #endif
646 EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha"));
649 } // namespace content