diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-28 14:29:10 +0000 |
commit | 2aa4a82499d4becd2284cdb482213d541b8804dd (patch) | |
tree | b80bf8bf13c3766139fbacc530efd0dd9d54394c /js/xpconnect/tests/mochitest/test_nukeContentWindow.html | |
parent | Initial commit. (diff) | |
download | firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.tar.xz firefox-2aa4a82499d4becd2284cdb482213d541b8804dd.zip |
Adding upstream version 86.0.1.upstream/86.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'js/xpconnect/tests/mochitest/test_nukeContentWindow.html')
-rw-r--r-- | js/xpconnect/tests/mochitest/test_nukeContentWindow.html | 75 |
1 files changed, 75 insertions, 0 deletions
diff --git a/js/xpconnect/tests/mochitest/test_nukeContentWindow.html b/js/xpconnect/tests/mochitest/test_nukeContentWindow.html new file mode 100644 index 0000000000..0db8749b59 --- /dev/null +++ b/js/xpconnect/tests/mochitest/test_nukeContentWindow.html @@ -0,0 +1,75 @@ +<!DOCTYPE HTML> +<html> +<!-- +https://bugzilla.mozilla.org/show_bug.cgi?id=1322273 +--> +<head> + <meta charset="utf-8"> + <title>Test for Bug 1322273</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> +</head> +<body> +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1322273">Mozilla Bug 1322273</a> + +<iframe id="subframe"></iframe> + +<script type="application/javascript"> +"use strict"; + +function waitForWindowDestroyed(winID, callback) { + let observer = { + observe: function(subject, topic, data) { + let id = subject.QueryInterface(SpecialPowers.Ci.nsISupportsPRUint64).data; + if (id != winID) { + return; + } + SpecialPowers.removeObserver(observer, "outer-window-nuked"); + SpecialPowers.executeSoon(callback); + } + }; + SpecialPowers.addObserver(observer, "outer-window-nuked"); +} + +add_task(async function() { + let frame = $('subframe'); + frame.srcdoc = "foo"; + await new Promise(resolve => frame.addEventListener("load", resolve, {once: true})); + + let win = frame.contentWindow; + let winID = SpecialPowers.wrap(win).docShell.outerWindowID; + + win.eval("obj = {}"); + win.obj.foo = {bar: "baz"}; + + let obj = win.obj; + + let system = SpecialPowers.Services.scriptSecurityManager.getSystemPrincipal() + let sandbox = SpecialPowers.Cu.Sandbox(system); + + sandbox.obj = obj; + + let isWrapperDead = SpecialPowers.Cu.evalInSandbox(`(${ + function isWrapperDead() { + return Cu.isDeadWrapper(obj); + } + })`, + sandbox); + + is(isWrapperDead(), false, "Sandbox wrapper for content window should not be dead"); + is(obj.foo.bar, "baz", "Content wrappers into and out of content window should be alive"); + + // Remove the frame, which should nuke the content window. + info("Remove the content frame"); + frame.remove(); + + // Give the nuke wrappers task a chance to run. + await new Promise(resolve => waitForWindowDestroyed(winID, resolve)); + + is(isWrapperDead(), true, "Sandbox wrapper for content window should be dead"); + is(obj.foo.bar, "baz", "Content wrappers into and out of content window should be alive"); +}); +</script> + +</body> +</html> |