2015-10-28 19:28:15 +02:00
|
|
|
import * as Dom from '../../src/js/utils/dom';
|
2015-03-26 06:43:41 +02:00
|
|
|
import Player from '../../src/js/player.js';
|
|
|
|
import document from 'global/document';
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const TestHelpers = {
|
|
|
|
makeTag() {
|
|
|
|
const videoTag = document.createElement('video');
|
|
|
|
|
2013-06-24 22:47:47 +03:00
|
|
|
videoTag.id = 'example_1';
|
|
|
|
videoTag.className = 'video-js vjs-default-skin';
|
|
|
|
return videoTag;
|
|
|
|
},
|
2015-03-26 06:43:41 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
makePlayer(playerOptions, videoTag) {
|
2015-03-26 06:43:41 +02:00
|
|
|
videoTag = videoTag || TestHelpers.makeTag();
|
2013-06-24 22:47:47 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const fixture = document.getElementById('qunit-fixture');
|
|
|
|
|
2013-06-24 22:47:47 +03:00
|
|
|
fixture.appendChild(videoTag);
|
|
|
|
|
|
|
|
playerOptions = playerOptions || {};
|
2016-08-03 21:27:03 +02:00
|
|
|
playerOptions.techOrder = playerOptions.techOrder || ['techFaker'];
|
2013-06-24 22:47:47 +03:00
|
|
|
|
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
|
|
|
const player = new Player(videoTag, playerOptions);
|
|
|
|
|
|
|
|
player.middleware_ = [player.tech_];
|
|
|
|
|
|
|
|
return player;
|
2015-03-26 06:43:41 +02:00
|
|
|
},
|
2014-10-16 22:59:41 +03:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
getComputedStyle(el, rule) {
|
2015-05-17 00:59:46 +02:00
|
|
|
if (document.defaultView && document.defaultView.getComputedStyle) {
|
|
|
|
return document.defaultView.getComputedStyle(el, null).getPropertyValue(rule);
|
|
|
|
}
|
2014-10-16 22:59:41 +03:00
|
|
|
|
2018-03-23 19:25:12 +02:00
|
|
|
return '';
|
2015-10-28 19:28:15 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Runs a range of assertions on a DOM element.
|
|
|
|
*
|
|
|
|
* @param {QUnit.Assert} assert
|
|
|
|
* @param {Element} el
|
|
|
|
* @param {Object} spec
|
|
|
|
* An object from which assertions are generated.
|
|
|
|
*
|
|
|
|
* @param {Object} [spec.attrs]
|
|
|
|
* An object mapping attribute names (keys) to strict values.
|
|
|
|
*
|
|
|
|
* @param {Array} [spec.classes]
|
|
|
|
* An array of classes that are expected on the element.
|
|
|
|
*
|
|
|
|
* @param {String} [spec.innerHTML]
|
|
|
|
* A string of text/html that is expected as the content of element.
|
|
|
|
* Both values will be trimmed, but remains case-sensitive.
|
|
|
|
*
|
|
|
|
* @param {Object} [spec.props]
|
|
|
|
* An object mapping property names (keys) to strict values.
|
|
|
|
*
|
|
|
|
* @param {String} [spec.tagName]
|
|
|
|
* A string (case-insensitive) representing that element's tagName.
|
|
|
|
*
|
|
|
|
* @return {Function}
|
|
|
|
* Invoke the returned function to run the assertions. This
|
|
|
|
* function has a `count` property which can be used to
|
|
|
|
* reference how many assertions will be run (e.g. for use
|
|
|
|
* with `assert.expect()`).
|
|
|
|
*/
|
2016-08-03 21:27:03 +02:00
|
|
|
assertEl(assert, el, spec) {
|
|
|
|
const attrs = spec.attrs ? Object.keys(spec.attrs) : [];
|
|
|
|
const classes = spec.classes || [];
|
|
|
|
const innerHTML = spec.innerHTML ? spec.innerHTML.trim() : '';
|
|
|
|
const props = spec.props ? Object.keys(spec.props) : [];
|
|
|
|
const tagName = spec.tagName ? spec.tagName.toLowerCase() : '';
|
2015-10-28 19:28:15 +02:00
|
|
|
|
|
|
|
// Return value is a function, which runs through all the combined
|
|
|
|
// assertions. This is done so that the count can be attached dynamically
|
|
|
|
// and run whenever desired.
|
2016-08-03 21:27:03 +02:00
|
|
|
const run = () => {
|
2015-10-28 19:28:15 +02:00
|
|
|
if (tagName) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const elTagName = el.tagName.toLowerCase();
|
|
|
|
const msg = `el should have been a <${tagName}> and was a <${elTagName}>`;
|
|
|
|
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.strictEqual(elTagName, tagName, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (innerHTML) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const elInnerHTML = el.innerHTML.trim();
|
|
|
|
const msg = 'el should have expected HTML content';
|
|
|
|
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.strictEqual(elInnerHTML, innerHTML, msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
attrs.forEach(a => {
|
2016-08-03 21:27:03 +02:00
|
|
|
const actual = el.getAttribute(a);
|
|
|
|
const expected = spec.attrs[a];
|
|
|
|
const msg = `el should have the "${a}" attribute with ` +
|
|
|
|
`the value "${expected}" and it was "${actual}"`;
|
|
|
|
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.strictEqual(actual, expected, msg);
|
|
|
|
});
|
|
|
|
|
|
|
|
classes.forEach(c => {
|
2016-08-03 21:27:03 +02:00
|
|
|
const msg = `el should have the "${c}" class in its ` +
|
|
|
|
`className, which is "${el.className}"`;
|
|
|
|
|
2017-01-19 23:01:56 +02:00
|
|
|
assert.ok(Dom.hasClass(el, c), msg);
|
2015-10-28 19:28:15 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
props.forEach(p => {
|
2016-08-03 21:27:03 +02:00
|
|
|
const actual = el[p];
|
|
|
|
const expected = spec.props[p];
|
|
|
|
const msg = `el should have the "${p}" property with the ` +
|
|
|
|
`value "${expected}" and it was "${actual}"`;
|
|
|
|
|
2015-10-28 19:28:15 +02:00
|
|
|
assert.strictEqual(actual, expected, msg);
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
// Include the number of assertions to run, so it can be used to set
|
|
|
|
// expectations (via `assert.expect()`).
|
2016-08-03 21:27:03 +02:00
|
|
|
run.count = Number(!!tagName) +
|
2015-10-28 19:28:15 +02:00
|
|
|
Number(!!innerHTML) +
|
|
|
|
classes.length +
|
|
|
|
attrs.length +
|
|
|
|
props.length;
|
|
|
|
|
|
|
|
return run;
|
2016-11-23 20:54:48 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Triggers an event on a DOM node natively.
|
|
|
|
*
|
|
|
|
* @param {Element} element
|
|
|
|
* @param {string} eventType
|
|
|
|
*/
|
|
|
|
triggerDomEvent(element, eventType) {
|
2016-12-02 21:17:36 +02:00
|
|
|
let event;
|
|
|
|
|
|
|
|
if (document.createEvent) {
|
|
|
|
event = document.createEvent('HTMLEvents');
|
|
|
|
event.initEvent(eventType, true, true);
|
|
|
|
} else {
|
|
|
|
event = document.createEventObject();
|
|
|
|
event.eventType = eventType;
|
|
|
|
}
|
|
|
|
|
|
|
|
event.eventName = eventType;
|
|
|
|
|
|
|
|
if (document.createEvent) {
|
|
|
|
element.dispatchEvent(event);
|
|
|
|
} else {
|
|
|
|
element.fireEvent('on' + event.eventType, event);
|
2016-11-23 20:54:48 +02:00
|
|
|
}
|
2014-10-16 22:59:41 +03:00
|
|
|
}
|
|
|
|
};
|
2015-03-26 06:43:41 +02:00
|
|
|
|
2015-05-04 01:12:38 +02:00
|
|
|
export default TestHelpers;
|