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';
|
2015-08-25 02:46:54 +02:00
|
|
|
import window from 'global/window';
|
2015-08-03 21:19:36 +02:00
|
|
|
|
2015-07-08 00:27:20 +02:00
|
|
|
q.module('Text Track List Converter', {});
|
2015-08-03 21:19:36 +02:00
|
|
|
|
|
|
|
let clean = (item) => {
|
|
|
|
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
|
|
|
};
|
|
|
|
|
|
|
|
let cleanup = (item) => {
|
|
|
|
if (Array.isArray(item)) {
|
|
|
|
item.forEach(clean);
|
|
|
|
} else {
|
|
|
|
clean(item);
|
|
|
|
}
|
|
|
|
|
|
|
|
return item;
|
|
|
|
};
|
|
|
|
|
|
|
|
if (Html5.supportsNativeTextTracks()) {
|
|
|
|
q.test('trackToJson_ produces correct representation for native track object', function(a) {
|
|
|
|
let track = document.createElement('track');
|
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';
|
|
|
|
|
|
|
|
a.deepEqual(cleanup(c.trackToJson_(track.track)), {
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
q.test('textTracksToJson produces good json output', function(a) {
|
|
|
|
let emulatedTrack = new TextTrack({
|
|
|
|
kind: 'captions',
|
|
|
|
label: 'English',
|
|
|
|
language: 'en',
|
|
|
|
tech: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
let nativeTrack = document.createElement('track');
|
|
|
|
nativeTrack.kind = 'captions';
|
|
|
|
nativeTrack.srclang = 'es';
|
|
|
|
nativeTrack.label = 'Spanish';
|
|
|
|
|
|
|
|
let tt = new TextTrackList();
|
|
|
|
tt.addTrack_(nativeTrack.track);
|
|
|
|
tt.addTrack_(emulatedTrack);
|
|
|
|
|
|
|
|
let 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
a.deepEqual(cleanup(c.textTracksToJson(tech)), [{
|
|
|
|
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');
|
|
|
|
});
|
|
|
|
|
|
|
|
q.test('jsonToTextTracks calls addRemoteTextTrack on the tech with mixed tracks', function(a) {
|
|
|
|
let emulatedTrack = new TextTrack({
|
|
|
|
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: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
let nativeTrack = document.createElement('track');
|
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';
|
|
|
|
|
|
|
|
let tt = new TextTrackList();
|
|
|
|
tt.addTrack_(nativeTrack.track);
|
|
|
|
tt.addTrack_(emulatedTrack);
|
|
|
|
|
|
|
|
let addRemotes = 0;
|
|
|
|
let 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);
|
|
|
|
|
|
|
|
a.equal(addRemotes, 2, 'we added two text tracks');
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
q.test('trackToJson_ produces correct representation for emulated track object', function(a) {
|
|
|
|
let track = new TextTrack({
|
|
|
|
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: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
a.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');
|
|
|
|
});
|
|
|
|
|
|
|
|
q.test('textTracksToJson produces good json output for emulated only', function(a) {
|
|
|
|
let emulatedTrack = new TextTrack({
|
|
|
|
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: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
let 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: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
let tt = new TextTrackList();
|
|
|
|
tt.addTrack_(anotherTrack);
|
|
|
|
tt.addTrack_(emulatedTrack);
|
|
|
|
|
|
|
|
let 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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
a.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');
|
|
|
|
});
|
|
|
|
|
|
|
|
q.test('jsonToTextTracks calls addRemoteTextTrack on the tech with emulated tracks only', function(a) {
|
|
|
|
let emulatedTrack = new TextTrack({
|
|
|
|
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: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
let 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: {}
|
|
|
|
});
|
|
|
|
|
|
|
|
let tt = new TextTrackList();
|
|
|
|
tt.addTrack_(anotherTrack);
|
|
|
|
tt.addTrack_(emulatedTrack);
|
|
|
|
|
|
|
|
let addRemotes = 0;
|
|
|
|
let 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);
|
|
|
|
|
|
|
|
a.equal(addRemotes, 2, 'we added two text tracks');
|
|
|
|
});
|