1 | import videojs from 'video.js';
|
2 | import '../../examples/basic-ad-plugin/example-plugin.js';
|
3 | import QUnit from 'qunit';
|
4 | import document from 'global/document';
|
5 |
|
6 | QUnit.module('Initial Events With No Preroll', {
|
7 | beforeEach() {
|
8 | this.video = document.createElement('video');
|
9 |
|
10 | this.fixture = document.querySelector('#qunit-fixture');
|
11 | this.fixture.appendChild(this.video);
|
12 |
|
13 | this.player = videojs(this.video);
|
14 |
|
15 | this.player.exampleAds({
|
16 | adServerUrl: '/test/integration/lib/inventory.json',
|
17 | playPreroll: false,
|
18 | playMidroll: false
|
19 | });
|
20 |
|
21 | this.player.src({
|
22 | src: 'http://vjs.zencdn.net/v/oceans.webm',
|
23 | type: 'video/webm'
|
24 | });
|
25 |
|
26 |
|
27 | this.player.muted(true);
|
28 | },
|
29 |
|
30 | afterEach() {
|
31 | this.player.dispose();
|
32 | }
|
33 | });
|
34 |
|
35 | QUnit.test('initial play event with no preroll: one please', function(assert) {
|
36 | const done = assert.async();
|
37 |
|
38 | let playEvents = 0;
|
39 |
|
40 | this.player.on('play', () => {
|
41 | playEvents++;
|
42 | });
|
43 |
|
44 | this.player.on(['error', 'aderror'], () => {
|
45 | assert.ok(false, 'no errors');
|
46 | done();
|
47 | });
|
48 |
|
49 | this.player.on('timeupdate', () => {
|
50 | if (this.player.currentTime() > 1) {
|
51 | assert.equal(playEvents, 1, '1 play event');
|
52 | done();
|
53 | }
|
54 | });
|
55 |
|
56 | this.player.ready(this.player.play);
|
57 |
|
58 | });
|
59 |
|
60 | QUnit.test('initial playing event with no preroll: 1+', function(assert) {
|
61 | const done = assert.async();
|
62 |
|
63 | let playingEvents = 0;
|
64 |
|
65 | this.player.on('playing', () => {
|
66 | playingEvents++;
|
67 | });
|
68 |
|
69 | this.player.on(['error', 'aderror'], () => {
|
70 | assert.ok(false, 'no errors');
|
71 | done();
|
72 | });
|
73 |
|
74 | this.player.on('timeupdate', () => {
|
75 | if (this.player.currentTime() > 1) {
|
76 | assert.ok(playingEvents >= 1, '1+ playing events');
|
77 | done();
|
78 | }
|
79 | });
|
80 |
|
81 | this.player.ready(this.player.play);
|
82 |
|
83 | });
|
84 |
|
85 | QUnit.test('no ended event at start if video with no preroll', function(assert) {
|
86 | const done = assert.async();
|
87 |
|
88 | let endedEvents = 0;
|
89 |
|
90 | this.player.on('ended', () => {
|
91 | endedEvents++;
|
92 | });
|
93 |
|
94 | this.player.on(['error', 'aderror'], () => {
|
95 | assert.ok(false, 'no errors');
|
96 | done();
|
97 | });
|
98 |
|
99 | this.player.on('timeupdate', () => {
|
100 | if (this.player.currentTime() > 1) {
|
101 | assert.equal(endedEvents, 0, 'no ended events');
|
102 | done();
|
103 | }
|
104 | });
|
105 |
|
106 | this.player.ready(this.player.play);
|
107 |
|
108 | });
|
109 |
|
110 | QUnit.test('initial loadstart event with no preroll: one please', function(assert) {
|
111 | const done = assert.async();
|
112 |
|
113 | let loadstartEvents = 0;
|
114 |
|
115 | this.player.on('loadstart', () => {
|
116 | loadstartEvents++;
|
117 | });
|
118 |
|
119 | this.player.on(['error', 'aderror'], () => {
|
120 | assert.ok(false, 'no errors');
|
121 | done();
|
122 | });
|
123 |
|
124 | this.player.on('timeupdate', () => {
|
125 | if (this.player.currentTime() > 1) {
|
126 | assert.equal(loadstartEvents, 1, '1 loadstart event');
|
127 | done();
|
128 | }
|
129 | });
|
130 |
|
131 | this.player.ready(this.player.play);
|
132 |
|
133 | });
|