4 <title>Verify MediaKeySession.keyStatuses with multiple updates
</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
)
19 // Even though key ids are uint8, using printable values so that
20 // they can be verified easily.
21 var key1
= stringToUint8Array('123');
22 var key2
= stringToUint8Array('4567890');
23 var rawKey1
= new Uint8Array([0xeb, 0xdd, 0x62, 0xf1, 0x68, 0x14, 0xd2, 0x7b,
24 0x68, 0xef, 0x12, 0x2a, 0xfc, 0xe4, 0xae, 0x3c]);
25 var rawKey2
= new Uint8Array([0x3c, 0xae, 0xe4, 0xfc, 0x2a, 0x12, 0xef, 0x68,
26 0x7b, 0xd2, 0x14, 0x68, 0xf1, 0x62, 0xdd, 0xeb]);
28 function processMessage(event
)
31 verifyKeyStatuses(mediaKeySession
.keyStatuses
, { expected
: [], unexpected
: [key1
, key2
] });
33 // Add key1 to the session.
35 var jwkSet
= stringToUint8Array(createJWKSet(createJWK(key1
, rawKey1
)));
36 mediaKeySession
.update(jwkSet
).catch(function(error
) {
37 forceTestFailureFromPromise(test
, error
);
41 function processKeyStatusesChange(event
)
44 // Verify that the session only contains key1.
45 dumpKeyStatuses(mediaKeySession
.keyStatuses
);
46 verifyKeyStatuses(mediaKeySession
.keyStatuses
, { expected
: [key1
], unexpected
: [key2
] });
48 // Now add key2 to the session.
50 var jwkSet
= stringToUint8Array(createJWKSet(createJWK(key2
, rawKey2
)));
51 mediaKeySession
.update(jwkSet
).catch(function(error
) {
52 forceTestFailureFromPromise(test
, error
);
55 // Verify that the session now contains key1 and key2.
56 dumpKeyStatuses(mediaKeySession
.keyStatuses
);
57 verifyKeyStatuses(mediaKeySession
.keyStatuses
, { expected
: [key1
, key2
] });
63 getSupportedInitDataType().then(function(type
) {
65 initData
= getInitData(initDataType
);
66 return navigator
.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
67 }).then(function(access
) {
68 return access
.createMediaKeys();
69 }).then(function(mediaKeys
) {
70 mediaKeySession
= mediaKeys
.createSession();
72 // There should be no keys defined yet.
73 assert_equals(mediaKeySession
.keyStatuses
.size
, 0);
75 waitForEventAndRunStep('message', mediaKeySession
, processMessage
, test
);
76 waitForEventAndRunStep('keystatuseschange', mediaKeySession
, processKeyStatusesChange
, test
);
78 return mediaKeySession
.generateRequest(initDataType
, initData
);
79 }).catch(function(error
) {
80 forceTestFailureFromPromise(test
, error
);
82 }, 'Verify MediaKeySession.keyStatuses with multiple updates.');