mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-11-24 21:31:04 +00:00
Bug 1450358
P8 Test that SharedWorker does not leak windows through its event listener. r=baku
This commit is contained in:
parent
41c2f967ce
commit
489c37ab4f
@ -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]
|
||||
|
52
dom/workers/test/test_sharedworker_event_listener_leaks.html
Normal file
52
dom/workers/test/test_sharedworker_event_listener_leaks.html
Normal 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>
|
||||
|
Loading…
Reference in New Issue
Block a user