diff --git a/src/plugin.js b/src/plugin.js index 6a46642..a9aa310 100644 --- a/src/plugin.js +++ b/src/plugin.js @@ -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(); @@ -89,7 +89,6 @@ export const handleEncryptedEvent = (player, event, options, sessions, eventBus, } sessions.push({ initData }); - return standard5July2016({ player, video: event.target, @@ -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) { diff --git a/test/plugin.test.js b/test/plugin.test.js index d9604fc..c6f0af0 100644 --- a/test/plugin.test.js +++ b/test/plugin.test.js @@ -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 }; @@ -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) {