mirror of
https://github.com/videojs/video.js.git
synced 2025-01-04 06:48:49 +02:00
Merge pull request #322 from gkatsev/plugin
Add plugin event ordering test
This commit is contained in:
commit
eadaa2f800
@ -95,3 +95,68 @@ test('Plugin should overwrite plugin of same name', function(){
|
||||
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 = PlayerTest.makePlayer({});
|
||||
|
||||
for (; i < 3; i++ ) {
|
||||
name = pluginName + i;
|
||||
expectedOrder.push(name);
|
||||
(function (name) {
|
||||
vjs.plugin(name, function (opts) {
|
||||
this.on('test', function (event) {
|
||||
order.push(name);
|
||||
});
|
||||
});
|
||||
player[name]({});
|
||||
})(name);
|
||||
}
|
||||
|
||||
vjs.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 = PlayerTest.makePlayer({});
|
||||
|
||||
for (; i < 3; i++ ) {
|
||||
name = pluginName + i;
|
||||
expectedOrder.push(name);
|
||||
(function (name) {
|
||||
vjs.plugin(name, function (opts) {
|
||||
this.on('test', function (event) {
|
||||
order.push(name);
|
||||
event.stopImmediatePropagation();
|
||||
});
|
||||
});
|
||||
player[name]({});
|
||||
})(name);
|
||||
}
|
||||
|
||||
vjs.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();
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user