Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(269)

Side by Side Diff: content/browser/media/cdm_service_impl_unittest.cc

Issue 1637083002: Add CdmService to keep track of CDMs (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 4 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(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 "content/browser/media/cdm_service_impl.h"
6
7 #include <algorithm>
8 #include <string>
9 #include <vector>
10
11 #include "base/base_paths.h"
12 #include "base/files/file_path.h"
13 #include "base/strings/string_split.h"
14 #include "base/strings/string_util.h"
15 #include "base/strings/utf_string_conversions.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace content {
19
20 const char kTestKeySystemType[] = "test";
21 const char kTestPath[] = "/aa/bb";
22 const char kVersion1[] = "1.1.1.1";
23 const char kVersion2[] = "1.1.1.2";
24 const char kTestCodecs[] = "vp9,mp4";
25 const char kCodecDelimiter[] = ",";
26
27 // For simplicity and to make failures easier to diagnose, this test uses
28 // std::string instead of base::FilePath and std::vector<std::string>.
29 class CdmServiceImplTest : public testing::Test {
30 public:
31 CdmServiceImplTest() {}
32 ~CdmServiceImplTest() override {}
33
34 protected:
35 void Register(const std::string& type,
36 const std::string& version,
37 const std::string& path,
38 const std::string& supported_codecs) {
39 std::vector<std::string> codecs =
Sorin Jianu 2016/04/15 01:53:26 const?
jrummell 2016/04/18 20:39:47 Done.
40 base::SplitString(supported_codecs, kCodecDelimiter,
41 base::KEEP_WHITESPACE, base::SPLIT_WANT_ALL);
42 cdm_service_.RegisterCdm(CdmInfo(type, base::Version(version),
43 base::FilePath::FromUTF8Unsafe(path),
44 codecs));
45 }
46
47 bool IsRegistered(const std::string& type, const std::string& version) {
48 for (const auto& cdm : cdm_service_.GetAllRegisteredCdms()) {
49 if (cdm.type == type && cdm.version.GetString() == version)
50 return true;
51 }
52 return false;
53 }
54
55 std::vector<std::string> GetVersions(const std::string& type) {
56 std::vector<std::string> versions;
57 for (const auto& cdm : cdm_service_.GetAllRegisteredCdms()) {
58 if (cdm.type == type)
59 versions.push_back(cdm.version.GetString());
60 }
61 return versions;
62 }
63
64 private:
65 CdmServiceImpl cdm_service_;
66 };
67
68 // Note that KeySystemService is a singleton, and thus the actions of
69 // one test impact other tests. So each test defines a different key system
70 // name to avoid conflicts.
71
72 TEST_F(CdmServiceImplTest, Register) {
73 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs);
74 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1));
75 }
76
77 TEST_F(CdmServiceImplTest, ReRegister) {
78 Register(kTestKeySystemType, kVersion1, "/bb/cc", "unknown");
79 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1));
80
81 // Now register same key system with different values.
82 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs);
83 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1));
84 }
85
86 TEST_F(CdmServiceImplTest, MultipleVersions) {
87 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs);
88 Register(kTestKeySystemType, kVersion2, "/bb/cc", "unknown");
89 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion1));
90 EXPECT_TRUE(IsRegistered(kTestKeySystemType, kVersion2));
91 }
92
93 TEST_F(CdmServiceImplTest, NewVersionInsertedFirst) {
94 Register(kTestKeySystemType, kVersion1, kTestPath, kTestCodecs);
95 Register(kTestKeySystemType, kVersion2, "/bb/cc", "unknown");
96
97 std::vector<std::string> versions = GetVersions(kTestKeySystemType);
Sorin Jianu 2016/04/15 01:53:26 const
jrummell 2016/04/18 20:39:47 Done.
98 EXPECT_EQ(2u, versions.size());
99 EXPECT_EQ(kVersion2, versions[0]);
100 EXPECT_EQ(kVersion1, versions[1]);
101 }
102
103 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698