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

Unified Diff: content/browser/media/cdm_service_impl_unittest.cc

Issue 1637083002: Add CdmService to keep track of CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: changes + file move Created 4 years, 9 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/browser/media/cdm_service_impl_unittest.cc
diff --git a/content/browser/media/cdm_service_impl_unittest.cc b/content/browser/media/cdm_service_impl_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..9acd8af0a28faa247ed1d96dbcf1ec4dec4faacc
--- /dev/null
+++ b/content/browser/media/cdm_service_impl_unittest.cc
@@ -0,0 +1,83 @@
+// 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/string_split.h"
+#include "base/strings/string_util.h"
+#include "base/strings/utf_string_conversions.h"
+#include "content/browser/media/cdm_service_impl.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[] = ",";
+
+// For simplicity and to make failures easier to diagnose, this test uses
+// std::string instead of base::FilePath and std::vector<std::string>.
+class CdmServiceImplTest : public testing::Test {
+ public:
+ CdmServiceImplTest() {}
+ ~CdmServiceImplTest() override {}
+
+ protected:
+ void Register(const std::string& name,
+ const std::string& version,
+ const std::string& path,
+ const std::string& supported_codecs) {
+ std::vector<std::string> codecs =
+ base::SplitString(supported_codecs, kCodecDelimiter,
+ base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
+ CdmService::GetInstance()->RegisterCdm(
+ CdmInfo(name, base::Version(version),
+ base::FilePath::FromUTF8Unsafe(path), codecs),
+ true);
+ }
+
+ bool IsRegistered(const std::string& name, const std::string& version) {
+ for (const auto& cdm : CdmService::GetInstance()->GetAllRegisteredCdms()) {
+ if (cdm.name == name && cdm.version.GetString() == version)
+ return true;
+ }
+ return false;
+ }
+};
+
+// 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(CdmServiceImplTest, Register) {
+ const char kTestKeySystem[] = "test1";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs);
+ EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
+}
+
+TEST_F(CdmServiceImplTest, ReRegister) {
+ const char kTestKeySystem[] = "test5";
+ Register(kTestKeySystem, kVersion1, "/bb/cc", "unknown");
+ EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
+
+ // Now register same key system with different values.
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs);
+ EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
+}
+
+TEST_F(CdmServiceImplTest, MultipleVersions) {
+ const char kTestKeySystem[] = "test8";
+ Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs);
+ Register(kTestKeySystem, kVersion2, "/bb/cc", "unknown");
+ EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
+ EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion2));
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698