Skip to content

Commit

Permalink
Don't require EME closed promises to resolve in any specific order (#…
Browse files Browse the repository at this point in the history
…46268)

The promise from .close and from .closed() should be equivalent in all cases.  So long as both promises resolve in the correct order relative to everything else, that should be sufficient.
  • Loading branch information
joeyparrish authored May 14, 2024
1 parent b70defd commit 915d40b
Showing 1 changed file with 21 additions and 7 deletions.
28 changes: 21 additions & 7 deletions encrypted-media/scripts/playback-temporary-events.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ function runTest(config,qualifier) {
_mediaKeys,
_mediaKeySession,
_mediaSource,
_resolvedClosePromises = 0,
_timeupdateEvent = false,
_events = [ ];

Expand Down Expand Up @@ -75,29 +76,42 @@ function runTest(config,qualifier) {
}).catch(onFailure);
}

function onClosed(event) {
_events.push('closed-attribute-resolved');
function onAllClosed() {
setTimeout(test.step_func(function() {
checkEventSequence( _events,
['generaterequest',
['license-request', 'license-request-response', 'update-resolved'], // potentially repeating
'allkeysusable',
'playing',
'closed-attribute-resolved',
'close-promise-resolved',
'closed-promise-0',
'closed-promise-1',
'emptykeyslist']);
test.done();
} ), 0);
}

function onClosed() {
// The two closed Promises are equivalent in every way. The order between them does not matter.
// But both should be resolved at the right time relative to the other events.
// We generate numbered events for them (e.g. 'closed-promise-0') so they can both be placed in
// the overall timeline, but we don't care which is which.
_events.push('closed-promise-' + _resolvedClosePromises);
_resolvedClosePromises++;
}

function onTimeupdate(event) {
if (_video.currentTime > (config.duration || 1) && !_timeupdateEvent) {
_timeupdateEvent = true;
_video.pause();

_mediaKeySession.closed.then(test.step_func(onClosed));
_mediaKeySession.close().then(function() {
_events.push('close-promise-resolved');
var closedAttributePromise = _mediaKeySession.closed;
var closeMethodPromise = _mediaKeySession.close();

closedAttributePromise.then(onClosed);
closeMethodPromise.then(onClosed);

Promise.all([ closedAttributePromise, closeMethodPromise ]).then(function() {
test.step_func(onAllClosed);
}).catch(onFailure);
}
}
Expand Down

0 comments on commit 915d40b

Please sign in to comment.