2016-08-03 21:27:47 +02:00
|
|
|
/* eslint-env qunit */
|
2015-03-26 06:43:41 +02:00
|
|
|
import TextTrackList from '../../../src/js/tracks/text-track-list.js';
|
|
|
|
import TextTrack from '../../../src/js/tracks/text-track.js';
|
2015-07-30 20:11:31 +02:00
|
|
|
import EventTarget from '../../../src/js/event-target.js';
|
2017-03-02 21:35:45 +02:00
|
|
|
import TechFaker from '../tech/tech-faker';
|
2018-07-25 23:33:30 +02:00
|
|
|
import sinon from 'sinon';
|
|
|
|
|
|
|
|
QUnit.module('Text Track List', {
|
|
|
|
beforeEach() {
|
|
|
|
this.clock = sinon.useFakeTimers();
|
|
|
|
},
|
|
|
|
afterEach() {
|
|
|
|
this.clock.restore();
|
|
|
|
}
|
|
|
|
});
|
2015-03-26 06:43:41 +02:00
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('trigger "change" event when "modechange" is fired on a track', function(assert) {
|
2016-08-03 21:27:47 +02:00
|
|
|
const tt = new EventTarget();
|
|
|
|
const ttl = new TextTrackList([tt]);
|
2016-03-07 21:54:32 +02:00
|
|
|
let changes = 0;
|
2016-08-03 21:27:47 +02:00
|
|
|
const changeHandler = function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
changes++;
|
|
|
|
};
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttl.on('change', changeHandler);
|
|
|
|
tt.trigger('modechange');
|
2018-07-25 23:33:30 +02:00
|
|
|
this.clock.tick(1);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttl.off('change', changeHandler);
|
|
|
|
ttl.onchange = changeHandler;
|
|
|
|
|
|
|
|
tt.trigger('modechange');
|
2018-07-25 23:33:30 +02:00
|
|
|
this.clock.tick(1);
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(changes, 2, 'two change events should have fired');
|
2019-03-18 21:49:48 +02:00
|
|
|
|
|
|
|
ttl.removeTrack(tt);
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('trigger "change" event when mode changes on a TextTrack', function(assert) {
|
2019-03-18 21:49:48 +02:00
|
|
|
const tech = new TechFaker();
|
|
|
|
const tt = new TextTrack({tech});
|
2016-08-03 21:27:47 +02:00
|
|
|
const ttl = new TextTrackList([tt]);
|
2016-03-07 21:54:32 +02:00
|
|
|
let changes = 0;
|
2016-08-03 21:27:47 +02:00
|
|
|
const changeHandler = function() {
|
2016-03-07 21:54:32 +02:00
|
|
|
changes++;
|
|
|
|
};
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttl.on('change', changeHandler);
|
|
|
|
tt.mode = 'showing';
|
2018-07-25 23:33:30 +02:00
|
|
|
this.clock.tick(1);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
|
|
|
ttl.off('change', changeHandler);
|
|
|
|
ttl.onchange = changeHandler;
|
|
|
|
|
|
|
|
tt.mode = 'hidden';
|
|
|
|
tt.mode = 'disabled';
|
2018-07-25 23:33:30 +02:00
|
|
|
this.clock.tick(1);
|
2015-02-14 01:18:07 +02:00
|
|
|
|
2018-07-25 23:33:30 +02:00
|
|
|
assert.equal(changes, 2, 'two change events should have fired');
|
2019-03-18 21:49:48 +02:00
|
|
|
ttl.removeTrack(tt);
|
|
|
|
tech.dispose();
|
2015-02-14 01:18:07 +02:00
|
|
|
});
|