This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Metadata cues may have length zero (#113)
* Metadata cues may have length zero It's not safe to assume that there is at least one element in metadata cues when addTextTrackData() is invoked. Double check the array is there and non-empty before tweaking start and end times. Add tests for that module. * Fix another bad array length check Empty arrays are truthy.
- Loading branch information
Showing
3 changed files
with
58 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Qunit from 'qunit'; | ||
import { addTextTrackData } from '../src/add-text-track-data'; | ||
|
||
const { equal, module, test } = Qunit; | ||
|
||
class MockTextTrack { | ||
constructor() { | ||
this.cues = []; | ||
} | ||
addCue(cue) { | ||
this.cues.push(cue); | ||
} | ||
} | ||
|
||
module('Text Track Data', { | ||
beforeEach() { | ||
this.sourceHandler = { | ||
inbandTextTrack_: new MockTextTrack(), | ||
metadataTrack_: new MockTextTrack(), | ||
mediaSource_: { | ||
duration: NaN | ||
}, | ||
timestampOffset: 0 | ||
}; | ||
} | ||
}); | ||
|
||
test('does nothing if no cues are specified', function() { | ||
addTextTrackData(this.sourceHandler, [], []); | ||
equal(this.sourceHandler.inbandTextTrack_.cues.length, 0, 'added no 608 cues'); | ||
equal(this.sourceHandler.metadataTrack_.cues.length, 0, 'added no metadata cues'); | ||
}); | ||
|
||
test('creates cues for 608 captions', function() { | ||
addTextTrackData(this.sourceHandler, [{ | ||
startTime: 0, | ||
endTime: 1, | ||
text: 'caption text' | ||
}], []); | ||
equal(this.sourceHandler.inbandTextTrack_.cues.length, 1, 'added one 608 cues'); | ||
equal(this.sourceHandler.metadataTrack_.cues.length, 0, 'added no metadata cues'); | ||
}); | ||
|
||
test('creates cues for timed metadata', function() { | ||
addTextTrackData(this.sourceHandler, [], [{ | ||
cueTime: 1, | ||
frames: [{}] | ||
}]); | ||
equal(this.sourceHandler.inbandTextTrack_.cues.length, 0, 'added no 608 cues'); | ||
equal(this.sourceHandler.metadataTrack_.cues.length, 1, 'added one metadata cues'); | ||
}); |