1
0
mirror of https://github.com/videojs/video.js.git synced 2024-11-24 08:42:25 +02:00

@gkatsev fixes track tests and ignored empty properties in tracks converter. closes #2744

This commit is contained in:
Gary Katsevman 2015-10-27 15:54:48 -04:00
parent 589cab7fa7
commit ab88bcdde3
3 changed files with 28 additions and 27 deletions

View File

@ -7,6 +7,7 @@ CHANGELOG
* @forbesjo updated karma to use all installed browsers for unit tests ([view](https://github.com/videojs/video.js/pull/2708))
* @forbesjo removed android/ios tests to increase build stability ([view](https://github.com/videojs/video.js/pull/2739))
* @nickygerritsen added canPlayType method to player ([view](https://github.com/videojs/video.js/pull/2709))
* @gkatsev fixes track tests and ignored empty properties in tracks converter ([view](https://github.com/videojs/video.js/pull/2744))
--------------------

View File

@ -13,13 +13,15 @@
* @private
*/
let trackToJson_ = function(track) {
return {
kind: track.kind,
label: track.label,
language: track.language,
id: track.id,
inBandMetadataTrackDispatchType: track.inBandMetadataTrackDispatchType,
mode: track.mode,
let ret = ['kind', 'label', 'language', 'id',
'inBandMetadataTrackDispatchType',
'mode', 'src'].reduce((acc, prop, i) => {
if (track[prop]) {
acc[prop] = track[prop];
}
return acc;
}, {
cues: track.cues && Array.prototype.map.call(track.cues, function(cue) {
return {
startTime: cue.startTime,
@ -27,9 +29,10 @@ let trackToJson_ = function(track) {
text: cue.text,
id: cue.id
};
}),
src: track.src
};
})
});
return ret;
};
/**
@ -46,7 +49,9 @@ let textTracksToJson = function(tech) {
let trackObjs = Array.prototype.map.call(trackEls, (t) => t.track);
let tracks = Array.prototype.map.call(trackEls, function(trackEl) {
let json = trackToJson_(trackEl.track);
json.src = trackEl.src;
if (trackEl.src) {
json.src = trackEl.src;
}
return json;
});

View File

@ -26,13 +26,12 @@ let cleanup = (item) => {
if (Html5.supportsNativeTextTracks()) {
q.test('trackToJson_ produces correct representation for native track object', function(a) {
let track = document.createElement('track');
track.src = 'http://example.com/english.vtt';
track.src = 'example.com/english.vtt';
track.kind = 'captions';
track.srclang = 'en';
track.label = 'English';
a.deepEqual(cleanup(c.trackToJson_(track.track)), {
src: undefined,
kind: 'captions',
label: 'English',
language: 'en',
@ -45,12 +44,10 @@ if (Html5.supportsNativeTextTracks()) {
kind: 'captions',
label: 'English',
language: 'en',
src: 'http://example.com/english.vtt',
tech: {}
});
let nativeTrack = document.createElement('track');
nativeTrack.src = 'http://example.com/spanish.vtt';
nativeTrack.kind = 'captions';
nativeTrack.srclang = 'es';
nativeTrack.label = 'Spanish';
@ -73,13 +70,11 @@ if (Html5.supportsNativeTextTracks()) {
};
a.deepEqual(cleanup(c.textTracksToJson(tech)), [{
src: 'http://example.com/spanish.vtt',
kind: 'captions',
label: 'Spanish',
language: 'es',
mode: 'disabled'
}, {
src: 'http://example.com/english.vtt',
kind: 'captions',
label: 'English',
language: 'en',
@ -92,12 +87,12 @@ if (Html5.supportsNativeTextTracks()) {
kind: 'captions',
label: 'English',
language: 'en',
src: 'http://example.com/english.vtt',
src: 'example.com/english.vtt',
tech: {}
});
let nativeTrack = document.createElement('track');
nativeTrack.src = 'http://example.com/spanish.vtt';
nativeTrack.src = 'example.com/spanish.vtt';
nativeTrack.kind = 'captions';
nativeTrack.srclang = 'es';
nativeTrack.label = 'Spanish';
@ -137,12 +132,12 @@ q.test('trackToJson_ produces correct representation for emulated track object',
kind: 'captions',
label: 'English',
language: 'en',
src: 'http://example.com/english.vtt',
src: 'example.com/english.vtt',
tech: {}
});
a.deepEqual(cleanup(c.trackToJson_(track)), {
src: 'http://example.com/english.vtt',
src: 'example.com/english.vtt',
kind: 'captions',
label: 'English',
language: 'en',
@ -155,12 +150,12 @@ q.test('textTracksToJson produces good json output for emulated only', function(
kind: 'captions',
label: 'English',
language: 'en',
src: 'http://example.com/english.vtt',
src: 'example.com/english.vtt',
tech: {}
});
let anotherTrack = new TextTrack({
src: 'http://example.com/spanish.vtt',
src: 'example.com/spanish.vtt',
kind: 'captions',
srclang: 'es',
label: 'Spanish',
@ -185,13 +180,13 @@ q.test('textTracksToJson produces good json output for emulated only', function(
};
a.deepEqual(cleanup(c.textTracksToJson(tech)), [{
src: 'http://example.com/spanish.vtt',
src: 'example.com/spanish.vtt',
kind: 'captions',
label: 'Spanish',
language: 'es',
mode: 'disabled'
}, {
src: 'http://example.com/english.vtt',
src: 'example.com/english.vtt',
kind: 'captions',
label: 'English',
language: 'en',
@ -204,12 +199,12 @@ q.test('jsonToTextTracks calls addRemoteTextTrack on the tech with emulated trac
kind: 'captions',
label: 'English',
language: 'en',
src: 'http://example.com/english.vtt',
src: 'example.com/english.vtt',
tech: {}
});
let anotherTrack = new TextTrack({
src: 'http://example.com/spanish.vtt',
src: 'example.com/spanish.vtt',
kind: 'captions',
srclang: 'es',
label: 'Spanish',