• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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.
4 
5 #include <string>
6 #include <vector>
7 
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"
15 
16 #include "widevine_cdm_version.h"  // In SHARED_INTERMEDIATE_DIR.
17 
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)
35 
36 namespace content {
37 
38 using blink::WebString;
39 
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";
47 
48 const char kClearKey[] = "org.w3.clearkey";
49 const char kPrefixedClearKey[] = "webkit-org.w3.clearkey";
50 const char kExternalClearKey[] = "org.chromium.externalclearkey";
51 
52 const char kAudioWebM[] = "audio/webm";
53 const char kVideoWebM[] = "video/webm";
54 const char kAudioFoo[] = "audio/foo";
55 const char kVideoFoo[] = "video/foo";
56 
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
65 };
66 
67 COMPILE_ASSERT((TEST_CODEC_FOO_ALL & EME_CODEC_ALL) == EME_CODEC_NONE,
68                 test_codec_masks_should_only_use_invalid_codec_masks);
69 
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.
AddContainerAndCodecMasksForTest()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;
81 
82   if (is_test_masks_added)
83     return;
84 
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);
89 
90   is_test_masks_added = true;
91 }
92 
93 class TestContentRendererClient : public ContentRendererClient {
94   virtual void AddKeySystems(
95       std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
96 };
97 
AddKeySystems(std::vector<content::KeySystemInfo> * key_systems)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);
105 
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);
114 }
115 
116 class KeySystemsTest : public testing::Test {
117  protected:
KeySystemsTest()118   KeySystemsTest() {
119     vp8_codec_.push_back("vp8");
120 
121     vp80_codec_.push_back("vp8.0");
122 
123     vp9_codec_.push_back("vp9");
124 
125     vp90_codec_.push_back("vp9.0");
126 
127     vorbis_codec_.push_back("vorbis");
128 
129     vp8_and_vorbis_codecs_.push_back("vp8");
130     vp8_and_vorbis_codecs_.push_back("vorbis");
131 
132     vp9_and_vorbis_codecs_.push_back("vp9");
133     vp9_and_vorbis_codecs_.push_back("vorbis");
134 
135     foovideo_codec_.push_back("foovideo");
136 
137     foovideo_extended_codec_.push_back("foovideo.4D400C");
138 
139     foovideo_dot_codec_.push_back("foovideo.");
140 
141     fooaudio_codec_.push_back("fooaudio");
142 
143     foovideo_and_fooaudio_codecs_.push_back("foovideo");
144     foovideo_and_fooaudio_codecs_.push_back("fooaudio");
145 
146     unknown_codec_.push_back("unknown");
147 
148     mixed_codecs_.push_back("vorbis");
149     mixed_codecs_.push_back("foovideo");
150 
151     // KeySystems requires a valid ContentRendererClient and thus ContentClient.
152     // The TestContentClient is not available inside Death Tests on some
153     // platforms (see below). Therefore, always provide a TestContentClient.
154     // Explanation: When Death Tests fork, there is a valid ContentClient.
155     // However, when they launch a new process instead of forking, the global
156     // variable is not copied and for some reason TestContentClientInitializer
157     // does not get created to set the global variable in the new process.
158     SetContentClient(&test_content_client_);
159     SetRendererClientForTesting(&content_renderer_client_);
160   }
161 
SetUp()162   virtual void SetUp() OVERRIDE {
163     AddContainerAndCodecMasksForTest();
164   }
165 
~KeySystemsTest()166   virtual ~KeySystemsTest() {
167     // Clear the use of content_client_, which was set in SetUp().
168     SetContentClient(NULL);
169   }
170 
171   typedef std::vector<std::string> CodecVector;
172 
no_codecs() const173   const CodecVector& no_codecs() const { return no_codecs_; }
174 
vp8_codec() const175   const CodecVector& vp8_codec() const { return vp8_codec_; }
vp80_codec() const176   const CodecVector& vp80_codec() const { return vp80_codec_; }
vp9_codec() const177   const CodecVector& vp9_codec() const { return vp9_codec_; }
vp90_codec() const178   const CodecVector& vp90_codec() const { return vp90_codec_; }
179 
vorbis_codec() const180   const CodecVector& vorbis_codec() const { return vorbis_codec_; }
181 
vp8_and_vorbis_codecs() const182   const CodecVector& vp8_and_vorbis_codecs() const {
183     return vp8_and_vorbis_codecs_;
184   }
vp9_and_vorbis_codecs() const185   const CodecVector& vp9_and_vorbis_codecs() const {
186     return vp9_and_vorbis_codecs_;
187   }
188 
foovideo_codec() const189   const CodecVector& foovideo_codec() const { return foovideo_codec_; }
foovideo_extended_codec() const190   const CodecVector& foovideo_extended_codec() const {
191     return foovideo_extended_codec_;
192   }
foovideo_dot_codec() const193   const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
fooaudio_codec() const194   const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
foovideo_and_fooaudio_codecs() const195   const CodecVector& foovideo_and_fooaudio_codecs() const {
196     return foovideo_and_fooaudio_codecs_;
197   }
198 
unknown_codec() const199   const CodecVector& unknown_codec() const { return unknown_codec_; }
200 
mixed_codecs() const201   const CodecVector& mixed_codecs() const { return mixed_codecs_; }
202 
203  private:
204   const CodecVector no_codecs_;
205   CodecVector vp8_codec_;
206   CodecVector vp80_codec_;
207   CodecVector vp9_codec_;
208   CodecVector vp90_codec_;
209   CodecVector vorbis_codec_;
210   CodecVector vp8_and_vorbis_codecs_;
211   CodecVector vp9_and_vorbis_codecs_;
212 
213   CodecVector foovideo_codec_;
214   CodecVector foovideo_extended_codec_;
215   CodecVector foovideo_dot_codec_;
216   CodecVector fooaudio_codec_;
217   CodecVector foovideo_and_fooaudio_codecs_;
218 
219   CodecVector unknown_codec_;
220 
221   CodecVector mixed_codecs_;
222 
223   TestContentClient test_content_client_;
224   TestContentRendererClient content_renderer_client_;
225 };
226 
227 // TODO(ddorwin): Consider moving GetPepperType() calls out to their own test.
228 
TEST_F(KeySystemsTest,EmptyKeySystem)229 TEST_F(KeySystemsTest, EmptyKeySystem) {
230   EXPECT_FALSE(IsConcreteSupportedKeySystem(std::string()));
231   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
232       kVideoWebM, no_codecs(), std::string()));
233   EXPECT_EQ("Unknown", KeySystemNameForUMA(std::string()));
234 }
235 
236 // Clear Key is the only key system registered in content.
TEST_F(KeySystemsTest,ClearKey)237 TEST_F(KeySystemsTest, ClearKey) {
238   EXPECT_TRUE(IsConcreteSupportedKeySystem(kClearKey));
239   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
240       kVideoWebM, no_codecs(), kClearKey));
241 
242   EXPECT_EQ("ClearKey", KeySystemNameForUMA(kClearKey));
243 
244   // Prefixed Clear Key is not supported internally.
245   EXPECT_FALSE(IsConcreteSupportedKeySystem(kPrefixedClearKey));
246   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
247       kVideoWebM, no_codecs(), kPrefixedClearKey));
248   EXPECT_EQ("Unknown", KeySystemNameForUMA(kPrefixedClearKey));
249 }
250 
251 // The key system is not registered and therefore is unrecognized.
TEST_F(KeySystemsTest,Basic_UnrecognizedKeySystem)252 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
253   static const char* const kUnrecognized = "org.example.unrecognized";
254 
255   EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnrecognized));
256   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
257       kVideoWebM, no_codecs(), kUnrecognized));
258 
259   EXPECT_EQ("Unknown", KeySystemNameForUMA(kUnrecognized));
260 
261   bool can_use = false;
262   EXPECT_DEBUG_DEATH_PORTABLE(
263       can_use = CanUseAesDecryptor(kUnrecognized),
264       "org.example.unrecognized is not a known concrete system");
265   EXPECT_FALSE(can_use);
266 
267 #if defined(ENABLE_PEPPER_CDMS)
268   std::string type;
269   EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized),
270                      "org.example.unrecognized is not a known concrete system");
271   EXPECT_TRUE(type.empty());
272 #endif
273 }
274 
TEST_F(KeySystemsTest,Basic_UsesAesDecryptor)275 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
276   EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
277   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
278       kVideoWebM, no_codecs(), kUsesAes));
279 
280   // No UMA value for this test key system.
281   EXPECT_EQ("Unknown", KeySystemNameForUMA(kUsesAes));
282 
283   EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
284 #if defined(ENABLE_PEPPER_CDMS)
285   std::string type;
286   EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
287                      "org.example.clear is not Pepper-based");
288   EXPECT_TRUE(type.empty());
289 #endif
290 }
291 
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1)292 TEST_F(KeySystemsTest,
293        IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1) {
294   // Valid video types.
295   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
296       kVideoWebM, vp8_codec(), kUsesAes));
297   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
298       kVideoWebM, vp80_codec(), kUsesAes));
299   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
300       kVideoWebM, vp8_and_vorbis_codecs(), kUsesAes));
301   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
302       kVideoWebM, vp9_codec(), kUsesAes));
303   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
304       kVideoWebM, vp90_codec(), kUsesAes));
305   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
306       kVideoWebM, vp9_and_vorbis_codecs(), kUsesAes));
307   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
308       kVideoWebM, vorbis_codec(), kUsesAes));
309 
310   // Non-Webm codecs.
311   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
312       kVideoWebM, foovideo_codec(), kUsesAes));
313   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
314       kVideoWebM, unknown_codec(), kUsesAes));
315   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
316       kVideoWebM, mixed_codecs(), kUsesAes));
317 
318   // Valid audio types.
319   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
320       kAudioWebM, no_codecs(), kUsesAes));
321   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
322       kAudioWebM, vorbis_codec(), kUsesAes));
323 
324   // Non-audio codecs.
325   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
326       kAudioWebM, vp8_codec(), kUsesAes));
327   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
328       kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
329   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
330       kAudioWebM, vp9_codec(), kUsesAes));
331   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
332       kAudioWebM, vp9_and_vorbis_codecs(), kUsesAes));
333 
334   // Non-Webm codec.
335   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
336       kAudioWebM, fooaudio_codec(), kUsesAes));
337 }
338 
339 // No parent is registered for UsesAes.
TEST_F(KeySystemsTest,Parent_NoParentRegistered)340 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
341   EXPECT_FALSE(IsConcreteSupportedKeySystem(kUsesAesParent));
342   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
343       kVideoWebM, no_codecs(), kUsesAesParent));
344 
345   // The parent is not supported for most things.
346   EXPECT_EQ("Unknown", KeySystemNameForUMA(kUsesAesParent));
347   bool result = false;
348   EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent),
349                               "org.example is not a known concrete system");
350   EXPECT_FALSE(result);
351 #if defined(ENABLE_PEPPER_CDMS)
352   std::string type;
353   EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
354                      "org.example is not a known concrete system");
355   EXPECT_TRUE(type.empty());
356 #endif
357 }
358 
TEST_F(KeySystemsTest,IsSupportedKeySystem_InvalidVariants)359 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
360   // Case sensitive.
361   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.ClEaR"));
362   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
363       kVideoWebM, no_codecs(), "org.example.ClEaR"));
364 
365   // TLDs are not allowed.
366   EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
367   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
368       kVideoWebM, no_codecs(), "org."));
369   EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
370   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
371       kVideoWebM, no_codecs(), "com"));
372 
373   // Extra period.
374   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example."));
375   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
376       kVideoWebM, no_codecs(), "org.example."));
377 
378   // Incomplete.
379   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clea"));
380   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
381       kVideoWebM, no_codecs(), "org.example.clea"));
382 
383   // Extra character.
384   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clearz"));
385   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
386       kVideoWebM, no_codecs(), "org.example.clearz"));
387 
388   // There are no child key systems for UsesAes.
389   EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clear.foo"));
390   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
391       kVideoWebM, no_codecs(), "org.example.clear.foo"));
392 }
393 
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_NoType)394 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
395   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
396       std::string(), no_codecs(), kUsesAes));
397   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
398       std::string(), no_codecs(), kUsesAesParent));
399 
400   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
401       std::string(), no_codecs(), "org.example.foo"));
402   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
403       std::string(), no_codecs(), "org.example.clear.foo"));
404 }
405 
406 // Tests the second registered container type.
407 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2)408 TEST_F(KeySystemsTest,
409        IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
410   // Valid video types.
411   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
412       kVideoFoo, no_codecs(), kUsesAes));
413   // The parent should be supported but is not. See http://crbug.com/164303.
414   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
415       kVideoFoo, no_codecs(), kUsesAesParent));
416   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
417       kVideoFoo, foovideo_codec(), kUsesAes));
418   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
419       kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
420   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
421       kVideoFoo, fooaudio_codec(), kUsesAes));
422 
423   // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
424   // They should really pass canPlayType().
425   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
426       kVideoFoo, foovideo_extended_codec(), kUsesAes));
427 
428   // Invalid codec format.
429   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
430       kVideoFoo, foovideo_dot_codec(), kUsesAes));
431 
432   // Non-container2 codec.
433   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
434       kVideoFoo, vp8_codec(), kUsesAes));
435   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
436       kVideoFoo, unknown_codec(), kUsesAes));
437   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
438       kVideoFoo, mixed_codecs(), kUsesAes));
439 
440   // Valid audio types.
441   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
442       kAudioFoo, no_codecs(), kUsesAes));
443   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
444       kAudioFoo, fooaudio_codec(), kUsesAes));
445 
446   // Non-audio codecs.
447   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
448       kAudioFoo, foovideo_codec(), kUsesAes));
449   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
450       kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
451 
452   // Non-container2 codec.
453   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
454       kAudioFoo, vorbis_codec(), kUsesAes));
455 }
456 
457 //
458 // Non-AesDecryptor-based key system.
459 //
460 
TEST_F(KeySystemsTest,Basic_ExternalDecryptor)461 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
462   EXPECT_TRUE(IsConcreteSupportedKeySystem(kExternal));
463   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
464       kVideoWebM, no_codecs(), kExternal));
465 
466   EXPECT_FALSE(CanUseAesDecryptor(kExternal));
467 #if defined(ENABLE_PEPPER_CDMS)
468   EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
469 #endif  // defined(ENABLE_PEPPER_CDMS)
470 
471 }
472 
TEST_F(KeySystemsTest,Parent_ParentRegistered)473 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
474   // The parent system is not a concrete system but is supported.
475   EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalParent));
476   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
477       kVideoWebM, no_codecs(), kExternalParent));
478 
479   // The parent is not supported for most things.
480   EXPECT_EQ("Unknown", KeySystemNameForUMA(kExternalParent));
481   bool result = false;
482   EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
483                               "com.example is not a known concrete system");
484   EXPECT_FALSE(result);
485 #if defined(ENABLE_PEPPER_CDMS)
486   std::string type;
487   EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
488                      "com.example is not a known concrete system");
489   EXPECT_TRUE(type.empty());
490 #endif
491 }
492 
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1)493 TEST_F(
494     KeySystemsTest,
495     IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
496   // Valid video types.
497   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
498       kVideoWebM, no_codecs(), kExternal));
499   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
500       kVideoWebM, vp8_codec(), kExternal));
501   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
502       kVideoWebM, vp80_codec(), kExternal));
503   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
504       kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
505   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
506       kVideoWebM, vp9_codec(), kExternal));
507   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
508       kVideoWebM, vp90_codec(), kExternal));
509   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
510       kVideoWebM, vp9_and_vorbis_codecs(), kExternal));
511   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
512       kVideoWebM, vorbis_codec(), kExternal));
513 
514   // Valid video types - parent key system.
515   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
516       kVideoWebM, no_codecs(), kExternalParent));
517   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
518       kVideoWebM, vp8_codec(), kExternalParent));
519   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
520       kVideoWebM, vp80_codec(), kExternalParent));
521   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
522       kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
523   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
524       kVideoWebM, vp9_codec(), kExternalParent));
525   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
526       kVideoWebM, vp90_codec(), kExternalParent));
527   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
528       kVideoWebM, vp9_and_vorbis_codecs(), kExternalParent));
529   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
530       kVideoWebM, vorbis_codec(), kExternalParent));
531 
532   // Non-Webm codecs.
533   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
534       kVideoWebM, foovideo_codec(), kExternal));
535   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
536       kVideoWebM, unknown_codec(), kExternal));
537   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
538       kVideoWebM, mixed_codecs(), kExternal));
539 
540   // Valid audio types.
541   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
542       kAudioWebM, no_codecs(), kExternal));
543   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
544       kAudioWebM, vorbis_codec(), kExternal));
545 
546   // Valid audio types - parent key system.
547   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
548       kAudioWebM, no_codecs(), kExternalParent));
549   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
550       kAudioWebM, vorbis_codec(), kExternalParent));
551 
552   // Non-audio codecs.
553   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
554       kAudioWebM, vp8_codec(), kExternal));
555   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
556       kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
557   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
558       kAudioWebM, vp9_codec(), kExternal));
559   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
560       kAudioWebM, vp9_and_vorbis_codecs(), kExternal));
561 
562   // Non-Webm codec.
563   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
564       kAudioWebM, fooaudio_codec(), kExternal));
565 }
566 
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2)567 TEST_F(
568     KeySystemsTest,
569     IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
570   // Valid video types.
571   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
572       kVideoFoo, no_codecs(), kExternal));
573   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
574       kVideoFoo, foovideo_codec(), kExternal));
575   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
576       kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
577   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
578       kVideoFoo, fooaudio_codec(), kExternal));
579 
580   // Valid video types - parent key system.
581   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
582       kVideoFoo, no_codecs(), kExternalParent));
583   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
584       kVideoFoo, foovideo_codec(), kExternalParent));
585   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
586       kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
587   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
588       kVideoFoo, fooaudio_codec(), kExternalParent));
589 
590   // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
591   // They should really pass canPlayType().
592   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
593       kVideoFoo, foovideo_extended_codec(), kExternal));
594 
595   // Invalid codec format.
596   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
597       kVideoFoo, foovideo_dot_codec(), kExternal));
598 
599   // Non-container2 codecs.
600   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
601       kVideoFoo, vp8_codec(), kExternal));
602   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
603       kVideoFoo, unknown_codec(), kExternal));
604   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
605       kVideoFoo, mixed_codecs(), kExternal));
606 
607   // Valid audio types.
608   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
609       kAudioFoo, no_codecs(), kExternal));
610   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
611       kAudioFoo, fooaudio_codec(), kExternal));
612 
613   // Valid audio types - parent key system.
614   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
615       kAudioFoo, no_codecs(), kExternalParent));
616   EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
617       kAudioFoo, fooaudio_codec(), kExternalParent));
618 
619   // Non-audio codecs.
620   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
621       kAudioFoo, foovideo_codec(), kExternal));
622   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
623       kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
624 
625   // Non-container2 codec.
626   EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
627       kAudioFoo, vorbis_codec(), kExternal));
628 }
629 
TEST_F(KeySystemsTest,KeySystemNameForUMA)630 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
631   EXPECT_EQ("ClearKey", KeySystemNameForUMA(kClearKey));
632   // Prefixed is not supported internally.
633   EXPECT_EQ("Unknown", KeySystemNameForUMA(kPrefixedClearKey));
634 
635   // External Clear Key never has a UMA name.
636   EXPECT_EQ("Unknown", KeySystemNameForUMA(kExternalClearKey));
637 
638 #if defined(WIDEVINE_CDM_AVAILABLE)
639   const char* const kTestWidevineUmaName = "Widevine";
640 #else
641   const char* const kTestWidevineUmaName = "Unknown";
642 #endif
643   EXPECT_EQ(kTestWidevineUmaName, KeySystemNameForUMA("com.widevine.alpha"));
644 }
645 
646 }  // namespace content
647