5 <title>WebVTT : position align test
</title>
6 <script src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css"/>
12 <script class=
"testbody" type=
"text/javascript">
13 SimpleTest.waitForExplicitFinish();
15 var video = document.createElement(
"video");
16 var trackElement = document.createElement(
"track");
19 function isTrackElemenLoaded() {
20 // Re-que isTrackElemenLoaded() at the end of the event loop until the track
21 // element has loaded its data.
22 if (trackElement.readyState ==
1) {
23 setTimeout(isTrackElemenLoaded,
0);
27 is(trackElement.readyState,
2,
"Track::ReadyState should be set to LOADED.");
32 info(
"--- check cues number ---");
33 var cues = trackElement.track.cues;
34 is(cues.length, cuesNumber,
"Cues number is correct.");
36 info(
"--- check the typedef of TextTrackCue and VTTCue ---");
37 isnot(window.TextTrackCue, undefined,
"TextTrackCue should be defined.");
38 isnot(window.VTTCue, undefined,
"VTTCue should be defined.");
40 info(
"--- check the type of first parsed cue ---");
41 ok(cues[
0] instanceof TextTrackCue,
"Cue should be an instanceof TextTrackCue.");
42 ok(cues[
0] instanceof VTTCue,
"Cue should be an instanceof VTTCue.");
44 info(
"--- check the cue's position alignment ---");
45 let expectedAlignment = [
"auto",
"line-left",
"center",
"line-right",
"auto"];
47 for (;idx < expectedAlignment.length; idx++) {
48 is(cues[idx].positionAlign, expectedAlignment[idx], cues[idx].text);
51 info(
"--- check the cue's computed position alignment ---");
52 // The
"computedPositionAlign" is the chrome-only attributes, we need to get
53 // the chrome privilege for cues.
54 let cuesChrome = SpecialPowers.wrap(cues);
55 expectedAlignment.push(
"line-left",
"line-right",
"center");
56 for (;idx < expectedAlignment.length; idx++) {
57 is(cuesChrome[idx].computedPositionAlign, expectedAlignment[idx],
58 cuesChrome[idx].text);
61 info(`test only setting text alignment with
"start"`);
62 expectedAlignment.push(
"line-left",
"line-right",
"line-left",
"line-right",
63 "line-left",
"line-left",
"line-right");
64 for (;idx < expectedAlignment.length; idx++) {
65 is(cuesChrome[idx].computedPositionAlign, expectedAlignment[idx],
66 cuesChrome[idx].text);
69 info(`test only setting text alignment with
"end"`);
70 expectedAlignment.push(
"line-right",
"line-left",
"line-right",
"line-left",
71 "line-right",
"line-right",
"line-left");
72 for (;idx < expectedAlignment.length; idx++) {
73 is(cuesChrome[idx].computedPositionAlign, expectedAlignment[idx],
74 cuesChrome[idx].text);
76 is(idx, cuesNumber,
"finished checking all cues");
78 info(
"--- check the cue's computed position alignment from DOM API ---");
79 is(cuesChrome[
0].computedPositionAlign,
"center",
"Cue's computedPositionAlign align is center.");
81 cuesChrome[
0].positionAlign =
"auto";
82 is(cuesChrome[
0].positionAlign,
"auto",
"Change cue's position align to \"auto\
"");
84 cuesChrome[
0].align =
"left";
85 is(cuesChrome[
0].align,
"left",
"Change cue's align to \"left\
".");
87 is(cuesChrome[
0].computedPositionAlign,
"line-left",
"Cue's computedPositionAlign becomes to \"line-left\
"");
89 info(
"--- finish test ---");
93 function setupTest() {
94 info(
"--- setup test ---");
95 video.src =
"seek.webm";
96 video.preload =
"auto";
98 trackElement.src =
"vttPositionAlign.vtt";
99 trackElement.kind =
"subtitles";
100 trackElement.default = true;
102 document.getElementById(
"content").appendChild(video);
103 video.appendChild(trackElement);
104 video.addEventListener(
"loadedmetadata", function() {
105 isTrackElemenLoaded();