| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src=../video-test.js></script> |
| <script type="text/javascript"> |
| // Regression test: two concurrent close() calls on the same MediaKeySession must not resolve the |
| // "closed" promise twice. Each close() checks m_closed before queuing its work, but m_closed is only |
| // set when the queued task runs, so both calls queue a sessionClosed() task; resolving the "closed" |
| // promise a second time previously tripped an assertion in DOMPromiseProxy::resolve(). |
| var mock; |
| var promise; |
| var promise2; |
| 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 gotMediaKeySystemAccess(result) { |
| mediaKeySystemAccess = result; |
| run('promise = mediaKeySystemAccess.createMediaKeys()'); |
| shouldResolve(promise).then(gotMediaKeys, failTest); |
| } |
| |
| function gotMediaKeys(result) { |
| mediaKeys = result; |
| run('kids = JSON.stringify({ kids: [ "MTIzNDU=" ] })'); |
| run('mediaKeySession = mediaKeys.createSession("temporary")'); |
| run('promise = mediaKeySession.generateRequest("keyids", encoder.encode(kids))'); |
| shouldResolve(promise).then(closeConcurrently, failTest); |
| } |
| |
| function closeConcurrently() { |
| consoleWrite('Two concurrent close() calls should both resolve without crashing.'); |
| run('promise = mediaKeySession.close()'); |
| run('promise2 = mediaKeySession.close()'); |
| // Wait on the raw promises (no per-promise logging) so completion order does not affect the output. |
| Promise.all([promise, promise2, mediaKeySession.closed]).then(finish, failTest); |
| } |
| |
| function finish() { |
| consoleWrite('Survived concurrent close() and the "closed" promise resolved exactly once.'); |
| mock.unregister(); |
| endTest(); |
| } |
| </script> |
| </head> |
| <body onload="doTest()"> |
| </body> |
| </html> |