| 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
|
|
|