| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src=../video-test.js></script> |
| <script type="text/javascript"> |
| var mock; |
| var promise; |
| var mediaKeySystemAccess; |
| var mediaKeys; |
| 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('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; |
| run('promise = mediaKeySystemAccess.createMediaKeys()'); |
| shouldResolve(promise).then(gotMediaKeys, failTest); |
| } |
| |
| 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 = [ |
| // Behavior 4 (temporary sessions): "All licenses and keys associated with a Key |
| // Session not explicitly stored MUST be destroyed when the session is closed." |
| // Temporary sessions have no persisted state and lose their keys on close(). |
| function() { |
| consoleWrite('Temporary session: keys are purged when the session is closed.'); |
| run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })'); |
| run('window.tempSession = mediaKeys.createSession("temporary")'); |
| run('promise = window.tempSession.generateRequest("keyids", stringToUInt8Array(kids))'); |
| shouldResolve(promise).then(() => { |
| run('window.tempSessionID = window.tempSession.sessionId'); |
| testExpected('mock.keyCountForSession(window.tempSessionID)', 1); |
| run('promise = window.tempSession.close()'); |
| return shouldResolve(promise); |
| }).then(() => { |
| testExpected('mock.keyCountForSession(window.tempSessionID)', 0); |
| next(); |
| }, next); |
| }, |
| |
| // Behavior 4 (persistent-license sessions): keys are retained across close() |
| // because they are "explicitly stored" and can be reloaded via load(). |
| function() { |
| consoleWrite('Persistent-license session: keys are retained across close.'); |
| run('kids = JSON.stringify({ kids: [ "Njc4OTA=" ] })'); |
| run('window.persistSession = mediaKeys.createSession("persistent-license")'); |
| run('promise = window.persistSession.generateRequest("keyids", stringToUInt8Array(kids))'); |
| shouldResolve(promise).then(() => { |
| run('window.persistSessionID = window.persistSession.sessionId'); |
| testExpected('mock.keyCountForSession(window.persistSessionID)', 1); |
| run('promise = window.persistSession.close()'); |
| return shouldResolve(promise); |
| }).then(() => { |
| testExpected('mock.keyCountForSession(window.persistSessionID)', 1); |
| next(); |
| }, next); |
| }, |
| |
| // Behavior 4 corollary: a fresh persistent-license session can load() a previously |
| // closed session's ID and observe the retained keys. |
| function() { |
| consoleWrite('Persistent-license: load() restores a previously stored session.'); |
| run('window.loadedSession = mediaKeys.createSession("persistent-license")'); |
| run('promise = window.loadedSession.load(window.persistSessionID)'); |
| shouldResolve(promise).then(() => { |
| testExpected('window.loadedSession.sessionId === window.persistSessionID', true); |
| testExpected('mock.keyCountForSession(window.loadedSession.sessionId)', 1); |
| next(); |
| }, next); |
| }, |
| ]; |
| </script> |
| </head> |
| <body onload="doTest()"> |
| </body> |
| </html> |