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_nukeContentWindow.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_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> |