manifest-loader_test.js
1.96 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
(function(window, videojs, undefined) {
var player, oldXhr, oldSourceBuffer;
module('HLS', {
setup: function() {
var video = document.createElement('video');
document.querySelector('#qunit-fixture').appendChild(video);
player = videojs(video);
oldXhr = window.XMLHttpRequest;
oldSourceBuffer = window.videojs.SourceBuffer;
// mock out SourceBuffer since it won't be available in phantomjs
window.videojs.SourceBuffer = function() {
this.appendBuffer = function() {};
};
},
teardown: function() {
window.XMLHttpRequest = oldXhr;
window.videojs.SourceBuffer = oldSourceBuffer;
}
});
asyncTest('loads the specified manifest URL on init', function() {
var loadedmanifest = false;
player.on('loadedmanifest', function() {
loadedmanifest = true;
});
player.on('loadedmetadata', function() {
ok(loadedmanifest, 'loadedmanifest fires');
ok(player.hls.manifest, 'the manifest is available');
ok(player.hls.manifest.segments, 'the segments are parsed');
strictEqual(player.hls.manifest,
player.hls.currentPlaylist,
'a playlist is selected');
strictEqual(player.hls.readyState(), 1, 'the readyState is HAVE_METADATA');
start();
});
player.hls('manifest/playlist.m3u8');
strictEqual(player.hls.readyState(), 0, 'the readyState is HAVE_NOTHING');
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
});
test('starts downloading a segment on loadedmetadata', function() {
var url;
window.XMLHttpRequest = function() {
this.open = function() {
url = arguments[1];
};
this.send = function() {
this.readyState = 4;
this.responseText = window.manifests['media'];
this.onreadystatechange();
};
};
player.hls('manifest/media.m3u8');
videojs.mediaSources[player.currentSrc()].trigger({
type: 'sourceopen'
});
strictEqual(url, '00001.ts', 'the first segment is requested');
});
})(window, window.videojs);