mirror of
https://gitlab.winehq.org/wine/wine-gecko.git
synced 2024-09-13 09:24:08 -07:00
170 lines
5.6 KiB
HTML
170 lines
5.6 KiB
HTML
<!DOCTYPE html>
|
|
<html>
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Test that processes that are shutdown send a 'process-shutdown'
|
|
message to their process message manager.</title>
|
|
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
|
|
</head>
|
|
<body onload="runTests();">
|
|
<p id="display">
|
|
</p>
|
|
<div id="content" style="display: none">
|
|
|
|
</div>
|
|
<pre id="test">
|
|
<script class="testbody" type="application/javascript;version=1.8">
|
|
|
|
const APP_URL = "http://example.org";
|
|
const APP_MANIFEST = "http://example.org/manifest.webapp";
|
|
const CHILD_PROCESS_SHUTDOWN_MESSAGE = "child-process-shutdown";
|
|
|
|
let ppmm = SpecialPowers.Cc["@mozilla.org/parentprocessmessagemanager;1"]
|
|
.getService(SpecialPowers.Ci.nsIMessageBroadcaster);
|
|
let obs = SpecialPowers.Cc["@mozilla.org/observer-service;1"]
|
|
.getService(SpecialPowers.Ci.nsIObserverService);
|
|
|
|
/**
|
|
* Load the example.org site in an <iframe mozbrowser>
|
|
*
|
|
* @param isApp
|
|
* If true, the example.org site will be loaded as an app.
|
|
*/
|
|
function loadBrowser(isApp, callback) {
|
|
let iframe = document.createElement("iframe");
|
|
if (isApp) {
|
|
iframe.setAttribute("mozapp", APP_MANIFEST);
|
|
}
|
|
SpecialPowers.wrap(iframe).mozbrowser = true;
|
|
iframe.src = APP_URL;
|
|
document.getElementById("content").appendChild(iframe);
|
|
|
|
iframe.addEventListener("mozbrowserloadend", function onloadend() {
|
|
iframe.removeEventListener("mozbrowserloadend", onloadend);
|
|
callback(iframe);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Prepare the child process for an intentional crash. This is to keep
|
|
* the leak automation tools happy.
|
|
*
|
|
* This also allows us to acquire the process message manaager that
|
|
* corresponds to the process by sending a message to a frame script
|
|
* in the content process and having it reply to us via the child
|
|
* process message manager.
|
|
*/
|
|
function prepareProcess(frameMM, callback) {
|
|
let frameScript = 'data:,\
|
|
privateNoteIntentionalCrash();\
|
|
var cpmm = Components.classes["@mozilla.org/childprocessmessagemanager;1"]\
|
|
.getService(Components.interfaces.nsISyncMessageSender);\
|
|
addMessageListener("TestChild:Ohai", function receiveMessage(msg) {\
|
|
cpmm.sendAsyncMessage("TestChild:Ohai");\
|
|
});';
|
|
frameMM.loadFrameScript(frameScript, false);
|
|
frameMM.sendAsyncMessage("TestChild:Ohai");
|
|
ppmm.addMessageListener("TestChild:Ohai", function receiveMessage(msg) {
|
|
ppmm.removeMessageListener("TestChild:Ohai", receiveMessage);
|
|
msg = SpecialPowers.wrap(msg);
|
|
callback(msg.target);
|
|
});
|
|
}
|
|
|
|
/**
|
|
* Expects an OOP frame's process to shut down and report four
|
|
* events/messages: an error event on the browser element, and a
|
|
* 'child-process-shutdown' message on both the frame and process
|
|
* message managers.
|
|
*/
|
|
function expectFrameProcessShutdown(iframe, frameMM, processMM, callback) {
|
|
let msgCount = 0;
|
|
function countMessage() {
|
|
msgCount += 1;
|
|
if (msgCount == 4) {
|
|
ok(true, "Observed all four expected events.");
|
|
callback();
|
|
}
|
|
};
|
|
|
|
iframe.addEventListener("mozbrowsererror", function onerror(event) {
|
|
iframe.removeEventListener("mozbrowsererror", onerror);
|
|
is(event.detail.type, "fatal", "Observed expected event.");
|
|
countMessage();
|
|
});
|
|
|
|
processMM.addMessageListener(CHILD_PROCESS_SHUTDOWN_MESSAGE, function receiveMessage() {
|
|
processMM.removeMessageListener(CHILD_PROCESS_SHUTDOWN_MESSAGE, receiveMessage);
|
|
ok(true, "Received 'child-process-shutdown' message from process message manager.");
|
|
countMessage();
|
|
});
|
|
|
|
frameMM.addMessageListener(CHILD_PROCESS_SHUTDOWN_MESSAGE, function receiveMessage() {
|
|
frameMM.removeMessageListener(CHILD_PROCESS_SHUTDOWN_MESSAGE, receiveMessage);
|
|
ok(true, "Received 'child-process-shutdown' message from frame message manager.");
|
|
countMessage();
|
|
});
|
|
|
|
obs.addObserver(function observe(subject, type, data) {
|
|
if (subject == SpecialPowers.unwrap(processMM)) {
|
|
obs.removeObserver(observe, "message-manager-disconnect");
|
|
ok(true, "Received 'message-manager-disconnect' notification with " +
|
|
"frame message manager");
|
|
countMessage();
|
|
}
|
|
}, "message-manager-disconnect", false);
|
|
}
|
|
|
|
function setUp() {
|
|
SpecialPowers.addPermission("browser", true, window.document);
|
|
SpecialPowers.addPermission("embed-apps", true, window.document);
|
|
// TODO: remove network.disable.ipc.security in bug 820712
|
|
SpecialPowers.pushPrefEnv({
|
|
"set": [['dom.mozBrowserFramesEnabled', true],
|
|
['dom.ipc.browser_frames.oop_by_default', true],
|
|
['network.disable.ipc.security', true]]}, runNextTest);
|
|
}
|
|
|
|
function makeKillTest(isApp) function testKill() {
|
|
loadBrowser(isApp, function (iframe) {
|
|
// We want to make sure we get notified on both the frame and
|
|
// process message managers.
|
|
let frameMM = SpecialPowers.getBrowserFrameMessageManager(iframe);
|
|
prepareProcess(frameMM, function (processMM) {
|
|
// Let's kill the content process by asking for a permission
|
|
// that it doesn't have.
|
|
ok(!processMM.assertPermission("frobnaz"),
|
|
"Content child should not have this permission");
|
|
expectFrameProcessShutdown(iframe, frameMM, processMM, function () {
|
|
iframe.parentNode.removeChild(iframe);
|
|
runNextTest();
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
function tearDown() {
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
let _tests = [
|
|
setUp,
|
|
makeKillTest(false),
|
|
makeKillTest(true),
|
|
tearDown
|
|
]
|
|
function runNextTest() {
|
|
SimpleTest.executeSoon(_tests.shift());
|
|
}
|
|
|
|
function runTests() {
|
|
SimpleTest.waitForExplicitFinish();
|
|
runNextTest();
|
|
}
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|