gecko-dev/dom/media/test/test_bug883173.html
alwu 7e3d903ca9 Bug 1550633 - part13.5 - wait text track element's 'load' event. r=jya
This patch do two things in order to trigger loading for track element and wait for correct event to check track's and cues' status after loading finished.

(1) listen track element's load event
There are some tests listening video's loadedmetadata, but it's wrong. The loading process of media element and track element are completely non-related.
If you would like to check track element's status, you should wait for track element's load event.

(2) enable track explictly
If the text track which has default attribute is added to the media element before the media element starts running automatic track selection [1], then it would be enable by the media element.
Otherwise, you have to enable track explicitly by changing its track mode.

[1] https://html.spec.whatwg.org/multipage/media.html#sourcing-out-of-band-text-tracks:text-track-7

Differential Revision: https://phabricator.services.mozilla.com/D31913

--HG--
extra : moz-landing-system : lando
2019-05-24 00:41:04 +00:00

40 lines
1.2 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 883173 - TextTrackCue(List) Sorting</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<video id="v" src="seek.webm" preload="metadata">
<track src="bug883173.vtt" kind="subtitles" id="default" default>
</video>
<script type="text/javascript">
/**
* This test is used to ensure that the cues in the cue list should be sorted by
* cues' start time and end time, not the present order in the file.
*/
function runTest() {
let trackElement = document.getElementById("default");
is(trackElement.readyState, 2, "Track::ReadyState should be set to LOADED.");
let expected = [[1, 3], [1, 2], [2, 4], [2, 3], [3, 4]];
let cueList = trackElement.track.cues;
is(cueList.length, expected.length, "Cue list length should be 5.");
for (let i = 0; i < expected.length; i++) {
is(cueList[i].startTime, expected[i][0],
`Cue's start time should be ${expected[i][0]}`);
is(cueList[i].endTime, expected[i][1],
`Cue's end time should be ${expected[i][1]}`);
}
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
onload = runTest;
</script>
</body>
</html>