4 <title>Verify MediaKeySession.keyStatuses with multiple sessions
</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 processMessage1(event
)
30 // This should only be called for session1.
31 assert_equals(event
.target
, mediaKeySession1
);
34 verifyKeyStatuses(mediaKeySession1
.keyStatuses
, { expected
: [], unexpected
: [key1
, key2
] });
36 // Add key1 to session1.
37 var jwkSet
= stringToUint8Array(createJWKSet(createJWK(key1
, rawKey1
)));
38 mediaKeySession1
.update(jwkSet
).catch(function(error
) {
39 forceTestFailureFromPromise(test
, error
);
43 function processKeyStatusesChange1(event
)
45 // This should only be called for session1.
46 assert_equals(event
.target
, mediaKeySession1
);
48 // Check that keyStatuses contains the expected key1 only.
49 dumpKeyStatuses(mediaKeySession1
.keyStatuses
);
50 verifyKeyStatuses(mediaKeySession1
.keyStatuses
, { expected
: [key1
], unexpected
: [key2
] });
52 // Now trigger a message event on session2.
53 mediaKeySession2
.generateRequest(initDataType
, initData
).catch(function(error
) {
54 forceTestFailureFromPromise(test
, error
);
58 function processMessage2(event
)
60 // This should only be called for session2.
61 assert_equals(event
.target
, mediaKeySession2
);
63 // session2 has no keys added yet.
64 verifyKeyStatuses(mediaKeySession2
.keyStatuses
, { expected
: [], unexpected
: [key1
, key2
] });
66 // session1 should still have 1 key.
67 verifyKeyStatuses(mediaKeySession1
.keyStatuses
, { expected
: [key1
], unexpected
: [key2
] });
69 // Add key2 to session2.
70 var jwkSet
= stringToUint8Array(createJWKSet(createJWK(key2
, rawKey2
)));
71 mediaKeySession2
.update(jwkSet
).catch(function(error
) {
72 forceTestFailureFromPromise(test
, error
);
76 function processKeyStatusesChange2(event
)
78 // This should only be called for session2.
79 assert_equals(event
.target
, mediaKeySession2
);
81 // Check that keyStatuses contains the expected key2 only.
82 dumpKeyStatuses(mediaKeySession2
.keyStatuses
);
83 verifyKeyStatuses(mediaKeySession2
.keyStatuses
, { expected
: [key2
], unexpected
: [key1
] });
85 // session1 should still have 1 key.
86 verifyKeyStatuses(mediaKeySession1
.keyStatuses
, { expected
: [key1
], unexpected
: [key2
] });
91 getSupportedInitDataType().then(function(type
) {
93 initData
= getInitData(initDataType
);
94 return navigator
.requestMediaKeySystemAccess('org.w3.clearkey', [{}]);
95 }).then(function(access
) {
96 return access
.createMediaKeys();
97 }).then(function(mediaKeys
) {
98 mediaKeySession1
= mediaKeys
.createSession();
99 mediaKeySession2
= mediaKeys
.createSession();
101 // There should be no keys defined on either session.
102 verifyKeyStatuses(mediaKeySession1
.keyStatuses
, { expected
: [], unexpected
: [key1
, key2
] });
103 verifyKeyStatuses(mediaKeySession2
.keyStatuses
, { expected
: [], unexpected
: [key1
, key2
] });
105 // Bind all the event handlers now.
106 waitForEventAndRunStep('message', mediaKeySession1
, processMessage1
, test
);
107 waitForEventAndRunStep('message', mediaKeySession2
, processMessage2
, test
);
108 waitForEventAndRunStep('keystatuseschange', mediaKeySession1
, processKeyStatusesChange1
, test
);
109 waitForEventAndRunStep('keystatuseschange', mediaKeySession2
, processKeyStatusesChange2
, test
);
111 // Generate a request on session1.
112 return mediaKeySession1
.generateRequest(initDataType
, initData
);
113 }).catch(function(error
) {
114 forceTestFailureFromPromise(test
, error
);
116 }, 'Verify MediaKeySession.keyStatuses with multiple sessions.');