2010-05-18 05:28:37 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css"
|
|
|
|
type="text/css"?>
|
|
|
|
<!--
|
|
|
|
https://bugzilla.mozilla.org/show_bug.cgi?id=549682
|
|
|
|
-->
|
|
|
|
<window title="Mozilla Bug 549682"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
onload="run()">
|
|
|
|
<label value="Mozilla Bug 549682"/>
|
|
|
|
<!-- test code goes here -->
|
|
|
|
<script type="application/javascript"><![CDATA[
|
|
|
|
var didRunAsync = false;
|
2010-12-07 06:34:34 -08:00
|
|
|
var didRunLocal = false;
|
2010-06-10 02:26:19 -07:00
|
|
|
var global = Components.classes["@mozilla.org/globalmessagemanager;1"].getService(Components.interfaces.nsIChromeFrameMessageManager);
|
2011-10-11 03:28:46 -07:00
|
|
|
var ppm = Components.classes["@mozilla.org/parentprocessmessagemanager;1"].getService(Components.interfaces.nsIFrameMessageManager);
|
|
|
|
var cpm = Components.classes["@mozilla.org/childprocessmessagemanager;1"].getService(Components.interfaces.nsISyncMessageSender);
|
|
|
|
|
|
|
|
var asyncPPML = false;
|
|
|
|
function ppmASL(m) {
|
|
|
|
asyncPPML = true;
|
|
|
|
}
|
|
|
|
var syncPPML = false;
|
|
|
|
function ppmSL(m) {
|
|
|
|
syncPPML = true;
|
|
|
|
}
|
|
|
|
ppm.addMessageListener("processmessageAsync", ppmASL);
|
|
|
|
ppm.addMessageListener("processmessageSync", ppmSL);
|
|
|
|
|
|
|
|
cpm.sendAsyncMessage("processmessageAsync", "");
|
|
|
|
cpm.sendSyncMessage("processmessageSync", "");
|
|
|
|
|
|
|
|
var asyncCPML = false;
|
|
|
|
function cpmASL(m) {
|
|
|
|
asyncCPML = true;
|
|
|
|
}
|
|
|
|
cpm.addMessageListener("childprocessmessage", cpmASL);
|
|
|
|
ppm.sendAsyncMessage("childprocessmessage", "");
|
|
|
|
|
|
|
|
function checkPMMMessages() {
|
|
|
|
opener.wrappedJSObject.ok(asyncPPML, "should have handled async message");
|
|
|
|
opener.wrappedJSObject.ok(syncPPML, "should have handled sync message");
|
|
|
|
opener.wrappedJSObject.ok(asyncCPML, "should have handled async message");
|
|
|
|
ppm.removeMessageListener("processmessageAsync", ppmASL);
|
|
|
|
ppm.removeMessageListener("processmessageSync", ppmSL);
|
|
|
|
cpm.removeMessageListener("childprocessmessage", cpmASL);
|
|
|
|
}
|
|
|
|
|
2010-06-10 02:26:19 -07:00
|
|
|
var globalListenerCallCount = 0;
|
|
|
|
function globalListener(m) {
|
|
|
|
++globalListenerCallCount;
|
|
|
|
if (m.name == "sync") {
|
|
|
|
global.removeMessageListener("async", globalListener);
|
|
|
|
global.removeMessageListener("sync", globalListener);
|
|
|
|
global.removeMessageListener("global-sync", globalListener);
|
|
|
|
// Note, the result depends on what other windows are open.
|
|
|
|
opener.wrappedJSObject.ok(globalListenerCallCount >= 4,
|
|
|
|
"Global listener should have been called at least 4 times!");
|
2010-12-07 06:34:34 -08:00
|
|
|
opener.wrappedJSObject.ok(didRunLocal, "Local message received.");
|
2010-06-10 02:26:19 -07:00
|
|
|
|
|
|
|
opener.setTimeout("done()", 0);
|
|
|
|
var i = document.getElementById("ifr");
|
|
|
|
i.parentNode.removeChild(i); // This is a crash test!
|
|
|
|
window.close();
|
|
|
|
}
|
|
|
|
}
|
2010-05-18 05:28:37 -07:00
|
|
|
|
|
|
|
function asyncL(m) {
|
|
|
|
didRunAsync = true;
|
|
|
|
opener.wrappedJSObject.is(m.name, "async", "Wrong message!");
|
|
|
|
opener.wrappedJSObject.is(m.json.data, 1234, "Wrong data!");
|
|
|
|
}
|
|
|
|
|
|
|
|
function syncL(m) {
|
|
|
|
opener.wrappedJSObject.is(m.name, "sync", "Wrong message!");
|
|
|
|
opener.wrappedJSObject.is(m.json.data, 1234, "Wrong data!");
|
|
|
|
opener.wrappedJSObject.ok(didRunAsync, "Should have run async!");
|
|
|
|
}
|
|
|
|
|
2010-12-07 06:34:34 -08:00
|
|
|
function localL(m) {
|
|
|
|
opener.wrappedJSObject.is(m.name, "lasync", "Wrong message!");
|
|
|
|
opener.wrappedJSObject.is(m.json.data, 2345, "Wrong data!");
|
|
|
|
didRunLocal = true;
|
|
|
|
}
|
|
|
|
|
2010-05-18 05:28:37 -07:00
|
|
|
function loadScript() {
|
2010-07-15 07:33:35 -07:00
|
|
|
// Async should be processed first!
|
2010-06-10 02:26:19 -07:00
|
|
|
messageManager.loadFrameScript("data:,sendAsyncMessage('async', { data: 1234 }); sendSyncMessage('sync', { data: 1234 });", false);
|
2010-05-18 05:28:37 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function run() {
|
2010-12-07 06:34:34 -08:00
|
|
|
var localmm = document.getElementById('ifr').messageManager;
|
|
|
|
localmm.addMessageListener("lasync", localL);
|
|
|
|
localmm.loadFrameScript("data:,sendAsyncMessage('lasync', { data: 2345 })", false);
|
|
|
|
|
2010-05-18 05:28:37 -07:00
|
|
|
messageManager.addMessageListener("async", asyncL);
|
|
|
|
messageManager.addMessageListener("sync", syncL);
|
2010-06-10 02:26:19 -07:00
|
|
|
global.addMessageListener("async", globalListener);
|
|
|
|
global.addMessageListener("sync", globalListener);
|
|
|
|
global.addMessageListener("global-sync", globalListener);
|
|
|
|
global.loadFrameScript("data:,sendSyncMessage('global-sync', { data: 1234 });", true);
|
2011-08-24 03:16:29 -07:00
|
|
|
var toBeRemovedScript = "data:,sendAsyncMessage('toberemoved', { data: 2345 })";
|
|
|
|
var c = 0;
|
|
|
|
messageManager.addMessageListener("toberemoved", function() {
|
|
|
|
++c;
|
|
|
|
opener.wrappedJSObject.is(c, 1, "Should be called only once!");
|
|
|
|
});
|
|
|
|
// This loads the script in the existing <browser>
|
|
|
|
messageManager.loadFrameScript(toBeRemovedScript, true);
|
|
|
|
// But it won't be loaded in the dynamically created <browser>
|
|
|
|
messageManager.removeDelayedFrameScript(toBeRemovedScript);
|
2010-06-10 02:26:19 -07:00
|
|
|
|
|
|
|
var oldValue = globalListenerCallCount;
|
|
|
|
var b = document.createElement("browser");
|
|
|
|
b.setAttribute("type", "content");
|
|
|
|
document.documentElement.appendChild(b);
|
|
|
|
opener.wrappedJSObject.is(globalListenerCallCount, oldValue + 1,
|
|
|
|
"Wrong message count");
|
|
|
|
|
2011-10-11 03:28:46 -07:00
|
|
|
setTimeout(checkPMMMessages, 0);
|
2010-05-18 05:28:37 -07:00
|
|
|
setTimeout(loadScript, 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
]]></script>
|
|
|
|
<browser type="content" src="about:blank" id="ifr"/>
|
|
|
|
</window>
|