2016-08-03 21:27:47 +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:47 +02:00
|
|
|
import sinon from 'sinon';
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2017-03-02 22:22:59 +02:00
|
|
|
QUnit.module('Audio 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-08-03 21:27:47 +02:00
|
|
|
const player = TestHelpers.makePlayer();
|
2016-04-22 20:31:12 +02:00
|
|
|
let calls = 0;
|
|
|
|
|
|
|
|
player.tech_.audioTracks = function() {
|
|
|
|
calls++;
|
|
|
|
};
|
|
|
|
|
|
|
|
player.audioTracks();
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(calls, 1, 'audioTrack 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 audio tracks', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const oldTestVid = Html5.TEST_VID;
|
|
|
|
const oldAudioTracks = Html5.prototype.audioTracks;
|
|
|
|
const events = {};
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
Html5.prototype.audioTracks = 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 = {
|
|
|
|
audioTracks: []
|
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:47 +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:47 +02:00
|
|
|
|
2016-04-22 20:31:12 +02:00
|
|
|
player.player_ = player;
|
2016-08-03 21:27:47 +02:00
|
|
|
player.options_ = {};
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2016-08-03 21:27:47 +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.audioTracks = oldAudioTracks;
|
2018-01-30 20:26:21 +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 audio tracks if the video supports it', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const oldTestVid = Html5.TEST_VID;
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
Html5.TEST_VID = {
|
|
|
|
audioTracks: []
|
|
|
|
};
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.ok(Html5.supportsNativeAudioTracks(), 'native audio 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 audio tracks if the video does not supports it', function(assert) {
|
2016-08-03 21:27:47 +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.supportsNativeAudioTracks(), 'native audio 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 audio track', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const player = TestHelpers.makePlayer();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
player.loadTech_('TechFaker');
|
2016-08-03 21:27:47 +02:00
|
|
|
const firstTracks = player.audioTracks();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
player.loadTech_('TechFaker');
|
2016-08-03 21:27:47 +02:00
|
|
|
const secondTracks = player.audioTracks();
|
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
|
|
|
});
|