Update V8 to version 4.7.56.
[chromium-blink-merge.git] / media / blink / key_system_config_selector_unittest.cc
blob70b890d8f6d091eb0cc599e6a775302d43efe34d
1 // Copyright 2015 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.
5 #include <string>
6 #include <vector>
8 #include "base/bind.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h"
11 #include "media/base/eme_constants.h"
12 #include "media/base/key_systems.h"
13 #include "media/base/media_permission.h"
14 #include "media/blink/key_system_config_selector.h"
15 #include "testing/gtest/include/gtest/gtest.h"
16 #include "third_party/WebKit/public/platform/WebEncryptedMediaTypes.h"
17 #include "third_party/WebKit/public/platform/WebMediaKeySystemConfiguration.h"
18 #include "third_party/WebKit/public/platform/WebSecurityOrigin.h"
19 #include "third_party/WebKit/public/platform/WebString.h"
20 #include "url/gurl.h"
22 namespace media {
24 namespace {
26 const char kSupported[] = "supported";
27 const char kRecommendIdentifier[] = "recommend_identifier";
28 const char kRequireIdentifier[] = "require_identifier";
29 const char kUnsupported[] = "unsupported";
31 // TODO(sandersd): Audio and video variants (doesn't matter for now because the
32 // checks are in KeySystems).
33 const char kSupportedContainer[] = "video/webm";
34 const char kUnsupportedContainer[] = "video/foo";
36 // TODO(sandersd): Extended codec variants (requires proprietary codec support).
37 const char kSupportedCodec[] = "vp8";
38 const char kUnsupportedCodec[] = "foo";
39 const char kUnsupportedCodecs[] = "vp8,foo";
40 const char kSupportedCodecs[] = "vp8,vp8";
42 const char kDefaultSecurityOrigin[] = "https://example.com/";
44 class FakeKeySystems : public KeySystems {
45 public:
46 ~FakeKeySystems() override {
49 bool IsSupportedKeySystem(const std::string& key_system) const override {
50 if (key_system == kSupported)
51 return true;
52 return false;
55 // TODO(sandersd): Move implementation into KeySystemConfigSelector?
56 bool IsSupportedInitDataType(const std::string& key_system,
57 EmeInitDataType init_data_type) const override {
58 switch (init_data_type) {
59 case EmeInitDataType::UNKNOWN:
60 return false;
61 case EmeInitDataType::WEBM:
62 return (init_data_types & kInitDataTypeMaskWebM) != 0;
63 case EmeInitDataType::CENC:
64 return (init_data_types & kInitDataTypeMaskCenc) != 0;
65 case EmeInitDataType::KEYIDS:
66 return (init_data_types & kInitDataTypeMaskKeyIds) != 0;
68 NOTREACHED();
69 return false;
72 // TODO(sandersd): Secure codec simulation.
73 EmeConfigRule GetContentTypeConfigRule(
74 const std::string& key_system,
75 EmeMediaType media_type,
76 const std::string& container_mime_type,
77 const std::vector<std::string>& codecs) const override {
78 if (container_mime_type == kUnsupportedContainer)
79 return EmeConfigRule::NOT_SUPPORTED;
80 DCHECK_EQ(kSupportedContainer, container_mime_type);
81 for (const std::string& codec : codecs) {
82 if (codec == kUnsupportedCodec)
83 return EmeConfigRule::NOT_SUPPORTED;
84 DCHECK_EQ(kSupportedCodec, codec);
86 return EmeConfigRule::SUPPORTED;
89 EmeConfigRule GetRobustnessConfigRule(
90 const std::string& key_system,
91 EmeMediaType media_type,
92 const std::string& requested_robustness) const override {
93 if (requested_robustness == kUnsupported)
94 return EmeConfigRule::NOT_SUPPORTED;
95 if (requested_robustness == kRequireIdentifier)
96 return EmeConfigRule::IDENTIFIER_REQUIRED;
97 if (requested_robustness == kRecommendIdentifier)
98 return EmeConfigRule::IDENTIFIER_RECOMMENDED;
99 if (requested_robustness == kSupported)
100 return EmeConfigRule::SUPPORTED;
101 NOTREACHED();
102 return EmeConfigRule::NOT_SUPPORTED;
105 EmeSessionTypeSupport GetPersistentLicenseSessionSupport(
106 const std::string& key_system) const override {
107 return persistent_license;
110 EmeSessionTypeSupport GetPersistentReleaseMessageSessionSupport(
111 const std::string& key_system) const override {
112 return persistent_release_message;
115 EmeFeatureSupport GetPersistentStateSupport(
116 const std::string& key_system) const override {
117 return persistent_state;
120 EmeFeatureSupport GetDistinctiveIdentifierSupport(
121 const std::string& key_system) const override {
122 return distinctive_identifier;
125 InitDataTypeMask init_data_types = kInitDataTypeMaskNone;
127 // INVALID so that they must be set in any test that needs them.
128 EmeSessionTypeSupport persistent_license = EmeSessionTypeSupport::INVALID;
129 EmeSessionTypeSupport persistent_release_message =
130 EmeSessionTypeSupport::INVALID;
132 // Every test implicitly requires these, so they must be set. They are set to
133 // values that are likely to cause tests to fail if they are accidentally
134 // depended on. Test cases explicitly depending on them should set them, as
135 // the default values may be changed.
136 EmeFeatureSupport persistent_state = EmeFeatureSupport::NOT_SUPPORTED;
137 EmeFeatureSupport distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
140 class FakeMediaPermission : public MediaPermission {
141 public:
142 void HasPermission(Type type,
143 const GURL& security_origin,
144 const PermissionStatusCB& permission_status_cb) override {
145 permission_status_cb.Run(is_granted);
148 void RequestPermission(
149 Type type,
150 const GURL& security_origin,
151 const PermissionStatusCB& permission_status_cb) override {
152 requests++;
153 permission_status_cb.Run(is_granted);
156 int requests = 0;
157 bool is_granted = false;
160 } // namespace
162 class KeySystemConfigSelectorTest : public testing::Test {
163 public:
164 KeySystemConfigSelectorTest()
165 : key_systems_(new FakeKeySystems()),
166 media_permission_(new FakeMediaPermission()) {}
168 void SelectConfig() {
169 media_permission_->requests = 0;
170 succeeded_count_ = 0;
171 not_supported_count_ = 0;
172 KeySystemConfigSelector(key_systems_.get(), media_permission_.get())
173 .SelectConfig(key_system_, configs_, security_origin_, false,
174 base::Bind(&KeySystemConfigSelectorTest::OnSucceeded,
175 base::Unretained(this)),
176 base::Bind(&KeySystemConfigSelectorTest::OnNotSupported,
177 base::Unretained(this)));
180 bool SelectConfigReturnsConfig() {
181 SelectConfig();
182 EXPECT_EQ(0, media_permission_->requests);
183 EXPECT_EQ(1, succeeded_count_);
184 EXPECT_EQ(0, not_supported_count_);
185 return (succeeded_count_ != 0);
188 bool SelectConfigReturnsError() {
189 SelectConfig();
190 EXPECT_EQ(0, media_permission_->requests);
191 EXPECT_EQ(0, succeeded_count_);
192 EXPECT_EQ(1, not_supported_count_);
193 return (not_supported_count_ != 0);
196 bool SelectConfigRequestsPermissionAndReturnsConfig() {
197 SelectConfig();
198 EXPECT_EQ(1, media_permission_->requests);
199 EXPECT_EQ(1, succeeded_count_);
200 EXPECT_EQ(0, not_supported_count_);
201 return (media_permission_->requests != 0 && succeeded_count_ != 0);
204 bool SelectConfigRequestsPermissionAndReturnsError() {
205 SelectConfig();
206 EXPECT_EQ(1, media_permission_->requests);
207 EXPECT_EQ(0, succeeded_count_);
208 EXPECT_EQ(1, not_supported_count_);
209 return (media_permission_->requests != 0 && not_supported_count_ != 0);
212 void OnSucceeded(const blink::WebMediaKeySystemConfiguration& result,
213 const CdmConfig& cdm_config) {
214 succeeded_count_++;
215 config_ = result;
218 void OnNotSupported(const blink::WebString&) { not_supported_count_++; }
220 scoped_ptr<FakeKeySystems> key_systems_;
221 scoped_ptr<FakeMediaPermission> media_permission_;
223 // Held values for the call to SelectConfig().
224 blink::WebString key_system_ = blink::WebString::fromUTF8(kSupported);
225 std::vector<blink::WebMediaKeySystemConfiguration> configs_;
226 blink::WebSecurityOrigin security_origin_ =
227 blink::WebSecurityOrigin::createFromString(kDefaultSecurityOrigin);
229 // Holds the last successful accumulated configuration.
230 blink::WebMediaKeySystemConfiguration config_;
232 int succeeded_count_;
233 int not_supported_count_;
235 DISALLOW_COPY_AND_ASSIGN(KeySystemConfigSelectorTest);
238 // --- Basics ---
240 TEST_F(KeySystemConfigSelectorTest, NoConfigs) {
241 ASSERT_TRUE(SelectConfigReturnsError());
244 // Most of the tests below assume that an empty config is valid.
245 TEST_F(KeySystemConfigSelectorTest, EmptyConfig) {
246 configs_.push_back(blink::WebMediaKeySystemConfiguration());
248 ASSERT_TRUE(SelectConfigReturnsConfig());
249 EXPECT_TRUE(config_.label.isNull());
250 EXPECT_TRUE(config_.initDataTypes.isEmpty());
251 EXPECT_TRUE(config_.audioCapabilities.isEmpty());
252 EXPECT_TRUE(config_.videoCapabilities.isEmpty());
253 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed,
254 config_.distinctiveIdentifier);
255 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed,
256 config_.persistentState);
257 ASSERT_EQ(1u, config_.sessionTypes.size());
258 EXPECT_EQ(blink::WebEncryptedMediaSessionType::Temporary,
259 config_.sessionTypes[0]);
262 TEST_F(KeySystemConfigSelectorTest, Label) {
263 blink::WebMediaKeySystemConfiguration config;
264 config.label = "foo";
265 configs_.push_back(config);
267 ASSERT_TRUE(SelectConfigReturnsConfig());
268 EXPECT_EQ("foo", config_.label);
271 // --- keySystem ---
272 // Empty is not tested because the empty check is in Blink.
274 TEST_F(KeySystemConfigSelectorTest, KeySystem_NonAscii) {
275 key_system_ = "\xde\xad\xbe\xef";
276 configs_.push_back(blink::WebMediaKeySystemConfiguration());
277 ASSERT_TRUE(SelectConfigReturnsError());
280 TEST_F(KeySystemConfigSelectorTest, KeySystem_Unsupported) {
281 key_system_ = kUnsupported;
282 configs_.push_back(blink::WebMediaKeySystemConfiguration());
283 ASSERT_TRUE(SelectConfigReturnsError());
286 // --- initDataTypes ---
288 TEST_F(KeySystemConfigSelectorTest, InitDataTypes_Empty) {
289 blink::WebMediaKeySystemConfiguration config;
290 config.hasInitDataTypes = true;
291 configs_.push_back(config);
293 ASSERT_TRUE(SelectConfigReturnsError());
296 TEST_F(KeySystemConfigSelectorTest, InitDataTypes_NoneSupported) {
297 key_systems_->init_data_types = kInitDataTypeMaskWebM;
299 std::vector<blink::WebEncryptedMediaInitDataType> init_data_types;
300 init_data_types.push_back(blink::WebEncryptedMediaInitDataType::Unknown);
301 init_data_types.push_back(blink::WebEncryptedMediaInitDataType::Cenc);
303 blink::WebMediaKeySystemConfiguration config;
304 config.hasInitDataTypes = true;
305 config.initDataTypes = init_data_types;
306 configs_.push_back(config);
308 ASSERT_TRUE(SelectConfigReturnsError());
311 TEST_F(KeySystemConfigSelectorTest, InitDataTypes_SubsetSupported) {
312 key_systems_->init_data_types = kInitDataTypeMaskWebM;
314 std::vector<blink::WebEncryptedMediaInitDataType> init_data_types;
315 init_data_types.push_back(blink::WebEncryptedMediaInitDataType::Unknown);
316 init_data_types.push_back(blink::WebEncryptedMediaInitDataType::Cenc);
317 init_data_types.push_back(blink::WebEncryptedMediaInitDataType::Webm);
319 blink::WebMediaKeySystemConfiguration config;
320 config.hasInitDataTypes = true;
321 config.initDataTypes = init_data_types;
322 configs_.push_back(config);
324 ASSERT_TRUE(SelectConfigReturnsConfig());
325 ASSERT_EQ(1u, config_.initDataTypes.size());
326 EXPECT_EQ(blink::WebEncryptedMediaInitDataType::Webm,
327 config_.initDataTypes[0]);
330 // --- distinctiveIdentifier ---
332 TEST_F(KeySystemConfigSelectorTest, DistinctiveIdentifier_Default) {
333 key_systems_->distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
335 blink::WebMediaKeySystemConfiguration config;
336 config.distinctiveIdentifier =
337 blink::WebMediaKeySystemConfiguration::Requirement::Optional;
338 configs_.push_back(config);
340 ASSERT_TRUE(SelectConfigReturnsConfig());
341 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed,
342 config_.distinctiveIdentifier);
345 TEST_F(KeySystemConfigSelectorTest, DistinctiveIdentifier_Forced) {
346 media_permission_->is_granted = true;
347 key_systems_->distinctive_identifier = EmeFeatureSupport::ALWAYS_ENABLED;
349 blink::WebMediaKeySystemConfiguration config;
350 config.distinctiveIdentifier =
351 blink::WebMediaKeySystemConfiguration::Requirement::Optional;
352 configs_.push_back(config);
354 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
355 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required,
356 config_.distinctiveIdentifier);
359 TEST_F(KeySystemConfigSelectorTest, DistinctiveIdentifier_Blocked) {
360 key_systems_->distinctive_identifier = EmeFeatureSupport::NOT_SUPPORTED;
362 blink::WebMediaKeySystemConfiguration config;
363 config.distinctiveIdentifier =
364 blink::WebMediaKeySystemConfiguration::Requirement::Required;
365 configs_.push_back(config);
367 ASSERT_TRUE(SelectConfigReturnsError());
370 TEST_F(KeySystemConfigSelectorTest, DistinctiveIdentifier_RequestsPermission) {
371 media_permission_->is_granted = true;
372 key_systems_->distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
374 blink::WebMediaKeySystemConfiguration config;
375 config.distinctiveIdentifier =
376 blink::WebMediaKeySystemConfiguration::Requirement::Required;
377 configs_.push_back(config);
379 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
380 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required,
381 config_.distinctiveIdentifier);
384 TEST_F(KeySystemConfigSelectorTest, DistinctiveIdentifier_RespectsPermission) {
385 media_permission_->is_granted = false;
386 key_systems_->distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
388 blink::WebMediaKeySystemConfiguration config;
389 config.distinctiveIdentifier =
390 blink::WebMediaKeySystemConfiguration::Requirement::Required;
391 configs_.push_back(config);
393 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsError());
396 // --- persistentState ---
398 TEST_F(KeySystemConfigSelectorTest, PersistentState_Default) {
399 key_systems_->persistent_state = EmeFeatureSupport::REQUESTABLE;
401 blink::WebMediaKeySystemConfiguration config;
402 config.persistentState =
403 blink::WebMediaKeySystemConfiguration::Requirement::Optional;
404 configs_.push_back(config);
406 ASSERT_TRUE(SelectConfigReturnsConfig());
407 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed,
408 config_.persistentState);
411 TEST_F(KeySystemConfigSelectorTest, PersistentState_Forced) {
412 key_systems_->persistent_state = EmeFeatureSupport::ALWAYS_ENABLED;
414 blink::WebMediaKeySystemConfiguration config;
415 config.persistentState =
416 blink::WebMediaKeySystemConfiguration::Requirement::Optional;
417 configs_.push_back(config);
419 ASSERT_TRUE(SelectConfigReturnsConfig());
420 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required,
421 config_.persistentState);
424 TEST_F(KeySystemConfigSelectorTest, PersistentState_Blocked) {
425 key_systems_->persistent_state = EmeFeatureSupport::ALWAYS_ENABLED;
427 blink::WebMediaKeySystemConfiguration config;
428 config.persistentState =
429 blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed;
430 configs_.push_back(config);
432 ASSERT_TRUE(SelectConfigReturnsError());
435 // --- sessionTypes ---
437 TEST_F(KeySystemConfigSelectorTest, SessionTypes_Empty) {
438 blink::WebMediaKeySystemConfiguration config;
439 config.hasSessionTypes = true;
440 configs_.push_back(config);
442 ASSERT_TRUE(SelectConfigReturnsConfig());
443 EXPECT_TRUE(config_.sessionTypes.isEmpty());
446 TEST_F(KeySystemConfigSelectorTest, SessionTypes_SubsetSupported) {
447 // Allow persistent state, as it would be required to be successful.
448 key_systems_->persistent_state = EmeFeatureSupport::REQUESTABLE;
449 key_systems_->persistent_license = EmeSessionTypeSupport::NOT_SUPPORTED;
451 std::vector<blink::WebEncryptedMediaSessionType> session_types;
452 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary);
453 session_types.push_back(
454 blink::WebEncryptedMediaSessionType::PersistentLicense);
456 blink::WebMediaKeySystemConfiguration config;
457 config.hasSessionTypes = true;
458 config.sessionTypes = session_types;
459 configs_.push_back(config);
461 ASSERT_TRUE(SelectConfigReturnsError());
464 TEST_F(KeySystemConfigSelectorTest, SessionTypes_AllSupported) {
465 // Allow persistent state, and expect it to be required.
466 key_systems_->persistent_state = EmeFeatureSupport::REQUESTABLE;
467 key_systems_->persistent_license = EmeSessionTypeSupport::SUPPORTED;
469 std::vector<blink::WebEncryptedMediaSessionType> session_types;
470 session_types.push_back(blink::WebEncryptedMediaSessionType::Temporary);
471 session_types.push_back(
472 blink::WebEncryptedMediaSessionType::PersistentLicense);
474 blink::WebMediaKeySystemConfiguration config;
475 config.persistentState =
476 blink::WebMediaKeySystemConfiguration::Requirement::Optional;
477 config.hasSessionTypes = true;
478 config.sessionTypes = session_types;
479 configs_.push_back(config);
481 ASSERT_TRUE(SelectConfigReturnsConfig());
482 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required,
483 config_.persistentState);
484 ASSERT_EQ(2u, config_.sessionTypes.size());
485 EXPECT_EQ(blink::WebEncryptedMediaSessionType::Temporary,
486 config_.sessionTypes[0]);
487 EXPECT_EQ(blink::WebEncryptedMediaSessionType::PersistentLicense,
488 config_.sessionTypes[1]);
491 TEST_F(KeySystemConfigSelectorTest, SessionTypes_PermissionCanBeRequired) {
492 media_permission_->is_granted = true;
493 key_systems_->distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
494 key_systems_->persistent_state = EmeFeatureSupport::REQUESTABLE;
495 key_systems_->persistent_license =
496 EmeSessionTypeSupport::SUPPORTED_WITH_IDENTIFIER;
498 std::vector<blink::WebEncryptedMediaSessionType> session_types;
499 session_types.push_back(
500 blink::WebEncryptedMediaSessionType::PersistentLicense);
502 blink::WebMediaKeySystemConfiguration config;
503 config.distinctiveIdentifier =
504 blink::WebMediaKeySystemConfiguration::Requirement::Optional;
505 config.persistentState =
506 blink::WebMediaKeySystemConfiguration::Requirement::Optional;
507 config.hasSessionTypes = true;
508 config.sessionTypes = session_types;
509 configs_.push_back(config);
511 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
512 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required,
513 config_.distinctiveIdentifier);
516 // --- videoCapabilities ---
518 TEST_F(KeySystemConfigSelectorTest, VideoCapabilities_Empty) {
519 blink::WebMediaKeySystemConfiguration config;
520 config.hasVideoCapabilities = true;
521 configs_.push_back(config);
523 ASSERT_TRUE(SelectConfigReturnsError());
526 TEST_F(KeySystemConfigSelectorTest, VideoCapabilities_NoneSupported) {
527 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(2);
528 video_capabilities[0].contentType = "a";
529 video_capabilities[0].mimeType = kUnsupportedContainer;
530 video_capabilities[1].contentType = "b";
531 video_capabilities[1].mimeType = kSupportedContainer;
532 video_capabilities[1].codecs = kUnsupportedCodec;
534 blink::WebMediaKeySystemConfiguration config;
535 config.hasVideoCapabilities = true;
536 config.videoCapabilities = video_capabilities;
537 configs_.push_back(config);
539 ASSERT_TRUE(SelectConfigReturnsError());
542 TEST_F(KeySystemConfigSelectorTest, VideoCapabilities_SubsetSupported) {
543 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(2);
544 video_capabilities[0].contentType = "a";
545 video_capabilities[0].mimeType = kUnsupportedContainer;
546 video_capabilities[1].contentType = "b";
547 video_capabilities[1].mimeType = kSupportedContainer;
549 blink::WebMediaKeySystemConfiguration config;
550 config.hasVideoCapabilities = true;
551 config.videoCapabilities = video_capabilities;
552 configs_.push_back(config);
554 ASSERT_TRUE(SelectConfigReturnsConfig());
555 ASSERT_EQ(1u, config_.videoCapabilities.size());
556 EXPECT_EQ("b", config_.videoCapabilities[0].contentType);
557 EXPECT_EQ(kSupportedContainer, config_.videoCapabilities[0].mimeType);
560 TEST_F(KeySystemConfigSelectorTest, VideoCapabilities_AllSupported) {
561 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(2);
562 video_capabilities[0].contentType = "a";
563 video_capabilities[0].mimeType = kSupportedContainer;
564 video_capabilities[1].contentType = "b";
565 video_capabilities[1].mimeType = kSupportedContainer;
566 video_capabilities[1].codecs = kSupportedCodecs;
568 blink::WebMediaKeySystemConfiguration config;
569 config.hasVideoCapabilities = true;
570 config.videoCapabilities = video_capabilities;
571 configs_.push_back(config);
573 ASSERT_TRUE(SelectConfigReturnsConfig());
574 ASSERT_EQ(2u, config_.videoCapabilities.size());
575 EXPECT_EQ("a", config_.videoCapabilities[0].contentType);
576 EXPECT_EQ("b", config_.videoCapabilities[1].contentType);
579 TEST_F(KeySystemConfigSelectorTest,
580 VideoCapabilities_Codecs_SubsetSupported) {
581 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(1);
582 video_capabilities[0].contentType = "a";
583 video_capabilities[0].mimeType = kSupportedContainer;
584 video_capabilities[0].codecs = kUnsupportedCodecs;
586 blink::WebMediaKeySystemConfiguration config;
587 config.hasVideoCapabilities = true;
588 config.videoCapabilities = video_capabilities;
589 configs_.push_back(config);
591 ASSERT_TRUE(SelectConfigReturnsError());
594 TEST_F(KeySystemConfigSelectorTest, VideoCapabilities_Codecs_AllSupported) {
595 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(1);
596 video_capabilities[0].contentType = "a";
597 video_capabilities[0].mimeType = kSupportedContainer;
598 video_capabilities[0].codecs = kSupportedCodecs;
600 blink::WebMediaKeySystemConfiguration config;
601 config.hasVideoCapabilities = true;
602 config.videoCapabilities = video_capabilities;
603 configs_.push_back(config);
605 ASSERT_TRUE(SelectConfigReturnsConfig());
606 ASSERT_EQ(1u, config_.videoCapabilities.size());
607 EXPECT_EQ(kSupportedCodecs, config_.videoCapabilities[0].codecs);
610 TEST_F(KeySystemConfigSelectorTest, VideoCapabilities_Robustness_Supported) {
611 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(1);
612 video_capabilities[0].contentType = "a";
613 video_capabilities[0].mimeType = kSupportedContainer;
614 video_capabilities[0].robustness = kSupported;
616 blink::WebMediaKeySystemConfiguration config;
617 config.hasVideoCapabilities = true;
618 config.videoCapabilities = video_capabilities;
619 configs_.push_back(config);
621 ASSERT_TRUE(SelectConfigReturnsConfig());
622 ASSERT_EQ(1u, config_.videoCapabilities.size());
623 EXPECT_EQ(kSupported, config_.videoCapabilities[0].robustness);
626 TEST_F(KeySystemConfigSelectorTest, VideoCapabilities_Robustness_Unsupported) {
627 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(1);
628 video_capabilities[0].contentType = "a";
629 video_capabilities[0].mimeType = kSupportedContainer;
630 video_capabilities[0].robustness = kUnsupported;
632 blink::WebMediaKeySystemConfiguration config;
633 config.hasVideoCapabilities = true;
634 config.videoCapabilities = video_capabilities;
635 configs_.push_back(config);
637 ASSERT_TRUE(SelectConfigReturnsError());
640 TEST_F(KeySystemConfigSelectorTest,
641 VideoCapabilities_Robustness_PermissionCanBeRequired) {
642 media_permission_->is_granted = true;
643 key_systems_->distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
645 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(1);
646 video_capabilities[0].contentType = "a";
647 video_capabilities[0].mimeType = kSupportedContainer;
648 video_capabilities[0].robustness = kRequireIdentifier;
650 blink::WebMediaKeySystemConfiguration config;
651 config.hasVideoCapabilities = true;
652 config.videoCapabilities = video_capabilities;
653 configs_.push_back(config);
655 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
656 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::Required,
657 config_.distinctiveIdentifier);
660 TEST_F(KeySystemConfigSelectorTest,
661 VideoCapabilities_Robustness_PermissionCanBeRecommended) {
662 media_permission_->is_granted = false;
663 key_systems_->distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
665 std::vector<blink::WebMediaKeySystemMediaCapability> video_capabilities(1);
666 video_capabilities[0].contentType = "a";
667 video_capabilities[0].mimeType = kSupportedContainer;
668 video_capabilities[0].robustness = kRecommendIdentifier;
670 blink::WebMediaKeySystemConfiguration config;
671 config.hasVideoCapabilities = true;
672 config.videoCapabilities = video_capabilities;
673 configs_.push_back(config);
675 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
676 EXPECT_EQ(blink::WebMediaKeySystemConfiguration::Requirement::NotAllowed,
677 config_.distinctiveIdentifier);
680 // --- audioCapabilities ---
681 // These are handled by the same code as |videoCapabilities|, so only minimal
682 // additional testing is done.
684 TEST_F(KeySystemConfigSelectorTest, AudioCapabilities_SubsetSupported) {
685 std::vector<blink::WebMediaKeySystemMediaCapability> audio_capabilities(2);
686 audio_capabilities[0].contentType = "a";
687 audio_capabilities[0].mimeType = kUnsupportedContainer;
688 audio_capabilities[1].contentType = "b";
689 audio_capabilities[1].mimeType = kSupportedContainer;
691 blink::WebMediaKeySystemConfiguration config;
692 config.hasAudioCapabilities = true;
693 config.audioCapabilities = audio_capabilities;
694 configs_.push_back(config);
696 ASSERT_TRUE(SelectConfigReturnsConfig());
697 ASSERT_EQ(1u, config_.audioCapabilities.size());
698 EXPECT_EQ("b", config_.audioCapabilities[0].contentType);
699 EXPECT_EQ(kSupportedContainer, config_.audioCapabilities[0].mimeType);
702 // --- Multiple configurations ---
704 TEST_F(KeySystemConfigSelectorTest, Configurations_AllSupported) {
705 blink::WebMediaKeySystemConfiguration config;
706 config.label = "a";
707 configs_.push_back(config);
708 config.label = "b";
709 configs_.push_back(config);
711 ASSERT_TRUE(SelectConfigReturnsConfig());
712 ASSERT_EQ("a", config_.label);
715 TEST_F(KeySystemConfigSelectorTest, Configurations_SubsetSupported) {
716 blink::WebMediaKeySystemConfiguration config1;
717 config1.label = "a";
718 config1.hasInitDataTypes = true;
719 configs_.push_back(config1);
721 blink::WebMediaKeySystemConfiguration config2;
722 config2.label = "b";
723 configs_.push_back(config2);
725 ASSERT_TRUE(SelectConfigReturnsConfig());
726 ASSERT_EQ("b", config_.label);
729 TEST_F(KeySystemConfigSelectorTest,
730 Configurations_FirstRequiresPermission_Allowed) {
731 media_permission_->is_granted = true;
732 key_systems_->distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
734 blink::WebMediaKeySystemConfiguration config1;
735 config1.label = "a";
736 config1.distinctiveIdentifier =
737 blink::WebMediaKeySystemConfiguration::Requirement::Required;
738 configs_.push_back(config1);
740 blink::WebMediaKeySystemConfiguration config2;
741 config2.label = "b";
742 configs_.push_back(config2);
744 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
745 ASSERT_EQ("a", config_.label);
748 TEST_F(KeySystemConfigSelectorTest,
749 Configurations_FirstRequiresPermission_Rejected) {
750 media_permission_->is_granted = false;
751 key_systems_->distinctive_identifier = EmeFeatureSupport::REQUESTABLE;
753 blink::WebMediaKeySystemConfiguration config1;
754 config1.label = "a";
755 config1.distinctiveIdentifier =
756 blink::WebMediaKeySystemConfiguration::Requirement::Required;
757 configs_.push_back(config1);
759 blink::WebMediaKeySystemConfiguration config2;
760 config2.label = "b";
761 configs_.push_back(config2);
763 ASSERT_TRUE(SelectConfigRequestsPermissionAndReturnsConfig());
764 ASSERT_EQ("b", config_.label);
767 } // namespace media