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

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: changes 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 <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";
xhwang 2016/04/13 00:22:12 nit: webm is not a codec
jrummell 2016/04/14 01:32:16 Done.
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(
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
54 // Note that KeySystemService is a singleton, and thus the actions of
55 // one test impact other tests. So each test defines a different key system
56 // name to avoid conflicts.
57
58 TEST_F(CdmServiceImplTest, Register) {
59 const char kTestKeySystem[] = "test1";
xhwang 2016/04/13 00:22:12 kTestKeySystemType? Also it seems not interesting
jrummell 2016/04/14 01:32:16 Renamed.
xhwang 2016/04/14 06:20:26 See the new comment about singleton.
60 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs);
61 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
62 }
63
64 TEST_F(CdmServiceImplTest, ReRegister) {
65 const char kTestKeySystem[] = "test2";
66 Register(kTestKeySystem, kVersion1, "/bb/cc", "unknown");
67 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
68
69 // Now register same key system with different values.
70 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs);
71 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
72 }
73
74 TEST_F(CdmServiceImplTest, MultipleVersions) {
75 const char kTestKeySystem[] = "test3";
76 Register(kTestKeySystem, kVersion1, kTestPath, kTestCodecs);
77 Register(kTestKeySystem, kVersion2, "/bb/cc", "unknown");
78 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion1));
79 EXPECT_TRUE(IsRegistered(kTestKeySystem, kVersion2));
80 }
xhwang 2016/04/13 00:22:12 Can you add a test to make sure the new CDM is ins
jrummell 2016/04/14 01:32:16 Done.
81
82 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698