1
0
mirror of https://github.com/videojs/video.js.git synced 2025-01-25 11:13:52 +02:00
video.js/test/unit/tracks/html-track-element.test.js
Brandon Casey a2b1a33606 fix: cues at startTime 0 do not fire (#4152)
Previously timeupdate would fire before the video was playing, and the tech was not ready. This caused issues when preload was set to auto, because cuechange would fire before the video was even started for cues with a startTime of 0.

Wait for tech to be ready before watching for timeupdate
update unit tests to use TechFaker
Add a unit test to verify that we wait for Tech to be ready.
2017-03-02 14:35:45 -05:00

79 lines
2.5 KiB
JavaScript

/* eslint-env qunit */
import HTMLTrackElement from '../../../src/js/tracks/html-track-element.js';
import TechFaker from '../tech/tech-faker';
QUnit.module('HTML Track Element', {
beforeEach() {
this.tech = new TechFaker();
},
afterEach() {
this.tech.dispose();
this.tech = null;
}
});
QUnit.test('html track element requires a tech', function(assert) {
assert.throws(
function() {
return new HTMLTrackElement();
},
new Error('A tech was not provided.'),
'a tech is required for html track element'
);
});
QUnit.test('can create a html track element with various properties', function(assert) {
const kind = 'chapters';
const label = 'English';
const language = 'en';
const src = 'http://www.example.com';
const htmlTrackElement = new HTMLTrackElement({
kind,
label,
language,
src,
tech: this.tech
});
assert.equal(typeof htmlTrackElement.default, 'undefined', 'we have a default');
assert.equal(htmlTrackElement.kind, kind, 'we have a kind');
assert.equal(htmlTrackElement.label, label, 'we have a label');
assert.equal(htmlTrackElement.readyState, 0, 'we have a readyState');
assert.equal(htmlTrackElement.src, src, 'we have a src');
assert.equal(htmlTrackElement.srclang, language, 'we have a srclang');
assert.equal(htmlTrackElement.track.cues, null, 'we have a track');
});
QUnit.test('defaults when items not provided', function(assert) {
const htmlTrackElement = new HTMLTrackElement({
tech: this.tech
});
assert.equal(typeof htmlTrackElement.default, 'undefined', 'we have a default');
assert.equal(htmlTrackElement.kind, 'subtitles', 'we have a kind');
assert.equal(htmlTrackElement.label, '', 'we have a label');
assert.equal(htmlTrackElement.readyState, 0, 'we have a readyState');
assert.equal(typeof htmlTrackElement.src, 'undefined', 'we have a src');
assert.equal(htmlTrackElement.srclang, '', 'we have a srclang');
assert.equal(htmlTrackElement.track.cues.length, 0, 'we have a track');
});
QUnit.test('fires loadeddata when track cues become populated', function(assert) {
let changes = 0;
const loadHandler = function() {
changes++;
};
const htmlTrackElement = new HTMLTrackElement({
tech() {}
});
htmlTrackElement.addEventListener('load', loadHandler);
// trigger loaded cues event
htmlTrackElement.track.trigger('loadeddata');
assert.equal(changes, 1, 'a loadeddata event trigger addEventListener');
assert.equal(htmlTrackElement.readyState, 2, 'readyState is loaded');
});