3 Any copyright is dedicated to the Public Domain.
4 http://creativecommons.org/publicdomain/zero/1.0/
6 <window title=
"Test for WorkerDebuggerGlobalScope.console methods"
7 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
10 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
11 <script src=
"chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
12 <script type=
"application/javascript" src=
"dom_worker_helper.js"/>
14 <script type=
"application/javascript">
17 const WORKER_URL =
"WorkerDebugger.console_worker.js";
18 const CHILD_WORKER_URL =
"WorkerDebugger.console_childWorker.js";
19 const DEBUGGER_URL = BASE_URL +
"WorkerDebugger.console_debugger.js";
21 consoleMessagesReceived =
0;
23 const ConsoleAPIStorage = SpecialPowers.Cc[
24 "@mozilla.org/consoleAPI-storage;1"
25 ].getService(SpecialPowers.Ci.nsIConsoleAPIStorage);
27 function consoleListener() {
28 this.observe = this.observe.bind(this);
29 ConsoleAPIStorage.addLogEventListener(this.observe, SpecialPowers.wrap(document).nodePrincipal);
32 consoleListener.prototype = {
34 var obj = aSubject.wrappedJSObject;
35 if (obj.arguments[
0] ==
"Hello from the debugger script!" &&
36 !consoleMessagesReceived) {
37 consoleMessagesReceived++;
38 ok(true,
"Something has been received");
39 ConsoleAPIStorage.removeLogEventListener(this.observe);
44 var cl = new consoleListener();
47 SimpleTest.waitForExplicitFinish();
49 info(
"Create a worker that creates a child worker, wait for their " +
50 "debuggers to be registered, and initialize them.");
51 let promise = waitForMultiple([
52 waitForRegister(WORKER_URL, DEBUGGER_URL),
53 waitForRegister(CHILD_WORKER_URL, DEBUGGER_URL)
55 let worker = new Worker(WORKER_URL);
56 let [dbg, childDbg] = await promise;
58 info(
"Send a request to the worker debugger. This should cause the " +
59 "the worker debugger to send a response.");
63 msg = JSON.parse(msg);
65 ok(false,
"Something went wrong");
69 if (msg.type == 'finish') {
70 ok(consoleMessagesReceived,
"We received something via debugger console!");
71 dbg.removeListener(this);
76 if (msg.type == 'status') {
77 ok(msg.what, msg.msg);
81 ok(false,
"Something went wrong");
85 dbg.postMessage(
"do magic");
92 <body xmlns=
"http://www.w3.org/1999/xhtml">
94 <div id=
"content" style=
"display:none;"></div>
97 <label id=
"test-result"/>