4 <title>Verify MediaKeySession.keyStatuses
</title>
5 <script src=
"encrypted-media-utils.js"></script>
6 <script src=
"../../resources/testharness.js"></script>
7 <script src=
"../../resources/testharnessreport.js"></script>
12 async_test(function(test
)
18 // Even though key ids are uint8, using printable values so that
19 // they can be verified easily.
20 var key1String
= '123';
21 var key2String
= '4567890';
22 var key1
= stringToUint8Array(key1String
);
23 var key2
= stringToUint8Array(key2String
);
24 var rawKey1
= new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
25 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
26 var rawKey2
= new Uint8Array([0x3c, 0xae, 0xe4, 0xfc, 0x2a, 0x12, 0xef, 0x68,
27 0x7b, 0xd2, 0x14, 0x68, 0xf1, 0x62, 0xdd, 0xeb]);
29 function processMessage(event
)
32 assert_equals(mediaKeySession
.keyStatuses
.size
, 0);
34 waitForEventAndRunStep('keystatuseschange', mediaKeySession
, processKeyStatusesChange
, test
);
36 var jwkSet
= stringToUint8Array(createJWKSet(createJWK(key1
, rawKey1
), createJWK(key2
, rawKey2
)));
37 mediaKeySession
.update(jwkSet
).catch(function(error
) {
38 forceTestFailureFromPromise(test
, error
);
42 function processKeyStatusesChange(event
)
44 // Two keys added, so both should show up in |keyStatuses|.
45 assert_equals(mediaKeySession
.keyStatuses
.size
, 2);
46 dumpKeyStatuses(mediaKeySession
.keyStatuses
);
48 // Check |keyStatuses| for 2 entries.
50 for (var entry
of mediaKeySession
.keyStatuses
) {
51 result
.push({ key
: arrayBufferAsString(entry
[0]), value
: entry
[1] });
53 assert_object_equals(result
,
54 [{ key
: key1String
, value
: 'usable'}, { key
: key2String
, value
: 'usable'}],
57 // |keyStatuses| must contain both keys.
59 for (var key
of mediaKeySession
.keyStatuses
.keys()) {
60 result
.push(arrayBufferAsString(key
));
62 assert_array_equals(result
,
63 [key1String
, key2String
],
64 'keyStatuses.keys() fails');
66 // Both values in |mediaKeySession| should be 'usable'.
68 for (var value
of mediaKeySession
.keyStatuses
.values()) {
71 assert_array_equals(result
,
73 'keyStatuses.values() fails');
75 // Check |keyStatuses.entries()|.
77 for (var entry
of mediaKeySession
.keyStatuses
.entries()) {
78 result
.push({ key
: arrayBufferAsString(entry
[0]), value
: entry
[1] });
80 assert_object_equals(result
,
81 [{ key
: key1String
, value
: 'usable'}, { key
: key2String
, value
: 'usable'}],
82 'keyStatuses.entries() fails');
84 // forEach() should return both entries.
86 mediaKeySession
.keyStatuses
.forEach(function(value
, key
, map
) {
87 result
.push({ key
: arrayBufferAsString(key
), value
: value
});
89 assert_object_equals(result
,
90 [{ key
: key1String
, value
: 'usable'}, { key
: key2String
, value
: 'usable'}],
91 'keyStatuses.forEach() fails');
93 assert_true(mediaKeySession
.keyStatuses
.has(key1
));
94 assert_true(mediaKeySession
.keyStatuses
.has(key2
));
95 assert_false(mediaKeySession
.keyStatuses
.has(stringToUint8Array('123456')));
96 assert_equals(mediaKeySession
.keyStatuses
.get(key1
), 'usable');
97 assert_equals(mediaKeySession
.keyStatuses
.get(key2
), 'usable');
98 assert_equals(mediaKeySession
.keyStatuses
.get(stringToUint8Array('123456')), undefined);
103 getSupportedInitDataType().then(function(type
) {
105 initData
= getInitData(initDataType
);
106 return navigator
.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
107 }).then(function(access
) {
108 return access
.createMediaKeys();
109 }).then(function(mediaKeys
) {
110 mediaKeySession
= mediaKeys
.createSession();
112 // There should be no keys defined yet.
113 assert_equals(mediaKeySession
.keyStatuses
.size
, 0);
115 waitForEventAndRunStep('message', mediaKeySession
, processMessage
, test
);
116 return mediaKeySession
.generateRequest(initDataType
, initData
);
117 }).catch(function(error
) {
118 forceTestFailureFromPromise(test
, error
);
120 }, 'Verify MediaKeySession.keyStatuses.');