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 | <?xml version="1.0"?> |
michael@0 | 2 | <!-- This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 3 | - License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 4 | - file, You can obtain one at http://mozilla.org/MPL/2.0/. --> |
michael@0 | 5 | |
michael@0 | 6 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
michael@0 | 7 | <window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 8 | width="800" height="800" orient="vertical" onload="initRemoteFrameScript();"> |
michael@0 | 9 | <script> |
michael@0 | 10 | |
michael@0 | 11 | function dumpClientRect(r) { |
michael@0 | 12 | dump(r.left + "," + r.top + "," + r.right + "," + |
michael@0 | 13 | r.bottom + "," + r.width + "," + r.height + "\n"); |
michael@0 | 14 | } |
michael@0 | 15 | |
michael@0 | 16 | function handleMozAfterPaint(e) { |
michael@0 | 17 | return; |
michael@0 | 18 | dump(e.type + "\n") |
michael@0 | 19 | var rects = e.clientRects; |
michael@0 | 20 | var i; |
michael@0 | 21 | dump("\tclientRects:\n"); |
michael@0 | 22 | for (i = 0; i < rects.length; ++i) { |
michael@0 | 23 | var r = rects.item(i); |
michael@0 | 24 | dump("\t\t"); |
michael@0 | 25 | dumpClientRect(rects.item(i)); |
michael@0 | 26 | } |
michael@0 | 27 | |
michael@0 | 28 | dump("\tboundingClientRect\n\t\t"); |
michael@0 | 29 | dumpClientRect(e.boundingClientRect); |
michael@0 | 30 | |
michael@0 | 31 | var paintRequests = e.paintRequests; |
michael@0 | 32 | dump("\tpaintRequests\n"); |
michael@0 | 33 | for (i = 0; i < paintRequests.length; ++i) { |
michael@0 | 34 | var pr = paintRequests.item(i); |
michael@0 | 35 | dump("\t\t"); |
michael@0 | 36 | dumpClientRect(pr.clientRect); |
michael@0 | 37 | if (pr.reason) |
michael@0 | 38 | dump("\t\t" + pr.reason + "\n"); |
michael@0 | 39 | } |
michael@0 | 40 | } |
michael@0 | 41 | |
michael@0 | 42 | function handleMozScrolledAreaChanged(e) { |
michael@0 | 43 | return; |
michael@0 | 44 | dump(e.type + "\n"); |
michael@0 | 45 | dump("\t" + e.x + "," + e.y + "," + e.width + "," + e.height + "\n"); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | function restart() { |
michael@0 | 49 | var y = document.getElementById('page'); |
michael@0 | 50 | var p = y.parentNode; |
michael@0 | 51 | p.removeChild(y); |
michael@0 | 52 | p.appendChild(y); |
michael@0 | 53 | |
michael@0 | 54 | var fl = y.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader; |
michael@0 | 55 | fl.activateFrameEvent("MozAfterPaint", true); |
michael@0 | 56 | fl.activateFrameEvent("MozScrolledAreaChanged", true); |
michael@0 | 57 | y.addEventListener("MozAfterPaint", handleMozAfterPaint, true); |
michael@0 | 58 | y.addEventListener("MozScrolledAreaChanged", handleMozScrolledAreaChanged, true); |
michael@0 | 59 | } |
michael@0 | 60 | |
michael@0 | 61 | function loadURL(url) { |
michael@0 | 62 | document.getElementById('page').setAttribute('src', url); |
michael@0 | 63 | } |
michael@0 | 64 | |
michael@0 | 65 | function randomClick() { |
michael@0 | 66 | // First focus the remote frame, then dispatch click. This way remote frame gets focus before |
michael@0 | 67 | // mouse event. |
michael@0 | 68 | document.getElementById('page').focus(); |
michael@0 | 69 | var frameLoader = document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader; |
michael@0 | 70 | var x = parseInt(Math.random() * 100); |
michael@0 | 71 | var y = parseInt(Math.random() * 100); |
michael@0 | 72 | frameLoader.sendCrossProcessMouseEvent("mousedown", x, y, 0, 1, 0, false); |
michael@0 | 73 | frameLoader.sendCrossProcessMouseEvent("mouseup", x, y, 0, 1, 0, false); |
michael@0 | 74 | } |
michael@0 | 75 | |
michael@0 | 76 | function keyPress() { |
michael@0 | 77 | // First focus the remote frame, then dispatch click. This way remote frame gets focus before |
michael@0 | 78 | // mouse event. |
michael@0 | 79 | document.getElementById('page').focus(); |
michael@0 | 80 | var frameLoader = document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader; |
michael@0 | 81 | |
michael@0 | 82 | var keyCode = Components.interfaces.nsIDOMKeyEvent.DOM_VK_A; |
michael@0 | 83 | frameLoader.sendCrossProcessKeyEvent("keydown", keyCode, 0, 0); |
michael@0 | 84 | frameLoader.sendCrossProcessKeyEvent("keypress", keyCode, 0, 0); |
michael@0 | 85 | frameLoader.sendCrossProcessKeyEvent("keyup", keyCode, 0, 0); |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | function openWindow() { |
michael@0 | 89 | window.open('chrome://global/content/test-ipc.xul', '_blank', 'chrome,resizable,width=800,height=800'); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function closeWindow() { |
michael@0 | 93 | window.close(); |
michael@0 | 94 | } |
michael@0 | 95 | |
michael@0 | 96 | function initRemoteFrameScript() { |
michael@0 | 97 | // 1. Test that loading a script works, and that accessing process level mm and |
michael@0 | 98 | // global mm works. |
michael@0 | 99 | var ppm = Components.classes["@mozilla.org/parentprocessmessagemanager;1"] |
michael@0 | 100 | .getService(Components.interfaces.nsIMessageBroadcaster); |
michael@0 | 101 | var gm = Components.classes["@mozilla.org/globalmessagemanager;1"] |
michael@0 | 102 | .getService(Components.interfaces.nsIMessageBroadcaster); |
michael@0 | 103 | var cpm = Components.classes["@mozilla.org/childprocessmessagemanager;1"] |
michael@0 | 104 | .getService(Components.interfaces.nsISyncMessageSender); |
michael@0 | 105 | |
michael@0 | 106 | if (ppm.childCount != 2) { |
michael@0 | 107 | alert("Should have two child processes!"); |
michael@0 | 108 | } |
michael@0 | 109 | var childprocessmm = ppm.getChildAt(1); // 0 is the in-process child process mm |
michael@0 | 110 | |
michael@0 | 111 | childprocessmm.addMessageListener("ppm-sync", |
michael@0 | 112 | function(m) { |
michael@0 | 113 | if (m.target != childprocessmm) alert("Wrong target!"); |
michael@0 | 114 | document.getElementById("messageLog").value += "[SYNC1 PPM]"; |
michael@0 | 115 | } |
michael@0 | 116 | ); |
michael@0 | 117 | |
michael@0 | 118 | ppm.addMessageListener("ppm-sync", |
michael@0 | 119 | function(m) { |
michael@0 | 120 | // Check that global process message manager gets the per-process mm as target. |
michael@0 | 121 | if (m.target != childprocessmm) alert("Wrong target!"); |
michael@0 | 122 | document.getElementById("messageLog").value += "[SYNC2 PPM]"; |
michael@0 | 123 | } |
michael@0 | 124 | ); |
michael@0 | 125 | childprocessmm.addMessageListener("ppm-async", |
michael@0 | 126 | function(m) { |
michael@0 | 127 | if (m.target != childprocessmm) alert("Wrong target!"); |
michael@0 | 128 | document.getElementById("messageLog").value += "[ASYNC1 PPM]"; |
michael@0 | 129 | } |
michael@0 | 130 | ); |
michael@0 | 131 | ppm.addMessageListener("ppm-async", |
michael@0 | 132 | function(m) { |
michael@0 | 133 | // Check that global process message manager gets the per-process mm as target. |
michael@0 | 134 | if (m.target != childprocessmm) alert("Wrong target!"); |
michael@0 | 135 | document.getElementById("messageLog").value += "[ASYNC2 PPM]"; |
michael@0 | 136 | } |
michael@0 | 137 | ); |
michael@0 | 138 | messageManager.loadFrameScript("chrome://global/content/remote-test-ipc.js", true); |
michael@0 | 139 | ppm.sendAsyncMessage("cpm-async"); |
michael@0 | 140 | |
michael@0 | 141 | // 2. Test that adding message listener works, and that receiving a sync message works. |
michael@0 | 142 | messageManager.addMessageListener("linkclick", |
michael@0 | 143 | function(m) { |
michael@0 | 144 | // This checks that json sending works in sync messages. |
michael@0 | 145 | document.getElementById("messageLog").value = m.name + ": " + m.json.href; |
michael@0 | 146 | return { message: "linkclick-received" }; |
michael@0 | 147 | }); |
michael@0 | 148 | |
michael@0 | 149 | // 3. Test that returning multiple json results works. |
michael@0 | 150 | messageManager.addMessageListener("linkclick", |
michael@0 | 151 | function(m) { |
michael@0 | 152 | return { message: "linkclick-received" }; |
michael@0 | 153 | }); |
michael@0 | 154 | |
michael@0 | 155 | // 4. Test that receiving an async message works. |
michael@0 | 156 | // Test also that sending async message to content works. |
michael@0 | 157 | // Test also that { receiveMessage: function(m) {} } works. |
michael@0 | 158 | messageManager.addMessageListener("linkclick-reply-object", |
michael@0 | 159 | { foobarObjectVar: true, |
michael@0 | 160 | receiveMessage: function(m) { |
michael@0 | 161 | var s = (m.json.message == "linkclick-received") && |
michael@0 | 162 | (this.foobarObjectVar) ? "PASS" : "FAIL"; |
michael@0 | 163 | messageManager.broadcastAsyncMessage("chrome-message", { ok : s } ); |
michael@0 | 164 | } |
michael@0 | 165 | } |
michael@0 | 166 | ); |
michael@0 | 167 | |
michael@0 | 168 | // 5. Final test to check that everything went ok. |
michael@0 | 169 | messageManager.addMessageListener("chrome-message-reply", |
michael@0 | 170 | function(m) { |
michael@0 | 171 | // Check that 'this' and .target values are handled correctly |
michael@0 | 172 | if (m.target == document.getElementById("page") && |
michael@0 | 173 | this == messageManager) { |
michael@0 | 174 | // Check that the message properties are enumerable. |
michael@0 | 175 | var hasName = false; |
michael@0 | 176 | var hasSync = false; |
michael@0 | 177 | var hasJSON = false; |
michael@0 | 178 | for (i in m) { |
michael@0 | 179 | if (i == "name") { |
michael@0 | 180 | hasName = true; |
michael@0 | 181 | } else if (i == "sync") { |
michael@0 | 182 | hasSync = true; |
michael@0 | 183 | } else if (i == "json") { |
michael@0 | 184 | hasJSON = true; |
michael@0 | 185 | } |
michael@0 | 186 | } |
michael@0 | 187 | if (hasName && hasSync && hasJSON) { |
michael@0 | 188 | document.getElementById("messageLog").value += ", " + m.json.ok; |
michael@0 | 189 | } |
michael@0 | 190 | } |
michael@0 | 191 | }); |
michael@0 | 192 | } |
michael@0 | 193 | |
michael@0 | 194 | var speedTestStartTime = 0; |
michael@0 | 195 | var speedTestCount = 0; |
michael@0 | 196 | function messageSpeed() { |
michael@0 | 197 | speedTestCount = 0; |
michael@0 | 198 | messageManager.addMessageListener("speed-test", speedHandler); |
michael@0 | 199 | messageManager.broadcastAsyncMessage("speed-test-start"); |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | function speedHandler() { |
michael@0 | 203 | if (!speedTestCount) { |
michael@0 | 204 | speedTestStartTime = new Date().getTime(); |
michael@0 | 205 | } |
michael@0 | 206 | if (++speedTestCount == 1000) { |
michael@0 | 207 | setTimeout("alert('" + speedTestCount + " in " + (new Date().getTime() - speedTestStartTime) + "ms')", 0); |
michael@0 | 208 | return { message: "done" }; |
michael@0 | 209 | } |
michael@0 | 210 | return { message: "continue" }; |
michael@0 | 211 | } |
michael@0 | 212 | |
michael@0 | 213 | var addRemoveTestCount = 0; |
michael@0 | 214 | |
michael@0 | 215 | function echoListener() { |
michael@0 | 216 | if (++addRemoveTestCount == 1) { |
michael@0 | 217 | alert("Expected echo message"); |
michael@0 | 218 | messageManager.removeMessageListener("async-echo", echoListener); |
michael@0 | 219 | messageManager.broadcastAsyncMessage("async-echo"); |
michael@0 | 220 | return; |
michael@0 | 221 | } |
michael@0 | 222 | alert("Unexpected echo message"); |
michael@0 | 223 | } |
michael@0 | 224 | |
michael@0 | 225 | function listenerAddRemove() { |
michael@0 | 226 | addRemoveTestCount = 0; |
michael@0 | 227 | messageManager.addMessageListener("async-echo", echoListener); |
michael@0 | 228 | messageManager.broadcastAsyncMessage("async-echo"); |
michael@0 | 229 | } |
michael@0 | 230 | |
michael@0 | 231 | var MozAfterPaintCount = 0; |
michael@0 | 232 | function enableMozAfterPaint() { |
michael@0 | 233 | messageManager.addMessageListener("MozAfterPaint", |
michael@0 | 234 | function(m) { |
michael@0 | 235 | document.getElementById("messageLog").value = m.name + "[" + (++MozAfterPaintCount) + "]"; |
michael@0 | 236 | }); |
michael@0 | 237 | messageManager.loadFrameScript("data:,addEventListener('MozAfterPaint', function(e) { sendAsyncMessage('MozAfterPaint'); },true);", false); |
michael@0 | 238 | } |
michael@0 | 239 | |
michael@0 | 240 | var Ci = Components.interfaces; |
michael@0 | 241 | var Cu = Components.utils; |
michael@0 | 242 | Cu.import("resource://gre/modules/XPCOMUtils.jsm"); |
michael@0 | 243 | </script> |
michael@0 | 244 | |
michael@0 | 245 | <toolbar id="controls"> |
michael@0 | 246 | <toolbarbutton label="Back"/> |
michael@0 | 247 | <toolbarbutton label="Forward"/> |
michael@0 | 248 | <textbox onchange="loadURL(this.value)" flex="1" id="URL"/> |
michael@0 | 249 | </toolbar> |
michael@0 | 250 | <toolbar> |
michael@0 | 251 | <toolbarbutton onclick="restart()" label="Recover"/> |
michael@0 | 252 | <toolbarbutton onclick="randomClick()" label="random click"/> |
michael@0 | 253 | <toolbarbutton onclick="keyPress()" label="key press"/> |
michael@0 | 254 | <toolbarbutton onclick="messageSpeed()" label="test message handling speed"/> |
michael@0 | 255 | <toolbarbutton onclick="listenerAddRemove()" label="test listener add/remove"/> |
michael@0 | 256 | <toolbarbutton onclick="enableMozAfterPaint()" label="MozAfterPaint"/> |
michael@0 | 257 | <toolbarbutton onclick="openWindow()" label="open new window"/> |
michael@0 | 258 | <toolbarbutton onclick="closeWindow()" label="close this window"/> |
michael@0 | 259 | </toolbar> |
michael@0 | 260 | <toolbar><label value="Load a script (URL) to content process:"/> |
michael@0 | 261 | <textbox flex="1" id="script"/><button |
michael@0 | 262 | label="send" oncommand="document.getElementById('page') |
michael@0 | 263 | .QueryInterface(Components.interfaces.nsIFrameLoaderOwner) |
michael@0 | 264 | .frameLoader.messageManager |
michael@0 | 265 | .loadFrameScript(this.previousSibling.value, false);"/> |
michael@0 | 266 | </toolbar> |
michael@0 | 267 | <toolbar> |
michael@0 | 268 | <label value="Eval script in chrome context"/> |
michael@0 | 269 | <textbox flex="1"/><button label="run" oncommand="eval(this.previousSibling.value);"/> |
michael@0 | 270 | </toolbar> |
michael@0 | 271 | |
michael@0 | 272 | <browser type="content" src="http://www.google.com/" flex="1" id="page" remote="true"/> |
michael@0 | 273 | <label id="messageLog" value="" crop="center"/> |
michael@0 | 274 | </window> |