2009-07-01 00:39:22 +04:00
|
|
|
<?xml version="1.0"?>
|
2012-05-21 15:12:37 +04:00
|
|
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
|
|
|
|
2009-07-01 00:39:22 +04:00
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
2019-09-30 22:31:56 +03:00
|
|
|
xmlns:html="http://www.w3.org/1999/xhtml"
|
2010-02-20 20:05:20 +03:00
|
|
|
width="800" height="800" orient="vertical" onload="initRemoteFrameScript();">
|
2009-07-01 00:39:22 +04:00
|
|
|
<script>
|
2009-11-17 17:22:23 +03:00
|
|
|
|
|
|
|
function dumpClientRect(r) {
|
|
|
|
dump(r.left + "," + r.top + "," + r.right + "," +
|
|
|
|
r.bottom + "," + r.width + "," + r.height + "\n");
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleMozAfterPaint(e) {
|
|
|
|
return;
|
|
|
|
dump(e.type + "\n")
|
|
|
|
var rects = e.clientRects;
|
|
|
|
var i;
|
|
|
|
dump("\tclientRects:\n");
|
2019-11-27 18:39:16 +03:00
|
|
|
for (i = 0; i < rects.length; ++i) {
|
2009-11-17 17:22:23 +03:00
|
|
|
var r = rects.item(i);
|
|
|
|
dump("\t\t");
|
|
|
|
dumpClientRect(rects.item(i));
|
|
|
|
}
|
|
|
|
|
|
|
|
dump("\tboundingClientRect\n\t\t");
|
|
|
|
dumpClientRect(e.boundingClientRect);
|
|
|
|
|
|
|
|
var paintRequests = e.paintRequests;
|
|
|
|
dump("\tpaintRequests\n");
|
2019-11-27 18:39:16 +03:00
|
|
|
for (i = 0; i < paintRequests.length; ++i) {
|
2009-11-17 17:22:23 +03:00
|
|
|
var pr = paintRequests.item(i);
|
|
|
|
dump("\t\t");
|
|
|
|
dumpClientRect(pr.clientRect);
|
|
|
|
if (pr.reason)
|
|
|
|
dump("\t\t" + pr.reason + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function handleMozScrolledAreaChanged(e) {
|
|
|
|
return;
|
|
|
|
dump(e.type + "\n");
|
|
|
|
dump("\t" + e.x + "," + e.y + "," + e.width + "," + e.height + "\n");
|
|
|
|
}
|
|
|
|
|
2009-07-01 00:39:22 +04:00
|
|
|
function restart() {
|
|
|
|
var y = document.getElementById('page');
|
|
|
|
var p = y.parentNode;
|
|
|
|
p.removeChild(y);
|
|
|
|
p.appendChild(y);
|
2009-11-17 17:22:23 +03:00
|
|
|
|
2019-02-16 01:20:49 +03:00
|
|
|
var fl = y.frameLoader;
|
2009-11-17 17:22:23 +03:00
|
|
|
fl.activateFrameEvent("MozAfterPaint", true);
|
|
|
|
fl.activateFrameEvent("MozScrolledAreaChanged", true);
|
|
|
|
y.addEventListener("MozAfterPaint", handleMozAfterPaint, true);
|
|
|
|
y.addEventListener("MozScrolledAreaChanged", handleMozScrolledAreaChanged, true);
|
2009-07-01 00:39:22 +04:00
|
|
|
}
|
2020-06-18 01:45:31 +03:00
|
|
|
|
2009-07-01 00:39:22 +04:00
|
|
|
function loadURL(url) {
|
|
|
|
document.getElementById('page').setAttribute('src', url);
|
|
|
|
}
|
2009-11-05 21:21:09 +03:00
|
|
|
|
2009-11-13 15:43:43 +03:00
|
|
|
function openWindow() {
|
2019-11-27 18:39:16 +03:00
|
|
|
window.open('chrome://global/content/test-ipc.xhtml', '_blank', 'chrome,resizable,width=800,height=800');
|
2009-11-13 15:43:43 +03:00
|
|
|
}
|
2020-06-18 01:45:31 +03:00
|
|
|
|
2009-11-13 15:43:43 +03:00
|
|
|
function closeWindow() {
|
|
|
|
window.close();
|
|
|
|
}
|
2010-02-20 20:05:20 +03:00
|
|
|
|
|
|
|
function initRemoteFrameScript() {
|
2010-08-31 22:58:35 +04:00
|
|
|
// 1. Test that loading a script works, and that accessing process level mm and
|
|
|
|
// global mm works.
|
|
|
|
var ppm = Components.classes["@mozilla.org/parentprocessmessagemanager;1"]
|
2018-03-01 22:19:56 +03:00
|
|
|
.getService();
|
2010-08-31 22:58:35 +04:00
|
|
|
var gm = Components.classes["@mozilla.org/globalmessagemanager;1"]
|
2018-03-01 22:19:56 +03:00
|
|
|
.getService();
|
2011-10-11 14:28:46 +04:00
|
|
|
var cpm = Components.classes["@mozilla.org/childprocessmessagemanager;1"]
|
2018-03-01 22:19:56 +03:00
|
|
|
.getService();
|
2011-10-11 14:28:46 +04:00
|
|
|
|
2012-08-27 18:13:02 +04:00
|
|
|
if (ppm.childCount != 2) {
|
2011-10-11 14:28:46 +04:00
|
|
|
alert("Should have two child processes!");
|
2011-08-02 23:57:48 +04:00
|
|
|
}
|
2012-08-27 18:13:02 +04:00
|
|
|
var childprocessmm = ppm.getChildAt(1); // 0 is the in-process child process mm
|
2020-06-18 01:45:31 +03:00
|
|
|
|
2011-08-02 23:57:48 +04:00
|
|
|
childprocessmm.addMessageListener("ppm-sync",
|
|
|
|
function(m) {
|
|
|
|
if (m.target != childprocessmm) alert("Wrong target!");
|
2020-06-18 01:45:31 +03:00
|
|
|
document.getElementById("messageLog").value += "[SYNC1 PPM]";
|
2011-08-02 23:57:48 +04:00
|
|
|
}
|
|
|
|
);
|
2020-06-18 01:45:31 +03:00
|
|
|
|
2010-08-31 22:58:35 +04:00
|
|
|
ppm.addMessageListener("ppm-sync",
|
|
|
|
function(m) {
|
2011-08-02 23:57:48 +04:00
|
|
|
// Check that global process message manager gets the per-process mm as target.
|
|
|
|
if (m.target != childprocessmm) alert("Wrong target!");
|
2020-06-18 01:45:31 +03:00
|
|
|
document.getElementById("messageLog").value += "[SYNC2 PPM]";
|
2011-08-02 23:57:48 +04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
childprocessmm.addMessageListener("ppm-async",
|
|
|
|
function(m) {
|
|
|
|
if (m.target != childprocessmm) alert("Wrong target!");
|
2020-06-18 01:45:31 +03:00
|
|
|
document.getElementById("messageLog").value += "[ASYNC1 PPM]";
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
|
|
|
);
|
|
|
|
ppm.addMessageListener("ppm-async",
|
|
|
|
function(m) {
|
2011-08-02 23:57:48 +04:00
|
|
|
// Check that global process message manager gets the per-process mm as target.
|
|
|
|
if (m.target != childprocessmm) alert("Wrong target!");
|
2020-06-18 01:45:31 +03:00
|
|
|
document.getElementById("messageLog").value += "[ASYNC2 PPM]";
|
2010-08-31 22:58:35 +04:00
|
|
|
}
|
|
|
|
);
|
2010-02-20 20:05:20 +03:00
|
|
|
messageManager.loadFrameScript("chrome://global/content/remote-test-ipc.js", true);
|
2010-08-31 22:58:35 +04:00
|
|
|
ppm.sendAsyncMessage("cpm-async");
|
2010-02-20 20:05:20 +03:00
|
|
|
|
|
|
|
// 2. Test that adding message listener works, and that receiving a sync message works.
|
|
|
|
messageManager.addMessageListener("linkclick",
|
|
|
|
function(m) {
|
2020-06-18 01:45:31 +03:00
|
|
|
// This checks that json sending works in sync messages.
|
2010-06-18 01:10:14 +04:00
|
|
|
document.getElementById("messageLog").value = m.name + ": " + m.json.href;
|
|
|
|
return { message: "linkclick-received" };
|
2010-02-20 20:05:20 +03:00
|
|
|
});
|
|
|
|
|
|
|
|
// 3. Test that returning multiple json results works.
|
|
|
|
messageManager.addMessageListener("linkclick",
|
|
|
|
function(m) {
|
|
|
|
return { message: "linkclick-received" };
|
|
|
|
});
|
|
|
|
|
|
|
|
// 4. Test that receiving an async message works.
|
|
|
|
// Test also that sending async message to content works.
|
2010-03-05 14:00:43 +03:00
|
|
|
// Test also that { receiveMessage: function(m) {} } works.
|
2010-02-20 20:05:20 +03:00
|
|
|
messageManager.addMessageListener("linkclick-reply-object",
|
2010-03-05 14:00:43 +03:00
|
|
|
{ foobarObjectVar: true,
|
|
|
|
receiveMessage: function(m) {
|
2019-11-27 18:39:16 +03:00
|
|
|
var s = (m.json.message == "linkclick-received") &&
|
2010-03-05 14:00:43 +03:00
|
|
|
(this.foobarObjectVar) ? "PASS" : "FAIL";
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("chrome-message", { ok : s } );
|
2010-03-05 14:00:43 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2010-02-20 20:05:20 +03:00
|
|
|
|
|
|
|
// 5. Final test to check that everything went ok.
|
|
|
|
messageManager.addMessageListener("chrome-message-reply",
|
|
|
|
function(m) {
|
2010-03-30 00:29:45 +04:00
|
|
|
// Check that 'this' and .target values are handled correctly
|
2019-11-27 18:39:16 +03:00
|
|
|
if (m.target == document.getElementById("page") &&
|
2010-06-18 01:10:14 +04:00
|
|
|
this == messageManager) {
|
2010-02-20 20:05:20 +03:00
|
|
|
// Check that the message properties are enumerable.
|
|
|
|
var hasName = false;
|
|
|
|
var hasSync = false;
|
|
|
|
var hasJSON = false;
|
|
|
|
for (i in m) {
|
|
|
|
if (i == "name") {
|
|
|
|
hasName = true;
|
|
|
|
} else if (i == "sync") {
|
|
|
|
hasSync = true;
|
|
|
|
} else if (i == "json") {
|
|
|
|
hasJSON = true;
|
|
|
|
}
|
|
|
|
}
|
2019-11-27 18:39:16 +03:00
|
|
|
if (hasName && hasSync && hasJSON) {
|
2010-02-20 20:05:20 +03:00
|
|
|
document.getElementById("messageLog").value += ", " + m.json.ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var speedTestStartTime = 0;
|
|
|
|
var speedTestCount = 0;
|
|
|
|
function messageSpeed() {
|
|
|
|
speedTestCount = 0;
|
|
|
|
messageManager.addMessageListener("speed-test", speedHandler);
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("speed-test-start");
|
2010-02-20 20:05:20 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
function speedHandler() {
|
|
|
|
if (!speedTestCount) {
|
|
|
|
speedTestStartTime = new Date().getTime();
|
|
|
|
}
|
|
|
|
if (++speedTestCount == 1000) {
|
|
|
|
setTimeout("alert('" + speedTestCount + " in " + (new Date().getTime() - speedTestStartTime) + "ms')", 0);
|
|
|
|
return { message: "done" };
|
|
|
|
}
|
|
|
|
return { message: "continue" };
|
|
|
|
}
|
|
|
|
|
|
|
|
var addRemoveTestCount = 0;
|
|
|
|
|
|
|
|
function echoListener() {
|
|
|
|
if (++addRemoveTestCount == 1) {
|
|
|
|
alert("Expected echo message");
|
|
|
|
messageManager.removeMessageListener("async-echo", echoListener);
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("async-echo");
|
2010-02-20 20:05:20 +03:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
alert("Unexpected echo message");
|
|
|
|
}
|
|
|
|
|
|
|
|
function listenerAddRemove() {
|
|
|
|
addRemoveTestCount = 0;
|
|
|
|
messageManager.addMessageListener("async-echo", echoListener);
|
2012-08-27 18:13:02 +04:00
|
|
|
messageManager.broadcastAsyncMessage("async-echo");
|
2010-02-20 20:05:20 +03:00
|
|
|
}
|
2010-03-01 17:47:27 +03:00
|
|
|
|
|
|
|
var MozAfterPaintCount = 0;
|
|
|
|
function enableMozAfterPaint() {
|
|
|
|
messageManager.addMessageListener("MozAfterPaint",
|
|
|
|
function(m) {
|
|
|
|
document.getElementById("messageLog").value = m.name + "[" + (++MozAfterPaintCount) + "]";
|
|
|
|
});
|
|
|
|
messageManager.loadFrameScript("data:,addEventListener('MozAfterPaint', function(e) { sendAsyncMessage('MozAfterPaint'); },true);", false);
|
|
|
|
}
|
2010-05-17 15:25:22 +04:00
|
|
|
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
2009-07-01 00:39:22 +04:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<toolbar id="controls">
|
|
|
|
<toolbarbutton label="Back"/>
|
|
|
|
<toolbarbutton label="Forward"/>
|
2019-09-30 22:31:56 +03:00
|
|
|
<html:input onchange="loadURL(this.value)" style="-moz-box-flex: 1" id="URL"/>
|
2010-02-20 20:05:20 +03:00
|
|
|
</toolbar>
|
|
|
|
<toolbar>
|
2009-07-01 00:39:22 +04:00
|
|
|
<toolbarbutton onclick="restart()" label="Recover"/>
|
2010-02-20 20:05:20 +03:00
|
|
|
<toolbarbutton onclick="messageSpeed()" label="test message handling speed"/>
|
|
|
|
<toolbarbutton onclick="listenerAddRemove()" label="test listener add/remove"/>
|
2010-03-01 17:47:27 +03:00
|
|
|
<toolbarbutton onclick="enableMozAfterPaint()" label="MozAfterPaint"/>
|
2009-11-13 15:43:43 +03:00
|
|
|
<toolbarbutton onclick="openWindow()" label="open new window"/>
|
|
|
|
<toolbarbutton onclick="closeWindow()" label="close this window"/>
|
2009-07-01 00:39:22 +04:00
|
|
|
</toolbar>
|
2010-02-20 20:05:20 +03:00
|
|
|
<toolbar><label value="Load a script (URL) to content process:"/>
|
2019-09-30 22:31:56 +03:00
|
|
|
<html:input style="-moz-box-flex: 1" id="script"/><button
|
2012-08-27 18:13:02 +04:00
|
|
|
label="send" oncommand="document.getElementById('page')
|
|
|
|
.frameLoader.messageManager
|
|
|
|
.loadFrameScript(this.previousSibling.value, false);"/>
|
2010-02-20 20:05:20 +03:00
|
|
|
</toolbar>
|
|
|
|
<toolbar>
|
|
|
|
<label value="Eval script in chrome context"/>
|
2019-09-30 22:31:56 +03:00
|
|
|
<html:input style="-moz-box-flex: 1"/><button label="run" oncommand="eval(this.previousSibling.value); // eslint-disable-line no-eval"/>
|
2010-02-20 20:05:20 +03:00
|
|
|
</toolbar>
|
2009-07-01 00:39:22 +04:00
|
|
|
|
2011-06-23 00:43:05 +04:00
|
|
|
<browser type="content" src="http://www.google.com/" flex="1" id="page" remote="true"/>
|
2010-02-20 20:05:20 +03:00
|
|
|
<label id="messageLog" value="" crop="center"/>
|
2009-07-01 00:39:22 +04:00
|
|
|
</window>
|