2016-08-03 21:27:47 +02:00
|
|
|
/* eslint-env qunit */
|
2015-03-26 06:43:41 +02:00
|
|
|
import TextTrackSettings from '../../../src/js/tracks/text-track-settings.js';
|
|
|
|
import TestHelpers from '../test-helpers.js';
|
2015-05-04 01:12:38 +02:00
|
|
|
import * as Events from '../../../src/js/utils/events.js';
|
2015-04-28 02:05:39 +02:00
|
|
|
import safeParseTuple from 'safe-json-parse/tuple';
|
2015-03-26 06:43:41 +02:00
|
|
|
import window from 'global/window';
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-03-07 21:54:32 +02:00
|
|
|
const tracks = [{
|
2015-02-14 01:18:07 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'test'
|
|
|
|
}];
|
|
|
|
|
2016-07-19 06:19:36 +02:00
|
|
|
const defaultSettings = {
|
2016-08-03 21:27:47 +02:00
|
|
|
backgroundColor: '#000',
|
|
|
|
backgroundOpacity: '1',
|
|
|
|
color: '#FFF',
|
|
|
|
fontFamily: 'proportionalSansSerif',
|
|
|
|
textOpacity: '1',
|
|
|
|
windowColor: '#000',
|
|
|
|
windowOpacity: '0'
|
2016-07-19 06:19:36 +02:00
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.module('Text Track Settings', {
|
2016-03-07 21:54:32 +02:00
|
|
|
beforeEach() {
|
2015-03-26 06:43:41 +02:00
|
|
|
window.localStorage.clear();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('should update settings', function() {
|
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks,
|
|
|
|
persistTextTrackSettings: true
|
|
|
|
});
|
2016-07-19 06:19:36 +02:00
|
|
|
const newSettings = {
|
|
|
|
backgroundOpacity: '0.5',
|
|
|
|
textOpacity: '0.5',
|
|
|
|
windowOpacity: '0.5',
|
2016-03-07 21:54:32 +02:00
|
|
|
edgeStyle: 'raised',
|
|
|
|
fontFamily: 'monospaceSerif',
|
2016-07-19 06:19:36 +02:00
|
|
|
color: '#F00',
|
2016-03-07 21:54:32 +02:00
|
|
|
backgroundColor: '#FFF',
|
|
|
|
windowColor: '#FFF',
|
|
|
|
fontPercent: 1.25
|
|
|
|
};
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
player.textTrackSettings.setValues(newSettings);
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.deepEqual(player.textTrackSettings.getValues(),
|
|
|
|
newSettings,
|
|
|
|
'values are updated');
|
|
|
|
|
|
|
|
QUnit.equal(player.$('.vjs-fg-color > select').selectedIndex,
|
|
|
|
2,
|
|
|
|
'fg-color is set to new value');
|
|
|
|
QUnit.equal(player.$('.vjs-bg-color > select').selectedIndex,
|
|
|
|
1,
|
|
|
|
'bg-color is set to new value');
|
|
|
|
QUnit.equal(player.$('.window-color > select').selectedIndex,
|
|
|
|
1,
|
|
|
|
'window-color is set to new value');
|
|
|
|
QUnit.equal(player.$('.vjs-text-opacity > select').selectedIndex,
|
|
|
|
1,
|
|
|
|
'text-opacity is set to new value');
|
|
|
|
QUnit.equal(player.$('.vjs-bg-opacity > select').selectedIndex,
|
|
|
|
1,
|
|
|
|
'bg-opacity is set to new value');
|
|
|
|
QUnit.equal(player.$('.vjs-window-opacity > select').selectedIndex,
|
|
|
|
1,
|
|
|
|
'window-opacity is set to new value');
|
|
|
|
QUnit.equal(player.$('.vjs-edge-style select').selectedIndex,
|
|
|
|
1,
|
|
|
|
'edge-style is set to new value');
|
|
|
|
QUnit.equal(player.$('.vjs-font-family select').selectedIndex,
|
|
|
|
3,
|
|
|
|
'font-family is set to new value');
|
|
|
|
QUnit.equal(player.$('.vjs-font-percent select').selectedIndex,
|
|
|
|
3,
|
|
|
|
'font-percent is set to new value');
|
2015-11-10 00:43:17 +02:00
|
|
|
|
|
|
|
Events.trigger(player.$('.vjs-done-button'), 'click');
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.deepEqual(safeParseTuple(
|
|
|
|
window.localStorage.getItem('vjs-text-track-settings'))[1],
|
|
|
|
newSettings,
|
|
|
|
'values are saved');
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('should restore default settings', function() {
|
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks,
|
2015-02-14 01:18:07 +02:00
|
|
|
persistTextTrackSettings: true
|
|
|
|
});
|
|
|
|
|
2015-11-10 00:43:17 +02:00
|
|
|
player.$('.vjs-fg-color > select').selectedIndex = 1;
|
|
|
|
player.$('.vjs-bg-color > select').selectedIndex = 1;
|
|
|
|
player.$('.window-color > select').selectedIndex = 1;
|
|
|
|
player.$('.vjs-text-opacity > select').selectedIndex = 1;
|
|
|
|
player.$('.vjs-bg-opacity > select').selectedIndex = 1;
|
|
|
|
player.$('.vjs-window-opacity > select').selectedIndex = 1;
|
|
|
|
player.$('.vjs-edge-style select').selectedIndex = 1;
|
|
|
|
player.$('.vjs-font-family select').selectedIndex = 1;
|
|
|
|
player.$('.vjs-font-percent select').selectedIndex = 3;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-11-10 00:43:17 +02:00
|
|
|
Events.trigger(player.$('.vjs-done-button'), 'click');
|
|
|
|
Events.trigger(player.$('.vjs-default-button'), 'click');
|
|
|
|
Events.trigger(player.$('.vjs-done-button'), 'click');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.deepEqual(player.textTrackSettings.getValues(),
|
|
|
|
defaultSettings,
|
|
|
|
'values are defaulted');
|
|
|
|
// TODO:
|
|
|
|
// MikeA: need to figure out how to modify saveSettings
|
|
|
|
// to factor in defaults are no longer null
|
|
|
|
// QUnit.deepEqual(window.localStorage.getItem('vjs-text-track-settings'),
|
|
|
|
// defaultSettings,
|
|
|
|
// 'values are saved');
|
|
|
|
|
|
|
|
QUnit.equal(player.$('.vjs-fg-color > select').selectedIndex,
|
|
|
|
0,
|
|
|
|
'fg-color is set to default value');
|
|
|
|
QUnit.equal(player.$('.vjs-bg-color > select').selectedIndex,
|
|
|
|
0,
|
|
|
|
'bg-color is set to default value');
|
|
|
|
QUnit.equal(player.$('.window-color > select').selectedIndex,
|
|
|
|
0,
|
|
|
|
'window-color is set to default value');
|
|
|
|
QUnit.equal(player.$('.vjs-text-opacity > select').selectedIndex,
|
|
|
|
0,
|
|
|
|
'text-opacity is set to default value');
|
|
|
|
QUnit.equal(player.$('.vjs-bg-opacity > select').selectedIndex,
|
|
|
|
0,
|
|
|
|
'bg-opacity is set to default value');
|
|
|
|
QUnit.equal(player.$('.vjs-window-opacity > select').selectedIndex,
|
|
|
|
0,
|
|
|
|
'window-opacity is set to default value');
|
|
|
|
QUnit.equal(player.$('.vjs-edge-style select').selectedIndex,
|
|
|
|
0,
|
|
|
|
'edge-style is set to default value');
|
|
|
|
QUnit.equal(player.$('.vjs-font-family select').selectedIndex,
|
|
|
|
0,
|
|
|
|
'font-family is set to default value');
|
|
|
|
QUnit.equal(player.$('.vjs-font-percent select').selectedIndex,
|
|
|
|
2,
|
|
|
|
'font-percent is set to default value');
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('should open on click', function() {
|
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-11-10 00:43:17 +02:00
|
|
|
Events.trigger(player.$('.vjs-texttrack-settings'), 'click');
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.ok(!player.textTrackSettings.hasClass('vjs-hidden'), 'settings open');
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('should close on done click', function() {
|
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-11-10 00:43:17 +02:00
|
|
|
Events.trigger(player.$('.vjs-texttrack-settings'), 'click');
|
|
|
|
Events.trigger(player.$('.vjs-done-button'), 'click');
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.ok(player.textTrackSettings.hasClass('vjs-hidden'), 'settings closed');
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('if persist option is set, restore settings on init', function() {
|
|
|
|
const oldRestoreSettings = TextTrackSettings.prototype.restoreSettings;
|
2016-03-07 21:54:32 +02:00
|
|
|
let restore = 0;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
TextTrackSettings.prototype.restoreSettings = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
restore++;
|
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks,
|
2015-02-14 01:18:07 +02:00
|
|
|
persistTextTrackSettings: true
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.equal(restore, 1, 'restore was called');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
TextTrackSettings.prototype.restoreSettings = oldRestoreSettings;
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('if persist option is set, save settings when "done"', function() {
|
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks,
|
|
|
|
persistTextTrackSettings: true
|
|
|
|
});
|
2016-08-03 21:27:47 +02:00
|
|
|
const oldSaveSettings = TextTrackSettings.prototype.saveSettings;
|
2016-03-07 21:54:32 +02:00
|
|
|
let save = 0;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
TextTrackSettings.prototype.saveSettings = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
save++;
|
|
|
|
};
|
|
|
|
|
2015-11-10 00:43:17 +02:00
|
|
|
Events.trigger(player.$('.vjs-done-button'), 'click');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.equal(save, 1, 'save was called');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
TextTrackSettings.prototype.saveSettings = oldSaveSettings;
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('do not try to restore or save settings if persist option is not set', function() {
|
|
|
|
const oldRestoreSettings = TextTrackSettings.prototype.restoreSettings;
|
|
|
|
const oldSaveSettings = TextTrackSettings.prototype.saveSettings;
|
2016-03-07 21:54:32 +02:00
|
|
|
let save = 0;
|
|
|
|
let restore = 0;
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
TextTrackSettings.prototype.restoreSettings = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
restore++;
|
|
|
|
};
|
2015-03-26 06:43:41 +02:00
|
|
|
TextTrackSettings.prototype.saveSettings = function() {
|
2015-02-14 01:18:07 +02:00
|
|
|
save++;
|
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks,
|
2015-02-14 01:18:07 +02:00
|
|
|
persistTextTrackSettings: false
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.equal(restore, 0, 'restore was not called');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-11-10 00:43:17 +02:00
|
|
|
Events.trigger(player.$('.vjs-done-button'), 'click');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
// saveSettings is called but does nothing
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.equal(save, 1, 'save was not called');
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2015-03-26 06:43:41 +02:00
|
|
|
TextTrackSettings.prototype.saveSettings = oldSaveSettings;
|
|
|
|
TextTrackSettings.prototype.restoreSettings = oldRestoreSettings;
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('should restore saved settings', function() {
|
2016-07-19 06:19:36 +02:00
|
|
|
const newSettings = {
|
|
|
|
backgroundOpacity: '0.5',
|
|
|
|
textOpacity: '0.5',
|
|
|
|
windowOpacity: '0.5',
|
2016-03-07 21:54:32 +02:00
|
|
|
edgeStyle: 'raised',
|
|
|
|
fontFamily: 'monospaceSerif',
|
2016-07-19 06:19:36 +02:00
|
|
|
color: '#F00',
|
2016-03-07 21:54:32 +02:00
|
|
|
backgroundColor: '#FFF',
|
|
|
|
windowColor: '#FFF',
|
|
|
|
fontPercent: 1.25
|
|
|
|
};
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
window.localStorage.setItem('vjs-text-track-settings', JSON.stringify(newSettings));
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks,
|
2015-02-14 01:18:07 +02:00
|
|
|
persistTextTrackSettings: true
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.deepEqual(player.textTrackSettings.getValues(), newSettings);
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.test('should not restore saved settings', function() {
|
2016-07-19 06:19:36 +02:00
|
|
|
const newSettings = {
|
|
|
|
backgroundOpacity: '0.5',
|
|
|
|
textOpacity: '0.5',
|
|
|
|
windowOpacity: '0.5',
|
2016-03-07 21:54:32 +02:00
|
|
|
edgeStyle: 'raised',
|
|
|
|
fontFamily: 'monospaceSerif',
|
2016-07-19 06:19:36 +02:00
|
|
|
color: '#F00',
|
2016-03-07 21:54:32 +02:00
|
|
|
backgroundColor: '#FFF',
|
|
|
|
windowColor: '#FFF',
|
|
|
|
fontPercent: 1.25
|
|
|
|
};
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
window.localStorage.setItem('vjs-text-track-settings', JSON.stringify(newSettings));
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
const player = TestHelpers.makePlayer({
|
2016-03-07 21:54:32 +02:00
|
|
|
tracks,
|
2015-02-14 01:18:07 +02:00
|
|
|
persistTextTrackSettings: false
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.deepEqual(player.textTrackSettings.getValues(), defaultSettings);
|
2015-08-25 02:46:54 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|