1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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>
|