1
0
mirror of https://github.com/videojs/video.js.git synced 2025-02-02 11:34:50 +02:00

added timeout fix and tests.

This commit is contained in:
Matthew McClure 2014-09-02 12:39:08 -07:00
parent 1aabc440b6
commit e72d682028
4 changed files with 40 additions and 4 deletions

View File

@ -1167,7 +1167,11 @@ vjs.Player.prototype.sourceList_ = function(sources){
this.loadTech(sourceTech.tech, sourceTech.source);
}
} else {
this.error({ code: 4, message: this.localize(this.options()['notSupportedMessage']) });
// We need to wrap this in a timeout to give folks a chance to add error event handlers
setTimeout(vjs.bind(this, function() {
this.error({ code: 4, message: this.localize(this.options()['notSupportedMessage']) });
}), 0);
// we could not find an appropriate tech, but let's still notify the delegate that this is it
// this needs a better comment about why this is needed
this.triggerReady();

View File

@ -136,7 +136,7 @@ test( 'should listen only once in multiple events from a single call', function(
vjs.trigger(el, 'click'); // No click should happen.
vjs.trigger(el, 'event1'); // event1 must be handled.
vjs.trigger(el, 'event1'); // No event1 should be handled.
vjs.trigger(el, 'event2'); // event2 must be handled.
vjs.trigger(el, 'event2'); // event2 must be handled.
vjs.trigger(el, 'event2'); // No event2 should be handled.
});

View File

@ -1,4 +1,13 @@
module('Player');
var playerClock;
module('Player', {
'setup': function() {
playerClock = sinon.useFakeTimers();
},
'teardown': function() {
playerClock.restore();
}
});
// Compiler doesn't like using 'this' in setup/teardown.
// module("Player", {
@ -113,6 +122,29 @@ test('should get tag, source, and track settings', function(){
ok(player.el() === null, 'player el killed');
});
test('should asynchronously fire error events during source selection', function() {
expect(2);
sinon.stub(vjs.log, 'error');
var player = PlayerTest.makePlayer({
'techOrder': ['foo'],
'sources': [
{ 'src': 'http://vjs.zencdn.net/v/oceans.mp4', 'type': 'video/mp4' }
]
});
ok(player.options_['techOrder'][0] === 'foo', 'Foo listed as the only tech');
player.on('error', function(e) {
ok(player.error().code === 4, 'Source could not be played error thrown');
});
playerClock.tick(1);
player.dispose();
vjs.log.error.restore();
});
test('should set the width and height of the player', function(){
var player = PlayerTest.makePlayer({ width: 123, height: '100%' });

View File

@ -14,7 +14,7 @@ var PlayerTest = {
fixture.appendChild(videoTag);
playerOptions = playerOptions || {};
playerOptions['techOrder'] = ['mediaFaker'];
playerOptions['techOrder'] = playerOptions['techOrder'] || ['mediaFaker'];
return player = new videojs.Player(videoTag, playerOptions);
}