2016-08-03 21:27:47 +02:00
|
|
|
/* eslint-env qunit */
|
2015-08-03 21:19:36 +02:00
|
|
|
import c from '../../../src/js/tracks/text-track-list-converter.js';
|
|
|
|
import TextTrack from '../../../src/js/tracks/text-track.js';
|
|
|
|
import TextTrackList from '../../../src/js/tracks/text-track-list.js';
|
|
|
|
import Html5 from '../../../src/js/tech/html5.js';
|
|
|
|
import document from 'global/document';
|
|
|
|
|
2016-08-03 21:27:47 +02:00
|
|
|
QUnit.module('Text Track List Converter', {});
|
2015-08-03 21:19:36 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const clean = (item) => {
|
2015-08-03 21:19:36 +02:00
|
|
|
delete item.id;
|
|
|
|
delete item.inBandMetadataTrackDispatchType;
|
2015-08-13 01:04:31 +02:00
|
|
|
delete item.cues;
|
2015-08-03 21:19:36 +02:00
|
|
|
};
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const cleanup = (item) => {
|
2015-08-03 21:19:36 +02:00
|
|
|
if (Array.isArray(item)) {
|
|
|
|
item.forEach(clean);
|
|
|
|
} else {
|
|
|
|
clean(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Html5.supportsNativeTextTracks()) {
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('trackToJson_ produces correct representation for native track object', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const track = document.createElement('track');
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-10-27 21:54:48 +02:00
|
|
|
track.src = 'example.com/english.vtt';
|
2015-08-03 21:19:36 +02:00
|
|
|
track.kind = 'captions';
|
|
|
|
track.srclang = 'en';
|
|
|
|
track.label = 'English';
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.deepEqual(cleanup(c.trackToJson_(track.track)), {
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
2015-08-13 01:04:31 +02:00
|
|
|
mode: 'disabled'
|
2015-08-03 21:19:36 +02:00
|
|
|
}, 'the json output is same');
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('textTracksToJson produces good json output', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const emulatedTrack = new TextTrack({
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
|
|
|
tech: {}
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const nativeTrack = document.createElement('track');
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
nativeTrack.kind = 'captions';
|
|
|
|
nativeTrack.srclang = 'es';
|
|
|
|
nativeTrack.label = 'Spanish';
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tt = new TextTrackList();
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2017-01-19 22:16:28 +02:00
|
|
|
tt.addTrack(nativeTrack.track);
|
|
|
|
tt.addTrack(emulatedTrack);
|
2015-08-03 21:19:36 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tech = {
|
2015-11-10 22:30:09 +02:00
|
|
|
$$() {
|
|
|
|
return [nativeTrack];
|
|
|
|
},
|
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
el() {
|
|
|
|
return {
|
|
|
|
querySelectorAll() {
|
|
|
|
return [nativeTrack];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
textTracks() {
|
|
|
|
return tt;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.deepEqual(cleanup(c.textTracksToJson(tech)), [{
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'Spanish',
|
|
|
|
language: 'es',
|
2015-08-13 01:04:31 +02:00
|
|
|
mode: 'disabled'
|
2015-08-03 21:19:36 +02:00
|
|
|
}, {
|
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
2015-08-13 01:04:31 +02:00
|
|
|
mode: 'disabled'
|
2015-08-03 21:19:36 +02:00
|
|
|
}], 'the output is correct');
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('jsonToTextTracks calls addRemoteTextTrack on the tech with mixed tracks', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const emulatedTrack = new TextTrack({
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/english.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
tech: {}
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const nativeTrack = document.createElement('track');
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2015-10-27 21:54:48 +02:00
|
|
|
nativeTrack.src = 'example.com/spanish.vtt';
|
2015-08-03 21:19:36 +02:00
|
|
|
nativeTrack.kind = 'captions';
|
|
|
|
nativeTrack.srclang = 'es';
|
|
|
|
nativeTrack.label = 'Spanish';
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tt = new TextTrackList();
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2017-01-19 22:16:28 +02:00
|
|
|
tt.addTrack(nativeTrack.track);
|
|
|
|
tt.addTrack(emulatedTrack);
|
2015-08-03 21:19:36 +02:00
|
|
|
|
|
|
|
let addRemotes = 0;
|
2016-08-03 21:27:03 +02:00
|
|
|
const tech = {
|
2015-11-10 22:30:09 +02:00
|
|
|
$$() {
|
|
|
|
return [nativeTrack];
|
|
|
|
},
|
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
el() {
|
|
|
|
return {
|
|
|
|
querySelectorAll() {
|
|
|
|
return [nativeTrack];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
textTracks() {
|
|
|
|
return tt;
|
|
|
|
},
|
|
|
|
addRemoteTextTrack() {
|
|
|
|
addRemotes++;
|
|
|
|
return {
|
|
|
|
track: {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
c.jsonToTextTracks(cleanup(c.textTracksToJson(tech)), tech);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(addRemotes, 2, 'we added two text tracks');
|
2015-08-03 21:19:36 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('trackToJson_ produces correct representation for emulated track object', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const track = new TextTrack({
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/english.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
tech: {}
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.deepEqual(cleanup(c.trackToJson_(track)), {
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/english.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
2015-08-13 01:04:31 +02:00
|
|
|
mode: 'disabled'
|
2015-08-03 21:19:36 +02:00
|
|
|
}, 'the json output is same');
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('textTracksToJson produces good json output for emulated only', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const emulatedTrack = new TextTrack({
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/english.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
tech: {}
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const anotherTrack = new TextTrack({
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/spanish.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
srclang: 'es',
|
|
|
|
label: 'Spanish',
|
|
|
|
tech: {}
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tt = new TextTrackList();
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2017-01-19 22:16:28 +02:00
|
|
|
tt.addTrack(anotherTrack);
|
|
|
|
tt.addTrack(emulatedTrack);
|
2015-08-03 21:19:36 +02:00
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tech = {
|
2015-11-10 22:30:09 +02:00
|
|
|
$$() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
el() {
|
|
|
|
return {
|
|
|
|
querySelectorAll() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
textTracks() {
|
|
|
|
return tt;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.deepEqual(cleanup(c.textTracksToJson(tech)), [{
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/spanish.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'Spanish',
|
|
|
|
language: 'es',
|
2015-08-13 01:04:31 +02:00
|
|
|
mode: 'disabled'
|
2015-08-03 21:19:36 +02:00
|
|
|
}, {
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/english.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
2015-08-13 01:04:31 +02:00
|
|
|
mode: 'disabled'
|
2015-08-03 21:19:36 +02:00
|
|
|
}], 'the output is correct');
|
|
|
|
});
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
QUnit.test('jsonToTextTracks calls addRemoteTextTrack on the tech with emulated tracks only', function(assert) {
|
2016-08-03 21:27:03 +02:00
|
|
|
const emulatedTrack = new TextTrack({
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/english.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
tech: {}
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const anotherTrack = new TextTrack({
|
2015-10-27 21:54:48 +02:00
|
|
|
src: 'example.com/spanish.vtt',
|
2015-08-03 21:19:36 +02:00
|
|
|
kind: 'captions',
|
|
|
|
srclang: 'es',
|
|
|
|
label: 'Spanish',
|
|
|
|
tech: {}
|
|
|
|
});
|
|
|
|
|
2016-08-03 21:27:03 +02:00
|
|
|
const tt = new TextTrackList();
|
2016-03-07 21:54:32 +02:00
|
|
|
|
2017-01-19 22:16:28 +02:00
|
|
|
tt.addTrack(anotherTrack);
|
|
|
|
tt.addTrack(emulatedTrack);
|
2015-08-03 21:19:36 +02:00
|
|
|
|
|
|
|
let addRemotes = 0;
|
2016-08-03 21:27:03 +02:00
|
|
|
const tech = {
|
2015-11-10 22:30:09 +02:00
|
|
|
$$() {
|
|
|
|
return [];
|
|
|
|
},
|
|
|
|
|
2015-08-03 21:19:36 +02:00
|
|
|
el() {
|
|
|
|
return {
|
|
|
|
querySelectorAll() {
|
|
|
|
return [];
|
|
|
|
}
|
|
|
|
};
|
|
|
|
},
|
|
|
|
textTracks() {
|
|
|
|
return tt;
|
|
|
|
},
|
|
|
|
addRemoteTextTrack() {
|
|
|
|
addRemotes++;
|
|
|
|
return {
|
|
|
|
track: {}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
c.jsonToTextTracks(cleanup(c.textTracksToJson(tech)), tech);
|
|
|
|
|
2016-08-12 19:51:31 +02:00
|
|
|
assert.equal(addRemotes, 2, 'we added two text tracks');
|
2015-08-03 21:19:36 +02:00
|
|
|
});
|