gap-skipper.test.js
6.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
import videojs from 'video.js';
import QUnit from 'qunit';
import {
useFakeEnvironment,
useFakeMediaSource,
createPlayer,
openMediaSource,
standardXHRResponse
} from './test-helpers.js';
import GapSkipper from '../src/gap-skipper';
QUnit.module('GapSkipper', {
beforeEach() {
this.env = useFakeEnvironment();
this.requests = this.env.requests;
this.mse = useFakeMediaSource();
this.clock = this.env.clock;
this.old = {};
// setup a player
this.player = createPlayer();
},
afterEach() {
this.env.restore();
this.mse.restore();
this.player.dispose();
}
});
QUnit.test('skips over gap in firefox with waiting event', function() {
this.player.autoplay(true);
// create a buffer with a gap between 10 & 20 seconds
this.player.tech_.buffered = function() {
return videojs.createTimeRanges([[0, 10], [20, 30]]);
};
// set an arbitrary source
this.player.src({
src: 'master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
// start playback normally
this.player.tech_.triggerReady();
this.clock.tick(1);
standardXHRResponse(this.requests.shift());
openMediaSource(this.player, this.clock);
this.player.tech_.trigger('play');
this.player.tech_.trigger('playing');
this.clock.tick(1);
// seek to 10 seconds and wait 12 seconds
this.player.currentTime(10);
this.player.tech_.trigger('waiting');
this.clock.tick(12000);
// check that player jumped the gap
QUnit.equal(Math.round(this.player.currentTime()),
20, 'Player seeked over gap after timer');
});
QUnit.test('skips over gap in chrome without waiting event', function() {
this.player.autoplay(true);
// create a buffer with a gap between 10 & 20 seconds
this.player.tech_.buffered = function() {
return videojs.createTimeRanges([[0, 10], [20, 30]]);
};
// set an arbitrary source
this.player.src({
src: 'master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
// start playback normally
this.player.tech_.triggerReady();
this.clock.tick(1);
standardXHRResponse(this.requests.shift());
openMediaSource(this.player, this.clock);
this.player.tech_.trigger('play');
this.player.tech_.trigger('playing');
this.clock.tick(1);
// seek to 10 seconds & simulate chrome waiting event
this.player.currentTime(10);
for (let i = 0; i < 10; i++) {
this.player.tech_.trigger('timeupdate');
}
this.clock.tick(2000);
// checks that player doesn't seek before timer expires
QUnit.equal(this.player.currentTime(), 10, 'Player doesnt seek over gap pre-timer');
this.clock.tick(10000);
// check that player jumped the gap
QUnit.equal(Math.round(this.player.currentTime()),
20, 'Player seeked over gap after timer');
});
QUnit.test('skips over gap in Chrome due to video underflow', function() {
this.player.autoplay(true);
this.player.tech_.buffered = () => {
return videojs.createTimeRanges([[0, 10], [10.1, 20]]);
};
// set an arbitrary source
this.player.src({
src: 'master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
// start playback normally
this.player.tech_.triggerReady();
this.clock.tick(1);
standardXHRResponse(this.requests.shift());
openMediaSource(this.player, this.clock);
this.player.tech_.trigger('play');
this.player.tech_.trigger('playing');
this.clock.tick(1);
this.player.currentTime(13);
let seeks = [];
this.player.tech_.setCurrentTime = (time) => {
seeks.push(time);
};
for (let i = 0; i < 7; i++) {
this.player.tech_.trigger('timeupdate');
}
QUnit.equal(seeks.length, 1, 'one seek');
QUnit.equal(seeks[0], 13, 'player seeked to current time');
});
QUnit.module('GapSkipper isolated functions', {
beforeEach() {
this.gapSkipper = new GapSkipper({
tech: {
on: () => {},
off: () => {}
}
});
}
});
QUnit.test('skips gap from video underflow', function() {
QUnit.equal(
this.gapSkipper.gapFromVideoUnderflow_(videojs.createTimeRanges(), 0),
null,
'returns null when buffer is empty');
QUnit.equal(
this.gapSkipper.gapFromVideoUnderflow_(videojs.createTimeRanges([[0, 10]]), 13),
null,
'returns null when there is only a previous buffer');
QUnit.equal(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 15),
null,
'returns null when gap is too far from current time');
QUnit.equal(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 9.9),
null,
'returns null when gap is after current time');
QUnit.equal(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [11.1, 20]]), 13),
null,
'returns null when gap is too large');
QUnit.equal(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 12.1),
null,
'returns null when time is less than or euqal to 2 seconds ahead');
QUnit.equal(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 14.1),
null,
'returns null when time is greater than or equal to 4 seconds ahead');
QUnit.deepEqual(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 12.2),
{start: 10, end: 10.1},
'returns gap when gap is small and time is greater than 2 seconds ahead in a buffer');
QUnit.deepEqual(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 13),
{start: 10, end: 10.1},
'returns gap when gap is small and time is 3 seconds ahead in a buffer');
QUnit.deepEqual(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 13.9),
{start: 10, end: 10.1},
'returns gap when gap is small and time is less than 4 seconds ahead in a buffer');
// In a case where current time is outside of the buffered range, something odd must've
// happened, but we should still allow the player to try to continue from that spot.
QUnit.deepEqual(
this.gapSkipper.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 12.9]]), 13),
{start: 10, end: 10.1},
'returns gap even when current time is not in buffered range');
});