blob: 35f85565dabe15ae7a9d9fffe3234de22721d163 [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 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('capabilities.sessionTypes = [ "temporary", "persistent-license" ]');
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('Loading MediaKeySession with a persistent license and empty ID should reject.');
run('mediaKeySession = mediaKeys.createSession("persistent-license")');
testExpected('typeof mediaKeySession', 'object');
run('promise = mediaKeySession.load("")');
shouldReject(promise).then(next, next);
},
function() {
consoleWrite('Loading MediaKeySession with a temporary license should reject.');
run('mediaKeySession = mediaKeys.createSession("temporary")');
testExpected('typeof mediaKeySession', 'object');
run('promise = mediaKeySession.load("valid-loaded-session")');
shouldReject(promise).then(next, next);
},
function() {
consoleWrite('Loading MediaKeySession with a non-sanitizable ID should reject.');
run('mediaKeySession = mediaKeys.createSession("persistent-license")');
testExpected('typeof mediaKeySession', 'object');
run('promise = mediaKeySession.load("non-sanitizable-loaded-session")');
shouldReject(promise).then(next, next);
},
function() {
consoleWrite('Loading MediaKeySession should resolve.');
run('mediaKeySession = mediaKeys.createSession("persistent-license")');
testExpected('typeof mediaKeySession', 'object');
run('promise = mediaKeySession.load("valid-loaded-session")');
mediaKeySession.addEventListener('message', function(event) {
testExpected('event.messageType', 'license-renewal');
testArraysEqual('new Uint8Array(event.message)', encoder.encode('session loaded'));
shouldResolve(promise).then(function(result) {
if (result)
consoleWrite('Load was successful.');
next();
}, next);
}, true);
},
];
</script>
</head>
<body onload="doTest()">
</body>
</html>