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=478957 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <title>Test for Bug 478957</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="text/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=478957">Mozilla Bug 478957</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 | |
michael@0 | 19 | <div id="log" style="font-size: small;"></div> |
michael@0 | 20 | |
michael@0 | 21 | <pre id="test"> |
michael@0 | 22 | <script type="application/javascript"> |
michael@0 | 23 | |
michael@0 | 24 | /** Test for Bug 478957 **/ |
michael@0 | 25 | |
michael@0 | 26 | // Tests whether we leak events and state change info when loading stuff from local files from a webserver. |
michael@0 | 27 | |
michael@0 | 28 | var manager = new MediaTestManager; |
michael@0 | 29 | |
michael@0 | 30 | var gEventTypes = [ 'loadstart', 'progress', 'suspend', 'abort', 'error', 'emptied', 'stalled', 'play', 'pause', 'loadedmetadata', 'loadeddata', 'waiting', 'playing', 'canplay', 'canplaythrough', 'seeking', 'seeked', 'timeupdate', 'ended', 'ratechange', 'durationchange', 'volumechange' ]; |
michael@0 | 31 | |
michael@0 | 32 | var gExpectedEvents = ['ratechange', 'loadstart', 'error']; |
michael@0 | 33 | |
michael@0 | 34 | function createTestArray() { |
michael@0 | 35 | var tests = []; |
michael@0 | 36 | var tmpVid = document.createElement("video"); |
michael@0 | 37 | |
michael@0 | 38 | for (var testNum=0; testNum<gInfoLeakTests.length; testNum++) { |
michael@0 | 39 | var test = gInfoLeakTests[testNum]; |
michael@0 | 40 | if (!tmpVid.canPlayType(test.type)) { |
michael@0 | 41 | continue; |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | var t = new Object; |
michael@0 | 45 | t.name = test.src; |
michael@0 | 46 | t.type = test.type; |
michael@0 | 47 | |
michael@0 | 48 | tests.push(t); |
michael@0 | 49 | } |
michael@0 | 50 | return tests; |
michael@0 | 51 | } |
michael@0 | 52 | |
michael@0 | 53 | function log(msg) { |
michael@0 | 54 | //dump(msg + "\n"); |
michael@0 | 55 | var l = document.getElementById('log'); |
michael@0 | 56 | l.innerHTML += msg + "<br>"; |
michael@0 | 57 | } |
michael@0 | 58 | |
michael@0 | 59 | function finish(v) { |
michael@0 | 60 | log("finish: " + v.name); |
michael@0 | 61 | v.parentNode.removeChild(v); |
michael@0 | 62 | clearInterval(v.checkStateInterval); |
michael@0 | 63 | manager.finished(v.token); |
michael@0 | 64 | v = null; |
michael@0 | 65 | } |
michael@0 | 66 | |
michael@0 | 67 | function listener(evt) { |
michael@0 | 68 | var v = evt.target; |
michael@0 | 69 | //log(filename(v.name) + ' got event ' + evt.type); |
michael@0 | 70 | ok(v.eventNum < gExpectedEvents.length, filename(v.name) + " Too many events received"); |
michael@0 | 71 | var expected = (v.eventNum < gExpectedEvents.length) ? gExpectedEvents[v.eventNum] : "NoEvent"; |
michael@0 | 72 | is(evt.type, expected, filename(v.name) + " Events received in wrong order"); |
michael@0 | 73 | v.eventNum++; |
michael@0 | 74 | if (v.eventNum == gExpectedEvents.length) { |
michael@0 | 75 | // In one second, move onto the next test. This give a chance for any |
michael@0 | 76 | // other events to come in. Note: we don't expect any events to come |
michael@0 | 77 | // in, unless we've leaked some info, and 1 second should be enough time |
michael@0 | 78 | // for the leak to show up. |
michael@0 | 79 | setTimeout(function() {finish(v);}, 1000); |
michael@0 | 80 | } |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | function createMedia(type, src, token) { |
michael@0 | 84 | var tag = getMajorMimeType(test.type); |
michael@0 | 85 | var v = document.createElement(tag); |
michael@0 | 86 | for (var i=0; i<gEventTypes.length; i++) { |
michael@0 | 87 | v.addEventListener(gEventTypes[i], listener, false); |
michael@0 | 88 | } |
michael@0 | 89 | v.src = src; |
michael@0 | 90 | v.name = src; |
michael@0 | 91 | document.body.appendChild(v); |
michael@0 | 92 | v.eventNum = 0; |
michael@0 | 93 | v.token = token; |
michael@0 | 94 | setTimeout( |
michael@0 | 95 | function() { |
michael@0 | 96 | v.checkStateInterval = setInterval(function(){checkState(v);},1); |
michael@0 | 97 | }, 0); |
michael@0 | 98 | } |
michael@0 | 99 | |
michael@0 | 100 | // Define our own ok() and is() functions. The mochitest ones take ages constructing the log |
michael@0 | 101 | // of all the passes, so only report failures. |
michael@0 | 102 | function test_ok(b, msg) { |
michael@0 | 103 | if (!b) { |
michael@0 | 104 | log("FAILED test_ok: " + msg); |
michael@0 | 105 | ok(b, msg); |
michael@0 | 106 | } |
michael@0 | 107 | } |
michael@0 | 108 | |
michael@0 | 109 | function test_is(a, b, msg) { |
michael@0 | 110 | if (a != b) { |
michael@0 | 111 | log("FAILED test_is: " + msg); |
michael@0 | 112 | is(a,b,msg); |
michael@0 | 113 | } |
michael@0 | 114 | } |
michael@0 | 115 | |
michael@0 | 116 | function filename(uri) { |
michael@0 | 117 | return uri.substr(uri.lastIndexOf("/")+1); |
michael@0 | 118 | } |
michael@0 | 119 | |
michael@0 | 120 | function checkState(v) { |
michael@0 | 121 | test_ok(v.networkState <= HTMLMediaElement.NETWORK_LOADING || |
michael@0 | 122 | v.networkState == HTMLMediaElement.NETWORK_NO_SOURCE, |
michael@0 | 123 | "NetworkState of " + v.networkState + " was leaked."); |
michael@0 | 124 | test_ok(v.readyState == HTMLMediaElement.HAVE_NOTHING, |
michael@0 | 125 | "Ready state of " + v.readyState + " was leaked"); |
michael@0 | 126 | test_is(v.seeking, false, "Seeking leaked"); |
michael@0 | 127 | test_is(v.currentTime, 0, "Leaked currentTime"); |
michael@0 | 128 | test_ok(isNaN(v.duration), "Leaked duration"); |
michael@0 | 129 | test_is(v.paused, true, "Paused leaked"); |
michael@0 | 130 | test_is(v.ended, false, "Ended leaked"); |
michael@0 | 131 | test_is(v.autoplay, false, "Autoplay leaked"); |
michael@0 | 132 | test_is(v.controls, false, "Controls leaked"); |
michael@0 | 133 | test_is(v.muted, false, "muted leaked"); |
michael@0 | 134 | test_ok(v.error==null || v.error.code==MediaError.MEDIA_ERR_SRC_NOT_SUPPORTED, |
michael@0 | 135 | "Error code should not exist or be SRC_NOT_SUPPORTED. v.error=" + |
michael@0 | 136 | (v.error ? v.error.code : "null")); |
michael@0 | 137 | test_ok(filename(v.currentSrc) == filename(v.name) || |
michael@0 | 138 | v.networkState == HTMLMediaElement.NETWORK_NO_SOURCE, |
michael@0 | 139 | "currentSrc should match candidate uri, if we've got a valid source"); |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | |
michael@0 | 143 | function startTest(test, token) { |
michael@0 | 144 | manager.started(token); |
michael@0 | 145 | log("Testing: " + test.type + " @ " + test.name); |
michael@0 | 146 | createMedia(test.type, test.name, token); |
michael@0 | 147 | } |
michael@0 | 148 | |
michael@0 | 149 | manager.runTests(createTestArray(), startTest); |
michael@0 | 150 | |
michael@0 | 151 | </script> |
michael@0 | 152 | </pre> |
michael@0 | 153 | |
michael@0 | 154 | </body> |
michael@0 | 155 | </html> |