| <!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('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('Removing from a non-callable MediaKeySession should reject.'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| testExpected('typeof mediaKeySession', 'object'); |
| run('promise = mediaKeySession.remove()'); |
| shouldReject(promise).then(next, next); |
| }, |
| |
| function() { |
| consoleWrite('Removing from a failed MediaKeySession should reject.'); |
| run('kids = JSON.stringify({ invalid: "invalid" })'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))'); |
| shouldReject(promise).then(function() { |
| run('promise = mediaKeySession.remove()'); |
| shouldReject(promise).then(next, next); |
| }, next); |
| }, |
| |
| function() { |
| consoleWrite('Removing from a valid MediaKeySession 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.remove()'); |
| shouldResolve(promise).then(next, next); |
| }, next); |
| }, |
| |
| function() { |
| consoleWrite('Removing from a valid MediaKeySession should dispatch a license-release message.'); |
| 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.remove()'); |
| mediaKeySession.addEventListener('message', function(event) { |
| testExpected('event.messageType', 'license-release'); |
| testArraysEqual('new Uint8Array(event.message)', encoder.encode("remove-message")); |
| |
| shouldResolve(promise).then(next, next); |
| }, true); |
| }, next); |
| }, |
| ]; |
| </script> |
| </head> |
| <body onload="doTest()"> |
| </body> |
| </html> |