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