| Index: content/common/media/key_system_service_unittest.cc
|
| diff --git a/content/common/media/key_system_service_unittest.cc b/content/common/media/key_system_service_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8d6fc90c0df562b8feecbb2cb35394026ce02280
|
| --- /dev/null
|
| +++ b/content/common/media/key_system_service_unittest.cc
|
| @@ -0,0 +1,135 @@
|
| +// 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/utf_string_conversions.h"
|
| +#include "content/public/common/key_system_service.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +
|
| +namespace content {
|
| +
|
| +const char kTestPath[] = "/aa/bb";
|
| +const char kTestCodecs[] = "webm,mp4";
|
| +
|
| +class KeySystemServiceTest : public testing::Test {
|
| + public:
|
| + KeySystemServiceTest() {}
|
| + ~KeySystemServiceTest() override {}
|
| +
|
| + protected:
|
| + void Register(const std::string& key_system,
|
| + const std::string& path,
|
| + const std::string& codecs) {
|
| + KeySystemService::GetInstance()->Register(
|
| + key_system, base::FilePath::FromUTF8Unsafe(path),
|
| + base::ASCIIToUTF16(codecs));
|
| + }
|
| +
|
| + bool PathDefined(const std::string& key_system) {
|
| + base::FilePath path;
|
| + return KeySystemService::GetInstance()->Path(key_system, &path);
|
| + }
|
| +
|
| + std::string Path(const std::string& key_system) {
|
| + base::FilePath path;
|
| + EXPECT_TRUE(KeySystemService::GetInstance()->Path(key_system, &path));
|
| + return path.AsUTF8Unsafe();
|
| + }
|
| +
|
| + bool CodecsDefined(const std::string& key_system) {
|
| + base::string16 codecs;
|
| + return KeySystemService::GetInstance()->Codecs(key_system, &codecs);
|
| + }
|
| +
|
| + std::string Codecs(const std::string& key_system) {
|
| + base::string16 codecs;
|
| + EXPECT_TRUE(KeySystemService::GetInstance()->Codecs(key_system, &codecs));
|
| + return base::UTF16ToASCII(codecs);
|
| + }
|
| +
|
| + void GetAllRegisteredKeySystems(std::vector<std::string>* key_systems,
|
| + std::vector<std::string>* paths) {
|
| + std::vector<base::FilePath> file_paths;
|
| + KeySystemService::GetInstance()->GetAllRegisteredKeySystems(key_systems,
|
| + &file_paths);
|
| + for (const auto& path : file_paths)
|
| + paths->push_back(path.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(KeySystemServiceTest, Register) {
|
| + const char kTestKeySystem[] = "test1";
|
| + Register(kTestKeySystem, kTestPath, kTestCodecs);
|
| + EXPECT_TRUE(PathDefined(kTestKeySystem));
|
| + EXPECT_TRUE(CodecsDefined(kTestKeySystem));
|
| +}
|
| +
|
| +TEST_F(KeySystemServiceTest, Path) {
|
| + const char kTestKeySystem[] = "test2";
|
| + Register(kTestKeySystem, kTestPath, kTestCodecs);
|
| + EXPECT_TRUE(PathDefined(kTestKeySystem));
|
| + EXPECT_EQ(Path(kTestKeySystem), kTestPath);
|
| +}
|
| +
|
| +TEST_F(KeySystemServiceTest, Codecs) {
|
| + const char kTestKeySystem[] = "test3";
|
| + Register(kTestKeySystem, kTestPath, kTestCodecs);
|
| + EXPECT_TRUE(CodecsDefined(kTestKeySystem));
|
| + EXPECT_EQ(Codecs(kTestKeySystem), kTestCodecs);
|
| +}
|
| +
|
| +TEST_F(KeySystemServiceTest, ReRegister) {
|
| + const char kTestKeySystem[] = "test4";
|
| + Register(kTestKeySystem, "/bb/cc", "unknown");
|
| + EXPECT_TRUE(PathDefined(kTestKeySystem));
|
| + EXPECT_EQ(Path(kTestKeySystem), "/bb/cc");
|
| + EXPECT_TRUE(CodecsDefined(kTestKeySystem));
|
| + EXPECT_EQ(Codecs(kTestKeySystem), "unknown");
|
| +
|
| + // Now register same key system with different values.
|
| + Register(kTestKeySystem, kTestPath, kTestCodecs);
|
| + EXPECT_TRUE(PathDefined(kTestKeySystem));
|
| + EXPECT_EQ(Path(kTestKeySystem), kTestPath);
|
| + EXPECT_TRUE(CodecsDefined(kTestKeySystem));
|
| + EXPECT_EQ(Codecs(kTestKeySystem), kTestCodecs);
|
| +}
|
| +
|
| +TEST_F(KeySystemServiceTest, RegisteredKeySystems) {
|
| + const char kTestKeySystem[] = "test5";
|
| + const char kDifferentTestPath[] = "/cc/dd";
|
| + std::vector<std::string> key_systems;
|
| + std::vector<std::string> paths;
|
| +
|
| + Register(kTestKeySystem, kDifferentTestPath, kTestCodecs);
|
| + GetAllRegisteredKeySystems(&key_systems, &paths);
|
| + EXPECT_GT(key_systems.size(), 0u);
|
| + EXPECT_GT(paths.size(), 0u);
|
| + EXPECT_EQ(key_systems.size(), paths.size());
|
| +
|
| + // Verify |kTestKeySystem| and |kDifferentTestPath| is in the returned data.
|
| + EXPECT_NE(std::find(key_systems.begin(), key_systems.end(), kTestKeySystem),
|
| + key_systems.end());
|
| + EXPECT_NE(std::find(paths.begin(), paths.end(), kDifferentTestPath),
|
| + paths.end());
|
| +
|
| + // Locate |kTestKeySystem| in |key_systems| and verify that the matching
|
| + // |kDifferentTestPath| is in the corresponding location in |paths|.
|
| + for (size_t i = 0; i < key_systems.size(); i++) {
|
| + if (key_systems[i] == kTestKeySystem) {
|
| + EXPECT_EQ(paths[i], kDifferentTestPath);
|
| + }
|
| + }
|
| +}
|
| +
|
| +} // namespace content
|
|
|