mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-28 13:40:17 -10:00
MozReview-Commit-ID: EGWYEmAkbtr Depends on D11693 Differential Revision: https://phabricator.services.mozilla.com/D11622
160 lines
4.8 KiB
HTML
160 lines
4.8 KiB
HTML
<!DOCTYPE HTML>
|
|
<html>
|
|
<!--
|
|
Bug 1060093 - Test DebuggerServer.getProcess
|
|
-->
|
|
<head>
|
|
<meta charset="utf-8">
|
|
<title>Mozilla Bug</title>
|
|
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
|
|
<link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css">
|
|
</head>
|
|
<body>
|
|
<pre id="test">
|
|
<script type="application/javascript">
|
|
"use strict";
|
|
|
|
// Part of this is a frame script.
|
|
/* eslint-env mozilla/frame-script */
|
|
|
|
const {require} = ChromeUtils.import("resource://devtools/shared/Loader.jsm", {});
|
|
const {DebuggerClient} = require("devtools/shared/client/debugger-client");
|
|
const {DebuggerServer} = require("devtools/server/main");
|
|
const Services = require("Services");
|
|
|
|
window.onload = function() {
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
SpecialPowers.pushPrefEnv({
|
|
"set": [
|
|
// Always log packets when running tests.
|
|
["devtools.debugger.log", true],
|
|
// Enabled mozbrowser frame to support remote=true
|
|
["dom.mozBrowserFramesEnabled", true],
|
|
// Allows creating a branch new process when creation the iframe
|
|
["dom.ipc.processCount", 10],
|
|
],
|
|
}, runTests);
|
|
};
|
|
|
|
function runTests() {
|
|
// Instantiate a minimal server
|
|
DebuggerServer.init();
|
|
DebuggerServer.allowChromeProcess = true;
|
|
if (!DebuggerServer.createRootActor) {
|
|
DebuggerServer.registerAllActors();
|
|
}
|
|
|
|
let client, iframe, processCount;
|
|
|
|
function connect() {
|
|
// Fake a first connection to the content process
|
|
const transport = DebuggerServer.connectPipe();
|
|
client = new DebuggerClient(transport);
|
|
client.connect().then(listProcess);
|
|
}
|
|
|
|
function listProcess() {
|
|
// Call listProcesses in order to start receiving new process notifications
|
|
client.mainRoot.on("processListChanged", function listener() {
|
|
client.removeListener("processListChanged", listener);
|
|
ok(true, "Received processListChanged event");
|
|
getProcess();
|
|
});
|
|
client.mainRoot.listProcesses().then(response => {
|
|
processCount = response.processes.length;
|
|
// Create a remote iframe to spawn a new process
|
|
createRemoteIframe();
|
|
});
|
|
}
|
|
|
|
function createRemoteIframe() {
|
|
iframe = document.createElement("iframe");
|
|
iframe.mozbrowser = true;
|
|
iframe.setAttribute("remote", "true");
|
|
iframe.setAttribute("src", "data:text/html,foo");
|
|
document.body.appendChild(iframe);
|
|
}
|
|
|
|
function getProcess() {
|
|
client.mainRoot.listProcesses().then(response => {
|
|
ok(response.processes.length >= 2, "Got at least the parent process and one child");
|
|
is(response.processes.length, processCount + 1,
|
|
"Got one additional process on the second call to listProcesses");
|
|
|
|
// Connect to the first content processe available
|
|
const content = response.processes.filter(p => (!p.parent))[0];
|
|
|
|
client.mainRoot.getProcess(content.id).then(front => {
|
|
const actor = front.targetForm;
|
|
ok(actor.consoleActor, "Got the console actor");
|
|
ok(actor.chromeDebugger, "Got the thread actor");
|
|
|
|
// Ensure sending at least one request to an actor...
|
|
client.request({
|
|
to: actor.consoleActor,
|
|
type: "evaluateJS",
|
|
text: "var a = 42; a",
|
|
}, function({result}) {
|
|
is(result, 42, "console.eval worked");
|
|
|
|
getProcessAgain(actor, content.id);
|
|
});
|
|
});
|
|
});
|
|
}
|
|
|
|
// Assert that calling client.getProcess against the same process id is
|
|
// returning the same actor.
|
|
function getProcessAgain(firstActor, id) {
|
|
client.mainRoot.getProcess(id).then(front => {
|
|
const actor = front.targetForm;
|
|
is(actor, firstActor,
|
|
"Second call to getProcess with the same id returns the same form");
|
|
closeClient();
|
|
});
|
|
}
|
|
|
|
function processScript() {
|
|
ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
const listener = function() {
|
|
Services.obs.removeObserver(listener, "devtools:loader:destroy");
|
|
sendAsyncMessage("test:getProcess-destroy", null);
|
|
};
|
|
Services.obs.addObserver(listener, "devtools:loader:destroy");
|
|
}
|
|
|
|
function closeClient() {
|
|
const onLoaderDestroyed = new Promise(done => {
|
|
const processListener = function() {
|
|
Services.ppmm.removeMessageListener("test:getProcess-destroy", processListener);
|
|
done();
|
|
};
|
|
Services.ppmm.addMessageListener("test:getProcess-destroy", processListener);
|
|
});
|
|
const script = "data:,(" + processScript + ")()";
|
|
Services.ppmm.loadProcessScript(script, true);
|
|
client.close();
|
|
|
|
onLoaderDestroyed.then(function() {
|
|
Services.ppmm.removeDelayedProcessScript(script);
|
|
info("Loader destroyed in the content process");
|
|
|
|
cleanup();
|
|
});
|
|
}
|
|
|
|
function cleanup() {
|
|
DebuggerServer.destroy();
|
|
iframe.remove();
|
|
SimpleTest.finish();
|
|
}
|
|
|
|
connect();
|
|
}
|
|
|
|
</script>
|
|
</pre>
|
|
</body>
|
|
</html>
|