summaryrefslogtreecommitdiffstats
path: root/dom/workers/test/test_sharedworker_event_listener_leaks.html
blob: 4016cdda480a9cd6116185758827cb955fdac305 (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
<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 1450358 - Test SharedWorker event listener leak conditions</title>
  <script src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="/tests/dom/events/test/event_leak_utils.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<script class="testbody" type="text/javascript">
// Manipulate SharedWorker objects in the frame's context.
// Its important here that we create a listener callback from
// the DOM objects back to the frame's global in order to
// exercise the leak condition.
async function useSharedWorker(contentWindow) {
  contentWindow.messageCount = 0;

  let sw = new contentWindow.SharedWorker("data:application/javascript,self.onconnect = e => e.ports[0].postMessage({})");
  sw.onerror = _ => {
    contentWindow.errorCount += 1;
  }
  await new Promise(resolve => {
    sw.port.onmessage = e => {
      contentWindow.messageCount += 1;
      resolve();
    };
  });

  is(contentWindow.messageCount, 1, "message should be received");
}

async function runTest() {
  try {
    await checkForEventListenerLeaks("SharedWorker", useSharedWorker);
  } catch (e) {
    ok(false, e);
  } finally {
    SimpleTest.finish();
  }
}

SimpleTest.waitForExplicitFinish();
addEventListener("load", runTest, { once: true });
</script>
</pre>
</body>
</html>