| <!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; |
| |
| 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(); |
| } |
| |
| function stringToUInt8Array(str) |
| { |
| var array = new Uint8Array(str.length); |
| for (var i=0; i<str.length; i++) |
| array[i] = str.charCodeAt(i); |
| return array; |
| } |
| |
| tests = [ |
| function() { |
| run('promise = mediaKeySystemAccess.createMediaKeys()'); |
| shouldResolve(promise).then(gotMediaKeys, failTest); |
| }, |
| |
| function() { |
| consoleWrite('Using an invalid initDataType string should reject.') |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| testExpected('typeof mediaKeySession', 'object') |
| run('promise = mediaKeySession.generateRequest("invalid", stringToUInt8Array("invalid"))'); |
| shouldReject(promise).then(next, next); |
| }, |
| |
| function() { |
| consoleWrite('Re-using a failed mediaKeySession should reject.') |
| run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })'); |
| run('promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids))'); |
| shouldReject(promise).then(next, next); |
| }, |
| |
| function() { |
| consoleWrite('Using a new mediaKeySession should resolve.') |
| run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| run('promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids))'); |
| shouldResolve(promise).then(next, next); |
| }, |
| |
| function() { |
| consoleWrite('Using invalid initData should reject.') |
| run('kids = JSON.stringify({ invalid: "invalid" })'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| run('promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids))'); |
| shouldReject(promise).then(next, next); |
| }, |
| |
| function() { |
| consoleWrite('Using initData with extraneous information should resolve.') |
| run('kids = JSON.stringify({ kids: [ "MTIzNDU="], invalid: "invalid" })'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| run('promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids))'); |
| shouldResolve(promise).then(next, next); |
| }, |
| |
| function() { |
| consoleWrite('initData is encoded in base64url.') |
| run('kids = JSON.stringify({ kids: [ "ig2FRSEF1BU1j-qPaObBkQ"] })'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| run('promise = mediaKeySession.generateRequest("keyids", stringToUInt8Array(kids))'); |
| shouldResolve(promise).then(next, next); |
| }, |
| ]; |
| </script> |
| </head> |
| <body onload="doTest()"> |
| </body> |
| </html> |