Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: webkit/media/crypto/key_systems_unittest.cc

Issue 11474037: Several updates to canPlayType() results for EME (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « webkit/media/crypto/key_systems.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "webkit/media/crypto/key_systems.h"
6
xhwang 2012/12/07 22:35:39 include vector and string
ddorwin 2012/12/08 00:29:07 Done.
7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
9
10 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
11
12 using WebKit::WebString;
13
14 #if defined(GOOGLE_CHROME_BUILD) || defined(USE_PROPRIETARY_CODECS)
15 #define EXPECT_PROPRIETARY EXPECT_TRUE
16 #else
17 #define EXPECT_PROPRIETARY EXPECT_FALSE
18 #endif
19
20 #if defined(WIDEVINE_CDM_AVAILABLE)
21 #define EXPECT_WV EXPECT_TRUE
22 #else
23 #define EXPECT_WV EXPECT_FALSE
24 #endif
25
26 #if defined(WIDEVINE_CDM_AVAILABLE) && \
27 defined(WIDEVINE_CDM_CENC_SUPPORT_AVAILABLE)
28 #define EXPECT_WVISO EXPECT_TRUE
29 #else
30 #define EXPECT_WVISO EXPECT_FALSE
31 #endif
32
33 namespace webkit_media {
34
35 class KeySystemsTest : public testing::Test {
36 public:
37 virtual void SetUp() {
38 vp8_codec.push_back("vp8");
39 vp80_codec.push_back("vp8.0");
40
41 vorbis_codec.push_back("vorbis");
42
43 vp8_and_vorbis_codecs.push_back("vp8");
44 vp8_and_vorbis_codecs.push_back("vorbis");
45
46 avc1_codec.push_back("avc1");
47
48 aac_codec.push_back("mp4a");
49
50 avc1_and_aac_codecs.push_back("avc1");
51 avc1_and_aac_codecs.push_back("mp4a");
52
53 unknown_codec.push_back("foo");
54
55 mixed_codecs.push_back("vorbis");
56 mixed_codecs.push_back("avc1");
57 }
58
59 protected:
60 const char* const kClearKey = "webkit-org.w3.clearkey";
61 const char* const kExternalClearKey = "org.chromium.externalclearkey";
62 const char* const kWidevineAlpha = "com.widevine.alpha";
63
64 const std::vector<std::string> no_codecs;
xhwang 2012/12/07 22:35:39 nit: s/no_codecs/no_codecs_ ? same question for al
ddorwin 2012/12/08 00:29:07 Done. Made them private and added accessors to pre
65
66 std::vector<std::string> vp8_codec;
67 std::vector<std::string> vp80_codec;
68 std::vector<std::string> vorbis_codec;
69 std::vector<std::string> vp8_and_vorbis_codecs;
70
71 std::vector<std::string> avc1_codec;
72 std::vector<std::string> aac_codec;
73 std::vector<std::string> avc1_and_aac_codecs;
74
75 std::vector<std::string> unknown_codec;
76
77 std::vector<std::string> mixed_codecs;
78
79 };
80
81 TEST_F(KeySystemsTest, ClearKey_Basic) {
82 EXPECT_TRUE(IsSupportedKeySystem(WebString::fromUTF8(kClearKey)));
83 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
84 "video/webm", std::vector<std::string>(), kClearKey));
85
86 // Not yet out from behind the vendor prefix.
87 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkey"));
88 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
89 "video/webm", std::vector<std::string>(), "org.w3.clearkey"));
90
91 EXPECT_STREQ("ClearKey", KeySystemNameForUMA(std::string(kClearKey)).c_str());
92 EXPECT_STREQ("ClearKey",
93 KeySystemNameForUMA(WebString::fromUTF8(kClearKey)).c_str());
94
95 EXPECT_TRUE(CanUseAesDecryptor(kClearKey));
96 EXPECT_TRUE(GetPluginType(kClearKey).empty()); // Does not use plugin.
97 }
98
99 TEST_F(KeySystemsTest, ClearKey_Parent) {
100 const char* const kClearKeyParent = "webkit-org.w3";
101
102 // The parent should be supported but is not. See http://crbug.com/164303.
103 EXPECT_FALSE(IsSupportedKeySystem(WebString::fromUTF8(kClearKeyParent)));
104 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
105 "video/webm", std::vector<std::string>(), kClearKeyParent));
xhwang 2012/12/07 22:35:39 can we use no_codecs for std::vector<std::string>(
ddorwin 2012/12/08 00:29:07 Done.
106
107 // The parent is not supported for most things.
108 EXPECT_STREQ("Unknown",
109 KeySystemNameForUMA(std::string(kClearKeyParent)).c_str());
110 EXPECT_STREQ("Unknown",
111 KeySystemNameForUMA(WebString::fromUTF8(kClearKeyParent)).c_str());
112 EXPECT_FALSE(CanUseAesDecryptor(kClearKeyParent));
113 EXPECT_TRUE(GetPluginType(kClearKeyParent).empty());
114 }
115
116 TEST_F(KeySystemsTest, ClearKey_IsSupportedKeySystem_InvalidVariants) {
117 // Case sensitive.
118 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.ClEaRkEy"));
119 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
120 "video/webm", std::vector<std::string>(), "webkit-org.w3.ClEaRkEy"));
121
122 // TLDs are not allowed.
123 EXPECT_FALSE(IsSupportedKeySystem("webkit-org."));
124 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
125 "video/webm", std::vector<std::string>(), "webkit-org."));
126 EXPECT_FALSE(IsSupportedKeySystem("webkit-org"));
127 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
128 "video/webm", std::vector<std::string>(), "webkit-org"));
129 EXPECT_FALSE(IsSupportedKeySystem("org."));
130 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
131 "video/webm", std::vector<std::string>(), "org."));
132 EXPECT_FALSE(IsSupportedKeySystem("org"));
133 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
134 "video/webm", std::vector<std::string>(), "org"));
135
136 // Extra period.
137 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3."));
138 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
139 "video/webm", std::vector<std::string>(), "webkit-org.w3."));
140
141 // Incomplete.
142 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearke"));
143 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
144 "video/webm", std::vector<std::string>(), "webkit-org.w3.clearke"));
145
146 // Extra character.
147 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearkeyz"));
148 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
149 "video/webm", std::vector<std::string>(), "webkit-org.w3.clearkeyz"));
150
151 // There are no child key systems for Clear Key.
152 EXPECT_FALSE(IsSupportedKeySystem("webkit-org.w3.clearkey.foo"));
153 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
154 "video/webm", std::vector<std::string>(), "webkit-org.w3.clearkey.foo"));
155 }
156
157 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_NoType) {
158 // These two should be true. See http://crbug.com/164303.
159 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
160 "", std::vector<std::string>(), kClearKey));
161 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
162 "", std::vector<std::string>(), "webkit-org.w3"));
163
164 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
165 "", std::vector<std::string>(), "webkit-org.w3.foo"));
166 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
167 "", std::vector<std::string>(), "webkit-org.w3.clearkey.foo"));
168 }
169
170 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_WebM) {
171 // Valid video types.
172 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
173 "video/webm", no_codecs, kClearKey));
174 // The parent should be supported but is not. See http://crbug.com/164303.
175 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
176 "video/webm", no_codecs, "webkit-org.w3"));
177 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
178 "video/webm", vp8_codec, kClearKey));
179 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
180 "video/webm", vp80_codec, kClearKey));
181 // These two should be true. See http://crbug.com/123421.
182 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
183 "video/webm", vp8_and_vorbis_codecs, kClearKey));
184 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
185 "video/webm", vorbis_codec, kClearKey));
186
187 // Non-Webm codecs.
188 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
189 "video/webm", avc1_codec, kClearKey));
190 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
191 "video/webm", unknown_codec, kClearKey));
192 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
193 "video/webm", mixed_codecs, kClearKey));
194
195 // Valid audio types.
196 // Should be true. See http://crbug.com/123421.
197 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
198 "audio/webm", no_codecs, kClearKey));
199 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
200 "audio/webm", vorbis_codec, kClearKey));
201
202 // Non-audio codecs.
203 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
204 "audio/webm", vp8_codec, kClearKey));
205 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
206 "audio/webm", vp8_and_vorbis_codecs, kClearKey));
207
208 // Non-Webm codec.
209 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
210 "audio/webm", aac_codec, kClearKey));
211 }
212
213 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_ClearKey_MP4) {
214 std::vector<std::string> avc1_extended_codec;
215 avc1_extended_codec.push_back("avc1.4D400C");
216 std::vector<std::string> avc1_dot_codec;
217 avc1_dot_codec.push_back("avc1.");
218 std::vector<std::string> avc2_codec;
219 avc2_codec.push_back("avc2");
220
221 // Valid video types.
222 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
223 "video/mp4", no_codecs, kClearKey));
224 // The parent should be supported but is not. See http://crbug.com/164303.
225 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
226 "video/mp4", no_codecs, "webkit-org.w3"));
227 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
228 "video/mp4", avc1_codec, kClearKey));
229 // These two should be true. See http://crbug.com/123421.
230 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
231 "video/mp4", avc1_and_aac_codecs, kClearKey));
232 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
233 "video/mp4", aac_codec, kClearKey));
234
235 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
236 // They should really pass canPlayType().
237 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
238 "video/mp4", avc1_extended_codec, kClearKey));
239
240 // Invalid codec format.
241 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
242 "video/mp4", avc1_dot_codec, kClearKey));
243
244 // Non-MP4 codecs.
245 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
246 "video/mp4", avc2_codec, kClearKey));
247 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
248 "video/mp4", vp8_codec, kClearKey));
249 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
250 "video/mp4", unknown_codec, kClearKey));
251 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
252 "video/mp4", mixed_codecs, kClearKey));
253
254 // Valid audio types.
255 // Should be true. See http://crbug.com/123421.
256 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
257 "audio/mp4", no_codecs, kClearKey));
258 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
259 "audio/mp4", aac_codec, kClearKey));
260
261 // Non-audio codecs.
262 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
263 "audio/mp4", avc1_codec, kClearKey));
264 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
265 "audio/mp4", avc1_and_aac_codecs, kClearKey));
266
267 // Non-MP4 codec.
268 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
269 "audio/mp4", vorbis_codec, kClearKey));
270 }
271
272 //
273 // External Clear Key
274 //
275
276 TEST_F(KeySystemsTest, ExternalClearKey_Basic) {
277 EXPECT_TRUE(IsSupportedKeySystem(WebString::fromUTF8(kExternalClearKey)));
278 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
279 "video/webm", std::vector<std::string>(), kExternalClearKey));
280
281 // External Clear Key does not have a UMA name because it is for testing.
282 EXPECT_STREQ(
283 "Unknown",
284 KeySystemNameForUMA(std::string(kExternalClearKey)).c_str());
285 EXPECT_STREQ(
286 "Unknown",
287 KeySystemNameForUMA(WebString::fromUTF8(kExternalClearKey)).c_str());
288
289 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKey));
290 EXPECT_STREQ("application/x-ppapi-clearkey-cdm",
291 GetPluginType(kExternalClearKey).c_str());
292 }
293
294 TEST_F(KeySystemsTest, ExternalClearKey_Parent) {
295 const char* const kExternalClearKeyParent = "org.chromium";
296
297 // The parent should be supported but is not. See http://crbug.com/164303.
298 EXPECT_FALSE(
299 IsSupportedKeySystem(WebString::fromUTF8(kExternalClearKeyParent)));
300 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
301 "video/webm", std::vector<std::string>(), kExternalClearKeyParent));
302
303 // The parent is not supported for most things.
304 EXPECT_STREQ(
305 "Unknown",
306 KeySystemNameForUMA(std::string(kExternalClearKeyParent)).c_str());
307 EXPECT_STREQ("Unknown",
308 KeySystemNameForUMA(
309 WebString::fromUTF8(kExternalClearKeyParent)).c_str());
310 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKeyParent));
311 EXPECT_TRUE(GetPluginType(kExternalClearKeyParent).empty());
312 }
313
314 TEST_F(KeySystemsTest, ExternalClearKey_IsSupportedKeySystem_InvalidVariants) {
315 // Case sensitive.
316 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy"));
317 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
318 "video/webm", std::vector<std::string>(),
319 "org.chromium.ExTeRnAlClEaRkEy"));
320
321 // TLDs are not allowed.
322 EXPECT_FALSE(IsSupportedKeySystem("org."));
323 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
324 "video/webm", std::vector<std::string>(), "org."));
325 EXPECT_FALSE(IsSupportedKeySystem("org"));
326 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
327 "video/webm", std::vector<std::string>(), "org"));
328
329 // Extra period.
330 EXPECT_FALSE(IsSupportedKeySystem("org.chromium."));
331 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
332 "video/webm", std::vector<std::string>(), "org.chromium."));
333
334 // Incomplete.
335 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke"));
336 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
337 "video/webm", std::vector<std::string>(),
338 "org.chromium.externalclearke"));
339
340 // Extra character.
341 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeyz"));
342 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
343 "video/webm", std::vector<std::string>(),
344 "org.chromium.externalclearkeyz"));
345
346 // There are no child key systems for Clear Key.
347 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.foo"));
348 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
349 "video/webm", std::vector<std::string>(),
350 "org.chromium.externalclearkey.foo"));
351 }
352
353 TEST_F(KeySystemsTest,
354 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_NoType) {
355 // These two should be true. See http://crbug.com/164303.
356 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
357 "", std::vector<std::string>(), kExternalClearKey));
358 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
359 "", std::vector<std::string>(), "org.chromium"));
360
361 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
362 "", std::vector<std::string>(), "org.chromium.foo"));
363 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
364 "", std::vector<std::string>(), "org.chromium.externalclearkey.foo"));
365 }
366
367 TEST_F(KeySystemsTest,
368 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_WebM) {
369 // Valid video types.
370 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
371 "video/webm", no_codecs, kExternalClearKey));
372 // The parent should be supported but is not. See http://crbug.com/164303.
373 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
374 "video/webm", no_codecs, "org.chromium"));
375 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
376 "video/webm", vp8_codec, kExternalClearKey));
377 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
378 "video/webm", vp80_codec, kExternalClearKey));
379 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
380 "video/webm", vp8_and_vorbis_codecs, kExternalClearKey));
381 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
382 "video/webm", vorbis_codec, kExternalClearKey));
383
384 // Non-Webm codecs.
385 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
386 "video/webm", avc1_codec, kExternalClearKey));
387 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
388 "video/webm", unknown_codec, kExternalClearKey));
389 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
390 "video/webm", mixed_codecs, kExternalClearKey));
391
392 // Valid audio types.
393 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
394 "audio/webm", no_codecs, kExternalClearKey));
395 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
396 "audio/webm", vorbis_codec, kExternalClearKey));
397
398 // Non-audio codecs.
399 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
400 "audio/webm", vp8_codec, kExternalClearKey));
401 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
402 "audio/webm", vp8_and_vorbis_codecs, kExternalClearKey));
403
404 // Non-Webm codec.
405 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
406 "audio/webm", aac_codec, kExternalClearKey));
407 }
408
409 TEST_F(KeySystemsTest,
410 IsSupportedKeySystemWithMediaMimeType_ExternalClearKey_MP4) {
411 std::vector<std::string> avc1_extended_codec;
412 avc1_extended_codec.push_back("avc1.4D400C");
413 std::vector<std::string> avc1_dot_codec;
414 avc1_dot_codec.push_back("avc1.");
415 std::vector<std::string> avc2_codec;
416 avc2_codec.push_back("avc2");
417
418 // Valid video types.
419 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
420 "video/mp4", no_codecs, kExternalClearKey));
421 // The parent should be supported but is not. See http://crbug.com/164303.
422 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
423 "video/mp4", no_codecs, "org.chromium"));
424 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
425 "video/mp4", avc1_codec, kExternalClearKey));
426 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
427 "video/mp4", avc1_and_aac_codecs, kExternalClearKey));
428 EXPECT_PROPRIETARY(IsSupportedKeySystemWithMediaMimeType(
429 "video/mp4", aac_codec, kExternalClearKey));
430
431 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
432 // They should really pass canPlayType().
433 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
434 "video/mp4", avc1_extended_codec, kExternalClearKey));
435
436 // Invalid codec format.
437 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
438 "video/mp4", avc1_dot_codec, kExternalClearKey));
439
440 // Non-MP4 codecs.
441 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
442 "video/mp4", avc2_codec, kExternalClearKey));
443 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
444 "video/mp4", vp8_codec, kExternalClearKey));
445 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
446 "video/mp4", unknown_codec, kExternalClearKey));
447 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
448 "video/mp4", mixed_codecs, kExternalClearKey));
449
450 // Valid audio types.
451 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
452 "audio/mp4", no_codecs, kExternalClearKey));
453 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
454 "audio/mp4", aac_codec, kExternalClearKey));
455
456 // Non-audio codecs.
457 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
458 "audio/mp4", avc1_codec, kExternalClearKey));
459 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
460 "audio/mp4", avc1_and_aac_codecs, kExternalClearKey));
461
462 // Non-MP4 codec.
463 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
464 "audio/mp4", vorbis_codec, kExternalClearKey));
465 }
466
467 //
468 // Widevine
469 //
470
471 TEST_F(KeySystemsTest, Widevine_Basic) {
472 EXPECT_WV(IsSupportedKeySystem(WebString::fromUTF8(kWidevineAlpha)));
473 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
474 "video/webm", std::vector<std::string>(), kWidevineAlpha));
475
476 #if defined(WIDEVINE_CDM_AVAILABLE)
477 const char* const kWidevineUmaName = "Widevine";
478 #else
479 const char* const kWidevineUmaName = "Unknown";
480 #endif
481 EXPECT_STREQ(
482 kWidevineUmaName,
483 KeySystemNameForUMA(std::string(kWidevineAlpha)).c_str());
484 EXPECT_STREQ(
485 kWidevineUmaName,
486 KeySystemNameForUMA(WebString::fromUTF8(kWidevineAlpha)).c_str());
487
488 EXPECT_FALSE(CanUseAesDecryptor(kWidevineAlpha));
489 #if defined(WIDEVINE_CDM_AVAILABLE)
490 EXPECT_STREQ("application/x-ppapi-widevine-cdm",
491 GetPluginType(kWidevineAlpha).c_str());
492 #else
493 EXPECT_TRUE(GetPluginType(kWidevineAlpha).empty());
494 #endif
495 }
496
497 TEST_F(KeySystemsTest, Widevine_Parent) {
498 const char* const kWidevineParent = "com.widevine";
499
500 EXPECT_WV(IsSupportedKeySystem(WebString::fromUTF8(kWidevineParent)));
501 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
502 "video/webm", std::vector<std::string>(), kWidevineParent));
503
504 // The parent is not supported for most things.
505 EXPECT_STREQ("Unknown",
506 KeySystemNameForUMA(std::string(kWidevineParent)).c_str());
507 EXPECT_STREQ("Unknown",
508 KeySystemNameForUMA(WebString::fromUTF8(kWidevineParent)).c_str());
509 EXPECT_FALSE(CanUseAesDecryptor(kWidevineParent));
510 EXPECT_TRUE(GetPluginType(kWidevineParent).empty());
511 }
512
513 TEST_F(KeySystemsTest, Widevine_IsSupportedKeySystem_InvalidVariants) {
514 // Case sensitive.
515 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.AlPhA"));
516 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
517 "video/webm", std::vector<std::string>(), "com.widevine.AlPhA"));
518
519 // TLDs are not allowed.
520 EXPECT_FALSE(IsSupportedKeySystem("com."));
521 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
522 "video/webm", std::vector<std::string>(), "com."));
523 EXPECT_FALSE(IsSupportedKeySystem("com"));
524 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
525 "video/webm", std::vector<std::string>(), "com"));
526
527 // Extra period.
528 EXPECT_FALSE(IsSupportedKeySystem("com.widevine."));
529 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
530 "video/webm", std::vector<std::string>(), "com.widevine."));
531
532 // Incomplete.
533 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph"));
534 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
535 "video/webm", std::vector<std::string>(), "com.widevine.alph"));
536
537 // Extra character.
538 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphab"));
539 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
540 "video/webm", std::vector<std::string>(), "com.widevine.alphab"));
541
542 // There are no child key systems for Widevine Alpha.
543 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.foo"));
544 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
545 "video/webm", std::vector<std::string>(), "com.widevine.alpha.foo"));
546 }
547
548 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_NoType) {
549 // These two should be true. See http://crbug.com/164303.
550 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
551 "", std::vector<std::string>(), "com.widevine.alpha"));
552 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
553 "", std::vector<std::string>(), "com.widevine"));
554
555 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
556 "", std::vector<std::string>(), "com.widevine.foo"));
557 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
558 "", std::vector<std::string>(), "com.widevine.alpha.foo"));
559 }
560
561 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_WebM) {
562 // Valid video types.
563 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
564 "video/webm", no_codecs, kWidevineAlpha));
565 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
566 "video/webm", no_codecs, "com.widevine"));
567 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
568 "video/webm", vp8_codec, kWidevineAlpha));
569 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
570 "video/webm", vp80_codec, kWidevineAlpha));
571 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
572 "video/webm", vp8_and_vorbis_codecs, kWidevineAlpha));
573 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
574 "video/webm", vorbis_codec, kWidevineAlpha));
575
576 // Non-Webm codecs.
577 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
578 "video/webm", avc1_codec, kWidevineAlpha));
579 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
580 "video/webm", unknown_codec, kWidevineAlpha));
581 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
582 "video/webm", mixed_codecs, kWidevineAlpha));
583
584 // Valid audio types.
585 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
586 "audio/webm", no_codecs, kWidevineAlpha));
587 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType(
588 "audio/webm", vorbis_codec, kWidevineAlpha));
589
590 // Non-audio codecs.
591 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
592 "audio/webm", vp8_codec, kWidevineAlpha));
593 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
594 "audio/webm", vp8_and_vorbis_codecs, kWidevineAlpha));
595
596 // Non-Webm codec.
597 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
598 "audio/webm", aac_codec, kWidevineAlpha));
599 }
600
601 TEST_F(KeySystemsTest, IsSupportedKeySystemWithMediaMimeType_Widevine_MP4) {
602 std::vector<std::string> avc1_extended_codec;
603 avc1_extended_codec.push_back("avc1.4D400C");
604 std::vector<std::string> avc1_dot_codec;
605 avc1_dot_codec.push_back("avc1.");
606 std::vector<std::string> avc2_codec;
607 avc2_codec.push_back("avc2");
608
609
610 // Valid video types.
611 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType(
612 "video/mp4", no_codecs, kWidevineAlpha));
613 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType(
614 "video/mp4", no_codecs, "com.widevine"));
615 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType(
616 "video/mp4", avc1_codec, kWidevineAlpha));
617 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType(
618 "video/mp4", avc1_and_aac_codecs, kWidevineAlpha));
619 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType(
620 "video/mp4", aac_codec, kWidevineAlpha));
621
622 // Extended codecs fail because this is handled by SimpleWebMimeRegistryImpl.
623 // They should really pass canPlayType().
624 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
625 "video/mp4", avc1_extended_codec, kWidevineAlpha));
626
627 // Invalid codec format.
628 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
629 "video/mp4", avc1_dot_codec, kWidevineAlpha));
630
631 // Non-MP4 codecs.
632 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
633 "video/mp4", avc2_codec, kWidevineAlpha));
634 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
635 "video/mp4", vp8_codec, kWidevineAlpha));
636 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
637 "video/mp4", unknown_codec, kWidevineAlpha));
638 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
639 "video/mp4", mixed_codecs, kWidevineAlpha));
640
641 // Valid audio types.
642 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType(
643 "audio/mp4", no_codecs, kWidevineAlpha));
644 EXPECT_WVISO(IsSupportedKeySystemWithMediaMimeType(
645 "audio/mp4", aac_codec, kWidevineAlpha));
646
647 // Non-audio codecs.
648 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
649 "audio/mp4", avc1_codec, kWidevineAlpha));
650 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
651 "audio/mp4", avc1_and_aac_codecs, kWidevineAlpha));
652
653 // Non-MP4 codec.
654 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
655 "audio/mp4", vorbis_codec, kWidevineAlpha));
656 }
657
658 } // namespace webkit_media
OLDNEW
« no previous file with comments | « webkit/media/crypto/key_systems.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698