зеркало из https://github.com/mozilla/gecko-dev.git
Bug 990812 - Tests for group message managers r=smaug
This commit is contained in:
Родитель
230fa7a56a
Коммит
ebbe1bba5f
|
@ -9,6 +9,11 @@ support-files =
|
|||
file_bug549682.xul
|
||||
file_bug616841.xul
|
||||
file_bug816340.xul
|
||||
file_bug990812-1.xul
|
||||
file_bug990812-2.xul
|
||||
file_bug990812-3.xul
|
||||
file_bug990812-4.xul
|
||||
file_bug990812-5.xul
|
||||
fileconstructor_file.png
|
||||
frame_bug814638.xul
|
||||
host_bug814638.xul
|
||||
|
@ -45,6 +50,7 @@ support-files =
|
|||
[test_bug814638.xul]
|
||||
[test_bug816340.xul]
|
||||
[test_bug914381.html]
|
||||
[test_bug990812.xul]
|
||||
[test_cpows.xul]
|
||||
skip-if = toolkit == "cocoa"
|
||||
[test_document_register.xul]
|
||||
|
|
|
@ -0,0 +1,64 @@
|
|||
<?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=990812
|
||||
-->
|
||||
<window title="Mozilla Bug 990812"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="start();">
|
||||
<label value="Mozilla Bug 990812"/>
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
var FRAME_SCRIPT_GLOBAL = "data:,sendSyncMessage('test', 'global')";
|
||||
var FRAME_SCRIPT_WINDOW = "data:,sendSyncMessage('test', 'window')";
|
||||
var FRAME_SCRIPT_GROUP = "data:,sendSyncMessage('test', 'group')";
|
||||
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageListenerManager);
|
||||
|
||||
function is(val, exp, msg) {
|
||||
opener.wrappedJSObject.is(val, exp, msg);
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that delayed frame scripts are loaded in the expected order.
|
||||
* Global frame scripts will be loaded before delayed frame scripts from
|
||||
* window message managers. The latter will be loaded before group message
|
||||
* manager frame scripts.
|
||||
*/
|
||||
function start() {
|
||||
globalMM.loadFrameScript(FRAME_SCRIPT_GLOBAL, true);
|
||||
messageManager.loadFrameScript(FRAME_SCRIPT_WINDOW, true);
|
||||
getGroupMessageManager("test").loadFrameScript(FRAME_SCRIPT_GROUP, true);
|
||||
|
||||
var order = ["global", "window", "group"];
|
||||
|
||||
messageManager.addMessageListener("test", function onMessage(msg) {
|
||||
var next = order.shift();
|
||||
opener.wrappedJSObject.is(msg.data, next, "received test:" + next);
|
||||
|
||||
if (order.length == 0) {
|
||||
opener.setTimeout("next()");
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
|
||||
var browser = document.createElement("browser");
|
||||
browser.setAttribute("messagemanagergroup", "test");
|
||||
browser.setAttribute("src", "about:mozilla");
|
||||
browser.setAttribute("type", "content-targetable");
|
||||
document.documentElement.appendChild(browser);
|
||||
|
||||
globalMM.removeDelayedFrameScript(FRAME_SCRIPT_GLOBAL);
|
||||
messageManager.removeDelayedFrameScript(FRAME_SCRIPT_WINDOW);
|
||||
getGroupMessageManager("test").removeDelayedFrameScript(FRAME_SCRIPT_GROUP);
|
||||
}
|
||||
|
||||
]]></script>
|
||||
|
||||
</window>
|
|
@ -0,0 +1,59 @@
|
|||
<?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=990812
|
||||
-->
|
||||
<window title="Mozilla Bug 990812"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="start();">
|
||||
<label value="Mozilla Bug 990812"/>
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
var FRAME_SCRIPT = "data:,sendAsyncMessage('test')";
|
||||
var order = ["group", "window", "global"];
|
||||
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageListenerManager);
|
||||
|
||||
function is(val, exp, msg) {
|
||||
opener.wrappedJSObject.is(val, exp, msg);
|
||||
}
|
||||
|
||||
function promiseMessage(type, mm) {
|
||||
return new Promise(function (resolve) {
|
||||
mm.addMessageListener("test", function onMessage() {
|
||||
mm.removeMessageListener("test", onMessage);
|
||||
is(type, order.shift(), "correct type " + type);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that async messages sent by frame scripts bubble up as expected,
|
||||
* passing the group, window, and global message managers in that order.
|
||||
*/
|
||||
function start() {
|
||||
var global = promiseMessage("global", globalMM);
|
||||
var window = promiseMessage("window", messageManager);
|
||||
var group = promiseMessage("group", getGroupMessageManager("test"));
|
||||
|
||||
var browser = document.querySelector("browser");
|
||||
browser.messageManager.loadFrameScript(FRAME_SCRIPT, true);
|
||||
|
||||
Promise.all([global, window, group]).then(function () {
|
||||
opener.setTimeout("next()");
|
||||
window.close();
|
||||
});
|
||||
}
|
||||
|
||||
]]></script>
|
||||
|
||||
<browser messagemanagergroup="test" type="content-targetable" src="about:mozilla" />
|
||||
|
||||
</window>
|
|
@ -0,0 +1,71 @@
|
|||
<?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=990812
|
||||
-->
|
||||
<window title="Mozilla Bug 990812"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="start();">
|
||||
<label value="Mozilla Bug 990812"/>
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
var FRAME_SCRIPT = "data:,addMessageListener('test', function (msg) {" +
|
||||
"sendSyncMessage('test', msg.data)})";
|
||||
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageListenerManager);
|
||||
|
||||
function is(val, exp, msg) {
|
||||
opener.wrappedJSObject.is(val, exp, msg);
|
||||
}
|
||||
|
||||
function promiseMessage(type, mm) {
|
||||
var order = [type, "window", "global"];
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
mm.addMessageListener("test", function onMessage(msg) {
|
||||
is(msg.data, order.shift(), "correct message " + msg.data);
|
||||
|
||||
if (order.length == 0) {
|
||||
mm.removeMessageListener("test", onMessage);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that broadcasting an async message does only reach descendants
|
||||
* of a specific message manager and respects message manager groups.
|
||||
*/
|
||||
function start() {
|
||||
var mm1 = document.querySelector("browser").messageManager;
|
||||
var promise1 = promiseMessage("group1", mm1);
|
||||
mm1.loadFrameScript(FRAME_SCRIPT, true);
|
||||
|
||||
var mm2 = document.querySelector("browser + browser").messageManager;
|
||||
var promise2 = promiseMessage("group2", mm2);
|
||||
mm2.loadFrameScript(FRAME_SCRIPT, true);
|
||||
|
||||
getGroupMessageManager("test1").broadcastAsyncMessage("test", "group1");
|
||||
getGroupMessageManager("test2").broadcastAsyncMessage("test", "group2");
|
||||
messageManager.broadcastAsyncMessage("test", "window");
|
||||
globalMM.broadcastAsyncMessage("test", "global");
|
||||
|
||||
Promise.all([promise1, promise2]).then(function () {
|
||||
opener.setTimeout("next()");
|
||||
window.close();
|
||||
});
|
||||
}
|
||||
|
||||
]]></script>
|
||||
|
||||
<browser messagemanagergroup="test1" type="content-targetable" src="about:mozilla" />
|
||||
<browser messagemanagergroup="test2" type="content-targetable" src="about:mozilla" />
|
||||
|
||||
</window>
|
|
@ -0,0 +1,68 @@
|
|||
<?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=990812
|
||||
-->
|
||||
<window title="Mozilla Bug 990812"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="start();">
|
||||
<label value="Mozilla Bug 990812"/>
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
var FRAME_SCRIPT1 = "data:,addMessageListener('test', function () {" +
|
||||
"sendSyncMessage('test', 'frame1')})";
|
||||
var FRAME_SCRIPT2 = "data:,addMessageListener('test', function () {" +
|
||||
"sendSyncMessage('test', 'frame2')})";
|
||||
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageListenerManager);
|
||||
|
||||
function is(val, exp, msg) {
|
||||
opener.wrappedJSObject.is(val, exp, msg);
|
||||
}
|
||||
|
||||
function promiseMessage(type, mm) {
|
||||
return new Promise(function (resolve) {
|
||||
mm.addMessageListener("test", function onMessage(msg) {
|
||||
mm.removeMessageListener("test", onMessage);
|
||||
is(msg.data, type, "correct message " + type);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Tests that swapping docShells works as expected wrt to groups.
|
||||
*/
|
||||
function start() {
|
||||
var browser1 = document.querySelector("browser");
|
||||
browser1.messageManager.loadFrameScript(FRAME_SCRIPT1, true);
|
||||
|
||||
var browser2 = document.querySelector("browser + browser");
|
||||
browser2.messageManager.loadFrameScript(FRAME_SCRIPT2, true);
|
||||
|
||||
var promise1 = promiseMessage("frame2", getGroupMessageManager("test1"));
|
||||
var promise2 = promiseMessage("frame1", getGroupMessageManager("test2"));
|
||||
|
||||
var flo1 = browser1.QueryInterface(Ci.nsIFrameLoaderOwner);
|
||||
var flo2 = browser2.QueryInterface(Ci.nsIFrameLoaderOwner);
|
||||
flo1.swapFrameLoaders(flo2);
|
||||
messageManager.broadcastAsyncMessage("test");
|
||||
|
||||
Promise.all([promise1, promise2]).then(function () {
|
||||
opener.setTimeout("next()");
|
||||
window.close();
|
||||
});
|
||||
}
|
||||
|
||||
]]></script>
|
||||
|
||||
<browser messagemanagergroup="test1" type="content-targetable" src="about:mozilla" />
|
||||
<browser messagemanagergroup="test2" type="content-targetable" src="about:mozilla" />
|
||||
|
||||
</window>
|
|
@ -0,0 +1,77 @@
|
|||
<?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=990812
|
||||
-->
|
||||
<window title="Mozilla Bug 990812"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="start();">
|
||||
<label value="Mozilla Bug 990812"/>
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
var FRAME_SCRIPT1 = "data:,addMessageListener('test', function () {" +
|
||||
"sendSyncMessage('test', 'group1')})";
|
||||
var FRAME_SCRIPT2 = "data:,addMessageListener('test', function () {" +
|
||||
"sendSyncMessage('test', 'group2')})";
|
||||
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageListenerManager);
|
||||
|
||||
function is(val, exp, msg) {
|
||||
opener.wrappedJSObject.is(val, exp, msg);
|
||||
}
|
||||
|
||||
function promiseTwoMessages(type, mm) {
|
||||
var numLeft = 2;
|
||||
|
||||
return new Promise(function (resolve) {
|
||||
mm.addMessageListener("test", function onMessage(msg) {
|
||||
is(msg.data, type, "correct message " + type);
|
||||
|
||||
if (--numLeft == 0) {
|
||||
mm.removeMessageListener("test", onMessage);
|
||||
resolve();
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* This test ensures that having multiple message manager groups with
|
||||
* multiple frame loaders in those works as expected. For a specific
|
||||
* group message manager, frame scripts should only be loaded by its
|
||||
* descendants and messages should only be received by and from those
|
||||
* child message managers.
|
||||
*/
|
||||
function start() {
|
||||
var gmm1 = getGroupMessageManager("test1");
|
||||
gmm1.loadFrameScript(FRAME_SCRIPT1, true);
|
||||
|
||||
var gmm2 = getGroupMessageManager("test2");
|
||||
gmm2.loadFrameScript(FRAME_SCRIPT2, true);
|
||||
|
||||
var promise1 = promiseTwoMessages("group1", gmm1);
|
||||
var promise2 = promiseTwoMessages("group2", gmm2);
|
||||
|
||||
messageManager.broadcastAsyncMessage("test");
|
||||
|
||||
Promise.all([promise1, promise2]).then(function () {
|
||||
opener.setTimeout("next()");
|
||||
window.close();
|
||||
});
|
||||
}
|
||||
|
||||
]]></script>
|
||||
|
||||
<browser messagemanagergroup="test1" type="content-targetable" src="about:mozilla" />
|
||||
<browser messagemanagergroup="test1" type="content-targetable" src="about:mozilla" />
|
||||
|
||||
<browser messagemanagergroup="test2" type="content-targetable" src="about:mozilla" />
|
||||
<browser messagemanagergroup="test2" type="content-targetable" src="about:mozilla" />
|
||||
|
||||
</window>
|
|
@ -0,0 +1,58 @@
|
|||
<?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=990812
|
||||
-->
|
||||
<window title="Mozilla Bug 990812"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
||||
onload="start();">
|
||||
<label value="Mozilla Bug 990812"/>
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript"><![CDATA[
|
||||
|
||||
var FRAME_SCRIPT_GLOBAL = "data:,sendSyncMessage('test', 'global')";
|
||||
var FRAME_SCRIPT_WINDOW = "data:,sendSyncMessage('test', 'window')";
|
||||
var FRAME_SCRIPT_GROUP = "data:,sendSyncMessage('test', 'group')";
|
||||
|
||||
var Cc = Components.classes;
|
||||
var Ci = Components.interfaces;
|
||||
var globalMM = Cc["@mozilla.org/globalmessagemanager;1"]
|
||||
.getService(Ci.nsIMessageListenerManager);
|
||||
|
||||
function is(val, exp, msg) {
|
||||
opener.wrappedJSObject.is(val, exp, msg);
|
||||
}
|
||||
|
||||
function start() {
|
||||
globalMM.loadFrameScript(FRAME_SCRIPT_GLOBAL, true);
|
||||
messageManager.loadFrameScript(FRAME_SCRIPT_WINDOW, true);
|
||||
getGroupMessageManager("test").loadFrameScript(FRAME_SCRIPT_GROUP, true);
|
||||
|
||||
var order = ["global", "window", "group"];
|
||||
|
||||
messageManager.addMessageListener("test", function onMessage(msg) {
|
||||
var next = order.shift();
|
||||
opener.wrappedJSObject.is(msg.data, next, "received test:" + next);
|
||||
|
||||
if (order.length == 0) {
|
||||
opener.setTimeout("next()");
|
||||
window.close();
|
||||
}
|
||||
});
|
||||
|
||||
var browser = document.createElement("browser");
|
||||
browser.setAttribute("messagemanagergroup", "test");
|
||||
browser.setAttribute("src", "about:mozilla");
|
||||
browser.setAttribute("type", "content-targetable");
|
||||
document.documentElement.appendChild(browser);
|
||||
|
||||
globalMM.removeDelayedFrameScript(FRAME_SCRIPT_GLOBAL);
|
||||
messageManager.removeDelayedFrameScript(FRAME_SCRIPT_WINDOW);
|
||||
getGroupMessageManager("test").removeDelayedFrameScript(FRAME_SCRIPT_GROUP);
|
||||
}
|
||||
|
||||
]]></script>
|
||||
|
||||
</window>
|
|
@ -0,0 +1,43 @@
|
|||
<?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=990812
|
||||
-->
|
||||
<window title="Mozilla Bug 990812"
|
||||
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
|
||||
<script type="application/javascript"
|
||||
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
||||
|
||||
<!-- test results are displayed in the html:body -->
|
||||
<body xmlns="http://www.w3.org/1999/xhtml">
|
||||
<a href="https://bugzilla.mozilla.org/show_bug.cgi?id=990812"
|
||||
target="_blank">Mozilla Bug 990812</a>
|
||||
</body>
|
||||
|
||||
<!-- test code goes here -->
|
||||
<script type="application/javascript"><![CDATA[
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var tests = [
|
||||
"file_bug990812-1.xul",
|
||||
"file_bug990812-2.xul",
|
||||
"file_bug990812-3.xul",
|
||||
"file_bug990812-4.xul",
|
||||
"file_bug990812-5.xul",
|
||||
];
|
||||
|
||||
function next() {
|
||||
if (tests.length > 0) {
|
||||
var file = tests.shift();
|
||||
info("-- running " + file);
|
||||
window.open(file, "", "chrome");
|
||||
} else {
|
||||
SimpleTest.finish();
|
||||
}
|
||||
}
|
||||
|
||||
addLoadEvent(next);
|
||||
]]></script>
|
||||
</window>
|
Загрузка…
Ссылка в новой задаче