Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / mochitest / test_finalizationRegistry_incumbent.html
blob8b6c71c9cfe396af3574794988590d069a4d2ce1
1 <!DOCTYPE HTML>
2 <html>
3 <head>
4 <meta charset="utf-8">
5 <title>Test FinalizationRegistry tracks its incumbent global</title>
6 <script src="/tests/SimpleTest/SimpleTest.js"></script>
7 <script type="application/javascript">
8 let resolvePromise, rejectPromise;
10 async function runTest(global, callback) {
11 let fr = new global.FinalizationRegistry(callback);
12 fr.register({}, undefined);
14 SpecialPowers.DOMWindowUtils.garbageCollect();
16 let promise = new Promise((resolve, reject) => {
17 resolvePromise = resolve;
18 rejectPromise = reject;
19 });
21 return promise;
24 function receiveMessage(event) {
25 resolvePromise(event.source.sourceName);
28 async function go() {
29 // This test uses FinalizationRegistry to trigger a callback and reports
30 // the incumbent global in the callback using postMessage. In all cases
31 // the author function that scheduled the callback is runTest(), so the
32 // incumbent global should be the main window.
34 SimpleTest.waitForExplicitFinish();
36 window.sourceName = "main";
37 window.addEventListener("message", receiveMessage, false);
39 let other = window.frames[0];
40 other.sourceName = "other";
41 other.addEventListener("message", receiveMessage, false);
43 is(await runTest(window, v => window.postMessage(v)), "main");
44 is(await runTest(window, window.postMessage.bind(window)), "main");
45 is(await runTest(other, v => other.postMessage(v)), "main");
46 is(await runTest(other, other.postMessage.bind(other)), "main");
47 is(await runTest(window, v => other.postMessage(v)), "main");
48 is(await runTest(window, other.postMessage.bind(other)), "main");
49 is(await runTest(other, v => window.postMessage(v)), "main");
50 is(await runTest(other, window.postMessage.bind(window)), "main");
52 SimpleTest.finish();
54 </script>
55 </head>
56 <body onload="go()">
57 <div style="display: none">
58 <!-- A subframe so we have another global to work with -->
59 <iframe></iframe>
60 </div>
61 </body>
62 </html>