| 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" |
| 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[] = "webm,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& name, |
| 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( |
| 41 CdmInfo(name, base::Version(version), |
| 42 base::FilePath::FromUTF8Unsafe(path), codecs), |
| 43 true); |
| 44 } |
| 45 |
| 46 bool IsRegistered(const std::string& name, const std::string& version) { |
| 47 for (const auto& cdm : CdmService::GetInstance()->GetAllRegisteredCdms()) { |
| 48 if (cdm.name == name && cdm.version.GetString() == version) |
| 49 return true; |
| 50 } |
| 51 return false; |
| 52 } |
| 53 }; |
| 54 |
| 55 // Note that KeySystemService is a singleton, and thus the actions of |
| 56 // one test impact other tests. So each test defines a different key system |
| 57 // name to avoid conflicts. |
| 58 |
| 59 TEST_F(CdmServiceImplTest, Register) { |
| 60 const char kTestKeySystem[] = "test1"; |
| 61 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs); |
| 62 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1)); |
| 63 } |
| 64 |
| 65 TEST_F(CdmServiceImplTest, ReRegister) { |
| 66 const char kTestKeySystem[] = "test5"; |
| 67 Register(kTestKeySystem, kVersion1, "/bb/cc", "unknown"); |
| 68 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1)); |
| 69 |
| 70 // Now register same key system with different values. |
| 71 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs); |
| 72 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1)); |
| 73 } |
| 74 |
| 75 TEST_F(CdmServiceImplTest, MultipleVersions) { |
| 76 const char kTestKeySystem[] = "test8"; |
| 77 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs); |
| 78 Register(kTestKeySystem, kVersion2, "/bb/cc", "unknown"); |
| 79 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1)); |
| 80 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion2)); |
| 81 } |
| 82 |
| 83 } // namespace content |
| OLD | NEW |