gecko-dev/dom/media/test/test_texttrack_moz.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

61 lines
1.9 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 881976 - TextTrackList</title>
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="manifest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<video id="v" src="seek.webm" preload="metadata">
<script type="text/javascript">
/**
* This test is used to ensure the text track list we got from video is as same
* as the one in the text track.
*/
var video = document.getElementById("v");
async function runTest() {
addTrackViaAddTrackAPI();
await addTrackViaTrackElement();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
onload = runTest;
/**
* The following are test helper functions.
*/
function addTrackViaAddTrackAPI() {
// Check if adding a text track manually sets the TextTrackList correctly.
video.addTextTrack("subtitles", "", "");
// TextTrack.textTrackList is an extension available only to privileged code,
// so we need to access it through the SpecialPowers object.
is(SpecialPowers.unwrap(SpecialPowers.wrap(video.textTracks[0]).textTrackList),
video.textTracks,
"The Track's TextTrackList should be the Video's TextTrackList.");
}
async function addTrackViaTrackElement() {
// Check if loading a Track via a TrackElement sets the TextTrackList correctly.
let trackElement = document.createElement("track");
trackElement.src = "basic.vtt";
trackElement.kind = "subtitles";
trackElement.default = true;
video.appendChild(trackElement);
info(`wait until the track finishes loading`);
await once(trackElement, "load");
is(trackElement.readyState, HTMLTrackElement.LOADED,
"Track::ReadyState should be set to LOADED.");
is(SpecialPowers.unwrap(SpecialPowers.wrap(trackElement.track).textTrackList),
video.textTracks,
"TrackElement's Track's TextTrackList should be the Video's TextTrackList.");
}
</script>
</body>
</html>