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

58 lines
1.8 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 917945 - VTTRegion</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="auto">
<track src="region.vtt" kind="subtitles" id="default" default>
</video>
<script type="text/javascript">
/**
* This test is used to ensure that we can parse VTT region attributes correctly
* from vtt file.
*/
var trackElement = document.getElementById("default");
async function runTest() {
await waitUntiTrackLoaded();
checkRegionAttributes();
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
SpecialPowers.pushPrefEnv({"set": [["media.webvtt.regions.enabled", true]]},
runTest);
/**
* The following are test helper functions.
*/
async function waitUntiTrackLoaded() {
if (trackElement.readyState != 2) {
info(`wait until the track finishes loading`);
await once(trackElement, "load");
}
is(trackElement.readyState, 2, "Track::ReadyState should be set to LOADED.");
}
function checkRegionAttributes() {
let cues = trackElement.track.cues;
is(cues.length, 1, "Cue list length should be 1.");
let region = cues[0].region;
isnot(region, null, "Region should not be null.");
is(region.width, 62, "Region width should be 50.");
is(region.lines, 5, "Region lines should be 5.");
is(region.regionAnchorX, 4, "Region regionAnchorX should be 4.");
is(region.regionAnchorY, 78, "Region regionAnchorY should be 78.");
is(region.viewportAnchorX, 10, "Region viewportAnchorX should be 10.");
is(region.viewportAnchorY, 90, "Region viewportAnchorY should be 90.");
is(region.scroll, "up", "Region scroll should be 'up'");
}
</script>
</body>
</html>