7429ce71 by David LaPalomento

Fix tests

Make the withCredentials test synchronous so that karma doesn't hang on it. Pull out test player creation so that it can be re-used. Re-indented player.src invocations.
1 parent e5a76497
(function(window, videojs, undefined) {
'use strict';
/*
======== A Handy Little QUnit Reference ========
http://api.qunitjs.com/
......@@ -30,6 +31,29 @@ var
requests,
xhr,
createPlayer = function(options) {
var tech, video, player;
video = document.createElement('video');
document.querySelector('#qunit-fixture').appendChild(video);
player = videojs(video, {
flash: {
swf: ''
},
techOrder: ['hls'],
hls: options || {}
});
player.buffered = function() {
return videojs.createTimeRange(0, 0);
};
tech = player.el().querySelector('.vjs-tech');
tech.vjs_getProperty = function() {};
tech.vjs_src = function() {};
videojs.Flash.onReady(tech.id);
return player;
},
standardXHRResponse = function(request) {
if (!request.url) {
return;
......@@ -96,20 +120,6 @@ module('HLS', {
this.abort = function() {};
};
// create the test player
var video = document.createElement('video');
document.querySelector('#qunit-fixture').appendChild(video);
player = videojs(video, {
flash: {
swf: ''//'../node_modules/video.js/dist/video-js/video-js.swf'
},
techOrder: ['hls']
});
player.buffered = function() {
return videojs.createTimeRange(0, 0);
};
// store functionality that some tests need to mock
oldSegmentParser = videojs.Hls.SegmentParser;
oldSetTimeout = window.setTimeout;
......@@ -121,10 +131,8 @@ module('HLS', {
requests.push(xhr);
};
var tech = player.el().querySelector('.vjs-tech');
tech.vjs_getProperty = function() {};
tech.vjs_src = function() {};
videojs.Flash.onReady(tech.id);
// create the test player
player = createPlayer();
},
teardown: function() {
......@@ -144,7 +152,10 @@ test('starts playing if autoplay is specified', function() {
plays++;
};
player.options().autoplay = true;
player.src({src: 'manifest/playlist.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/playlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -160,7 +171,10 @@ test('creates a PlaylistLoader on init', function() {
});
ok(!player.hls.playlists, 'waits for set src to create the loader');
player.src({src:'manifest/playlist.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src:'manifest/playlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -182,7 +196,10 @@ test('sets the duration if one is available on the playlist', function() {
}
calls++;
};
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -201,7 +218,10 @@ test('calculates the duration if needed', function() {
}
durations.push(duration);
};
player.src({src: 'http://example.com/manifest/missingExtinf.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'http://example.com/manifest/missingExtinf.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -214,7 +234,10 @@ test('calculates the duration if needed', function() {
});
test('starts downloading a segment on loadedmetadata', function() {
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.buffered = function() {
return videojs.createTimeRange(0, 0);
};
......@@ -232,7 +255,10 @@ test('starts downloading a segment on loadedmetadata', function() {
});
test('recognizes absolute URIs and requests them unmodified', function() {
player.src({src: 'manifest/absoluteUris.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/absoluteUris.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -245,7 +271,10 @@ test('recognizes absolute URIs and requests them unmodified', function() {
});
test('recognizes domain-relative URLs', function() {
player.src({src: 'manifest/domainUris.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/domainUris.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -260,14 +289,20 @@ test('recognizes domain-relative URLs', function() {
test('re-initializes the tech for each source', function() {
var firstPlaylists, secondPlaylists, firstMSE, secondMSE;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
firstPlaylists = player.hls.playlists;
firstMSE = player.hls.mediaSource;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -283,7 +318,10 @@ test('triggers an error when a master playlist request errors', function() {
player.on('error', function() {
error = player.hls.error;
});
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -294,7 +332,10 @@ test('triggers an error when a master playlist request errors', function() {
});
test('downloads media playlists after loading the master', function() {
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -324,7 +365,10 @@ test('timeupdates do not check to fill the buffer until a media playlist is read
};
this.send = function() {};
};
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -335,7 +379,10 @@ test('timeupdates do not check to fill the buffer until a media playlist is read
});
test('calculates the bandwidth after downloading a segment', function() {
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -352,7 +399,10 @@ test('calculates the bandwidth after downloading a segment', function() {
test('selects a playlist after segment downloads', function() {
var calls = 0;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.selectPlaylist = function() {
calls++;
return player.hls.playlists.master.playlists[0];
......@@ -382,7 +432,10 @@ test('selects a playlist after segment downloads', function() {
test('moves to the next segment if there is a network error', function() {
var mediaIndex;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -401,7 +454,10 @@ test('updates the duration after switching playlists', function() {
var
calls = 0,
selectedPlaylist = false;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.selectPlaylist = function() {
selectedPlaylist = true;
return player.hls.playlists.master.playlists[1];
......@@ -433,7 +489,10 @@ test('downloads additional playlists if required', function() {
playlist = {
uri: 'media3.m3u8'
};
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -471,7 +530,10 @@ test('downloads additional playlists if required', function() {
test('selects a playlist below the current bandwidth', function() {
var playlist;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -493,7 +555,10 @@ test('selects a playlist below the current bandwidth', function() {
test('raises the minimum bitrate for a stream proportionially', function() {
var playlist;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -515,7 +580,10 @@ test('raises the minimum bitrate for a stream proportionially', function() {
test('uses the lowest bitrate if no other is suitable', function() {
var playlist;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -535,7 +603,10 @@ test('uses the lowest bitrate if no other is suitable', function() {
test('selects the correct rendition by player dimensions', function() {
var playlist;
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
......@@ -565,7 +636,10 @@ test('selects the correct rendition by player dimensions', function() {
test('does not download the next segment if the buffer is full', function() {
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.currentTime = function() {
return 15;
};
......@@ -584,7 +658,10 @@ test('does not download the next segment if the buffer is full', function() {
});
test('downloads the next segment if the buffer is getting low', function() {
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -612,7 +689,10 @@ test('downloads the next segment if the buffer is getting low', function() {
});
test('stops downloading segments at the end of the playlist', function() {
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -626,7 +706,10 @@ test('stops downloading segments at the end of the playlist', function() {
test('only makes one segment request at a time', function() {
var openedXhrs = 0;
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -650,7 +733,10 @@ test('only makes one segment request at a time', function() {
});
test('cancels outstanding XHRs when seeking', function() {
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -688,7 +774,10 @@ test('flushes the parser after each segment', function() {
this.tagsAvailable = function() {};
};
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -720,7 +809,10 @@ test('drops tags before the target timestamp when seeking', function() {
// push a tag into the buffer
tags.push({ pts: 0, bytes: 0 });
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -774,7 +866,10 @@ test('clears pending buffer updates when seeking', function() {
};
// queue up a tag to be pushed into the buffer (but don't push it yet!)
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -802,7 +897,10 @@ test('playlist 404 should trigger MEDIA_ERR_NETWORK', function() {
player.on('error', function() {
errorTriggered = true;
});
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -818,7 +916,10 @@ test('playlist 404 should trigger MEDIA_ERR_NETWORK', function() {
});
test('segment 404 should trigger MEDIA_ERR_NETWORK', function () {
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
......@@ -831,7 +932,10 @@ test('segment 404 should trigger MEDIA_ERR_NETWORK', function () {
});
test('segment 500 should trigger MEDIA_ERR_ABORTED', function () {
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
......@@ -845,14 +949,20 @@ test('segment 500 should trigger MEDIA_ERR_ABORTED', function () {
test('has no effect if native HLS is available', function() {
videojs.Hls.supportsNativeHls = true;
player.src({src: 'http://example.com/manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'http://example.com/manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
ok(!(player.currentSrc() in videojs.mediaSources),
'no media source was opened');
});
test('duration is Infinity for live playlists', function() {
player.src({src: 'http://example.com/manifest/missingEndlist.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'http://example.com/manifest/missingEndlist.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -868,7 +978,10 @@ test('does not reload playlists with an endlist tag', function() {
window.setTimeout = function(callback, timeout) {
callbacks.push({ callback: callback, timeout: timeout });
};
player.src({src: 'manifest/media.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -877,7 +990,10 @@ test('does not reload playlists with an endlist tag', function() {
});
test('updates the media index when a playlist reloads', function() {
player.src({src: 'http://example.com/live-updating.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'http://example.com/live-updating.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -920,7 +1036,10 @@ test('mediaIndex is zero before the first segment loads', function() {
this.open = function() {};
this.send = function() {};
};
player.src({src: 'http://example.com/first-seg-load.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'http://example.com/first-seg-load.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -929,7 +1048,10 @@ test('mediaIndex is zero before the first segment loads', function() {
});
test('reloads out-of-date live playlists when switching variants', function() {
player.src({src: 'http://example.com/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'http://example.com/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
......@@ -970,40 +1092,38 @@ test('does not reload master playlists', function() {
callbacks.push(callback);
};
player.src({src: 'http://example.com/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'http://example.com/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
strictEqual(callbacks.length, 0, 'no reload scheduled');
strictEqual(callbacks.length,
0, 'no reload scheduled');
});
test('if withCredentials option is used, withCredentials is set on the XHR object', function() {
stop();
player.dispose();
var video = document.createElement('video');
document.querySelector('#qunit-fixture').appendChild(video);
player = videojs(video, {
flash: {
swf: '../node_modules/video.js/dist/video-js/video-js.swf'
},
hls: {
player = createPlayer({
withCredentials: true
},
techOrder: ['hls']
}, function() {
player.src({src: 'http://example.com/media.m3u8', type: 'application/vnd.apple.mpegurl'});
});
player.src({
src: 'http://example.com/media.m3u8',
type: 'application/vnd.apple.mpegurl'
});
player.hls.mediaSource.trigger({
type: 'sourceopen'
});
ok(requests[0].withCredentials, "with credentials should be set to true if that option is passed in");
start();
});
});
test('does not break if the playlist has no segments', function() {
player.src({src: 'manifest/master.m3u8', type: 'application/vnd.apple.mpegurl'});
player.src({
src: 'manifest/master.m3u8',
type: 'application/vnd.apple.mpegurl'
});
try {
player.hls.mediaSource.trigger({
type: 'sourceopen'
......