content/media/test/test_load.html

Tue, 06 Jan 2015 21:39:09 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Tue, 06 Jan 2015 21:39:09 +0100
branch
TOR_BUG_9701
changeset 8
97036ab72558
permissions
-rw-r--r--

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.

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

mercurial