| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/browser/media/cdm_service_impl.h" | 5 #include "content/browser/media/cdm_registry_impl.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "base/base_paths.h" | 11 #include "base/base_paths.h" |
| 12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
| 13 #include "base/strings/string_split.h" | 13 #include "base/strings/string_split.h" |
| 14 #include "base/strings/string_util.h" | 14 #include "base/strings/string_util.h" |
| 15 #include "base/strings/utf_string_conversions.h" | 15 #include "base/strings/utf_string_conversions.h" |
| 16 #include "base/version.h" | 16 #include "base/version.h" |
| 17 #include "content/public/common/cdm_info.h" | 17 #include "content/public/common/cdm_info.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 19 |
| 20 namespace content { | 20 namespace content { |
| 21 | 21 |
| 22 const char kTestKeySystemType[] = "test"; | 22 const char kTestKeySystemType[] = "test"; |
| 23 const char kTestPath[] = "/aa/bb"; | 23 const char kTestPath[] = "/aa/bb"; |
| 24 const char kVersion1[] = "1.1.1.1"; | 24 const char kVersion1[] = "1.1.1.1"; |
| 25 const char kVersion2[] = "1.1.1.2"; | 25 const char kVersion2[] = "1.1.1.2"; |
| 26 const char kTestCodecs[] = "vp9,mp4"; | 26 const char kTestCodecs[] = "vp9,mp4"; |
| 27 const char kCodecDelimiter[] = ","; | 27 const char kCodecDelimiter[] = ","; |
| 28 | 28 |
| 29 // For simplicity and to make failures easier to diagnose, this test uses | 29 // For simplicity and to make failures easier to diagnose, this test uses |
| 30 // std::string instead of base::FilePath and std::vector<std::string>. | 30 // std::string instead of base::FilePath and std::vector<std::string>. |
| 31 class CdmServiceImplTest : public testing::Test { | 31 class CdmRegistryImplTest : public testing::Test { |
| 32 public: | 32 public: |
| 33 CdmServiceImplTest() {} | 33 CdmRegistryImplTest() {} |
| 34 ~CdmServiceImplTest() override {} | 34 ~CdmRegistryImplTest() override {} |
| 35 | 35 |
| 36 protected: | 36 protected: |
| 37 void Register(const std::string& type, | 37 void Register(const std::string& type, |
| 38 const std::string& version, | 38 const std::string& version, |
| 39 const std::string& path, | 39 const std::string& path, |
| 40 const std::string& supported_codecs) { | 40 const std::string& supported_codecs) { |
| 41 const std::vector<std::string> codecs = | 41 const std::vector<std::string> codecs = |
| 42 base::SplitString(supported_codecs, kCodecDelimiter, | 42 base::SplitString(supported_codecs, kCodecDelimiter, |
| 43 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); | 43 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 44 cdm_service_.RegisterCdm(CdmInfo(type, base::Version(version), | 44 cdm_registry_.RegisterCdm(CdmInfo(type, base::Version(version), |
| 45 base::FilePath::FromUTF8Unsafe(path), | 45 base::FilePath::FromUTF8Unsafe(path), |
| 46 codecs)); | 46 codecs)); |
| 47 } | 47 } |
| 48 | 48 |
| 49 bool IsRegistered(const std::string& type, const std::string& version) { | 49 bool IsRegistered(const std::string& type, const std::string& version) { |
| 50 for (const auto& cdm : cdm_service_.GetAllRegisteredCdms()) { | 50 for (const auto& cdm : cdm_registry_.GetAllRegisteredCdms()) { |
| 51 if (cdm.type == type && cdm.version.GetString() == version) | 51 if (cdm.type == type && cdm.version.GetString() == version) |
| 52 return true; | 52 return true; |
| 53 } | 53 } |
| 54 return false; | 54 return false; |
| 55 } | 55 } |
| 56 | 56 |
| 57 std::vector<std::string> GetVersions(const std::string& type) { | 57 std::vector<std::string> GetVersions(const std::string& type) { |
| 58 std::vector<std::string> versions; | 58 std::vector<std::string> versions; |
| 59 for (const auto& cdm : cdm_service_.GetAllRegisteredCdms()) { | 59 for (const auto& cdm : cdm_registry_.GetAllRegisteredCdms()) { |
| 60 if (cdm.type == type) | 60 if (cdm.type == type) |
| 61 versions.push_back(cdm.version.GetString()); | 61 versions.push_back(cdm.version.GetString()); |
| 62 } | 62 } |
| 63 return versions; | 63 return versions; |
| 64 } | 64 } |
| 65 | 65 |
| 66 private: | 66 private: |
| 67 CdmServiceImpl cdm_service_; | 67 CdmRegistryImpl cdm_registry_; |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 // Note that KeySystemService is a singleton, and thus the actions of | 70 // Note that KeySystemService is a singleton, and thus the actions of |
| 71 // one test impact other tests. So each test defines a different key system | 71 // one test impact other tests. So each test defines a different key system |
| 72 // name to avoid conflicts. | 72 // name to avoid conflicts. |
| 73 | 73 |
| 74 TEST_F(CdmServiceImplTest, Register) { | 74 TEST_F(CdmRegistryImplTest, Register) { |
| 75 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs); | 75 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs); |
| 76 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1)); | 76 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1)); |
| 77 } | 77 } |
| 78 | 78 |
| 79 TEST_F(CdmServiceImplTest, ReRegister) { | 79 TEST_F(CdmRegistryImplTest, ReRegister) { |
| 80 Register(kTestKeySystemType, kVersion1, "/bb/cc", "unknown"); | 80 Register(kTestKeySystemType, kVersion1, "/bb/cc", "unknown"); |
| 81 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1)); | 81 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1)); |
| 82 | 82 |
| 83 // Now register same key system with different values. | 83 // Now register same key system with different values. |
| 84 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs); | 84 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs); |
| 85 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1)); | 85 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1)); |
| 86 } | 86 } |
| 87 | 87 |
| 88 TEST_F(CdmServiceImplTest, MultipleVersions) { | 88 TEST_F(CdmRegistryImplTest, MultipleVersions) { |
| 89 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs); | 89 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs); |
| 90 Register(kTestKeySystemType, kVersion2, "/bb/cc", "unknown"); | 90 Register(kTestKeySystemType, kVersion2, "/bb/cc", "unknown"); |
| 91 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1)); | 91 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1)); |
| 92 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion2)); | 92 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion2)); |
| 93 } | 93 } |
| 94 | 94 |
| 95 TEST_F(CdmServiceImplTest, NewVersionInsertedFirst) { | 95 TEST_F(CdmRegistryImplTest, NewVersionInsertedFirst) { |
| 96 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs); | 96 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs); |
| 97 Register(kTestKeySystemType, kVersion2, "/bb/cc", "unknown"); | 97 Register(kTestKeySystemType, kVersion2, "/bb/cc", "unknown"); |
| 98 | 98 |
| 99 const std::vector<std::string> versions = GetVersions(kTestKeySystemType); | 99 const std::vector<std::string> versions = GetVersions(kTestKeySystemType); |
| 100 EXPECT_EQ(2u, versions.size()); | 100 EXPECT_EQ(2u, versions.size()); |
| 101 EXPECT_EQ(kVersion2, versions[0]); | 101 EXPECT_EQ(kVersion2, versions[0]); |
| 102 EXPECT_EQ(kVersion1, versions[1]); | 102 EXPECT_EQ(kVersion1, versions[1]); |
| 103 } | 103 } |
| 104 | 104 |
| 105 } // namespace content | 105 } // namespace content |
| OLD | NEW |