Skip to content

Commit

Permalink
Test handleEncryptedEvent gets fired after ended
Browse files Browse the repository at this point in the history
  • Loading branch information
Essk committed Aug 5, 2024
1 parent d488416 commit e99939f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 14 deletions.
5 changes: 2 additions & 3 deletions src/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const removeSession = (sessions, initData) => {
}
};

export const handleEncryptedEvent = (player, event, options, sessions, eventBus, emeError) => {
export function handleEncryptedEvent(player, event, options, sessions, eventBus, emeError) {
if (!options || !options.keySystems) {
// return silently since it may be handled by a different system
return Promise.resolve();
Expand Down Expand Up @@ -89,7 +89,6 @@ export const handleEncryptedEvent = (player, event, options, sessions, eventBus,
}

sessions.push({ initData });

return standard5July2016({
player,
video: event.target,
Expand All @@ -109,7 +108,7 @@ export const handleEncryptedEvent = (player, event, options, sessions, eventBus,

emeError(error, metadata);
});
};
}

export const handleWebKitNeedKeyEvent = (event, options, eventBus, emeError) => {
if (!options.keySystems || !options.keySystems[LEGACY_FAIRPLAY_KEY_SYSTEM] || !event.initData) {
Expand Down
31 changes: 20 additions & 11 deletions test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -518,9 +518,11 @@ QUnit.test('handleEncryptedEvent uses predefined init data', function(assert) {
});
});

QUnit.skip('handleEncryptedEvent called on replay or seekback after `ended` ', function(assert) {
QUnit.test('handleEncryptedEvent called explicitly on replay or seekback after `ended` if browser is Firefox ', function(assert) {
const done = assert.async();

this.clock = sinon.useFakeTimers();

videojs.browser = {
IS_FIREFOX: true
};
Expand All @@ -529,17 +531,24 @@ QUnit.skip('handleEncryptedEvent called on replay or seekback after `ended` ', f
this.player.trigger('ready');
this.player.trigger('play');

const handleEncryptedEventSpy = sinon.stub(plug, 'setupSessions');

setTimeout(() => {
this.player.trigger('ended');
plug.handleEncryptedEvent = sinon.spy();

setTimeout(() => {
this.player.trigger('play');
assert.ok(handleEncryptedEventSpy.calledOnce, 'successfully');
done();
}, 0);
}, 0);
this.clock.tick(1);
this.player.trigger('ended');
this.clock.tick(1);
this.player.trigger('play');
assert.ok(plug.handleEncryptedEvent.calledOnce, 'HandleEncryptedEvent called if play fires after ended');
plug.handleEncryptedEvent.resetHistory();
this.player.trigger('ended');
this.player.trigger('seek');
assert.ok(plug.handleEncryptedEvent.calledOnce, 'HandleEncryptedEvent called if seek fires after ended');
plug.handleEncryptedEvent.resetHistory();
this.player.trigger('ended');
this.player.trigger('seek');
this.player.trigger('play');
assert.ok(plug.handleEncryptedEvent.calledOnce, 'HandleEncryptedEvent only called once if seek and play both fire after ended');
sinon.restore();
done();
});

QUnit.test('handleMsNeedKeyEvent uses predefined init data', function(assert) {
Expand Down

0 comments on commit e99939f

Please sign in to comment.