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 using blink::WebString;
37
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";
45
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";
49
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";
54
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";
59
60 namespace content {
61
62 // Helper functions that handle the WebString conversion to simplify tests.
KeySystemNameForUMAUTF8(const std::string & key_system)63 static std::string KeySystemNameForUMAUTF8(const std::string& key_system) {
64 return KeySystemNameForUMA(WebString::fromUTF8(key_system));
65 }
66
IsConcreteSupportedKeySystemUTF8(const std::string & key_system)67 static bool IsConcreteSupportedKeySystemUTF8(const std::string& key_system) {
68 return IsConcreteSupportedKeySystem(WebString::fromUTF8(key_system));
69 }
70
71 class TestContentRendererClient : public ContentRendererClient {
72 virtual void AddKeySystems(
73 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
74 };
75
AddKeySystems(std::vector<content::KeySystemInfo> * key_systems)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 };
82 #endif
83
84 KeySystemInfo aes(kUsesAes);
85
86 aes.supported_types.push_back(std::make_pair(kAudioWebM, kWebMAudioCodecs));
87 aes.supported_types.push_back(std::make_pair(kVideoWebM, kWebMVideoCodecs));
88
89 aes.supported_types.push_back(std::make_pair(kAudioFoo, kFooAudioCodecs));
90 aes.supported_types.push_back(std::make_pair(kVideoFoo, kFooVideoCodecs));
91
92 aes.use_aes_decryptor = true;
93
94 key_systems->push_back(aes);
95
96 KeySystemInfo ext(kExternal);
97
98 ext.supported_types.push_back(std::make_pair(kAudioWebM, kWebMAudioCodecs));
99 ext.supported_types.push_back(std::make_pair(kVideoWebM, kWebMVideoCodecs));
100
101 ext.supported_types.push_back(std::make_pair(kAudioFoo, kFooAudioCodecs));
102 ext.supported_types.push_back(std::make_pair(kVideoFoo, kFooVideoCodecs));
103
104 ext.parent_key_system = kExternalParent;
105
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)
111
112 key_systems->push_back(ext);
113 }
114
115 class KeySystemsTest : public testing::Test {
116 protected:
KeySystemsTest()117 KeySystemsTest() {
118 vp8_codec_.push_back("vp8");
119
120 vp80_codec_.push_back("vp8.0");
121
122 vorbis_codec_.push_back("vorbis");
123
124 vp8_and_vorbis_codecs_.push_back("vp8");
125 vp8_and_vorbis_codecs_.push_back("vorbis");
126
127 foovideo_codec_.push_back("foovideo");
128
129 foovideo_extended_codec_.push_back("foovideo.4D400C");
130
131 foovideo_dot_codec_.push_back("foovideo.");
132
133 fooaudio_codec_.push_back("fooaudio");
134
135 foovideo_and_fooaudio_codecs_.push_back("foovideo");
136 foovideo_and_fooaudio_codecs_.push_back("fooaudio");
137
138 unknown_codec_.push_back("unknown");
139
140 mixed_codecs_.push_back("vorbis");
141 mixed_codecs_.push_back("foovideo");
142
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_);
152 }
153
~KeySystemsTest()154 virtual ~KeySystemsTest() {
155 // Clear the use of content_client_, which was set in SetUp().
156 SetContentClient(NULL);
157 }
158
159 typedef std::vector<std::string> CodecVector;
160
no_codecs() const161 const CodecVector& no_codecs() const { return no_codecs_; }
162
vp8_codec() const163 const CodecVector& vp8_codec() const { return vp8_codec_; }
vp80_codec() const164 const CodecVector& vp80_codec() const { return vp80_codec_; }
vorbis_codec() const165 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
vp8_and_vorbis_codecs() const166 const CodecVector& vp8_and_vorbis_codecs() const {
167 return vp8_and_vorbis_codecs_;
168 }
169
foovideo_codec() const170 const CodecVector& foovideo_codec() const { return foovideo_codec_; }
foovideo_extended_codec() const171 const CodecVector& foovideo_extended_codec() const {
172 return foovideo_extended_codec_;
173 }
foovideo_dot_codec() const174 const CodecVector& foovideo_dot_codec() const { return foovideo_dot_codec_; }
fooaudio_codec() const175 const CodecVector& fooaudio_codec() const { return fooaudio_codec_; }
foovideo_and_fooaudio_codecs() const176 const CodecVector& foovideo_and_fooaudio_codecs() const {
177 return foovideo_and_fooaudio_codecs_;
178 }
179
unknown_codec() const180 const CodecVector& unknown_codec() const { return unknown_codec_; }
181
mixed_codecs() const182 const CodecVector& mixed_codecs() const { return mixed_codecs_; }
183
184 private:
185 const CodecVector no_codecs_;
186
187 CodecVector vp8_codec_;
188 CodecVector vp80_codec_;
189 CodecVector vorbis_codec_;
190 CodecVector vp8_and_vorbis_codecs_;
191
192 CodecVector foovideo_codec_;
193 CodecVector foovideo_extended_codec_;
194 CodecVector foovideo_dot_codec_;
195 CodecVector fooaudio_codec_;
196 CodecVector foovideo_and_fooaudio_codecs_;
197
198 CodecVector unknown_codec_;
199
200 CodecVector mixed_codecs_;
201
202 TestContentClient test_content_client_;
203 TestContentRendererClient content_renderer_client_;
204 };
205
206 // TODO(ddorwin): Consider moving GetUUID() into these tests or moving
207 // GetPepperType() calls out to their own test.
208
209 // Clear Key is the only key system registered in content.
TEST_F(KeySystemsTest,ClearKey)210 TEST_F(KeySystemsTest, ClearKey) {
211 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kPrefixedClearKey));
212 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
213 kVideoWebM, no_codecs(), kPrefixedClearKey));
214
215 EXPECT_EQ("ClearKey", KeySystemNameForUMAUTF8(kPrefixedClearKey));
216
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));
222 }
223
224 // The key system is not registered and therefore is unrecognized.
TEST_F(KeySystemsTest,Basic_UnrecognizedKeySystem)225 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
226 static const char* const kUnrecognized = "org.example.unrecognized";
227
228 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kUnrecognized));
229 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
230 kVideoWebM, no_codecs(), kUnrecognized));
231
232 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnrecognized));
233
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);
239
240 #if defined(ENABLE_PEPPER_CDMS)
241 std::string type;
242 EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized),
243 "org.example.unrecognized is not a known concrete system");
244 EXPECT_TRUE(type.empty());
245 #endif
246 }
247
TEST_F(KeySystemsTest,Basic_UsesAesDecryptor)248 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
249 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kUsesAes));
250 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
251 kVideoWebM, no_codecs(), kUsesAes));
252
253 // No UMA value for this test key system.
254 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUsesAes));
255
256 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
257 #if defined(ENABLE_PEPPER_CDMS)
258 std::string type;
259 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
260 "org.example.clear is not Pepper-based");
261 EXPECT_TRUE(type.empty());
262 #endif
263 }
264
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer1)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));
276
277 // Non-Webm codecs.
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));
284
285 // Valid audio types.
286 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
287 kAudioWebM, no_codecs(), kUsesAes));
288 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
289 kAudioWebM, vorbis_codec(), kUsesAes));
290
291 // Non-audio codecs.
292 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
293 kAudioWebM, vp8_codec(), kUsesAes));
294 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
295 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
296
297 // Non-Webm codec.
298 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
299 kAudioWebM, fooaudio_codec(), kUsesAes));
300 }
301
302 // No parent is registered for UsesAes.
TEST_F(KeySystemsTest,Parent_NoParentRegistered)303 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
304 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kUsesAesParent));
305 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
306 kVideoWebM, no_codecs(), kUsesAesParent));
307
308 // The parent is not supported for most things.
309 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUsesAesParent));
310 bool result = false;
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)
315 std::string type;
316 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
317 "org.example is not a known concrete system");
318 EXPECT_TRUE(type.empty());
319 #endif
320 }
321
TEST_F(KeySystemsTest,IsSupportedKeySystem_InvalidVariants)322 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
323 // Case sensitive.
324 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8("org.example.ClEaR"));
325 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
326 kVideoWebM, no_codecs(), "org.example.ClEaR"));
327
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"));
335
336 // Extra period.
337 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example."));
338 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
339 kVideoWebM, no_codecs(), "org.example."));
340
341 // Incomplete.
342 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clea"));
343 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
344 kVideoWebM, no_codecs(), "org.example.clea"));
345
346 // Extra character.
347 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.clearz"));
348 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
349 kVideoWebM, no_codecs(), "org.example.clearz"));
350
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"));
355 }
356
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_NoType)357 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_NoType) {
358 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
359 std::string(), no_codecs(), kUsesAes));
360 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
361 std::string(), no_codecs(), kUsesAesParent));
362
363 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
364 std::string(), no_codecs(), "org.example.foo"));
365 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
366 std::string(), no_codecs(), "org.example.clear.foo"));
367 }
368
369 // Tests the second registered container type.
370 // TODO(ddorwin): Combined with TypesContainer1 in a future CL.
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2)371 TEST_F(KeySystemsTest,
372 IsSupportedKeySystemWithMediaMimeType_UsesAesDecryptor_TypesContainer2) {
373 // Valid video types.
374 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
375 kVideoFoo, no_codecs(), kUsesAes));
376 // The parent should be supported but is not. See http://crbug.com/164303.
377 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
378 kVideoFoo, no_codecs(), kUsesAesParent));
379 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
380 kVideoFoo, foovideo_codec(), kUsesAes));
381 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
382 kVideoFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
383 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
384 kVideoFoo, fooaudio_codec(), kUsesAes));
385
386 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
387 // They should really pass canPlayType().
388 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
389 kVideoFoo, foovideo_extended_codec(), kUsesAes));
390
391 // Invalid codec format.
392 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
393 kVideoFoo, foovideo_dot_codec(), kUsesAes));
394
395 // Non-container2 codec.
396 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
397 kVideoFoo, vp8_codec(), kUsesAes));
398 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
399 kVideoFoo, unknown_codec(), kUsesAes));
400 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
401 kVideoFoo, mixed_codecs(), kUsesAes));
402
403 // Valid audio types.
404 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
405 kAudioFoo, no_codecs(), kUsesAes));
406 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
407 kAudioFoo, fooaudio_codec(), kUsesAes));
408
409 // Non-audio codecs.
410 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
411 kAudioFoo, foovideo_codec(), kUsesAes));
412 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
413 kAudioFoo, foovideo_and_fooaudio_codecs(), kUsesAes));
414
415 // Non-container2 codec.
416 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
417 kAudioFoo, vorbis_codec(), kUsesAes));
418 }
419
420 //
421 // Non-AesDecryptor-based key system.
422 //
423
TEST_F(KeySystemsTest,Basic_ExternalDecryptor)424 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
425 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kExternal));
426 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
427 kVideoWebM, no_codecs(), kExternal));
428
429 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
430 #if defined(ENABLE_PEPPER_CDMS)
431 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
432 #endif // defined(ENABLE_PEPPER_CDMS)
433
434 }
435
TEST_F(KeySystemsTest,Parent_ParentRegistered)436 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
437 // The parent system is not a concrete system but is supported.
438 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kExternalParent));
439 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
440 kVideoWebM, no_codecs(), kExternalParent));
441
442 // The parent is not supported for most things.
443 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kExternalParent));
444 bool result = false;
445 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
446 "com.example is not a known concrete system");
447 EXPECT_FALSE(result);
448 #if defined(ENABLE_PEPPER_CDMS)
449 std::string type;
450 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
451 "com.example is not a known concrete system");
452 EXPECT_TRUE(type.empty());
453 #endif
454 }
455
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1)456 TEST_F(
457 KeySystemsTest,
458 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer1) {
459 // Valid video types.
460 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
461 kVideoWebM, no_codecs(), kExternal));
462 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
463 kVideoWebM, vp8_codec(), kExternal));
464 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
465 kVideoWebM, vp80_codec(), kExternal));
466 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
467 kVideoWebM, vp8_and_vorbis_codecs(), kExternal));
468 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
469 kVideoWebM, vorbis_codec(), kExternal));
470
471 // Valid video types - parent key system.
472 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
473 kVideoWebM, no_codecs(), kExternalParent));
474 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
475 kVideoWebM, vp8_codec(), kExternalParent));
476 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
477 kVideoWebM, vp80_codec(), kExternalParent));
478 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
479 kVideoWebM, vp8_and_vorbis_codecs(), kExternalParent));
480 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
481 kVideoWebM, vorbis_codec(), kExternalParent));
482
483 // Non-Webm codecs.
484 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
485 kVideoWebM, foovideo_codec(), kExternal));
486 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
487 kVideoWebM, unknown_codec(), kExternal));
488 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
489 kVideoWebM, mixed_codecs(), kExternal));
490
491 // Valid audio types.
492 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
493 kAudioWebM, no_codecs(), kExternal));
494 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
495 kAudioWebM, vorbis_codec(), kExternal));
496
497 // Valid audio types - parent key system.
498 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
499 kAudioWebM, no_codecs(), kExternalParent));
500 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
501 kAudioWebM, vorbis_codec(), kExternalParent));
502
503 // Non-audio codecs.
504 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
505 kAudioWebM, vp8_codec(), kExternal));
506 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
507 kAudioWebM, vp8_and_vorbis_codecs(), kExternal));
508
509 // Non-Webm codec.
510 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
511 kAudioWebM, fooaudio_codec(), kExternal));
512 }
513
TEST_F(KeySystemsTest,IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2)514 TEST_F(
515 KeySystemsTest,
516 IsSupportedKeySystemWithMediaMimeType_ExternalDecryptor_TypesContainer2) {
517 // Valid video types.
518 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
519 kVideoFoo, no_codecs(), kExternal));
520 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
521 kVideoFoo, foovideo_codec(), kExternal));
522 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
523 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternal));
524 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
525 kVideoFoo, fooaudio_codec(), kExternal));
526
527 // Valid video types - parent key system.
528 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
529 kVideoFoo, no_codecs(), kExternalParent));
530 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
531 kVideoFoo, foovideo_codec(), kExternalParent));
532 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
533 kVideoFoo, foovideo_and_fooaudio_codecs(), kExternalParent));
534 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
535 kVideoFoo, fooaudio_codec(), kExternalParent));
536
537 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
538 // They should really pass canPlayType().
539 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
540 kVideoFoo, foovideo_extended_codec(), kExternal));
541
542 // Invalid codec format.
543 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
544 kVideoFoo, foovideo_dot_codec(), kExternal));
545
546 // Non-container2 codecs.
547 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
548 kVideoFoo, vp8_codec(), kExternal));
549 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
550 kVideoFoo, unknown_codec(), kExternal));
551 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
552 kVideoFoo, mixed_codecs(), kExternal));
553
554 // Valid audio types.
555 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
556 kAudioFoo, no_codecs(), kExternal));
557 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
558 kAudioFoo, fooaudio_codec(), kExternal));
559
560 // Valid audio types - parent key system.
561 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
562 kAudioFoo, no_codecs(), kExternalParent));
563 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
564 kAudioFoo, fooaudio_codec(), kExternalParent));
565
566 // Non-audio codecs.
567 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
568 kAudioFoo, foovideo_codec(), kExternal));
569 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
570 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
571
572 // Non-container2 codec.
573 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
574 kAudioFoo, vorbis_codec(), kExternal));
575 }
576
577 #if defined(OS_ANDROID)
TEST_F(KeySystemsTest,GetUUID_RegisteredExternalDecryptor)578 TEST_F(KeySystemsTest, GetUUID_RegisteredExternalDecryptor) {
579 std::vector<uint8> uuid = GetUUID(kExternal);
580 EXPECT_EQ(16u, uuid.size());
581 EXPECT_EQ(0xef, uuid[15]);
582 }
583
TEST_F(KeySystemsTest,GetUUID_RegisteredAesDecryptor)584 TEST_F(KeySystemsTest, GetUUID_RegisteredAesDecryptor) {
585 EXPECT_TRUE(GetUUID(kUsesAes).empty());
586 }
587
TEST_F(KeySystemsTest,GetUUID_Unrecognized)588 TEST_F(KeySystemsTest, GetUUID_Unrecognized) {
589 std::vector<uint8> uuid;
590 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(kExternalParent),
591 "com.example is not a known concrete system");
592 EXPECT_TRUE(uuid.empty());
593
594 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(""), " is not a concrete system");
595 EXPECT_TRUE(uuid.empty());
596 }
597 #endif // defined(OS_ANDROID)
598
TEST_F(KeySystemsTest,KeySystemNameForUMA)599 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
600 EXPECT_EQ("ClearKey", KeySystemNameForUMAUTF8(kPrefixedClearKey));
601 // Unprefixed is not yet supported.
602 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnprefixedClearKey));
603
604 // External Clear Key never has a UMA name.
605 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kExternalClearKey));
606
607 #if defined(WIDEVINE_CDM_AVAILABLE)
608 const char* const kTestWidevineUmaName = "Widevine";
609 #else
610 const char* const kTestWidevineUmaName = "Unknown";
611 #endif
612 EXPECT_EQ(kTestWidevineUmaName,
613 KeySystemNameForUMAUTF8("com.widevine.alpha"));
614 }
615
616 } // namespace content
617