OLD | NEW |
| (Empty) |
1 // Copyright 2014 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 <string> | |
6 #include <vector> | |
7 | |
8 #include "base/test/simple_test_tick_clock.h" | |
9 #include "content/public/renderer/content_renderer_client.h" | |
10 #include "content/renderer/media/render_media_client.h" | |
11 #include "content/test/test_content_client.h" | |
12 #include "testing/gtest/include/gtest/gtest.h" | |
13 | |
14 #include "widevine_cdm_version.h" // In SHARED_INTERMEDIATE_DIR. | |
15 | |
16 namespace content { | |
17 | |
18 namespace { | |
19 | |
20 class TestKeySystemProperties : public media::KeySystemProperties { | |
21 public: | |
22 TestKeySystemProperties(const std::string& key_system_name) | |
23 : key_system_name_(key_system_name) {} | |
24 | |
25 std::string GetKeySystemName() const override { return key_system_name_; } | |
26 bool IsSupportedInitDataType( | |
27 media::EmeInitDataType init_data_type) const override { | |
28 return false; | |
29 } | |
30 media::SupportedCodecs GetSupportedCodecs() const override { | |
31 return media::EME_CODEC_NONE; | |
32 } | |
33 media::EmeConfigRule GetRobustnessConfigRule( | |
34 media::EmeMediaType media_type, | |
35 const std::string& requested_robustness) const override { | |
36 return requested_robustness.empty() ? media::EmeConfigRule::SUPPORTED | |
37 : media::EmeConfigRule::NOT_SUPPORTED; | |
38 } | |
39 media::EmeSessionTypeSupport GetPersistentLicenseSessionSupport() | |
40 const override { | |
41 return media::EmeSessionTypeSupport::NOT_SUPPORTED; | |
42 } | |
43 media::EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport() | |
44 const override { | |
45 return media::EmeSessionTypeSupport::NOT_SUPPORTED; | |
46 } | |
47 media::EmeFeatureSupport GetPersistentStateSupport() const override { | |
48 return media::EmeFeatureSupport::NOT_SUPPORTED; | |
49 } | |
50 media::EmeFeatureSupport GetDistinctiveIdentifierSupport() const override { | |
51 return media::EmeFeatureSupport::NOT_SUPPORTED; | |
52 } | |
53 | |
54 private: | |
55 const std::string key_system_name_; | |
56 }; | |
57 | |
58 class TestContentRendererClient : public ContentRendererClient { | |
59 public: | |
60 TestContentRendererClient() : is_extra_key_system_enabled_(false) {} | |
61 | |
62 // ContentRendererClient implementation. | |
63 void AddSupportedKeySystems( | |
64 std::vector<std::unique_ptr<media::KeySystemProperties>>* | |
65 key_systems_properties) override { | |
66 key_systems_properties->emplace_back( | |
67 new TestKeySystemProperties("test.keysystem")); | |
68 | |
69 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | |
70 if (is_extra_key_system_enabled_) { | |
71 key_systems_properties->emplace_back( | |
72 new TestKeySystemProperties(kWidevineKeySystem)); | |
73 } | |
74 #endif | |
75 } | |
76 | |
77 void EnableExtraKeySystem() { is_extra_key_system_enabled_ = true; } | |
78 | |
79 private: | |
80 // Whether a platform-specific extra key system is "supported" by |this|. | |
81 bool is_extra_key_system_enabled_; | |
82 }; | |
83 | |
84 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | |
85 bool ContainsWidevine( | |
86 const std::vector<std::unique_ptr<media::KeySystemProperties>>& | |
87 key_systems_properties) { | |
88 for (const auto& key_system_properties : key_systems_properties) { | |
89 if (key_system_properties->GetKeySystemName() == kWidevineKeySystem) | |
90 return true; | |
91 } | |
92 return false; | |
93 } | |
94 #endif | |
95 | |
96 } // namespace | |
97 | |
98 class RenderMediaClientTest : public testing::Test { | |
99 protected: | |
100 RenderMediaClientTest() | |
101 : render_media_client_(RenderMediaClient::GetInstance()) { | |
102 SetContentClient(&test_content_client_); | |
103 SetRendererClientForTesting(&test_content_renderer_client_); | |
104 } | |
105 | |
106 void EnableExtraKeySystem() { | |
107 test_content_renderer_client_.EnableExtraKeySystem(); | |
108 } | |
109 | |
110 RenderMediaClient* render_media_client_; | |
111 | |
112 private: | |
113 typedef base::hash_map<std::string, std::string> KeySystemNameForUMAMap; | |
114 | |
115 TestContentClient test_content_client_; | |
116 TestContentRendererClient test_content_renderer_client_; | |
117 KeySystemNameForUMAMap key_system_name_for_uma_map_; | |
118 }; | |
119 | |
120 TEST_F(RenderMediaClientTest, KeySystemNameForUMA) { | |
121 std::vector<media::KeySystemInfoForUMA> key_systems_info_for_uma; | |
122 render_media_client_->AddKeySystemsInfoForUMA(&key_systems_info_for_uma); | |
123 | |
124 std::string widevine_uma_name; | |
125 std::string clearkey_uma_name; | |
126 for (const media::KeySystemInfoForUMA& info : key_systems_info_for_uma) { | |
127 if (info.key_system == "com.widevine.alpha") | |
128 widevine_uma_name = info.key_system_name_for_uma; | |
129 if (info.key_system == "org.w3.clearkey") | |
130 clearkey_uma_name = info.key_system_name_for_uma; | |
131 } | |
132 | |
133 #if defined(WIDEVINE_CDM_AVAILABLE) | |
134 EXPECT_EQ("Widevine", widevine_uma_name); | |
135 #else | |
136 EXPECT_TRUE(widevine_uma_name.empty()); | |
137 #endif | |
138 | |
139 EXPECT_TRUE(clearkey_uma_name.empty()) << "Clear Key is added by media/ and " | |
140 "should not be added by the " | |
141 "MediaClient."; | |
142 } | |
143 | |
144 TEST_F(RenderMediaClientTest, IsKeySystemsUpdateNeeded) { | |
145 base::SimpleTestTickClock* tick_clock = new base::SimpleTestTickClock(); | |
146 render_media_client_->SetTickClockForTesting( | |
147 std::unique_ptr<base::TickClock>(tick_clock)); | |
148 | |
149 // IsKeySystemsUpdateNeeded() always returns true after construction. | |
150 EXPECT_TRUE(render_media_client_->IsKeySystemsUpdateNeeded()); | |
151 | |
152 std::vector<std::unique_ptr<media::KeySystemProperties>> | |
153 key_systems_properties; | |
154 render_media_client_->AddSupportedKeySystems(&key_systems_properties); | |
155 | |
156 // No update needed immediately after AddSupportedKeySystems() call. | |
157 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded()); | |
158 | |
159 #if defined(WIDEVINE_CDM_AVAILABLE) && defined(WIDEVINE_CDM_IS_COMPONENT) | |
160 // Widevine not supported because extra key system isn't enabled. | |
161 EXPECT_FALSE(ContainsWidevine(key_systems_properties)); | |
162 | |
163 // This is timing related. The update interval for Widevine is 1000 ms. | |
164 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded()); | |
165 tick_clock->Advance(base::TimeDelta::FromMilliseconds(990)); | |
166 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded()); | |
167 tick_clock->Advance(base::TimeDelta::FromMilliseconds(10)); | |
168 EXPECT_TRUE(render_media_client_->IsKeySystemsUpdateNeeded()); | |
169 | |
170 EnableExtraKeySystem(); | |
171 | |
172 key_systems_properties.clear(); | |
173 render_media_client_->AddSupportedKeySystems(&key_systems_properties); | |
174 EXPECT_TRUE(ContainsWidevine(key_systems_properties)); | |
175 | |
176 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded()); | |
177 tick_clock->Advance(base::TimeDelta::FromMilliseconds(1000)); | |
178 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded()); | |
179 tick_clock->Advance(base::TimeDelta::FromMilliseconds(1000)); | |
180 EXPECT_FALSE(render_media_client_->IsKeySystemsUpdateNeeded()); | |
181 #endif | |
182 } | |
183 | |
184 } // namespace content | |
OLD | NEW |