2014-09-02 22:39:08 +03:00
|
|
|
module('Player', {
|
|
|
|
'setup': function() {
|
2014-12-03 21:31:39 +02:00
|
|
|
this.clock = sinon.useFakeTimers();
|
2014-09-02 22:39:08 +03:00
|
|
|
},
|
|
|
|
'teardown': function() {
|
2014-12-03 21:31:39 +02:00
|
|
|
this.clock.restore();
|
2014-09-02 22:39:08 +03:00
|
|
|
}
|
|
|
|
});
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
// Compiler doesn't like using 'this' in setup/teardown.
|
|
|
|
// module("Player", {
|
|
|
|
// /**
|
|
|
|
// * @this {*}
|
|
|
|
// */
|
|
|
|
// setup: function(){
|
|
|
|
// window.player1 = true; // using window works
|
|
|
|
// },
|
|
|
|
|
|
|
|
// /**
|
|
|
|
// * @this {*}
|
|
|
|
// */
|
|
|
|
// teardown: function(){
|
|
|
|
// // if (this.player && this.player.el() !== null) {
|
|
|
|
// // this.player.dispose();
|
|
|
|
// // this.player = null;
|
|
|
|
// // }
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
|
|
|
|
// Object.size = function(obj) {
|
|
|
|
// var size = 0, key;
|
|
|
|
// for (key in obj) {
|
|
|
|
// console.log('key', key)
|
|
|
|
// if (obj.hasOwnProperty(key)) size++;
|
|
|
|
// }
|
|
|
|
// return size;
|
|
|
|
// };
|
|
|
|
|
|
|
|
|
|
|
|
test('should create player instance that inherits from component and dispose it', function(){
|
|
|
|
var player = PlayerTest.makePlayer();
|
|
|
|
|
|
|
|
ok(player.el().nodeName === 'DIV');
|
|
|
|
ok(player.on, 'component function exists');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
ok(player.el() === null, 'element disposed');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should accept options from multiple sources and override in correct order', function(){
|
|
|
|
// For closure compiler to work, all reference to the prop have to be the same type
|
|
|
|
// As in options['attr'] or options.attr. Compiler will minimize each separately.
|
|
|
|
// Since we're using setAttribute which requires a string, we have to use the string
|
|
|
|
// version of the key for all version.
|
|
|
|
|
|
|
|
// Set a global option
|
|
|
|
vjs.options['attr'] = 1;
|
|
|
|
|
|
|
|
var tag0 = PlayerTest.makeTag();
|
|
|
|
var player0 = new vjs.Player(tag0);
|
|
|
|
|
2013-02-09 01:29:04 +03:00
|
|
|
ok(player0.options_['attr'] === 1, 'global option was set');
|
2013-01-11 00:06:12 +03:00
|
|
|
player0.dispose();
|
|
|
|
|
|
|
|
// Set a tag level option
|
|
|
|
var tag1 = PlayerTest.makeTag();
|
|
|
|
tag1.setAttribute('attr', 'asdf'); // Attributes must be set as strings
|
|
|
|
|
|
|
|
var player1 = new vjs.Player(tag1);
|
2013-01-18 05:03:25 +03:00
|
|
|
ok(player1.options_['attr'] === 'asdf', 'Tag options overrode global options');
|
2013-01-11 00:06:12 +03:00
|
|
|
player1.dispose();
|
|
|
|
|
|
|
|
// Set a tag level option
|
|
|
|
var tag2 = PlayerTest.makeTag();
|
|
|
|
tag2.setAttribute('attr', 'asdf');
|
|
|
|
|
|
|
|
var player2 = new vjs.Player(tag2, { 'attr': 'fdsa' });
|
2013-01-18 05:03:25 +03:00
|
|
|
ok(player2.options_['attr'] === 'fdsa', 'Init options overrode tag and global options');
|
2013-01-11 00:06:12 +03:00
|
|
|
player2.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should get tag, source, and track settings', function(){
|
2014-08-05 01:12:17 +03:00
|
|
|
// Partially tested in lib->getElementAttributes
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
2014-05-13 03:08:48 +03:00
|
|
|
var html = '<video id="example_1" class="video-js" autoplay preload="none">';
|
2013-01-11 00:06:12 +03:00
|
|
|
html += '<source src="http://google.com" type="video/mp4">';
|
|
|
|
html += '<source src="http://google.com" type="video/webm">';
|
2014-05-08 00:59:01 +03:00
|
|
|
html += '<track src="http://google.com" kind="captions" attrtest>';
|
2013-01-11 00:06:12 +03:00
|
|
|
html += '</video>';
|
|
|
|
|
|
|
|
fixture.innerHTML += html;
|
|
|
|
|
|
|
|
var tag = document.getElementById('example_1');
|
2014-05-13 03:08:48 +03:00
|
|
|
var player = PlayerTest.makePlayer({}, tag);
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2013-01-18 05:03:25 +03:00
|
|
|
ok(player.options_['autoplay'] === true);
|
2014-05-13 03:08:48 +03:00
|
|
|
ok(player.options_['preload'] === 'none'); // No extern. Use string.
|
2013-01-18 05:03:25 +03:00
|
|
|
ok(player.options_['id'] === 'example_1');
|
|
|
|
ok(player.options_['sources'].length === 2);
|
|
|
|
ok(player.options_['sources'][0].src === 'http://google.com');
|
|
|
|
ok(player.options_['sources'][0].type === 'video/mp4');
|
|
|
|
ok(player.options_['sources'][1].type === 'video/webm');
|
|
|
|
ok(player.options_['tracks'].length === 1);
|
|
|
|
ok(player.options_['tracks'][0]['kind'] === 'captions'); // No extern
|
2014-05-08 00:59:01 +03:00
|
|
|
ok(player.options_['tracks'][0]['attrtest'] === '');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
ok(player.el().className.indexOf('video-js') !== -1, 'transferred class from tag to player div');
|
|
|
|
ok(player.el().id === 'example_1', 'transferred id from tag to player div');
|
|
|
|
|
|
|
|
ok(vjs.players[player.id()] === player, 'player referenceable from global list');
|
|
|
|
ok(tag.id !== player.id, 'tag ID no longer is the same as player ID');
|
|
|
|
ok(tag.className !== player.el().className, 'tag classname updated');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
|
2013-06-29 01:42:47 +03:00
|
|
|
ok(tag['player'] !== player, 'tag player ref killed');
|
2013-02-09 01:29:04 +03:00
|
|
|
ok(!vjs.players['example_1'], 'global player ref killed');
|
|
|
|
ok(player.el() === null, 'player el killed');
|
2012-12-11 03:40:12 +03:00
|
|
|
});
|
|
|
|
|
2014-09-02 22:39:08 +03:00
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
2014-12-03 21:31:39 +02:00
|
|
|
this.clock.tick(1);
|
2014-09-02 22:39:08 +03:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
vjs.log.error.restore();
|
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should set the width and height of the player', function(){
|
|
|
|
var player = PlayerTest.makePlayer({ width: 123, height: '100%' });
|
|
|
|
|
2013-02-09 01:29:04 +03:00
|
|
|
ok(player.width() === 123);
|
|
|
|
ok(player.el().style.width === '123px');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
var container = document.createElement('div');
|
|
|
|
fixture.appendChild(container);
|
|
|
|
|
|
|
|
// Player container needs to have height in order to have height
|
|
|
|
// Don't want to mess with the fixture itself
|
|
|
|
container.appendChild(player.el());
|
2013-02-09 01:29:04 +03:00
|
|
|
container.style.height = '1000px';
|
2013-01-11 00:06:12 +03:00
|
|
|
ok(player.height() === 1000);
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2013-03-09 11:39:28 +03:00
|
|
|
test('should not force width and height', function() {
|
|
|
|
var player = PlayerTest.makePlayer({ width: 'auto', height: 'auto' });
|
|
|
|
ok(player.el().style.width === '', 'Width is not forced');
|
|
|
|
ok(player.el().style.height === '', 'Height is not forced');
|
2013-04-09 02:23:41 +03:00
|
|
|
|
2013-03-09 11:39:28 +03:00
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2013-11-27 03:53:23 +03:00
|
|
|
test('should wrap the original tag in the player div', function(){
|
2013-01-11 00:06:12 +03:00
|
|
|
var tag = PlayerTest.makeTag();
|
|
|
|
var container = document.createElement('div');
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
container.appendChild(tag);
|
|
|
|
fixture.appendChild(container);
|
|
|
|
|
|
|
|
var player = new vjs.Player(tag);
|
|
|
|
var el = player.el();
|
|
|
|
|
2013-02-09 01:29:04 +03:00
|
|
|
ok(el.parentNode === container, 'player placed at same level as tag');
|
2013-01-11 00:06:12 +03:00
|
|
|
// Tag may be placed inside the player element or it may be removed from the DOM
|
2013-02-09 01:29:04 +03:00
|
|
|
ok(tag.parentNode !== container, 'tag removed from original place');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2013-11-27 03:53:23 +03:00
|
|
|
test('should set and update the poster value', function(){
|
|
|
|
var tag, poster, updatedPoster, player;
|
2013-08-25 02:34:26 +03:00
|
|
|
|
2013-11-27 03:53:23 +03:00
|
|
|
poster = 'http://example.com/poster.jpg';
|
2013-08-25 02:34:26 +03:00
|
|
|
updatedPoster = 'http://example.com/updated-poster.jpg';
|
|
|
|
|
|
|
|
tag = PlayerTest.makeTag();
|
2013-11-27 03:53:23 +03:00
|
|
|
tag.setAttribute('poster', poster);
|
2013-08-25 02:34:26 +03:00
|
|
|
|
2013-11-27 03:53:23 +03:00
|
|
|
player = PlayerTest.makePlayer({}, tag);
|
|
|
|
equal(player.poster(), poster, 'the poster property should equal the tag attribute');
|
2013-08-25 02:34:26 +03:00
|
|
|
|
2013-11-27 03:53:23 +03:00
|
|
|
var pcEmitted = false;
|
|
|
|
player.on('posterchange', function(){
|
|
|
|
pcEmitted = true;
|
|
|
|
});
|
2013-08-25 02:34:26 +03:00
|
|
|
|
|
|
|
player.poster(updatedPoster);
|
2013-11-27 03:53:23 +03:00
|
|
|
ok(pcEmitted, 'posterchange event was emitted');
|
|
|
|
equal(player.poster(), updatedPoster, 'the updated poster is returned');
|
2013-08-25 02:34:26 +03:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2015-02-09 19:11:00 +02:00
|
|
|
// hasStarted() is equivalent to the "show poster flag" in the
|
|
|
|
// standard, for the purpose of displaying the poster image
|
|
|
|
// https://html.spec.whatwg.org/multipage/embedded-content.html#dom-media-play
|
|
|
|
test('should hide the poster when play is called', function() {
|
|
|
|
var player = PlayerTest.makePlayer({
|
|
|
|
poster: 'https://example.com/poster.jpg'
|
|
|
|
});
|
|
|
|
|
|
|
|
equal(player.hasStarted(), false, 'the show poster flag is true before play');
|
|
|
|
player.play();
|
|
|
|
equal(player.hasStarted(), true, 'the show poster flag is false after play');
|
|
|
|
|
|
|
|
player.trigger('loadstart');
|
|
|
|
equal(player.hasStarted(),
|
|
|
|
false,
|
|
|
|
'the resource selection algorithm sets the show poster flag to true');
|
|
|
|
|
|
|
|
player.play();
|
|
|
|
equal(player.hasStarted(), true, 'the show poster flag is false after play');
|
|
|
|
});
|
|
|
|
|
2013-01-11 00:06:12 +03:00
|
|
|
test('should load a media controller', function(){
|
|
|
|
var player = PlayerTest.makePlayer({
|
|
|
|
preload: 'none',
|
|
|
|
sources: [
|
2013-02-09 01:29:04 +03:00
|
|
|
{ src: 'http://google.com', type: 'video/mp4' },
|
|
|
|
{ src: 'http://google.com', type: 'video/webm' }
|
2013-01-11 00:06:12 +03:00
|
|
|
]
|
|
|
|
});
|
|
|
|
|
2013-02-09 01:29:04 +03:00
|
|
|
ok(player.el().children[0].className.indexOf('vjs-tech') !== -1, 'media controller loaded');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
2013-01-18 04:33:53 +03:00
|
|
|
|
2013-03-06 00:23:01 +03:00
|
|
|
test('should be able to initialize player twice on the same tag using string reference', function() {
|
|
|
|
var videoTag = PlayerTest.makeTag();
|
|
|
|
var id = videoTag.id;
|
|
|
|
|
|
|
|
var fixture = document.getElementById('qunit-fixture');
|
|
|
|
fixture.appendChild(videoTag);
|
|
|
|
|
|
|
|
var player = vjs(videoTag.id);
|
|
|
|
ok(player, 'player is created');
|
|
|
|
player.dispose();
|
|
|
|
|
|
|
|
ok(!document.getElementById(id), 'element is removed');
|
|
|
|
videoTag = PlayerTest.makeTag();
|
|
|
|
fixture.appendChild(videoTag);
|
|
|
|
|
|
|
|
//here we receive cached version instead of real
|
|
|
|
player = vjs(videoTag.id);
|
|
|
|
//here it triggers error, because player was destroyed already after first dispose
|
|
|
|
player.dispose();
|
|
|
|
});
|
2013-05-03 03:15:37 +03:00
|
|
|
|
2013-08-10 00:29:22 +03:00
|
|
|
test('should set controls and trigger events', function() {
|
|
|
|
expect(6);
|
2013-05-03 03:15:37 +03:00
|
|
|
|
|
|
|
var player = PlayerTest.makePlayer({ 'controls': false });
|
|
|
|
ok(player.controls() === false, 'controls set through options');
|
2013-08-10 00:29:22 +03:00
|
|
|
var hasDisabledClass = player.el().className.indexOf('vjs-controls-disabled');
|
|
|
|
ok(hasDisabledClass !== -1, 'Disabled class added to player');
|
|
|
|
|
2013-05-03 03:15:37 +03:00
|
|
|
player.controls(true);
|
|
|
|
ok(player.controls() === true, 'controls updated');
|
2013-08-10 00:29:22 +03:00
|
|
|
var hasEnabledClass = player.el().className.indexOf('vjs-controls-enabled');
|
|
|
|
ok(hasEnabledClass !== -1, 'Disabled class added to player');
|
2013-05-03 03:15:37 +03:00
|
|
|
|
2013-08-10 00:29:22 +03:00
|
|
|
player.on('controlsenabled', function(){
|
|
|
|
ok(true, 'enabled fired once');
|
|
|
|
});
|
|
|
|
player.on('controlsdisabled', function(){
|
|
|
|
ok(true, 'disabled fired once');
|
2013-05-03 03:15:37 +03:00
|
|
|
});
|
|
|
|
player.controls(false);
|
2013-08-10 00:29:22 +03:00
|
|
|
player.controls(true);
|
|
|
|
// Check for unnecessary events
|
|
|
|
player.controls(true);
|
2013-05-03 03:15:37 +03:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2013-05-29 01:29:42 +03:00
|
|
|
// Can't figure out how to test fullscreen events with tests
|
|
|
|
// Browsers aren't triggering the events at least
|
|
|
|
// asyncTest('should trigger the fullscreenchange event', function() {
|
|
|
|
// expect(3);
|
|
|
|
|
|
|
|
// var player = PlayerTest.makePlayer();
|
|
|
|
// player.on('fullscreenchange', function(){
|
|
|
|
// ok(true, 'fullscreenchange event fired');
|
2014-09-06 00:19:30 +03:00
|
|
|
// ok(this.isFullscreen() === true, 'isFullscreen is true');
|
2013-05-29 01:29:42 +03:00
|
|
|
// ok(this.el().className.indexOf('vjs-fullscreen') !== -1, 'vjs-fullscreen class added');
|
|
|
|
|
|
|
|
// player.dispose();
|
|
|
|
// start();
|
|
|
|
// });
|
|
|
|
|
2014-09-06 00:19:30 +03:00
|
|
|
// player.requestFullscreen();
|
2013-05-29 01:29:42 +03:00
|
|
|
// });
|
|
|
|
|
2013-08-10 00:29:22 +03:00
|
|
|
test('should toggle user the user state between active and inactive', function(){
|
|
|
|
var player = PlayerTest.makePlayer({});
|
|
|
|
|
|
|
|
expect(9);
|
|
|
|
|
|
|
|
ok(player.userActive(), 'User should be active at player init');
|
|
|
|
|
|
|
|
player.on('userinactive', function(){
|
|
|
|
ok(true, 'userinactive event triggered');
|
|
|
|
});
|
|
|
|
|
|
|
|
player.on('useractive', function(){
|
|
|
|
ok(true, 'useractive event triggered');
|
|
|
|
});
|
|
|
|
|
|
|
|
player.userActive(false);
|
|
|
|
ok(player.userActive() === false, 'Player state changed to inactive');
|
|
|
|
ok(player.el().className.indexOf('vjs-user-active') === -1, 'Active class removed');
|
|
|
|
ok(player.el().className.indexOf('vjs-user-inactive') !== -1, 'Inactive class added');
|
|
|
|
|
|
|
|
player.userActive(true);
|
|
|
|
ok(player.userActive() === true, 'Player state changed to active');
|
|
|
|
ok(player.el().className.indexOf('vjs-user-inactive') === -1, 'Inactive class removed');
|
|
|
|
ok(player.el().className.indexOf('vjs-user-active') !== -1, 'Active class added');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should add a touch-enabled classname when touch is supported', function(){
|
|
|
|
var player;
|
|
|
|
|
|
|
|
expect(1);
|
|
|
|
|
|
|
|
// Fake touch support. Real touch support isn't needed for this test.
|
|
|
|
var origTouch = vjs.TOUCH_ENABLED;
|
|
|
|
vjs.TOUCH_ENABLED = true;
|
|
|
|
|
|
|
|
player = PlayerTest.makePlayer({});
|
|
|
|
|
|
|
|
ok(player.el().className.indexOf('vjs-touch-enabled'), 'touch-enabled classname added');
|
|
|
|
|
|
|
|
|
|
|
|
vjs.TOUCH_ENABLED = origTouch;
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
test('should allow for tracking when native controls are used', function(){
|
|
|
|
var player = PlayerTest.makePlayer({});
|
|
|
|
|
|
|
|
expect(6);
|
|
|
|
|
|
|
|
// Make sure native controls is false before starting test
|
|
|
|
player.usingNativeControls(false);
|
|
|
|
|
|
|
|
player.on('usingnativecontrols', function(){
|
|
|
|
ok(true, 'usingnativecontrols event triggered');
|
|
|
|
});
|
|
|
|
|
|
|
|
player.on('usingcustomcontrols', function(){
|
|
|
|
ok(true, 'usingcustomcontrols event triggered');
|
|
|
|
});
|
|
|
|
|
|
|
|
player.usingNativeControls(true);
|
|
|
|
ok(player.usingNativeControls() === true, 'Using native controls is true');
|
|
|
|
ok(player.el().className.indexOf('vjs-using-native-controls') !== -1, 'Native controls class added');
|
|
|
|
|
|
|
|
player.usingNativeControls(false);
|
|
|
|
ok(player.usingNativeControls() === false, 'Using native controls is false');
|
|
|
|
ok(player.el().className.indexOf('vjs-using-native-controls') === -1, 'Native controls class removed');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2014-05-13 03:08:48 +03:00
|
|
|
// test('should use custom message when encountering an unsupported video type',
|
|
|
|
// function() {
|
|
|
|
// videojs.options['notSupportedMessage'] = 'Video no go <a href="">link</a>';
|
|
|
|
// var fixture = document.getElementById('qunit-fixture');
|
2013-07-12 23:05:25 +03:00
|
|
|
|
2014-05-13 03:08:48 +03:00
|
|
|
// var html =
|
|
|
|
// '<video id="example_1">' +
|
|
|
|
// '<source src="fake.foo" type="video/foo">' +
|
|
|
|
// '</video>';
|
2013-07-12 23:05:25 +03:00
|
|
|
|
2014-05-13 03:08:48 +03:00
|
|
|
// fixture.innerHTML += html;
|
2013-07-12 23:05:25 +03:00
|
|
|
|
2014-05-13 03:08:48 +03:00
|
|
|
// var tag = document.getElementById('example_1');
|
|
|
|
// var player = new vjs.Player(tag);
|
2013-07-12 23:05:25 +03:00
|
|
|
|
2014-05-13 03:08:48 +03:00
|
|
|
// var incompatibilityMessage = player.el().getElementsByTagName('p')[0];
|
|
|
|
// // ie8 capitalizes tag names
|
|
|
|
// equal(incompatibilityMessage.innerHTML.toLowerCase(), 'video no go <a href="">link</a>');
|
2013-07-12 23:05:25 +03:00
|
|
|
|
2014-05-13 03:08:48 +03:00
|
|
|
// player.dispose();
|
|
|
|
// });
|
2013-12-03 02:29:41 +03:00
|
|
|
|
|
|
|
test('should register players with generated ids', function(){
|
|
|
|
var fixture, video, player, id;
|
|
|
|
fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
video = document.createElement('video');
|
|
|
|
video.className = 'vjs-default-skin video-js';
|
|
|
|
fixture.appendChild(video);
|
|
|
|
|
|
|
|
player = new vjs.Player(video);
|
|
|
|
id = player.el().id;
|
|
|
|
|
|
|
|
equal(player.el().id, player.id(), 'the player and element ids are equal');
|
|
|
|
ok(vjs.players[id], 'the generated id is registered');
|
|
|
|
});
|
2014-04-03 20:41:02 +03:00
|
|
|
|
|
|
|
test('should not add multiple first play events despite subsequent loads', function() {
|
|
|
|
expect(1);
|
|
|
|
|
|
|
|
var player = PlayerTest.makePlayer({});
|
|
|
|
|
|
|
|
player.on('firstplay', function(){
|
2014-06-11 02:55:08 +03:00
|
|
|
ok(true, 'First play should fire once.');
|
2014-04-03 20:41:02 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// Checking to make sure onLoadStart removes first play listener before adding a new one.
|
|
|
|
player.trigger('loadstart');
|
|
|
|
player.trigger('loadstart');
|
|
|
|
player.trigger('play');
|
|
|
|
});
|
|
|
|
|
2014-06-11 02:55:08 +03:00
|
|
|
test('should fire firstplay after resetting the player', function() {
|
|
|
|
var player = PlayerTest.makePlayer({});
|
|
|
|
|
|
|
|
var fpFired = false;
|
|
|
|
player.on('firstplay', function(){
|
|
|
|
fpFired = true;
|
|
|
|
});
|
|
|
|
|
|
|
|
// init firstplay listeners
|
|
|
|
player.trigger('loadstart');
|
|
|
|
player.trigger('play');
|
|
|
|
ok(fpFired, 'First firstplay fired');
|
|
|
|
|
|
|
|
// reset the player
|
|
|
|
player.trigger('loadstart');
|
|
|
|
fpFired = false;
|
|
|
|
player.trigger('play');
|
|
|
|
ok(fpFired, 'Second firstplay fired');
|
|
|
|
|
|
|
|
// the play event can fire before the loadstart event.
|
|
|
|
// in that case we still want the firstplay even to fire.
|
|
|
|
player.tech.paused = function(){ return false; };
|
|
|
|
fpFired = false;
|
|
|
|
// reset the player
|
|
|
|
player.trigger('loadstart');
|
|
|
|
// player.trigger('play');
|
|
|
|
ok(fpFired, 'Third firstplay fired');
|
|
|
|
});
|
|
|
|
|
2014-04-03 20:41:02 +03:00
|
|
|
test('should remove vjs-has-started class', function(){
|
|
|
|
expect(3);
|
|
|
|
|
|
|
|
var player = PlayerTest.makePlayer({});
|
|
|
|
|
|
|
|
player.trigger('loadstart');
|
|
|
|
player.trigger('play');
|
|
|
|
ok(player.el().className.indexOf('vjs-has-started') !== -1, 'vjs-has-started class added');
|
|
|
|
|
|
|
|
player.trigger('loadstart');
|
|
|
|
ok(player.el().className.indexOf('vjs-has-started') === -1, 'vjs-has-started class removed');
|
|
|
|
|
|
|
|
player.trigger('play');
|
|
|
|
ok(player.el().className.indexOf('vjs-has-started') !== -1, 'vjs-has-started class added again');
|
|
|
|
});
|
2014-05-13 03:08:48 +03:00
|
|
|
|
|
|
|
test('player should handle different error types', function(){
|
|
|
|
expect(8);
|
|
|
|
var player = PlayerTest.makePlayer({});
|
|
|
|
var testMsg = 'test message';
|
|
|
|
|
|
|
|
// prevent error log messages in the console
|
|
|
|
sinon.stub(vjs.log, 'error');
|
|
|
|
|
|
|
|
// error code supplied
|
|
|
|
function errCode(){
|
|
|
|
equal(player.error().code, 1, 'error code is correct');
|
|
|
|
}
|
|
|
|
player.on('error', errCode);
|
|
|
|
player.error(1);
|
|
|
|
player.off('error', errCode);
|
|
|
|
|
|
|
|
// error instance supplied
|
|
|
|
function errInst(){
|
|
|
|
equal(player.error().code, 2, 'MediaError code is correct');
|
|
|
|
equal(player.error().message, testMsg, 'MediaError message is correct');
|
|
|
|
}
|
|
|
|
player.on('error', errInst);
|
|
|
|
player.error(new vjs.MediaError({ code: 2, message: testMsg }));
|
|
|
|
player.off('error', errInst);
|
|
|
|
|
|
|
|
// error message supplied
|
|
|
|
function errMsg(){
|
|
|
|
equal(player.error().code, 0, 'error message code is correct');
|
|
|
|
equal(player.error().message, testMsg, 'error message is correct');
|
|
|
|
}
|
|
|
|
player.on('error', errMsg);
|
|
|
|
player.error(testMsg);
|
|
|
|
player.off('error', errMsg);
|
|
|
|
|
|
|
|
// error config supplied
|
|
|
|
function errConfig(){
|
|
|
|
equal(player.error().code, 3, 'error config code is correct');
|
|
|
|
equal(player.error().message, testMsg, 'error config message is correct');
|
|
|
|
}
|
|
|
|
player.on('error', errConfig);
|
|
|
|
player.error({ code: 3, message: testMsg });
|
|
|
|
player.off('error', errConfig);
|
|
|
|
|
|
|
|
// check for vjs-error classname
|
|
|
|
ok(player.el().className.indexOf('vjs-error') >= 0, 'player does not have vjs-error classname');
|
|
|
|
|
|
|
|
// restore error logging
|
|
|
|
vjs.log.error.restore();
|
|
|
|
});
|
|
|
|
|
2014-07-01 22:10:45 +03:00
|
|
|
test('Data attributes on the video element should persist in the new wrapper element', function() {
|
|
|
|
var dataId, tag, player;
|
|
|
|
|
|
|
|
dataId = 123;
|
|
|
|
|
|
|
|
tag = PlayerTest.makeTag();
|
|
|
|
tag.setAttribute('data-id', dataId);
|
|
|
|
|
|
|
|
player = PlayerTest.makePlayer({}, tag);
|
|
|
|
|
|
|
|
equal(player.el().getAttribute('data-id'), dataId, 'data-id should be available on the new player element after creation');
|
|
|
|
});
|
2014-08-05 01:12:17 +03:00
|
|
|
|
2014-08-05 01:04:39 +03:00
|
|
|
test('should restore attributes from the original video tag when creating a new element', function(){
|
|
|
|
var player, html5Mock, el;
|
2014-08-05 01:12:17 +03:00
|
|
|
|
2014-08-05 01:04:39 +03:00
|
|
|
player = PlayerTest.makePlayer();
|
|
|
|
html5Mock = { player_: player };
|
2014-08-05 01:12:17 +03:00
|
|
|
|
2014-08-05 01:04:39 +03:00
|
|
|
// simulate attributes stored from the original tag
|
|
|
|
player.tagAttributes = {
|
|
|
|
'preload': 'auto',
|
2014-10-04 01:24:22 +03:00
|
|
|
'autoplay': true,
|
2014-08-05 01:04:39 +03:00
|
|
|
'webkit-playsinline': true
|
|
|
|
};
|
2014-08-05 01:12:17 +03:00
|
|
|
|
2014-08-05 01:04:39 +03:00
|
|
|
// set options that should override tag attributes
|
|
|
|
player.options_['preload'] = 'none';
|
2014-08-05 01:12:17 +03:00
|
|
|
|
2014-08-05 01:04:39 +03:00
|
|
|
// create the element
|
|
|
|
el = vjs.Html5.prototype.createEl.call(html5Mock);
|
2014-08-05 01:12:17 +03:00
|
|
|
|
2014-08-05 01:04:39 +03:00
|
|
|
equal(el.getAttribute('preload'), 'none', 'attribute was successful overridden by an option');
|
2014-10-04 01:24:22 +03:00
|
|
|
equal(el.getAttribute('autoplay'), '', 'autoplay attribute was set properly');
|
2014-08-05 01:04:39 +03:00
|
|
|
equal(el.getAttribute('webkit-playsinline'), '', 'webkit-playsinline attribute was set properly');
|
2014-08-05 01:12:17 +03:00
|
|
|
});
|
2014-08-25 12:28:52 +03:00
|
|
|
|
2014-08-25 12:35:06 +03:00
|
|
|
test('should honor default inactivity timeout', function() {
|
2014-09-02 21:04:30 +03:00
|
|
|
var player;
|
2014-08-25 17:42:58 +03:00
|
|
|
var clock = sinon.useFakeTimers();
|
2014-08-25 12:35:06 +03:00
|
|
|
|
|
|
|
// default timeout is 2000ms
|
|
|
|
player = PlayerTest.makePlayer({});
|
|
|
|
|
|
|
|
equal(player.userActive(), true, 'User is active on creation');
|
2014-08-25 17:42:58 +03:00
|
|
|
clock.tick(1800);
|
|
|
|
equal(player.userActive(), true, 'User is still active');
|
|
|
|
clock.tick(500);
|
|
|
|
equal(player.userActive(), false, 'User is inactive after timeout expired');
|
2014-08-25 12:35:06 +03:00
|
|
|
|
2014-08-25 17:42:58 +03:00
|
|
|
clock.restore();
|
2014-08-25 12:35:06 +03:00
|
|
|
});
|
|
|
|
|
2014-08-25 12:28:52 +03:00
|
|
|
test('should honor configured inactivity timeout', function() {
|
2014-09-02 21:04:30 +03:00
|
|
|
var player;
|
2014-08-25 17:42:58 +03:00
|
|
|
var clock = sinon.useFakeTimers();
|
2014-08-25 12:28:52 +03:00
|
|
|
|
|
|
|
// default timeout is 2000ms, set to shorter 200ms
|
|
|
|
player = PlayerTest.makePlayer({
|
2014-09-02 21:04:30 +03:00
|
|
|
'inactivityTimeout': 200
|
2014-08-25 12:28:52 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
equal(player.userActive(), true, 'User is active on creation');
|
2014-08-25 17:42:58 +03:00
|
|
|
clock.tick(150);
|
|
|
|
equal(player.userActive(), true, 'User is still active');
|
|
|
|
clock.tick(350);
|
2014-08-25 12:28:52 +03:00
|
|
|
// make sure user is now inactive after 500ms
|
2014-08-25 17:42:58 +03:00
|
|
|
equal(player.userActive(), false, 'User is inactive after timeout expired');
|
|
|
|
|
|
|
|
clock.restore();
|
2014-08-25 12:28:52 +03:00
|
|
|
});
|
2014-08-25 12:35:06 +03:00
|
|
|
|
|
|
|
test('should honor disabled inactivity timeout', function() {
|
2014-09-02 21:04:30 +03:00
|
|
|
var player;
|
2014-08-25 17:42:58 +03:00
|
|
|
var clock = sinon.useFakeTimers();
|
2014-08-25 12:35:06 +03:00
|
|
|
|
|
|
|
// default timeout is 2000ms, disable by setting to zero
|
|
|
|
player = PlayerTest.makePlayer({
|
2014-09-02 21:04:30 +03:00
|
|
|
'inactivityTimeout': 0
|
2014-08-25 12:35:06 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
equal(player.userActive(), true, 'User is active on creation');
|
2014-08-25 17:42:58 +03:00
|
|
|
clock.tick(5000);
|
|
|
|
equal(player.userActive(), true, 'User is still active');
|
2014-08-25 12:35:06 +03:00
|
|
|
|
2014-08-25 17:42:58 +03:00
|
|
|
clock.restore();
|
2014-08-25 12:35:06 +03:00
|
|
|
});
|
2014-09-04 18:51:05 +03:00
|
|
|
|
|
|
|
test('should clear pending errors on disposal', function() {
|
|
|
|
var clock = sinon.useFakeTimers(), player;
|
|
|
|
|
|
|
|
player = PlayerTest.makePlayer();
|
|
|
|
player.src({
|
|
|
|
src: 'http://example.com/movie.unsupported-format',
|
|
|
|
type: 'video/unsupported-format'
|
|
|
|
});
|
|
|
|
player.dispose();
|
|
|
|
try {
|
|
|
|
clock.tick(5000);
|
|
|
|
} catch (e) {
|
|
|
|
return ok(!e, 'threw an error: ' + e.message);
|
|
|
|
}
|
|
|
|
ok(true, 'did not throw an error after disposal');
|
|
|
|
});
|
2014-09-16 20:55:55 +03:00
|
|
|
|
|
|
|
test('pause is called when player ended event is fired and player is not paused', function() {
|
|
|
|
var video = document.createElement('video'),
|
|
|
|
player = PlayerTest.makePlayer({}, video),
|
|
|
|
pauses = 0;
|
|
|
|
player.paused = function() {
|
|
|
|
return false;
|
|
|
|
};
|
|
|
|
player.pause = function() {
|
|
|
|
pauses++;
|
|
|
|
};
|
|
|
|
player.trigger('ended');
|
|
|
|
equal(pauses, 1, 'pause was called');
|
|
|
|
});
|
|
|
|
|
|
|
|
test('pause is not called if the player is paused and ended is fired', function() {
|
|
|
|
var video = document.createElement('video'),
|
|
|
|
player = PlayerTest.makePlayer({}, video),
|
|
|
|
pauses = 0;
|
|
|
|
player.paused = function() {
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
player.pause = function() {
|
|
|
|
pauses++;
|
|
|
|
};
|
|
|
|
player.trigger('ended');
|
|
|
|
equal(pauses, 0, 'pause was not called when ended fired');
|
|
|
|
});
|
2014-10-01 04:34:51 +03:00
|
|
|
|
|
|
|
test('should add an audio class if an audio el is used', function() {
|
|
|
|
var audio = document.createElement('audio'),
|
|
|
|
player = PlayerTest.makePlayer({}, audio),
|
|
|
|
audioClass = 'vjs-audio';
|
|
|
|
|
|
|
|
ok(player.el().className.indexOf(audioClass) !== -1, 'added '+ audioClass +' css class');
|
|
|
|
});
|