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
|
/* eslint-env qunit */
import TestHelpers from './test-helpers.js';
import sinon from 'sinon';
import { computedStyle } from '../../src/js/utils/dom.js';
import { createTimeRange } from '../../src/js/utils/time.js';
QUnit.module('SeekToLive', {
beforeEach() {
this.clock = sinon.useFakeTimers();
this.player = TestHelpers.makePlayer();
this.seekToLive = this.player.controlBar.seekToLive;
this.getComputedDisplay = () => {
return computedStyle(this.seekToLive.el(), 'display');
};
this.mockLiveui = () => {
this.player.paused = () => false;
this.player.hasStarted = () => true;
this.player.options_.liveui = true;
this.player.seekable = () => createTimeRange(0, 45);
this.player.currentTime = () => this.player.liveTracker.liveCurrentTime();
this.player.duration(Infinity);
};
},
afterEach() {
this.player.dispose();
this.clock.restore();
}
});
QUnit.test('liveui enabled, can switch between at and behind live edge ', function(assert) {
this.mockLiveui();
assert.notEqual(this.getComputedDisplay(), 'none', 'is not hidden');
assert.ok(this.seekToLive.hasClass('vjs-at-live-edge'), 'has at live edge class');
this.player.currentTime = () => 0;
this.player.seekable = () => createTimeRange(0, 38);
this.clock.tick(30);
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
});
QUnit.test('liveui enabled can show/hide on durationchange', function(assert) {
// start out non-live
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
// switch to live
this.mockLiveui();
assert.notEqual(this.getComputedDisplay(), 'none', 'is not hidden');
assert.ok(this.seekToLive.hasClass('vjs-at-live-edge'), 'has at live edge class');
// switch to non-live
this.player.duration(20);
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
// back to live again.
this.mockLiveui();
assert.notEqual(this.getComputedDisplay(), 'none', 'is not hidden');
assert.ok(this.seekToLive.hasClass('vjs-at-live-edge'), 'has at live edge class');
});
QUnit.test('liveui disabled live window is never shown', function(assert) {
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
this.player.paused = () => false;
this.player.hasStarted = () => true;
this.player.currentTime = () => this.player.liveTracker.liveCurrentTime();
// liveui false, seekable range is good though
this.player.options_.liveui = false;
this.player.duration(Infinity);
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
this.player.duration(10);
// liveui false
this.player.options_.liveui = false;
this.player.seekable = () => createTimeRange(0, 19);
this.player.duration(Infinity);
assert.equal(this.getComputedDisplay(), 'none', 'is hidden');
assert.notOk(this.seekToLive.hasClass('vjs-at-live-edge'), 'does not have at live edge class');
});
|