Backed out changeset 06f41c22f3a6 (bug 1888460) for causing linux xpcshell failures...
[gecko.git] / dom / workers / test / test_WorkerDebugger_console.xhtml
blobb38ccdac457cc7006d0999011175d19876e45e42
1 <?xml version="1.0"?>
2 <!--
3 Any copyright is dedicated to the Public Domain.
4 http://creativecommons.org/publicdomain/zero/1.0/
5 -->
6 <window title="Test for WorkerDebuggerGlobalScope.console methods"
7 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
8 onload="test();">
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">
15 <![CDATA[
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;
22 function test() {
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 = {
33 observe(aSubject) {
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();
46 (async function() {
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)
54 ]);
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.");
60 dbg.addListener({
61 onMessage(msg) {
62 try {
63 msg = JSON.parse(msg);
64 } catch(e) {
65 ok(false, "Something went wrong");
66 return;
69 if (msg.type == 'finish') {
70 ok(consoleMessagesReceived, "We received something via debugger console!");
71 dbg.removeListener(this);
72 SimpleTest.finish();
73 return;
76 if (msg.type == 'status') {
77 ok(msg.what, msg.msg);
78 return;
81 ok(false, "Something went wrong");
83 });
85 dbg.postMessage("do magic");
86 })();
89 ]]>
90 </script>
92 <body xmlns="http://www.w3.org/1999/xhtml">
93 <p id="display"></p>
94 <div id="content" style="display:none;"></div>
95 <pre id="test"></pre>
96 </body>
97 <label id="test-result"/>
98 </window>