2015-04-14 22:08:32 +02:00
|
|
|
import ChaptersButton from '../../../src/js/control-bar/text-track-controls/chapters-button.js';
|
|
|
|
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';
|
|
|
|
|
|
|
|
import TextTrackDisplay from '../../../src/js/tracks/text-track-display.js';
|
|
|
|
import Html5 from '../../../src/js/tech/html5.js';
|
|
|
|
import Flash from '../../../src/js/tech/flash.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';
|
|
|
|
|
|
|
|
q.module('Tracks');
|
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() {
|
|
|
|
var player, chaptersButton;
|
|
|
|
|
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
|
|
|
|
|
|
|
var menuContentElement = chaptersButton.el().getElementsByTagName('UL')[0];
|
|
|
|
var titleElement = menuContentElement.children[0];
|
|
|
|
|
|
|
|
ok(titleElement.innerHTML === 'Chapters', 'title element placed in ul');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('Player track methods call the tech', function() {
|
|
|
|
var player,
|
|
|
|
calls = 0;
|
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
player = TestHelpers.makePlayer();
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
player.tech.textTracks = function() {
|
|
|
|
calls++;
|
|
|
|
};
|
|
|
|
player.tech.addTextTrack = function() {
|
|
|
|
calls++;
|
|
|
|
};
|
|
|
|
|
|
|
|
player.addTextTrack();
|
|
|
|
player.textTracks();
|
|
|
|
|
|
|
|
equal(calls, 2, 'both textTrack and addTextTrack defer to the tech');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('TextTrackDisplay initializes tracks on player ready', function() {
|
|
|
|
var calls = 0,
|
2015-03-26 06:43:41 +02:00
|
|
|
ttd = new TextTrackDisplay({
|
2015-02-14 01:18:07 +02:00
|
|
|
on: Function.prototype,
|
|
|
|
addTextTracks: function() {
|
|
|
|
calls--;
|
|
|
|
},
|
|
|
|
getChild: function() {
|
|
|
|
calls--;
|
|
|
|
},
|
|
|
|
ready: function() {
|
|
|
|
calls++;
|
|
|
|
}
|
|
|
|
}, {});
|
|
|
|
|
|
|
|
equal(calls, 1, 'only a player.ready call was made');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('listen to remove and add track events in native text tracks', function() {
|
2015-05-04 01:12:38 +02:00
|
|
|
var oldTestVid = Html5.TEST_VID,
|
2015-02-14 01:18:07 +02:00
|
|
|
player,
|
|
|
|
options,
|
|
|
|
oldTextTracks,
|
|
|
|
events = {},
|
|
|
|
html;
|
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
oldTextTracks = Html5.prototype.textTracks;
|
|
|
|
Html5.prototype.textTracks = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
return {
|
|
|
|
addEventListener: function(type, handler) {
|
|
|
|
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.
|
|
|
|
controls: Function.prototype,
|
|
|
|
ready: Function.prototype,
|
|
|
|
options: function() {
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
addChild: Function.prototype,
|
|
|
|
id: Function.prototype,
|
|
|
|
el: function() {
|
|
|
|
return {
|
|
|
|
insertBefore: Function.prototype,
|
|
|
|
appendChild: Function.prototype
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
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
|
|
|
|
|
|
|
ok(events['removetrack'], 'removetrack listener was added');
|
|
|
|
ok(events['addtrack'], 'addtrack listener was added');
|
|
|
|
|
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() {
|
|
|
|
var update = 0,
|
|
|
|
i,
|
|
|
|
player,
|
|
|
|
tag,
|
|
|
|
track,
|
|
|
|
oldTextTracks,
|
|
|
|
events = {},
|
|
|
|
oldCaptionsUpdate,
|
|
|
|
oldSubsUpdate,
|
|
|
|
oldChaptersUpdate;
|
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
oldCaptionsUpdate = CaptionsButton.prototype.update;
|
|
|
|
oldSubsUpdate = SubtitlesButton.prototype.update;
|
|
|
|
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);
|
|
|
|
};
|
2015-03-26 06:43:41 +02:00
|
|
|
ChaptersButton.prototype.update = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
update++;
|
|
|
|
oldChaptersUpdate.call(this);
|
|
|
|
};
|
|
|
|
|
2015-04-14 22:08:32 +02:00
|
|
|
Tech.prototype['featuresNativeTextTracks'] = true;
|
|
|
|
oldTextTracks = Tech.prototype.textTracks;
|
|
|
|
Tech.prototype.textTracks = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
return {
|
|
|
|
length: 0,
|
|
|
|
addEventListener: function(type, handler) {
|
|
|
|
if (!events[type]) {
|
|
|
|
events[type] = [];
|
|
|
|
}
|
|
|
|
events[type].push(handler);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
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-03-26 06:43:41 +02:00
|
|
|
player = TestHelpers.makePlayer({}, tag);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
player.player_ = player;
|
|
|
|
|
|
|
|
equal(update, 3, 'update was called on the three buttons during init');
|
|
|
|
|
|
|
|
for (i = 0; i < events['removetrack'].length; i++) {
|
|
|
|
events['removetrack'][i]();
|
|
|
|
}
|
|
|
|
|
|
|
|
equal(update, 6, 'update was called on the three buttons for remove track');
|
|
|
|
|
|
|
|
for (i = 0; i < events['addtrack'].length; i++) {
|
|
|
|
events['addtrack'][i]();
|
|
|
|
}
|
|
|
|
|
|
|
|
equal(update, 9, 'update was called on the three buttons for remove track');
|
|
|
|
|
2015-04-14 22:08:32 +02:00
|
|
|
Tech.prototype.textTracks = oldTextTracks;
|
|
|
|
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-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
test('if native text tracks are not supported, create a texttrackdisplay', function() {
|
2015-05-04 01:12:38 +02:00
|
|
|
var oldTestVid = Html5.TEST_VID,
|
|
|
|
oldIsFirefox = browser.IS_FIREFOX,
|
2015-03-26 06:43:41 +02:00
|
|
|
oldTextTrackDisplay = Component.getComponent('TextTrackDisplay'),
|
2015-02-14 01:18:07 +02:00
|
|
|
called = false,
|
|
|
|
player,
|
|
|
|
tag,
|
|
|
|
track,
|
|
|
|
options,
|
|
|
|
html;
|
|
|
|
|
|
|
|
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
|
|
|
});
|
|
|
|
|
|
|
|
test('Player track methods call the tech', function() {
|
|
|
|
var player,
|
|
|
|
calls = 0;
|
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
player = TestHelpers.makePlayer();
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
player.tech.textTracks = function() {
|
|
|
|
calls++;
|
|
|
|
};
|
|
|
|
player.tech.addTextTrack = function() {
|
|
|
|
calls++;
|
|
|
|
};
|
|
|
|
|
|
|
|
player.addTextTrack();
|
|
|
|
player.textTracks();
|
|
|
|
|
|
|
|
equal(calls, 2, 'both textTrack and addTextTrack defer to the tech');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('html5 tech supports native text tracks if the video supports it, unless mode is a number', function() {
|
2015-05-04 01:12:38 +02:00
|
|
|
var 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() {
|
2015-05-04 01:12:38 +02:00
|
|
|
var oldTestVid = Html5.TEST_VID,
|
|
|
|
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-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer({
|
2015-02-18 00:19:21 +02:00
|
|
|
html5: {
|
|
|
|
nativeTextTracks: false
|
|
|
|
}
|
|
|
|
}),
|
|
|
|
htmltracks,
|
|
|
|
flashtracks;
|
|
|
|
|
|
|
|
player.loadTech('Html5');
|
|
|
|
|
|
|
|
htmltracks = player.textTracks();
|
|
|
|
|
|
|
|
player.loadTech('Flash');
|
|
|
|
|
|
|
|
flashtracks = player.textTracks();
|
|
|
|
|
|
|
|
ok(htmltracks === flashtracks, 'the tracks are equal');
|
|
|
|
});
|
2015-08-03 21:19:36 +02:00
|
|
|
|
|
|
|
if (Html5.supportsNativeTextTracks()) {
|
|
|
|
test('listen to remove and add track events in native text tracks', 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');
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
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');
|
|
|
|
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();
|
|
|
|
};
|
|
|
|
emulatedTt.on('addtrack', addtrack);
|
|
|
|
|
|
|
|
});
|
|
|
|
}
|