mirror of
https://github.com/videojs/video.js.git
synced 2024-12-16 11:37:29 +02:00
a8ff970d4a
Broke out bind, guid, and element data functions from Lib Separated out more dom functions in to dom.js Broke out URL functions into url.js Removed setLocalStorage since it wasn't being used Moved browser tests out of lib Moved log functions into their own file Removed trim() since it wasn't being used Moved formatTime into its own file Moved round into its own file and renamed roundFloat() Moved capitalize into its own file and renamed as toTitleCase() Moved createTimeRange into its own file Removed Lib.arr.forEach infavor of the native forEach Removed Lib.obj.create in favor of native Object.create (ES6-sham) Removed obj.each in favor of native Object.getOwnPropertyNames().forEach() Removed obj.merge and copy. Using lodash.assign instead. Replaced Lib.obj.isPlain with lodash.isPlainObject Removed Lib.obj.isArray in favor of the native Array.isArray Also removed the lib.js tests file as all tests have been moved or removed. Removed Lib.isEmpty in favor of !Object.getOwnPropertyNames().length Switched Util.mergeOptions and deepMerge to use new mergeOptions() Moved Lib.TEST_VID to Html5.TEST_VID Removed Lib references everywhere. Woo! Attempting to fix sourcemap test errors by setting grunt-browserify version Switched to object.assign from lodash.assign Removed unused 'inherits' dependency Reorganzied test files and added '.test' to file names Combined js/core.js and js/video.js Moved events.js into the utils directory
169 lines
4.0 KiB
JavaScript
169 lines
4.0 KiB
JavaScript
import Plugin from '../../src/js/plugins.js';
|
|
import Player from '../../src/js/player.js';
|
|
import TestHelpers from './test-helpers.js';
|
|
|
|
q.module('Plugins');
|
|
|
|
test('Plugin should get initialized and receive options', function(){
|
|
expect(2);
|
|
|
|
Plugin('myPlugin1', function(options){
|
|
ok(true, 'Plugin initialized');
|
|
ok(options['test'], 'Option passed through');
|
|
});
|
|
|
|
Plugin('myPlugin2', function(options){
|
|
ok(false, 'Plugin initialized and should not have been');
|
|
});
|
|
|
|
var player = TestHelpers.makePlayer({
|
|
'plugins': {
|
|
'myPlugin1': {
|
|
'test': true
|
|
}
|
|
}
|
|
});
|
|
|
|
player.dispose();
|
|
});
|
|
|
|
test('Plugin should have the option of being initilized outside of player init', function(){
|
|
expect(3);
|
|
|
|
Plugin('myPlugin3', function(options){
|
|
ok(true, 'Plugin initialized after player init');
|
|
ok(options['test'], 'Option passed through');
|
|
});
|
|
|
|
var player = TestHelpers.makePlayer({});
|
|
|
|
ok(player['myPlugin3'], 'Plugin has direct access on player instance');
|
|
|
|
player['myPlugin3']({
|
|
'test': true
|
|
});
|
|
|
|
player.dispose();
|
|
});
|
|
|
|
test('Plugin should be able to add a UI component', function(){
|
|
expect(2);
|
|
|
|
Plugin('myPlugin4', function(options){
|
|
ok((this instanceof Player), 'Plugin executed in player scope by default');
|
|
this.addChild('component');
|
|
});
|
|
|
|
var player = TestHelpers.makePlayer({});
|
|
player['myPlugin4']({
|
|
'test': true
|
|
});
|
|
|
|
var comp = player.getChild('component');
|
|
ok(comp, 'Plugin added a component to the player');
|
|
|
|
player.dispose();
|
|
});
|
|
|
|
test('Plugin should overwrite plugin of same name', function(){
|
|
var v1Called = 0,
|
|
v2Called = 0,
|
|
v3Called = 0;
|
|
|
|
// Create initial plugin
|
|
Plugin('myPlugin5', function(options){
|
|
v1Called++;
|
|
});
|
|
var player = TestHelpers.makePlayer({});
|
|
player['myPlugin5']({});
|
|
|
|
// Overwrite and create new player
|
|
Plugin('myPlugin5', function(options){
|
|
v2Called++;
|
|
});
|
|
var player2 = TestHelpers.makePlayer({});
|
|
player2['myPlugin5']({});
|
|
|
|
// Overwrite and init new version on existing player
|
|
Plugin('myPlugin5', function(options){
|
|
v3Called++;
|
|
});
|
|
player2['myPlugin5']({});
|
|
|
|
var comp = player.getChild('component');
|
|
ok(v1Called === 1, 'First version of plugin called once');
|
|
ok(v2Called === 1, 'Plugin overwritten for new player');
|
|
ok(v3Called === 1, 'Plugin overwritten for existing player');
|
|
|
|
player.dispose();
|
|
player2.dispose();
|
|
});
|
|
|
|
|
|
test('Plugins should get events in registration order', function() {
|
|
var order = [];
|
|
var expectedOrder = [];
|
|
var pluginName = 'orderPlugin';
|
|
var i = 0;
|
|
var name;
|
|
var player = TestHelpers.makePlayer({});
|
|
var plugin = function (name) {
|
|
Plugin(name, function (opts) {
|
|
this.on('test', function (event) {
|
|
order.push(name);
|
|
});
|
|
});
|
|
player[name]({});
|
|
};
|
|
|
|
for (; i < 3; i++ ) {
|
|
name = pluginName + i;
|
|
expectedOrder.push(name);
|
|
plugin(name);
|
|
}
|
|
|
|
Plugin('testerPlugin', function (opts) {
|
|
this.trigger('test');
|
|
});
|
|
|
|
player['testerPlugin']({});
|
|
|
|
deepEqual(order, expectedOrder, 'plugins should receive events in order of initialization');
|
|
player.dispose();
|
|
});
|
|
|
|
test('Plugins should not get events after stopImmediatePropagation is called', function () {
|
|
var order = [];
|
|
var expectedOrder = [];
|
|
var pluginName = 'orderPlugin';
|
|
var i = 0;
|
|
var name;
|
|
var player = TestHelpers.makePlayer({});
|
|
var plugin = function (name) {
|
|
Plugin(name, function (opts) {
|
|
this.on('test', function (event) {
|
|
order.push(name);
|
|
event.stopImmediatePropagation();
|
|
});
|
|
});
|
|
player[name]({});
|
|
};
|
|
|
|
for (; i < 3; i++ ) {
|
|
name = pluginName + i;
|
|
expectedOrder.push(name);
|
|
plugin(name);
|
|
}
|
|
|
|
Plugin('testerPlugin', function (opts) {
|
|
this.trigger('test');
|
|
});
|
|
|
|
player['testerPlugin']({});
|
|
|
|
deepEqual(order, expectedOrder.slice(0, order.length), 'plugins should receive events in order of initialization, until stopImmediatePropagation');
|
|
|
|
equal(order.length, 1, 'only one event listener should have triggered');
|
|
player.dispose();
|
|
});
|