diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /js/xpconnect/tests/mochitest/test_finalizationRegistry_incumbent.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect/tests/mochitest/test_finalizationRegistry_incumbent.html')
-rw-r--r-- | js/xpconnect/tests/mochitest/test_finalizationRegistry_incumbent.html | 62 |
1 files changed, 62 insertions, 0 deletions
diff --git a/js/xpconnect/tests/mochitest/test_finalizationRegistry_incumbent.html b/js/xpconnect/tests/mochitest/test_finalizationRegistry_incumbent.html new file mode 100644 index 0000000000..8b6c71c9cf --- /dev/null +++ b/js/xpconnect/tests/mochitest/test_finalizationRegistry_incumbent.html @@ -0,0 +1,62 @@ +<!DOCTYPE HTML> +<html> + <head> + <meta charset="utf-8"> + <title>Test FinalizationRegistry tracks its incumbent global</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <script type="application/javascript"> + let resolvePromise, rejectPromise; + + async function runTest(global, callback) { + let fr = new global.FinalizationRegistry(callback); + fr.register({}, undefined); + + SpecialPowers.DOMWindowUtils.garbageCollect(); + + let promise = new Promise((resolve, reject) => { + resolvePromise = resolve; + rejectPromise = reject; + }); + + return promise; + } + + function receiveMessage(event) { + resolvePromise(event.source.sourceName); + } + + async function go() { + // This test uses FinalizationRegistry to trigger a callback and reports + // the incumbent global in the callback using postMessage. In all cases + // the author function that scheduled the callback is runTest(), so the + // incumbent global should be the main window. + + SimpleTest.waitForExplicitFinish(); + + window.sourceName = "main"; + window.addEventListener("message", receiveMessage, false); + + let other = window.frames[0]; + other.sourceName = "other"; + other.addEventListener("message", receiveMessage, false); + + is(await runTest(window, v => window.postMessage(v)), "main"); + is(await runTest(window, window.postMessage.bind(window)), "main"); + is(await runTest(other, v => other.postMessage(v)), "main"); + is(await runTest(other, other.postMessage.bind(other)), "main"); + is(await runTest(window, v => other.postMessage(v)), "main"); + is(await runTest(window, other.postMessage.bind(other)), "main"); + is(await runTest(other, v => window.postMessage(v)), "main"); + is(await runTest(other, window.postMessage.bind(window)), "main"); + + SimpleTest.finish(); + } + </script> + </head> + <body onload="go()"> + <div style="display: none"> + <!-- A subframe so we have another global to work with --> + <iframe></iframe> + </div> + </body> +</html> |