| OLD | NEW |
| 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/renderer/media/crypto/key_systems.h" | 8 #include "content/renderer/media/crypto/key_systems.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/WebKit/public/platform/WebString.h" | 10 #include "third_party/WebKit/public/platform/WebString.h" |
| (...skipping 190 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 // Not yet out from behind the vendor prefix. | 201 // Not yet out from behind the vendor prefix. |
| 202 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.w3.clearkey")); | 202 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.w3.clearkey")); |
| 203 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( | 203 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 204 "video/webm", no_codecs(), "org.w3.clearkey")); | 204 "video/webm", no_codecs(), "org.w3.clearkey")); |
| 205 | 205 |
| 206 EXPECT_STREQ("ClearKey", | 206 EXPECT_STREQ("ClearKey", |
| 207 KeySystemNameForUMA(WebString::fromUTF8(kClearKey)).c_str()); | 207 KeySystemNameForUMA(WebString::fromUTF8(kClearKey)).c_str()); |
| 208 | 208 |
| 209 EXPECT_TRUE(CanUseAesDecryptor(kClearKey)); | 209 EXPECT_TRUE(CanUseAesDecryptor(kClearKey)); |
| 210 #if defined(ENABLE_PEPPER_CDMS) | 210 #if defined(ENABLE_PEPPER_CDMS) |
| 211 EXPECT_TRUE(GetPepperType(kClearKey).empty()); // Does not use Pepper. | 211 std::string type; |
| 212 EXPECT_DCHECK_DEATH(type = GetPepperType(kClearKey), |
| 213 "webkit-org.w3.clearkey is not Pepper-based"); |
| 214 EXPECT_TRUE(type.empty()); |
| 212 #endif | 215 #endif |
| 213 } | 216 } |
| 214 | 217 |
| 215 TEST_F(KeySystemsTest, ClearKey_Parent) { | 218 TEST_F(KeySystemsTest, ClearKey_Parent) { |
| 216 const char* const kClearKeyParent = "webkit-org.w3"; | 219 const char* const kClearKeyParent = "webkit-org.w3"; |
| 217 | 220 |
| 218 // The parent should be supported but is not. See http://crbug.com/164303. | 221 // The parent should be supported but is not. See http://crbug.com/164303. |
| 219 EXPECT_FALSE( | 222 EXPECT_FALSE( |
| 220 IsConcreteSupportedKeySystem(WebString::fromUTF8(kClearKeyParent))); | 223 IsConcreteSupportedKeySystem(WebString::fromUTF8(kClearKeyParent))); |
| 221 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( | 224 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 222 "video/webm", no_codecs(), kClearKeyParent)); | 225 "video/webm", no_codecs(), kClearKeyParent)); |
| 223 | 226 |
| 224 // The parent is not supported for most things. | 227 // The parent is not supported for most things. |
| 225 EXPECT_STREQ("Unknown", | 228 EXPECT_STREQ("Unknown", |
| 226 KeySystemNameForUMA(WebString::fromUTF8(kClearKeyParent)).c_str()); | 229 KeySystemNameForUMA(WebString::fromUTF8(kClearKeyParent)).c_str()); |
| 227 EXPECT_FALSE(CanUseAesDecryptor(kClearKeyParent)); | 230 bool result = false; |
| 231 EXPECT_DCHECK_DEATH(result = CanUseAesDecryptor(kClearKeyParent), |
| 232 "webkit-org.w3 is not a known concrete system"); |
| 233 EXPECT_FALSE(result); |
| 228 #if defined(ENABLE_PEPPER_CDMS) | 234 #if defined(ENABLE_PEPPER_CDMS) |
| 229 std::string type; | 235 std::string type; |
| 230 EXPECT_DCHECK_DEATH(type = GetPepperType(kClearKeyParent), | 236 EXPECT_DCHECK_DEATH(type = GetPepperType(kClearKeyParent), |
| 231 "webkit-org.w3 is not a concrete system"); | 237 "webkit-org.w3 is not a known concrete system"); |
| 232 EXPECT_TRUE(type.empty()); | 238 EXPECT_TRUE(type.empty()); |
| 233 #endif | 239 #endif |
| 234 } | 240 } |
| 235 | 241 |
| 236 TEST_F(KeySystemsTest, ClearKey_IsSupportedKeySystem_InvalidVariants) { | 242 TEST_F(KeySystemsTest, ClearKey_IsSupportedKeySystem_InvalidVariants) { |
| 237 // Case sensitive. | 243 // Case sensitive. |
| 238 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.ClEaRkEy")); | 244 EXPECT_FALSE(IsConcreteSupportedKeySystem("webkit-org.w3.ClEaRkEy")); |
| 239 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( | 245 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 240 "video/webm", no_codecs(), "webkit-org.w3.ClEaRkEy")); | 246 "video/webm", no_codecs(), "webkit-org.w3.ClEaRkEy")); |
| 241 | 247 |
| (...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 386 EXPECT_ECK( | 392 EXPECT_ECK( |
| 387 IsConcreteSupportedKeySystem(WebString::fromUTF8(kExternalClearKey))); | 393 IsConcreteSupportedKeySystem(WebString::fromUTF8(kExternalClearKey))); |
| 388 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( | 394 EXPECT_ECK(IsSupportedKeySystemWithMediaMimeType( |
| 389 "video/webm", no_codecs(), kExternalClearKey)); | 395 "video/webm", no_codecs(), kExternalClearKey)); |
| 390 | 396 |
| 391 // External Clear Key does not have a UMA name because it is for testing. | 397 // External Clear Key does not have a UMA name because it is for testing. |
| 392 EXPECT_STREQ( | 398 EXPECT_STREQ( |
| 393 "Unknown", | 399 "Unknown", |
| 394 KeySystemNameForUMA(WebString::fromUTF8(kExternalClearKey)).c_str()); | 400 KeySystemNameForUMA(WebString::fromUTF8(kExternalClearKey)).c_str()); |
| 395 | 401 |
| 402 #if defined(ENABLE_PEPPER_CDMS) |
| 396 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKey)); | 403 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKey)); |
| 397 #if defined(ENABLE_PEPPER_CDMS) | |
| 398 EXPECT_STREQ("application/x-ppapi-clearkey-cdm", | 404 EXPECT_STREQ("application/x-ppapi-clearkey-cdm", |
| 399 GetPepperType(kExternalClearKey).c_str()); | 405 GetPepperType(kExternalClearKey).c_str()); |
| 406 #else |
| 407 bool result = false; |
| 408 EXPECT_DCHECK_DEATH( |
| 409 result = CanUseAesDecryptor(kExternalClearKey), |
| 410 "org.chromium.externalclearkey is not a known concrete system"); |
| 411 EXPECT_FALSE(result); |
| 400 #endif | 412 #endif |
| 401 } | 413 } |
| 402 | 414 |
| 403 TEST_F(KeySystemsTest, ExternalClearKey_Parent) { | 415 TEST_F(KeySystemsTest, ExternalClearKey_Parent) { |
| 404 const char* const kExternalClearKeyParent = "org.chromium"; | 416 const char* const kExternalClearKeyParent = "org.chromium"; |
| 405 | 417 |
| 406 // The parent should be supported but is not. See http://crbug.com/164303. | 418 // The parent should be supported but is not. See http://crbug.com/164303. |
| 407 EXPECT_FALSE(IsConcreteSupportedKeySystem( | 419 EXPECT_FALSE(IsConcreteSupportedKeySystem( |
| 408 WebString::fromUTF8(kExternalClearKeyParent))); | 420 WebString::fromUTF8(kExternalClearKeyParent))); |
| 409 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( | 421 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 410 "video/webm", no_codecs(), kExternalClearKeyParent)); | 422 "video/webm", no_codecs(), kExternalClearKeyParent)); |
| 411 | 423 |
| 412 // The parent is not supported for most things. | 424 // The parent is not supported for most things. |
| 413 EXPECT_STREQ("Unknown", | 425 EXPECT_STREQ("Unknown", |
| 414 KeySystemNameForUMA( | 426 KeySystemNameForUMA( |
| 415 WebString::fromUTF8(kExternalClearKeyParent)).c_str()); | 427 WebString::fromUTF8(kExternalClearKeyParent)).c_str()); |
| 416 EXPECT_FALSE(CanUseAesDecryptor(kExternalClearKeyParent)); | 428 bool result = false; |
| 429 EXPECT_DCHECK_DEATH(result = CanUseAesDecryptor(kExternalClearKeyParent), |
| 430 "org.chromium is not a known concrete system"); |
| 431 EXPECT_FALSE(result); |
| 417 #if defined(ENABLE_PEPPER_CDMS) | 432 #if defined(ENABLE_PEPPER_CDMS) |
| 418 std::string type; | 433 std::string type; |
| 419 EXPECT_DCHECK_DEATH(type = GetPepperType(kExternalClearKeyParent), | 434 EXPECT_DCHECK_DEATH(type = GetPepperType(kExternalClearKeyParent), |
| 420 "org.chromium is not a concrete system"); | 435 "org.chromium is not a known concrete system"); |
| 421 EXPECT_TRUE(type.empty()); | 436 EXPECT_TRUE(type.empty()); |
| 422 #endif | 437 #endif |
| 423 } | 438 } |
| 424 | 439 |
| 425 TEST_F(KeySystemsTest, ExternalClearKey_IsSupportedKeySystem_InvalidVariants) { | 440 TEST_F(KeySystemsTest, ExternalClearKey_IsSupportedKeySystem_InvalidVariants) { |
| 426 // Case sensitive. | 441 // Case sensitive. |
| 427 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy")); | 442 EXPECT_FALSE(IsConcreteSupportedKeySystem("org.chromium.ExTeRnAlClEaRkEy")); |
| 428 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( | 443 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 429 "video/webm", no_codecs(), | 444 "video/webm", no_codecs(), |
| 430 "org.chromium.ExTeRnAlClEaRkEy")); | 445 "org.chromium.ExTeRnAlClEaRkEy")); |
| (...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 587 | 602 |
| 588 #if defined(WIDEVINE_CDM_AVAILABLE) | 603 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 589 const char* const kWidevineUmaName = "Widevine"; | 604 const char* const kWidevineUmaName = "Widevine"; |
| 590 #else | 605 #else |
| 591 const char* const kWidevineUmaName = "Unknown"; | 606 const char* const kWidevineUmaName = "Unknown"; |
| 592 #endif | 607 #endif |
| 593 EXPECT_STREQ( | 608 EXPECT_STREQ( |
| 594 kWidevineUmaName, | 609 kWidevineUmaName, |
| 595 KeySystemNameForUMA(WebString::fromUTF8(kWidevineAlpha)).c_str()); | 610 KeySystemNameForUMA(WebString::fromUTF8(kWidevineAlpha)).c_str()); |
| 596 | 611 |
| 612 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 597 EXPECT_FALSE(CanUseAesDecryptor(kWidevineAlpha)); | 613 EXPECT_FALSE(CanUseAesDecryptor(kWidevineAlpha)); |
| 614 #else |
| 615 bool result = false; |
| 616 EXPECT_DCHECK_DEATH(result = CanUseAesDecryptor(kWidevineAlpha), |
| 617 "com.widevine.alpha is not a known concrete system"); |
| 618 EXPECT_FALSE(result); |
| 619 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 620 |
| 598 #if defined(ENABLE_PEPPER_CDMS) | 621 #if defined(ENABLE_PEPPER_CDMS) |
| 599 #if defined(WIDEVINE_CDM_AVAILABLE) | 622 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 600 EXPECT_STREQ("application/x-ppapi-widevine-cdm", | 623 EXPECT_STREQ("application/x-ppapi-widevine-cdm", |
| 601 GetPepperType(kWidevineAlpha).c_str()); | 624 GetPepperType(kWidevineAlpha).c_str()); |
| 602 #else | 625 #else |
| 603 std::string type; | 626 std::string type; |
| 604 EXPECT_DCHECK_DEATH(type = GetPepperType(kWidevineAlpha), | 627 EXPECT_DCHECK_DEATH(type = GetPepperType(kWidevineAlpha), |
| 605 "com.widevine.alpha is not a concrete system"); | 628 "com.widevine.alpha is not a known concrete system"); |
| 606 EXPECT_TRUE(type.empty()); | 629 EXPECT_TRUE(type.empty()); |
| 607 #endif // defined(WIDEVINE_CDM_AVAILABLE) | 630 #endif // defined(WIDEVINE_CDM_AVAILABLE) |
| 608 #endif // defined(ENABLE_PEPPER_CDMS) | 631 #endif // defined(ENABLE_PEPPER_CDMS) |
| 609 | 632 |
| 610 } | 633 } |
| 611 | 634 |
| 612 TEST_F(KeySystemsTest, Widevine_Parent) { | 635 TEST_F(KeySystemsTest, Widevine_Parent) { |
| 613 // The parent system is not a concrete system but is supported. | 636 // The parent system is not a concrete system but is supported. |
| 614 EXPECT_FALSE(IsConcreteSupportedKeySystem(WebString::fromUTF8(kWidevine))); | 637 EXPECT_FALSE(IsConcreteSupportedKeySystem(WebString::fromUTF8(kWidevine))); |
| 615 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( | 638 EXPECT_WV(IsSupportedKeySystemWithMediaMimeType( |
| 616 "video/webm", no_codecs(), kWidevine)); | 639 "video/webm", no_codecs(), kWidevine)); |
| 617 | 640 |
| 618 // The parent is not supported for most things. | 641 // The parent is not supported for most things. |
| 619 EXPECT_STREQ("Unknown", | 642 EXPECT_STREQ("Unknown", |
| 620 KeySystemNameForUMA(WebString::fromUTF8(kWidevine)).c_str()); | 643 KeySystemNameForUMA(WebString::fromUTF8(kWidevine)).c_str()); |
| 621 EXPECT_FALSE(CanUseAesDecryptor(kWidevine)); | 644 bool result = false; |
| 645 EXPECT_DCHECK_DEATH(result = CanUseAesDecryptor(kWidevine), |
| 646 "com.widevine is not a known concrete system"); |
| 647 EXPECT_FALSE(result); |
| 622 #if defined(ENABLE_PEPPER_CDMS) | 648 #if defined(ENABLE_PEPPER_CDMS) |
| 623 std::string type; | 649 std::string type; |
| 624 EXPECT_DCHECK_DEATH(type = GetPepperType(kWidevine), | 650 EXPECT_DCHECK_DEATH(type = GetPepperType(kWidevine), |
| 625 "com.widevine is not a concrete system"); | 651 "com.widevine is not a known concrete system"); |
| 626 EXPECT_TRUE(type.empty()); | 652 EXPECT_TRUE(type.empty()); |
| 627 #endif | 653 #endif |
| 628 } | 654 } |
| 629 | 655 |
| 630 TEST_F(KeySystemsTest, Widevine_IsSupportedKeySystem_InvalidVariants) { | 656 TEST_F(KeySystemsTest, Widevine_IsSupportedKeySystem_InvalidVariants) { |
| 631 // Case sensitive. | 657 // Case sensitive. |
| 632 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.AlPhA")); | 658 EXPECT_FALSE(IsConcreteSupportedKeySystem("com.widevine.AlPhA")); |
| 633 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( | 659 EXPECT_FALSE(IsSupportedKeySystemWithMediaMimeType( |
| 634 "video/webm", no_codecs(), "com.widevine.AlPhA")); | 660 "video/webm", no_codecs(), "com.widevine.AlPhA")); |
| 635 | 661 |
| (...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 | 822 |
| 797 #if defined(OS_ANDROID) | 823 #if defined(OS_ANDROID) |
| 798 TEST_F(KeySystemsTest, GetUUID_Widevine) { | 824 TEST_F(KeySystemsTest, GetUUID_Widevine) { |
| 799 #if defined(WIDEVINE_CDM_AVAILABLE) | 825 #if defined(WIDEVINE_CDM_AVAILABLE) |
| 800 std::vector<uint8> uuid = GetUUID(kWidevineAlpha); | 826 std::vector<uint8> uuid = GetUUID(kWidevineAlpha); |
| 801 EXPECT_EQ(16u, uuid.size()); | 827 EXPECT_EQ(16u, uuid.size()); |
| 802 EXPECT_EQ(0xED, uuid[15]); | 828 EXPECT_EQ(0xED, uuid[15]); |
| 803 #else | 829 #else |
| 804 std::vector<uint8> uuid; | 830 std::vector<uint8> uuid; |
| 805 EXPECT_DCHECK_DEATH(uuid = GetUUID(kWidevineAlpha), | 831 EXPECT_DCHECK_DEATH(uuid = GetUUID(kWidevineAlpha), |
| 806 "com.widevine.alpha is not a concrete system"); | 832 "com.widevine.alpha is not a known concrete system"); |
| 807 EXPECT_TRUE(uuid.empty()); | 833 EXPECT_TRUE(uuid.empty()); |
| 808 #endif | 834 #endif |
| 809 } | 835 } |
| 810 | 836 |
| 811 TEST_F(KeySystemsTest, GetUUID_Unrecognized) { | 837 TEST_F(KeySystemsTest, GetUUID_Unrecognized) { |
| 812 std::vector<uint8> uuid; | 838 std::vector<uint8> uuid; |
| 813 EXPECT_DCHECK_DEATH(uuid = GetUUID(kWidevine), | 839 EXPECT_DCHECK_DEATH(uuid = GetUUID(kWidevine), |
| 814 "com.widevine is not a concrete system"); | 840 "com.widevine is not a known concrete system"); |
| 815 EXPECT_TRUE(uuid.empty()); | 841 EXPECT_TRUE(uuid.empty()); |
| 816 | 842 |
| 817 EXPECT_TRUE(GetUUID(kClearKey).empty()); | 843 EXPECT_TRUE(GetUUID(kClearKey).empty()); |
| 818 | 844 |
| 819 EXPECT_DCHECK_DEATH(uuid = GetUUID(""), " is not a concrete system"); | 845 EXPECT_DCHECK_DEATH(uuid = GetUUID(""), " is not a concrete system"); |
| 820 EXPECT_TRUE(uuid.empty()); | 846 EXPECT_TRUE(uuid.empty()); |
| 821 } | 847 } |
| 822 #endif // defined(OS_ANDROID) | 848 #endif // defined(OS_ANDROID) |
| 823 | 849 |
| 824 } // namespace content | 850 } // namespace content |
| OLD | NEW |