2016-08-03 21:27:03 +02:00
|
|
|
/* eslint-env qunit */
|
2015-05-04 01:12:38 +02:00
|
|
|
import videojs from '../../src/js/video.js';
|
2015-11-10 00:43:17 +02:00
|
|
|
import * as Dom from '../../src/js/utils/dom.js';
|
2016-12-23 18:29:23 +02:00
|
|
|
import log from '../../src/js/utils/log.js';
|
2015-03-26 06:43:41 +02:00
|
|
|
import document from 'global/document';
|
feat: middleware (#3788)
Add middleware support. Middleware can function as go-between between the player and the tech. For example, it can modify the duration that the tech returns to the player. In addition, middleware allow for supporting custom video sources and types.
Currently, middleware can only intercept timeline methods like duration, currentTime, and setCurrentTime.
For example,
```js
videojs.use('video/foo', {
setSource(src, next) {
next(null, {
src: 'http://example.com/video.mp4',
type: 'video/mp4'
});
}
});
```
Will allow you to set a source with type `video/foo` which will play back `video.mp4`.
This makes setting the source asynchronous, which aligns it with the spec a bit more. Methods like play can still be called synchronously on the player after setting the source and the player will play once the source has loaded.
`sourceOrder` option was removed as well and it will now always use source ordering.
BREAKING CHANGE: setting the source is now asynchronous. `sourceOrder` option removed and made the default.
2017-01-20 00:29:09 +02:00
|
|
|
import sinon from 'sinon';
|
|
|
|
|
|
|
|
QUnit.module('video.js', {
|
|
|
|
beforeEach() {
|
|
|
|
this.clock = sinon.useFakeTimers();
|
|
|
|
},
|
|
|
|
afterEach() {
|
|
|
|
this.clock.restore();
|
2018-01-30 18:43:47 +02:00
|
|
|
videojs.getAllPlayers().forEach(p => p.dispose());
|
feat: middleware (#3788)
Add middleware support. Middleware can function as go-between between the player and the tech. For example, it can modify the duration that the tech returns to the player. In addition, middleware allow for supporting custom video sources and types.
Currently, middleware can only intercept timeline methods like duration, currentTime, and setCurrentTime.
For example,
```js
videojs.use('video/foo', {
setSource(src, next) {
next(null, {
src: 'http://example.com/video.mp4',
type: 'video/mp4'
});
}
});
```
Will allow you to set a source with type `video/foo` which will play back `video.mp4`.
This makes setting the source asynchronous, which aligns it with the spec a bit more. Methods like play can still be called synchronously on the player after setting the source and the player will play once the source has loaded.
`sourceOrder` option was removed as well and it will now always use source ordering.
BREAKING CHANGE: setting the source is now asynchronous. `sourceOrder` option removed and made the default.
2017-01-20 00:29:09 +02:00
|
|
|
}
|
|
|
|
});
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should return a video player instance', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
fixture.innerHTML += '<video id="test_vid_id"></video>' +
|
|
|
|
'<video id="test_vid_id2"></video>';
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const player = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
2013-01-11 00:06:12 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(
|
|
|
|
videojs.getPlayers().test_vid_id === player,
|
|
|
|
'added player to global reference'
|
|
|
|
);
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const playerAgain = videojs('test_vid_id');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
2016-08-03 21:27:03 +02:00
|
|
|
});
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
QUnit.test(
|
|
|
|
'should log if the supplied element is not included in the DOM',
|
|
|
|
function(assert) {
|
|
|
|
const origWarnLog = log.warn;
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
const warnLogs = [];
|
2017-11-07 22:44:16 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
log.warn = (args) => {
|
|
|
|
warnLogs.push(args);
|
|
|
|
};
|
2017-11-07 22:44:16 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
const vid = document.createElement('video');
|
2017-11-07 22:44:16 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
vid.id = 'test_vid_id';
|
|
|
|
fixture.appendChild(vid);
|
|
|
|
const player = videojs(vid);
|
2017-11-07 22:44:16 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.equal(warnLogs.length, 0, 'no warn logs');
|
2017-11-07 22:44:16 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
const vid2 = document.createElement('video');
|
2017-11-17 01:12:37 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
vid2.id = 'test_vid_id2';
|
|
|
|
const player2 = videojs(vid2);
|
2017-11-07 22:44:16 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(player2, 'created player from tag');
|
|
|
|
assert.equal(warnLogs.length, 1, 'logged a warning');
|
|
|
|
assert.equal(
|
|
|
|
warnLogs[0],
|
|
|
|
'The element supplied is not included in the DOM',
|
|
|
|
'logged the right message'
|
|
|
|
);
|
2017-11-07 22:44:16 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
// should only log warnings on the first creation
|
|
|
|
videojs(vid2);
|
|
|
|
videojs('test_vid_id2');
|
|
|
|
assert.equal(warnLogs.length, 1, 'did not log another warning');
|
2017-11-17 01:12:37 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
log.warn = origWarnLog;
|
|
|
|
}
|
|
|
|
);
|
2017-11-07 22:44:16 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
QUnit.test(
|
|
|
|
'should log about already initalized players if options already passed',
|
|
|
|
function(assert) {
|
|
|
|
const origWarnLog = log.warn;
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
const warnLogs = [];
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
log.warn = (args) => {
|
|
|
|
warnLogs.push(args);
|
|
|
|
};
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
fixture.innerHTML += '<video id="test_vid_id"></video>';
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
const player = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.equal(player.id(), 'test_vid_id', 'player has the right ID');
|
|
|
|
assert.equal(warnLogs.length, 0, 'no warn logs');
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
const playerAgain = videojs('test_vid_id');
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(player, playerAgain, 'did not create a second player from same tag');
|
|
|
|
assert.equal(warnLogs.length, 0, 'no warn logs');
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
const playerAgainWithOptions = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(
|
|
|
|
player,
|
|
|
|
playerAgainWithOptions,
|
|
|
|
'did not create a second player from same tag'
|
|
|
|
);
|
|
|
|
assert.equal(warnLogs.length, 1, 'logged a warning');
|
|
|
|
assert.equal(
|
|
|
|
warnLogs[0],
|
|
|
|
'Player "test_vid_id" is already initialised. Options will not be applied.',
|
|
|
|
'logged the right message'
|
|
|
|
);
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
log.warn = origWarnLog;
|
|
|
|
}
|
|
|
|
);
|
2016-12-23 18:29:23 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should return a video player instance from el html5 tech', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
fixture.innerHTML += '<video id="test_vid_id"></video>' +
|
|
|
|
'<video id="test_vid_id2"></video>';
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const vid = document.querySelector('#test_vid_id');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const player = videojs(vid);
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(
|
|
|
|
videojs.getPlayers().test_vid_id === player,
|
|
|
|
'added player to global reference'
|
|
|
|
);
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const playerAgain = videojs(vid);
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2016-01-15 22:27:35 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
2013-01-11 00:06:12 +03:00
|
|
|
});
|
2014-08-18 20:43:30 +03:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should return a video player instance from el techfaker', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2014-08-18 20:43:30 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
fixture.innerHTML += '<video id="test_vid_id"></video>' +
|
|
|
|
'<video id="test_vid_id2"></video>';
|
2014-08-18 20:43:30 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const vid = document.querySelector('#test_vid_id');
|
|
|
|
const player = videojs(vid, {techOrder: ['techFaker']});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(
|
|
|
|
videojs.getPlayers().test_vid_id === player,
|
|
|
|
'added player to global reference'
|
|
|
|
);
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const playerAgain = videojs(vid);
|
2015-05-20 00:33:52 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2015-05-20 00:33:52 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
2016-08-03 21:27:03 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should add the value to the languages object', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const code = 'es';
|
|
|
|
const data = {Hello: 'Hola'};
|
|
|
|
const result = videojs.addLanguage(code, data);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(videojs.options.languages[code], 'should exist');
|
|
|
|
assert.equal(videojs.options.languages.es.Hello, 'Hola', 'should match');
|
|
|
|
assert.deepEqual(result.Hello, videojs.options.languages.es.Hello, 'should also match');
|
2015-05-20 00:33:52 +02:00
|
|
|
});
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should add the value to the languages object with lower case lang code', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const code = 'DE';
|
|
|
|
const data = {Hello: 'Guten Tag'};
|
|
|
|
const result = videojs.addLanguage(code, data);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(videojs.options.languages[code.toLowerCase()], 'should exist');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(
|
|
|
|
videojs.options.languages[code.toLowerCase()].Hello,
|
|
|
|
'Guten Tag',
|
|
|
|
'should match'
|
|
|
|
);
|
|
|
|
assert.deepEqual(
|
|
|
|
result,
|
|
|
|
videojs.options.languages[code.toLowerCase()],
|
|
|
|
'should also match'
|
|
|
|
);
|
2016-08-03 21:27:03 +02:00
|
|
|
});
|
2015-05-04 01:12:38 +02:00
|
|
|
|
2017-01-18 08:52:23 +02:00
|
|
|
QUnit.test('should expose plugin functions', function(assert) {
|
|
|
|
[
|
|
|
|
'registerPlugin',
|
|
|
|
'plugin',
|
|
|
|
'getPlugins',
|
|
|
|
'getPlugin',
|
|
|
|
'getPluginVersion'
|
|
|
|
].forEach(name => {
|
|
|
|
assert.strictEqual(typeof videojs[name], 'function', `videojs.${name} is a function`);
|
|
|
|
});
|
2015-05-04 01:12:38 +02:00
|
|
|
});
|
2015-07-30 18:10:04 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should expose options and players properties for backward-compatibility', function(assert) {
|
|
|
|
assert.ok(typeof videojs.options, 'object', 'options should be an object');
|
|
|
|
assert.ok(typeof videojs.players, 'object', 'players should be an object');
|
2015-07-30 18:10:04 +02:00
|
|
|
});
|
2015-11-10 00:43:17 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('should expose DOM functions', function(assert) {
|
2017-01-19 23:01:56 +02:00
|
|
|
const methods = [
|
|
|
|
'isEl',
|
|
|
|
'isTextNode',
|
|
|
|
'createEl',
|
|
|
|
'hasClass',
|
|
|
|
'addClass',
|
|
|
|
'removeClass',
|
|
|
|
'toggleClass',
|
|
|
|
'setAttributes',
|
|
|
|
'getAttributes',
|
|
|
|
'emptyEl',
|
|
|
|
'insertContent',
|
|
|
|
'appendContent'
|
|
|
|
];
|
|
|
|
|
|
|
|
methods.forEach(name => {
|
|
|
|
assert.strictEqual(typeof videojs[name], 'function', `function videojs.${name}`);
|
|
|
|
assert.strictEqual(typeof Dom[name], 'function', `Dom.${name} function exists`);
|
2015-11-10 00:43:17 +02:00
|
|
|
});
|
|
|
|
});
|
2016-12-19 18:51:42 +02:00
|
|
|
|
|
|
|
QUnit.test('ingest player div if data-vjs-player attribute is present on video parentNode', function(assert) {
|
|
|
|
const fixture = document.querySelector('#qunit-fixture');
|
|
|
|
|
|
|
|
fixture.innerHTML = `
|
|
|
|
<div data-vjs-player class="foo">
|
|
|
|
<video id="test_vid_id">
|
|
|
|
<source src="http://example.com/video.mp4" type="video/mp4"></source>
|
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
|
|
|
|
const playerDiv = document.querySelector('.foo');
|
|
|
|
const vid = document.querySelector('#test_vid_id');
|
|
|
|
|
|
|
|
const player = videojs(vid, {
|
|
|
|
techOrder: ['html5']
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(player.el(), playerDiv, 'we re-used the given div');
|
|
|
|
assert.ok(player.hasClass('foo'), 'keeps any classes that were around previously');
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('ingested player div should not create a new tag for movingMediaElementInDOM', function(assert) {
|
|
|
|
const Html5 = videojs.getTech('Html5');
|
|
|
|
const oldIS = Html5.isSupported;
|
|
|
|
const oldMoving = Html5.prototype.movingMediaElementInDOM;
|
|
|
|
const oldCPT = Html5.nativeSourceHandler.canPlayType;
|
|
|
|
const fixture = document.querySelector('#qunit-fixture');
|
|
|
|
|
|
|
|
fixture.innerHTML = `
|
|
|
|
<div data-vjs-player class="foo">
|
|
|
|
<video id="test_vid_id">
|
|
|
|
<source src="http://example.com/video.mp4" type="video/mp4"></source>
|
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
Html5.prototype.movingMediaElementInDOM = false;
|
|
|
|
Html5.isSupported = () => true;
|
|
|
|
Html5.nativeSourceHandler.canPlayType = () => true;
|
|
|
|
|
|
|
|
const playerDiv = document.querySelector('.foo');
|
|
|
|
const vid = document.querySelector('#test_vid_id');
|
|
|
|
|
|
|
|
const player = videojs(vid, {
|
|
|
|
techOrder: ['html5']
|
|
|
|
});
|
|
|
|
|
feat: middleware (#3788)
Add middleware support. Middleware can function as go-between between the player and the tech. For example, it can modify the duration that the tech returns to the player. In addition, middleware allow for supporting custom video sources and types.
Currently, middleware can only intercept timeline methods like duration, currentTime, and setCurrentTime.
For example,
```js
videojs.use('video/foo', {
setSource(src, next) {
next(null, {
src: 'http://example.com/video.mp4',
type: 'video/mp4'
});
}
});
```
Will allow you to set a source with type `video/foo` which will play back `video.mp4`.
This makes setting the source asynchronous, which aligns it with the spec a bit more. Methods like play can still be called synchronously on the player after setting the source and the player will play once the source has loaded.
`sourceOrder` option was removed as well and it will now always use source ordering.
BREAKING CHANGE: setting the source is now asynchronous. `sourceOrder` option removed and made the default.
2017-01-20 00:29:09 +02:00
|
|
|
this.clock.tick(1);
|
|
|
|
|
2016-12-19 18:51:42 +02:00
|
|
|
assert.equal(player.el(), playerDiv, 'we re-used the given div');
|
|
|
|
assert.equal(player.tech_.el(), vid, 'we re-used the video element');
|
|
|
|
assert.ok(player.hasClass('foo'), 'keeps any classes that were around previously');
|
|
|
|
|
|
|
|
Html5.prototype.movingMediaElementInDOM = oldMoving;
|
|
|
|
Html5.isSupported = oldIS;
|
|
|
|
Html5.nativeSourceHandler.canPlayType = oldCPT;
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('should create a new tag for movingMediaElementInDOM', function(assert) {
|
|
|
|
const Html5 = videojs.getTech('Html5');
|
|
|
|
const oldMoving = Html5.prototype.movingMediaElementInDOM;
|
|
|
|
const oldCPT = Html5.nativeSourceHandler.canPlayType;
|
|
|
|
const fixture = document.querySelector('#qunit-fixture');
|
|
|
|
const oldIS = Html5.isSupported;
|
|
|
|
|
|
|
|
fixture.innerHTML = `
|
|
|
|
<div class="foo">
|
|
|
|
<video id="test_vid_id">
|
|
|
|
<source src="http://example.com/video.mp4" type="video/mp4"></source>
|
|
|
|
</video>
|
|
|
|
</div>
|
|
|
|
`;
|
|
|
|
Html5.prototype.movingMediaElementInDOM = false;
|
|
|
|
Html5.isSupported = () => true;
|
|
|
|
Html5.nativeSourceHandler.canPlayType = () => true;
|
|
|
|
|
|
|
|
const playerDiv = document.querySelector('.foo');
|
|
|
|
const vid = document.querySelector('#test_vid_id');
|
|
|
|
|
|
|
|
const player = videojs(vid, {
|
|
|
|
techOrder: ['html5']
|
|
|
|
});
|
|
|
|
|
feat: middleware (#3788)
Add middleware support. Middleware can function as go-between between the player and the tech. For example, it can modify the duration that the tech returns to the player. In addition, middleware allow for supporting custom video sources and types.
Currently, middleware can only intercept timeline methods like duration, currentTime, and setCurrentTime.
For example,
```js
videojs.use('video/foo', {
setSource(src, next) {
next(null, {
src: 'http://example.com/video.mp4',
type: 'video/mp4'
});
}
});
```
Will allow you to set a source with type `video/foo` which will play back `video.mp4`.
This makes setting the source asynchronous, which aligns it with the spec a bit more. Methods like play can still be called synchronously on the player after setting the source and the player will play once the source has loaded.
`sourceOrder` option was removed as well and it will now always use source ordering.
BREAKING CHANGE: setting the source is now asynchronous. `sourceOrder` option removed and made the default.
2017-01-20 00:29:09 +02:00
|
|
|
this.clock.tick(1);
|
|
|
|
|
2016-12-19 18:51:42 +02:00
|
|
|
assert.notEqual(player.el(), playerDiv, 'we used a new div');
|
|
|
|
assert.notEqual(player.tech_.el(), vid, 'we a new video element');
|
|
|
|
|
|
|
|
Html5.prototype.movingMediaElementInDOM = oldMoving;
|
|
|
|
Html5.isSupported = oldIS;
|
|
|
|
Html5.nativeSourceHandler.canPlayType = oldCPT;
|
|
|
|
});
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-01-30 18:19:06 +02:00
|
|
|
QUnit.test('getPlayer', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
fixture.innerHTML += '<video-js id="test_vid_id"></video-js>';
|
|
|
|
|
|
|
|
assert.notOk(videojs.getPlayer('test_vid_id'), 'no player was created yet');
|
|
|
|
|
|
|
|
const tag = document.querySelector('#test_vid_id');
|
|
|
|
const player = videojs(tag);
|
|
|
|
|
|
|
|
assert.strictEqual(videojs.getPlayer('#test_vid_id'), player, 'the player was returned when using a jQuery-style ID selector');
|
|
|
|
assert.strictEqual(videojs.getPlayer('test_vid_id'), player, 'the player was returned when using a raw ID value');
|
|
|
|
assert.strictEqual(videojs.getPlayer(tag), player, 'the player was returned when using the original tag/element');
|
2018-02-22 21:22:12 +02:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('videojs() works with the tech id', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
fixture.innerHTML += '<video-js id="player"></video-js>';
|
|
|
|
|
|
|
|
const tag = document.querySelector('#player');
|
|
|
|
const player = videojs('#player', {techOrder: ['html5']});
|
|
|
|
|
|
|
|
assert.strictEqual(videojs('player_html5_api'), player, 'the player was returned for the tech id');
|
|
|
|
assert.strictEqual(videojs(tag), player, 'the player was returned when using the original tag/element');
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
|
|
|
QUnit.test('getPlayer works with the tech id', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
fixture.innerHTML += '<video-js id="player"></video-js>';
|
|
|
|
|
|
|
|
const tag = document.querySelector('#player');
|
|
|
|
const player = videojs('#player', {techOrder: ['html5']});
|
|
|
|
|
|
|
|
assert.strictEqual(videojs.getPlayer('player_html5_api'), player, 'the player was returned for the tech id');
|
|
|
|
assert.strictEqual(videojs.getPlayer(tag), player, 'the player was returned when using the original tag/element');
|
2018-01-30 18:19:06 +02:00
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2018-01-30 18:43:47 +02:00
|
|
|
QUnit.test('getAllPlayers', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
fixture.innerHTML += '<video id="test_vid_id"></video>' +
|
|
|
|
'<video id="test_vid_id2"></video>';
|
|
|
|
|
|
|
|
let all = videojs.getAllPlayers();
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(all), 'an array was returned');
|
|
|
|
assert.strictEqual(all.length, 0, 'the array was empty because no players have been created yet');
|
|
|
|
|
|
|
|
const player = videojs('test_vid_id');
|
|
|
|
const player2 = videojs('test_vid_id2');
|
|
|
|
|
|
|
|
all = videojs.getAllPlayers();
|
|
|
|
|
|
|
|
assert.ok(Array.isArray(all), 'an array was returned');
|
|
|
|
assert.strictEqual(all.length, 2, 'the array had two items');
|
|
|
|
assert.notStrictEqual(all.indexOf(player), -1, 'the first player was in the array');
|
|
|
|
assert.notStrictEqual(all.indexOf(player2), -1, 'the second player was in the array');
|
|
|
|
});
|
|
|
|
|
2017-11-13 21:20:05 +02:00
|
|
|
/* **************************************************** *
|
|
|
|
* div embed tests copied from video emebed tests above *
|
|
|
|
* **************************************************** */
|
2017-11-16 18:19:47 +02:00
|
|
|
QUnit.module('video.js video-js embed', {
|
|
|
|
beforeEach() {
|
|
|
|
this.clock = sinon.useFakeTimers();
|
|
|
|
},
|
|
|
|
afterEach() {
|
|
|
|
this.clock.restore();
|
2018-01-30 18:43:47 +02:00
|
|
|
videojs.getAllPlayers().forEach(p => p.dispose());
|
2017-11-16 18:19:47 +02:00
|
|
|
}
|
|
|
|
});
|
2018-01-30 18:43:47 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
QUnit.test('should return a video player instance', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
fixture.innerHTML += '<video-js id="test_vid_id"></video-js>' +
|
|
|
|
'<video-js id="test_vid_id2"></video-js>';
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const player = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(
|
|
|
|
videojs.getPlayers().test_vid_id === player,
|
|
|
|
'added player to global reference'
|
|
|
|
);
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const playerAgain = videojs('test_vid_id');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
|
|
|
});
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-05-23 03:44:35 +02:00
|
|
|
QUnit.test('should add video-js class to video-js embed if missing', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
fixture.innerHTML += '<video-js id="test_vid_id"></video-js>' +
|
|
|
|
'<video-js id="test_vid_id2" class="foo"></video-js>';
|
|
|
|
|
|
|
|
const player = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
|
|
|
|
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
|
|
|
assert.ok(player.hasClass('video-js'), 'we have the video-js class');
|
|
|
|
|
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
|
|
|
|
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
|
|
|
assert.ok(player2.hasClass('video-js'), 'we have the video-js class');
|
|
|
|
assert.ok(player2.hasClass('foo'), 'we have the foo class');
|
|
|
|
});
|
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
QUnit.test(
|
|
|
|
'should log about already initalized players if options already passed',
|
|
|
|
function(assert) {
|
|
|
|
const origWarnLog = log.warn;
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
const warnLogs = [];
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
log.warn = (args) => {
|
|
|
|
warnLogs.push(args);
|
|
|
|
};
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
fixture.innerHTML += '<video-js id="test_vid_id"></video-js>';
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
const player = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.equal(player.id(), 'test_vid_id', 'player has the right ID');
|
|
|
|
assert.equal(warnLogs.length, 0, 'no warn logs');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
const playerAgain = videojs('test_vid_id');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(player, playerAgain, 'did not create a second player from same tag');
|
|
|
|
assert.equal(warnLogs.length, 0, 'no warn logs');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
const playerAgainWithOptions = videojs('test_vid_id', { techOrder: ['techFaker'] });
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.equal(
|
|
|
|
player,
|
|
|
|
playerAgainWithOptions,
|
|
|
|
'did not create a second player from same tag'
|
|
|
|
);
|
|
|
|
assert.equal(warnLogs.length, 1, 'logged a warning');
|
|
|
|
assert.equal(
|
|
|
|
warnLogs[0],
|
|
|
|
'Player "test_vid_id" is already initialised. Options will not be applied.',
|
|
|
|
'logged the right message'
|
|
|
|
);
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2018-09-28 20:58:15 +02:00
|
|
|
log.warn = origWarnLog;
|
|
|
|
}
|
|
|
|
);
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
QUnit.test('should return a video player instance from el html5 tech', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
fixture.innerHTML += '<video-js id="test_vid_id"></video-js>' +
|
|
|
|
'<video-js id="test_vid_id2"></video-js>';
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const vid = document.querySelector('#test_vid_id');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const player = videojs(vid);
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(
|
|
|
|
videojs.getPlayers().test_vid_id === player,
|
|
|
|
'added player to global reference'
|
|
|
|
);
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const playerAgain = videojs(vid);
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
|
|
|
});
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
QUnit.test('should return a video player instance from el techfaker', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
fixture.innerHTML += '<video-js id="test_vid_id"></video-js>' +
|
|
|
|
'<video-js id="test_vid_id2"></video-js>';
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const vid = document.querySelector('#test_vid_id');
|
|
|
|
const player = videojs(vid, {techOrder: ['techFaker']});
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player, 'created player from tag');
|
|
|
|
assert.ok(player.id() === 'test_vid_id');
|
2018-09-28 20:58:15 +02:00
|
|
|
assert.ok(
|
|
|
|
videojs.getPlayers().test_vid_id === player,
|
|
|
|
'added player to global reference'
|
|
|
|
);
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const playerAgain = videojs(vid);
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player === playerAgain, 'did not create a second player from same tag');
|
|
|
|
assert.equal(player, playerAgain, 'we did not make a new player');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player2.id() === 'test_vid_id2', 'created player from element');
|
|
|
|
});
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
QUnit.test('adds video-js class name with the video-js embed', function(assert) {
|
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
fixture.innerHTML += '<video-js id="test_vid_id"></video-js>' +
|
|
|
|
'<video-js class="video-js" id="test_vid_id2"></video-js>';
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
const vid = document.querySelector('#test_vid_id');
|
|
|
|
const player = videojs(vid, {techOrder: ['techFaker']});
|
|
|
|
const tag2 = document.getElementById('test_vid_id2');
|
|
|
|
const player2 = videojs(tag2, { techOrder: ['techFaker'] });
|
2017-11-13 21:20:05 +02:00
|
|
|
|
2017-11-16 18:19:47 +02:00
|
|
|
assert.ok(player.hasClass('video-js'), 'video-js class was added to the first embed');
|
|
|
|
assert.ok(player2.hasClass('video-js'), 'video-js class was preserved to the second embed');
|
|
|
|
});
|
2022-05-18 16:59:17 +02:00
|
|
|
|
2022-05-20 19:21:14 +02:00
|
|
|
let testOrSkip = 'test';
|
|
|
|
|
|
|
|
// The following test uses some DocumentFragment properties that are not
|
|
|
|
// available in IE or older Safaris, so we skip it.
|
|
|
|
if (videojs.browser.IE_VERSION || videojs.browser.IS_ANY_SAFARI) {
|
|
|
|
testOrSkip = 'skip';
|
|
|
|
}
|
|
|
|
|
|
|
|
QUnit[testOrSkip]('stores placeholder el and restores on dispose', function(assert) {
|
2022-05-18 16:59:17 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
|
|
|
const embeds = [
|
|
|
|
{
|
|
|
|
type: 'video el',
|
|
|
|
src: '<video id="test1"><source src="http://example.com/video.mp4" type="video/mp4"></source></video>',
|
|
|
|
initSelector: 'test1',
|
|
|
|
testSelector: '#test1'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'video-js el',
|
|
|
|
src: '<video-js id="test2"><source src="http://example.com/video.mp4" type="video/mp4"></source></video-js>',
|
|
|
|
initSelector: 'test2',
|
|
|
|
testSelector: '#test2'
|
|
|
|
},
|
|
|
|
{
|
|
|
|
type: 'div ingest',
|
|
|
|
src: '<div data-vjs-player><video id="test3"><source src="http://example.com/video.mp4" type="video/mp4"></source></video></div>',
|
|
|
|
initSelector: 'test3',
|
|
|
|
testSelector: 'div[data-vjs-player]'
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
|
|
|
embeds.forEach(embed => {
|
|
|
|
const comparisonEl = document.createRange().createContextualFragment(embed.src).children[0];
|
|
|
|
|
|
|
|
fixture.innerHTML += embed.src;
|
|
|
|
|
|
|
|
const player = videojs(embed.initSelector, {restoreEl: true});
|
|
|
|
|
|
|
|
assert.ok(comparisonEl.isEqualNode(player.options_.restoreEl), `${embed.type}: restoreEl option replaced by an element`);
|
|
|
|
assert.notOk(document.querySelector(embed.testSelector).isSameNode(player.options_.restoreEl), `${embed.type}: restoreEl is not the original element`);
|
|
|
|
assert.notOk(comparisonEl.isSameNode(player.options_.restoreEl), `${embed.type}: restoreEl is not the control element`);
|
|
|
|
|
|
|
|
player.dispose();
|
|
|
|
|
|
|
|
const expectedEl = document.querySelector(embed.testSelector);
|
|
|
|
|
|
|
|
assert.ok(comparisonEl.isEqualNode(expectedEl), `${embed.type}: element was restored`);
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|