Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix track tests and ignore empty properties in tracks #2744

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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