| 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 // TODO(sandersd): Refactor to remove recomputed codec arrays, and generally | 5 // TODO(sandersd): Refactor to remove recomputed codec arrays, and generally |
| 6 // shorten and improve coverage. | 6 // shorten and improve coverage. |
| 7 // - http://crbug.com/417444 | 7 // - http://crbug.com/417444 |
| 8 // - http://crbug.com/457438 | 8 // - http://crbug.com/457438 |
| 9 // TODO(sandersd): Add tests to cover codec vectors with empty items. | 9 // TODO(sandersd): Add tests to cover codec vectors with empty items. |
| 10 // http://crbug.com/417461 | 10 // http://crbug.com/417461 |
| 11 | 11 |
| 12 #include <string> | 12 #include <string> |
| 13 #include <vector> | 13 #include <vector> |
| 14 | 14 |
| 15 #include "base/logging.h" | 15 #include "base/logging.h" |
| 16 #include "media/base/eme_constants.h" | 16 #include "media/base/eme_constants.h" |
| 17 #include "media/base/key_system_info.h" | 17 #include "media/base/key_system_info.h" |
| 18 #include "media/base/key_systems.h" | 18 #include "media/base/key_systems.h" |
| 19 #include "media/base/media_client.h" | 19 #include "media/base/media_client.h" |
| 20 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 21 | 21 |
| 22 // Death tests are not always available, including on Android. | |
| 23 // EXPECT_DEBUG_DEATH_PORTABLE executes tests correctly except in the case that | |
| 24 // death tests are not available and NDEBUG is not defined. | |
| 25 #if defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) | |
| 26 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ | |
| 27 EXPECT_DEBUG_DEATH(statement, regex) | |
| 28 #else | |
| 29 #if defined(NDEBUG) | |
| 30 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ | |
| 31 do { statement; } while (false) | |
| 32 #else | |
| 33 #include "base/logging.h" | |
| 34 #define EXPECT_DEBUG_DEATH_PORTABLE(statement, regex) \ | |
| 35 LOG(WARNING) << "Death tests are not supported on this platform.\n" \ | |
| 36 << "Statement '" #statement "' cannot be verified."; | |
| 37 #endif // defined(NDEBUG) | |
| 38 #endif // defined(GTEST_HAS_DEATH_TEST) && !defined(OS_ANDROID) | |
| 39 | |
| 40 namespace media { | 22 namespace media { |
| 41 | 23 |
| 42 // These are the (fake) key systems that are registered for these tests. | 24 // These are the (fake) key systems that are registered for these tests. |
| 43 // kUsesAes uses the AesDecryptor like Clear Key. | 25 // kUsesAes uses the AesDecryptor like Clear Key. |
| 44 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM. | 26 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM. |
| 45 const char kUsesAes[] = "x-org.example.clear"; | 27 const char kUsesAes[] = "x-org.example.clear"; |
| 46 const char kUsesAesParent[] = "x-org.example"; // Not registered. | 28 const char kUsesAesParent[] = "x-org.example"; // Not registered. |
| 47 const char kUseAesNameForUMA[] = "UseAes"; | 29 const char kUseAesNameForUMA[] = "UseAes"; |
| 48 const char kExternal[] = "x-com.example.test"; | 30 const char kExternal[] = "x-com.example.test"; |
| 49 const char kExternalParent[] = "x-com.example"; | 31 const char kExternalParent[] = "x-com.example"; |
| (...skipping 349 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 399 EmeInitDataType::UNKNOWN)); | 381 EmeInitDataType::UNKNOWN)); |
| 400 } | 382 } |
| 401 | 383 |
| 402 // The key system is not registered and therefore is unrecognized. | 384 // The key system is not registered and therefore is unrecognized. |
| 403 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) { | 385 TEST_F(KeySystemsTest, Basic_UnrecognizedKeySystem) { |
| 404 static const char* const kUnrecognized = "x-org.example.unrecognized"; | 386 static const char* const kUnrecognized = "x-org.example.unrecognized"; |
| 405 | 387 |
| 406 EXPECT_FALSE(IsSupportedKeySystem(kUnrecognized)); | 388 EXPECT_FALSE(IsSupportedKeySystem(kUnrecognized)); |
| 407 | 389 |
| 408 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUnrecognized)); | 390 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUnrecognized)); |
| 409 | 391 EXPECT_FALSE(CanUseAesDecryptor(kUnrecognized)); |
| 410 bool can_use = false; | |
| 411 EXPECT_DEBUG_DEATH_PORTABLE( | |
| 412 can_use = CanUseAesDecryptor(kUnrecognized), | |
| 413 "x-org.example.unrecognized is not a known concrete system"); | |
| 414 EXPECT_FALSE(can_use); | |
| 415 | 392 |
| 416 #if defined(ENABLE_PEPPER_CDMS) | 393 #if defined(ENABLE_PEPPER_CDMS) |
| 417 std::string type; | 394 std::string type; |
| 418 EXPECT_DEBUG_DEATH( | 395 EXPECT_DEBUG_DEATH( |
| 419 type = GetPepperType(kUnrecognized), | 396 type = GetPepperType(kUnrecognized), |
| 420 "x-org.example.unrecognized is not a known concrete system"); | 397 "x-org.example.unrecognized is not a known concrete system"); |
| 421 EXPECT_TRUE(type.empty()); | 398 EXPECT_TRUE(type.empty()); |
| 422 #endif | 399 #endif |
| 423 } | 400 } |
| 424 | 401 |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 487 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType( | 464 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType( |
| 488 kAudioWebM, fooaudio_codec(), kUsesAes)); | 465 kAudioWebM, fooaudio_codec(), kUsesAes)); |
| 489 } | 466 } |
| 490 | 467 |
| 491 // No parent is registered for UsesAes. | 468 // No parent is registered for UsesAes. |
| 492 TEST_F(KeySystemsTest, Parent_NoParentRegistered) { | 469 TEST_F(KeySystemsTest, Parent_NoParentRegistered) { |
| 493 EXPECT_FALSE(IsSupportedKeySystem(kUsesAesParent)); | 470 EXPECT_FALSE(IsSupportedKeySystem(kUsesAesParent)); |
| 494 | 471 |
| 495 // The parent is not supported for most things. | 472 // The parent is not supported for most things. |
| 496 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAesParent)); | 473 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAesParent)); |
| 497 bool result = false; | 474 EXPECT_FALSE(CanUseAesDecryptor(kUsesAesParent)); |
| 498 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kUsesAesParent), | 475 |
| 499 "x-org.example is not a known concrete system"); | |
| 500 EXPECT_FALSE(result); | |
| 501 #if defined(ENABLE_PEPPER_CDMS) | 476 #if defined(ENABLE_PEPPER_CDMS) |
| 502 std::string type; | 477 std::string type; |
| 503 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent), | 478 EXPECT_DEBUG_DEATH(type = GetPepperType(kUsesAesParent), |
| 504 "x-org.example is not a known concrete system"); | 479 "x-org.example is not a known concrete system"); |
| 505 EXPECT_TRUE(type.empty()); | 480 EXPECT_TRUE(type.empty()); |
| 506 #endif | 481 #endif |
| 507 } | 482 } |
| 508 | 483 |
| 509 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) { | 484 TEST_F(KeySystemsTest, IsSupportedKeySystem_InvalidVariants) { |
| 510 // Case sensitive. | 485 // Case sensitive. |
| (...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 606 } | 581 } |
| 607 | 582 |
| 608 TEST_F(KeySystemsTest, Parent_ParentRegistered) { | 583 TEST_F(KeySystemsTest, Parent_ParentRegistered) { |
| 609 // Unprefixed has no parent key system support. | 584 // Unprefixed has no parent key system support. |
| 610 EXPECT_FALSE(IsSupportedKeySystem(kExternalParent)); | 585 EXPECT_FALSE(IsSupportedKeySystem(kExternalParent)); |
| 611 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType( | 586 EXPECT_TRUE(PrefixedIsSupportedKeySystemWithMediaMimeType( |
| 612 kVideoWebM, no_codecs(), kExternalParent)); | 587 kVideoWebM, no_codecs(), kExternalParent)); |
| 613 | 588 |
| 614 // The parent is not supported for most things. | 589 // The parent is not supported for most things. |
| 615 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalParent)); | 590 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalParent)); |
| 616 bool result = false; | 591 EXPECT_FALSE(CanUseAesDecryptor(kExternalParent)); |
| 617 EXPECT_DEBUG_DEATH_PORTABLE(result = CanUseAesDecryptor(kExternalParent), | 592 |
| 618 "x-com.example is not a known concrete system"); | |
| 619 EXPECT_FALSE(result); | |
| 620 #if defined(ENABLE_PEPPER_CDMS) | 593 #if defined(ENABLE_PEPPER_CDMS) |
| 621 std::string type; | 594 std::string type; |
| 622 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent), | 595 EXPECT_DEBUG_DEATH(type = GetPepperType(kExternalParent), |
| 623 "x-com.example is not a known concrete system"); | 596 "x-com.example is not a known concrete system"); |
| 624 EXPECT_TRUE(type.empty()); | 597 EXPECT_TRUE(type.empty()); |
| 625 #endif | 598 #endif |
| 626 } | 599 } |
| 627 | 600 |
| 628 TEST_F( | 601 TEST_F( |
| 629 KeySystemsTest, | 602 KeySystemsTest, |
| (...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 846 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else")); | 819 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else")); |
| 847 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other")); | 820 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other")); |
| 848 | 821 |
| 849 EXPECT_FALSE(IsSupportedKeySystem("x-")); | 822 EXPECT_FALSE(IsSupportedKeySystem("x-")); |
| 850 EXPECT_TRUE(IsSupportedKeySystem("x-something")); | 823 EXPECT_TRUE(IsSupportedKeySystem("x-something")); |
| 851 EXPECT_FALSE(IsSupportedKeySystem("x-something.else")); | 824 EXPECT_FALSE(IsSupportedKeySystem("x-something.else")); |
| 852 EXPECT_FALSE(IsSupportedKeySystem("x-other")); | 825 EXPECT_FALSE(IsSupportedKeySystem("x-other")); |
| 853 } | 826 } |
| 854 | 827 |
| 855 } // namespace media | 828 } // namespace media |
| OLD | NEW |