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

Side by Side Diff: chrome/renderer/media/chrome_key_systems_provider_unittest.cc

Issue 2712983004: Simplify/Cleanup MediaClient (Closed)
Patch Set: Fix test leak Created 3 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
« no previous file with comments | « chrome/renderer/media/chrome_key_systems_provider.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2017 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 "chrome/renderer/media/chrome_key_systems_provider.h"
6
7 #include <memory>
8 #include <string>
9 #include <vector>
10
11 #include "base/bind.h"
12 #include "base/bind_helpers.h"
13 #include "base/test/simple_test_tick_clock.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR.
17
18 namespace chrome {
19
20 namespace {
21
22 class TestKeySystemProperties : public media::KeySystemProperties {
23 public:
24 explicit TestKeySystemProperties(const std::string& key_system_name)
25 : key_system_name_(key_system_name) {}
26
27 std::string GetKeySystemName() const override { return key_system_name_; }
28 bool IsSupportedInitDataType(
29 media::EmeInitDataType init_data_type) const override {
30 return false;
31 }
32 media::SupportedCodecs GetSupportedCodecs() const override {
33 return media::EME_CODEC_NONE;
34 }
35 media::EmeConfigRule GetRobustnessConfigRule(
36 media::EmeMediaType media_type,
37 const std::string& requested_robustness) const override {
38 return requested_robustness.empty() ? media::EmeConfigRule::SUPPORTED
39 : media::EmeConfigRule::NOT_SUPPORTED;
40 }
41 media::EmeSessionTypeSupport GetPersistentLicenseSessionSupport()
42 const override {
43 return media::EmeSessionTypeSupport::NOT_SUPPORTED;
44 }
45 media::EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport()
46 const override {
47 return media::EmeSessionTypeSupport::NOT_SUPPORTED;
48 }
49 media::EmeFeatureSupport GetPersistentStateSupport() const override {
50 return media::EmeFeatureSupport::NOT_SUPPORTED;
51 }
52 media::EmeFeatureSupport GetDistinctiveIdentifierSupport() const override {
53 return media::EmeFeatureSupport::NOT_SUPPORTED;
54 }
55
56 private:
57 const std::string key_system_name_;
58 };
59
60 class TestKeySystemsProviderDelegate {
61 public:
62 TestKeySystemsProviderDelegate() : include_widevine_(false) {}
63
64 void AddTestKeySystems(
65 std::vector<std::unique_ptr<media::KeySystemProperties>>* key_systems) {
66 key_systems->emplace_back(
67 new TestKeySystemProperties("com.example.foobar"));
68
69 if (include_widevine_) {
70 #if defined(WIDEVINE_CDM_AVAILABLE)
71 key_systems->emplace_back(
72 new TestKeySystemProperties(kWidevineKeySystem));
73 #else
74 // Tests should only attempt to include Widevine when it is available.
75 NOTREACHED();
76 #endif
77 }
78 }
79
80 void set_include_widevine(bool include_widevine) {
81 include_widevine_ = include_widevine;
82 }
83
84 private:
85 bool include_widevine_;
86 };
87
88 } // namespace
89
90 TEST(ChromeKeySystemsProviderTest, IsKeySystemsUpdateNeeded) {
91 ChromeKeySystemsProvider key_systems_provider;
92
93 base::SimpleTestTickClock* tick_clock = new base::SimpleTestTickClock();
94 key_systems_provider.SetTickClockForTesting(
95 std::unique_ptr<base::TickClock>(tick_clock));
96
97 std::unique_ptr<TestKeySystemsProviderDelegate> provider_delegate(
98 new TestKeySystemsProviderDelegate());
99 key_systems_provider.SetProviderDelegateForTesting(
100 base::Bind(&TestKeySystemsProviderDelegate::AddTestKeySystems,
101 base::Unretained(provider_delegate.get())));
102
103 // IsKeySystemsUpdateNeeded() always returns true after construction.
104 EXPECT_TRUE(key_systems_provider.IsKeySystemsUpdateNeeded());
105
106 std::vector<std::unique_ptr<media::KeySystemProperties>> key_systems;
107 key_systems_provider.AddSupportedKeySystems(&key_systems);
108
109 // No update needed immediately after AddSupportedKeySystems() call.
110 EXPECT_FALSE(key_systems_provider.IsKeySystemsUpdateNeeded());
111
112 // Widevine not initially provided.
113 EXPECT_EQ(key_systems.size(), 1U);
114 EXPECT_EQ(key_systems[0]->GetKeySystemName(), "com.example.foobar");
115
116 // This is timing related. The update interval for Widevine is 1000 ms.
117 EXPECT_FALSE(key_systems_provider.IsKeySystemsUpdateNeeded());
118 tick_clock->Advance(base::TimeDelta::FromMilliseconds(990));
119 EXPECT_FALSE(key_systems_provider.IsKeySystemsUpdateNeeded());
120 tick_clock->Advance(base::TimeDelta::FromMilliseconds(10));
121
122 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
123 // Require update once enough time has passed for builds that install Widevine
124 // as a component.
125 EXPECT_TRUE(key_systems_provider.IsKeySystemsUpdateNeeded());
126
127 // Now add Widevine.
128 provider_delegate->set_include_widevine(true);
129 key_systems.clear();
130 key_systems_provider.AddSupportedKeySystems(&key_systems);
131
132 // Widevine should now be among the list.
133 bool found_widevine = false;
134 for (const auto& key_system_properties : key_systems) {
135 if (key_system_properties->GetKeySystemName() == kWidevineKeySystem) {
136 found_widevine = true;
137 break;
138 }
139 }
140 EXPECT_TRUE(found_widevine);
141
142 // Update not needed now, nor later because Widevine has been described.
143 EXPECT_FALSE(key_systems_provider.IsKeySystemsUpdateNeeded());
144 tick_clock->Advance(base::TimeDelta::FromMilliseconds(1000));
145 EXPECT_FALSE(key_systems_provider.IsKeySystemsUpdateNeeded());
146 tick_clock->Advance(base::TimeDelta::FromMilliseconds(1000));
147 EXPECT_FALSE(key_systems_provider.IsKeySystemsUpdateNeeded());
148 #else
149 // No update needed for builds that either don't offer Widevine or do so
150 // as part of Chrome rather than component installer.
151 EXPECT_FALSE(key_systems_provider.IsKeySystemsUpdateNeeded());
152 #endif // defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT)
153 }
154
155 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/renderer/media/chrome_key_systems_provider.cc ('k') | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698