| <!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 = {}; |
| |
| function doTest() |
| { |
| if (!window.internals) { |
| failTest("Internals is required for this test.") |
| return; |
| } |
| |
| run('internals.initializeMockMediaSource()'); |
| run('mock = internals.registerMockCDM()'); |
| run('mock.supportedDataTypes = ["mock"]'); |
| run('capabilities.initDataTypes = ["mock"]'); |
| 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() { |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| testExpected('typeof mediaKeySession', 'object') |
| next(); |
| }, |
| |
| function() { |
| run('mock.supportedSessionTypes = ["temporary"]'); |
| testDOMException('mediaKeySession = mediaKeys.createSession("persistent-license")', 'DOMException.NOT_SUPPORTED_ERR'); |
| next(); |
| }, |
| |
| function() { |
| run('mock.supportsSessions = false'); |
| testDOMException('mediaKeySession = mediaKeys.createSession("temporary")', 'DOMException.INVALID_STATE_ERR'); |
| next(); |
| } |
| ]; |
| </script> |
| </head> |
| <body onload="doTest()"> |
| </body> |
| </html> |