Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
harisha-swaminathan committed Jul 22, 2024
1 parent 0e81954 commit d488416
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 2 deletions.
45 changes: 44 additions & 1 deletion test/eme.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ QUnit.test('keystatuseschange triggers keystatuschange on eventBus for each key'

});

QUnit.test('keystatuseschange with expired key closes and recreates session', function(assert) {
QUnit.test('keystatuseschange with expired key closes', function(assert) {
const removeSessionCalls = [];
// once the eme module gets the removeSession function, the session argument is already
// bound to the function (note that it's a custom session maintained by the plugin, not
Expand Down Expand Up @@ -259,6 +259,49 @@ QUnit.test('keystatuseschange with expired key closes and recreates session', fu
// synchronously
assert.equal(removeSessionCalls.length, 1, 'called remove session');
assert.equal(removeSessionCalls[0], initData, 'called to remove session with initData');

assert.equal(creates, 1, 'no new session created');
});

QUnit.test('all existing sessions are closed and removed on `ended`', function(assert) {
const removeSessionCalls = [];
// once the eme module gets the removeSession function, the session argument is already
// bound to the function (note that it's a custom session maintained by the plugin, not
// the native session), so only initData is passed
const removeSession = (initData) => removeSessionCalls.push(initData);
const initData = new Uint8Array([1, 2, 3]);
const mockSession = getMockSession();
const eventBus = {
trigger: (name) => {},
isDisposed: () => {
return false;
}
};
let creates = 0;

makeNewRequest(this.player, {
mediaKeys: {
createSession: () => {
creates++;

return mockSession;
}
},
initDataType: '',
initData,
options: {},
getLicense() {},
removeSession,
eventBus
});

assert.equal(creates, 1, 'created session');
assert.equal(mockSession.listeners.length, 2, 'added listeners');

this.player.trigger('ended');

assert.equal(mockSession.numCloses, 1, 'closed session');
assert.equal(removeSessionCalls.length, 1, 'called remove session');
});

QUnit.test('keystatuseschange with internal-error logs a warning', function(assert) {
Expand Down
26 changes: 25 additions & 1 deletion test/plugin.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import QUnit from 'qunit';
import sinon from 'sinon';
import videojs from 'video.js';
import window from 'global/window';

import * as plug from '../src/plugin';
import {
default as plugin,
hasSession,
Expand Down Expand Up @@ -518,6 +518,30 @@ QUnit.test('handleEncryptedEvent uses predefined init data', function(assert) {
});
});

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

videojs.browser = {
IS_FIREFOX: true
};
this.player.eme();

this.player.trigger('ready');
this.player.trigger('play');

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

setTimeout(() => {
this.player.trigger('ended');

setTimeout(() => {
this.player.trigger('play');
assert.ok(handleEncryptedEventSpy.calledOnce, 'successfully');
done();
}, 0);
}, 0);
});

QUnit.test('handleMsNeedKeyEvent uses predefined init data', function(assert) {
const options = {
keySystems: {
Expand Down

0 comments on commit d488416

Please sign in to comment.