| Index: content/common/media/cdm_service_unittest.cc
|
| diff --git a/content/common/media/cdm_service_unittest.cc b/content/common/media/cdm_service_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d8852a617f38c76737fbd86b7d60070eb6a1679f
|
| --- /dev/null
|
| +++ b/content/common/media/cdm_service_unittest.cc
|
| @@ -0,0 +1,94 @@
|
| +// 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/cdm_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>.
|
| +class CdmServiceTest : public testing::Test {
|
| + public:
|
| + CdmServiceTest() {}
|
| + ~CdmServiceTest() override {}
|
| +
|
| + protected:
|
| + void Register(const std::string& cdm_id,
|
| + 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);
|
| + CdmService::GetInstance()->Register(
|
| + cdm_id, version, base::FilePath::FromUTF8Unsafe(module_library_path),
|
| + codecs, init_data_types);
|
| + }
|
| +
|
| + bool IsRegistered(const std::string& cdm_id, const std::string& version) {
|
| + for (const auto& cdm : CdmService::GetInstance()->GetAllRegisteredCdms()) {
|
| + if (cdm.cdm_id == cdm_id && cdm.version == 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(CdmServiceTest, Register) {
|
| + const char kTestKeySystem[] = "test1";
|
| + Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
|
| + kTestInitDataTypes);
|
| + EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
|
| +}
|
| +
|
| +TEST_F(CdmServiceTest, ReRegister) {
|
| + const char kTestKeySystem[] = "test5";
|
| + Register(kTestKeySystem, kVersion1, "/bb/cc", "unknown", "cenc");
|
| + EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
|
| +
|
| + // Now register same key system with different values.
|
| + Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
|
| + kTestInitDataTypes);
|
| + EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
|
| +}
|
| +
|
| +TEST_F(CdmServiceTest, MultipleVersions) {
|
| + const char kTestKeySystem[] = "test8";
|
| + Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs,
|
| + kTestInitDataTypes);
|
| + Register(kTestKeySystem, kVersion2, "/bb/cc", "unknown", "cenc");
|
| + EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
|
| + EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion2));
|
| +}
|
| +
|
| +} // namespace content
|
|
|