2016-08-03 21:27:03 +02:00
|
|
|
/* eslint-env qunit */
|
2016-04-22 20:31:12 +02:00
|
|
|
import Html5 from '../../../src/js/tech/html5.js';
|
|
|
|
import TestHelpers from '../test-helpers.js';
|
2016-08-03 21:27:03 +02:00
|
|
|
import sinon from 'sinon';
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
QUnit.module('Video Tracks', {
|
2016-08-12 19:51:31 +02:00
|
|
|
beforeEach(assert) {
|
2016-04-22 20:31:12 +02:00
|
|
|
this.clock = sinon.useFakeTimers();
|
|
|
|
},
|
2016-08-12 19:51:31 +02:00
|
|
|
afterEach(assert) {
|
2016-04-22 20:31:12 +02:00
|
|
|
this.clock.restore();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('Player track methods call the tech', function(assert) {
|
2016-04-22 20:31:12 +02:00
|
|
|
let calls = 0;
|
2016-08-03 21:27:03 +02:00
|
|
|
const player = TestHelpers.makePlayer();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
player.tech_.videoTracks = function() {
|
|
|
|
calls++;
|
|
|
|
};
|
|
|
|
|
|
|
|
player.videoTracks();
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(calls, 1, 'videoTrack defers to the tech');
|
2016-04-22 20:31:12 +02:00
|
|
|
player.dispose();
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('listen to remove and add track events in native video tracks', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const oldTestVid = Html5.TEST_VID;
|
|
|
|
const oldVideoTracks = Html5.prototype.videoTracks;
|
|
|
|
const events = {};
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
Html5.prototype.videoTracks = function() {
|
|
|
|
return {
|
2018-01-30 20:26:21 +02:00
|
|
|
removeEventListener() {},
|
2016-04-22 20:31:12 +02:00
|
|
|
addEventListener(type, handler) {
|
|
|
|
events[type] = true;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
Html5.TEST_VID = {
|
|
|
|
videoTracks: []
|
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const player = {
|
2016-04-22 20:31:12 +02:00
|
|
|
// Function.prototype is a built-in no-op function.
|
|
|
|
controls() {},
|
|
|
|
ready() {},
|
|
|
|
options() {
|
|
|
|
return {};
|
|
|
|
},
|
|
|
|
addChild() {},
|
|
|
|
id() {},
|
|
|
|
el() {
|
|
|
|
return {
|
|
|
|
insertBefore() {},
|
|
|
|
appendChild() {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2016-08-03 21:27:03 +02:00
|
|
|
|
2016-04-22 20:31:12 +02:00
|
|
|
player.player_ = player;
|
2016-08-03 21:27:03 +02:00
|
|
|
player.options_ = {};
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const html = new Html5({});
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(events.removetrack, 'removetrack listener was added');
|
|
|
|
assert.ok(events.addtrack, 'addtrack listener was added');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
Html5.TEST_VID = oldTestVid;
|
|
|
|
Html5.prototype.videoTracks = oldVideoTracks;
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
html.dispose();
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('html5 tech supports native video tracks if the video supports it', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const oldTestVid = Html5.TEST_VID;
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
Html5.TEST_VID = {
|
|
|
|
videoTracks: []
|
|
|
|
};
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(Html5.supportsNativeVideoTracks(), 'native video tracks are supported');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
Html5.TEST_VID = oldTestVid;
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('html5 tech does not support native video tracks if the video does not supports it', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const oldTestVid = Html5.TEST_VID;
|
|
|
|
|
2016-04-22 20:31:12 +02:00
|
|
|
Html5.TEST_VID = {};
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(!Html5.supportsNativeVideoTracks(), 'native video tracks are not supported');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
Html5.TEST_VID = oldTestVid;
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('when switching techs, we should not get a new video track', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const player = TestHelpers.makePlayer();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
player.loadTech_('TechFaker');
|
2016-08-03 21:27:03 +02:00
|
|
|
const firstTracks = player.videoTracks();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
player.loadTech_('TechFaker');
|
2016-08-03 21:27:03 +02:00
|
|
|
const secondTracks = player.videoTracks();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(firstTracks === secondTracks, 'the tracks are equal');
|
2016-08-25 16:58:42 +02:00
|
|
|
|
|
|
|
player.dispose();
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|