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

Side by Side Diff: content/renderer/media/crypto/key_systems_unittest.cc

Issue 170783010: Encrypted Media: Handle blink::WebString in WebMediaPlayer*. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase only Created 6 years, 10 months 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
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <string> 5 #include <string>
6 #include <vector> 6 #include <vector>
7 7
8 #include "content/public/common/content_client.h" 8 #include "content/public/common/content_client.h"
9 #include "content/public/renderer/content_renderer_client.h" 9 #include "content/public/renderer/content_renderer_client.h"
10 #include "content/public/renderer/key_system_info.h" 10 #include "content/public/renderer/key_system_info.h"
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
52 static const char kWebMAudioCodecs[] = "vorbis"; 52 static const char kWebMAudioCodecs[] = "vorbis";
53 static const char kWebMVideoCodecs[] = "vorbis,vp8,vp8.0"; 53 static const char kWebMVideoCodecs[] = "vorbis,vp8,vp8.0";
54 54
55 static const char kAudioFoo[] = "audio/foo"; 55 static const char kAudioFoo[] = "audio/foo";
56 static const char kVideoFoo[] = "video/foo"; 56 static const char kVideoFoo[] = "video/foo";
57 static const char kFooAudioCodecs[] = "fooaudio"; 57 static const char kFooAudioCodecs[] = "fooaudio";
58 static const char kFooVideoCodecs[] = "fooaudio,foovideo"; 58 static const char kFooVideoCodecs[] = "fooaudio,foovideo";
59 59
60 namespace content { 60 namespace content {
61 61
62 // Helper functions that handle the WebString conversion to simplify tests.
63 static std::string KeySystemNameForUMAUTF8(const std::string& key_system) {
64 return KeySystemNameForUMA(WebString::fromUTF8(key_system));
65 }
66
67 static bool IsConcreteSupportedKeySystemUTF8(const std::string& key_system) {
68 return IsConcreteSupportedKeySystem(WebString::fromUTF8(key_system));
69 }
70
71 class TestContentRendererClient : public ContentRendererClient { 62 class TestContentRendererClient : public ContentRendererClient {
72 virtual void AddKeySystems( 63 virtual void AddKeySystems(
73 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE; 64 std::vector<content::KeySystemInfo>* key_systems) OVERRIDE;
74 }; 65 };
75 66
76 void TestContentRendererClient::AddKeySystems( 67 void TestContentRendererClient::AddKeySystems(
77 std::vector<content::KeySystemInfo>* key_systems) { 68 std::vector<content::KeySystemInfo>* key_systems) {
78 #if defined(OS_ANDROID) 69 #if defined(OS_ANDROID)
79 static const uint8 kExternalUuid[16] = { 70 static const uint8 kExternalUuid[16] = {
80 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF, 71 0x01, 0x23, 0x45, 0x67, 0x89, 0xAB, 0xCD, 0xEF,
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after
199 190
200 CodecVector mixed_codecs_; 191 CodecVector mixed_codecs_;
201 192
202 TestContentClient test_content_client_; 193 TestContentClient test_content_client_;
203 TestContentRendererClient content_renderer_client_; 194 TestContentRendererClient content_renderer_client_;
204 }; 195 };
205 196
206 // TODO(ddorwin): Consider moving GetUUID() into these tests or moving 197 // TODO(ddorwin): Consider moving GetUUID() into these tests or moving
207 // GetPepperType() calls out to their own test. 198 // GetPepperType() calls out to their own test.
208 199
200 TEST_F(KeySystemsTest, EmptyKeySystem) {
201 EXPECT_FALSE(IsConcreteSupportedKeySystem(std::string()));
202 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
203 kVideoWebM, no_codecs(), std::string()));
204 EXPECT_EQ("Unknown", KeySystemNameForUMA(std::string()));
205 }
206
209 // Clear Key is the only key system registered in content. 207 // Clear Key is the only key system registered in content.
210 TEST_F(KeySystemsTest, ClearKey) { 208 TEST_F(KeySystemsTest, ClearKey) {
211 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kPrefixedClearKey)); 209 EXPECT_TRUE(IsConcreteSupportedKeySystem(kPrefixedClearKey));
212 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 210 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
213 kVideoWebM, no_codecs(), kPrefixedClearKey)); 211 kVideoWebM, no_codecs(), kPrefixedClearKey));
214 212
215 EXPECT_EQ("ClearKey", KeySystemNameForUMAUTF8(kPrefixedClearKey)); 213 EXPECT_EQ("ClearKey", KeySystemNameForUMA(kPrefixedClearKey));
216 214
217 // Not yet out from behind the vendor prefix. 215 // Not yet out from behind the vendor prefix.
218 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey)); 216 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnprefixedClearKey));
219 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 217 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
220 kVideoWebM, no_codecs(), kUnprefixedClearKey)); 218 kVideoWebM, no_codecs(), kUnprefixedClearKey));
221 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnprefixedClearKey)); 219 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUnprefixedClearKey));
222 } 220 }
223 221
224 // The key system is not registered and therefore is unrecognized. 222 // The key system is not registered and therefore is unrecognized.
225 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) { 223 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) {
226 static const char* const kUnrecognized = "org.example.unrecognized"; 224 static const char* const kUnrecognized = "org.example.unrecognized";
227 225
228 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kUnrecognized)); 226 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUnrecognized));
229 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 227 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
230 kVideoWebM, no_codecs(), kUnrecognized)); 228 kVideoWebM, no_codecs(), kUnrecognized));
231 229
232 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnrecognized)); 230 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUnrecognized));
233 231
234 bool can_use = false; 232 bool can_use = false;
235 EXPECT_DEBUG_DEATH_PORTABLE( 233 EXPECT_DEBUG_DEATH_PORTABLE(
236 can_use = CanUseAesDecryptor(kUnrecognized), 234 can_use = CanUseAesDecryptor(kUnrecognized),
237 "org.example.unrecognized is not a known concrete system"); 235 "org.example.unrecognized is not a known concrete system");
238 EXPECT_FALSE(can_use); 236 EXPECT_FALSE(can_use);
239 237
240 #if defined(ENABLE_PEPPER_CDMS) 238 #if defined(ENABLE_PEPPER_CDMS)
241 std::string type; 239 std::string type;
242 EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized), 240 EXPECT_DEBUG_DEATH(type = GetPepperType(kUnrecognized),
243 "org.example.unrecognized is not a known concrete system"); 241 "org.example.unrecognized is not a known concrete system");
244 EXPECT_TRUE(type.empty()); 242 EXPECT_TRUE(type.empty());
245 #endif 243 #endif
246 } 244 }
247 245
248 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) { 246 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
249 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kUsesAes)); 247 EXPECT_TRUE(IsConcreteSupportedKeySystem(kUsesAes));
250 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 248 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
251 kVideoWebM, no_codecs(), kUsesAes)); 249 kVideoWebM, no_codecs(), kUsesAes));
252 250
253 // No UMA value for this test key system. 251 // No UMA value for this test key system.
254 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUsesAes)); 252 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUsesAes));
255 253
256 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes)); 254 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
257 #if defined(ENABLE_PEPPER_CDMS) 255 #if defined(ENABLE_PEPPER_CDMS)
258 std::string type; 256 std::string type;
259 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes), 257 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAes),
260 "org.example.clear is not Pepper-based"); 258 "org.example.clear is not Pepper-based");
261 EXPECT_TRUE(type.empty()); 259 EXPECT_TRUE(type.empty());
262 #endif 260 #endif
263 } 261 }
264 262
(...skipping 29 matching lines...) Expand all
294 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 292 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
295 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes)); 293 kAudioWebM, vp8_and_vorbis_codecs(), kUsesAes));
296 294
297 // Non-Webm codec. 295 // Non-Webm codec.
298 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 296 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
299 kAudioWebM, fooaudio_codec(), kUsesAes)); 297 kAudioWebM, fooaudio_codec(), kUsesAes));
300 } 298 }
301 299
302 // No parent is registered for UsesAes. 300 // No parent is registered for UsesAes.
303 TEST_F(KeySystemsTest, Parent_NoParentRegistered) { 301 TEST_F(KeySystemsTest, Parent_NoParentRegistered) {
304 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kUsesAesParent)); 302 EXPECT_FALSE(IsConcreteSupportedKeySystem(kUsesAesParent));
305 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 303 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
306 kVideoWebM, no_codecs(), kUsesAesParent)); 304 kVideoWebM, no_codecs(), kUsesAesParent));
307 305
308 // The parent is not supported for most things. 306 // The parent is not supported for most things.
309 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUsesAesParent)); 307 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUsesAesParent));
310 bool result = false; 308 bool result = false;
311 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent), 309 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent),
312 "org.example is not a known concrete system"); 310 "org.example is not a known concrete system");
313 EXPECT_FALSE(result); 311 EXPECT_FALSE(result);
314 #if defined(ENABLE_PEPPER_CDMS) 312 #if defined(ENABLE_PEPPER_CDMS)
315 std::string type; 313 std::string type;
316 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent), 314 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent),
317 "org.example is not a known concrete system"); 315 "org.example is not a known concrete system");
318 EXPECT_TRUE(type.empty()); 316 EXPECT_TRUE(type.empty());
319 #endif 317 #endif
320 } 318 }
321 319
322 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) { 320 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) {
323 // Case sensitive. 321 // Case sensitive.
324 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8("org.example.ClEaR")); 322 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.example.ClEaR"));
325 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 323 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
326 kVideoWebM, no_codecs(), "org.example.ClEaR")); 324 kVideoWebM, no_codecs(), "org.example.ClEaR"));
327 325
328 // TLDs are not allowed. 326 // TLDs are not allowed.
329 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.")); 327 EXPECT_FALSE(IsConcreteSupportedKeySystem("org."));
330 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 328 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
331 kVideoWebM, no_codecs(), "org.")); 329 kVideoWebM, no_codecs(), "org."));
332 EXPECT_FALSE(IsConcreteSupportedKeySystem("com")); 330 EXPECT_FALSE(IsConcreteSupportedKeySystem("com"));
333 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 331 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
334 kVideoWebM, no_codecs(), "com")); 332 kVideoWebM, no_codecs(), "com"));
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
415 // Non-container2 codec. 413 // Non-container2 codec.
416 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( 414 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType(
417 kAudioFoo, vorbis_codec(), kUsesAes)); 415 kAudioFoo, vorbis_codec(), kUsesAes));
418 } 416 }
419 417
420 // 418 //
421 // Non-AesDecryptor-based key system. 419 // Non-AesDecryptor-based key system.
422 // 420 //
423 421
424 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) { 422 TEST_F(KeySystemsTest, Basic_ExternalDecryptor) {
425 EXPECT_TRUE(IsConcreteSupportedKeySystemUTF8(kExternal)); 423 EXPECT_TRUE(IsConcreteSupportedKeySystem(kExternal));
426 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 424 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
427 kVideoWebM, no_codecs(), kExternal)); 425 kVideoWebM, no_codecs(), kExternal));
428 426
429 EXPECT_FALSE(CanUseAesDecryptor(kExternal)); 427 EXPECT_FALSE(CanUseAesDecryptor(kExternal));
430 #if defined(ENABLE_PEPPER_CDMS) 428 #if defined(ENABLE_PEPPER_CDMS)
431 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal)); 429 EXPECT_EQ("application/x-ppapi-external-cdm", GetPepperType(kExternal));
432 #endif // defined(ENABLE_PEPPER_CDMS) 430 #endif // defined(ENABLE_PEPPER_CDMS)
433 431
434 } 432 }
435 433
436 TEST_F(KeySystemsTest, Parent_ParentRegistered) { 434 TEST_F(KeySystemsTest, Parent_ParentRegistered) {
437 // The parent system is not a concrete system but is supported. 435 // The parent system is not a concrete system but is supported.
438 EXPECT_FALSE(IsConcreteSupportedKeySystemUTF8(kExternalParent)); 436 EXPECT_FALSE(IsConcreteSupportedKeySystem(kExternalParent));
439 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 437 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
440 kVideoWebM, no_codecs(), kExternalParent)); 438 kVideoWebM, no_codecs(), kExternalParent));
441 439
442 // The parent is not supported for most things. 440 // The parent is not supported for most things.
443 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kExternalParent)); 441 EXPECT_EQ("Unknown", KeySystemNameForUMA(kExternalParent));
444 bool result = false; 442 bool result = false;
445 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent), 443 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent),
446 "com.example is not a known concrete system"); 444 "com.example is not a known concrete system");
447 EXPECT_FALSE(result); 445 EXPECT_FALSE(result);
448 #if defined(ENABLE_PEPPER_CDMS) 446 #if defined(ENABLE_PEPPER_CDMS)
449 std::string type; 447 std::string type;
450 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent), 448 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent),
451 "com.example is not a known concrete system"); 449 "com.example is not a known concrete system");
452 EXPECT_TRUE(type.empty()); 450 EXPECT_TRUE(type.empty());
453 #endif 451 #endif
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
590 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(kExternalParent), 588 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(kExternalParent),
591 "com.example is not a known concrete system"); 589 "com.example is not a known concrete system");
592 EXPECT_TRUE(uuid.empty()); 590 EXPECT_TRUE(uuid.empty());
593 591
594 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(""), " is not a concrete system"); 592 EXPECT_DEBUG_DEATH_PORTABLE(uuid = GetUUID(""), " is not a concrete system");
595 EXPECT_TRUE(uuid.empty()); 593 EXPECT_TRUE(uuid.empty());
596 } 594 }
597 #endif // defined(OS_ANDROID) 595 #endif // defined(OS_ANDROID)
598 596
599 TEST_F(KeySystemsTest, KeySystemNameForUMA) { 597 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
600 EXPECT_EQ("ClearKey", KeySystemNameForUMAUTF8(kPrefixedClearKey)); 598 EXPECT_EQ("ClearKey", KeySystemNameForUMA(kPrefixedClearKey));
601 // Unprefixed is not yet supported. 599 // Unprefixed is not yet supported.
602 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kUnprefixedClearKey)); 600 EXPECT_EQ("Unknown", KeySystemNameForUMA(kUnprefixedClearKey));
603 601
604 // External Clear Key never has a UMA name. 602 // External Clear Key never has a UMA name.
605 EXPECT_EQ("Unknown", KeySystemNameForUMAUTF8(kExternalClearKey)); 603 EXPECT_EQ("Unknown", KeySystemNameForUMA(kExternalClearKey));
606 604
607 #if defined(WIDEVINE_CDM_AVAILABLE) 605 #if defined(WIDEVINE_CDM_AVAILABLE)
608 const char* const kTestWidevineUmaName = "Widevine"; 606 const char* const kTestWidevineUmaName = "Widevine";
609 #else 607 #else
610 const char* const kTestWidevineUmaName = "Unknown"; 608 const char* const kTestWidevineUmaName = "Unknown";
611 #endif 609 #endif
612 EXPECT_EQ(kTestWidevineUmaName, 610 EXPECT_EQ(kTestWidevineUmaName,
613 KeySystemNameForUMAUTF8("com.widevine.alpha")); 611 KeySystemNameForUMA("com.widevine.alpha"));
614 } 612 }
615 613
616 } // namespace content 614 } // namespace content
OLDNEW
« no previous file with comments | « content/renderer/media/crypto/key_systems.cc ('k') | content/renderer/media/webmediaplayer_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698