Skip to content

Commit

Permalink
@gkatsev fixes track tests and ignored empty properties in tracks con…
Browse files Browse the repository at this point in the history
…verter. closes #2744
  • Loading branch information
gkatsev committed Oct 27, 2015
1 parent 589cab7 commit ab88bcd
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 27 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))

--------------------

Expand Down
27 changes: 16 additions & 11 deletions src/js/tracks/text-track-list-converter.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,23 +13,26 @@
* @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,
endTime: cue.endTime,
text: cue.text,
id: cue.id
};
}),
src: track.src
};
})
});

return ret;
};

/**
Expand All @@ -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;
});

Expand Down
27 changes: 11 additions & 16 deletions test/unit/tracks/text-track-list-converter.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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';
Expand All @@ -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',
Expand All @@ -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';
Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit ab88bcd

Please sign in to comment.