2015-03-26 06:43:41 +02:00
|
|
|
import { TextTrackMenuItem } from '../../../src/js/tracks/text-track-controls';
|
|
|
|
import TestHelpers from '../test-helpers.js';
|
|
|
|
import * as Lib from '../../../src/js/lib.js';
|
|
|
|
|
|
|
|
q.module('Text Track Controls');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
var track = {
|
|
|
|
kind: 'captions',
|
|
|
|
label: 'test'
|
|
|
|
};
|
|
|
|
|
|
|
|
test('should be displayed when text tracks list is not empty', function() {
|
2015-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer({
|
2015-02-14 01:18:07 +02:00
|
|
|
tracks: [track]
|
|
|
|
});
|
|
|
|
|
|
|
|
ok(!player.controlBar.captionsButton.hasClass('vjs-hidden'), 'control is displayed');
|
|
|
|
equal(player.textTracks().length, 1, 'textTracks contains one item');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should be displayed when a text track is added to an empty track list', function() {
|
2015-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer();
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
player.addRemoteTextTrack(track);
|
|
|
|
|
|
|
|
ok(!player.controlBar.captionsButton.hasClass('vjs-hidden'), 'control is displayed');
|
|
|
|
equal(player.textTracks().length, 1, 'textTracks contains one item');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not be displayed when text tracks list is empty', function() {
|
2015-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer();
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ok(player.controlBar.captionsButton.hasClass('vjs-hidden'), 'control is not displayed');
|
|
|
|
equal(player.textTracks().length, 0, 'textTracks is empty');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should not be displayed when last text track is removed', function() {
|
2015-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer({
|
2015-02-14 01:18:07 +02:00
|
|
|
tracks: [track]
|
|
|
|
});
|
|
|
|
|
|
|
|
player.removeRemoteTextTrack(player.textTracks()[0]);
|
|
|
|
|
|
|
|
ok(player.controlBar.captionsButton.hasClass('vjs-hidden'), 'control is not displayed');
|
|
|
|
equal(player.textTracks().length, 0, 'textTracks is empty');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('menu should contain "Settings", "Off" and one track', function() {
|
2015-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer({
|
2015-02-14 01:18:07 +02:00
|
|
|
tracks: [track]
|
|
|
|
}),
|
|
|
|
menuItems = player.controlBar.captionsButton.items;
|
|
|
|
|
|
|
|
equal(menuItems.length, 3, 'menu contains three items');
|
|
|
|
equal(menuItems[0].track.label, 'captions settings', 'menu contains "captions settings"');
|
|
|
|
equal(menuItems[1].track.label, 'captions off', 'menu contains "captions off"');
|
|
|
|
equal(menuItems[2].track.label, 'test', 'menu contains "test" track');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('menu should update with addRemoteTextTrack', function() {
|
2015-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer({
|
2015-02-14 01:18:07 +02:00
|
|
|
tracks: [track]
|
|
|
|
});
|
|
|
|
|
|
|
|
player.addRemoteTextTrack(track);
|
|
|
|
|
|
|
|
equal(player.controlBar.captionsButton.items.length, 4, 'menu does contain added track');
|
|
|
|
equal(player.textTracks().length, 2, 'textTracks contains two items');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('menu should update with removeRemoteTextTrack', function() {
|
2015-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer({
|
2015-02-14 01:18:07 +02:00
|
|
|
tracks: [track, track]
|
|
|
|
});
|
|
|
|
|
|
|
|
player.removeRemoteTextTrack(player.textTracks()[0]);
|
|
|
|
|
|
|
|
equal(player.controlBar.captionsButton.items.length, 3, 'menu does not contain removed track');
|
|
|
|
equal(player.textTracks().length, 1, 'textTracks contains one item');
|
|
|
|
});
|
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
if (!Lib.IS_IE8) {
|
2015-02-14 01:18:07 +02:00
|
|
|
// This test doesn't work on IE8.
|
|
|
|
// However, this test tests a specific with iOS7 where the TextTrackList doesn't report track mode changes.
|
|
|
|
// TODO: figure out why this test doens't work on IE8. https://github.com/videojs/video.js/issues/1861
|
|
|
|
test('menu items should polyfill mode change events', function() {
|
2015-03-26 06:43:41 +02:00
|
|
|
var player = TestHelpers.makePlayer({}),
|
2015-02-14 01:18:07 +02:00
|
|
|
changes,
|
|
|
|
trackMenuItem;
|
|
|
|
|
|
|
|
// emulate a TextTrackList that doesn't report track mode changes,
|
|
|
|
// like iOS7
|
|
|
|
player.textTracks().onchange = undefined;
|
2015-03-26 06:43:41 +02:00
|
|
|
trackMenuItem = new TextTrackMenuItem(player, {
|
2015-02-14 01:18:07 +02:00
|
|
|
track: track
|
|
|
|
});
|
|
|
|
|
|
|
|
player.textTracks().on('change', function() {
|
|
|
|
changes++;
|
|
|
|
});
|
|
|
|
changes = 0;
|
|
|
|
trackMenuItem.trigger('tap');
|
|
|
|
equal(changes, 1, 'taps trigger change events');
|
|
|
|
|
|
|
|
trackMenuItem.trigger('click');
|
|
|
|
equal(changes, 2, 'clicks trigger change events');
|
|
|
|
});
|
|
|
|
}
|