mirror of
https://github.com/DanielnetoDotCom/YouPHPTube
synced 2025-10-05 19:42:38 +02:00
Moving to node_modules folder to make easier to upgrade
trying to move from Bootstrap 3 to Bootstrap 5
This commit is contained in:
parent
047e363a16
commit
d4d042e041
8460 changed files with 1355889 additions and 547977 deletions
61
node_modules/videojs-contrib-ads/test/unit/states/abstract/test.AdState.js
generated
vendored
Normal file
61
node_modules/videojs-contrib-ads/test/unit/states/abstract/test.AdState.js
generated
vendored
Normal file
|
@ -0,0 +1,61 @@
|
|||
import QUnit from 'qunit';
|
||||
import AdState from '../../../../src/states/abstract/AdState.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('AdState', {
|
||||
beforeEach() {
|
||||
this.player = {
|
||||
ads: {}
|
||||
};
|
||||
|
||||
this.adState = new AdState(this.player);
|
||||
this.adState.transitionTo = (newState) => {
|
||||
this.newState = newState.name;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('does not start out with content resuming', function(assert) {
|
||||
assert.equal(this.adState.contentResuming, false);
|
||||
});
|
||||
|
||||
QUnit.test('is an ad state', function(assert) {
|
||||
assert.equal(this.adState.isAdState(), true);
|
||||
});
|
||||
|
||||
QUnit.test('transitions to ContentPlayback on playing if content resuming', function(assert) {
|
||||
this.adState.contentResuming = true;
|
||||
this.adState.onPlaying();
|
||||
assert.equal(this.newState, 'ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('doesn\'t transition on playing if content not resuming', function(assert) {
|
||||
this.adState.onPlaying();
|
||||
assert.equal(this.newState, undefined, 'no transition');
|
||||
});
|
||||
|
||||
QUnit.test('transitions to ContentPlayback on contentresumed if content resuming', function(assert) {
|
||||
this.adState.contentResuming = true;
|
||||
this.adState.onContentResumed();
|
||||
assert.equal(this.newState, 'ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('doesn\'t transition on contentresumed if content not resuming', function(assert) {
|
||||
this.adState.onContentResumed();
|
||||
assert.equal(this.newState, undefined, 'no transition');
|
||||
});
|
||||
|
||||
QUnit.test('can check if content is resuming', function(assert) {
|
||||
assert.equal(this.adState.isContentResuming(), false, 'not resuming');
|
||||
this.adState.contentResuming = true;
|
||||
assert.equal(this.adState.isContentResuming(), true, 'resuming');
|
||||
});
|
||||
|
||||
QUnit.test('can check if in ad break', function(assert) {
|
||||
assert.equal(this.adState.inAdBreak(), false, 'not in ad break');
|
||||
this.player.ads._inLinearAdMode = true;
|
||||
assert.equal(this.adState.inAdBreak(), true, 'in ad break');
|
||||
});
|
46
node_modules/videojs-contrib-ads/test/unit/states/abstract/test.ContentState.js
generated
vendored
Normal file
46
node_modules/videojs-contrib-ads/test/unit/states/abstract/test.ContentState.js
generated
vendored
Normal file
|
@ -0,0 +1,46 @@
|
|||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
import ContentState from '../../../../src/states/abstract/ContentState.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('ContentState', {
|
||||
beforeEach() {
|
||||
this.player = {
|
||||
ads: {
|
||||
debug: () => {}
|
||||
}
|
||||
};
|
||||
|
||||
this.contentState = new ContentState(this.player);
|
||||
this.contentState.transitionTo = (newState) => {
|
||||
this.newState = newState.name;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('is not an ad state', function(assert) {
|
||||
assert.equal(this.contentState.isAdState(), false);
|
||||
});
|
||||
|
||||
QUnit.test('handles content changed when not playing', function(assert) {
|
||||
this.player.paused = () => true;
|
||||
this.player.pause = sinon.stub();
|
||||
|
||||
this.contentState.onContentChanged(this.player);
|
||||
assert.equal(this.newState, 'BeforePreroll');
|
||||
assert.equal(this.player.pause.callCount, 0, 'did not pause player');
|
||||
assert.ok(!this.player.ads._pausedOnContentupdate, 'did not set _pausedOnContentupdate');
|
||||
});
|
||||
|
||||
QUnit.test('handles content changed when playing', function(assert) {
|
||||
this.player.paused = () => false;
|
||||
this.player.pause = sinon.stub();
|
||||
|
||||
this.contentState.onContentChanged(this.player);
|
||||
assert.equal(this.newState, 'Preroll');
|
||||
assert.equal(this.player.pause.callCount, 1, 'paused player');
|
||||
assert.equal(this.player.ads._pausedOnContentupdate, true, 'set _pausedOnContentupdate');
|
||||
});
|
68
node_modules/videojs-contrib-ads/test/unit/states/abstract/test.State.js
generated
vendored
Normal file
68
node_modules/videojs-contrib-ads/test/unit/states/abstract/test.State.js
generated
vendored
Normal file
|
@ -0,0 +1,68 @@
|
|||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
import State from '../../../../src/states/abstract/State.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('State', {
|
||||
beforeEach() {
|
||||
this.player = {
|
||||
ads: {
|
||||
debug: () => {}
|
||||
}
|
||||
};
|
||||
|
||||
this.state = new State(this.player);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('sets this.player', function(assert) {
|
||||
assert.equal(this.state.player, this.player);
|
||||
});
|
||||
|
||||
QUnit.test('can transition to another state', function(assert) {
|
||||
let mockStateInit = false;
|
||||
|
||||
class MockState {
|
||||
static _getName() {
|
||||
return 'MockState';
|
||||
}
|
||||
init() {
|
||||
mockStateInit = true;
|
||||
}
|
||||
}
|
||||
|
||||
this.state.cleanup = sinon.stub();
|
||||
|
||||
this.state.transitionTo(MockState);
|
||||
assert.ok(this.state.cleanup.calledOnce, 'cleaned up old state');
|
||||
assert.equal(this.player.ads._state.constructor.name, 'MockState', 'set ads._state');
|
||||
assert.equal(mockStateInit, true, 'initialized new state');
|
||||
});
|
||||
|
||||
QUnit.test('throws error if isAdState is not implemented', function(assert) {
|
||||
let error;
|
||||
|
||||
try {
|
||||
this.state.isAdState();
|
||||
} catch (e) {
|
||||
error = e;
|
||||
}
|
||||
assert.equal(error.message, 'isAdState unimplemented for Anonymous State');
|
||||
});
|
||||
|
||||
QUnit.test('is not resuming content by default', function(assert) {
|
||||
assert.equal(this.state.isContentResuming(), false);
|
||||
});
|
||||
|
||||
QUnit.test('is not in an ad break by default', function(assert) {
|
||||
assert.equal(this.state.inAdBreak(), false);
|
||||
});
|
||||
|
||||
QUnit.test('handles events', function(assert) {
|
||||
this.state.onPlay = sinon.stub();
|
||||
this.state.handleEvent('play');
|
||||
assert.ok(this.state.onPlay.calledOnce);
|
||||
});
|
39
node_modules/videojs-contrib-ads/test/unit/states/test.AdsDone.js
generated
vendored
Normal file
39
node_modules/videojs-contrib-ads/test/unit/states/test.AdsDone.js
generated
vendored
Normal file
|
@ -0,0 +1,39 @@
|
|||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
import AdsDone from '../../../src/states/AdsDone.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('AdsDone', {
|
||||
beforeEach() {
|
||||
this.events = [];
|
||||
this.player = {
|
||||
trigger: (event) => {
|
||||
this.events.push(event);
|
||||
},
|
||||
ads: {}
|
||||
};
|
||||
|
||||
this.adsDone = new AdsDone(this.player);
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('sets _contentHasEnded on init', function(assert) {
|
||||
this.adsDone.init(this.player);
|
||||
assert.equal(this.player.ads._contentHasEnded, true, 'content has ended');
|
||||
});
|
||||
|
||||
QUnit.test('ended event on init', function(assert) {
|
||||
this.adsDone.init(this.player);
|
||||
assert.equal(this.events[0], 'ended', 'content has ended');
|
||||
});
|
||||
|
||||
QUnit.test('does not play midrolls', function(assert) {
|
||||
this.adsDone.transitionTo = sinon.spy();
|
||||
|
||||
this.adsDone.init(this.player);
|
||||
this.adsDone.startLinearAdMode();
|
||||
assert.equal(this.adsDone.transitionTo.callCount, 0, 'no transition');
|
||||
});
|
152
node_modules/videojs-contrib-ads/test/unit/states/test.BeforePreroll.js
generated
vendored
Normal file
152
node_modules/videojs-contrib-ads/test/unit/states/test.BeforePreroll.js
generated
vendored
Normal file
|
@ -0,0 +1,152 @@
|
|||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
|
||||
import BeforePreroll from '../../../src/states/BeforePreroll.js';
|
||||
import * as CancelContentPlay from '../../../src/cancelContentPlay.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('BeforePreroll', {
|
||||
beforeEach() {
|
||||
this.events = [];
|
||||
|
||||
this.player = {
|
||||
ads: {
|
||||
debug: () => {},
|
||||
_shouldBlockPlay: false,
|
||||
settings: {}
|
||||
},
|
||||
setTimeout: () => {},
|
||||
trigger: (event) => {
|
||||
this.events.push(event);
|
||||
}
|
||||
};
|
||||
|
||||
this.beforePreroll = new BeforePreroll(this.player);
|
||||
this.beforePreroll.transitionTo = (newState, arg, arg2) => {
|
||||
this.newState = newState.name;
|
||||
this.transitionArg = arg;
|
||||
this.transitionArg2 = arg2;
|
||||
};
|
||||
|
||||
this.cancelContentPlayStub = sinon.stub(CancelContentPlay, 'cancelContentPlay');
|
||||
},
|
||||
|
||||
afterEach() {
|
||||
this.cancelContentPlayStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('transitions to Preroll (adsready first)', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
assert.equal(this.beforePreroll.adsReady, false);
|
||||
this.beforePreroll.onAdsReady(this.player);
|
||||
assert.equal(this.beforePreroll.adsReady, true);
|
||||
this.beforePreroll.onPlay(this.player);
|
||||
assert.equal(this.newState, 'Preroll');
|
||||
assert.equal(this.transitionArg, true);
|
||||
});
|
||||
|
||||
QUnit.test('transitions to Preroll (play first)', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
assert.equal(this.beforePreroll.adsReady, false);
|
||||
this.beforePreroll.onPlay(this.player);
|
||||
assert.equal(this.newState, 'Preroll');
|
||||
assert.equal(this.transitionArg, false);
|
||||
});
|
||||
|
||||
QUnit.test('cancels ads', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
this.beforePreroll.onAdsCanceled(this.player);
|
||||
assert.equal(this.beforePreroll.shouldResumeToContent, true);
|
||||
this.beforePreroll.onPlay(this.player);
|
||||
assert.equal(this.newState, 'Preroll');
|
||||
assert.equal(this.transitionArg, false);
|
||||
assert.equal(this.transitionArg2, true);
|
||||
});
|
||||
|
||||
QUnit.test('transitions to content resuming in preroll on error', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
this.beforePreroll.onAdsError(this.player);
|
||||
assert.equal(this.beforePreroll.shouldResumeToContent, true);
|
||||
this.beforePreroll.onPlay(this.player);
|
||||
assert.equal(this.newState, 'Preroll');
|
||||
assert.equal(this.transitionArg, false);
|
||||
assert.equal(this.transitionArg2, true);
|
||||
});
|
||||
|
||||
QUnit.test('has no preroll', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
this.beforePreroll.onNoPreroll(this.player);
|
||||
assert.equal(this.beforePreroll.shouldResumeToContent, true);
|
||||
this.beforePreroll.onPlay(this.player);
|
||||
assert.equal(this.newState, 'Preroll');
|
||||
assert.equal(this.transitionArg, false);
|
||||
assert.equal(this.transitionArg2, true);
|
||||
});
|
||||
|
||||
QUnit.test('skips the preroll', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
this.beforePreroll.skipLinearAdMode();
|
||||
assert.equal(this.events[0], 'adskip');
|
||||
assert.equal(this.beforePreroll.shouldResumeToContent, true);
|
||||
this.beforePreroll.onPlay(this.player);
|
||||
assert.equal(this.newState, 'Preroll');
|
||||
assert.equal(this.transitionArg, false);
|
||||
assert.equal(this.transitionArg2, true);
|
||||
});
|
||||
|
||||
QUnit.test('handles content change', function(assert) {
|
||||
sinon.spy(this.beforePreroll, 'init');
|
||||
this.beforePreroll.onContentChanged(this.player);
|
||||
assert.equal(this.beforePreroll.init.calledOnce, true);
|
||||
});
|
||||
|
||||
QUnit.test('sets _shouldBlockPlay to true by default', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
assert.equal(this.player.ads._shouldBlockPlay, true);
|
||||
});
|
||||
|
||||
QUnit.test('sets _shouldBlockPlay to true if allowVjsAutoplay option is true and player.autoplay() is false', function(assert) {
|
||||
this.player.ads.settings.allowVjsAutoplay = true;
|
||||
|
||||
this.player.autoplay = () => false;
|
||||
|
||||
this.beforePreroll.init(this.player);
|
||||
assert.equal(this.player.ads._shouldBlockPlay, true);
|
||||
});
|
||||
|
||||
QUnit.test('sets _shouldBlockPlay to false if allowVjsAutoplay option is true and player.autoplay() is truthy', function(assert) {
|
||||
this.player.ads.settings.allowVjsAutoplay = true;
|
||||
|
||||
this.player.autoplay = () => 'play';
|
||||
|
||||
this.beforePreroll.init(this.player);
|
||||
assert.equal(this.player.ads._shouldBlockPlay, false);
|
||||
});
|
||||
|
||||
QUnit.test('updates `shouldResumeToContent` on `nopreroll`', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
this.beforePreroll.onNoPreroll();
|
||||
assert.strictEqual(this.beforePreroll.shouldResumeToContent, true);
|
||||
});
|
||||
|
||||
QUnit.test('updates `shouldResumeToContent` on `adserror`', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
this.beforePreroll.onAdsError();
|
||||
assert.strictEqual(this.beforePreroll.shouldResumeToContent, true);
|
||||
});
|
||||
|
||||
QUnit.test('updates `shouldResumeToContent` on `adscanceled`', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
this.beforePreroll.onAdsCanceled(this.player);
|
||||
assert.strictEqual(this.beforePreroll.shouldResumeToContent, true);
|
||||
});
|
||||
|
||||
QUnit.test('updates `shouldResumeToContent` on `skipLinearAdMode`', function(assert) {
|
||||
this.beforePreroll.init(this.player);
|
||||
this.beforePreroll.skipLinearAdMode();
|
||||
assert.strictEqual(this.beforePreroll.shouldResumeToContent, true);
|
||||
});
|
62
node_modules/videojs-contrib-ads/test/unit/states/test.ContentPlayback.js
generated
vendored
Normal file
62
node_modules/videojs-contrib-ads/test/unit/states/test.ContentPlayback.js
generated
vendored
Normal file
|
@ -0,0 +1,62 @@
|
|||
import QUnit from 'qunit';
|
||||
import ContentPlayback from '../../../src/states/ContentPlayback.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('ContentPlayback', {
|
||||
beforeEach() {
|
||||
this.events = [];
|
||||
this.playTriggered = false;
|
||||
|
||||
this.player = {
|
||||
paused: () => false,
|
||||
play: () => {},
|
||||
trigger: (event) => {
|
||||
this.events.push(event);
|
||||
},
|
||||
ads: {
|
||||
debug: () => {},
|
||||
_shouldBlockPlay: true
|
||||
}
|
||||
};
|
||||
|
||||
this.contentPlayback = new ContentPlayback(this.player);
|
||||
this.contentPlayback.transitionTo = (newState) => {
|
||||
this.newState = newState.name;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('adsready triggers readyforpreroll', function(assert) {
|
||||
this.contentPlayback.init(this.player);
|
||||
this.contentPlayback.onAdsReady(this.player);
|
||||
assert.equal(this.events[0], 'readyforpreroll');
|
||||
});
|
||||
|
||||
QUnit.test('no readyforpreroll if nopreroll_', function(assert) {
|
||||
this.player.ads.nopreroll_ = true;
|
||||
this.contentPlayback.init(this.player);
|
||||
this.contentPlayback.onAdsReady(this.player);
|
||||
assert.equal(this.events.length, 0, 'no events triggered');
|
||||
});
|
||||
|
||||
QUnit.test('transitions to Postroll on readyforpostroll', function(assert) {
|
||||
this.contentPlayback.init(this.player, false);
|
||||
this.contentPlayback.onReadyForPostroll(this.player);
|
||||
assert.equal(this.newState, 'Postroll', 'transitioned to Postroll');
|
||||
});
|
||||
|
||||
QUnit.test('transitions to Midroll on startlinearadmode', function(assert) {
|
||||
this.contentPlayback.init(this.player, false);
|
||||
this.contentPlayback.startLinearAdMode();
|
||||
assert.equal(this.newState, 'Midroll', 'transitioned to Midroll');
|
||||
});
|
||||
|
||||
QUnit.test('sets _shouldBlockPlay to false on init', function(assert) {
|
||||
assert.equal(this.player.ads._shouldBlockPlay, true);
|
||||
|
||||
this.contentPlayback.init(this.player);
|
||||
assert.equal(this.player.ads._shouldBlockPlay, false);
|
||||
});
|
51
node_modules/videojs-contrib-ads/test/unit/states/test.Midroll.js
generated
vendored
Normal file
51
node_modules/videojs-contrib-ads/test/unit/states/test.Midroll.js
generated
vendored
Normal file
|
@ -0,0 +1,51 @@
|
|||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
import Midroll from '../../../src/states/Midroll.js';
|
||||
import adBreak from '../../../src/adBreak.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('Midroll', {
|
||||
beforeEach() {
|
||||
this.player = {
|
||||
addClass: () => {},
|
||||
removeClass: () => {},
|
||||
ads: {
|
||||
_inLinearAdMode: true,
|
||||
endLinearAdMode: () => {
|
||||
this.calledEndLinearAdMode = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
this.midroll = new Midroll(this.player);
|
||||
|
||||
this.adBreakStartStub = sinon.stub(adBreak, 'start');
|
||||
this.adBreakEndStub = sinon.stub(adBreak, 'end');
|
||||
},
|
||||
|
||||
afterEach() {
|
||||
this.adBreakStartStub.restore();
|
||||
this.adBreakEndStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('starts an ad break on init', function(assert) {
|
||||
this.midroll.init(this.player);
|
||||
assert.equal(this.player.ads.adType, 'midroll', 'ad type is midroll');
|
||||
assert.equal(this.adBreakStartStub.callCount, 1, 'ad break started');
|
||||
});
|
||||
|
||||
QUnit.test('ends an ad break on endLinearAdMode', function(assert) {
|
||||
this.midroll.init(this.player);
|
||||
this.midroll.endLinearAdMode();
|
||||
assert.equal(this.adBreakEndStub.callCount, 1, 'ad break ended');
|
||||
});
|
||||
|
||||
QUnit.test('adserror during ad break ends ad break', function(assert) {
|
||||
this.midroll.init(this.player);
|
||||
this.midroll.onAdsError(this.player);
|
||||
assert.equal(this.calledEndLinearAdMode, true, 'linear ad mode ended');
|
||||
});
|
151
node_modules/videojs-contrib-ads/test/unit/states/test.Postroll.js
generated
vendored
Normal file
151
node_modules/videojs-contrib-ads/test/unit/states/test.Postroll.js
generated
vendored
Normal file
|
@ -0,0 +1,151 @@
|
|||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
import Postroll from '../../../src/states/Postroll.js';
|
||||
import adBreak from '../../../src/adBreak.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('Postroll', {
|
||||
beforeEach() {
|
||||
this.events = [];
|
||||
|
||||
this.player = {
|
||||
ads: {
|
||||
settings: {},
|
||||
debug: () => {},
|
||||
inAdBreak: () => false
|
||||
},
|
||||
addClass: () => {},
|
||||
removeClass: () => {},
|
||||
setTimeout: () => {},
|
||||
trigger: (event) => {
|
||||
this.events.push(event);
|
||||
},
|
||||
clearTimeout: () => {}
|
||||
};
|
||||
|
||||
this.postroll = new Postroll(this.player);
|
||||
|
||||
this.postroll.transitionTo = (newState) => {
|
||||
this.newState = newState.name;
|
||||
};
|
||||
|
||||
this.adBreakStartStub = sinon.stub(adBreak, 'start');
|
||||
this.adBreakEndStub = sinon.stub(adBreak, 'end');
|
||||
},
|
||||
|
||||
afterEach() {
|
||||
this.adBreakStartStub.restore();
|
||||
this.adBreakEndStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('sets _contentEnding on init', function(assert) {
|
||||
this.postroll.init(this.player);
|
||||
assert.equal(this.player.ads._contentEnding, true, 'content is ending');
|
||||
});
|
||||
|
||||
QUnit.test('startLinearAdMode starts ad break', function(assert) {
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.startLinearAdMode();
|
||||
assert.equal(this.adBreakStartStub.callCount, 1, 'ad break started');
|
||||
assert.equal(this.player.ads.adType, 'postroll', 'ad type is postroll');
|
||||
});
|
||||
|
||||
QUnit.test('removes ad loading class on ad started', function(assert) {
|
||||
this.player.removeClass = sinon.spy();
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.onAdStarted(this.player);
|
||||
assert.ok(this.player.removeClass.calledWith('vjs-ad-loading'));
|
||||
});
|
||||
|
||||
QUnit.test('ends linear ad mode & ended event on ads error', function(assert) {
|
||||
this.player.ads.endLinearAdMode = sinon.spy();
|
||||
|
||||
this.postroll.init(this.player);
|
||||
this.player.ads.inAdBreak = () => true;
|
||||
this.postroll.onAdsError(this.player);
|
||||
assert.equal(this.player.ads.endLinearAdMode.callCount, 1, 'linear ad mode ended');
|
||||
});
|
||||
|
||||
QUnit.test('no endLinearAdMode on adserror if not in ad break', function(assert) {
|
||||
this.player.ads.endLinearAdMode = sinon.spy();
|
||||
|
||||
this.postroll.init(this.player);
|
||||
this.player.ads.inAdBreak = () => false;
|
||||
this.postroll.onAdsError(this.player);
|
||||
assert.equal(this.player.ads.endLinearAdMode.callCount, 0, 'linear ad mode ended');
|
||||
});
|
||||
|
||||
QUnit.test('does not transition to AdsDone unless content resuming', function(assert) {
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.onEnded(this.player);
|
||||
assert.equal(this.newState, undefined, 'no transition');
|
||||
});
|
||||
|
||||
QUnit.test('transitions to BeforePreroll on content changed after ad break', function(assert) {
|
||||
this.postroll.isContentResuming = () => true;
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.onContentChanged(this.player);
|
||||
assert.equal(this.newState, 'BeforePreroll');
|
||||
});
|
||||
|
||||
QUnit.test('transitions to Preroll on content changed before ad break', function(assert) {
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.onContentChanged(this.player);
|
||||
assert.equal(this.newState, 'Preroll');
|
||||
});
|
||||
|
||||
QUnit.test('doesn\'t transition on content changed during ad break', function(assert) {
|
||||
this.postroll.inAdBreak = () => true;
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.onContentChanged(this.player);
|
||||
assert.equal(this.newState, undefined, 'no transition');
|
||||
});
|
||||
|
||||
QUnit.test('transitions to AdsDone on nopostroll before ad break', function(assert) {
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.onNoPostroll(this.player);
|
||||
assert.equal(this.newState, 'AdsDone');
|
||||
});
|
||||
|
||||
QUnit.test('no transition on nopostroll during ad break', function(assert) {
|
||||
this.postroll.inAdBreak = () => true;
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.onNoPostroll(this.player);
|
||||
assert.equal(this.newState, undefined, 'no transition');
|
||||
});
|
||||
|
||||
QUnit.test('no transition on nopostroll after ad break', function(assert) {
|
||||
this.postroll.isContentResuming = () => true;
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.onNoPostroll(this.player);
|
||||
assert.equal(this.newState, undefined, 'no transition');
|
||||
});
|
||||
|
||||
QUnit.test('can abort', function(assert) {
|
||||
const removeClassSpy = sinon.spy(this.player, 'removeClass');
|
||||
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.abort(this.player);
|
||||
assert.equal(this.postroll.contentResuming, true, 'contentResuming');
|
||||
assert.ok(removeClassSpy.calledWith('vjs-ad-loading'), 'loading class removed');
|
||||
});
|
||||
|
||||
QUnit.test('can clean up', function(assert) {
|
||||
const clearSpy = sinon.spy(this.player, 'clearTimeout');
|
||||
|
||||
this.postroll.init(this.player);
|
||||
this.postroll.cleanup(this.player);
|
||||
assert.equal(this.player.ads._contentEnding, false, '_contentEnding');
|
||||
assert.ok(clearSpy.calledWith(this.postroll._postrollTimeout), 'cleared timeout');
|
||||
});
|
||||
|
||||
QUnit.test('can tell if waiting for ad break', function(assert) {
|
||||
this.postroll.init(this.player);
|
||||
assert.equal(this.postroll.isWaitingForAdBreak(), true, 'waiting for ad break');
|
||||
this.postroll.startLinearAdMode();
|
||||
assert.equal(this.postroll.isWaitingForAdBreak(), false, 'not waiting for ad break');
|
||||
});
|
265
node_modules/videojs-contrib-ads/test/unit/states/test.Preroll.js
generated
vendored
Normal file
265
node_modules/videojs-contrib-ads/test/unit/states/test.Preroll.js
generated
vendored
Normal file
|
@ -0,0 +1,265 @@
|
|||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
import Preroll from '../../../src/states/Preroll.js';
|
||||
import adBreak from '../../../src/adBreak.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('Preroll', {
|
||||
beforeEach() {
|
||||
this.events = [];
|
||||
this.playTriggered = false;
|
||||
this.classes = [];
|
||||
|
||||
this.player = {
|
||||
ads: {
|
||||
debug: () => {},
|
||||
settings: {},
|
||||
inAdBreak: () => false,
|
||||
isContentResuming: () => false,
|
||||
_shouldBlockPlay: true
|
||||
},
|
||||
setTimeout: () => {},
|
||||
clearTimeout: () => {},
|
||||
addClass: (name) => this.classes.push(name),
|
||||
removeClass: (name) => this.classes.splice(this.classes.indexOf(name), 1),
|
||||
hasClass: (name) => this.classes.indexOf(name) !== -1,
|
||||
one: () => {},
|
||||
trigger: (event) => {
|
||||
this.events.push(event);
|
||||
},
|
||||
paused: () => {},
|
||||
play: () => {
|
||||
this.playTriggered = true;
|
||||
}
|
||||
};
|
||||
|
||||
this.preroll = new Preroll(this.player);
|
||||
|
||||
this.preroll.transitionTo = (newState, arg) => {
|
||||
this.newState = newState.name;
|
||||
this.transitionArg = arg;
|
||||
};
|
||||
|
||||
this.preroll.afterLoadStart = (callback) => {
|
||||
callback();
|
||||
};
|
||||
|
||||
this.adBreakStartStub = sinon.stub(adBreak, 'start');
|
||||
this.adBreakEndStub = sinon.stub(adBreak, 'end');
|
||||
},
|
||||
|
||||
afterEach() {
|
||||
this.adBreakStartStub.restore();
|
||||
this.adBreakEndStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('plays a preroll (adsready true)', function(assert) {
|
||||
this.preroll.init(this.player, true);
|
||||
assert.equal(this.preroll.adsReady, true, 'adsready from init');
|
||||
assert.equal(this.events[0], 'readyforpreroll', 'readyforpreroll from init');
|
||||
assert.equal(this.preroll.inAdBreak(), false, 'not in ad break');
|
||||
assert.equal(this.preroll.isWaitingForAdBreak(), true, 'waiting for ad break');
|
||||
|
||||
this.preroll.startLinearAdMode();
|
||||
// Because adBreak.start is mocked.
|
||||
this.player.ads._inLinearAdMode = true;
|
||||
assert.equal(this.adBreakStartStub.callCount, 1, 'ad break started');
|
||||
assert.equal(this.player.ads.adType, 'preroll', 'adType is preroll');
|
||||
assert.equal(this.preroll.isContentResuming(), false, 'content not resuming');
|
||||
assert.equal(this.preroll.inAdBreak(), true, 'in ad break');
|
||||
assert.equal(this.preroll.isWaitingForAdBreak(), false, 'not waiting for ad break');
|
||||
|
||||
this.preroll.endLinearAdMode();
|
||||
assert.equal(this.adBreakEndStub.callCount, 1, 'ad break ended');
|
||||
assert.equal(this.preroll.isContentResuming(), true, 'content resuming');
|
||||
assert.equal(this.preroll.isWaitingForAdBreak(), false, 'not waiting for ad break');
|
||||
|
||||
this.preroll.onPlaying();
|
||||
assert.equal(this.newState, 'ContentPlayback', 'transitioned to ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('plays a preroll (adsready false)', function(assert) {
|
||||
this.preroll.init(this.player, false);
|
||||
assert.equal(this.preroll.adsReady, false, 'not adsReady yet');
|
||||
|
||||
this.preroll.onAdsReady(this.player);
|
||||
assert.equal(this.preroll.adsReady, true, 'adsready from init');
|
||||
assert.equal(this.events[0], 'readyforpreroll', 'readyforpreroll from init');
|
||||
assert.equal(this.preroll.inAdBreak(), false, 'not in ad break');
|
||||
assert.equal(this.preroll.isWaitingForAdBreak(), true, 'waiting for ad break');
|
||||
|
||||
this.preroll.startLinearAdMode();
|
||||
// Because adBreak.start is mocked.
|
||||
this.player.ads._inLinearAdMode = true;
|
||||
assert.equal(this.adBreakStartStub.callCount, 1, 'ad break started');
|
||||
assert.equal(this.player.ads.adType, 'preroll', 'adType is preroll');
|
||||
assert.equal(this.preroll.isContentResuming(), false, 'content not resuming');
|
||||
assert.equal(this.preroll.inAdBreak(), true, 'in ad break');
|
||||
assert.equal(this.preroll.isWaitingForAdBreak(), false, 'not waiting for ad break');
|
||||
|
||||
this.preroll.endLinearAdMode();
|
||||
assert.equal(this.adBreakEndStub.callCount, 1, 'ad break ended');
|
||||
assert.equal(this.preroll.isContentResuming(), true, 'content resuming');
|
||||
assert.equal(this.preroll.isWaitingForAdBreak(), false, 'not waiting for ad break');
|
||||
|
||||
this.preroll.onPlaying();
|
||||
assert.equal(this.newState, 'ContentPlayback', 'transitioned to ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('can handle nopreroll event', function(assert) {
|
||||
this.preroll.init(this.player, false, false);
|
||||
this.preroll.onNoPreroll(this.player);
|
||||
assert.equal(this.preroll.isContentResuming(), true);
|
||||
this.preroll.onPlaying(this.player);
|
||||
assert.equal(this.newState, 'ContentPlayback', 'transitioned to ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('can handle adscanceled', function(assert) {
|
||||
this.preroll.init(this.player, false, false);
|
||||
this.preroll.onAdsCanceled(this.player);
|
||||
assert.equal(this.preroll.isContentResuming(), true);
|
||||
assert.notOk(this.player.hasClass('vjs-ad-loading'));
|
||||
assert.notOk(this.player.hasClass('vjs-ad-content-resuming'));
|
||||
assert.notOk(this.preroll._timeout);
|
||||
this.preroll.onPlaying(this.player);
|
||||
assert.equal(this.newState, 'ContentPlayback', 'transitioned to ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('can handle adserror', function(assert) {
|
||||
this.preroll.init(this.player, false, false);
|
||||
this.preroll.onAdsError(this.player);
|
||||
assert.equal(this.preroll.isContentResuming(), true);
|
||||
assert.notOk(this.player.hasClass('vjs-ad-loading'));
|
||||
assert.notOk(this.player.hasClass('vjs-ad-content-resuming'));
|
||||
assert.notOk(this.preroll._timeout);
|
||||
this.preroll.onPlaying(this.player);
|
||||
assert.equal(this.newState, 'ContentPlayback', 'transitioned to ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('can skip linear ad mode', function(assert) {
|
||||
this.preroll.init(this.player, false, false);
|
||||
this.preroll.skipLinearAdMode();
|
||||
assert.equal(this.preroll.isContentResuming(), true);
|
||||
this.preroll.onPlaying(this.player);
|
||||
assert.equal(this.newState, 'ContentPlayback', 'transitioned to ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('can handle adtimeout', function(assert) {
|
||||
this.preroll.init(this.player, false, false);
|
||||
this.preroll.onAdTimeout(this.player);
|
||||
assert.equal(this.preroll.isContentResuming(), true);
|
||||
assert.notOk(this.player.hasClass('vjs-ad-loading'));
|
||||
assert.notOk(this.player.hasClass('vjs-ad-content-resuming'));
|
||||
assert.notOk(this.preroll._timeout);
|
||||
this.preroll.onPlaying(this.player);
|
||||
assert.equal(this.newState, 'ContentPlayback', 'transitioned to ContentPlayback');
|
||||
});
|
||||
|
||||
QUnit.test('removes ad loading class on ads started', function(assert) {
|
||||
this.preroll.init(this.player, false);
|
||||
|
||||
const removeClassSpy = sinon.spy(this.player, 'removeClass');
|
||||
|
||||
this.preroll.onAdStarted(this.player);
|
||||
assert.ok(removeClassSpy.calledWith('vjs-ad-loading'), 'loading class removed');
|
||||
});
|
||||
|
||||
QUnit.test('only plays after no ad in correct conditions', function(assert) {
|
||||
this.preroll.init(this.player, false, false);
|
||||
|
||||
this.player.ads._playRequested = false;
|
||||
this.player.ads._pausedOnContentupdate = false;
|
||||
this.player.paused = () => false;
|
||||
this.preroll.resumeAfterNoPreroll(this.player);
|
||||
assert.equal(
|
||||
this.playTriggered, false,
|
||||
'should not call play when playing already'
|
||||
);
|
||||
|
||||
this.player.ads._playRequested = true;
|
||||
this.player.ads._pausedOnContentupdate = false;
|
||||
this.player.paused = () => false;
|
||||
this.preroll.resumeAfterNoPreroll(this.player);
|
||||
assert.equal(
|
||||
this.playTriggered, false,
|
||||
'should not call play when playing already 2'
|
||||
);
|
||||
|
||||
this.player.ads._playRequested = false;
|
||||
this.player.ads._pausedOnContentupdate = true;
|
||||
this.player.paused = () => false;
|
||||
this.preroll.resumeAfterNoPreroll(this.player);
|
||||
assert.equal(
|
||||
this.playTriggered, false,
|
||||
'should not call play when playing already 3'
|
||||
);
|
||||
|
||||
this.player.ads._playRequested = false;
|
||||
this.player.ads._pausedOnContentupdate = false;
|
||||
this.player.paused = () => true;
|
||||
this.preroll.resumeAfterNoPreroll(this.player);
|
||||
assert.equal(
|
||||
this.playTriggered, false,
|
||||
'should not call play when playback has never started'
|
||||
);
|
||||
|
||||
this.player.ads._playRequested = true;
|
||||
this.player.ads._pausedOnContentupdate = false;
|
||||
this.player.paused = () => true;
|
||||
this.preroll.resumeAfterNoPreroll(this.player);
|
||||
assert.equal(
|
||||
this.playTriggered, true,
|
||||
'should call play when playback had been started and the player is paused'
|
||||
);
|
||||
|
||||
this.player.ads._playRequested = false;
|
||||
this.player.ads._pausedOnContentupdate = true;
|
||||
this.player.paused = () => true;
|
||||
this.preroll.resumeAfterNoPreroll(this.player);
|
||||
assert.equal(
|
||||
this.playTriggered, true,
|
||||
'should call play when playback had been started on the last source and the player is paused'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('remove ad loading class on cleanup', function(assert) {
|
||||
this.preroll.init(this.player, false);
|
||||
|
||||
const removeClassSpy = sinon.spy(this.player, 'removeClass');
|
||||
|
||||
this.preroll.cleanup(this.player);
|
||||
assert.ok(removeClassSpy.calledWith('vjs-ad-loading'), 'loading class removed');
|
||||
});
|
||||
|
||||
QUnit.test('resets _shouldBlockPlay to false when ad break starts', function(assert) {
|
||||
this.preroll.init(this.player, true);
|
||||
this.preroll.startLinearAdMode();
|
||||
assert.equal(this.player.ads._shouldBlockPlay, false);
|
||||
});
|
||||
|
||||
QUnit.test('resets _shouldBlockPlay to false when no preroll', function(assert) {
|
||||
this.preroll.init(this.player, true, false);
|
||||
this.preroll.resumeAfterNoPreroll(this.player);
|
||||
assert.equal(this.player.ads._shouldBlockPlay, false);
|
||||
});
|
||||
|
||||
QUnit.test('adserror (Preroll) will trigger play & playing if its already playing', function(assert) {
|
||||
this.preroll.init(this.player, false, false);
|
||||
this.playingTriggered = false;
|
||||
// due AdError 1009: The VAST response document is empty
|
||||
this.player.ads._playRequested = true;
|
||||
this.player.ads._pausedOnContentupdate = false;
|
||||
this.player.paused = () => false;
|
||||
this.preroll.onAdsError(this.player);
|
||||
|
||||
assert.equal(this.preroll.adType, null);
|
||||
assert.equal(this.events[0], 'play', 'playing from adserror');
|
||||
assert.equal(this.events[1], 'playing', 'playing from adserror');
|
||||
assert.equal(this.player.ads._shouldBlockPlay, false);
|
||||
assert.equal(this.preroll.isContentResuming(), true);
|
||||
|
||||
});
|
54
node_modules/videojs-contrib-ads/test/unit/states/test.StitchedAdRoll.js
generated
vendored
Normal file
54
node_modules/videojs-contrib-ads/test/unit/states/test.StitchedAdRoll.js
generated
vendored
Normal file
|
@ -0,0 +1,54 @@
|
|||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
import StitchedAdRoll from '../../../src/states/StitchedAdRoll.js';
|
||||
import adBreak from '../../../src/adBreak.js';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('StitchedAdRoll', {
|
||||
beforeEach() {
|
||||
this.player = {
|
||||
addClass: () => {},
|
||||
removeClass: () => {},
|
||||
trigger: sinon.spy(),
|
||||
ads: {
|
||||
_inLinearAdMode: true,
|
||||
debug: () => {}
|
||||
}
|
||||
};
|
||||
|
||||
this.adroll = new StitchedAdRoll(this.player);
|
||||
|
||||
this.adBreakStartStub = sinon.stub(adBreak, 'start');
|
||||
this.adBreakEndStub = sinon.stub(adBreak, 'end');
|
||||
},
|
||||
|
||||
afterEach() {
|
||||
this.adBreakStartStub.restore();
|
||||
this.adBreakEndStub.restore();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('starts an ad break on init', function(assert) {
|
||||
this.adroll.init();
|
||||
assert.equal(this.player.ads.adType, 'stitched', 'ad type is stitched');
|
||||
assert.equal(this.adBreakStartStub.callCount, 1, 'ad break started');
|
||||
});
|
||||
|
||||
QUnit.test('ends an ad break on endLinearAdMode', function(assert) {
|
||||
this.adroll.init();
|
||||
this.adroll.endLinearAdMode();
|
||||
assert.equal(this.adBreakEndStub.callCount, 1, 'ad break ended');
|
||||
});
|
||||
|
||||
QUnit.test('adended during ad break leaves linear ad mode and re-triggers ended', function(assert) {
|
||||
sinon.spy(this.adroll, 'endLinearAdMode');
|
||||
|
||||
this.adroll.init();
|
||||
this.adroll.onAdEnded();
|
||||
assert.ok(this.player.trigger.calledOnce, 'the player fired one event');
|
||||
assert.ok(this.player.trigger.calledWith('ended'), 'the event it fired was ended');
|
||||
assert.ok(this.adroll.endLinearAdMode.calledOnce, 'the ad roll called endLinearAdMode');
|
||||
});
|
44
node_modules/videojs-contrib-ads/test/unit/states/test.StitchedContentPlayback.js
generated
vendored
Normal file
44
node_modules/videojs-contrib-ads/test/unit/states/test.StitchedContentPlayback.js
generated
vendored
Normal file
|
@ -0,0 +1,44 @@
|
|||
import StitchedContentPlayback from '../../../src/states/StitchedContentPlayback.js';
|
||||
import QUnit from 'qunit';
|
||||
|
||||
/*
|
||||
* These tests are intended to be isolated unit tests for one state with all
|
||||
* other modules mocked.
|
||||
*/
|
||||
QUnit.module('StitchedContentPlayback', {
|
||||
beforeEach() {
|
||||
this.events = [];
|
||||
this.playTriggered = false;
|
||||
|
||||
this.player = {
|
||||
paused: () => false,
|
||||
play: () => {},
|
||||
trigger: (event) => {
|
||||
this.events.push(event);
|
||||
},
|
||||
ads: {
|
||||
debug: () => {},
|
||||
_contentHasEnded: false,
|
||||
_shouldBlockPlay: true
|
||||
}
|
||||
};
|
||||
|
||||
this.stitchedContentPlayback = new StitchedContentPlayback(this.player);
|
||||
this.stitchedContentPlayback.transitionTo = (newState) => {
|
||||
this.newState = newState.name;
|
||||
};
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('transitions to StitchedAdRoll when startLinearAdMode is called', function(assert) {
|
||||
this.stitchedContentPlayback.init();
|
||||
this.stitchedContentPlayback.startLinearAdMode();
|
||||
assert.equal(this.newState, 'StitchedAdRoll', 'transitioned to StitchedAdRoll');
|
||||
});
|
||||
|
||||
QUnit.test('sets _shouldBlockPlay to false on init', function(assert) {
|
||||
assert.equal(this.player.ads._shouldBlockPlay, true);
|
||||
|
||||
this.stitchedContentPlayback.init();
|
||||
assert.equal(this.player.ads._shouldBlockPlay, false);
|
||||
});
|
164
node_modules/videojs-contrib-ads/test/unit/test.ads.js
generated
vendored
Normal file
164
node_modules/videojs-contrib-ads/test/unit/test.ads.js
generated
vendored
Normal file
|
@ -0,0 +1,164 @@
|
|||
import videojs from 'video.js';
|
||||
import getAds from '../../src/ads.js';
|
||||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
|
||||
QUnit.module('Ads Object', {
|
||||
beforeEach() {
|
||||
this.player = {
|
||||
currentSrc: () => {},
|
||||
duration: () => {},
|
||||
on: () => {},
|
||||
one: () => {},
|
||||
ready: () => {},
|
||||
setTimeout: () => {}
|
||||
};
|
||||
this.player.ads = getAds(this.player);
|
||||
this.player.ads.settings = {};
|
||||
}
|
||||
}, function() {
|
||||
|
||||
/*
|
||||
* Basic live detection
|
||||
*/
|
||||
QUnit.test('isLive', function(assert) {
|
||||
this.player.duration = () => 5;
|
||||
assert.equal(this.player.ads.isLive(this.player), false);
|
||||
|
||||
this.player.duration = () => Infinity;
|
||||
assert.equal(this.player.ads.isLive(this.player), true);
|
||||
});
|
||||
|
||||
/*
|
||||
* `contentIsLive` setting overrides live detection
|
||||
*/
|
||||
QUnit.test('isLive and contentIsLive', function(assert) {
|
||||
this.player.duration = () => 5;
|
||||
this.player.ads.settings.contentIsLive = true;
|
||||
assert.equal(this.player.ads.isLive(this.player), true);
|
||||
|
||||
this.player.duration = () => 5;
|
||||
this.player.ads.settings.contentIsLive = false;
|
||||
assert.equal(this.player.ads.isLive(this.player), false);
|
||||
|
||||
this.player.duration = () => Infinity;
|
||||
this.player.ads.settings.contentIsLive = true;
|
||||
assert.equal(this.player.ads.isLive(this.player), true);
|
||||
|
||||
this.player.duration = () => Infinity;
|
||||
this.player.ads.settings.contentIsLive = false;
|
||||
assert.equal(this.player.ads.isLive(this.player), false);
|
||||
});
|
||||
|
||||
QUnit.test('stitchedAds', function(assert) {
|
||||
assert.notOk(this.player.ads.stitchedAds());
|
||||
|
||||
this.player.ads.settings.stitchedAds = true;
|
||||
|
||||
assert.ok(this.player.ads.stitchedAds());
|
||||
|
||||
sinon.spy(videojs.log, 'warn');
|
||||
this.player.ads.stitchedAds(false);
|
||||
|
||||
assert.ok(videojs.log.warn.calledOnce, 'using as a setter is deprecated');
|
||||
assert.notOk(this.player.ads.stitchedAds());
|
||||
assert.notOk(this.player.ads.settings.stitchedAds);
|
||||
|
||||
videojs.log.warn.restore();
|
||||
});
|
||||
|
||||
QUnit.test('shouldPlayContentBehindAd', function(assert) {
|
||||
|
||||
// liveCuePoints true + finite duration
|
||||
this.player.ads.settings.liveCuePoints = true;
|
||||
this.player.duration = () => 60;
|
||||
videojs.browser.IS_IOS = false;
|
||||
videojs.browser.IS_ANDROID = false;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
this.player.ads.settings.liveCuePoints = true;
|
||||
this.player.duration = () => 60;
|
||||
videojs.browser.IS_IOS = true;
|
||||
videojs.browser.IS_ANDROID = false;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
this.player.ads.settings.liveCuePoints = true;
|
||||
this.player.duration = () => 60;
|
||||
videojs.browser.IS_IOS = false;
|
||||
videojs.browser.IS_ANDROID = true;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
// liveCuePoints true + infinite duration
|
||||
this.player.ads.settings.liveCuePoints = true;
|
||||
this.player.duration = () => Infinity;
|
||||
videojs.browser.IS_IOS = false;
|
||||
videojs.browser.IS_ANDROID = false;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), true);
|
||||
|
||||
this.player.ads.settings.liveCuePoints = true;
|
||||
this.player.duration = () => Infinity;
|
||||
videojs.browser.IS_IOS = true;
|
||||
videojs.browser.IS_ANDROID = false;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
this.player.ads.settings.liveCuePoints = true;
|
||||
this.player.duration = () => Infinity;
|
||||
videojs.browser.IS_IOS = false;
|
||||
videojs.browser.IS_ANDROID = true;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
// liveCuePoints false + finite duration
|
||||
this.player.ads.settings.liveCuePoints = false;
|
||||
this.player.duration = () => 60;
|
||||
videojs.browser.IS_IOS = false;
|
||||
videojs.browser.IS_ANDROID = false;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
this.player.ads.settings.liveCuePoints = false;
|
||||
this.player.duration = () => 60;
|
||||
videojs.browser.IS_IOS = true;
|
||||
videojs.browser.IS_ANDROID = false;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
this.player.ads.settings.liveCuePoints = false;
|
||||
this.player.duration = () => 60;
|
||||
videojs.browser.IS_IOS = false;
|
||||
videojs.browser.IS_ANDROID = true;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
// liveCuePoints false + infinite duration
|
||||
this.player.ads.settings.liveCuePoints = false;
|
||||
this.player.duration = () => Infinity;
|
||||
videojs.browser.IS_IOS = false;
|
||||
videojs.browser.IS_ANDROID = false;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
this.player.ads.settings.liveCuePoints = false;
|
||||
this.player.duration = () => Infinity;
|
||||
videojs.browser.IS_IOS = true;
|
||||
videojs.browser.IS_ANDROID = false;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
|
||||
this.player.ads.settings.liveCuePoints = false;
|
||||
this.player.duration = () => Infinity;
|
||||
videojs.browser.IS_IOS = false;
|
||||
videojs.browser.IS_ANDROID = true;
|
||||
assert.equal(this.player.ads.shouldPlayContentBehindAd(this.player), false);
|
||||
});
|
||||
|
||||
QUnit.test('shouldTakeSnapshots', function(assert) {
|
||||
this.player.ads.shouldPlayContentBehindAd = () => false;
|
||||
this.player.ads.stitchedAds = () => false;
|
||||
|
||||
assert.ok(this.player.ads.shouldTakeSnapshots());
|
||||
|
||||
this.player.ads.shouldPlayContentBehindAd = () => true;
|
||||
|
||||
assert.notOk(this.player.ads.shouldTakeSnapshots());
|
||||
|
||||
this.player.ads.shouldPlayContentBehindAd = () => false;
|
||||
this.player.ads.stitchedAds = () => true;
|
||||
|
||||
assert.notOk(this.player.ads.shouldTakeSnapshots());
|
||||
});
|
||||
});
|
245
node_modules/videojs-contrib-ads/test/unit/test.playMiddleware.js
generated
vendored
Normal file
245
node_modules/videojs-contrib-ads/test/unit/test.playMiddleware.js
generated
vendored
Normal file
|
@ -0,0 +1,245 @@
|
|||
import pm from '../../src/playMiddleware.js';
|
||||
import QUnit from 'qunit';
|
||||
import sinon from 'sinon';
|
||||
import videojs from 'video.js';
|
||||
|
||||
QUnit.module('Play Middleware', {}, function() {
|
||||
const baseMockedVjsNotSupported = {
|
||||
use: () => {},
|
||||
VERSION: '5.0.0',
|
||||
browser: {
|
||||
}
|
||||
};
|
||||
|
||||
const baseMockedVjsIsSupported = {
|
||||
use: () => {},
|
||||
VERSION: '6.7.3',
|
||||
browser: {
|
||||
IS_IOS: false,
|
||||
IS_ANDROID: false
|
||||
},
|
||||
middleware: {
|
||||
TERMINATOR: {fake: 'terminator'}
|
||||
}
|
||||
};
|
||||
|
||||
QUnit.module('Not supported unit tests', {
|
||||
beforeEach() {
|
||||
this.videojs = videojs.mergeOptions({}, baseMockedVjsNotSupported);
|
||||
},
|
||||
afterEach() {
|
||||
this.videojs = null;
|
||||
}
|
||||
}, function() {
|
||||
QUnit.test('isMiddlewareMediatorSupported is false if old video.js version', function(assert) {
|
||||
// Mock videojs.browser to mock an older videojs version
|
||||
pm.testHook(this.videojs);
|
||||
|
||||
assert.equal(
|
||||
pm.isMiddlewareMediatorSupported(), false,
|
||||
'old video.js does not support middleware mediators'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('isMiddlewareMediatorSupported is false if on mobile', function(assert) {
|
||||
// Mock videojs.browser to fake being on Android
|
||||
this.videojs.browser.IS_ANDROID = true;
|
||||
this.videojs.browser.IS_IOS = false;
|
||||
pm.testHook(this.videojs);
|
||||
|
||||
assert.equal(
|
||||
pm.isMiddlewareMediatorSupported(), false,
|
||||
'is not supported on Android'
|
||||
);
|
||||
|
||||
// Mock videojs.browser to fake being on iOS
|
||||
this.videojs.browser.IS_ANDROID = false;
|
||||
this.videojs.browser.IS_IOS = true;
|
||||
pm.testHook(this.videojs);
|
||||
|
||||
assert.equal(
|
||||
pm.isMiddlewareMediatorSupported(), false,
|
||||
'is not supported on iOS'
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
QUnit.module('Supported unit tests', {
|
||||
beforeEach() {
|
||||
// Stub videojs to force playMiddleware to be used
|
||||
this.videojs = videojs.mergeOptions({}, baseMockedVjsIsSupported);
|
||||
pm.testHook(this.videojs);
|
||||
|
||||
this.triggeredEvent = null;
|
||||
this.addedClass = null;
|
||||
|
||||
// Stub the player
|
||||
this.player = {
|
||||
ads: {
|
||||
_shouldBlockPlay: false,
|
||||
_playBlocked: false,
|
||||
debug: () => {}
|
||||
},
|
||||
trigger: (event) => {
|
||||
this.triggeredEvent = event;
|
||||
},
|
||||
addClass: (className) => {
|
||||
this.addedClass = className;
|
||||
}
|
||||
};
|
||||
|
||||
this.sandbox = sinon.sandbox.create();
|
||||
},
|
||||
afterEach() {
|
||||
// Reset variables
|
||||
this.videojs = null;
|
||||
this.sandbox.restore();
|
||||
}
|
||||
});
|
||||
|
||||
QUnit.test('isMiddlewareMediatorSupported is true if middleware mediators exist on desktop', function(assert) {
|
||||
assert.equal(
|
||||
pm.isMiddlewareMediatorSupported(), true,
|
||||
'is supported if middleware mediators exist and not mobile'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('playMiddleware returns with a setSource, callPlay and play method', function(assert) {
|
||||
const m = pm.playMiddleware(this.player);
|
||||
|
||||
this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true);
|
||||
assert.equal(typeof m, 'object', 'returns an object');
|
||||
assert.equal(typeof m.setSource, 'function', 'has setSource');
|
||||
assert.equal(typeof m.callPlay, 'function', 'has callPlay');
|
||||
assert.equal(typeof m.play, 'function', 'has play');
|
||||
});
|
||||
|
||||
QUnit.test('playMiddleware callPlay will terminate if _shouldBlockPlay is true', function(assert) {
|
||||
const m = pm.playMiddleware(this.player);
|
||||
|
||||
this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true);
|
||||
this.player.ads._shouldBlockPlay = true;
|
||||
assert.equal(
|
||||
m.callPlay(), this.videojs.middleware.TERMINATOR,
|
||||
'callPlay returns terminator'
|
||||
);
|
||||
assert.strictEqual(
|
||||
this.player.ads._playBlocked, true,
|
||||
'_playBlocked is set'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('playMiddleware callPlay will not terminate if _shouldBlockPlay is false', function(assert) {
|
||||
const m = pm.playMiddleware(this.player);
|
||||
|
||||
this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true);
|
||||
this.player.ads._shouldBlockPlay = false;
|
||||
|
||||
assert.equal(
|
||||
m.callPlay(), undefined,
|
||||
'callPlay should not return an object'
|
||||
);
|
||||
assert.notEqual(
|
||||
m.callPlay(), this.videojs.middleware.TERMINATOR,
|
||||
'callPlay should not return the terminator'
|
||||
);
|
||||
assert.strictEqual(
|
||||
this.player.ads._playBlocked, false,
|
||||
'_playBlocked should not be set'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test("playMiddleware callPlay will not terminate if the player doesn't have this plugin", function(assert) {
|
||||
const nonAdsPlayer = {
|
||||
trigger: (event) => {
|
||||
this.triggeredEvent = event;
|
||||
},
|
||||
addClass: (className) => {
|
||||
this.addedClass = className;
|
||||
}
|
||||
};
|
||||
const m = pm.playMiddleware(nonAdsPlayer);
|
||||
|
||||
this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true);
|
||||
this.player.ads._shouldBlockPlay = true;
|
||||
|
||||
assert.equal(
|
||||
m.callPlay(), undefined,
|
||||
'callPlay should not return an object'
|
||||
);
|
||||
assert.strictEqual(
|
||||
this.player.ads._playBlocked, false,
|
||||
'_playBlocked should not be set'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('playMiddleware play will trigger play event if callPlay terminates', function(assert) {
|
||||
const m = pm.playMiddleware(this.player);
|
||||
|
||||
this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true);
|
||||
this.player.ads._shouldBlockPlay = true;
|
||||
// Mock that the callPlay method terminated
|
||||
this.player.ads._playBlocked = true;
|
||||
|
||||
// Play terminates, there's no value returned
|
||||
m.play(true, null);
|
||||
assert.equal(this.triggeredEvent, 'play');
|
||||
assert.equal(this.addedClass, 'vjs-has-started');
|
||||
assert.equal(
|
||||
this.player.ads._playBlocked, false,
|
||||
'_playBlocked is reset'
|
||||
);
|
||||
});
|
||||
|
||||
QUnit.test('playMiddleware play will not trigger play event if another middleware terminated', function(assert) {
|
||||
const m = pm.playMiddleware(this.player);
|
||||
|
||||
this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true);
|
||||
// Mock that another middleware terminated but the playMiddleware did not
|
||||
this.player.ads._shouldBlockPlay = true;
|
||||
this.player.ads._playBlocked = false;
|
||||
this.sandbox.stub(m, 'callPlay').returns(undefined);
|
||||
|
||||
// Another middleware terminated so the first argument is true
|
||||
m.play(true, null);
|
||||
assert.equal(this.triggeredEvent, null, 'no events should be triggered');
|
||||
assert.equal(this.addedClass, null, 'no classes should be added');
|
||||
assert.equal(this.player.ads._playBlocked, false, '_playBlocked has not changed');
|
||||
});
|
||||
|
||||
QUnit.test("playMiddleware play will not trigger play event if the player doesn't have this plugin", function(assert) {
|
||||
let evt = null;
|
||||
let cnm = null;
|
||||
const nonAdsPlayer = {
|
||||
trigger: (event) => {
|
||||
evt = event;
|
||||
},
|
||||
addClass: (className) => {
|
||||
cnm = className;
|
||||
}
|
||||
};
|
||||
const m = pm.playMiddleware(nonAdsPlayer);
|
||||
|
||||
this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true);
|
||||
|
||||
m.play(true, null);
|
||||
assert.equal(evt, null, 'the play event should not have been triggered');
|
||||
assert.equal(cnm, null, 'the class should not have been added');
|
||||
});
|
||||
|
||||
QUnit.test("playMiddleware won't trigger play event if callPlay doesn't terminate", function(assert) {
|
||||
const m = pm.playMiddleware(this.player);
|
||||
const originalPlayBlocked = this.player.ads._playBlocked;
|
||||
|
||||
this.sandbox.stub(pm, 'isMiddlewareMediatorSupported').returns(true);
|
||||
m.play(false, {});
|
||||
assert.equal(this.triggeredEvent, null, 'no events should be triggered');
|
||||
assert.equal(this.addedClass, null, 'no classes should be added');
|
||||
assert.strictEqual(
|
||||
this.player.ads._playBlocked, originalPlayBlocked,
|
||||
'_playBlocked remains unchanged'
|
||||
);
|
||||
});
|
||||
|
||||
});
|
||||
|
130
node_modules/videojs-contrib-ads/test/unit/test.redispatch.js
generated
vendored
Normal file
130
node_modules/videojs-contrib-ads/test/unit/test.redispatch.js
generated
vendored
Normal file
|
@ -0,0 +1,130 @@
|
|||
import redispatch from '../../src/redispatch.js';
|
||||
import QUnit from 'qunit';
|
||||
|
||||
QUnit.module('Redispatch', {
|
||||
|
||||
beforeEach(assert) {
|
||||
|
||||
// Player event buffer.
|
||||
// Mocked player pushes events here when they are triggered.
|
||||
// redispatch helper returns event buffer after each redispatch.
|
||||
let eventBuffer = [];
|
||||
|
||||
// Mocked player
|
||||
this.player = {
|
||||
trigger(event) {
|
||||
eventBuffer.push(event);
|
||||
},
|
||||
|
||||
currentSrc() {
|
||||
return 'my vid';
|
||||
},
|
||||
|
||||
ads: {
|
||||
snapshot: {
|
||||
ended: false,
|
||||
currentSrc: 'my vid'
|
||||
},
|
||||
|
||||
videoElementRecycled() {
|
||||
return false;
|
||||
},
|
||||
|
||||
stitchedAds() {
|
||||
return false;
|
||||
},
|
||||
|
||||
isResumingAfterNoPreroll() {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
// Redispatch helper for tests
|
||||
this.redispatch = function(type) {
|
||||
const event = {type};
|
||||
|
||||
eventBuffer = [];
|
||||
redispatch.call(this.player, event);
|
||||
|
||||
if (eventBuffer.length === 1) {
|
||||
return eventBuffer[0].type;
|
||||
} else if (event.cancelBubble) {
|
||||
return 'cancelled';
|
||||
} else if (eventBuffer.length === 0) {
|
||||
return 'ignored';
|
||||
}
|
||||
throw new Error('Event buffer has more than 1 event');
|
||||
|
||||
};
|
||||
},
|
||||
|
||||
afterEach(assert) {
|
||||
// Cleanup
|
||||
this.player = null;
|
||||
this.redispatch = null;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
QUnit.test('playing event in different ad states', function(assert) {
|
||||
|
||||
this.player.ads.isInAdMode = () => false;
|
||||
this.player.ads.isContentResuming = () => false;
|
||||
assert.equal(this.redispatch('playing'), 'ignored');
|
||||
|
||||
this.player.ads.isInAdMode = () => true;
|
||||
this.player.ads.isContentResuming = () => false;
|
||||
assert.equal(this.redispatch('playing'), 'adplaying');
|
||||
|
||||
this.player.ads.isInAdMode = () => true;
|
||||
this.player.ads.isContentResuming = () => true;
|
||||
assert.equal(this.redispatch('playing'), 'ignored');
|
||||
|
||||
});
|
||||
|
||||
QUnit.test('play events in different states', function(assert) {
|
||||
this.player.ads.inAdBreak = () => false;
|
||||
this.player.ads.isInAdMode = () => true;
|
||||
this.player.ads.isContentResuming = () => true;
|
||||
assert.equal(
|
||||
this.redispatch('play'), 'contentplay',
|
||||
'should be contentplay when content is resuming'
|
||||
);
|
||||
|
||||
this.player.ads.inAdBreak = () => false;
|
||||
this.player.ads.isInAdMode = () => false;
|
||||
this.player.ads.isContentResuming = () => false;
|
||||
this.player.ads._playRequested = false;
|
||||
assert.strictEqual(
|
||||
this.redispatch('play'), 'ignored',
|
||||
"should not be redispatched if play hasn't been requested yet"
|
||||
);
|
||||
|
||||
this.player.ads.inAdBreak = () => false;
|
||||
this.player.ads.isInAdMode = () => false;
|
||||
this.player.ads.isContentResuming = () => false;
|
||||
this.player.ads._playRequested = true;
|
||||
assert.strictEqual(
|
||||
this.redispatch('play'), 'ignored',
|
||||
'should not be redispatched if in content state'
|
||||
);
|
||||
|
||||
this.player.ads.inAdBreak = () => false;
|
||||
this.player.ads.isInAdMode = () => true;
|
||||
this.player.ads.isContentResuming = () => false;
|
||||
this.player.ads._playRequested = true;
|
||||
assert.strictEqual(
|
||||
this.redispatch('play'), 'ignored',
|
||||
'should not prefix when not in an ad break'
|
||||
);
|
||||
|
||||
this.player.ads.inAdBreak = () => true;
|
||||
this.player.ads.isInAdMode = () => true;
|
||||
this.player.ads.isContentResuming = () => false;
|
||||
this.player.ads._playRequested = true;
|
||||
assert.strictEqual(
|
||||
this.redispatch('play'), 'adplay',
|
||||
'should be adplay when in an ad break'
|
||||
);
|
||||
});
|
47
node_modules/videojs-contrib-ads/test/unit/test.register.js
generated
vendored
Normal file
47
node_modules/videojs-contrib-ads/test/unit/test.register.js
generated
vendored
Normal file
|
@ -0,0 +1,47 @@
|
|||
import videojs from 'video.js';
|
||||
import contribAdsPlugin from '../../src/plugin.js';
|
||||
import register from '../../src/register.js';
|
||||
import { hasAdsPlugin} from '../../src/register.js';
|
||||
import QUnit from 'qunit';
|
||||
|
||||
// Cross-compatible plugin de-registration.
|
||||
const deregister = () => {
|
||||
|
||||
// Video.js 7.2+
|
||||
if (videojs.deregisterPlugin) {
|
||||
return videojs.deregisterPlugin('ads');
|
||||
}
|
||||
|
||||
// Video.js 6.0 thru 7.1
|
||||
if (videojs.getPlugin) {
|
||||
const Plugin = videojs.getPlugin('plugin');
|
||||
|
||||
if (Plugin && Plugin.deregisterPlugin) {
|
||||
return Plugin.deregisterPlugin('ads');
|
||||
}
|
||||
}
|
||||
|
||||
// Video.js 5
|
||||
const Player = videojs.getComponent('Player');
|
||||
|
||||
if (Player && Player.prototype.ads) {
|
||||
delete Player.prototype.ads;
|
||||
}
|
||||
};
|
||||
|
||||
QUnit.module('Register');
|
||||
|
||||
QUnit.test('registration fails if plugin exists, succeeds otherwise', function(assert) {
|
||||
|
||||
// The plugin is already registered here.
|
||||
assert.notOk(register(contribAdsPlugin), 'plugin was already registered');
|
||||
assert.ok(hasAdsPlugin(), 'plugin exists');
|
||||
|
||||
// De-register the plugin and verify that it no longer exists.
|
||||
deregister();
|
||||
assert.notOk(hasAdsPlugin(), 'plugin does not exist');
|
||||
|
||||
// Re-register the plugin and verify that it exists.
|
||||
assert.ok(register(contribAdsPlugin), 'plugin was registered');
|
||||
assert.ok(hasAdsPlugin(), 'plugin exists');
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue