1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
8 #include "testing/gtest/include/gtest/gtest.h"
9 #include "third_party/WebKit/Source/Platform/chromium/public/WebString.h"
10 #include "webkit/media/crypto/key_systems.h"
12 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
14 #if defined(WIDEVINE_CDM_AVAILABLE) && \
15 defined(OS_LINUX) && !defined(OS_CHROMEOS)
16 #include <gnu/libc-version.h>
19 using WebKit::WebString
;
21 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
22 #define EXPECT_PROPRIETARY EXPECT_TRUE
24 #define EXPECT_PROPRIETARY EXPECT_FALSE
27 #if defined(WIDEVINE_CDM_AVAILABLE)
28 #if defined(OS_LINUX) && !defined(OS_CHROMEOS)
29 // TODO(ddorwin): Remove after bots switch to Precise.
30 #define EXPECT_WV(a) \
31 EXPECT_EQ((std::string(gnu_get_libc_version()) != "2.11.1"), (a))
33 #define EXPECT_WV EXPECT_TRUE
34 #endif // defined(OS_LINUX) && !defined(OS_CHROMEOS)
36 #if defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
37 #define EXPECT_WVCENC EXPECT_TRUE
39 #if defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
40 #define EXPECT_WVAVC1 EXPECT_TRUE
41 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
42 #define EXPECT_WVAVC1AAC EXPECT_TRUE
44 #define EXPECT_WVAVC1AAC EXPECT_FALSE
45 #endif // defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
46 #else // !defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
47 #define EXPECT_WVAVC1 EXPECT_FALSE
48 #define EXPECT_WVAVC1AAC EXPECT_FALSE
49 #endif // defined(WIDEVINE_CDM_AVC1_SUPPORT_AVAILABLE)
51 #if defined(WIDEVINE_CDM_AAC_SUPPORT_AVAILABLE)
52 #define EXPECT_WVAAC EXPECT_TRUE
54 #define EXPECT_WVAAC EXPECT_FALSE
57 #else // !defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
58 #define EXPECT_WVCENC EXPECT_FALSE
59 #define EXPECT_WVAVC1 EXPECT_FALSE
60 #define EXPECT_WVAVC1AAC EXPECT_FALSE
61 #define EXPECT_WVAAC EXPECT_FALSE
62 #endif // defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
64 #else // !defined(WIDEVINE_CDM_AVAILABLE)
65 #define EXPECT_WV EXPECT_FALSE
66 #define EXPECT_WVCENC EXPECT_FALSE
67 #define EXPECT_WVAVC1 EXPECT_FALSE
68 #define EXPECT_WVAVC1AAC EXPECT_FALSE
69 #define EXPECT_WVAAC EXPECT_FALSE
70 #endif // defined(WIDEVINE_CDM_AVAILABLE)
72 namespace webkit_media
{
74 static const char* const kClearKey
= "webkit-org.w3.clearkey";
75 static const char* const kExternalClearKey
= "org.chromium.externalclearkey";
76 static const char* const kWidevine
= "com.widevine";
77 static const char* const kWidevineAlpha
= "com.widevine.alpha";
79 class KeySystemsTest
: public testing::Test
{
82 vp8_codec_
.push_back("vp8");
84 vp80_codec_
.push_back("vp8.0");
86 vorbis_codec_
.push_back("vorbis");
88 vp8_and_vorbis_codecs_
.push_back("vp8");
89 vp8_and_vorbis_codecs_
.push_back("vorbis");
91 avc1_codec_
.push_back("avc1");
93 avc1_extended_codec_
.push_back("avc1.4D400C");
95 avc1_dot_codec_
.push_back("avc1.");
97 avc2_codec_
.push_back("avc2");
99 aac_codec_
.push_back("mp4a");
101 avc1_and_aac_codecs_
.push_back("avc1");
102 avc1_and_aac_codecs_
.push_back("mp4a");
104 unknown_codec_
.push_back("foo");
106 mixed_codecs_
.push_back("vorbis");
107 mixed_codecs_
.push_back("avc1");
110 typedef std::vector
<std::string
> CodecVector
;
112 const CodecVector
& no_codecs() const { return no_codecs_
; }
114 const CodecVector
& vp8_codec() const { return vp8_codec_
; }
115 const CodecVector
& vp80_codec() const { return vp80_codec_
; }
116 const CodecVector
& vorbis_codec() const { return vorbis_codec_
; }
117 const CodecVector
& vp8_and_vorbis_codecs() const {
118 return vp8_and_vorbis_codecs_
;
121 const CodecVector
& avc1_codec() const { return avc1_codec_
; }
122 const CodecVector
& avc1_extended_codec() const {
123 return avc1_extended_codec_
;
125 const CodecVector
& avc1_dot_codec() const { return avc1_dot_codec_
; }
126 const CodecVector
& avc2_codec() const { return avc2_codec_
; }
127 const CodecVector
& aac_codec() const { return aac_codec_
; }
128 const CodecVector
& avc1_and_aac_codecs() const {
129 return avc1_and_aac_codecs_
;
132 const CodecVector
& unknown_codec() const { return unknown_codec_
; }
134 const CodecVector
& mixed_codecs() const { return mixed_codecs_
; }
137 const CodecVector no_codecs_
;
139 CodecVector vp8_codec_
;
140 CodecVector vp80_codec_
;
141 CodecVector vorbis_codec_
;
142 CodecVector vp8_and_vorbis_codecs_
;
144 CodecVector avc1_codec_
;
145 CodecVector avc1_extended_codec_
;
146 CodecVector avc1_dot_codec_
;
147 CodecVector avc2_codec_
;
148 CodecVector aac_codec_
;
149 CodecVector avc1_and_aac_codecs_
;
151 CodecVector unknown_codec_
;
153 CodecVector mixed_codecs_
;
157 TEST_F(KeySystemsTest
, ClearKey_Basic
) {
158 EXPECT_TRUE(IsSupportedKeySystem(WebString::fromUTF8(kClearKey
)));
159 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
160 "video/webm", no_codecs(), kClearKey
));
162 // Not yet out from behind the vendor prefix.
163 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkey"));
164 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
165 "video/webm", no_codecs(), "org.w3.clearkey"));
167 EXPECT_STREQ("ClearKey", KeySystemNameForUMA(std::string(kClearKey
)).c_str());
168 EXPECT_STREQ("ClearKey",
169 KeySystemNameForUMA(WebString::fromUTF8(kClearKey
)).c_str());
171 EXPECT_TRUE(CanUseAesDecryptor(kClearKey
));
172 EXPECT_TRUE(GetPluginType(kClearKey
).empty()); // Does not use plugin.
175 TEST_F(KeySystemsTest
, ClearKey_Parent
) {
176 const char* const kClearKeyParent
= "webkit-org.w3";
178 // The parent should be supported but is not. See http://crbug.com/164303.
179 EXPECT_FALSE(IsSupportedKeySystem(WebString::fromUTF8(kClearKeyParent
)));
180 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
181 "video/webm", no_codecs(), kClearKeyParent
));
183 // The parent is not supported for most things.
184 EXPECT_STREQ("Unknown",
185 KeySystemNameForUMA(std::string(kClearKeyParent
)).c_str());
186 EXPECT_STREQ("Unknown",
187 KeySystemNameForUMA(WebString::fromUTF8(kClearKeyParent
)).c_str());
188 EXPECT_FALSE(CanUseAesDecryptor(kClearKeyParent
));
189 EXPECT_TRUE(GetPluginType(kClearKeyParent
).empty());
192 TEST_F(KeySystemsTest
, ClearKey_IsSupportedKeySystem_InvalidVariants
) {
194 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.ClEaRkEy"));
195 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
196 "video/webm", no_codecs(), "webkit-org.w3.ClEaRkEy"));
198 // TLDs are not allowed.
199 EXPECT_FALSE(IsSupportedKeySystem("webkit-org."));
200 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
201 "video/webm", no_codecs(), "webkit-org."));
202 EXPECT_FALSE(IsSupportedKeySystem("webkit-org"));
203 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
204 "video/webm", no_codecs(), "webkit-org"));
205 EXPECT_FALSE(IsSupportedKeySystem("org."));
206 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
207 "video/webm", no_codecs(), "org."));
208 EXPECT_FALSE(IsSupportedKeySystem("org"));
209 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
210 "video/webm", no_codecs(), "org"));
213 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3."));
214 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
215 "video/webm", no_codecs(), "webkit-org.w3."));
218 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearke"));
219 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
220 "video/webm", no_codecs(), "webkit-org.w3.clearke"));
223 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearkeyz"));
224 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
225 "video/webm", no_codecs(), "webkit-org.w3.clearkeyz"));
227 // There are no child key systems for Clear Key.
228 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearkey.foo"));
229 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
230 "video/webm", no_codecs(), "webkit-org.w3.clearkey.foo"));
233 TEST_F(KeySystemsTest
, IsSupportedKeySystemWithMediaMimeType_ClearKey_NoType
) {
234 // These two should be true. See http://crbug.com/164303.
235 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
236 std::string(), no_codecs(), kClearKey
));
237 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
238 std::string(), no_codecs(), "webkit-org.w3"));
240 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
241 std::string(), no_codecs(), "webkit-org.w3.foo"));
242 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
243 std::string(), no_codecs(), "webkit-org.w3.clearkey.foo"));
246 TEST_F(KeySystemsTest
, IsSupportedKeySystemWithMediaMimeType_ClearKey_WebM
) {
247 // Valid video types.
248 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
249 "video/webm", no_codecs(), kClearKey
));
250 // The parent should be supported but is not. See http://crbug.com/164303.
251 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
252 "video/webm", no_codecs(), "webkit-org.w3"));
253 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
254 "video/webm", vp8_codec(), kClearKey
));
255 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
256 "video/webm", vp80_codec(), kClearKey
));
257 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
258 "video/webm", vp8_and_vorbis_codecs(), kClearKey
));
259 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
260 "video/webm", vorbis_codec(), kClearKey
));
263 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
264 "video/webm", avc1_codec(), kClearKey
));
265 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
266 "video/webm", unknown_codec(), kClearKey
));
267 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
268 "video/webm", mixed_codecs(), kClearKey
));
270 // Valid audio types.
271 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
272 "audio/webm", no_codecs(), kClearKey
));
273 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
274 "audio/webm", vorbis_codec(), kClearKey
));
277 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
278 "audio/webm", vp8_codec(), kClearKey
));
279 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
280 "audio/webm", vp8_and_vorbis_codecs(), kClearKey
));
283 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
284 "audio/webm", aac_codec(), kClearKey
));
287 TEST_F(KeySystemsTest
, IsSupportedKeySystemWithMediaMimeType_ClearKey_MP4
) {
288 // Valid video types.
289 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
290 "video/mp4", no_codecs(), kClearKey
));
291 // The parent should be supported but is not. See http://crbug.com/164303.
292 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
293 "video/mp4", no_codecs(), "webkit-org.w3"));
294 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
295 "video/mp4", avc1_codec(), kClearKey
));
296 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
297 "video/mp4", avc1_and_aac_codecs(), kClearKey
));
298 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
299 "video/mp4", aac_codec(), kClearKey
));
301 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
302 // They should really pass canPlayType().
303 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
304 "video/mp4", avc1_extended_codec(), kClearKey
));
306 // Invalid codec format.
307 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
308 "video/mp4", avc1_dot_codec(), kClearKey
));
311 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
312 "video/mp4", avc2_codec(), kClearKey
));
313 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
314 "video/mp4", vp8_codec(), kClearKey
));
315 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
316 "video/mp4", unknown_codec(), kClearKey
));
317 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
318 "video/mp4", mixed_codecs(), kClearKey
));
320 // Valid audio types.
321 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
322 "audio/mp4", no_codecs(), kClearKey
));
323 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
324 "audio/mp4", aac_codec(), kClearKey
));
327 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
328 "audio/mp4", avc1_codec(), kClearKey
));
329 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
330 "audio/mp4", avc1_and_aac_codecs(), kClearKey
));
333 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
334 "audio/mp4", vorbis_codec(), kClearKey
));
338 // External Clear Key
341 TEST_F(KeySystemsTest
, ExternalClearKey_Basic
) {
342 EXPECT_TRUE(IsSupportedKeySystem(WebString::fromUTF8(kExternalClearKey
)));
343 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
344 "video/webm", no_codecs(), kExternalClearKey
));
346 // External Clear Key does not have a UMA name because it is for testing.
349 KeySystemNameForUMA(std::string(kExternalClearKey
)).c_str());
352 KeySystemNameForUMA(WebString::fromUTF8(kExternalClearKey
)).c_str());
354 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKey
));
355 EXPECT_STREQ("application/x-ppapi-clearkey-cdm",
356 GetPluginType(kExternalClearKey
).c_str());
359 TEST_F(KeySystemsTest
, ExternalClearKey_Parent
) {
360 const char* const kExternalClearKeyParent
= "org.chromium";
362 // The parent should be supported but is not. See http://crbug.com/164303.
364 IsSupportedKeySystem(WebString::fromUTF8(kExternalClearKeyParent
)));
365 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
366 "video/webm", no_codecs(), kExternalClearKeyParent
));
368 // The parent is not supported for most things.
371 KeySystemNameForUMA(std::string(kExternalClearKeyParent
)).c_str());
372 EXPECT_STREQ("Unknown",
374 WebString::fromUTF8(kExternalClearKeyParent
)).c_str());
375 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKeyParent
));
376 EXPECT_TRUE(GetPluginType(kExternalClearKeyParent
).empty());
379 TEST_F(KeySystemsTest
, ExternalClearKey_IsSupportedKeySystem_InvalidVariants
) {
381 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy"));
382 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
383 "video/webm", no_codecs(),
384 "org.chromium.ExTeRnAlClEaRkEy"));
386 // TLDs are not allowed.
387 EXPECT_FALSE(IsSupportedKeySystem("org."));
388 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
389 "video/webm", no_codecs(), "org."));
390 EXPECT_FALSE(IsSupportedKeySystem("org"));
391 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
392 "video/webm", no_codecs(), "org"));
395 EXPECT_FALSE(IsSupportedKeySystem("org.chromium."));
396 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
397 "video/webm", no_codecs(), "org.chromium."));
400 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke"));
401 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
402 "video/webm", no_codecs(),
403 "org.chromium.externalclearke"));
406 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeyz"));
407 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
408 "video/webm", no_codecs(),
409 "org.chromium.externalclearkeyz"));
411 // There are no child key systems for Clear Key.
412 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.foo"));
413 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
414 "video/webm", no_codecs(),
415 "org.chromium.externalclearkey.foo"));
418 TEST_F(KeySystemsTest
,
419 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_NoType
) {
420 // These two should be true. See http://crbug.com/164303.
421 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
422 std::string(), no_codecs(), kExternalClearKey
));
423 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
424 std::string(), no_codecs(), "org.chromium"));
426 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
427 std::string(), no_codecs(), "org.chromium.foo"));
428 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
429 std::string(), no_codecs(), "org.chromium.externalclearkey.foo"));
432 TEST_F(KeySystemsTest
,
433 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_WebM
) {
434 // Valid video types.
435 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
436 "video/webm", no_codecs(), kExternalClearKey
));
437 // The parent should be supported but is not. See http://crbug.com/164303.
438 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
439 "video/webm", no_codecs(), "org.chromium"));
440 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
441 "video/webm", vp8_codec(), kExternalClearKey
));
442 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
443 "video/webm", vp80_codec(), kExternalClearKey
));
444 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
445 "video/webm", vp8_and_vorbis_codecs(), kExternalClearKey
));
446 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
447 "video/webm", vorbis_codec(), kExternalClearKey
));
450 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
451 "video/webm", avc1_codec(), kExternalClearKey
));
452 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
453 "video/webm", unknown_codec(), kExternalClearKey
));
454 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
455 "video/webm", mixed_codecs(), kExternalClearKey
));
457 // Valid audio types.
458 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
459 "audio/webm", no_codecs(), kExternalClearKey
));
460 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
461 "audio/webm", vorbis_codec(), kExternalClearKey
));
464 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
465 "audio/webm", vp8_codec(), kExternalClearKey
));
466 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
467 "audio/webm", vp8_and_vorbis_codecs(), kExternalClearKey
));
470 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
471 "audio/webm", aac_codec(), kExternalClearKey
));
474 TEST_F(KeySystemsTest
,
475 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_MP4
) {
476 // Valid video types.
477 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
478 "video/mp4", no_codecs(), kExternalClearKey
));
479 // The parent should be supported but is not. See http://crbug.com/164303.
480 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
481 "video/mp4", no_codecs(), "org.chromium"));
482 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
483 "video/mp4", avc1_codec(), kExternalClearKey
));
484 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
485 "video/mp4", avc1_and_aac_codecs(), kExternalClearKey
));
486 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
487 "video/mp4", aac_codec(), kExternalClearKey
));
489 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
490 // They should really pass canPlayType().
491 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
492 "video/mp4", avc1_extended_codec(), kExternalClearKey
));
494 // Invalid codec format.
495 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
496 "video/mp4", avc1_dot_codec(), kExternalClearKey
));
499 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
500 "video/mp4", avc2_codec(), kExternalClearKey
));
501 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
502 "video/mp4", vp8_codec(), kExternalClearKey
));
503 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
504 "video/mp4", unknown_codec(), kExternalClearKey
));
505 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
506 "video/mp4", mixed_codecs(), kExternalClearKey
));
508 // Valid audio types.
509 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
510 "audio/mp4", no_codecs(), kExternalClearKey
));
511 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
512 "audio/mp4", aac_codec(), kExternalClearKey
));
515 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
516 "audio/mp4", avc1_codec(), kExternalClearKey
));
517 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
518 "audio/mp4", avc1_and_aac_codecs(), kExternalClearKey
));
521 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
522 "audio/mp4", vorbis_codec(), kExternalClearKey
));
529 TEST_F(KeySystemsTest
, Widevine_Basic
) {
530 EXPECT_WV(IsSupportedKeySystem(WebString::fromUTF8(kWidevineAlpha
)));
531 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
532 "video/webm", no_codecs(), kWidevineAlpha
));
534 #if defined(WIDEVINE_CDM_AVAILABLE)
535 const char* const kWidevineUmaName
= "Widevine";
537 const char* const kWidevineUmaName
= "Unknown";
541 KeySystemNameForUMA(std::string(kWidevineAlpha
)).c_str());
544 KeySystemNameForUMA(WebString::fromUTF8(kWidevineAlpha
)).c_str());
546 EXPECT_FALSE(CanUseAesDecryptor(kWidevineAlpha
));
547 #if defined(WIDEVINE_CDM_AVAILABLE)
548 EXPECT_STREQ("application/x-ppapi-widevine-cdm",
549 GetPluginType(kWidevineAlpha
).c_str());
551 EXPECT_TRUE(GetPluginType(kWidevineAlpha
).empty());
555 TEST_F(KeySystemsTest
, Widevine_Parent
) {
556 const char* const kWidevineParent
= kWidevine
;
558 EXPECT_WV(IsSupportedKeySystem(WebString::fromUTF8(kWidevineParent
)));
559 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
560 "video/webm", no_codecs(), kWidevineParent
));
562 // The parent is not supported for most things.
563 EXPECT_STREQ("Unknown",
564 KeySystemNameForUMA(std::string(kWidevineParent
)).c_str());
565 EXPECT_STREQ("Unknown",
566 KeySystemNameForUMA(WebString::fromUTF8(kWidevineParent
)).c_str());
567 EXPECT_FALSE(CanUseAesDecryptor(kWidevineParent
));
568 EXPECT_TRUE(GetPluginType(kWidevineParent
).empty());
571 TEST_F(KeySystemsTest
, Widevine_IsSupportedKeySystem_InvalidVariants
) {
573 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.AlPhA"));
574 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
575 "video/webm", no_codecs(), "com.widevine.AlPhA"));
577 // TLDs are not allowed.
578 EXPECT_FALSE(IsSupportedKeySystem("com."));
579 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
580 "video/webm", no_codecs(), "com."));
581 EXPECT_FALSE(IsSupportedKeySystem("com"));
582 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
583 "video/webm", no_codecs(), "com"));
586 EXPECT_FALSE(IsSupportedKeySystem("com.widevine."));
587 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
588 "video/webm", no_codecs(), "com.widevine."));
591 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph"));
592 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
593 "video/webm", no_codecs(), "com.widevine.alph"));
596 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphab"));
597 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
598 "video/webm", no_codecs(), "com.widevine.alphab"));
600 // There are no child key systems for Widevine Alpha.
601 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.foo"));
602 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
603 "video/webm", no_codecs(), "com.widevine.alpha.foo"));
606 TEST_F(KeySystemsTest
, IsSupportedKeySystemWithMediaMimeType_Widevine_NoType
) {
607 // These two should be true. See http://crbug.com/164303.
608 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
609 std::string(), no_codecs(), kWidevineAlpha
));
610 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
611 std::string(), no_codecs(), kWidevine
));
613 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
614 std::string(), no_codecs(), "com.widevine.foo"));
615 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
616 std::string(), no_codecs(), "com.widevine.alpha.foo"));
619 TEST_F(KeySystemsTest
, IsSupportedKeySystemWithMediaMimeType_Widevine_WebM
) {
620 // Valid video types.
621 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
622 "video/webm", no_codecs(), kWidevineAlpha
));
623 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
624 "video/webm", vp8_codec(), kWidevineAlpha
));
625 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
626 "video/webm", vp80_codec(), kWidevineAlpha
));
627 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
628 "video/webm", vp8_and_vorbis_codecs(), kWidevineAlpha
));
629 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
630 "video/webm", vorbis_codec(), kWidevineAlpha
));
632 // Valid video types - parent key system.
633 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
634 "video/webm", no_codecs(), kWidevine
));
635 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
636 "video/webm", vp8_codec(), kWidevine
));
637 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
638 "video/webm", vp80_codec(), kWidevine
));
639 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
640 "video/webm", vp8_and_vorbis_codecs(), kWidevine
));
641 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
642 "video/webm", vorbis_codec(), kWidevine
));
645 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
646 "video/webm", avc1_codec(), kWidevineAlpha
));
647 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
648 "video/webm", unknown_codec(), kWidevineAlpha
));
649 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
650 "video/webm", mixed_codecs(), kWidevineAlpha
));
652 // Valid audio types.
653 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
654 "audio/webm", no_codecs(), kWidevineAlpha
));
655 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
656 "audio/webm", vorbis_codec(), kWidevineAlpha
));
658 // Valid audio types - parent key system.
659 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
660 "audio/webm", no_codecs(), kWidevine
));
661 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
662 "audio/webm", vorbis_codec(), kWidevine
));
665 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
666 "audio/webm", vp8_codec(), kWidevineAlpha
));
667 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
668 "audio/webm", vp8_and_vorbis_codecs(), kWidevineAlpha
));
671 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
672 "audio/webm", aac_codec(), kWidevineAlpha
));
675 TEST_F(KeySystemsTest
, IsSupportedKeySystemWithMediaMimeType_Widevine_MP4
) {
676 // Valid video types.
677 EXPECT_WVCENC(IsSupportedKeySystemWithMediaMimeType(
678 "video/mp4", no_codecs(), kWidevineAlpha
));
679 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
680 "video/mp4", avc1_codec(), kWidevineAlpha
));
681 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
682 "video/mp4", avc1_and_aac_codecs(), kWidevineAlpha
));
683 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
684 "video/mp4", aac_codec(), kWidevineAlpha
));
686 // Valid video types - parent key system.
687 EXPECT_WVCENC(IsSupportedKeySystemWithMediaMimeType(
688 "video/mp4", no_codecs(), kWidevine
));
689 EXPECT_WVAVC1(IsSupportedKeySystemWithMediaMimeType(
690 "video/mp4", avc1_codec(), kWidevine
));
691 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
692 "video/mp4", avc1_and_aac_codecs(), kWidevine
));
693 EXPECT_WVAVC1AAC(IsSupportedKeySystemWithMediaMimeType(
694 "video/mp4", aac_codec(), kWidevine
));
696 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
697 // They should really pass canPlayType().
698 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
699 "video/mp4", avc1_extended_codec(), kWidevineAlpha
));
701 // Invalid codec format.
702 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
703 "video/mp4", avc1_dot_codec(), kWidevineAlpha
));
706 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
707 "video/mp4", avc2_codec(), kWidevineAlpha
));
708 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
709 "video/mp4", vp8_codec(), kWidevineAlpha
));
710 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
711 "video/mp4", unknown_codec(), kWidevineAlpha
));
712 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
713 "video/mp4", mixed_codecs(), kWidevineAlpha
));
715 // Valid audio types.
716 EXPECT_WVCENC(IsSupportedKeySystemWithMediaMimeType(
717 "audio/mp4", no_codecs(), kWidevineAlpha
));
718 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType(
719 "audio/mp4", aac_codec(), kWidevineAlpha
));
721 // Valid audio types - parent key system.
722 EXPECT_WVCENC(IsSupportedKeySystemWithMediaMimeType(
723 "audio/mp4", no_codecs(), kWidevine
));
724 EXPECT_WVAAC(IsSupportedKeySystemWithMediaMimeType(
725 "audio/mp4", aac_codec(), kWidevine
));
728 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
729 "audio/mp4", avc1_codec(), kWidevineAlpha
));
730 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
731 "audio/mp4", avc1_and_aac_codecs(), kWidevineAlpha
));
734 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
735 "audio/mp4", vorbis_codec(), kWidevineAlpha
));
738 } // namespace webkit_media