| 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/string16.h" |
| 12 #include "base/strings/string_split.h" |
| 13 #include "base/strings/string_util.h" |
| 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "content/public/common/cdm_service.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" |
| 17 |
| 18 namespace content { |
| 19 |
| 20 const char kTestPath[] = "/aa/bb"; |
| 21 const char kVersion1[] = "1.1.1.1"; |
| 22 const char kVersion2[] = "1.1.1.2"; |
| 23 const char kTestCodecs[] = "webm,mp4"; |
| 24 const char kCodecDelimiter[] = ","; |
| 25 const char kTestInitDataTypes[] = "keyids,cenc,webm"; |
| 26 const char kInitDataTypeDelimiter[] = ","; |
| 27 |
| 28 // For simplicity and to make failures easier to diagnose, this test uses |
| 29 // std::string instead of base::FilePath and std::vector<base::string16>. |
| 30 class CdmServiceTest : public testing::Test { |
| 31 public: |
| 32 CdmServiceTest() {} |
| 33 ~CdmServiceTest() override {} |
| 34 |
| 35 protected: |
| 36 void Register(const std::string& cdm_id, |
| 37 const std::string& version, |
| 38 const std::string& module_library_path, |
| 39 const std::string& supported_codecs, |
| 40 const std::string& supported_init_data_types) { |
| 41 std::vector<base::string16> codecs = |
| 42 base::SplitString(base::ASCIIToUTF16(supported_codecs), |
| 43 base::ASCIIToUTF16(kCodecDelimiter), |
| 44 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 45 std::vector<base::string16> init_data_types = |
| 46 base::SplitString(base::ASCIIToUTF16(supported_init_data_types), |
| 47 base::ASCIIToUTF16(kInitDataTypeDelimiter), |
| 48 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL); |
| 49 CdmService::GetInstance()->Register( |
| 50 cdm_id, version, base::FilePath::FromUTF8Unsafe(module_library_path), |
| 51 codecs, init_data_types); |
| 52 } |
| 53 |
| 54 bool IsRegistered(const std::string& cdm_id, const std::string& version) { |
| 55 for (const auto& cdm : CdmService::GetInstance()->GetAllRegisteredCdms()) { |
| 56 if (cdm.cdm_id == cdm_id && cdm.version == version) |
| 57 return true; |
| 58 } |
| 59 return false; |
| 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(CdmServiceTest, Register) { |
| 68 const char kTestKeySystem[] = "test1"; |
| 69 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs, |
| 70 kTestInitDataTypes); |
| 71 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1)); |
| 72 } |
| 73 |
| 74 TEST_F(CdmServiceTest, ReRegister) { |
| 75 const char kTestKeySystem[] = "test5"; |
| 76 Register(kTestKeySystem, kVersion1, "/bb/cc", "unknown", "cenc"); |
| 77 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1)); |
| 78 |
| 79 // Now register same key system with different values. |
| 80 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs, |
| 81 kTestInitDataTypes); |
| 82 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1)); |
| 83 } |
| 84 |
| 85 TEST_F(CdmServiceTest, MultipleVersions) { |
| 86 const char kTestKeySystem[] = "test8"; |
| 87 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs, |
| 88 kTestInitDataTypes); |
| 89 Register(kTestKeySystem, kVersion2, "/bb/cc", "unknown", "cenc"); |
| 90 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1)); |
| 91 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion2)); |
| 92 } |
| 93 |
| 94 } // namespace content |
| OLD | NEW |