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

Unified Diff: content/common/media/content_decryption_module_service_unittest.cc

Issue 1637083002: Add CdmService to keep track of CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: ContentDecryptionModule Created 4 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 side-by-side diff with in-line comments
Download patch
Index: content/common/media/content_decryption_module_service_unittest.cc
diff --git a/content/common/media/content_decryption_module_service_unittest.cc b/content/common/media/content_decryption_module_service_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..bd070c14146a7c5af36e574311228ff8002dc9fa
--- /dev/null
+++ b/content/common/media/content_decryption_module_service_unittest.cc
@@ -0,0 +1,250 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include <algorithm>
+#include <string>
+#include <vector>
+
+#include "base/base_paths.h"
+#include "base/files/file_path.h"
+#include "base/strings/string16.h"
+#include "base/strings/string_split.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/public/common/content_decryption_module_service.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+const char kTestPath[] = "/aa/bb";
+const char kVersion1[] = "1.1.1.1";
+const char kVersion2[] = "1.1.1.2";
+const char kTestCodecs[] = "webm,mp4";
+const char kCodecDelimiter[] = ",";
+const char kTestInitDataTypes[] = "keyids,cenc,webm";
+const char kInitDataTypeDelimiter[] = ",";
+
+// For simplicity and to make failures easier to diagnose, this test uses
+// std::string instead of base::FilePath and std::vector<base::string16>
+// for module_library_path and supported_codecs, respectively.
+class ContentDecryptionModuleServiceTest : public testing::Test {
+ public:
+ ContentDecryptionModuleServiceTest() {}
+ ~ContentDecryptionModuleServiceTest() override {}
+
+ protected:
+ void Register(const std::string& key_system,
+ const std::string& version,
+ const std::string& module_library_path,
+ const std::string& supported_codecs,
+ const std::string& supported_init_data_types) {
+ std::vector<base::string16> codecs =
+ base::SplitString(base::ASCIIToUTF16(supported_codecs),
+ base::ASCIIToUTF16(kCodecDelimiter),
+ base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
+ std::vector<base::string16> init_data_types =
+ base::SplitString(base::ASCIIToUTF16(supported_init_data_types),
+ base::ASCIIToUTF16(kInitDataTypeDelimiter),
+ base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
+ ContentDecryptionModuleService::GetInstance()->Register(
+ key_system, version,
+ base::FilePath::FromUTF8Unsafe(module_library_path), codecs,
+ init_data_types);
+ }
+
+ bool PathDefined(const std::string& key_system, const std::string& version) {
+ base::FilePath module_library_path;
+ return ContentDecryptionModuleService::GetInstance()->GetCdmLibraryPath(
+ key_system, version, &module_library_path);
+ }
+
+ std::string Path(const std::string& key_system, const std::string& version) {
+ base::FilePath module_library_path;
+ EXPECT_TRUE(
+ ContentDecryptionModuleService::GetInstance()->GetCdmLibraryPath(
+ key_system, version, &module_library_path));
+ return module_library_path.AsUTF8Unsafe();
+ }
+
+ bool CodecsDefined(const std::string& key_system,
+ const std::string& version) {
+ std::vector<base::string16> supported_codecs;
+ return ContentDecryptionModuleService::GetInstance()->GetSupportedCodecs(
+ key_system, version, &supported_codecs);
+ }
+
+ std::string Codecs(const std::string& key_system,
+ const std::string& version) {
+ std::vector<base::string16> supported_codecs;
+ EXPECT_TRUE(
+ ContentDecryptionModuleService::GetInstance()->GetSupportedCodecs(
+ key_system, version, &supported_codecs));
+ return base::UTF16ToASCII(base::JoinString(
+ supported_codecs, base::ASCIIToUTF16(kCodecDelimiter)));
+ }
+
+ bool InitDataTypesDefined(const std::string& key_system,
+ const std::string& version) {
+ std::vector<base::string16> supported_init_data_types;
+ return ContentDecryptionModuleService::GetInstance()
+ ->GetSupportedInitDataTypes(key_system, version,
+ &supported_init_data_types);
+ }
+
+ std::string InitDataTypes(const std::string& key_system,
+ const std::string& version) {
+ std::vector<base::string16> supported_init_data_types;
+ EXPECT_TRUE(ContentDecryptionModuleService::GetInstance()
+ ->GetSupportedInitDataTypes(key_system, version,
+ &supported_init_data_types));
+ return base::UTF16ToASCII(base::JoinString(
+ supported_init_data_types, base::ASCIIToUTF16(kInitDataTypeDelimiter)));
+ }
+
+ void GetAllRegisteredKeySystems(
+ std::vector<std::pair<std::string, std::string>>* key_systems) {
+ std::vector<std::pair<std::string, base::FilePath>> registered_key_systems;
+ ContentDecryptionModuleService::GetInstance()->GetAllRegisteredModules(
+ &registered_key_systems);
+ for (const auto& key_system : registered_key_systems)
+ key_systems->push_back(
+ std::make_pair(key_system.first, key_system.second.AsUTF8Unsafe()));
+ }
+};
+
+// Note that KeySystemService is a singleton, and thus the actions of
+// one test impact other tests. So each test defines a different key system
+// name to avoid conflicts.
+
+TEST_F(ContentDecryptionModuleServiceTest, Register) {
+ const char kTestKeySystem[] = "test1";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ EXPECT_TRUE(PathDefined(kTestKeySystem, kVersion1));
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, kVersion1));
+}
+
+TEST_F(ContentDecryptionModuleServiceTest, Path) {
+ const char kTestKeySystem[] = "test2";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ EXPECT_TRUE(PathDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(Path(kTestKeySystem, kVersion1), kTestPath);
+}
+
+TEST_F(ContentDecryptionModuleServiceTest, Codecs) {
+ const char kTestKeySystem[] = "test3";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(Codecs(kTestKeySystem, kVersion1), kTestCodecs);
+}
+
+TEST_F(ContentDecryptionModuleServiceTest, InitDataTypes) {
+ const char kTestKeySystem[] = "test4";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ EXPECT_TRUE(InitDataTypesDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(InitDataTypes(kTestKeySystem, kVersion1), kTestInitDataTypes);
+}
+
+TEST_F(ContentDecryptionModuleServiceTest, ReRegister) {
+ const char kTestKeySystem[] = "test5";
+ Register(kTestKeySystem, kVersion1, "/bb/cc", "unknown", "cenc");
+ EXPECT_TRUE(PathDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(Path(kTestKeySystem, kVersion1), "/bb/cc");
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(Codecs(kTestKeySystem, kVersion1), "unknown");
+ EXPECT_TRUE(InitDataTypesDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(InitDataTypes(kTestKeySystem, kVersion1), "cenc");
+
+ // Now register same key system with different values.
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ EXPECT_TRUE(PathDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(Path(kTestKeySystem, kVersion1), kTestPath);
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(Codecs(kTestKeySystem, kVersion1), kTestCodecs);
+ EXPECT_TRUE(InitDataTypesDefined(kTestKeySystem, kVersion1));
+ EXPECT_EQ(InitDataTypes(kTestKeySystem, kVersion1), kTestInitDataTypes);
+}
+
+TEST_F(ContentDecryptionModuleServiceTest, DifferentVersions) {
+ const char kTestKeySystem[] = "test6";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ EXPECT_TRUE(PathDefined(kTestKeySystem, kVersion1));
+ EXPECT_FALSE(PathDefined(kTestKeySystem, kVersion2));
+ EXPECT_EQ(Path(kTestKeySystem, kVersion1), kTestPath);
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, kVersion1));
+ EXPECT_FALSE(CodecsDefined(kTestKeySystem, kVersion2));
+ EXPECT_EQ(Codecs(kTestKeySystem, kVersion1), kTestCodecs);
+ EXPECT_TRUE(InitDataTypesDefined(kTestKeySystem, kVersion1));
+ EXPECT_FALSE(InitDataTypesDefined(kTestKeySystem, kVersion2));
+ EXPECT_EQ(InitDataTypes(kTestKeySystem, kVersion1), kTestInitDataTypes);
+}
+
+TEST_F(ContentDecryptionModuleServiceTest, LatestVersion) {
+ const char kTestKeySystem[] = "test7";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ EXPECT_TRUE(PathDefined(kTestKeySystem, std::string()));
+ EXPECT_EQ(Path(kTestKeySystem, std::string()), kTestPath);
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, std::string()));
+ EXPECT_EQ(Codecs(kTestKeySystem, std::string()), kTestCodecs);
+ EXPECT_TRUE(InitDataTypesDefined(kTestKeySystem, std::string()));
+ EXPECT_EQ(InitDataTypes(kTestKeySystem, std::string()), kTestInitDataTypes);
+}
+
+TEST_F(ContentDecryptionModuleServiceTest, MultipleVersions) {
+ const char kTestKeySystem[] = "test8";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ Register(kTestKeySystem, kVersion2, "/bb/cc", "unknown", "cenc");
+
+ EXPECT_TRUE(PathDefined(kTestKeySystem, kVersion1));
+ EXPECT_TRUE(PathDefined(kTestKeySystem, kVersion2));
+ EXPECT_TRUE(PathDefined(kTestKeySystem, std::string()));
+ EXPECT_EQ(Path(kTestKeySystem, kVersion1), kTestPath);
+ EXPECT_EQ(Path(kTestKeySystem, kVersion2), "/bb/cc");
+ EXPECT_EQ(Path(kTestKeySystem, std::string()), "/bb/cc");
+
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, kVersion1));
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, kVersion2));
+ EXPECT_TRUE(CodecsDefined(kTestKeySystem, std::string()));
+ EXPECT_EQ(Codecs(kTestKeySystem, kVersion1), kTestCodecs);
+ EXPECT_EQ(Codecs(kTestKeySystem, kVersion2), "unknown");
+ EXPECT_EQ(Codecs(kTestKeySystem, std::string()), "unknown");
+
+ EXPECT_TRUE(InitDataTypesDefined(kTestKeySystem, kVersion1));
+ EXPECT_TRUE(InitDataTypesDefined(kTestKeySystem, kVersion2));
+ EXPECT_TRUE(InitDataTypesDefined(kTestKeySystem, std::string()));
+ EXPECT_EQ(InitDataTypes(kTestKeySystem, kVersion1), kTestInitDataTypes);
+ EXPECT_EQ(InitDataTypes(kTestKeySystem, kVersion2), "cenc");
+ EXPECT_EQ(InitDataTypes(kTestKeySystem, std::string()), "cenc");
+}
+
+TEST_F(ContentDecryptionModuleServiceTest, RegisteredKeySystems) {
+ const char kTestKeySystem[] = "test9";
+ const char kDifferentTestPath[] = "/cc/dd";
+ std::vector<std::pair<std::string, std::string>> key_systems;
+
+ Register(kTestKeySystem, kVersion1, kDifferentTestPath, kTestCodecs,
+ kTestInitDataTypes);
+ GetAllRegisteredKeySystems(&key_systems);
+ EXPECT_GT(key_systems.size(), 0u);
+
+ // Verify |kTestKeySystem| and |kDifferentTestPath| is in the returned data.
+ bool found = false;
+ for (const auto& key_system : key_systems) {
+ if (key_system.first == kTestKeySystem) {
+ EXPECT_EQ(key_system.second, kDifferentTestPath);
+ found = true;
+ break;
+ }
+ }
+ EXPECT_EQ(found, true);
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698