playback-watcher.test.js
22 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
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
import videojs from 'video.js';
import QUnit from 'qunit';
import {
useFakeEnvironment,
useFakeMediaSource,
createPlayer,
openMediaSource,
standardXHRResponse
} from './test-helpers.js';
import PlaybackWatcher from '../src/playback-watcher';
let monitorCurrentTime_;
QUnit.module('PlaybackWatcher', {
beforeEach(assert) {
this.env = useFakeEnvironment(assert);
this.requests = this.env.requests;
this.mse = useFakeMediaSource();
this.clock = this.env.clock;
this.old = {};
// setup a player
this.player = createPlayer();
this.player.autoplay(true);
},
afterEach() {
this.env.restore();
this.mse.restore();
this.player.dispose();
}
});
QUnit.test('skips over gap in firefox with waiting event', function(assert) {
let hlsGapSkipEvents = 0;
this.player.autoplay(true);
this.player.tech_.on('usage', (event) => {
if (event.name === 'hls-gap-skip') {
hlsGapSkipEvents++;
}
});
// 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('canplay');
this.player.tech_.trigger('play');
this.player.tech_.trigger('playing');
this.clock.tick(1);
assert.equal(hlsGapSkipEvents, 0, 'there is no skipped gap');
// 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
assert.equal(Math.round(this.player.currentTime()),
20, 'Player seeked over gap after timer');
assert.equal(hlsGapSkipEvents, 1, 'there is one skipped gap');
});
QUnit.test('skips over gap in chrome without waiting event', function(assert) {
let hlsGapSkipEvents = 0;
this.player.autoplay(true);
this.player.tech_.on('usage', (event) => {
if (event.name === 'hls-gap-skip') {
hlsGapSkipEvents++;
}
});
// 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('canplay');
this.player.tech_.trigger('play');
this.player.tech_.trigger('playing');
this.clock.tick(1);
assert.equal(hlsGapSkipEvents, 0, 'there is no skipped gap');
// seek to 10 seconds & simulate chrome waiting event
this.player.currentTime(10);
this.clock.tick(4000);
// checks that player doesn't seek before timer expires
assert.equal(this.player.currentTime(), 10, 'Player doesnt seek over gap pre-timer');
this.clock.tick(10000);
// check that player jumped the gap
assert.equal(Math.round(this.player.currentTime()),
20, 'Player seeked over gap after timer');
assert.equal(hlsGapSkipEvents, 1, 'there is one skipped gap');
});
QUnit.test('skips over gap in Chrome due to video underflow', function(assert) {
let hlsVideoUnderflowEvents = 0;
this.player.autoplay(true);
this.player.tech_.on('usage', (event) => {
if (event.name === 'hls-video-underflow') {
hlsVideoUnderflowEvents++;
}
});
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);
assert.equal(hlsVideoUnderflowEvents, 0, 'no video underflow event got triggered');
this.player.currentTime(13);
let seeks = [];
this.player.tech_.setCurrentTime = (time) => {
seeks.push(time);
};
this.player.tech_.trigger('waiting');
assert.equal(seeks.length, 1, 'one seek');
assert.equal(seeks[0], 13, 'player seeked to current time');
assert.equal(hlsVideoUnderflowEvents, 1, 'triggered a video underflow event');
});
QUnit.test('seek to live point if we fall off the end of a live playlist',
function(assert) {
// set an arbitrary live source
this.player.src({
src: 'liveStart30sBefore.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(0);
let seeks = [];
this.player.tech_.setCurrentTime = (time) => {
seeks.push(time);
};
this.player.tech_.hls.playbackWatcher_.seekable = () => {
return videojs.createTimeRanges([[1, 45]]);
};
this.player.tech_.trigger('waiting');
assert.equal(seeks.length, 1, 'one seek');
assert.equal(seeks[0], 45, 'player seeked to live point');
});
QUnit.test('seeks to current time when stuck inside buffered region', function(assert) {
// set an arbitrary live source
this.player.src({
src: 'liveStart30sBefore.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('canplay');
this.player.tech_.trigger('play');
this.player.tech_.trigger('playing');
this.clock.tick(1);
this.player.currentTime(10);
let seeks = [];
this.player.tech_.setCurrentTime = (time) => {
seeks.push(time);
};
this.player.tech_.seeking = () => false;
this.player.tech_.buffered = () => videojs.createTimeRanges([[0, 30]]);
this.player.tech_.seekable = () => videojs.createTimeRanges([[0, 30]]);
this.player.tech_.paused = () => false;
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop has run through once, `lastRecordedTime` should have been recorded
// and `consecutiveUpdates` set to 0 to begin count
assert.equal(this.player.tech_.hls.playbackWatcher_.lastRecordedTime, 10,
'Playback Watcher stored current time');
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 0,
'consecutiveUpdates set to 0');
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop should increment consecutive updates until it is >= 5
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 1,
'consecutiveUpdates incremented');
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop should increment consecutive updates until it is >= 5
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 2,
'consecutiveUpdates incremented');
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop should increment consecutive updates until it is >= 5
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 3,
'consecutiveUpdates incremented');
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop should increment consecutive updates until it is >= 5
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 4,
'consecutiveUpdates incremented');
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop should increment consecutive updates until it is >= 5
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 5,
'consecutiveUpdates incremented');
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop should see consecutive updates >= 5, call `waiting_`
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 0,
'consecutiveUpdates reset');
// Playback watcher seeked to currentTime in `waiting_` to correct the `unknownwaiting`
assert.equal(seeks.length, 1, 'one seek');
assert.equal(seeks[0], 10, 'player seeked to currentTime');
});
QUnit.test('does not seek to current time when stuck near edge of buffered region',
function(assert) {
// set an arbitrary live source
this.player.src({
src: 'liveStart30sBefore.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('canplay');
this.player.tech_.trigger('play');
this.player.tech_.trigger('playing');
this.clock.tick(1);
this.player.currentTime(29.98);
let seeks = [];
this.player.tech_.setCurrentTime = (time) => {
seeks.push(time);
};
this.player.tech_.seeking = () => false;
this.player.tech_.buffered = () => videojs.createTimeRanges([[0, 30]]);
this.player.tech_.seekable = () => videojs.createTimeRanges([[0, 30]]);
this.player.tech_.paused = () => false;
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop has run through once, `lastRecordedTime` should have been recorded
// and `consecutiveUpdates` set to 0 to begin count
assert.equal(this.player.tech_.hls.playbackWatcher_.lastRecordedTime, 29.98,
'Playback Watcher stored current time');
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 0,
'consecutiveUpdates set to 0');
// Playback watcher loop runs on a 250ms clock
this.clock.tick(250);
// Loop has run through a second time, should detect that currentTime hasn't made
// progress while at the end of the buffer. Since the currentTime is at the end of the
// buffer, `consecutiveUpdates` should not be incremented
assert.equal(this.player.tech_.hls.playbackWatcher_.lastRecordedTime, 29.98,
'Playback Watcher stored current time');
assert.equal(this.player.tech_.hls.playbackWatcher_.consecutiveUpdates, 0,
'consecutiveUpdates should still be 0');
// no corrective seek
assert.equal(seeks.length, 0, 'no seek');
});
QUnit.test('fires notifications when activated', function(assert) {
let buffered = [[]];
let seekable = [[]];
let currentTime = 0;
let hlsLiveResyncEvents = 0;
let hlsVideoUnderflowEvents = 0;
let playbackWatcher;
this.player.src({
src: 'liveStart30sBefore.m3u8',
type: 'application/vnd.apple.mpegurl'
});
this.player.tech_.triggerReady();
this.clock.tick(1);
this.player.tech_.currentTime = function() {
return currentTime;
};
this.player.tech_.buffered = function() {
return {
length: buffered.length,
start(i) {
return buffered[i][0];
},
end(i) {
return buffered[i][1];
}
};
};
playbackWatcher = this.player.tech_.hls.playbackWatcher_;
playbackWatcher.seekable = function() {
return {
length: seekable.length,
start(i) {
return seekable[i][0];
},
end(i) {
return seekable[i][1];
}
};
};
this.player.tech_.on('usage', (event) => {
if (event.name === 'hls-live-resync') {
hlsLiveResyncEvents++;
}
if (event.name === 'hls-video-underflow') {
hlsVideoUnderflowEvents++;
}
});
currentTime = 19;
seekable[0] = [20, 30];
playbackWatcher.waiting_();
assert.equal(hlsLiveResyncEvents, 1, 'triggered a liveresync event');
currentTime = 12;
seekable[0] = [0, 100];
buffered = [[0, 9], [10, 20]];
playbackWatcher.waiting_();
assert.equal(hlsVideoUnderflowEvents, 1, 'triggered a videounderflow event');
assert.equal(hlsLiveResyncEvents, 1, 'did not trigger an additional liveresync event');
});
QUnit.test('fixes bad seeks', function(assert) {
// set an arbitrary live source
this.player.src({
src: 'liveStart30sBefore.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);
let playbackWatcher = this.player.tech_.hls.playbackWatcher_;
let seeks = [];
let seekable;
let seeking;
let currentTime;
playbackWatcher.seekable = () => seekable;
playbackWatcher.tech_ = {
off: () => {},
seeking: () => seeking,
setCurrentTime: (time) => {
seeks.push(time);
},
currentTime: () => currentTime
};
currentTime = 50;
seekable = videojs.createTimeRanges([[1, 45]]);
seeking = false;
assert.ok(!playbackWatcher.fixesBadSeeks_(), 'does nothing when not seeking');
assert.equal(seeks.length, 0, 'did not seek');
seeking = true;
assert.ok(playbackWatcher.fixesBadSeeks_(), 'acts when seek past seekable range');
assert.equal(seeks.length, 1, 'seeked');
assert.equal(seeks[0], 45, 'player seeked to live point');
currentTime = 0;
assert.ok(playbackWatcher.fixesBadSeeks_(), 'acts when seek before seekable range');
assert.equal(seeks.length, 2, 'seeked');
assert.equal(seeks[1], 1.1, 'player seeked to start of the live window');
currentTime = 30;
assert.ok(!playbackWatcher.fixesBadSeeks_(), 'does nothing when time within range');
assert.equal(seeks.length, 2, 'did not seek');
});
QUnit.test('corrects seek outside of seekable', function(assert) {
// set an arbitrary live source
this.player.src({
src: 'liveStart30sBefore.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);
let playbackWatcher = this.player.tech_.hls.playbackWatcher_;
let seeks = [];
let seekable;
let seeking;
let currentTime;
playbackWatcher.seekable = () => seekable;
playbackWatcher.tech_ = {
off: () => {},
seeking: () => seeking,
setCurrentTime: (time) => {
seeks.push(time);
},
currentTime: () => currentTime,
// mocked out
paused: () => false,
buffered: () => videojs.createTimeRanges()
};
// waiting
currentTime = 50;
seekable = videojs.createTimeRanges([[1, 45]]);
seeking = true;
this.player.tech_.trigger('waiting');
assert.equal(seeks.length, 1, 'seeked');
assert.equal(seeks[0], 45, 'player seeked to live point');
currentTime = 0;
this.player.tech_.trigger('waiting');
assert.equal(seeks.length, 2, 'seeked');
assert.equal(seeks[1], 1.1, 'player seeked to start of the live window');
// inside of seekable range
currentTime = 10;
this.player.tech_.trigger('waiting');
assert.equal(seeks.length, 2, 'did not seek');
currentTime = 50;
// if we're not seeking, the case shouldn't be handled here
seeking = false;
this.player.tech_.trigger('waiting');
assert.equal(seeks.length, 2, 'did not seek');
// no check for 0 with seeking false because that should be handled by live falloff
// checkCurrentTime
seeking = true;
currentTime = 50;
playbackWatcher.checkCurrentTime_();
assert.equal(seeks.length, 3, 'seeked');
assert.equal(seeks[2], 45, 'player seeked to live point');
currentTime = 0;
playbackWatcher.checkCurrentTime_();
assert.equal(seeks.length, 4, 'seeked');
assert.equal(seeks[3], 1.1, 'player seeked to live point');
currentTime = 10;
playbackWatcher.checkCurrentTime_();
assert.equal(seeks.length, 4, 'did not seek');
seeking = false;
currentTime = 50;
playbackWatcher.checkCurrentTime_();
assert.equal(seeks.length, 4, 'did not seek');
currentTime = 0;
playbackWatcher.checkCurrentTime_();
assert.equal(seeks.length, 4, 'did not seek');
});
QUnit.test('calls fixesBadSeeks_ on seekablechanged', function(assert) {
// set an arbitrary live source
this.player.src({
src: 'liveStart30sBefore.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);
let playbackWatcher = this.player.tech_.hls.playbackWatcher_;
let fixesBadSeeks_ = 0;
playbackWatcher.fixesBadSeeks_ = () => fixesBadSeeks_++;
this.player.tech_.trigger('seekablechanged');
assert.equal(fixesBadSeeks_, 1, 'fixesBadSeeks_ was called');
});
QUnit.module('PlaybackWatcher isolated functions', {
beforeEach() {
monitorCurrentTime_ = PlaybackWatcher.prototype.monitorCurrentTime_;
PlaybackWatcher.prototype.monitorCurrentTime_ = () => {};
this.playbackWatcher = new PlaybackWatcher({
tech: {
on: () => {},
off: () => {}
}
});
},
afterEach() {
this.playbackWatcher.dispose();
PlaybackWatcher.prototype.monitorCurrentTime_ = monitorCurrentTime_;
}
});
QUnit.test('skips gap from video underflow', function(assert) {
assert.equal(
this.playbackWatcher.gapFromVideoUnderflow_(videojs.createTimeRanges(), 0),
null,
'returns null when buffer is empty');
assert.equal(
this.playbackWatcher.gapFromVideoUnderflow_(videojs.createTimeRanges([[0, 10]]), 13),
null,
'returns null when there is only a previous buffer');
assert.equal(
this.playbackWatcher.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 15),
null,
'returns null when gap is too far from current time');
assert.equal(
this.playbackWatcher.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 9.9),
null,
'returns null when gap is after current time');
assert.equal(
this.playbackWatcher.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10.1], [10.2, 20]]), 12.1),
null,
'returns null when time is less than or equal to 2 seconds ahead');
assert.equal(
this.playbackWatcher.gapFromVideoUnderflow_(
videojs.createTimeRanges([[0, 10], [10.1, 20]]), 14.1),
null,
'returns null when time is greater than or equal to 4 seconds ahead');
assert.deepEqual(
this.playbackWatcher.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');
assert.deepEqual(
this.playbackWatcher.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');
assert.deepEqual(
this.playbackWatcher.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.
assert.deepEqual(
this.playbackWatcher.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');
});
QUnit.test('detects live window falloff', function(assert) {
let beforeSeekableWindow_ =
this.playbackWatcher.beforeSeekableWindow_.bind(this.playbackWatcher);
assert.ok(
beforeSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 10),
'true if playlist live and current time before seekable');
assert.ok(
!beforeSeekableWindow_(videojs.createTimeRanges([]), 10),
'false if no seekable range');
assert.ok(
!beforeSeekableWindow_(videojs.createTimeRanges([[0, 10]]), -1),
'false if seekable range starts at 0');
assert.ok(
!beforeSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 11),
'false if current time at seekable start');
assert.ok(
!beforeSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 20),
'false if current time at seekable end');
assert.ok(
!beforeSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 15),
'false if current time within seekable range');
assert.ok(
!beforeSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 21),
'false if current time past seekable range');
assert.ok(
beforeSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 0),
'true if current time is 0 and earlier than seekable range');
});
QUnit.test('detects beyond seekable window', function(assert) {
let afterSeekableWindow_ =
this.playbackWatcher.afterSeekableWindow_.bind(this.playbackWatcher);
assert.ok(
!afterSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 10.8),
'false if before seekable range');
assert.ok(
afterSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 20.2),
'true if after seekable range');
assert.ok(
!afterSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 10.9),
'false if within starting seekable range buffer');
assert.ok(
!afterSeekableWindow_(videojs.createTimeRanges([[11, 20]]), 20.1),
'false if within ending seekable range buffer');
assert.ok(
!afterSeekableWindow_(videojs.createTimeRanges(), 10),
'false if no seekable range');
assert.ok(
!afterSeekableWindow_(videojs.createTimeRanges([[0, 10]]), -0.2),
'false if current time is negative');
assert.ok(
!afterSeekableWindow_(videojs.createTimeRanges([[0, 10]]), 5),
'false if within seekable range');
assert.ok(
!afterSeekableWindow_(videojs.createTimeRanges([[0, 10]]), 0),
'false if within seekable range');
assert.ok(
!afterSeekableWindow_(videojs.createTimeRanges([[0, 10]]), 10),
'false if within seekable range');
});