Bug 1450358 P8 Test that SharedWorker does not leak windows through its event listener. r=baku

This commit is contained in:
Ben Kelly 2018-04-04 11:25:43 -07:00
parent 41c2f967ce
commit 489c37ab4f
2 changed files with 54 additions and 0 deletions

View File

@ -103,6 +103,7 @@ support-files =
!/dom/xhr/tests/subdir/relativeLoad_sub_worker.js
!/dom/xhr/tests/subdir/relativeLoad_sub_worker2.js
!/dom/xhr/tests/subdir/relativeLoad_sub_import.js
!/dom/events/test/event_leak_utils.js
[test_404.html]
[test_atob.html]
@ -196,3 +197,4 @@ scheme=https
[test_subworkers_suspended.html]
skip-if = toolkit == 'android' #bug 1366501
[test_bug1317725.html]
[test_sharedworker_event_listener_leaks.html]

View File

@ -0,0 +1,52 @@
<!--
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 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 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>