1
0
mirror of https://github.com/videojs/video.js.git synced 2025-07-13 01:30:17 +02:00

@misteroneill updated tests to qunit 2.0. closes #3509

This commit is contained in:
Pat O'Neill
2016-08-12 13:51:31 -04:00
committed by Gary Katsevman
parent b3e4e95f9c
commit 72c44daaf3
45 changed files with 1701 additions and 1700 deletions

View File

@ -15,19 +15,19 @@ import TextTrackList from '../../../src/js/tracks/text-track-list';
import sinon from 'sinon';
QUnit.module('Media Tech', {
setup() {
beforeEach(assert) {
this.noop = function() {};
this.clock = sinon.useFakeTimers();
this.featuresProgessEvents = Tech.prototype.featuresProgessEvents;
Tech.prototype.featuresProgressEvents = false;
},
teardown() {
afterEach(assert) {
this.clock.restore();
Tech.prototype.featuresProgessEvents = this.featuresProgessEvents;
}
});
QUnit.test('should synthesize timeupdate events by default', function() {
QUnit.test('should synthesize timeupdate events by default', function(assert) {
let timeupdates = 0;
const tech = new Tech();
@ -38,10 +38,10 @@ QUnit.test('should synthesize timeupdate events by default', function() {
tech.trigger('play');
this.clock.tick(250);
QUnit.equal(timeupdates, 1, 'triggered at least one timeupdate');
assert.equal(timeupdates, 1, 'triggered at least one timeupdate');
});
QUnit.test('stops manual timeupdates while paused', function() {
QUnit.test('stops manual timeupdates while paused', function(assert) {
let timeupdates = 0;
const tech = new Tech();
@ -51,19 +51,19 @@ QUnit.test('stops manual timeupdates while paused', function() {
tech.trigger('play');
this.clock.tick(10 * 250);
QUnit.ok(timeupdates > 0, 'timeupdates fire during playback');
assert.ok(timeupdates > 0, 'timeupdates fire during playback');
tech.trigger('pause');
timeupdates = 0;
this.clock.tick(10 * 250);
QUnit.equal(timeupdates, 0, 'timeupdates do not fire when paused');
assert.equal(timeupdates, 0, 'timeupdates do not fire when paused');
tech.trigger('play');
this.clock.tick(10 * 250);
QUnit.ok(timeupdates > 0, 'timeupdates fire when playback resumes');
assert.ok(timeupdates > 0, 'timeupdates fire when playback resumes');
});
QUnit.test('should synthesize progress events by default', function() {
QUnit.test('should synthesize progress events by default', function(assert) {
let progresses = 0;
let bufferedPercent = 0.5;
const tech = new Tech();
@ -76,19 +76,19 @@ QUnit.test('should synthesize progress events by default', function() {
};
this.clock.tick(500);
QUnit.equal(progresses, 0, 'waits until ready');
assert.equal(progresses, 0, 'waits until ready');
tech.trigger('ready');
this.clock.tick(500);
QUnit.equal(progresses, 1, 'triggered one event');
assert.equal(progresses, 1, 'triggered one event');
tech.trigger('ready');
bufferedPercent = 0.75;
this.clock.tick(500);
QUnit.equal(progresses, 2, 'repeated readies are ok');
assert.equal(progresses, 2, 'repeated readies are ok');
});
QUnit.test('dispose() should stop time tracking', function() {
QUnit.test('dispose() should stop time tracking', function(assert) {
const tech = new Tech();
tech.dispose();
@ -98,41 +98,41 @@ QUnit.test('dispose() should stop time tracking', function() {
try {
this.clock.tick(10 * 1000);
} catch (e) {
return QUnit.equal(e, undefined, 'threw an exception');
return assert.equal(e, undefined, 'threw an exception');
}
QUnit.ok(true, 'no exception was thrown');
assert.ok(true, 'no exception was thrown');
});
QUnit.test('dispose() should clear all tracks that are passed when its created', function() {
QUnit.test('dispose() should clear all tracks that are passed when its created', function(assert) {
const audioTracks = new AudioTrackList([new AudioTrack(), new AudioTrack()]);
const videoTracks = new VideoTrackList([new VideoTrack(), new VideoTrack()]);
const textTracks = new TextTrackList([new TextTrack({tech: {}}),
new TextTrack({tech: {}})]);
QUnit.equal(audioTracks.length, 2, 'should have two audio tracks at the start');
QUnit.equal(videoTracks.length, 2, 'should have two video tracks at the start');
QUnit.equal(textTracks.length, 2, 'should have two text tracks at the start');
assert.equal(audioTracks.length, 2, 'should have two audio tracks at the start');
assert.equal(videoTracks.length, 2, 'should have two video tracks at the start');
assert.equal(textTracks.length, 2, 'should have two text tracks at the start');
const tech = new Tech({audioTracks, videoTracks, textTracks});
QUnit.equal(tech.videoTracks().length,
assert.equal(tech.videoTracks().length,
videoTracks.length,
'should hold video tracks that we passed');
QUnit.equal(tech.audioTracks().length,
assert.equal(tech.audioTracks().length,
audioTracks.length,
'should hold audio tracks that we passed');
QUnit.equal(tech.textTracks().length,
assert.equal(tech.textTracks().length,
textTracks.length,
'should hold text tracks that we passed');
tech.dispose();
QUnit.equal(audioTracks.length, 0, 'should have zero audio tracks after dispose');
QUnit.equal(videoTracks.length, 0, 'should have zero video tracks after dispose');
QUnit.equal(textTracks.length, 0, 'should have zero text tracks after dispose');
assert.equal(audioTracks.length, 0, 'should have zero audio tracks after dispose');
assert.equal(videoTracks.length, 0, 'should have zero video tracks after dispose');
assert.equal(textTracks.length, 0, 'should have zero text tracks after dispose');
});
QUnit.test('dispose() should clear all tracks that are added after creation', function() {
QUnit.test('dispose() should clear all tracks that are added after creation', function(assert) {
const tech = new Tech();
tech.addRemoteTextTrack({});
@ -144,30 +144,30 @@ QUnit.test('dispose() should clear all tracks that are added after creation', fu
tech.videoTracks().addTrack_(new VideoTrack());
tech.videoTracks().addTrack_(new VideoTrack());
QUnit.equal(tech.audioTracks().length, 2, 'should have two audio tracks at the start');
QUnit.equal(tech.videoTracks().length, 2, 'should have two video tracks at the start');
QUnit.equal(tech.textTracks().length, 2, 'should have two video tracks at the start');
QUnit.equal(tech.remoteTextTrackEls().length,
assert.equal(tech.audioTracks().length, 2, 'should have two audio tracks at the start');
assert.equal(tech.videoTracks().length, 2, 'should have two video tracks at the start');
assert.equal(tech.textTracks().length, 2, 'should have two video tracks at the start');
assert.equal(tech.remoteTextTrackEls().length,
2,
'should have two remote text tracks els');
QUnit.equal(tech.remoteTextTracks().length, 2, 'should have two remote text tracks');
assert.equal(tech.remoteTextTracks().length, 2, 'should have two remote text tracks');
tech.dispose();
QUnit.equal(tech.audioTracks().length,
assert.equal(tech.audioTracks().length,
0,
'should have zero audio tracks after dispose');
QUnit.equal(tech.videoTracks().length,
assert.equal(tech.videoTracks().length,
0,
'should have zero video tracks after dispose');
QUnit.equal(tech.remoteTextTrackEls().length,
assert.equal(tech.remoteTextTrackEls().length,
0,
'should have zero remote text tracks els');
QUnit.equal(tech.remoteTextTracks().length, 0, 'should have zero remote text tracks');
QUnit.equal(tech.textTracks().length, 0, 'should have zero video tracks after dispose');
assert.equal(tech.remoteTextTracks().length, 0, 'should have zero remote text tracks');
assert.equal(tech.textTracks().length, 0, 'should have zero video tracks after dispose');
});
QUnit.test('should add the source handler interface to a tech', function() {
QUnit.test('should add the source handler interface to a tech', function(assert) {
const sourceA = { src: 'foo.mp4', type: 'video/mp4' };
const sourceB = { src: 'no-support', type: 'no-support' };
@ -178,16 +178,16 @@ QUnit.test('should add the source handler interface to a tech', function() {
Tech.withSourceHandlers(MyTech);
// Check for the expected class methods
QUnit.ok(MyTech.registerSourceHandler,
assert.ok(MyTech.registerSourceHandler,
'added a registerSourceHandler function to the Tech');
QUnit.ok(MyTech.selectSourceHandler,
assert.ok(MyTech.selectSourceHandler,
'added a selectSourceHandler function to the Tech');
// Create an instance of Tech
const tech = new MyTech();
// Check for the expected instance methods
QUnit.ok(tech.setSource, 'added a setSource function to the tech instance');
assert.ok(tech.setSource, 'added a setSource function to the tech instance');
// Create an internal state class for the source handler
// The internal class would be used by a source handler to maintain state
@ -209,7 +209,7 @@ QUnit.test('should add the source handler interface to a tech', function() {
return '';
},
canHandleSource(source, options) {
QUnit.strictEqual(tech.options_,
assert.strictEqual(tech.options_,
options,
'tech options passed to canHandleSource');
if (source.type !== 'no-support') {
@ -218,13 +218,13 @@ QUnit.test('should add the source handler interface to a tech', function() {
return '';
},
handleSource(s, t, o) {
QUnit.strictEqual(tech,
assert.strictEqual(tech,
t,
'tech instance passed to source handler');
QUnit.strictEqual(sourceA,
assert.strictEqual(sourceA,
s,
'tech instance passed to the source handler');
QUnit.strictEqual(tech.options_,
assert.strictEqual(tech.options_,
o,
'tech options passed to the source handler handleSource');
return new HandlerInternalState();
@ -241,41 +241,41 @@ QUnit.test('should add the source handler interface to a tech', function() {
return '';
},
handleSource(source, tech_, options) {
QUnit.ok(false, 'handlerTwo supports nothing and should never be called');
assert.ok(false, 'handlerTwo supports nothing and should never be called');
}
};
// Test registering source handlers
MyTech.registerSourceHandler(handlerOne);
QUnit.strictEqual(MyTech.sourceHandlers[0],
assert.strictEqual(MyTech.sourceHandlers[0],
handlerOne,
'handlerOne was added to the source handler array');
MyTech.registerSourceHandler(handlerTwo, 0);
QUnit.strictEqual(MyTech.sourceHandlers[0],
assert.strictEqual(MyTech.sourceHandlers[0],
handlerTwo,
'handlerTwo was registered at the correct index (0)');
// Test handler selection
QUnit.strictEqual(MyTech.selectSourceHandler(sourceA, tech.options_),
assert.strictEqual(MyTech.selectSourceHandler(sourceA, tech.options_),
handlerOne,
'handlerOne was selected to handle the valid source');
QUnit.strictEqual(MyTech.selectSourceHandler(sourceB, tech.options_),
assert.strictEqual(MyTech.selectSourceHandler(sourceB, tech.options_),
null,
'no handler was selected to handle the invalid source');
// Test canPlayType return values
QUnit.strictEqual(MyTech.canPlayType(sourceA.type),
assert.strictEqual(MyTech.canPlayType(sourceA.type),
'probably',
'the Tech returned probably for the valid source');
QUnit.strictEqual(MyTech.canPlayType(sourceB.type),
assert.strictEqual(MyTech.canPlayType(sourceB.type),
'',
'the Tech returned an empty string for the invalid source');
// Test canPlaySource return values
QUnit.strictEqual(MyTech.canPlaySource(sourceA, tech.options_),
assert.strictEqual(MyTech.canPlaySource(sourceA, tech.options_),
'probably',
'the Tech returned probably for the valid source');
QUnit.strictEqual(MyTech.canPlaySource(sourceB, tech.options_),
assert.strictEqual(MyTech.canPlaySource(sourceB, tech.options_),
'',
'the Tech returned an empty string for the invalid source');
@ -288,52 +288,52 @@ QUnit.test('should add the source handler interface to a tech', function() {
tech.videoTracks().addTrack_(new VideoTrack());
tech.videoTracks().addTrack_(new VideoTrack());
QUnit.equal(tech.audioTracks().length, 2, 'should have two audio tracks at the start');
QUnit.equal(tech.videoTracks().length, 2, 'should have two video tracks at the start');
QUnit.equal(tech.textTracks().length, 2, 'should have two video tracks at the start');
QUnit.equal(tech.remoteTextTrackEls().length,
assert.equal(tech.audioTracks().length, 2, 'should have two audio tracks at the start');
assert.equal(tech.videoTracks().length, 2, 'should have two video tracks at the start');
assert.equal(tech.textTracks().length, 2, 'should have two video tracks at the start');
assert.equal(tech.remoteTextTrackEls().length,
2,
'should have two remote text tracks els');
QUnit.equal(tech.remoteTextTracks().length, 2, 'should have two remote text tracks');
assert.equal(tech.remoteTextTracks().length, 2, 'should have two remote text tracks');
// Pass a source through the source handler process of a tech instance
tech.setSource(sourceA);
// verify that the Tracks are still there
QUnit.equal(tech.audioTracks().length, 2, 'should have two audio tracks at the start');
QUnit.equal(tech.videoTracks().length, 2, 'should have two video tracks at the start');
QUnit.equal(tech.textTracks().length, 2, 'should have two video tracks at the start');
QUnit.equal(tech.remoteTextTrackEls().length,
assert.equal(tech.audioTracks().length, 2, 'should have two audio tracks at the start');
assert.equal(tech.videoTracks().length, 2, 'should have two video tracks at the start');
assert.equal(tech.textTracks().length, 2, 'should have two video tracks at the start');
assert.equal(tech.remoteTextTrackEls().length,
2,
'should have two remote text tracks els');
QUnit.equal(tech.remoteTextTracks().length, 2, 'should have two remote text tracks');
assert.equal(tech.remoteTextTracks().length, 2, 'should have two remote text tracks');
QUnit.strictEqual(tech.currentSource_, sourceA, 'sourceA was handled and stored');
QUnit.ok(tech.sourceHandler_.dispose, 'the handlerOne state instance was stored');
assert.strictEqual(tech.currentSource_, sourceA, 'sourceA was handled and stored');
assert.ok(tech.sourceHandler_.dispose, 'the handlerOne state instance was stored');
// Pass a second source
tech.setSource(sourceA);
QUnit.strictEqual(tech.currentSource_, sourceA, 'sourceA was handled and stored');
QUnit.ok(tech.sourceHandler_.dispose, 'the handlerOne state instance was stored');
assert.strictEqual(tech.currentSource_, sourceA, 'sourceA was handled and stored');
assert.ok(tech.sourceHandler_.dispose, 'the handlerOne state instance was stored');
// verify that all the tracks were removed as we got a new source
QUnit.equal(tech.audioTracks().length, 0, 'should have zero audio tracks');
QUnit.equal(tech.videoTracks().length, 0, 'should have zero video tracks');
QUnit.equal(tech.textTracks().length, 2, 'should have two text tracks');
QUnit.equal(tech.remoteTextTrackEls().length,
assert.equal(tech.audioTracks().length, 0, 'should have zero audio tracks');
assert.equal(tech.videoTracks().length, 0, 'should have zero video tracks');
assert.equal(tech.textTracks().length, 2, 'should have two text tracks');
assert.equal(tech.remoteTextTrackEls().length,
2,
'should have two remote text tracks els');
QUnit.equal(tech.remoteTextTracks().length, 2, 'should have two remote text tracks');
assert.equal(tech.remoteTextTracks().length, 2, 'should have two remote text tracks');
// Check that the handler dipose method works
QUnit.ok(disposeCalled, 'dispose has been called for the handler yet');
assert.ok(disposeCalled, 'dispose has been called for the handler yet');
disposeCalled = false;
tech.dispose();
QUnit.ok(disposeCalled,
assert.ok(disposeCalled,
'the handler dispose method was called when the tech was disposed');
});
QUnit.test('should handle unsupported sources with the source handler API', function() {
QUnit.test('should handle unsupported sources with the source handler API', function(assert) {
// Define a new tech class
const MyTech = extendFn(Tech);
@ -350,11 +350,11 @@ QUnit.test('should handle unsupported sources with the source handler API', func
};
tech.setSource('');
QUnit.ok(usedNative,
assert.ok(usedNative,
'native source handler was used when an unsupported source was set');
});
QUnit.test('should allow custom error events to be set', function() {
QUnit.test('should allow custom error events to be set', function(assert) {
const tech = new Tech();
const errors = [];
@ -362,26 +362,26 @@ QUnit.test('should allow custom error events to be set', function() {
errors.push(tech.error());
});
QUnit.equal(tech.error(), null, 'error is null by default');
assert.equal(tech.error(), null, 'error is null by default');
tech.error(new MediaError(1));
QUnit.equal(errors.length, 1, 'triggered an error event');
QUnit.equal(errors[0].code, 1, 'set the proper code');
assert.equal(errors.length, 1, 'triggered an error event');
assert.equal(errors[0].code, 1, 'set the proper code');
tech.error(2);
QUnit.equal(errors.length, 2, 'triggered an error event');
QUnit.equal(errors[1].code, 2, 'wrapped the error code');
assert.equal(errors.length, 2, 'triggered an error event');
assert.equal(errors[1].code, 2, 'wrapped the error code');
});
QUnit.test('should track whether a video has played', function() {
QUnit.test('should track whether a video has played', function(assert) {
const tech = new Tech();
QUnit.equal(tech.played().length, 0, 'starts with zero length');
assert.equal(tech.played().length, 0, 'starts with zero length');
tech.trigger('playing');
QUnit.equal(tech.played().length, 1, 'has length after playing');
assert.equal(tech.played().length, 1, 'has length after playing');
});
QUnit.test('delegates seekable to the source handler', function() {
QUnit.test('delegates seekable to the source handler', function(assert) {
const MyTech = extendFn(Tech, {
seekable() {
throw new Error('You should not be calling me!');
@ -417,24 +417,24 @@ QUnit.test('delegates seekable to the source handler', function() {
type: 'video/mp4'
});
tech.seekable();
QUnit.equal(seekableCount, 1, 'called the source handler');
assert.equal(seekableCount, 1, 'called the source handler');
});
QUnit.test('Tech.isTech returns correct answers for techs and components', function() {
QUnit.test('Tech.isTech returns correct answers for techs and components', function(assert) {
const isTech = Tech.isTech;
QUnit.ok(isTech(Tech), 'Tech is a Tech');
QUnit.ok(isTech(Html5), 'Html5 is a Tech');
QUnit.ok(isTech(new Html5({}, {})), 'An html5 instance is a Tech');
QUnit.ok(isTech(Flash), 'Flash is a Tech');
QUnit.ok(!isTech(5), 'A number is not a Tech');
QUnit.ok(!isTech('this is a tech'), 'A string is not a Tech');
QUnit.ok(!isTech(Button), 'A Button is not a Tech');
QUnit.ok(!isTech(new Button({}, {})), 'A Button instance is not a Tech');
QUnit.ok(!isTech(isTech), 'A function is not a Tech');
assert.ok(isTech(Tech), 'Tech is a Tech');
assert.ok(isTech(Html5), 'Html5 is a Tech');
assert.ok(isTech(new Html5({}, {})), 'An html5 instance is a Tech');
assert.ok(isTech(Flash), 'Flash is a Tech');
assert.ok(!isTech(5), 'A number is not a Tech');
assert.ok(!isTech('this is a tech'), 'A string is not a Tech');
assert.ok(!isTech(Button), 'A Button is not a Tech');
assert.ok(!isTech(new Button({}, {})), 'A Button instance is not a Tech');
assert.ok(!isTech(isTech), 'A function is not a Tech');
});
QUnit.test('Tech#setSource clears currentSource_ after repeated loadstart', function() {
QUnit.test('Tech#setSource clears currentSource_ after repeated loadstart', function(assert) {
let disposed = false;
const MyTech = extendFn(Tech);
@ -464,21 +464,21 @@ QUnit.test('Tech#setSource clears currentSource_ after repeated loadstart', func
tech.setSource('test');
tech.currentSource_ = 'test';
tech.trigger('loadstart');
QUnit.equal(tech.currentSource_, 'test', 'Current source is test');
assert.equal(tech.currentSource_, 'test', 'Current source is test');
// Second loadstart
tech.trigger('loadstart');
QUnit.equal(tech.currentSource_, null, 'Current source is null');
QUnit.equal(disposed, true, 'disposed is true');
assert.equal(tech.currentSource_, null, 'Current source is null');
assert.equal(disposed, true, 'disposed is true');
// Third loadstart
tech.currentSource_ = 'test';
tech.trigger('loadstart');
QUnit.equal(tech.currentSource_, null, 'Current source is still null');
assert.equal(tech.currentSource_, null, 'Current source is still null');
});
QUnit.test('setSource after tech dispose should dispose source handler once', function() {
QUnit.test('setSource after tech dispose should dispose source handler once', function(assert) {
const MyTech = extendFn(Tech);
Tech.withSourceHandlers(MyTech);
@ -506,23 +506,23 @@ QUnit.test('setSource after tech dispose should dispose source handler once', fu
tech.setSource('test');
QUnit.equal(disposeCount, 0, 'did not call sourceHandler_ dispose for initial dispose');
assert.equal(disposeCount, 0, 'did not call sourceHandler_ dispose for initial dispose');
tech.dispose();
QUnit.ok(!tech.sourceHandler_, 'sourceHandler should be unset');
QUnit.equal(disposeCount, 1, 'called the source handler dispose');
assert.ok(!tech.sourceHandler_, 'sourceHandler should be unset');
assert.equal(disposeCount, 1, 'called the source handler dispose');
// this would normally be done above tech on src after dispose
tech.el_ = tech.createEl();
tech.setSource('test');
QUnit.equal(disposeCount, 1, 'did not dispose after initial setSource');
assert.equal(disposeCount, 1, 'did not dispose after initial setSource');
tech.setSource('test');
QUnit.equal(disposeCount, 2, 'did dispose on second setSource');
assert.equal(disposeCount, 2, 'did dispose on second setSource');
});
QUnit.test('setSource after previous setSource should dispose source handler once', function() {
QUnit.test('setSource after previous setSource should dispose source handler once', function(assert) {
const MyTech = extendFn(Tech);
Tech.withSourceHandlers(MyTech);
@ -549,13 +549,13 @@ QUnit.test('setSource after previous setSource should dispose source handler onc
const tech = new MyTech();
tech.setSource('test');
QUnit.equal(disposeCount, 0, 'did not call dispose for initial setSource');
assert.equal(disposeCount, 0, 'did not call dispose for initial setSource');
tech.setSource('test');
QUnit.equal(disposeCount, 1, 'did dispose for second setSource');
assert.equal(disposeCount, 1, 'did dispose for second setSource');
tech.setSource('test');
QUnit.equal(disposeCount, 2, 'did dispose for third setSource');
assert.equal(disposeCount, 2, 'did dispose for third setSource');
});