Bug 1915045 Ensure decode tasks are scheduled on BufferingState::Enter() r=media...
[gecko.git] / js / xpconnect / tests / mochitest / test_nukeContentWindow.html
blob0db8749b5928e3bd52be3f2ca563259c96d45956
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=1322273
5 -->
6 <head>
7 <meta charset="utf-8">
8 <title>Test for Bug 1322273</title>
9 <script src="/tests/SimpleTest/SimpleTest.js"></script>
10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1322273">Mozilla Bug 1322273</a>
15 <iframe id="subframe"></iframe>
17 <script type="application/javascript">
18 "use strict";
20 function waitForWindowDestroyed(winID, callback) {
21 let observer = {
22 observe: function(subject, topic, data) {
23 let id = subject.QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data;
24 if (id != winID) {
25 return;
27 SpecialPowers.removeObserver(observer, "outer-window-nuked");
28 SpecialPowers.executeSoon(callback);
31 SpecialPowers.addObserver(observer, "outer-window-nuked");
34 add_task(async function() {
35 let frame = $('subframe');
36 frame.srcdoc = "foo";
37 await new Promise(resolve => frame.addEventListener("load", resolve, {once: true}));
39 let win = frame.contentWindow;
40 let winID = SpecialPowers.wrap(win).docShell.outerWindowID;
42 win.eval("obj = {}");
43 win.obj.foo = {bar: "baz"};
45 let obj = win.obj;
47 let system = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal()
48 let sandbox = SpecialPowers.Cu.Sandbox(system);
50 sandbox.obj = obj;
52 let isWrapperDead = SpecialPowers.Cu.evalInSandbox(`(${
53 function isWrapperDead() {
54 return Cu.isDeadWrapper(obj);
56 })`,
57 sandbox);
59 is(isWrapperDead(), false, "Sandbox wrapper for content window should not be dead");
60 is(obj.foo.bar, "baz", "Content wrappers into and out of content window should be alive");
62 // Remove the frame, which should nuke the content window.
63 info("Remove the content frame");
64 frame.remove();
66 // Give the nuke wrappers task a chance to run.
67 await new Promise(resolve => waitForWindowDestroyed(winID, resolve));
69 is(isWrapperDead(), true, "Sandbox wrapper for content window should be dead");
70 is(obj.foo.bar, "baz", "Content wrappers into and out of content window should be alive");
71 });
72 </script>
74 </body>
75 </html>