2014-10-29 13:11:33 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<!--
|
|
|
|
Any copyright is dedicated to the Public Domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/
|
|
|
|
-->
|
|
|
|
<window title="Test for WorkerDebugger"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
onload="test();">
|
|
|
|
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
|
|
|
|
<script type="application/javascript"
|
|
|
|
src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
|
|
|
|
<script type="application/javascript" src="dom_worker_helper.js"/>
|
|
|
|
|
|
|
|
<script type="application/javascript">
|
|
|
|
<![CDATA[
|
|
|
|
|
2015-03-17 03:15:19 -07:00
|
|
|
const WORKER_URL = "WorkerDebugger_worker.js";
|
2014-10-29 13:11:33 -07:00
|
|
|
const CHILD_WORKER_URL = "WorkerDebugger_childWorker.js";
|
|
|
|
const SHARED_WORKER_URL = "WorkerDebugger_sharedWorker.js";
|
|
|
|
|
|
|
|
function test() {
|
|
|
|
Task.spawn(function* () {
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
|
|
|
|
2015-03-17 03:15:19 -07:00
|
|
|
info("Create a top-level chrome worker that creates a non-top-level " +
|
|
|
|
"content worker and wait for their debuggers to be registered.");
|
2014-10-29 13:11:33 -07:00
|
|
|
let promise = waitForMultiple([
|
2015-03-17 03:15:19 -07:00
|
|
|
waitForRegister(WORKER_URL),
|
|
|
|
waitForRegister(CHILD_WORKER_URL)
|
2014-10-29 13:11:33 -07:00
|
|
|
]);
|
2015-03-17 03:15:19 -07:00
|
|
|
worker = new ChromeWorker(WORKER_URL);
|
|
|
|
let [dbg, childDbg] = yield promise;
|
2014-10-29 13:11:33 -07:00
|
|
|
|
2015-03-17 03:15:19 -07:00
|
|
|
info("Check that the top-level chrome worker debugger has the " +
|
|
|
|
"correct properties.");
|
|
|
|
is(dbg.isChrome, true,
|
|
|
|
"Chrome worker debugger should be chrome.");
|
|
|
|
is(dbg.parent, null,
|
|
|
|
"Top-level debugger should not have parent.");
|
|
|
|
is(dbg.type, Ci.nsIWorkerDebugger.TYPE_DEDICATED,
|
|
|
|
"Chrome worker debugger should be dedicated.");
|
|
|
|
is(dbg.window, window,
|
|
|
|
"Top-level dedicated worker debugger should have window.");
|
|
|
|
|
|
|
|
info("Check that the non-top-level content worker debugger has the " +
|
|
|
|
"correct properties.");
|
|
|
|
is(childDbg.isChrome, false,
|
|
|
|
"Content worker debugger should be content.");
|
|
|
|
is(childDbg.parent, dbg,
|
|
|
|
"Non-top-level worker debugger should have parent.");
|
|
|
|
is(childDbg.type, Ci.nsIWorkerDebugger.TYPE_DEDICATED,
|
|
|
|
"Content worker debugger should be dedicated.");
|
|
|
|
is(childDbg.window, null,
|
|
|
|
"Non-top-level worker debugger should not have window.");
|
|
|
|
|
|
|
|
info("Terminate the top-level chrome worker and the non-top-level " +
|
|
|
|
"content worker, and wait for their debuggers to be " +
|
|
|
|
"unregistered and closed.");
|
2014-10-29 13:11:33 -07:00
|
|
|
promise = waitForMultiple([
|
2015-03-17 03:15:19 -07:00
|
|
|
waitForUnregister(CHILD_WORKER_URL),
|
|
|
|
waitForDebuggerClose(childDbg),
|
|
|
|
waitForUnregister(WORKER_URL),
|
|
|
|
waitForDebuggerClose(dbg),
|
2014-10-29 13:11:33 -07:00
|
|
|
]);
|
|
|
|
worker.terminate();
|
|
|
|
yield promise;
|
|
|
|
|
2015-03-17 03:15:19 -07:00
|
|
|
info("Create a shared worker and wait for its debugger to be " +
|
|
|
|
"registered");
|
|
|
|
promise = waitForRegister(SHARED_WORKER_URL);
|
2014-10-29 13:11:33 -07:00
|
|
|
worker = new SharedWorker(SHARED_WORKER_URL);
|
2015-03-17 03:15:19 -07:00
|
|
|
let sharedDbg = yield promise;
|
|
|
|
|
|
|
|
info("Check that the shared worker debugger has the correct " +
|
|
|
|
"properties.");
|
|
|
|
is(sharedDbg.isChrome, false,
|
|
|
|
"Shared worker debugger should be content.");
|
|
|
|
is(sharedDbg.parent, null,
|
|
|
|
"Shared worker debugger should not have parent.");
|
|
|
|
is(sharedDbg.type, Ci.nsIWorkerDebugger.TYPE_SHARED,
|
|
|
|
"Shared worker debugger should be shared.");
|
|
|
|
is(sharedDbg.window, null,
|
|
|
|
"Shared worker debugger should not have window.");
|
2014-10-29 13:11:33 -07:00
|
|
|
|
2015-03-17 03:15:19 -07:00
|
|
|
info("Create a shared worker with the same URL and check that its " +
|
|
|
|
"debugger is not registered again.");
|
2014-10-29 13:11:33 -07:00
|
|
|
let listener = {
|
|
|
|
onRegistered: function () {
|
|
|
|
ok(false,
|
2015-03-17 03:15:19 -07:00
|
|
|
"Shared worker debugger should not be registered again.");
|
2014-10-29 13:11:33 -07:00
|
|
|
},
|
|
|
|
};
|
|
|
|
wdm.addListener(listener);
|
|
|
|
worker = new SharedWorker(SHARED_WORKER_URL);
|
|
|
|
|
2015-03-17 03:15:19 -07:00
|
|
|
info("Send a message to the shared worker to tell it to close " +
|
|
|
|
"itself, and wait for its debugger to be closed.");
|
|
|
|
promise = waitForMultiple([
|
|
|
|
waitForUnregister(SHARED_WORKER_URL),
|
|
|
|
waitForDebuggerClose(sharedDbg)
|
|
|
|
]);
|
2014-10-29 13:11:33 -07:00
|
|
|
worker.port.start();
|
|
|
|
worker.port.postMessage("close");
|
2015-03-17 03:15:19 -07:00
|
|
|
yield promise;
|
|
|
|
|
|
|
|
wdm.removeListener(listener);
|
|
|
|
SimpleTest.finish();
|
2014-10-29 13:11:33 -07:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
]]>
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<body xmlns="http://www.w3.org/1999/xhtml">
|
|
|
|
<p id="display"></p>
|
|
|
|
<div id="content" style="display:none;"></div>
|
|
|
|
<pre id="test"></pre>
|
|
|
|
</body>
|
|
|
|
<label id="test-result"/>
|
|
|
|
</window>
|