mirror of
https://github.com/shaka-project/shaka-player.git
synced 2026-06-14 15:56:38 +03:00
fbbd63d96b
This change fixes tests on Chromecast by loading tests later in the process. Test scripts are now dynamically inserted by boot.js, rather than loaded by Karma. The bootstrapping code then awaits the completion of that before starting the Karma frameworks (Jasmine) to run the tests. This also removes the use of goog.provide/goog.require in tests and test utils. We don't need to load test utils or library sources dynamically in each test, and this gives us more explicit control over script loading and ordering. Closes #4094
82 lines
2.2 KiB
JavaScript
82 lines
2.2 KiB
JavaScript
/*! @license
|
|
* Shaka Player
|
|
* Copyright 2016 Google LLC
|
|
* SPDX-License-Identifier: Apache-2.0
|
|
*/
|
|
|
|
describe('SbvTextParser', () => {
|
|
it('supports no cues', () => {
|
|
verifyHelper([],
|
|
'',
|
|
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
|
|
});
|
|
|
|
it('handles a blank line at the end of the file', () => {
|
|
verifyHelper(
|
|
[
|
|
{startTime: 20, endTime: 40, payload: 'Test'},
|
|
],
|
|
'0:00:20.000,0:00:40.000\n' +
|
|
'Test\n\n',
|
|
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
|
|
});
|
|
|
|
it('handles no blank line at the end of the file', () => {
|
|
verifyHelper(
|
|
[
|
|
{startTime: 20, endTime: 40, payload: 'Test'},
|
|
],
|
|
'0:00:20.000,0:00:40.000\n' +
|
|
'Test\n',
|
|
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
|
|
});
|
|
|
|
it('handles no newline after the final text payload', () => {
|
|
verifyHelper(
|
|
[
|
|
{startTime: 20, endTime: 40, payload: 'Test'},
|
|
],
|
|
'0:00:20.000,0:00:40.000\n' +
|
|
'Test',
|
|
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
|
|
});
|
|
|
|
it('supports multiple cues', () => {
|
|
verifyHelper(
|
|
[
|
|
{startTime: 20, endTime: 40, payload: 'Test'},
|
|
{startTime: 40, endTime: 50, payload: 'Test2'},
|
|
],
|
|
'0:00:20.000,0:00:40.000\n' +
|
|
'Test\n\n' +
|
|
'0:00:40.000,0:00:50.000\n' +
|
|
'Test2',
|
|
{periodStart: 0, segmentStart: 0, segmentEnd: 0, vttOffset: 0});
|
|
});
|
|
|
|
/**
|
|
* @param {!Array} cues
|
|
* @param {string} text
|
|
* @param {shaka.extern.TextParser.TimeContext} time
|
|
*/
|
|
function verifyHelper(cues, text, time) {
|
|
const BufferUtils = shaka.util.BufferUtils;
|
|
const StringUtils = shaka.util.StringUtils;
|
|
|
|
const data = BufferUtils.toUint8(StringUtils.toUTF8(text));
|
|
|
|
const parser = new shaka.text.SbvTextParser();
|
|
const result = parser.parseMedia(data, time);
|
|
|
|
const expected = cues.map((cue) => {
|
|
if (cue.nestedCues) {
|
|
cue.nestedCues = cue.nestedCues.map(
|
|
(nestedCue) => jasmine.objectContaining(nestedCue),
|
|
);
|
|
}
|
|
return jasmine.objectContaining(cue);
|
|
});
|
|
expect(result).toEqual(expected);
|
|
}
|
|
});
|