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

Side by Side Diff: media/base/key_systems_unittest.cc

Issue 2712983004: Simplify/Cleanup MediaClient (Closed)
Patch Set: Created 3 years, 9 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 // TODO(sandersd): Refactor to remove recomputed codec arrays, and generally 5 // TODO(sandersd): Refactor to remove recomputed codec arrays, and generally
6 // shorten and improve coverage. 6 // shorten and improve coverage.
7 // - http://crbug.com/417444 7 // - http://crbug.com/417444
8 // - http://crbug.com/457438 8 // - http://crbug.com/457438
9 // TODO(sandersd): Add tests to cover codec vectors with empty items. 9 // TODO(sandersd): Add tests to cover codec vectors with empty items.
10 // http://crbug.com/417461 10 // http://crbug.com/417461
11 11
12 #include <string> 12 #include <string>
13 #include <vector> 13 #include <vector>
14 14
15 #include "base/logging.h" 15 #include "base/logging.h"
16 #include "media/base/eme_constants.h" 16 #include "media/base/eme_constants.h"
17 #include "media/base/key_systems.h" 17 #include "media/base/key_systems.h"
18 #include "media/base/media.h" 18 #include "media/base/media.h"
19 #include "media/base/media_client.h" 19 #include "media/base/media_client.h"
20 #include "ppapi/features/features.h" 20 #include "ppapi/features/features.h"
21 #include "testing/gtest/include/gtest/gtest.h" 21 #include "testing/gtest/include/gtest/gtest.h"
22 #include "third_party/widevine/cdm/widevine_cdm_common.h"
22 23
23 namespace media { 24 namespace media {
24 25
25 // These are the (fake) key systems that are registered for these tests. 26 // These are the (fake) key systems that are registered for these tests.
26 // kUsesAes uses the AesDecryptor like Clear Key. 27 // kUsesAes uses the AesDecryptor like Clear Key.
27 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM. 28 // kExternal uses an external CDM, such as Pepper-based or Android platform CDM.
28 const char kUsesAes[] = "x-org.example.clear"; 29 const char kUsesAes[] = "x-org.example.clear";
29 const char kUseAesNameForUMA[] = "UseAes";
30 const char kExternal[] = "x-com.example.test"; 30 const char kExternal[] = "x-com.example.test";
31 const char kExternalNameForUMA[] = "External";
32 31
33 const char kClearKey[] = "org.w3.clearkey"; 32 const char kClearKey[] = "org.w3.clearkey";
34 const char kExternalClearKey[] = "org.chromium.externalclearkey"; 33 const char kExternalClearKey[] = "org.chromium.externalclearkey";
35 34
36 const char kAudioWebM[] = "audio/webm"; 35 const char kAudioWebM[] = "audio/webm";
37 const char kVideoWebM[] = "video/webm"; 36 const char kVideoWebM[] = "video/webm";
38 const char kAudioFoo[] = "audio/foo"; 37 const char kAudioFoo[] = "audio/foo";
39 const char kVideoFoo[] = "video/foo"; 38 const char kVideoFoo[] = "video/foo";
40 39
41 // Pick some arbitrary bit fields as long as they are not in conflict with the 40 // Pick some arbitrary bit fields as long as they are not in conflict with the
(...skipping 125 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 return true; 166 return true;
168 #endif 167 #endif
169 } 168 }
170 169
171 class TestMediaClient : public MediaClient { 170 class TestMediaClient : public MediaClient {
172 public: 171 public:
173 TestMediaClient(); 172 TestMediaClient();
174 ~TestMediaClient() override; 173 ~TestMediaClient() override;
175 174
176 // MediaClient implementation. 175 // MediaClient implementation.
177 void AddKeySystemsInfoForUMA(
178 std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) final;
179 bool IsKeySystemsUpdateNeeded() final;
180 void AddSupportedKeySystems(std::vector<std::unique_ptr<KeySystemProperties>>* 176 void AddSupportedKeySystems(std::vector<std::unique_ptr<KeySystemProperties>>*
181 key_systems_properties) override; 177 key_systems_properties) override;
182 void RecordRapporURL(const std::string& metric, const GURL& url) final; 178 void RecordRapporURL(const std::string& metric, const GURL& url) final;
183 bool IsSupportedVideoConfig(const media::VideoConfig& config) final; 179 bool IsSupportedVideoConfig(const media::VideoConfig& config) final;
184
185 // Helper function to test the case where IsKeySystemsUpdateNeeded() is true
186 // after AddSupportedKeySystems() is called.
187 void SetKeySystemsUpdateNeeded();
188
189 // Helper function to disable "kExternal" key system support so that we can
190 // test the key system update case.
191 void DisableExternalKeySystemSupport();
192
193 private:
194 bool is_update_needed_;
195 bool supports_external_key_system_;
196 }; 180 };
197 181
198 TestMediaClient::TestMediaClient() 182 TestMediaClient::TestMediaClient() {}
199 : is_update_needed_(true), supports_external_key_system_(true) {
200 }
201 183
202 TestMediaClient::~TestMediaClient() { 184 TestMediaClient::~TestMediaClient() {
203 } 185 }
204 186
205 void TestMediaClient::AddKeySystemsInfoForUMA(
206 std::vector<KeySystemInfoForUMA>* key_systems_info_for_uma) {
207 key_systems_info_for_uma->push_back(
208 media::KeySystemInfoForUMA(kUsesAes, kUseAesNameForUMA));
209 key_systems_info_for_uma->push_back(
210 media::KeySystemInfoForUMA(kExternal, kExternalNameForUMA));
211 }
212
213 bool TestMediaClient::IsKeySystemsUpdateNeeded() {
214 return is_update_needed_;
215 }
216
217 void TestMediaClient::AddSupportedKeySystems( 187 void TestMediaClient::AddSupportedKeySystems(
218 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) { 188 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) {
219 DCHECK(is_update_needed_);
220
221 key_systems->emplace_back(new AesKeySystemProperties(kUsesAes)); 189 key_systems->emplace_back(new AesKeySystemProperties(kUsesAes));
222 190 key_systems->emplace_back(new ExternalKeySystemProperties());
223 if (supports_external_key_system_)
224 key_systems->emplace_back(new ExternalKeySystemProperties());
225
226 is_update_needed_ = false;
227 } 191 }
228 192
229 void TestMediaClient::RecordRapporURL(const std::string& /* metric */, 193 void TestMediaClient::RecordRapporURL(const std::string& /* metric */,
230 const GURL& /* url */) { 194 const GURL& /* url */) {
231 NOTIMPLEMENTED(); 195 NOTIMPLEMENTED();
232 } 196 }
233 197
234 bool TestMediaClient::IsSupportedVideoConfig(const media::VideoConfig& config) { 198 bool TestMediaClient::IsSupportedVideoConfig(const media::VideoConfig& config) {
235 return true; 199 return true;
236 } 200 }
237 201
238 void TestMediaClient::SetKeySystemsUpdateNeeded() {
239 is_update_needed_ = true;
240 }
241
242 void TestMediaClient::DisableExternalKeySystemSupport() {
243 supports_external_key_system_ = false;
244 }
245
246 class PotentiallySupportedNamesTestMediaClient : public TestMediaClient {
247 void AddSupportedKeySystems(std::vector<std::unique_ptr<KeySystemProperties>>*
248 key_systems_properties) final;
249 };
250
251 void PotentiallySupportedNamesTestMediaClient::AddSupportedKeySystems(
252 std::vector<std::unique_ptr<KeySystemProperties>>* key_systems) {
253 // org.w3.clearkey is automatically registered.
254 key_systems->emplace_back(new AesKeySystemProperties("com.widevine.alpha"));
255 key_systems->emplace_back(
256 new AesKeySystemProperties("org.chromium.externalclearkey"));
257 key_systems->emplace_back(
258 new AesKeySystemProperties("org.chromium.externalclearkey.something"));
259 key_systems->emplace_back(
260 new AesKeySystemProperties("com.chromecast.something"));
261 key_systems->emplace_back(new AesKeySystemProperties("x-something"));
262 }
263
264 class KeySystemsPotentiallySupportedNamesTest : public testing::Test {
265 protected:
266 KeySystemsPotentiallySupportedNamesTest() {
267 SetMediaClient(&test_media_client_);
268 }
269
270 ~KeySystemsPotentiallySupportedNamesTest() override {
271 // Clear the use of |test_media_client_|, which was set in SetUp().
272 SetMediaClient(nullptr);
273 }
274
275 private:
276 PotentiallySupportedNamesTestMediaClient test_media_client_;
277 };
278
279 class KeySystemsTest : public testing::Test { 202 class KeySystemsTest : public testing::Test {
280 protected: 203 protected:
281 KeySystemsTest() { 204 KeySystemsTest() {
282 vp8_codec_.push_back("vp8"); 205 vp8_codec_.push_back("vp8");
283 206
284 vp80_codec_.push_back("vp8.0"); 207 vp80_codec_.push_back("vp8.0");
285 208
286 vp9_codec_.push_back("vp9"); 209 vp9_codec_.push_back("vp9");
287 210
288 vp90_codec_.push_back("vp9.0"); 211 vp90_codec_.push_back("vp9.0");
(...skipping 24 matching lines...) Expand all
313 236
314 SetMediaClient(&test_media_client_); 237 SetMediaClient(&test_media_client_);
315 } 238 }
316 239
317 void SetUp() override { 240 void SetUp() override {
318 AddContainerAndCodecMasksForTest(); 241 AddContainerAndCodecMasksForTest();
319 } 242 }
320 243
321 ~KeySystemsTest() override { 244 ~KeySystemsTest() override {
322 // Clear the use of |test_media_client_|, which was set in SetUp(). 245 // Clear the use of |test_media_client_|, which was set in SetUp().
246 // NOTE: This does not clear any cached KeySystemProperties in the global
247 // KeySystems instance.
323 SetMediaClient(nullptr); 248 SetMediaClient(nullptr);
324 } 249 }
325 250
326 void UpdateClientKeySystems() {
327 test_media_client_.SetKeySystemsUpdateNeeded();
328 test_media_client_.DisableExternalKeySystemSupport();
329 }
330
331 typedef std::vector<std::string> CodecVector; 251 typedef std::vector<std::string> CodecVector;
332 252
333 const CodecVector& no_codecs() const { return no_codecs_; } 253 const CodecVector& no_codecs() const { return no_codecs_; }
334 254
335 const CodecVector& vp8_codec() const { return vp8_codec_; } 255 const CodecVector& vp8_codec() const { return vp8_codec_; }
336 const CodecVector& vp80_codec() const { return vp80_codec_; } 256 const CodecVector& vp80_codec() const { return vp80_codec_; }
337 const CodecVector& vp9_codec() const { return vp9_codec_; } 257 const CodecVector& vp9_codec() const { return vp9_codec_; }
338 const CodecVector& vp90_codec() const { return vp90_codec_; } 258 const CodecVector& vp90_codec() const { return vp90_codec_; }
339 259
340 const CodecVector& vorbis_codec() const { return vorbis_codec_; } 260 const CodecVector& vorbis_codec() const { return vorbis_codec_; }
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
429 EXPECT_TRUE(type.empty()); 349 EXPECT_TRUE(type.empty());
430 #endif 350 #endif
431 } 351 }
432 352
433 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) { 353 TEST_F(KeySystemsTest, Basic_UsesAesDecryptor) {
434 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes)); 354 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
435 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType( 355 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
436 kVideoWebM, no_codecs(), kUsesAes)); 356 kVideoWebM, no_codecs(), kUsesAes));
437 357
438 // No UMA value for this test key system. 358 // No UMA value for this test key system.
439 EXPECT_EQ("UseAes", GetKeySystemNameForUMA(kUsesAes)); 359 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kUsesAes));
440 360
441 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes)); 361 EXPECT_TRUE(CanUseAesDecryptor(kUsesAes));
442 #if BUILDFLAG(ENABLE_PEPPER_CDMS) 362 #if BUILDFLAG(ENABLE_PEPPER_CDMS)
443 std::string type; 363 std::string type;
444 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON) 364 #if !defined(NDEBUG) || defined(DCHECK_ALWAYS_ON)
445 EXPECT_DEATH(type = GetPepperType(kUsesAes), 365 EXPECT_DEATH(type = GetPepperType(kUsesAes),
446 "x-org.example.clear is not Pepper-based"); 366 "x-org.example.clear is not Pepper-based");
447 #endif 367 #endif
448 EXPECT_TRUE(type.empty()); 368 EXPECT_TRUE(type.empty());
449 #endif 369 #endif
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
703 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType( 623 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
704 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal)); 624 kAudioFoo, foovideo_and_fooaudio_codecs(), kExternal));
705 625
706 // Non-container2 codec. 626 // Non-container2 codec.
707 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType( 627 EXPECT_FALSE(IsSupportedKeySystemWithAudioMimeType(
708 kAudioFoo, vorbis_codec(), kExternal)); 628 kAudioFoo, vorbis_codec(), kExternal));
709 } 629 }
710 630
711 TEST_F(KeySystemsTest, KeySystemNameForUMA) { 631 TEST_F(KeySystemsTest, KeySystemNameForUMA) {
712 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey)); 632 EXPECT_EQ("ClearKey", GetKeySystemNameForUMA(kClearKey));
633 EXPECT_EQ("Widevine", GetKeySystemNameForUMA(kWidevineKeySystem));
634 EXPECT_EQ("Unknown", GetKeySystemNameForUMA("Foo"));
713 635
714 // External Clear Key never has a UMA name. 636 // External Clear Key never has a UMA name.
715 if (CanRunExternalKeySystemTests()) 637 if (CanRunExternalKeySystemTests())
716 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey)); 638 EXPECT_EQ("Unknown", GetKeySystemNameForUMA(kExternalClearKey));
717 } 639 }
718 640
719 TEST_F(KeySystemsTest, KeySystemsUpdate) {
720 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
721 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
722 kVideoWebM, no_codecs(), kUsesAes));
723
724 if (CanRunExternalKeySystemTests()) {
725 EXPECT_TRUE(IsSupportedKeySystem(kExternal));
726 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(kVideoWebM, no_codecs(),
727 kExternal));
728 }
729
730 UpdateClientKeySystems();
731
732 EXPECT_TRUE(IsSupportedKeySystem(kUsesAes));
733 EXPECT_TRUE(IsSupportedKeySystemWithMediaMimeType(
734 kVideoWebM, no_codecs(), kUsesAes));
735 if (CanRunExternalKeySystemTests())
736 EXPECT_FALSE(IsSupportedKeySystem(kExternal));
737 }
738
739 TEST_F(KeySystemsPotentiallySupportedNamesTest, PotentiallySupportedNames) {
740 EXPECT_FALSE(IsSupportedKeySystem("org.w3"));
741 EXPECT_FALSE(IsSupportedKeySystem("org.w3."));
742 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearke"));
743 EXPECT_TRUE(IsSupportedKeySystem("org.w3.clearkey"));
744 EXPECT_FALSE(IsSupportedKeySystem("org.w3.clearkeys"));
745
746 EXPECT_FALSE(IsSupportedKeySystem("com.widevine"));
747 EXPECT_FALSE(IsSupportedKeySystem("com.widevine."));
748 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alph"));
749 EXPECT_TRUE(IsSupportedKeySystem("com.widevine.alpha"));
750 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.beta"));
751 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alphabeta"));
752 EXPECT_FALSE(IsSupportedKeySystem("com.widevine.alpha.beta"));
753
754 EXPECT_FALSE(IsSupportedKeySystem("org.chromium"));
755 EXPECT_FALSE(IsSupportedKeySystem("org.chromium."));
756 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearke"));
757 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey"));
758 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkeys"));
759 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey."));
760 EXPECT_TRUE(IsSupportedKeySystem("org.chromium.externalclearkey.something"));
761 EXPECT_FALSE(
762 IsSupportedKeySystem("org.chromium.externalclearkey.something.else"));
763 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.externalclearkey.other"));
764 EXPECT_FALSE(IsSupportedKeySystem("org.chromium.other"));
765
766 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast"));
767 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast."));
768 EXPECT_TRUE(IsSupportedKeySystem("com.chromecast.something"));
769 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.something.else"));
770 EXPECT_FALSE(IsSupportedKeySystem("com.chromecast.other"));
771
772 EXPECT_FALSE(IsSupportedKeySystem("x-"));
773 EXPECT_TRUE(IsSupportedKeySystem("x-something"));
774 EXPECT_FALSE(IsSupportedKeySystem("x-something.else"));
775 EXPECT_FALSE(IsSupportedKeySystem("x-other"));
776 }
777
778 } // namespace media 641 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698