summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/test_WorkerDebugger.xul
blob: f3397bd54cb8536d0053f60f1211e26e1a9e6183 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
<?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[

    const WORKER_URL = "WorkerDebugger_worker.js";
    const CHILD_WORKER_URL = "WorkerDebugger_childWorker.js";
    const SHARED_WORKER_URL = "WorkerDebugger_sharedWorker.js";

    function test() {
      Task.spawn(function* () {
        SimpleTest.waitForExplicitFinish();

        info("Create a top-level chrome worker that creates a non-top-level " +
             "content worker and wait for their debuggers to be registered.");
        let promise = waitForMultiple([
          waitForRegister(WORKER_URL),
          waitForRegister(CHILD_WORKER_URL)
        ]);
        worker = new ChromeWorker(WORKER_URL);
        let [dbg, childDbg] = yield promise;

        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.");
        promise = waitForMultiple([
          waitForUnregister(CHILD_WORKER_URL),
          waitForDebuggerClose(childDbg),
          waitForUnregister(WORKER_URL),
          waitForDebuggerClose(dbg),
        ]);
        worker.terminate();
        yield promise;

        info("Create a shared worker and wait for its debugger to be " + 
             "registered");
        promise = waitForRegister(SHARED_WORKER_URL);
        worker = new SharedWorker(SHARED_WORKER_URL);
        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.");

        info("Create a shared worker with the same URL and check that its " +
             "debugger is not registered again.");
        let listener = {
          onRegistered: function () {
            ok(false,
               "Shared worker debugger should not be registered again.");
          },
        };
        wdm.addListener(listener);
        worker = new SharedWorker(SHARED_WORKER_URL);

        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)
        ]);
        worker.port.start();
        worker.port.postMessage("close");
        yield promise;

        wdm.removeListener(listener);
        SimpleTest.finish();
      });
    }

  ]]>
  </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>