Standardize plugin naming and re-organize some tests
Move segment parsing tests into their own file and top-level plugin tests intovideojs-hls_test.js. Use 'videojs' instead of 'video-js'.
Showing
6 changed files
with
80 additions
and
64 deletions
... | @@ -13,7 +13,7 @@ | ... | @@ -13,7 +13,7 @@ |
13 | <script src="node_modules/videojs-media-sources/videojs-media-sources.js"></script> | 13 | <script src="node_modules/videojs-media-sources/videojs-media-sources.js"></script> |
14 | 14 | ||
15 | <!-- HLS plugin --> | 15 | <!-- HLS plugin --> |
16 | <script src="src/video-js-hls.js"></script> | 16 | <script src="src/videojs-hls.js"></script> |
17 | 17 | ||
18 | <!-- segment handling --> | 18 | <!-- segment handling --> |
19 | <script src="src/flv-tag.js"></script> | 19 | <script src="src/flv-tag.js"></script> | ... | ... |
... | @@ -17,7 +17,7 @@ videojs.plugin('hls', function(options) { | ... | @@ -17,7 +17,7 @@ videojs.plugin('hls', function(options) { |
17 | player = this, | 17 | player = this, |
18 | url, | 18 | url, |
19 | 19 | ||
20 | loadSegment, | 20 | fillBuffer, |
21 | selectPlaylist; | 21 | selectPlaylist; |
22 | 22 | ||
23 | if (typeof options === 'string') { | 23 | if (typeof options === 'string') { | ... | ... |
... | @@ -8,13 +8,6 @@ | ... | @@ -8,13 +8,6 @@ |
8 | Parser = window.videojs.m3u8.Parser, | 8 | Parser = window.videojs.m3u8.Parser, |
9 | parser; | 9 | parser; |
10 | 10 | ||
11 | module('environment'); | ||
12 | |||
13 | test('is sane', function() { | ||
14 | expect(1); | ||
15 | ok(true); | ||
16 | }); | ||
17 | |||
18 | /* | 11 | /* |
19 | M3U8 Test Suite | 12 | M3U8 Test Suite |
20 | */ | 13 | */ | ... | ... |
... | @@ -35,13 +35,6 @@ | ... | @@ -35,13 +35,6 @@ |
35 | testScriptEcmaArray, | 35 | testScriptEcmaArray, |
36 | testNalUnit; | 36 | testNalUnit; |
37 | 37 | ||
38 | module('environment'); | ||
39 | |||
40 | test('is sane', function() { | ||
41 | expect(1); | ||
42 | ok(true); | ||
43 | }); | ||
44 | |||
45 | module('segment parser', { | 38 | module('segment parser', { |
46 | setup: function() { | 39 | setup: function() { |
47 | parser = new window.videojs.hls.SegmentParser(); | 40 | parser = new window.videojs.hls.SegmentParser(); |
... | @@ -228,25 +221,4 @@ | ... | @@ -228,25 +221,4 @@ |
228 | 'the size of the previous tag is correct'); | 221 | 'the size of the previous tag is correct'); |
229 | } | 222 | } |
230 | }); | 223 | }); |
231 | 224 | })(window); | |
232 | module('segment controller', { | ||
233 | setup: function() { | ||
234 | segmentController = new window.videojs.hls.SegmentController(); | ||
235 | this.vjsget = window.videojs.get; | ||
236 | window.videojs.get = function(url, success) { | ||
237 | success(window.bcSegment); | ||
238 | }; | ||
239 | }, | ||
240 | teardown: function() { | ||
241 | window.videojs.get = this.vjsget; | ||
242 | } | ||
243 | }); | ||
244 | |||
245 | test('bandwidth calulation test', function() { | ||
246 | var | ||
247 | multiSecondData = segmentController.calculateThroughput(10000, 1000, 2000), | ||
248 | subSecondData = segmentController.calculateThroughput(10000, 1000, 1500); | ||
249 | equal(multiSecondData, 80000, 'MULTI-Second bits per second calculation'); | ||
250 | equal(subSecondData, 160000, 'SUB-Second bits per second calculation'); | ||
251 | }); | ||
252 | })(this); | ... | ... |
... | @@ -12,7 +12,7 @@ | ... | @@ -12,7 +12,7 @@ |
12 | <script src="../node_modules/videojs-media-sources/videojs-media-sources.js"></script> | 12 | <script src="../node_modules/videojs-media-sources/videojs-media-sources.js"></script> |
13 | 13 | ||
14 | <!-- HLS plugin --> | 14 | <!-- HLS plugin --> |
15 | <script src="../src/video-js-hls.js"></script> | 15 | <script src="../src/videojs-hls.js"></script> |
16 | <script src="../src/flv-tag.js"></script> | 16 | <script src="../src/flv-tag.js"></script> |
17 | <script src="../src/exp-golomb.js"></script> | 17 | <script src="../src/exp-golomb.js"></script> |
18 | <script src="../src/h264-stream.js"></script> | 18 | <script src="../src/h264-stream.js"></script> |
... | @@ -34,7 +34,15 @@ | ... | @@ -34,7 +34,15 @@ |
34 | <script src="../src/bin-utils.js"></script> | 34 | <script src="../src/bin-utils.js"></script> |
35 | 35 | ||
36 | <!-- Test cases --> | 36 | <!-- Test cases --> |
37 | <script src="video-js-hls_test.js"></script> | 37 | <script> |
38 | module('environment'); | ||
39 | test('is sane', function() { | ||
40 | expect(1); | ||
41 | ok(true); | ||
42 | }); | ||
43 | </script> | ||
44 | <script src="videojs-hls_test.js"></script> | ||
45 | <script src="segment-parser.js"></script> | ||
38 | <script src="exp-golomb_test.js"></script> | 46 | <script src="exp-golomb_test.js"></script> |
39 | <script src="flv-tag_test.js"></script> | 47 | <script src="flv-tag_test.js"></script> |
40 | <script src="m3u8_test.js"></script> | 48 | <script src="m3u8_test.js"></script> | ... | ... |
1 | (function(window, videojs, undefined) { | 1 | (function(window, videojs, undefined) { |
2 | var player, oldXhr, oldSourceBuffer; | 2 | /* |
3 | ======== A Handy Little QUnit Reference ======== | ||
4 | http://api.qunitjs.com/ | ||
5 | |||
6 | Test methods: | ||
7 | module(name, {[setup][ ,teardown]}) | ||
8 | test(name, callback) | ||
9 | expect(numberOfAssertions) | ||
10 | stop(increment) | ||
11 | start(decrement) | ||
12 | Test assertions: | ||
13 | ok(value, [message]) | ||
14 | equal(actual, expected, [message]) | ||
15 | notEqual(actual, expected, [message]) | ||
16 | deepEqual(actual, expected, [message]) | ||
17 | notDeepEqual(actual, expected, [message]) | ||
18 | strictEqual(actual, expected, [message]) | ||
19 | notStrictEqual(actual, expected, [message]) | ||
20 | throws(block, [expected], [message]) | ||
21 | */ | ||
22 | |||
23 | var player, oldXhr, oldSourceBuffer, xhrParams; | ||
3 | 24 | ||
4 | module('HLS', { | 25 | module('HLS', { |
5 | setup: function() { | 26 | setup: function() { |
... | @@ -7,10 +28,21 @@ module('HLS', { | ... | @@ -7,10 +28,21 @@ module('HLS', { |
7 | document.querySelector('#qunit-fixture').appendChild(video); | 28 | document.querySelector('#qunit-fixture').appendChild(video); |
8 | player = videojs(video); | 29 | player = videojs(video); |
9 | 30 | ||
31 | // make XHR synchronous | ||
10 | oldXhr = window.XMLHttpRequest; | 32 | oldXhr = window.XMLHttpRequest; |
11 | oldSourceBuffer = window.videojs.SourceBuffer; | 33 | window.XMLHttpRequest = function() { |
34 | this.open = function() { | ||
35 | xhrParams = arguments; | ||
36 | }; | ||
37 | this.send = function() { | ||
38 | this.readyState = 4; | ||
39 | this.responseText = window.manifests['media']; | ||
40 | this.onreadystatechange(); | ||
41 | }; | ||
42 | }; | ||
12 | 43 | ||
13 | // mock out SourceBuffer since it won't be available in phantomjs | 44 | // mock out SourceBuffer since it won't be available in phantomjs |
45 | oldSourceBuffer = window.videojs.SourceBuffer; | ||
14 | window.videojs.SourceBuffer = function() { | 46 | window.videojs.SourceBuffer = function() { |
15 | this.appendBuffer = function() {}; | 47 | this.appendBuffer = function() {}; |
16 | }; | 48 | }; |
... | @@ -21,20 +53,13 @@ module('HLS', { | ... | @@ -21,20 +53,13 @@ module('HLS', { |
21 | } | 53 | } |
22 | }); | 54 | }); |
23 | 55 | ||
24 | asyncTest('loads the specified manifest URL on init', function() { | 56 | test('loads the specified manifest URL on init', function() { |
25 | var loadedmanifest = false; | 57 | var loadedmanifest = false, loadedmetadata = false; |
26 | player.on('loadedmanifest', function() { | 58 | player.on('loadedmanifest', function() { |
27 | loadedmanifest = true; | 59 | loadedmanifest = true; |
28 | }); | 60 | }); |
29 | player.on('loadedmetadata', function() { | 61 | player.on('loadedmetadata', function() { |
30 | ok(loadedmanifest, 'loadedmanifest fires'); | 62 | loadedmetadata = true; |
31 | ok(player.hls.manifest, 'the manifest is available'); | ||
32 | ok(player.hls.manifest.segments, 'the segments are parsed'); | ||
33 | strictEqual(player.hls.manifest, | ||
34 | player.hls.currentPlaylist, | ||
35 | 'a playlist is selected'); | ||
36 | strictEqual(player.hls.readyState(), 1, 'the readyState is HAVE_METADATA'); | ||
37 | start(); | ||
38 | }); | 63 | }); |
39 | 64 | ||
40 | player.hls('manifest/playlist.m3u8'); | 65 | player.hls('manifest/playlist.m3u8'); |
... | @@ -42,26 +67,44 @@ asyncTest('loads the specified manifest URL on init', function() { | ... | @@ -42,26 +67,44 @@ asyncTest('loads the specified manifest URL on init', function() { |
42 | videojs.mediaSources[player.currentSrc()].trigger({ | 67 | videojs.mediaSources[player.currentSrc()].trigger({ |
43 | type: 'sourceopen' | 68 | type: 'sourceopen' |
44 | }); | 69 | }); |
70 | ok(loadedmanifest, 'loadedmanifest fires'); | ||
71 | ok(loadedmetadata, 'loadedmetadata fires'); | ||
72 | ok(player.hls.manifest, 'the manifest is available'); | ||
73 | ok(player.hls.manifest.segments, 'the segment entries are parsed'); | ||
74 | strictEqual(player.hls.manifest, | ||
75 | player.hls.currentPlaylist, | ||
76 | 'a playlist is selected'); | ||
77 | strictEqual(player.hls.readyState(), 1, 'the readyState is HAVE_METADATA'); | ||
45 | }); | 78 | }); |
46 | 79 | ||
47 | test('starts downloading a segment on loadedmetadata', function() { | 80 | test('starts downloading a segment on loadedmetadata', function() { |
48 | var url; | ||
49 | window.XMLHttpRequest = function() { | ||
50 | this.open = function() { | ||
51 | url = arguments[1]; | ||
52 | }; | ||
53 | this.send = function() { | ||
54 | this.readyState = 4; | ||
55 | this.responseText = window.manifests['media']; | ||
56 | this.onreadystatechange(); | ||
57 | }; | ||
58 | }; | ||
59 | player.hls('manifest/media.m3u8'); | 81 | player.hls('manifest/media.m3u8'); |
60 | videojs.mediaSources[player.currentSrc()].trigger({ | 82 | videojs.mediaSources[player.currentSrc()].trigger({ |
61 | type: 'sourceopen' | 83 | type: 'sourceopen' |
62 | }); | 84 | }); |
63 | 85 | ||
64 | strictEqual(url, '00001.ts', 'the first segment is requested'); | 86 | strictEqual(xhrParams[1], '00001.ts', 'the first segment is requested'); |
87 | }); | ||
88 | |||
89 | module('segment controller', { | ||
90 | setup: function() { | ||
91 | segmentController = new window.videojs.hls.SegmentController(); | ||
92 | this.vjsget = window.videojs.get; | ||
93 | window.videojs.get = function(url, success) { | ||
94 | success(window.bcSegment); | ||
95 | }; | ||
96 | }, | ||
97 | teardown: function() { | ||
98 | window.videojs.get = this.vjsget; | ||
99 | } | ||
100 | }); | ||
101 | |||
102 | test('bandwidth calulation test', function() { | ||
103 | var | ||
104 | multiSecondData = segmentController.calculateThroughput(10000, 1000, 2000), | ||
105 | subSecondData = segmentController.calculateThroughput(10000, 1000, 1500); | ||
106 | equal(multiSecondData, 80000, 'MULTI-Second bits per second calculation'); | ||
107 | equal(subSecondData, 160000, 'SUB-Second bits per second calculation'); | ||
65 | }); | 108 | }); |
66 | 109 | ||
67 | })(window, window.videojs); | 110 | })(window, window.videojs); | ... | ... |
-
Please register or sign in to post a comment