mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-11 16:32:59 +00:00
Bug 1351124 - Factor out ClearKey license generation in EME mochitests. r=jya
Makes it easier to re-use in the test in the next patch. MozReview-Commit-ID: 56Gbe8KFSgX --HG-- extra : rebase_source : 3e2aa140dbf4faad015c1c760fc5b18de396d848
This commit is contained in:
parent
9096e7b95d
commit
87ce56017f
@ -107,41 +107,37 @@ function SourceBufferListToString(sbl)
|
||||
return "SourceBufferList[" + sbl.map(SourceBufferToString).join(", ") + "]";
|
||||
}
|
||||
|
||||
function GenerateClearKeyLicense(licenseRequest, keyStore)
|
||||
{
|
||||
var msgStr = ArrayBufferToString(licenseRequest);
|
||||
var msg = JSON.parse(msgStr);
|
||||
|
||||
var keys = [];
|
||||
for (var i = 0; i < msg.kids.length; i++) {
|
||||
var id64 = msg.kids[i];
|
||||
var idHex = Base64ToHex(msg.kids[i]).toLowerCase();
|
||||
var key = keyStore[idHex];
|
||||
|
||||
if (key) {
|
||||
keys.push({
|
||||
"kty": "oct",
|
||||
"kid": id64,
|
||||
"k": HexToBase64(key)
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return new TextEncoder().encode(JSON.stringify({
|
||||
"keys" : keys,
|
||||
"type" : msg.type || "temporary"
|
||||
}));
|
||||
}
|
||||
|
||||
function UpdateSessionFunc(test, token, sessionType, resolve, reject) {
|
||||
return function(ev) {
|
||||
var msgStr = ArrayBufferToString(ev.message);
|
||||
var msg = JSON.parse(msgStr);
|
||||
|
||||
Log(token, "got message from CDM: " + msgStr);
|
||||
is(msg.type, sessionType, TimeStamp(token) + " key session type should match");
|
||||
ok(msg.kids, TimeStamp(token) + " message event should contain key ID array");
|
||||
|
||||
var outKeys = [];
|
||||
|
||||
for (var i = 0; i < msg.kids.length; i++) {
|
||||
var id64 = msg.kids[i];
|
||||
var idHex = Base64ToHex(msg.kids[i]).toLowerCase();
|
||||
var key = test.keys[idHex];
|
||||
|
||||
if (key) {
|
||||
Log(token, "found key " + key + " for key id " + idHex);
|
||||
outKeys.push({
|
||||
"kty":"oct",
|
||||
"kid":id64,
|
||||
"k":HexToBase64(key)
|
||||
});
|
||||
} else {
|
||||
reject(`${token} couldn't find key for key id ${idHex}`);
|
||||
}
|
||||
}
|
||||
|
||||
var update = JSON.stringify({
|
||||
"keys" : outKeys,
|
||||
"type" : msg.type
|
||||
});
|
||||
Log(token, "sending update message to CDM: " + update);
|
||||
|
||||
ev.target.update(StringToArrayBuffer(update)).then(function() {
|
||||
var license = GenerateClearKeyLicense(ev.message, test.keys);
|
||||
Log(token, "sending update message to CDM: " + (new TextDecoder().decode(license)));
|
||||
ev.target.update(license).then(function() {
|
||||
Log(token, "MediaKeySession update ok!");
|
||||
resolve(ev.target);
|
||||
}).catch(function(reason) {
|
||||
|
@ -69,29 +69,16 @@
|
||||
|
||||
.then((mediaKeys) => {
|
||||
video.setMediaKeys(mediaKeys);
|
||||
|
||||
var session = mediaKeys.createSession();
|
||||
once(session, "message", (ev) => {
|
||||
is(ev.messageType, "license-request", "Expected a license-request");
|
||||
|
||||
var keys = [];
|
||||
for (var keyid in test.keys) {
|
||||
keys.push({
|
||||
"kty":"oct",
|
||||
"kid":HexToBase64(keyid),
|
||||
"k":HexToBase64(test.keys[keyid])
|
||||
});
|
||||
}
|
||||
|
||||
var license = new TextEncoder().encode(JSON.stringify({
|
||||
"keys": keys,
|
||||
"type": test.sessionType || "temporary"
|
||||
}));
|
||||
session.update(license);
|
||||
session.update(GenerateClearKeyLicense(ev.message, test.keys));
|
||||
});
|
||||
|
||||
var json = JSON.stringify({
|
||||
"kids":Object.keys(test.keys).map(HexToBase64)
|
||||
});
|
||||
|
||||
var request = new TextEncoder().encode(json);
|
||||
session.generateRequest("keyids", request)
|
||||
.then(e => {
|
||||
|
Loading…
Reference in New Issue
Block a user