diff options
Diffstat (limited to 'chromium/content/browser/media/key_system_support_impl_unittest.cc')
-rw-r--r-- | chromium/content/browser/media/key_system_support_impl_unittest.cc | 92 |
1 files changed, 52 insertions, 40 deletions
diff --git a/chromium/content/browser/media/key_system_support_impl_unittest.cc b/chromium/content/browser/media/key_system_support_impl_unittest.cc index aa3134ae60e..8ba04e3e867 100644 --- a/chromium/content/browser/media/key_system_support_impl_unittest.cc +++ b/chromium/content/browser/media/key_system_support_impl_unittest.cc @@ -22,11 +22,35 @@ namespace content { namespace { +using VideoCodec = media::VideoCodec; +using EncryptionMode = media::EncryptionMode; +using CdmSessionType = media::CdmSessionType; + const char kTestCdmGuid[] = "62FE9C4B-384E-48FD-B28A-9F6F248BC8CC"; const char kVersion[] = "1.1.1.1"; const char kTestPath[] = "/aa/bb"; const char kTestFileSystemId[] = "file_system_id"; +// Helper function to compare a STL container to an initializer_list. +template <typename Container, typename T> +bool StlEquals(const Container a, std::initializer_list<T> b) { + return a == Container(b); +} + +#define EXPECT_STL_EQ(a, ...) \ + do { \ + EXPECT_TRUE(StlEquals(a, {__VA_ARGS__})); \ + } while (false) + +#define EXPECT_VIDEO_CODECS(...) \ + EXPECT_STL_EQ(capability_->video_codecs, __VA_ARGS__) + +#define EXPECT_ENCRYPTION_SCHEMES(...) \ + EXPECT_STL_EQ(capability_->encryption_schemes, __VA_ARGS__) + +#define EXPECT_SESSION_TYPES(...) \ + EXPECT_STL_EQ(capability_->session_types, __VA_ARGS__) + } // namespace class KeySystemSupportTest : public testing::Test { @@ -36,20 +60,24 @@ class KeySystemSupportTest : public testing::Test { KeySystemSupportImpl::Create(mojo::MakeRequest(&key_system_support_)); } - // Registers |key_system| with |supported_video_codecs| and - // |supports_persistent_license|. All other values for CdmInfo have some - // default value as they're not returned by IsKeySystemSupported(). - void Register(const std::string& key_system, - const std::vector<media::VideoCodec>& supported_video_codecs, - bool supports_persistent_license, - const base::flat_set<media::EncryptionMode>& supported_modes) { + // TODO(xhwang): Add tests for hardware secure video codecs and encryption + // schemes. + CdmCapability GetTestCdmCapability() { + return CdmCapability( + {VideoCodec::kCodecVP8, VideoCodec::kCodecVP9}, + {EncryptionMode::kCenc, EncryptionMode::kCbcs}, + {CdmSessionType::kTemporary, CdmSessionType::kPersistentLicense}, {}); + } + + // Registers |key_system| with |capability|. All other values for CdmInfo have + // some default value as they're not returned by IsKeySystemSupported(). + void Register(const std::string& key_system, CdmCapability capability) { DVLOG(1) << __func__; CdmRegistry::GetInstance()->RegisterCdm( CdmInfo(key_system, kTestCdmGuid, base::Version(kVersion), base::FilePath::FromUTF8Unsafe(kTestPath), kTestFileSystemId, - supported_video_codecs, supports_persistent_license, - supported_modes, key_system, false)); + std::move(capability), key_system, false)); } // Determines if |key_system| is registered. If it is, updates |codecs_| @@ -58,8 +86,7 @@ class KeySystemSupportTest : public testing::Test { DVLOG(1) << __func__; bool is_available = false; key_system_support_->IsKeySystemSupported(key_system, &is_available, - &codecs_, &persistent_, - &encryption_schemes_); + &capability_); return is_available; } @@ -67,9 +94,7 @@ class KeySystemSupportTest : public testing::Test { TestBrowserThreadBundle test_browser_thread_bundle_; // Updated by IsSupported(). - std::vector<media::VideoCodec> codecs_; - bool persistent_; - std::vector<media::EncryptionMode> encryption_schemes_; + media::mojom::KeySystemCapabilityPtr capability_; }; // Note that as CdmRegistry::GetInstance() is a static, it is shared between @@ -78,45 +103,32 @@ class KeySystemSupportTest : public testing::Test { TEST_F(KeySystemSupportTest, NoKeySystems) { EXPECT_FALSE(IsSupported("KeySystem1")); + EXPECT_FALSE(capability_); } TEST_F(KeySystemSupportTest, OneKeySystem) { - Register("KeySystem2", {media::VideoCodec::kCodecVP8}, true, - {media::EncryptionMode::kCenc, media::EncryptionMode::kCbcs}); + Register("KeySystem2", GetTestCdmCapability()); + EXPECT_TRUE(IsSupported("KeySystem2")); - EXPECT_EQ(1u, codecs_.size()); - EXPECT_EQ(media::VideoCodec::kCodecVP8, codecs_[0]); - EXPECT_TRUE(persistent_); - EXPECT_EQ(2u, encryption_schemes_.size()); - EXPECT_EQ(media::EncryptionMode::kCenc, encryption_schemes_[0]); - EXPECT_EQ(media::EncryptionMode::kCbcs, encryption_schemes_[1]); + EXPECT_VIDEO_CODECS(VideoCodec::kCodecVP8, VideoCodec::kCodecVP9); + EXPECT_ENCRYPTION_SCHEMES(EncryptionMode::kCenc, EncryptionMode::kCbcs); + EXPECT_SESSION_TYPES(CdmSessionType::kTemporary, + CdmSessionType::kPersistentLicense); } TEST_F(KeySystemSupportTest, MultipleKeySystems) { - Register("KeySystem3", - {media::VideoCodec::kCodecVP8, media::VideoCodec::kCodecVP9}, true, - {media::EncryptionMode::kCenc}); - Register("KeySystem4", {media::VideoCodec::kCodecVP9}, false, - {media::EncryptionMode::kCbcs}); + Register("KeySystem3", GetTestCdmCapability()); + Register("KeySystem4", GetTestCdmCapability()); + EXPECT_TRUE(IsSupported("KeySystem3")); - EXPECT_EQ(2u, codecs_.size()); - EXPECT_EQ(media::VideoCodec::kCodecVP8, codecs_[0]); - EXPECT_EQ(media::VideoCodec::kCodecVP9, codecs_[1]); - EXPECT_TRUE(persistent_); - EXPECT_EQ(1u, encryption_schemes_.size()); - EXPECT_EQ(media::EncryptionMode::kCenc, encryption_schemes_[0]); EXPECT_TRUE(IsSupported("KeySystem4")); - EXPECT_EQ(1u, codecs_.size()); - EXPECT_EQ(media::VideoCodec::kCodecVP9, codecs_[0]); - EXPECT_FALSE(persistent_); - EXPECT_EQ(1u, encryption_schemes_.size()); - EXPECT_EQ(media::EncryptionMode::kCbcs, encryption_schemes_[0]); } TEST_F(KeySystemSupportTest, MissingKeySystem) { - Register("KeySystem5", {media::VideoCodec::kCodecVP8}, true, - {media::EncryptionMode::kCenc}); + Register("KeySystem5", GetTestCdmCapability()); + EXPECT_FALSE(IsSupported("KeySystem6")); + EXPECT_FALSE(capability_); } } // namespace content |