1
0
mirror of https://github.com/videojs/video.js.git synced 2024-12-12 11:15:04 +02:00
video.js/test/unit/videojs-integration.test.js
2019-08-01 14:26:59 -04:00

85 lines
2.4 KiB
JavaScript

/* eslint-env qunit */
import videojs from '../../src/js/video.js';
import window from 'global/window';
import document from 'global/document';
import * as Fn from '../../src/js/utils/fn';
/**
* This test is very important for dom-data memory checking
* as it runs through a basic player lifecycle for real.
*/
QUnit.test('create a real player and dispose', function(assert) {
assert.timeout(30000);
const done = assert.async();
const fixture = document.getElementById('qunit-fixture');
const old = {};
// TODO: remove this code when we have a videojs debug build
// see https://github.com/videojs/video.js/issues/5858
old.bind = Fn.bind;
Fn.bind = function(context, fn, uid) {
const retval = old.bind(context, fn, uid);
retval.og_ = fn.og_ || fn;
retval.cx_ = fn.cx_ || context;
return retval;
};
old.throttle = Fn.throttle;
Fn.throttle = function(fn, wait) {
const retval = old.throttle(fn, wait);
retval.og_ = fn.og_ || fn;
retval.cx_ = fn.cx_;
return retval;
};
old.debounce = Fn.debounce;
Fn.debounce = function(func, wait, immediate, context = window) {
const retval = old.debounce(func, wait, immediate, context);
retval.og_ = func.og_ || func;
retval.cx_ = func.cx_;
return retval;
};
// TODO: use a local source rather than a remote one
fixture.innerHTML = `
<video-js
id="vid1"
controls
preload="auto"
width="640"
height="264"
poster="http://vjs.zencdn.net/v/oceans.png">
<source src="http://vjs.zencdn.net/v/oceans.mp4" type="video/mp4">
<source src="http://vjs.zencdn.net/v/oceans.webm" type="video/webm">
<source src="http://vjs.zencdn.net/v/oceans.ogv" type="video/ogg">
<track kind="captions" src="../docs/examples/shared/example-captions.vtt" srclang="en" label="English">
<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p>
</video-js>
`.trim();
const player = videojs('vid1', {techOrder: ['html5']});
player.muted(true);
player.addTextTrack('captions', 'foo', 'en');
player.ready(function() {
assert.ok(player.tech_, 'tech exists');
assert.equal(player.textTracks().length, 1, 'should have one text track');
player.dispose();
Object.keys(old).forEach(function(k) {
Fn[k] = old[k];
});
done();
}, true);
});