/
cue_integration.js
55 lines (49 loc) · 1.88 KB
/
cue_integration.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*! @license
* Shaka Player
* Copyright 2016 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/
goog.require('shaka.text.VttTextParser');
goog.require('shaka.util.BufferUtils');
goog.require('shaka.util.StringUtils');
describe('Cue', () => {
// This integration test checks platform support for various cue scenarios
// that have caused platform-specific issues. The unit tests for each parser
// use a mocked VTTCue implementation, so they do not find platform issues.
// The scenarios under test are not specific to WebVTT, but WebVTT is used to
// exercise the platform's native cues and ensure that no errors occur.
it('handles offsets', () => {
// Offsets must be handled early.
// See issue #502
const cues = parseVtt(
'WEBVTT\n\n' +
'00:00:20.000 --> 00:00:40.000\n' +
'Test',
{periodStart: 7, segmentStart: 10, segmentEnd: 60, vttOffset: 7});
expect(cues.length).toBe(1);
expect(cues[0].startTime).toBe(27);
expect(cues[0].endTime).toBe(47);
});
it('does not object to extra settings', () => {
// To simplify refactoring, we are no longer checking for VTTCue before
// setting properties that only exist on VTTCue. So we want to ensure that
// errors are not thrown when the extra settings are assigned.
const cues = parseVtt(
'WEBVTT\n\n' +
'ID1\n' +
'00:00:20.000 --> 00:00:40.000 align:middle size:56% vertical:lr\n' +
'Test',
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
expect(cues.length).toBe(1);
});
/**
* @param {string} text
* @param {!shaka.extern.TextParser.TimeContext} time
* @return {!Array.<!shaka.extern.Cue>}
*/
function parseVtt(text, time) {
const data =
shaka.util.BufferUtils.toUint8(shaka.util.StringUtils.toUTF8(text));
return new shaka.text.VttTextParser().parseMedia(data, time);
}
});