Fri, 16 Jan 2015 04:50:19 +0100
Replace accessor implementation with direct member state manipulation, by
request https://trac.torproject.org/projects/tor/ticket/9701#comment:32
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=833386 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset='utf-8'> |
michael@0 | 8 | <title>Test for Bug 833386 - TextTrackList</title> |
michael@0 | 9 | <script type="text/javascript" src="/MochiKit/MochiKit.js"></script> |
michael@0 | 10 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 11 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 12 | </head> |
michael@0 | 13 | <body> |
michael@0 | 14 | <p id="display"></p> |
michael@0 | 15 | <div id="content" style="display: none"> |
michael@0 | 16 | </div> |
michael@0 | 17 | <pre id="test"> |
michael@0 | 18 | <script class="testbody" type="text/javascript"> |
michael@0 | 19 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 20 | SpecialPowers.pushPrefEnv({"set": [["media.webvtt.enabled", true], |
michael@0 | 21 | ["media.webvtt.regions.enabled", true]]}, |
michael@0 | 22 | function() { |
michael@0 | 23 | var video = document.createElement("video"); |
michael@0 | 24 | |
michael@0 | 25 | isnot(video.textTracks, undefined, "HTMLMediaElement::TextTrack() property should be available.") |
michael@0 | 26 | |
michael@0 | 27 | var trackList = video.textTracks; |
michael@0 | 28 | is(trackList.length, 0, "Length should be 0."); |
michael@0 | 29 | |
michael@0 | 30 | ok(typeof video.addTextTrack == "function", "HTMLMediaElement::AddTextTrack() function should be available.") |
michael@0 | 31 | video.addTextTrack("subtitles", "third", "en-CA"); |
michael@0 | 32 | is(trackList.length, 1, "Length should be 1."); |
michael@0 | 33 | |
michael@0 | 34 | var textTrack = video.textTracks[0]; |
michael@0 | 35 | is(textTrack.label, "third", "Label should be set to third."); |
michael@0 | 36 | is(textTrack.language, "en-CA", "Language should be en-CA."); |
michael@0 | 37 | is(textTrack.kind, "subtitles", "Default kind should be subtitles."); |
michael@0 | 38 | is(textTrack.mode, "hidden", "Default mode should be hidden."); |
michael@0 | 39 | |
michael@0 | 40 | // Mode should not allow a bogus value. |
michael@0 | 41 | textTrack.mode = 'bogus'; |
michael@0 | 42 | is(textTrack.mode, 'hidden', "Mode should be not allow a bogus value."); |
michael@0 | 43 | |
michael@0 | 44 | // Should allow all these values for mode. |
michael@0 | 45 | checkMode("showing", "Mode should allow \"showing\""); |
michael@0 | 46 | checkMode("disabled", "Mode should allow \"disabled\""); |
michael@0 | 47 | checkMode("hidden", "Mode should allow \"hidden\""); |
michael@0 | 48 | |
michael@0 | 49 | // All below are read-only properties and so should not allow setting. |
michael@0 | 50 | textTrack.label = "French subtitles"; |
michael@0 | 51 | is(textTrack.label, "third", "Label is read-only so should still be \"label\"."); |
michael@0 | 52 | |
michael@0 | 53 | textTrack.language = "en"; |
michael@0 | 54 | is(textTrack.language, "en-CA", "Language is read-only so should still be \"en-CA\"."); |
michael@0 | 55 | |
michael@0 | 56 | textTrack.kind = "captions"; |
michael@0 | 57 | is(textTrack.kind, "subtitles", "Kind is read-only so should still be \"subtitles\""); |
michael@0 | 58 | |
michael@0 | 59 | function checkMode(value, message) { |
michael@0 | 60 | textTrack.mode = value; |
michael@0 | 61 | is(textTrack.mode, value, message); |
michael@0 | 62 | } |
michael@0 | 63 | |
michael@0 | 64 | // Insert some tracks in an order that is not sorted, we will test if they |
michael@0 | 65 | // are sorted later. |
michael@0 | 66 | var trackOne = document.createElement("track"); |
michael@0 | 67 | trackOne.label = "first"; |
michael@0 | 68 | trackOne.src = "basic.vtt"; |
michael@0 | 69 | trackOne.default = true; |
michael@0 | 70 | trackOne.id = "2"; |
michael@0 | 71 | video.appendChild(trackOne); |
michael@0 | 72 | |
michael@0 | 73 | video.addTextTrack("subtitles", "fourth", "en-CA"); |
michael@0 | 74 | |
michael@0 | 75 | var trackTwo = document.createElement("track"); |
michael@0 | 76 | trackTwo.label = "second"; |
michael@0 | 77 | trackTwo.src = "basic.vtt"; |
michael@0 | 78 | trackTwo.default = true; |
michael@0 | 79 | video.appendChild(trackTwo); |
michael@0 | 80 | |
michael@0 | 81 | video.src = "seek.webm"; |
michael@0 | 82 | video.preload = "auto"; |
michael@0 | 83 | |
michael@0 | 84 | document.getElementById("content").appendChild(video); |
michael@0 | 85 | |
michael@0 | 86 | video.addEventListener("loadedmetadata", function run_tests() { |
michael@0 | 87 | // Re-que run_tests() at the end of the event loop until the track |
michael@0 | 88 | // element has loaded its data. |
michael@0 | 89 | if (trackOne.readyState == 1 || trackTwo.readyState == 1) { |
michael@0 | 90 | setTimeout(run_tests, 0); |
michael@0 | 91 | return; |
michael@0 | 92 | } |
michael@0 | 93 | is(trackOne.readyState, 2, "First Track::ReadyState should be set to LOADED."); |
michael@0 | 94 | is(trackTwo.readyState, 2, "Second Track::ReadyState should be set to LOADED."); |
michael@0 | 95 | |
michael@0 | 96 | // We're testing two things here, firstly that tracks created from a track |
michael@0 | 97 | // element have a default mode 'disabled' and tracks created with the |
michael@0 | 98 | // 'addTextTrack' method have a default mode of 'hidden'. |
michael@0 | 99 | // Secondly we're testing that the tracks are sorted properly. |
michael@0 | 100 | // For the tracks to be sorted the first two tracks, added through a |
michael@0 | 101 | // TrackElement, must occupy the first two indexes in their TrackElement |
michael@0 | 102 | // tree order. The second two tracks, added through the 'addTextTrack' |
michael@0 | 103 | // method, will occupy the last two indexes in the order that they were |
michael@0 | 104 | // added in. |
michael@0 | 105 | var trackData = [ |
michael@0 | 106 | { label: "first", mode: "showing", id: "2" }, |
michael@0 | 107 | { label: "second", mode: "disabled", id: "" }, |
michael@0 | 108 | { label: "third", mode: "hidden", id: "" }, |
michael@0 | 109 | { label: "fourth", mode: "hidden", id: "" } |
michael@0 | 110 | ]; |
michael@0 | 111 | is(video.textTracks.length, trackData.length, "TextTracks length should be " + trackData.length); |
michael@0 | 112 | for (var i = 0; i < trackData.length; i++) { |
michael@0 | 113 | var track = video.textTracks[i]; |
michael@0 | 114 | isnot(track, null, "Video should have a text track at index " + i); |
michael@0 | 115 | var info = trackData[i]; |
michael@0 | 116 | for (var key in info) { |
michael@0 | 117 | is(track[key], info[key], "Track at index " + i + " should have a '" + key + "'' property " + |
michael@0 | 118 | "with a value of '" + info[key] + "'."); |
michael@0 | 119 | } |
michael@0 | 120 | } |
michael@0 | 121 | SimpleTest.finish(); |
michael@0 | 122 | }); |
michael@0 | 123 | }); |
michael@0 | 124 | </script> |
michael@0 | 125 | </pre> |
michael@0 | 126 | </body> |
michael@0 | 127 | </html> |