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=479859
5 -->
6 <head>
7 <title>Test for Bug 479859</title>
8 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
10 <script type="application/javascript" src="manifest.js"></script>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=479859">Mozilla Bug 479859</a>
14 <p id="display"></p>
15 <div id="content" style="display: none">
17 </div>
18 <pre id="test">
19 <script type="text/javascript">
21 function log(msg) {
22 //document.getElementById('log').innerHTML += "<p>" + msg + "</p>";
23 }
25 // We don't track: progress, canplay, canplaythrough and stalled events,
26 // as these can be delivered out of order, and/or multiple times.
27 var gEventTypes = [ 'loadstart', 'abort', 'error', 'emptied', 'play',
28 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'seeking',
29 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ];
31 var gEventNum = 0;
32 var gTestNum = 0;
33 var gTestFileNum = 0;
34 var gExpectedEvents = null;
35 var gTest = null;
36 var gTestName = "?";
38 function listener(evt) {
39 log('event ' + evt.type);
40 ok(gEventNum < gExpectedEvents.length, gTestName+" - corrent number of events received");
41 var expected = (gEventNum < gExpectedEvents.length) ? gExpectedEvents[gEventNum] : "NoEvent";
42 is(evt.type, expected, gTestName+" - events received in order");
43 gEventNum++;
44 if (gEventNum == gExpectedEvents.length) {
45 setTimeout(nextTest, 0);
46 }
47 }
49 function source_error(evt) {
50 log('event source_error');
51 ok(evt.type == "error", "Should only get error events here");
52 ok(gEventNum < gExpectedEvents.length, gTestName+" - corrent number of events received");
53 var expected = (gEventNum < gExpectedEvents.length) ? gExpectedEvents[gEventNum] : "NoEvent";
54 is("source_error", expected, gTestName+" - events received in order");
55 gEventNum++;
56 if (gEventNum == gExpectedEvents.length) {
57 setTimeout(nextTest, 0);
58 }
59 }
61 var gMedia = null;
63 function createMedia(tag) {
64 gMedia = document.createElement(tag);
65 gMedia.preload = "auto";
66 for (var i=0; i<gEventTypes.length; i++) {
67 gMedia.addEventListener(gEventTypes[i], listener, false);
68 }
69 }
71 function addSource(src, type) {
72 var s = document.createElement("source");
73 s.addEventListener("error", source_error, false);
74 s.src = src;
75 s.type = type;
76 gMedia.appendChild(s);
77 return s;
78 }
80 function prependSource(src, type) {
81 var s = document.createElement("source");
82 s.addEventListener("error", source_error, false);
83 s.src = src;
84 s.type = type;
85 gMedia.insertBefore(s, gMedia.firstChild);
86 return s;
87 }
89 var gTests = [
90 {
91 // Test 0: adding video to doc, then setting src should load implicitly.
92 create:
93 function(src, type) {
94 document.body.appendChild(gMedia);
95 gMedia.src = src;
96 },
97 expectedEvents: ['ratechange', 'loadstart', 'durationchange', 'loadedmetadata', 'loadeddata']
98 }, {
99 // Test 1: adding video to doc, then adding source.
100 create:
101 function(src, type) {
102 document.body.appendChild(gMedia);
103 addSource(src, type);
104 },
105 expectedEvents: ['loadstart', 'durationchange', 'loadedmetadata', 'loadeddata']
106 },{
107 // Test 2: video with multiple source, the first of which are bad, we should load the last,
108 // and receive error events for failed loads on the source children.
109 create:
110 function(src, type) {
111 document.body.appendChild(gMedia);
112 addSource("404a", type);
113 addSource("404b", type);
114 addSource(src, type);
115 },
116 expectedEvents: ['loadstart', 'source_error', 'source_error', 'durationchange', 'loadedmetadata', 'loadeddata']
117 }, {
118 // Test 3: video with bad src, good <source>, ensure that <source> aren't used.
119 create:
120 function(src, type) {
121 gMedia.src = "404a";
122 addSource(src, type);
123 document.body.appendChild(gMedia);
124 },
125 expectedEvents: ['ratechange', 'loadstart', 'error']
126 }, {
127 // Test 4: video with only bad source, loading, then adding a good source
128 // - should resume load.
129 create:
130 function(src, type) {
131 addSource("404a", type);
132 var s2 = addSource("404b", type);
133 s2.addEventListener("error",
134 function(e) {
135 // Should awaken waiting load, causing successful load.
136 addSource(src, type);
137 },
138 false);
139 document.body.appendChild(gMedia);
140 },
141 expectedEvents: ['loadstart', 'source_error', 'source_error', 'durationchange', 'loadedmetadata', 'loadeddata']
142 }, {
143 // Test 5: video with only 1 bad source, let it fail to load, then prepend
144 // a good <source> to the video, it shouldn't be selected, because the
145 // "pointer" should be after the last child - the bad source.
146 prepended: false,
147 create:
148 function(src, type) {
149 var prepended = false;
150 addSource("404a", type);
151 var s2 = addSource("404b", type);
152 s2.addEventListener("error",
153 function(e) {
154 // Should awaken waiting load, causing successful load.
155 if (!prepended) {
156 prependSource(src, type);
157 prepended = true;
158 }
159 },
160 false);
161 document.body.appendChild(gMedia);
162 },
163 expectedEvents: ['loadstart', 'source_error', 'source_error']
164 }
165 ];
167 function nextTest() {
168 if (gMedia) {
169 for (var i=0; i<gEventTypes.length; i++) {
170 gMedia.removeEventListener(gEventTypes[i], listener, false);
171 }
172 removeNodeAndSource(gMedia);
173 gMedia = null;
174 }
175 gEventNum = 0;
177 if (gTestNum == gTests.length) {
178 gTestNum = 0;
179 ++gTestFileNum;
180 if (gTestFileNum == gSmallTests.length) {
181 SimpleTest.finish();
182 return;
183 }
184 }
186 var src = gSmallTests[gTestFileNum].name;
187 var type = gSmallTests[gTestFileNum].type;
189 var t = gTests[gTestNum];
190 gTestNum++;
192 createMedia(type.match(/^audio\//) ? "audio" : "video");
193 if (!gMedia.canPlayType(type)) {
194 // Unsupported type, skip to next test
195 nextTest();
196 return;
197 }
199 gTestName = "Test " + src + " " + (gTestNum - 1);
200 log("Starting " + gTestName);
201 gExpectedEvents = t.expectedEvents;
203 t.create(src, type);
204 }
206 addLoadEvent(nextTest);
207 SimpleTest.waitForExplicitFinish();
209 </script>
210 </pre>
212 <div id="log" style="font-size: small"></div>
213 </body>
214 </html>