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