dom/messagechannel/tests/test_event_listener_leaks.html
author Agi Sferro <agi@mozilla.com>
Mon, 17 Dec 2018 22:32:11 +0000
changeset 451061 42f4f1c36ef6daf56fae1433db40a3116b3dfe9d
parent 422414 e4b352ed03f7bef3af5aa4c163a1a050177ab061
child 469641 ba6f655fd68963530c866d0d4a48c3db3d307777
permissions -rw-r--r--
Bug 1502118 - Enforce GV lints with apilint. r=snorp This makes it so that apilints lints with "GV" codes are enforced and will fail the build. Depends on D13882 Differential Revision: https://phabricator.services.mozilla.com/D13883

<!--
  Any copyright is dedicated to the Public Domain.
  http://creativecommons.org/publicdomain/zero/1.0/
-->
<!DOCTYPE HTML>
<html>
<head>
  <title>Bug 1450358 - Test MessageChannel event listener leak conditions</title>
  <script type="text/javascript" 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 MessageChannel 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 useMessagePort(contentWindow) {
  contentWindow.messageCount = 0;

  let mc = new contentWindow.MessageChannel
  mc.port1.postMessage("foo");

  await new Promise(resolve => {
    mc.port2.onmessage = e => {
      contentWindow.messageCount += 1;
      resolve();
    };
  });

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

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

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