content/media/test/test_texttrack.html

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/content/media/test/test_texttrack.html	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,127 @@
     1.4 +<!DOCTYPE HTML>
     1.5 +<html>
     1.6 +<!--
     1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=833386
     1.8 +-->
     1.9 +<head>
    1.10 +  <meta charset='utf-8'>
    1.11 +  <title>Test for Bug 833386 - TextTrackList</title>
    1.12 +  <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
    1.13 +  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
    1.14 +  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
    1.15 +</head>
    1.16 +<body>
    1.17 +<p id="display"></p>
    1.18 +<div id="content" style="display: none">
    1.19 +</div>
    1.20 +<pre id="test">
    1.21 +<script class="testbody" type="text/javascript">
    1.22 +SimpleTest.waitForExplicitFinish();
    1.23 +SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true],
    1.24 +                                   ["media.webvtt.regions.enabled", true]]},
    1.25 +  function() {
    1.26 +    var video = document.createElement("video");
    1.27 +
    1.28 +    isnot(video.textTracks, undefined, "HTMLMediaElement::TextTrack() property should be available.")
    1.29 +
    1.30 +    var trackList = video.textTracks;
    1.31 +    is(trackList.length, 0, "Length should be 0.");
    1.32 +
    1.33 +    ok(typeof video.addTextTrack == "function", "HTMLMediaElement::AddTextTrack() function should be available.")
    1.34 +    video.addTextTrack("subtitles", "third", "en-CA");
    1.35 +    is(trackList.length, 1, "Length should be 1.");
    1.36 +
    1.37 +    var textTrack = video.textTracks[0];
    1.38 +    is(textTrack.label, "third", "Label should be set to third.");
    1.39 +    is(textTrack.language, "en-CA", "Language should be en-CA.");
    1.40 +    is(textTrack.kind, "subtitles", "Default kind should be subtitles.");
    1.41 +    is(textTrack.mode, "hidden", "Default mode should be hidden.");
    1.42 +
    1.43 +    // Mode should not allow a bogus value.
    1.44 +    textTrack.mode = 'bogus';
    1.45 +    is(textTrack.mode, 'hidden', "Mode should be not allow a bogus value.");
    1.46 +
    1.47 +    // Should allow all these values for mode.
    1.48 +    checkMode("showing", "Mode should allow \"showing\"");
    1.49 +    checkMode("disabled", "Mode should allow \"disabled\"");
    1.50 +    checkMode("hidden", "Mode should allow \"hidden\"");
    1.51 +
    1.52 +    // All below are read-only properties and so should not allow setting.
    1.53 +    textTrack.label = "French subtitles";
    1.54 +    is(textTrack.label, "third", "Label is read-only so should still be \"label\".");
    1.55 +
    1.56 +    textTrack.language = "en";
    1.57 +    is(textTrack.language, "en-CA", "Language is read-only so should still be \"en-CA\".");
    1.58 +
    1.59 +    textTrack.kind = "captions";
    1.60 +    is(textTrack.kind, "subtitles", "Kind is read-only so should still be \"subtitles\"");
    1.61 +
    1.62 +    function checkMode(value, message) {
    1.63 +      textTrack.mode = value;
    1.64 +      is(textTrack.mode, value, message);
    1.65 +    }
    1.66 +
    1.67 +    // Insert some tracks in an order that is not sorted, we will test if they
    1.68 +    // are sorted later.
    1.69 +    var trackOne = document.createElement("track");
    1.70 +    trackOne.label = "first";
    1.71 +    trackOne.src = "basic.vtt";
    1.72 +    trackOne.default = true;
    1.73 +    trackOne.id = "2";
    1.74 +    video.appendChild(trackOne);
    1.75 +
    1.76 +    video.addTextTrack("subtitles", "fourth", "en-CA");
    1.77 +
    1.78 +    var trackTwo = document.createElement("track");
    1.79 +    trackTwo.label = "second";
    1.80 +    trackTwo.src = "basic.vtt";
    1.81 +    trackTwo.default = true;
    1.82 +    video.appendChild(trackTwo);
    1.83 +
    1.84 +    video.src = "seek.webm";
    1.85 +    video.preload = "auto";
    1.86 +
    1.87 +    document.getElementById("content").appendChild(video);
    1.88 +
    1.89 +    video.addEventListener("loadedmetadata", function run_tests() {
    1.90 +      // Re-que run_tests() at the end of the event loop until the track
    1.91 +      // element has loaded its data.
    1.92 +      if (trackOne.readyState == 1 || trackTwo.readyState == 1) {
    1.93 +        setTimeout(run_tests, 0);
    1.94 +        return;
    1.95 +      }
    1.96 +      is(trackOne.readyState, 2, "First Track::ReadyState should be set to LOADED.");
    1.97 +      is(trackTwo.readyState, 2, "Second Track::ReadyState should be set to LOADED.");
    1.98 +
    1.99 +      // We're testing two things here, firstly that tracks created from a track
   1.100 +      // element have a default mode 'disabled' and tracks created with the
   1.101 +      // 'addTextTrack' method have a default mode of 'hidden'.
   1.102 +      // Secondly we're testing that the tracks are sorted properly.
   1.103 +      // For the tracks to be sorted the first two tracks, added through a
   1.104 +      // TrackElement, must occupy the first two indexes in their TrackElement
   1.105 +      // tree order. The second two tracks, added through the 'addTextTrack'
   1.106 +      // method, will occupy the last two indexes in the order that they were
   1.107 +      // added in.
   1.108 +      var trackData = [
   1.109 +        { label: "first", mode: "showing", id: "2" },
   1.110 +        { label: "second", mode: "disabled", id: "" },
   1.111 +        { label: "third", mode: "hidden", id: "" },
   1.112 +        { label: "fourth", mode: "hidden", id: "" }
   1.113 +      ];
   1.114 +      is(video.textTracks.length, trackData.length, "TextTracks length should be " + trackData.length);
   1.115 +      for (var i = 0; i < trackData.length; i++) {
   1.116 +        var track = video.textTracks[i];
   1.117 +        isnot(track, null, "Video should have a text track at index " + i);
   1.118 +        var info = trackData[i];
   1.119 +        for (var key in info) {
   1.120 +          is(track[key], info[key], "Track at index " + i + " should have a '" + key + "'' property " +
   1.121 +                                    "with a value of '" + info[key] + "'.");
   1.122 +        }
   1.123 +      }
   1.124 +      SimpleTest.finish();
   1.125 +    });
   1.126 +});
   1.127 +</script>
   1.128 +</pre>
   1.129 +</body>
   1.130 +</html>

mercurial