summaryrefslogtreecommitdiffstats
path: root/dom/media/webvtt/test/mochitest/test_texttrackregion.html
blob: f41c404445fd92f7eadce5ce453f02a7eb5a4e62 (plain)
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
<!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>