Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | <!DOCTYPE HTML> |
michael@0 | 2 | <html> |
michael@0 | 3 | <!-- |
michael@0 | 4 | https://bugzilla.mozilla.org/show_bug.cgi?id=677638 |
michael@0 | 5 | --> |
michael@0 | 6 | <head> |
michael@0 | 7 | <meta charset="utf-8"> |
michael@0 | 8 | <title>Test for Bug 677638 - start/close</title> |
michael@0 | 9 | <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 10 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
michael@0 | 11 | </head> |
michael@0 | 12 | <body> |
michael@0 | 13 | <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=677638">Mozilla Bug 677638</a> |
michael@0 | 14 | <div id="content"></div> |
michael@0 | 15 | <pre id="test"> |
michael@0 | 16 | </pre> |
michael@0 | 17 | <script type="application/javascript"> |
michael@0 | 18 | |
michael@0 | 19 | function runTests() { |
michael@0 | 20 | if (!tests.length) { |
michael@0 | 21 | SimpleTest.finish(); |
michael@0 | 22 | return; |
michael@0 | 23 | } |
michael@0 | 24 | |
michael@0 | 25 | var test = tests.shift(); |
michael@0 | 26 | test(); |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | function testOnMessage() { |
michael@0 | 30 | var a = new MessageChannel(); |
michael@0 | 31 | ok(a, "MessageChannel created"); |
michael@0 | 32 | |
michael@0 | 33 | a.port1.postMessage(42); |
michael@0 | 34 | a.port2.postMessage(43); |
michael@0 | 35 | ok(true, "MessagePort{1,2}.postmessage() invoked"); |
michael@0 | 36 | |
michael@0 | 37 | var events = 2; |
michael@0 | 38 | |
michael@0 | 39 | a.port1.onmessage = function(evt) { |
michael@0 | 40 | ok(true, "This method should be called"); |
michael@0 | 41 | if (!--events) runTests(); |
michael@0 | 42 | } |
michael@0 | 43 | |
michael@0 | 44 | a.port2.onmessage = function(evt) { |
michael@0 | 45 | ok(true, "This method should be called"); |
michael@0 | 46 | if (!--events) runTests(); |
michael@0 | 47 | } |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function testAddEventListener() { |
michael@0 | 51 | var a = new MessageChannel(); |
michael@0 | 52 | ok(a, "MessageChannel created"); |
michael@0 | 53 | |
michael@0 | 54 | a.port1.postMessage(42); |
michael@0 | 55 | a.port2.postMessage(43); |
michael@0 | 56 | ok(true, "MessagePort{1,2}.postmessage() invoked"); |
michael@0 | 57 | |
michael@0 | 58 | a.port1.addEventListener('message', function(evt) { |
michael@0 | 59 | ok(false, "This method should not be called"); |
michael@0 | 60 | }, false); |
michael@0 | 61 | |
michael@0 | 62 | a.port2.addEventListener('message', function(evt) { |
michael@0 | 63 | ok(false, "This method should not be called"); |
michael@0 | 64 | }, false); |
michael@0 | 65 | |
michael@0 | 66 | setTimeout(runTests, 0); |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | function testAddEventListenerAndStart() { |
michael@0 | 70 | var a = new MessageChannel(); |
michael@0 | 71 | ok(a, "MessageChannel created"); |
michael@0 | 72 | |
michael@0 | 73 | a.port1.postMessage(42); |
michael@0 | 74 | a.port2.postMessage(43); |
michael@0 | 75 | ok(true, "MessagePort{1,2}.postmessage() invoked"); |
michael@0 | 76 | |
michael@0 | 77 | var events = 2; |
michael@0 | 78 | |
michael@0 | 79 | a.port1.addEventListener('message', function(evt) { |
michael@0 | 80 | ok(true, "This method should be called"); |
michael@0 | 81 | if (!--events) runTests(); |
michael@0 | 82 | }, false); |
michael@0 | 83 | |
michael@0 | 84 | a.port2.addEventListener('message', function(evt) { |
michael@0 | 85 | ok(true, "This method should be called"); |
michael@0 | 86 | if (!--events) runTests(); |
michael@0 | 87 | }, false); |
michael@0 | 88 | |
michael@0 | 89 | a.port1.start(); |
michael@0 | 90 | a.port2.start(); |
michael@0 | 91 | } |
michael@0 | 92 | |
michael@0 | 93 | function testAddEventListener1AndStart() { |
michael@0 | 94 | var a = new MessageChannel(); |
michael@0 | 95 | ok(a, "MessageChannel created"); |
michael@0 | 96 | |
michael@0 | 97 | a.port1.postMessage(42); |
michael@0 | 98 | a.port2.postMessage(43); |
michael@0 | 99 | ok(true, "MessagePort{1,2}.postmessage() invoked"); |
michael@0 | 100 | |
michael@0 | 101 | var events = 1; |
michael@0 | 102 | |
michael@0 | 103 | a.port1.addEventListener('message', function(evt) { |
michael@0 | 104 | ok(true, "This method should be called"); |
michael@0 | 105 | if (!--events) runTests(); |
michael@0 | 106 | }, false); |
michael@0 | 107 | |
michael@0 | 108 | a.port2.addEventListener('message', function(evt) { |
michael@0 | 109 | ok(false, "This method should not be called"); |
michael@0 | 110 | }, false); |
michael@0 | 111 | |
michael@0 | 112 | a.port1.start(); |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | function testAddEventListener2AndStart() { |
michael@0 | 116 | var a = new MessageChannel(); |
michael@0 | 117 | ok(a, "MessageChannel created"); |
michael@0 | 118 | |
michael@0 | 119 | a.port1.postMessage(42); |
michael@0 | 120 | a.port2.postMessage(43); |
michael@0 | 121 | ok(true, "MessagePort{1,2}.postmessage() invoked"); |
michael@0 | 122 | |
michael@0 | 123 | var events = 1; |
michael@0 | 124 | |
michael@0 | 125 | a.port1.addEventListener('message', function(evt) { |
michael@0 | 126 | ok(false, "This method should not be called"); |
michael@0 | 127 | }, false); |
michael@0 | 128 | |
michael@0 | 129 | a.port2.addEventListener('message', function(evt) { |
michael@0 | 130 | ok(true, "This method should be called"); |
michael@0 | 131 | if (!--events) runTests(); |
michael@0 | 132 | }, false); |
michael@0 | 133 | |
michael@0 | 134 | a.port2.start(); |
michael@0 | 135 | } |
michael@0 | 136 | |
michael@0 | 137 | function testTimer() { |
michael@0 | 138 | var a = new MessageChannel(); |
michael@0 | 139 | ok(a, "MessageChannel created"); |
michael@0 | 140 | |
michael@0 | 141 | a.port1.postMessage(42); |
michael@0 | 142 | a.port2.postMessage(43); |
michael@0 | 143 | ok(true, "MessagePort{1,2}.postmessage() invoked"); |
michael@0 | 144 | |
michael@0 | 145 | setTimeout(function() { |
michael@0 | 146 | var events = 2; |
michael@0 | 147 | a.port1.onmessage = function(evt) { |
michael@0 | 148 | ok(true, "This method should be called"); |
michael@0 | 149 | if (!--events) runTests(); |
michael@0 | 150 | } |
michael@0 | 151 | |
michael@0 | 152 | a.port2.onmessage = function(evt) { |
michael@0 | 153 | ok(true, "This method should be called"); |
michael@0 | 154 | if (!--events) runTests(); |
michael@0 | 155 | } |
michael@0 | 156 | }, 200); |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | function testAddEventListenerAndStartWrongOrder() { |
michael@0 | 160 | var a = new MessageChannel(); |
michael@0 | 161 | ok(a, "MessageChannel created"); |
michael@0 | 162 | |
michael@0 | 163 | a.port1.postMessage(42); |
michael@0 | 164 | a.port2.postMessage(43); |
michael@0 | 165 | ok(true, "MessagePort{1,2}.postmessage() invoked"); |
michael@0 | 166 | |
michael@0 | 167 | var events = 2; |
michael@0 | 168 | |
michael@0 | 169 | a.port1.start(); |
michael@0 | 170 | a.port1.addEventListener('message', function(evt) { |
michael@0 | 171 | ok(true, "This method should be called"); |
michael@0 | 172 | if (!--events) runTests(); |
michael@0 | 173 | }, false); |
michael@0 | 174 | |
michael@0 | 175 | a.port2.start(); |
michael@0 | 176 | a.port2.addEventListener('message', function(evt) { |
michael@0 | 177 | ok(true, "This method should be called"); |
michael@0 | 178 | if (!--events) runTests(); |
michael@0 | 179 | }, false); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | function testOnMessageClone() { |
michael@0 | 183 | var a = new MessageChannel(); |
michael@0 | 184 | ok(a, "MessageChannel created"); |
michael@0 | 185 | |
michael@0 | 186 | a.port1.postMessage(42); |
michael@0 | 187 | a.port2.postMessage(43); |
michael@0 | 188 | ok(true, "MessagePort{1,2}.postmessage() invoked"); |
michael@0 | 189 | |
michael@0 | 190 | var events = 2; |
michael@0 | 191 | |
michael@0 | 192 | addEventListener('message', testOnMessageCloneCb, false); |
michael@0 | 193 | function testOnMessageCloneCb(evt) { |
michael@0 | 194 | a.port1.onmessage = function(evt) { |
michael@0 | 195 | ok(true, "This method should be called"); |
michael@0 | 196 | testOnMessageCloneFinish(); |
michael@0 | 197 | } |
michael@0 | 198 | |
michael@0 | 199 | evt.data.onmessage = function(evt) { |
michael@0 | 200 | ok(true, "This method should be called"); |
michael@0 | 201 | testOnMessageCloneFinish(); |
michael@0 | 202 | } |
michael@0 | 203 | |
michael@0 | 204 | a.port2.onmessage = function(evt) { |
michael@0 | 205 | ok(false, "This method should not be called"); |
michael@0 | 206 | } |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | function testOnMessageCloneFinish() { |
michael@0 | 210 | if (!--events) { |
michael@0 | 211 | removeEventListener('message', testOnMessageCloneCb); |
michael@0 | 212 | runTests(); |
michael@0 | 213 | } |
michael@0 | 214 | } |
michael@0 | 215 | |
michael@0 | 216 | postMessage(a.port2, '*', [a.port2]); |
michael@0 | 217 | } |
michael@0 | 218 | |
michael@0 | 219 | var tests = [ |
michael@0 | 220 | testOnMessage, |
michael@0 | 221 | testAddEventListener, |
michael@0 | 222 | testAddEventListenerAndStart, |
michael@0 | 223 | testAddEventListener1AndStart, |
michael@0 | 224 | testAddEventListener2AndStart, |
michael@0 | 225 | testTimer, |
michael@0 | 226 | testAddEventListenerAndStartWrongOrder, |
michael@0 | 227 | testOnMessageClone, |
michael@0 | 228 | ]; |
michael@0 | 229 | |
michael@0 | 230 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 231 | SpecialPowers.pushPrefEnv({"set": [["dom.messageChannel.enabled", true]]}, runTests); |
michael@0 | 232 | </script> |
michael@0 | 233 | </body> |
michael@0 | 234 | </html> |