2016-08-03 21:27:47 +02:00
|
|
|
/* eslint-env qunit */
|
2016-04-22 20:31:12 +02:00
|
|
|
import AudioTrackList from '../../../src/js/tracks/audio-track-list.js';
|
|
|
|
import AudioTrack from '../../../src/js/tracks/audio-track.js';
|
|
|
|
import EventTarget from '../../../src/js/event-target.js';
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.module('Audio Track List');
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('trigger "change" when "enabledchange" is fired on a track', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const track = new EventTarget();
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.loaded_ = true;
|
2016-08-03 21:27:47 +02:00
|
|
|
const audioTrackList = new AudioTrackList([track]);
|
2016-04-22 20:31:12 +02:00
|
|
|
let changes = 0;
|
2016-08-03 21:27:47 +02:00
|
|
|
const changeHandler = function() {
|
2016-04-22 20:31:12 +02:00
|
|
|
changes++;
|
|
|
|
};
|
2016-08-03 21:27:47 +02:00
|
|
|
|
2016-04-22 20:31:12 +02:00
|
|
|
audioTrackList.on('change', changeHandler);
|
|
|
|
track.trigger('enabledchange');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(changes, 1, 'one change events for trigger');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
audioTrackList.off('change', changeHandler);
|
|
|
|
audioTrackList.onchange = changeHandler;
|
|
|
|
|
|
|
|
track.trigger('enabledchange');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(changes, 2, 'one change events for another trigger');
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
audioTrackList.removeTrack(track);
|
|
|
|
audioTrackList.off('change');
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('only one track is ever enabled', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const track = new AudioTrack({enabled: true});
|
|
|
|
const track2 = new AudioTrack({enabled: true});
|
|
|
|
const track3 = new AudioTrack({enabled: true});
|
|
|
|
const track4 = new AudioTrack();
|
|
|
|
const list = new AudioTrackList([track, track2]);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, false, 'track is disabled');
|
|
|
|
assert.equal(track2.enabled, true, 'track2 is enabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, true, 'track is enabled');
|
|
|
|
assert.equal(track2.enabled, false, 'track2 is disabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2017-01-19 22:16:28 +02:00
|
|
|
list.addTrack(track3);
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, false, 'track is disabled');
|
|
|
|
assert.equal(track2.enabled, false, 'track2 is disabled');
|
|
|
|
assert.equal(track3.enabled, true, 'track3 is enabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2019-03-25 18:02:33 +02:00
|
|
|
track2.enabled = true;
|
|
|
|
assert.equal(track.enabled, false, 'track is disabled');
|
|
|
|
assert.equal(track2.enabled, true, 'track2 is enabled');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track3.enabled, false, 'track3 is disabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2017-01-19 22:16:28 +02:00
|
|
|
list.addTrack(track4);
|
2019-03-25 18:02:33 +02:00
|
|
|
assert.equal(track.enabled, false, 'track is disabled');
|
|
|
|
assert.equal(track2.enabled, true, 'track2 is enabled');
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track3.enabled, false, 'track3 is disabled');
|
|
|
|
assert.equal(track4.enabled, false, 'track4 is disabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2019-03-18 21:49:48 +02:00
|
|
|
list.removeTrack(track);
|
|
|
|
list.removeTrack(track2);
|
|
|
|
list.removeTrack(track3);
|
|
|
|
list.removeTrack(track4);
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('all tracks can be disabled', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const track = new AudioTrack();
|
|
|
|
const track2 = new AudioTrack();
|
|
|
|
|
|
|
|
// we need audiotracklist here to verify that it does not
|
|
|
|
// re-enable a track
|
|
|
|
const list = new AudioTrackList([track, track2]);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, false, 'track is disabled');
|
|
|
|
assert.equal(track2.enabled, false, 'track2 is disabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, true, 'track is enabled');
|
|
|
|
assert.equal(track2.enabled, false, 'track2 is disabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = false;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(track.enabled, false, 'track is disabled');
|
|
|
|
assert.equal(track2.enabled, false, 'track2 is disabled');
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
list.removeTrack(track);
|
|
|
|
list.removeTrack(track2);
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('trigger a change event per enabled change', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const track = new AudioTrack({enabled: true});
|
|
|
|
const track2 = new AudioTrack({enabled: true});
|
|
|
|
const track3 = new AudioTrack({enabled: true});
|
|
|
|
const track4 = new AudioTrack();
|
|
|
|
const list = new AudioTrackList([track, track2]);
|
2016-04-22 20:31:12 +02:00
|
|
|
let change = 0;
|
2016-08-03 21:27:47 +02:00
|
|
|
|
2016-04-22 20:31:12 +02:00
|
|
|
list.on('change', () => change++);
|
|
|
|
track.enabled = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(change, 1, 'one change triggered');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2017-01-19 22:16:28 +02:00
|
|
|
list.addTrack(track3);
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(change, 2, 'another change triggered by adding an enabled track');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = true;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(change, 3, 'another change trigger by changing enabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
|
|
|
track.enabled = false;
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(change, 4, 'another change trigger by changing enabled');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2017-01-19 22:16:28 +02:00
|
|
|
list.addTrack(track4);
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(change, 4, 'no change triggered by adding a disabled track');
|
2016-04-22 20:31:12 +02:00
|
|
|
|
2019-03-18 21:49:48 +02:00
|
|
|
list.removeTrack(track);
|
|
|
|
list.removeTrack(track2);
|
|
|
|
list.removeTrack(track3);
|
|
|
|
list.removeTrack(track4);
|
|
|
|
list.off();
|
2016-04-22 20:31:12 +02:00
|
|
|
});
|