Source code

Revision control

Copy as Markdown

Other Tools

Test Info: Errors

<!--
Any copyright is dedicated to the Public Domain.
-->
<!DOCTYPE HTML>
<html>
<head>
<title>Bug 1450358 - Test BroadcastChannel 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 BroadcastChannel 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.
let count = 0;
async function useBroadcastChannel(contentWindow) {
contentWindow.messageCount = 0;
count += 1;
const name = `test_event_listener_leaks-${count}`;
let bc = new contentWindow.BroadcastChannel(name);
let outer = new BroadcastChannel(name);
outer.postMessage("foo");
await new Promise(resolve => {
bc.onmessage = () => {
contentWindow.messageCount += 1;
resolve();
};
});
is(contentWindow.messageCount, 1, "message should be received");
}
async function runTest() {
try {
await checkForEventListenerLeaks("BroadcastChannel", useBroadcastChannel);
} catch (e) {
ok(false, e);
} finally {
SimpleTest.finish();
}
}
SimpleTest.waitForExplicitFinish();
addEventListener("load", runTest, { once: true });
</script>
</pre>
</body>
</html>