2015-04-14 22:08:32 +02:00
|
|
|
import ChaptersButton from '../../../src/js/control-bar/text-track-controls/chapters-button.js';
|
2016-03-25 20:16:56 +02:00
|
|
|
import DescriptionsButton from '../../../src/js/control-bar/text-track-controls/descriptions-button.js';
|
2015-04-14 22:08:32 +02:00
|
|
|
import SubtitlesButton from '../../../src/js/control-bar/text-track-controls/subtitles-button.js';
|
|
|
|
import CaptionsButton from '../../../src/js/control-bar/text-track-controls/captions-button.js';
|
|
|
|
|
2015-11-24 09:39:58 +02:00
|
|
|
import TextTrack from '../../../src/js/tracks/text-track.js';
|
2015-04-14 22:08:32 +02:00
|
|
|
import TextTrackDisplay from '../../../src/js/tracks/text-track-display.js';
|
|
|
|
import Html5 from '../../../src/js/tech/html5.js';
|
|
|
|
import Tech from '../../../src/js/tech/tech.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import Component from '../../../src/js/component.js';
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
import * as browser from '../../../src/js/utils/browser.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import TestHelpers from '../test-helpers.js';
|
|
|
|
import document from 'global/document';
|
|
|
|
|
2015-12-08 18:24:51 +02:00
|
|
|
q.module('Tracks', {
|
2016-03-07 21:54:32 +02:00
|
|
|
setup() {
|
2015-12-08 18:24:51 +02:00
|
|
|
this.clock = sinon.useFakeTimers();
|
|
|
|
},
|
2016-03-07 21:54:32 +02:00
|
|
|
teardown() {
|
2015-12-08 18:24:51 +02:00
|
|
|
this.clock.restore();
|
|
|
|
}
|
|
|
|
});
|
2015-03-11 03:01:11 +02:00
|
|
|
|
2015-02-14 01:18:07 +02:00
|
|
|
test('should place title list item into ul', function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
let player;
|
|
|
|
let chaptersButton;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
player = TestHelpers.makePlayer();
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-11 03:01:11 +02:00
|
|
|
chaptersButton = new ChaptersButton(player);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
let menuContentElement = chaptersButton.el().getElementsByTagName('UL')[0];
|
|
|
|
let titleElement = menuContentElement.children[0];
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ok(titleElement.innerHTML === 'Chapters', 'title element placed in ul');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Player track methods call the tech', function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
let player;
|
|
|
|
let calls = 0;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
player = TestHelpers.makePlayer();
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-09-15 02:45:14 +02:00
|
|
|
player.tech_.textTracks = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
calls++;
|
|
|
|
};
|
2015-09-15 02:45:14 +02:00
|
|
|
player.tech_.addTextTrack = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
calls++;
|
|
|
|
};
|
|
|
|
|
|
|
|
player.addTextTrack();
|
|
|
|
player.textTracks();
|
|
|
|
|
|
|
|
equal(calls, 2, 'both textTrack and addTextTrack defer to the tech');
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('TextTrackDisplay initializes tracks on player ready', function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
let calls = 0;
|
|
|
|
let ttd = new TextTrackDisplay({
|
|
|
|
on() {},
|
|
|
|
addTextTracks() {
|
|
|
|
calls--;
|
|
|
|
},
|
|
|
|
getChild() {
|
|
|
|
calls--;
|
|
|
|
},
|
|
|
|
ready() {
|
|
|
|
calls++;
|
|
|
|
}
|
|
|
|
}, {});
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
equal(calls, 1, 'only a player.ready call was made');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('listen to remove and add track events in native text tracks', function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
let oldTestVid = Html5.TEST_VID;
|
|
|
|
let player;
|
|
|
|
let options;
|
|
|
|
let oldTextTracks = Html5.prototype.textTracks;
|
|
|
|
let events = {};
|
|
|
|
let html;
|
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
Html5.prototype.textTracks = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
return {
|
2016-03-07 21:54:32 +02:00
|
|
|
addEventListener(type, handler) {
|
2015-02-14 01:18:07 +02:00
|
|
|
events[type] = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
Html5.TEST_VID = {
|
2015-02-14 01:18:07 +02:00
|
|
|
textTracks: []
|
|
|
|
};
|
|
|
|
|
|
|
|
player = {
|
|
|
|
// Function.prototype is a built-in no-op function.
|
2016-03-07 21:54:32 +02:00
|
|
|
controls() {},
|
|
|
|
ready() {},
|
|
|
|
options() {
|
2015-02-14 01:18:07 +02:00
|
|
|
return {};
|
|
|
|
},
|
2016-03-07 21:54:32 +02:00
|
|
|
addChild() {},
|
|
|
|
id() {},
|
|
|
|
el() {
|
2015-02-14 01:18:07 +02:00
|
|
|
return {
|
2016-03-07 21:54:32 +02:00
|
|
|
insertBefore() {},
|
|
|
|
appendChild() {}
|
2015-02-14 01:18:07 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
player.player_ = player;
|
|
|
|
player.options_ = options = {};
|
|
|
|
|
2015-05-06 20:01:52 +02:00
|
|
|
html = new Html5(options);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
ok(events.removetrack, 'removetrack listener was added');
|
|
|
|
ok(events.addtrack, 'addtrack listener was added');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
Html5.TEST_VID = oldTestVid;
|
2015-03-26 06:43:41 +02:00
|
|
|
Html5.prototype.textTracks = oldTextTracks;
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('update texttrack buttons on removetrack or addtrack', function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
let update = 0;
|
|
|
|
let i;
|
|
|
|
let player;
|
|
|
|
let tag;
|
|
|
|
let track;
|
|
|
|
let oldTextTracks;
|
|
|
|
let events = {};
|
|
|
|
let oldCaptionsUpdate;
|
|
|
|
let oldSubsUpdate;
|
|
|
|
let oldChaptersUpdate;
|
2016-03-25 20:16:56 +02:00
|
|
|
let oldDescriptionsUpdate;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
oldCaptionsUpdate = CaptionsButton.prototype.update;
|
|
|
|
oldSubsUpdate = SubtitlesButton.prototype.update;
|
2016-03-25 20:16:56 +02:00
|
|
|
oldDescriptionsUpdate = DescriptionsButton.prototype.update;
|
2015-03-26 06:43:41 +02:00
|
|
|
oldChaptersUpdate = ChaptersButton.prototype.update;
|
|
|
|
CaptionsButton.prototype.update = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
update++;
|
|
|
|
oldCaptionsUpdate.call(this);
|
|
|
|
};
|
2015-03-26 06:43:41 +02:00
|
|
|
SubtitlesButton.prototype.update = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
update++;
|
|
|
|
oldSubsUpdate.call(this);
|
|
|
|
};
|
2016-03-25 20:16:56 +02:00
|
|
|
DescriptionsButton.prototype.update = function() {
|
|
|
|
update++;
|
|
|
|
oldDescriptionsUpdate.call(this);
|
|
|
|
};
|
2015-03-26 06:43:41 +02:00
|
|
|
ChaptersButton.prototype.update = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
update++;
|
|
|
|
oldChaptersUpdate.call(this);
|
|
|
|
};
|
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
Tech.prototype.featuresNativeTextTracks = true;
|
2015-04-14 22:08:32 +02:00
|
|
|
oldTextTracks = Tech.prototype.textTracks;
|
|
|
|
Tech.prototype.textTracks = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
return {
|
|
|
|
length: 0,
|
2016-03-07 21:54:32 +02:00
|
|
|
addEventListener(type, handler) {
|
2015-02-14 01:18:07 +02:00
|
|
|
if (!events[type]) {
|
|
|
|
events[type] = [];
|
|
|
|
}
|
|
|
|
events[type].push(handler);
|
2015-08-25 02:46:54 +02:00
|
|
|
},
|
|
|
|
// Requrired in player.dispose()
|
2016-03-07 21:54:32 +02:00
|
|
|
removeEventListener() {}
|
2015-02-14 01:18:07 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
tag = document.createElement('video');
|
|
|
|
track = document.createElement('track');
|
|
|
|
track.kind = 'captions';
|
|
|
|
track.label = 'en';
|
|
|
|
track.language = 'English';
|
2015-08-25 02:46:54 +02:00
|
|
|
track.src = '#en.vtt';
|
2015-02-14 01:18:07 +02:00
|
|
|
tag.appendChild(track);
|
|
|
|
track = document.createElement('track');
|
|
|
|
track.kind = 'captions';
|
|
|
|
track.label = 'es';
|
|
|
|
track.language = 'Spanish';
|
2015-08-25 02:46:54 +02:00
|
|
|
track.src = '#es.vtt';
|
2015-02-14 01:18:07 +02:00
|
|
|
tag.appendChild(track);
|
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
player = TestHelpers.makePlayer({}, tag);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
player.player_ = player;
|
|
|
|
|
2016-03-25 20:16:56 +02:00
|
|
|
equal(update, 4, 'update was called on the four buttons during init');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
for (i = 0; i < events.removetrack.length; i++) {
|
|
|
|
events.removetrack[i]();
|
2015-02-14 01:18:07 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 20:16:56 +02:00
|
|
|
equal(update, 8, 'update was called on the four buttons for remove track');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
for (i = 0; i < events.addtrack.length; i++) {
|
|
|
|
events.addtrack[i]();
|
2015-02-14 01:18:07 +02:00
|
|
|
}
|
|
|
|
|
2016-03-25 20:16:56 +02:00
|
|
|
equal(update, 12, 'update was called on the four buttons for remove track');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-04-14 22:08:32 +02:00
|
|
|
Tech.prototype.textTracks = oldTextTracks;
|
2016-03-07 21:54:32 +02:00
|
|
|
Tech.prototype.featuresNativeTextTracks = false;
|
2015-03-26 06:43:41 +02:00
|
|
|
CaptionsButton.prototype.update = oldCaptionsUpdate;
|
|
|
|
SubtitlesButton.prototype.update = oldSubsUpdate;
|
|
|
|
ChaptersButton.prototype.update = oldChaptersUpdate;
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('if native text tracks are not supported, create a texttrackdisplay', function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
let oldTestVid = Html5.TEST_VID;
|
|
|
|
let oldIsFirefox = browser.IS_FIREFOX;
|
|
|
|
let oldTextTrackDisplay = Component.getComponent('TextTrackDisplay');
|
|
|
|
let called = false;
|
|
|
|
let player;
|
|
|
|
let tag;
|
|
|
|
let track;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
tag = document.createElement('video');
|
|
|
|
track = document.createElement('track');
|
|
|
|
track.kind = 'captions';
|
|
|
|
track.label = 'en';
|
|
|
|
track.language = 'English';
|
|
|
|
track.src = 'en.vtt';
|
|
|
|
tag.appendChild(track);
|
|
|
|
track = document.createElement('track');
|
|
|
|
track.kind = 'captions';
|
|
|
|
track.label = 'es';
|
|
|
|
track.language = 'Spanish';
|
|
|
|
track.src = 'es.vtt';
|
|
|
|
tag.appendChild(track);
|
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
Html5.TEST_VID = {
|
2015-02-14 01:18:07 +02:00
|
|
|
textTracks: []
|
|
|
|
};
|
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
browser.IS_FIREFOX = true;
|
2015-03-26 06:43:41 +02:00
|
|
|
Component.registerComponent('TextTrackDisplay', function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
called = true;
|
2015-03-26 06:43:41 +02:00
|
|
|
});
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
player = TestHelpers.makePlayer({}, tag);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ok(called, 'text track display was created');
|
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
Html5.TEST_VID = oldTestVid;
|
|
|
|
browser.IS_FIREFOX = oldIsFirefox;
|
2015-03-26 06:43:41 +02:00
|
|
|
Component.registerComponent('TextTrackDisplay', oldTextTrackDisplay);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-08-25 02:46:54 +02:00
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('html5 tech supports native text tracks if the video supports it, unless mode is a number', function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
let oldTestVid = Html5.TEST_VID;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
Html5.TEST_VID = {
|
2015-02-14 01:18:07 +02:00
|
|
|
textTracks: [{
|
|
|
|
mode: 0
|
|
|
|
}]
|
|
|
|
};
|
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
ok(!Html5.supportsNativeTextTracks(), 'native text tracks are not supported if mode is a number');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
Html5.TEST_VID = oldTestVid;
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('html5 tech supports native text tracks if the video supports it, unless it is firefox', function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
let oldTestVid = Html5.TEST_VID;
|
|
|
|
let oldIsFirefox = browser.IS_FIREFOX;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
Html5.TEST_VID = {
|
2015-02-14 01:18:07 +02:00
|
|
|
textTracks: []
|
|
|
|
};
|
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
browser.IS_FIREFOX = true;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
ok(!Html5.supportsNativeTextTracks(), 'if textTracks are available on video element, native text tracks are supported');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
Html5.TEST_VID = oldTestVid;
|
|
|
|
browser.IS_FIREFOX = oldIsFirefox;
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
2015-02-18 00:19:21 +02:00
|
|
|
|
|
|
|
test('when switching techs, we should not get a new text track', function() {
|
2015-08-24 21:48:42 +02:00
|
|
|
let player = TestHelpers.makePlayer();
|
2015-02-18 00:19:21 +02:00
|
|
|
|
2015-09-15 02:45:14 +02:00
|
|
|
player.loadTech_('TechFaker');
|
2015-08-24 21:48:42 +02:00
|
|
|
let firstTracks = player.textTracks();
|
2015-02-18 00:19:21 +02:00
|
|
|
|
2015-09-15 02:45:14 +02:00
|
|
|
player.loadTech_('TechFaker');
|
2015-08-24 21:48:42 +02:00
|
|
|
let secondTracks = player.textTracks();
|
2015-02-18 00:19:21 +02:00
|
|
|
|
2015-08-24 21:48:42 +02:00
|
|
|
ok(firstTracks === secondTracks, 'the tracks are equal');
|
2015-02-18 00:19:21 +02:00
|
|
|
});
|
2015-08-03 21:19:36 +02:00
|
|
|
|
|
|
|
if (Html5.supportsNativeTextTracks()) {
|
2015-08-13 01:04:31 +02:00
|
|
|
test('listen to native remove and add track events in native text tracks', function(assert) {
|
2015-08-03 21:19:36 +02:00
|
|
|
let done = assert.async();
|
|
|
|
|
|
|
|
let el = document.createElement('video');
|
|
|
|
let html = new Html5({el});
|
|
|
|
let tt = el.textTracks;
|
|
|
|
let emulatedTt = html.textTracks();
|
|
|
|
let track = document.createElement('track');
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
el.appendChild(track);
|
|
|
|
|
|
|
|
let addtrack = function() {
|
|
|
|
equal(emulatedTt.length, tt.length, 'we have matching tracks length');
|
|
|
|
equal(emulatedTt.length, 1, 'we have one text track');
|
|
|
|
|
|
|
|
emulatedTt.off('addtrack', addtrack);
|
|
|
|
el.removeChild(track);
|
|
|
|
};
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
emulatedTt.on('addtrack', addtrack);
|
|
|
|
emulatedTt.on('removetrack', function() {
|
|
|
|
equal(emulatedTt.length, tt.length, 'we have matching tracks length');
|
|
|
|
equal(emulatedTt.length, 0, 'we have no more text tracks');
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should have removed tracks on dispose', function(assert) {
|
|
|
|
let done = assert.async();
|
|
|
|
|
|
|
|
let el = document.createElement('video');
|
|
|
|
let html = new Html5({el});
|
|
|
|
let tt = el.textTracks;
|
|
|
|
let emulatedTt = html.textTracks();
|
|
|
|
let track = document.createElement('track');
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
el.appendChild(track);
|
|
|
|
|
|
|
|
let addtrack = function() {
|
|
|
|
equal(emulatedTt.length, tt.length, 'we have matching tracks length');
|
|
|
|
equal(emulatedTt.length, 1, 'we have one text track');
|
|
|
|
|
|
|
|
emulatedTt.off('addtrack', addtrack);
|
|
|
|
html.dispose();
|
|
|
|
|
|
|
|
equal(emulatedTt.length, tt.length, 'we have matching tracks length');
|
|
|
|
equal(emulatedTt.length, 0, 'we have no more text tracks');
|
|
|
|
|
|
|
|
done();
|
|
|
|
};
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
emulatedTt.on('addtrack', addtrack);
|
|
|
|
});
|
|
|
|
}
|
2015-11-25 23:00:49 +02:00
|
|
|
|
|
|
|
test('should check for text track changes when emulating text tracks', function() {
|
|
|
|
let tech = new Tech();
|
|
|
|
let numTextTrackChanges = 0;
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-11-25 23:00:49 +02:00
|
|
|
tech.on('texttrackchange', function() {
|
|
|
|
numTextTrackChanges++;
|
|
|
|
});
|
|
|
|
tech.emulateTextTracks();
|
|
|
|
equal(numTextTrackChanges, 1, 'we got a texttrackchange event');
|
|
|
|
});
|
2015-11-24 09:39:58 +02:00
|
|
|
|
|
|
|
test('removes cuechange event when text track is hidden for emulated tracks', function() {
|
|
|
|
let player = TestHelpers.makePlayer();
|
|
|
|
let tt = new TextTrack({
|
|
|
|
tech: player.tech_,
|
|
|
|
mode: 'showing'
|
|
|
|
});
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-11-24 09:39:58 +02:00
|
|
|
tt.addCue({
|
|
|
|
id: '1',
|
|
|
|
startTime: 2,
|
|
|
|
endTime: 5
|
|
|
|
});
|
|
|
|
player.tech_.textTracks().addTrack_(tt);
|
|
|
|
player.tech_.emulateTextTracks();
|
|
|
|
|
|
|
|
let numTextTrackChanges = 0;
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-11-24 09:39:58 +02:00
|
|
|
player.tech_.on('texttrackchange', function() {
|
|
|
|
numTextTrackChanges++;
|
|
|
|
});
|
|
|
|
|
|
|
|
tt.mode = 'showing';
|
|
|
|
equal(numTextTrackChanges, 1,
|
|
|
|
'texttrackchange should be called once for mode change');
|
|
|
|
tt.mode = 'showing';
|
|
|
|
equal(numTextTrackChanges, 2,
|
|
|
|
'texttrackchange should be called once for mode change');
|
|
|
|
|
|
|
|
player.tech_.currentTime = function() {
|
|
|
|
return 3;
|
|
|
|
};
|
|
|
|
player.tech_.trigger('timeupdate');
|
|
|
|
equal(numTextTrackChanges, 3,
|
|
|
|
'texttrackchange should be triggered once for the cuechange');
|
|
|
|
|
|
|
|
tt.mode = 'hidden';
|
|
|
|
equal(numTextTrackChanges, 4,
|
|
|
|
'texttrackchange should be called once for the mode change');
|
|
|
|
|
|
|
|
player.tech_.currentTime = function() {
|
|
|
|
return 7;
|
|
|
|
};
|
|
|
|
player.tech_.trigger('timeupdate');
|
|
|
|
equal(numTextTrackChanges, 4,
|
|
|
|
'texttrackchange should be not be called since mode is hidden');
|
|
|
|
});
|
2015-12-08 18:24:51 +02:00
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
test('should return correct remote text track values', function() {
|
2015-12-08 18:24:51 +02:00
|
|
|
let fixture = document.getElementById('qunit-fixture');
|
2016-03-07 21:54:32 +02:00
|
|
|
let html = `
|
|
|
|
<video id="example_1" class="video-js" autoplay preload="none">
|
|
|
|
<source src="http://google.com" type="video/mp4">
|
|
|
|
<source src="http://google.com" type="video/webm">
|
|
|
|
<track kind="captions" label="label">
|
|
|
|
</video>
|
|
|
|
`;
|
2015-12-08 18:24:51 +02:00
|
|
|
|
|
|
|
fixture.innerHTML += html;
|
|
|
|
let tag = document.getElementById('example_1');
|
|
|
|
let player = TestHelpers.makePlayer({}, tag);
|
|
|
|
|
|
|
|
this.clock.tick(1);
|
|
|
|
|
|
|
|
equal(player.remoteTextTracks().length, 1, 'add text track via html');
|
|
|
|
equal(player.remoteTextTrackEls().length, 1, 'add html track element via html');
|
|
|
|
|
|
|
|
let htmlTrackElement = player.addRemoteTextTrack({
|
|
|
|
kind: 'captions',
|
|
|
|
label: 'label'
|
|
|
|
});
|
|
|
|
|
|
|
|
equal(player.remoteTextTracks().length, 2, 'add text track via method');
|
|
|
|
equal(player.remoteTextTrackEls().length, 2, 'add html track element via method');
|
|
|
|
|
|
|
|
player.removeRemoteTextTrack(htmlTrackElement.track);
|
|
|
|
|
|
|
|
equal(player.remoteTextTracks().length, 1, 'remove text track via method');
|
|
|
|
equal(player.remoteTextTrackEls().length, 1, 'remove html track element via method');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
test('should uniformly create html track element when adding text track', function() {
|
2015-12-08 18:24:51 +02:00
|
|
|
let player = TestHelpers.makePlayer();
|
|
|
|
let track = {
|
|
|
|
kind: 'kind',
|
|
|
|
src: 'src',
|
|
|
|
language: 'language',
|
|
|
|
label: 'label',
|
|
|
|
default: 'default'
|
|
|
|
};
|
|
|
|
|
|
|
|
equal(player.remoteTextTrackEls().length, 0, 'no html text tracks');
|
|
|
|
|
|
|
|
let htmlTrackElement = player.addRemoteTextTrack(track);
|
|
|
|
|
|
|
|
equal(htmlTrackElement.kind, htmlTrackElement.track.kind, 'verify html track element kind');
|
|
|
|
equal(htmlTrackElement.src, htmlTrackElement.track.src, 'verify html track element src');
|
|
|
|
equal(htmlTrackElement.srclang, htmlTrackElement.track.language, 'verify html track element language');
|
|
|
|
equal(htmlTrackElement.label, htmlTrackElement.track.label, 'verify html track element label');
|
|
|
|
equal(htmlTrackElement.default, htmlTrackElement.track.default, 'verify html track element default');
|
|
|
|
|
|
|
|
equal(player.remoteTextTrackEls().length, 1, 'html track element exist');
|
|
|
|
equal(player.remoteTextTrackEls().getTrackElementByTrack_(htmlTrackElement.track), htmlTrackElement, 'verify same html track element');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
2016-04-19 21:18:21 +02:00
|
|
|
|
|
|
|
test('default text tracks should show by default', function() {
|
|
|
|
let tag = TestHelpers.makeTag();
|
|
|
|
let capt = document.createElement('track');
|
|
|
|
|
2016-04-19 23:09:53 +02:00
|
|
|
capt.setAttribute('kind', 'captions');
|
2016-04-19 21:18:21 +02:00
|
|
|
capt.setAttribute('default', 'default');
|
|
|
|
|
|
|
|
tag.appendChild(capt);
|
|
|
|
|
|
|
|
let player = TestHelpers.makePlayer({
|
|
|
|
html5: {
|
|
|
|
nativeTextTracks: false
|
|
|
|
}
|
|
|
|
}, tag);
|
|
|
|
|
|
|
|
// native tracks are initialized after the player is ready
|
|
|
|
this.clock.tick(1);
|
|
|
|
|
|
|
|
let tracks = player.textTracks();
|
|
|
|
|
|
|
|
equal(tracks[0].kind, 'captions', 'the captions track is present');
|
|
|
|
equal(tracks[0].mode, 'showing', 'the captions track is showing');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('default captions take precedence over default descriptions', function() {
|
|
|
|
let tag = TestHelpers.makeTag();
|
|
|
|
let desc = document.createElement('track');
|
|
|
|
let capt = document.createElement('track');
|
|
|
|
|
2016-04-19 23:09:53 +02:00
|
|
|
desc.setAttribute('kind', 'descriptions');
|
2016-04-19 21:18:21 +02:00
|
|
|
desc.setAttribute('default', 'default');
|
2016-04-19 23:09:53 +02:00
|
|
|
capt.setAttribute('kind', 'captions');
|
2016-04-19 21:18:21 +02:00
|
|
|
capt.setAttribute('default', 'default');
|
|
|
|
|
|
|
|
tag.appendChild(desc);
|
|
|
|
tag.appendChild(capt);
|
|
|
|
|
|
|
|
let player = TestHelpers.makePlayer({
|
|
|
|
html5: {
|
|
|
|
nativeTextTracks: false
|
|
|
|
}
|
|
|
|
}, tag);
|
|
|
|
|
|
|
|
// native tracks are initialized after the player is ready
|
|
|
|
this.clock.tick(1);
|
|
|
|
|
|
|
|
let tracks = player.textTracks();
|
|
|
|
|
|
|
|
equal(tracks[0].kind, 'descriptions', 'the descriptions track is first');
|
|
|
|
equal(tracks[0].mode, 'disabled', 'the descriptions track is disabled');
|
|
|
|
equal(tracks[1].kind, 'captions', 'the captions track is second');
|
|
|
|
equal(tracks[1].mode, 'showing', 'the captions track is showing');
|
|
|
|
});
|
2016-04-19 21:46:33 +02:00
|
|
|
|
|
|
|
test('removeRemoteTextTrack should be able to take both a track and the response from addRemoteTextTrack', function() {
|
|
|
|
let player = TestHelpers.makePlayer();
|
|
|
|
let track = {
|
|
|
|
kind: 'kind',
|
|
|
|
src: 'src',
|
|
|
|
language: 'language',
|
|
|
|
label: 'label',
|
|
|
|
default: 'default'
|
|
|
|
};
|
|
|
|
let htmlTrackElement = player.addRemoteTextTrack(track);
|
|
|
|
|
|
|
|
equal(player.remoteTextTrackEls().length, 1, 'html track element exist');
|
|
|
|
|
|
|
|
player.removeRemoteTextTrack(htmlTrackElement);
|
|
|
|
|
|
|
|
equal(player.remoteTextTrackEls().length, 0, 'the track element was removed correctly');
|
|
|
|
|
|
|
|
htmlTrackElement = player.addRemoteTextTrack(track);
|
|
|
|
equal(player.remoteTextTrackEls().length, 1, 'html track element exist');
|
|
|
|
|
|
|
|
player.removeRemoteTextTrack(htmlTrackElement.track);
|
|
|
|
equal(player.remoteTextTrackEls().length, 0, 'the track element was removed correctly');
|
|
|
|
});
|