| <!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('Closing a non-callable MediaKeySession should reject.'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| testExpected('typeof mediaKeySession', 'object'); |
| run('promise = mediaKeySession.close()'); |
| shouldReject(promise).then(next, next); |
| }, |
| |
| function() { |
| consoleWrite('Closing 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.close()'); |
| shouldReject(promise).then(next, next); |
| }, next); |
| }, |
| |
| function() { |
| consoleWrite('Closing 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.close()'); |
| shouldResolve(promise).then(next, next); |
| }, next); |
| }, |
| |
| function() { |
| consoleWrite('Closing a valid MediaKeySession should resolve the "closed" promise.') |
| run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))'); |
| shouldResolve(promise).then(function() { |
| shouldResolve(mediaKeySession.closed).then(function() { |
| consoleWrite('"closed" promise correctly resolved.'); |
| next(); |
| }, next); |
| |
| run('promise = mediaKeySession.close()'); |
| shouldResolve(promise); |
| }, next); |
| }, |
| |
| function() { |
| consoleWrite('Already closed MediaKeySession should resolve the "closed" promise immediately.'); |
| 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.close()'); |
| shouldResolve(promise).then(function() { |
| shouldResolve(mediaKeySession.closed).then(function () { |
| consoleWrite('"closed" promise correctly resolved.'); |
| next(); |
| }, next); |
| }, next); |
| }, next); |
| }, |
| |
| function() { |
| consoleWrite('Closing a closed 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.close()'); |
| shouldResolve(promise).then(function() { |
| run('promise = mediaKeySession.close()'); |
| shouldResolve(promise).then(next, next); |
| }, next); |
| }, next); |
| }, |
| |
| function() { |
| consoleWrite('Operating on a closed MediaKeySession should resolve for close(), reject otherwise.') |
| 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.close()'); |
| shouldResolve(promise).then(function() { |
| run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))'); |
| shouldReject(promise).then(function() { |
| run('promise = mediaKeySession.update(encoder.encode("some-data"))'); |
| shouldReject(promise).then(function() { |
| run('promise = mediaKeySession.close()'); |
| shouldResolve(promise).then(function() { |
| run('promise = mediaKeySession.remove()'); |
| shouldReject(promise).then(next, next); |
| }, next); |
| }, next); |
| }, next); |
| }, next); |
| }, next); |
| }, |
| ]; |
| </script> |
| </head> |
| <body onload="doTest()"> |
| </body> |
| </html> |