blob: 61ceda6da489432d20a58bfbba2b2a657cdb45a6 [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src=../video-test.js></script>
<script type="text/javascript">
var mock;
var promise;
var mediaKeySystemAccess;
var mediaKeys;
var mediaKeySession;
var capabilities = {};
var kids;
var iteratorArray;
var encoder = new TextEncoder();
function doTest()
{
if (!window.internals) {
failTest("Internals is required for this test.")
return;
}
run('internals.initializeMockMediaSource()');
run('mock = internals.registerMockCDM()');
run('mock.supportedDataTypes = ["keyids"]');
run('capabilities.initDataTypes = ["keyids"]');
run(`capabilities.videoCapabilities = [{ contentType: 'video/mock; codecs="mock"' }] `);
run('promise = navigator.requestMediaKeySystemAccess("org.webkit.mock", [capabilities])');
shouldResolve(promise).then(gotMediaKeySystemAccess, failTest);
}
function next() {
if (!tests.length) {
mock.unregister();
endTest()
return;
}
var nextTest = tests.shift();
consoleWrite('');
nextTest();
}
function gotMediaKeySystemAccess(result) {
mediaKeySystemAccess = result;
next();
}
function gotMediaKeys(result) {
mediaKeys = result;
next();
}
tests = [
function() {
run('promise = mediaKeySystemAccess.createMediaKeys()');
shouldResolve(promise).then(gotMediaKeys, failTest);
},
function() {
consoleWrite('Using a non-callable MediaKeySession should reject.');
run('mediaKeySession = mediaKeys.createSession("temporary")');
testExpected('typeof mediaKeySession', 'object');
run('promise = mediaKeySession.update(encoder.encode("invalid-state"))');
shouldReject(promise).then(next, next);
},
function() {
consoleWrite('Using a zero-length response should reject.');
run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })');
run('mediaKeySession = mediaKeys.createSession("temporary")');
run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))');
shouldResolve(promise).then(function() {
run('promise = mediaKeySession.update(new Uint8Array(0))');
shouldReject(promise).then(next, next);
}, next);
},
function() {
consoleWrite('Using a non-sanitizable response should reject.');
run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })');
run('mediaKeySession = mediaKeys.createSession("temporary")');
run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))');
shouldResolve(promise).then(function() {
run('promise = mediaKeySession.update(encoder.encode("invalid-response"))');
shouldReject(promise).then(next, next);
}, next);
},
function() {
consoleWrite('Using a sanitizable response should resolve.');
run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })');
run('mediaKeySession = mediaKeys.createSession("temporary")');
run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))');
shouldResolve(promise).then(function() {
run('promise = mediaKeySession.update(encoder.encode("valid-response"))');
shouldResolve(promise).then(next, next);
}, next);
},
function() {
consoleWrite('Using a sanitizable response with invalid format should resolve.');
run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })');
run('mediaKeySession = mediaKeys.createSession("temporary")');
run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))');
shouldResolve(promise).then(function() {
run('promise = mediaKeySession.update(encoder.encode("valid-response invalid-format"))');
shouldReject(promise).then(next, next);
}, next);
},
function() {
consoleWrite('A valid MediaKeySession properly dispatches keystatuseschange event.');
run('kids = JSON.stringify({ kids: [ "MTIzNDU=", "Njc4OTA=" ] })');
run('mediaKeySession = mediaKeys.createSession("temporary")');
run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))');
shouldResolve(promise).then(function() {
run('promise = mediaKeySession.update(encoder.encode("valid-response keys-changed"))');
mediaKeySession.addEventListener('keystatuseschange', function(event) {
testExpected('mediaKeySession.keyStatuses.size', 2);
testExpected('mediaKeySession.keyStatuses.has(encoder.encode("12345"))', true);
testExpected('mediaKeySession.keyStatuses.get(encoder.encode("12345"))', 'usable');
testExpected('mediaKeySession.keyStatuses.has(encoder.encode("67890"))', true);
testExpected('mediaKeySession.keyStatuses.get(encoder.encode("67890"))', 'usable');
testExpected('mediaKeySession.keyStatuses.has(encoder.encode("invalid"))', false);
testExpected('mediaKeySession.keyStatuses.get(encoder.encode("invalid"))', undefined);
iteratorArray = [];
for (var pair of mediaKeySession.keyStatuses)
iteratorArray.push([ new Uint8Array(pair[0]), pair[1] ]);
testExpected('iteratorArray.length', 2);
testArraysEqual('iteratorArray[0][0]', encoder.encode('12345'));
testExpected('iteratorArray[0][1]', 'usable');
testArraysEqual('iteratorArray[1][0]', encoder.encode('67890'));
testExpected('iteratorArray[1][1]', 'usable');
iteratorArray = [];
for (var key of mediaKeySession.keyStatuses.keys())
iteratorArray.push(new Uint8Array(key));
testExpected('iteratorArray.length', 2);
testArraysEqual('iteratorArray[0]', encoder.encode('12345'));
testArraysEqual('iteratorArray[1]', encoder.encode('67890'));
iteratorArray = [];
for (var value of mediaKeySession.keyStatuses.values())
iteratorArray.push(value);
testArraysEqual('iteratorArray', [ 'usable', 'usable' ]);
iteratorArray = [];
for (var entry of mediaKeySession.keyStatuses.entries())
iteratorArray.push({ key: new Uint8Array(entry[0]), value: entry[1] });
testExpected('iteratorArray.length', 2);
testArraysEqual('iteratorArray[0].key', encoder.encode('12345'));
testExpected('iteratorArray[0].value', 'usable');
testArraysEqual('iteratorArray[1].key', encoder.encode('67890'));
testExpected('iteratorArray[1].value', 'usable');
iteratorArray = [];
mediaKeySession.keyStatuses.forEach(function(value, key) {
iteratorArray.push({ key: new Uint8Array(key), value: value });
});
testExpected('iteratorArray.length', 2);
testArraysEqual('iteratorArray[0].key', encoder.encode('12345'));
testExpected('iteratorArray[0].value', 'usable');
testArraysEqual('iteratorArray[1].key', encoder.encode('67890'));
testExpected('iteratorArray[1].value', 'usable');
shouldResolve(promise).then(next, next);
}, false);
}, next);
},
];
</script>
</head>
<body onload="doTest()">
</body>
</html>