summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/test_shutdownCheck.xhtml
blob: 257b37fe32ea18fadb4203b3d626b1eb0ed355e8 (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
<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>

<window title="Worker shutdown check"
        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
  <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>

  <!-- test results are displayed in the html:body -->
  <body xmlns="http://www.w3.org/1999/xhtml">
  </body>

  <!-- test code goes here -->
  <script type="application/javascript">
  <![CDATA[

SimpleTest.waitForExplicitFinish()

const URL = "worker_shutdownCheck.js";

function checkWorker() {
  const wdm = Cc["@mozilla.org/dom/workers/workerdebuggermanager;1"].
              getService(Ci.nsIWorkerDebuggerManager);

  let e = wdm.getWorkerDebuggerEnumerator();
  while (e.hasMoreElements()) {
    let dbg = e.getNext().QueryInterface(Ci.nsIWorkerDebugger);
    if (dbg.url == URL) {
      return true;
    }
  }

  return false;
}

new Promise(resolve => {
  var w = new Worker(URL);
  ok(checkWorker(), "We have the worker");
  w.onmessage = () => { resolve(); }
}).then(() => {
  info("Waiting...");

  // We don't know if the worker thread is able to shutdown when calling
  // CC/GC. Better to check again in case.
  function checkGC() {
    Cu.forceCC();
    Cu.forceGC();
    if (!checkWorker()) {
      ok(true, "We don't have the worker");
      SimpleTest.finish();
      return;
    }
    setTimeout(checkGC, 200);
  }

  checkGC();
});

  ]]>
  </script>
</window>