diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/webvtt/test/mochitest/test_webvtt_positionalign.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/webvtt/test/mochitest/test_webvtt_positionalign.html')
-rw-r--r-- | dom/media/webvtt/test/mochitest/test_webvtt_positionalign.html | 113 |
1 files changed, 113 insertions, 0 deletions
diff --git a/dom/media/webvtt/test/mochitest/test_webvtt_positionalign.html b/dom/media/webvtt/test/mochitest/test_webvtt_positionalign.html new file mode 100644 index 0000000000..267fd52f93 --- /dev/null +++ b/dom/media/webvtt/test/mochitest/test_webvtt_positionalign.html @@ -0,0 +1,113 @@ +<!DOCTYPE HTML> +<html> +<head> + <meta charset='utf-8'> + <title>WebVTT : position align test</title> + <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<div id="content"> +</div> +<script class="testbody" type="text/javascript"> +SimpleTest.waitForExplicitFinish(); + +var video = document.createElement("video"); +var trackElement = document.createElement("track"); +var cuesNumber = 22; + +function isTrackElemenLoaded() { + // Re-que isTrackElemenLoaded() at the end of the event loop until the track + // element has loaded its data. + if (trackElement.readyState == 1) { + setTimeout(isTrackElemenLoaded, 0); + return; + } + + is(trackElement.readyState, 2, "Track::ReadyState should be set to LOADED."); + runTest(); +} + +function runTest() { + info("--- check cues number ---"); + var cues = trackElement.track.cues; + is(cues.length, cuesNumber, "Cues number is correct."); + + info("--- check the typedef of TextTrackCue and VTTCue ---"); + isnot(window.TextTrackCue, undefined, "TextTrackCue should be defined."); + isnot(window.VTTCue, undefined, "VTTCue should be defined."); + + info("--- check the type of first parsed cue ---"); + ok(cues[0] instanceof TextTrackCue, "Cue should be an instanceof TextTrackCue."); + ok(cues[0] instanceof VTTCue, "Cue should be an instanceof VTTCue."); + + info("--- check the cue's position alignment ---"); + let expectedAlignment = ["auto", "line-left", "center", "line-right", "auto"]; + let idx = 0; + for (;idx < expectedAlignment.length; idx++) { + is(cues[idx].positionAlign, expectedAlignment[idx], cues[idx].text); + } + + info("--- check the cue's computed position alignment ---"); + // The "computedPositionAlign" is the chrome-only attributes, we need to get + // the chrome privilege for cues. + let cuesChrome = SpecialPowers.wrap(cues); + expectedAlignment.push("line-left", "line-right", "center"); + for (;idx < expectedAlignment.length; idx++) { + is(cuesChrome[idx].computedPositionAlign, expectedAlignment[idx], + cuesChrome[idx].text); + } + + info(`test only setting text alignment with "start"`); + expectedAlignment.push("line-left", "line-right", "line-left", "line-right", + "line-left", "line-left", "line-right"); + for (;idx < expectedAlignment.length; idx++) { + is(cuesChrome[idx].computedPositionAlign, expectedAlignment[idx], + cuesChrome[idx].text); + } + + info(`test only setting text alignment with "end"`); + expectedAlignment.push("line-right", "line-left", "line-right", "line-left", + "line-right", "line-right", "line-left"); + for (;idx < expectedAlignment.length; idx++) { + is(cuesChrome[idx].computedPositionAlign, expectedAlignment[idx], + cuesChrome[idx].text); + } + is(idx, cuesNumber, "finished checking all cues"); + + info("--- check the cue's computed position alignment from DOM API ---"); + is(cuesChrome[0].computedPositionAlign, "center", "Cue's computedPositionAlign align is center."); + + cuesChrome[0].positionAlign = "auto"; + is(cuesChrome[0].positionAlign, "auto", "Change cue's position align to \"auto\""); + + cuesChrome[0].align = "left"; + is(cuesChrome[0].align, "left", "Change cue's align to \"left\"."); + + is(cuesChrome[0].computedPositionAlign, "line-left", "Cue's computedPositionAlign becomes to \"line-left\""); + + info("--- finish test ---"); + SimpleTest.finish(); +} + +function setupTest() { + info("--- setup test ---"); + video.src = "seek.webm"; + video.preload = "auto"; + + trackElement.src = "vttPositionAlign.vtt"; + trackElement.kind = "subtitles"; + trackElement.default = true; + + document.getElementById("content").appendChild(video); + video.appendChild(trackElement); + video.addEventListener("loadedmetadata", function() { + isTrackElemenLoaded(); + }, {once: true}); +} + +onload = setupTest; +</script> +</body> +</html> |