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
|
/* eslint-env qunit */
import TestHelpers from './test-helpers';
QUnit.module('Player: loadMedia/getMedia', {
beforeEach() {
this.player = TestHelpers.makePlayer({});
},
afterEach() {
this.player.dispose();
}
});
QUnit.test('loadMedia sets source from a string', function(assert) {
this.player.loadMedia({
src: 'foo.mp4'
});
assert.strictEqual(this.player.currentSrc(), 'foo.mp4', 'currentSrc was correct');
});
QUnit.test('loadMedia sets source from an object', function(assert) {
this.player.loadMedia({
src: {
src: 'foo.mp4',
type: 'video/mp4'
}
});
assert.strictEqual(this.player.currentSrc(), 'foo.mp4', 'currentSrc was correct');
});
QUnit.test('loadMedia sets source from an array', function(assert) {
const sources = [{
src: 'foo.mp4',
type: 'video/mp4'
}, {
src: 'foo.webm',
type: 'video/webm'
}];
this.player.loadMedia({
src: sources
});
assert.strictEqual(this.player.currentSrc(), sources[0].src, 'currentSrc was correct');
assert.deepEqual(this.player.currentSource(), sources[0], 'currentSource was correct');
assert.deepEqual(this.player.currentSources(), sources, 'currentSources were correct');
});
QUnit.test('loadMedia sets poster and backfills artwork', function(assert) {
this.player.loadMedia({
poster: 'foo.jpg'
});
assert.strictEqual(this.player.poster(), 'foo.jpg', 'poster was correct');
});
QUnit.test('loadMedia sets artwork via poster', function(assert) {
this.player.loadMedia({
poster: 'foo.jpg'
});
const {artwork} = this.player.getMedia();
assert.deepEqual(artwork, [{
src: 'foo.jpg',
type: 'image/jpeg'
}], 'the artwork was set to match the poster');
});
QUnit.test('loadMedia sets artwork and poster independently', function(assert) {
this.player.loadMedia({
poster: 'foo.jpg',
artwork: [{
src: 'bar.png',
type: 'image/png'
}]
});
assert.strictEqual(this.player.poster(), 'foo.jpg', 'poster was correct');
assert.deepEqual(this.player.getMedia().artwork, [{
src: 'bar.png',
type: 'image/png'
}], 'the artwork was provided, so does not match poster');
});
QUnit.test('loadMedia creates text tracks', function(assert) {
this.player.loadMedia({
textTracks: [{
kind: 'captions',
src: 'foo.vtt',
language: 'en',
label: 'English'
}]
});
const rtt = this.player.remoteTextTracks()[0];
assert.ok(Boolean(rtt), 'the track exists');
assert.strictEqual(rtt.kind, 'captions', 'the kind is correct');
assert.strictEqual(rtt.src, 'foo.vtt', 'the src is correct');
assert.strictEqual(rtt.language, 'en', 'the language is correct');
assert.strictEqual(rtt.label, 'English', 'the label is correct');
});
QUnit.test('getMedia returns a clone of the media object', function(assert) {
const original = {
arbitrary: true,
src: 'foo.mp4',
poster: 'foo.gif',
textTracks: [{
kind: 'captions',
src: 'foo.vtt',
language: 'en',
label: 'English'
}]
};
this.player.loadMedia(original);
const result = this.player.getMedia();
assert.notStrictEqual(result, original, 'a new object is returned');
assert.deepEqual(result, {
arbitrary: true,
artwork: [{
src: 'foo.gif',
type: 'image/gif'
}],
src: 'foo.mp4',
poster: 'foo.gif',
textTracks: [{
kind: 'captions',
src: 'foo.vtt',
language: 'en',
label: 'English'
}]
}, 'the object has the expected structure');
});
QUnit.test('getMedia returns a new media object when no media has been loaded', function(assert) {
this.player.poster = () => 'foo.gif';
this.player.currentSources = () => [{src: 'foo.mp4', type: 'video/mp4'}];
this.player.remoteTextTracks = () => [{
kind: 'captions',
src: 'foo.vtt',
language: 'en',
label: 'English'
}, {
kind: 'subtitles',
src: 'bar.vtt',
language: 'de',
label: 'German'
}];
const result = this.player.getMedia();
assert.deepEqual(result, {
artwork: [{
src: 'foo.gif',
type: 'image/gif'
}],
src: [{
src: 'foo.mp4',
type: 'video/mp4'
}],
poster: 'foo.gif',
textTracks: [{
kind: 'captions',
src: 'foo.vtt',
language: 'en',
label: 'English'
}, {
kind: 'subtitles',
src: 'bar.vtt',
language: 'de',
label: 'German'
}]
}, 'the object has the expected structure');
});
// This only tests the relevant aspect of the reset function. The rest of its
// effects are tested in player.test.js
QUnit.test('reset discards the media object', function(assert) {
this.player.loadMedia({
poster: 'foo.jpg',
src: 'foo.mp4',
textTracks: [{src: 'foo.vtt'}]
});
this.player.reset();
// TODO: There is a bug with player.reset() where it does not clear internal
// cachces completely. Remove this when that's fixed.
this.player.cache_.sources = [];
assert.deepEqual(this.player.getMedia(), {src: [], textTracks: []}, 'any empty media object is returned');
});
|