2009-06-30 13:39:22 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
2010-02-20 09:05:20 -08:00
|
|
|
width="800" height="800" orient="vertical" onload="initRemoteFrameScript();">
|
2009-06-30 13:39:22 -07:00
|
|
|
<script>
|
2009-11-17 06:22:23 -08: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");
|
|
|
|
for (i = 0; i < rects.length; ++i) {
|
|
|
|
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");
|
|
|
|
for (i = 0; i < paintRequests.length; ++i) {
|
|
|
|
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-06-30 13:39:22 -07:00
|
|
|
function restart() {
|
|
|
|
var y = document.getElementById('page');
|
|
|
|
var p = y.parentNode;
|
|
|
|
p.removeChild(y);
|
|
|
|
p.appendChild(y);
|
2009-11-17 06:22:23 -08:00
|
|
|
|
|
|
|
var fl = y.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader;
|
|
|
|
fl.activateFrameEvent("MozAfterPaint", true);
|
|
|
|
fl.activateFrameEvent("MozScrolledAreaChanged", true);
|
|
|
|
y.addEventListener("MozAfterPaint", handleMozAfterPaint, true);
|
|
|
|
y.addEventListener("MozScrolledAreaChanged", handleMozScrolledAreaChanged, true);
|
2009-06-30 13:39:22 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadURL(url) {
|
|
|
|
document.getElementById('page').setAttribute('src', url);
|
|
|
|
}
|
2009-11-05 10:21:09 -08:00
|
|
|
|
|
|
|
function randomClick() {
|
|
|
|
// First focus the remote frame, then dispatch click. This way remote frame gets focus before
|
|
|
|
// mouse event.
|
|
|
|
document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner)
|
|
|
|
.frameLoader.activateRemoteFrame();
|
|
|
|
var frameLoader = document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader;
|
|
|
|
var x = parseInt(Math.random() * 100);
|
|
|
|
var y = parseInt(Math.random() * 100);
|
|
|
|
frameLoader.sendCrossProcessMouseEvent("mousedown", x, y, 0, 1, 0, false);
|
|
|
|
frameLoader.sendCrossProcessMouseEvent("mouseup", x, y, 0, 1, 0, false);
|
|
|
|
}
|
2009-11-13 04:43:43 -08:00
|
|
|
|
2010-03-18 23:52:18 -07:00
|
|
|
function keyPress() {
|
|
|
|
// First focus the remote frame, then dispatch click. This way remote frame gets focus before
|
|
|
|
// mouse event.
|
|
|
|
document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner)
|
|
|
|
.frameLoader.activateRemoteFrame();
|
|
|
|
var frameLoader = document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader;
|
|
|
|
|
|
|
|
var keyCode = Components.interfaces.nsIDOMKeyEvent.DOM_VK_A;
|
|
|
|
frameLoader.sendCrossProcessKeyEvent("keydown", keyCode, 0, 0);
|
|
|
|
frameLoader.sendCrossProcessKeyEvent("keypress", keyCode, 0, 0);
|
|
|
|
frameLoader.sendCrossProcessKeyEvent("keyup", keyCode, 0, 0);
|
|
|
|
}
|
|
|
|
|
2009-11-13 04:43:43 -08:00
|
|
|
function openWindow() {
|
|
|
|
window.open('chrome://global/content/test-ipc.xul', '_blank', 'chrome,resizable,width=800,height=800');
|
|
|
|
}
|
|
|
|
|
|
|
|
function closeWindow() {
|
|
|
|
window.close();
|
|
|
|
}
|
2010-02-20 09:05:20 -08:00
|
|
|
|
|
|
|
function initRemoteFrameScript() {
|
|
|
|
// 1. Test that loading a script works
|
|
|
|
messageManager.loadFrameScript("chrome://global/content/remote-test-ipc.js", true);
|
|
|
|
|
|
|
|
// 2. Test that adding message listener works, and that receiving a sync message works.
|
|
|
|
messageManager.addMessageListener("linkclick",
|
|
|
|
function(m) {
|
2010-06-17 14:10:14 -07:00
|
|
|
// This checks that json sending works in sync messages.
|
|
|
|
document.getElementById("messageLog").value = m.name + ": " + m.json.href;
|
|
|
|
return { message: "linkclick-received" };
|
2010-02-20 09:05:20 -08: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 03:00:43 -08:00
|
|
|
// Test also that { receiveMessage: function(m) {} } works.
|
2010-02-20 09:05:20 -08:00
|
|
|
messageManager.addMessageListener("linkclick-reply-object",
|
2010-03-05 03:00:43 -08:00
|
|
|
{ foobarObjectVar: true,
|
|
|
|
receiveMessage: function(m) {
|
|
|
|
var s = (m.json.message == "linkclick-received") &&
|
|
|
|
(this.foobarObjectVar) ? "PASS" : "FAIL";
|
|
|
|
messageManager.sendAsyncMessage("chrome-message", { ok : s } );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2010-02-20 09:05:20 -08:00
|
|
|
|
|
|
|
// 5. Final test to check that everything went ok.
|
|
|
|
messageManager.addMessageListener("chrome-message-reply",
|
|
|
|
function(m) {
|
2010-03-29 13:29:45 -07:00
|
|
|
// Check that 'this' and .target values are handled correctly
|
2010-03-05 03:00:43 -08:00
|
|
|
if (m.target == document.getElementById("page") &&
|
2010-06-17 14:10:14 -07:00
|
|
|
this == messageManager) {
|
2010-02-20 09:05:20 -08: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;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (hasName && hasSync && hasJSON) {
|
|
|
|
document.getElementById("messageLog").value += ", " + m.json.ok;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
var speedTestStartTime = 0;
|
|
|
|
var speedTestCount = 0;
|
|
|
|
function messageSpeed() {
|
|
|
|
speedTestCount = 0;
|
|
|
|
messageManager.addMessageListener("speed-test", speedHandler);
|
|
|
|
messageManager.sendAsyncMessage("speed-test-start");
|
|
|
|
}
|
|
|
|
|
|
|
|
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);
|
|
|
|
messageManager.sendAsyncMessage("async-echo");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
alert("Unexpected echo message");
|
|
|
|
}
|
|
|
|
|
|
|
|
function listenerAddRemove() {
|
|
|
|
addRemoveTestCount = 0;
|
|
|
|
messageManager.addMessageListener("async-echo", echoListener);
|
|
|
|
messageManager.sendAsyncMessage("async-echo");
|
|
|
|
}
|
2010-03-01 06:47:27 -08: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 04:25:22 -07:00
|
|
|
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
var Cu = Components.utils;
|
|
|
|
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
|
|
|
|
|
|
|
function DialogProvider() { }
|
|
|
|
|
|
|
|
DialogProvider.prototype = {
|
|
|
|
QueryInterface: XPCOMUtils.generateQI([Ci.nsIBrowserDOMWindow, Ci.nsIDialogCreator, Ci.nsISupports]),
|
|
|
|
openURI: function (aURI, aOpener, aWhere, aContext) {
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
isTabContentWindow: function (aWindow) {
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
openDialog: function(aType, aName, aFeatures, aArguments, aFrameElement) {
|
|
|
|
alert(aType + ", " + aName + ", " + aFeatures + ", " + aArguments + ", " + aFrameElement);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function defaultDialogs(useDefault) {
|
|
|
|
window.QueryInterface(Ci.nsIDOMChromeWindow).browserDOMWindow = useDefault ? null : new DialogProvider();
|
|
|
|
}
|
|
|
|
|
|
|
|
defaultDialogs(false);
|
|
|
|
|
|
|
|
window.addEventListener("MozDelayedModalDialog",
|
|
|
|
function(e) { alert(e.type + ", " + e.target); },
|
|
|
|
true);
|
|
|
|
|
2009-06-30 13:39:22 -07:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<toolbar id="controls">
|
|
|
|
<toolbarbutton label="Back"/>
|
|
|
|
<toolbarbutton label="Forward"/>
|
|
|
|
<textbox onchange="loadURL(this.value)" flex="1" id="URL"/>
|
2010-02-20 09:05:20 -08:00
|
|
|
</toolbar>
|
|
|
|
<toolbar>
|
2009-06-30 13:39:22 -07:00
|
|
|
<toolbarbutton onclick="restart()" label="Recover"/>
|
2009-11-05 10:21:09 -08:00
|
|
|
<toolbarbutton onclick="randomClick()" label="random click"/>
|
2010-03-18 23:52:18 -07:00
|
|
|
<toolbarbutton onclick="keyPress()" label="key press"/>
|
2010-02-20 09:05:20 -08:00
|
|
|
<toolbarbutton onclick="messageSpeed()" label="test message handling speed"/>
|
|
|
|
<toolbarbutton onclick="listenerAddRemove()" label="test listener add/remove"/>
|
2010-03-01 06:47:27 -08:00
|
|
|
<toolbarbutton onclick="enableMozAfterPaint()" label="MozAfterPaint"/>
|
2009-11-13 04:43:43 -08:00
|
|
|
<toolbarbutton onclick="openWindow()" label="open new window"/>
|
|
|
|
<toolbarbutton onclick="closeWindow()" label="close this window"/>
|
2009-06-30 13:39:22 -07:00
|
|
|
</toolbar>
|
2010-02-20 09:05:20 -08:00
|
|
|
<toolbar><label value="Load a script (URL) to content process:"/>
|
|
|
|
<textbox flex="1" id="script"/><button
|
|
|
|
label="send" oncommand="document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.
|
|
|
|
messageManager.loadFrameScript(this.previousSibling.value, false);"/>
|
|
|
|
</toolbar>
|
|
|
|
<toolbar>
|
|
|
|
<label value="Eval script in chrome context"/>
|
|
|
|
<textbox flex="1"/><button label="run" oncommand="eval(this.previousSibling.value);"/>
|
|
|
|
</toolbar>
|
2010-05-17 04:25:22 -07:00
|
|
|
<toolbar>
|
|
|
|
<checkbox label="allow dialogs from remote content"
|
|
|
|
oncommand="document.getElementById('page').QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.delayRemoteDialogs = this.checked;"/>
|
|
|
|
</toolbar>
|
2009-06-30 13:39:22 -07:00
|
|
|
|
2009-11-05 10:14:22 -08:00
|
|
|
<browser type="content" src="http://www.google.com/" flex="1" id="page" remote="true"
|
|
|
|
onfocus="this.QueryInterface(Components.interfaces.nsIFrameLoaderOwner).frameLoader.activateRemoteFrame();"/>
|
2010-02-20 09:05:20 -08:00
|
|
|
<label id="messageLog" value="" crop="center"/>
|
2009-06-30 13:39:22 -07:00
|
|
|
</window>
|