1 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1273251
3 const {NetUtil} = ChromeUtils.importESModule("resource://gre/modules/NetUtil.sys.mjs");
4 const {TestUtils} = ChromeUtils.importESModule("resource://testing-common/TestUtils.sys.mjs");
6 function getWindowlessBrowser(url) {
7 let ssm = Services.scriptSecurityManager;
9 let uri = NetUtil.newURI(url);
11 let principal = ssm.createContentPrincipal(uri, {});
13 let webnav = Services.appShell.createWindowlessBrowser(false);
15 let docShell = webnav.docShell;
17 docShell.createAboutBlankDocumentViewer(principal, principal);
22 function StubPolicy(id) {
23 return new WebExtensionPolicy({
25 mozExtensionHostname: id,
26 baseURL: `file:///{id}`,
28 allowedOrigins: new MatchPatternSet([]),
29 localizeCallback(string) {},
33 add_task(async function() {
34 let policy = StubPolicy("foo");
37 let webnavA = getWindowlessBrowser("moz-extension://foo/a.html");
38 let webnavB = getWindowlessBrowser("moz-extension://foo/b.html");
40 let winA = Cu.waiveXrays(webnavA.document.defaultView);
41 let winB = Cu.waiveXrays(webnavB.document.defaultView);
44 winB.eval(`winA.thing = {foo: "bar"};`);
46 let getThing = winA.eval(String(() => {
54 // Check that the object can be accessed normally before windowB is closed.
55 equal(getThing(), "bar");
59 // Wrappers are nuked asynchronously, so wait for that to happen.
60 await TestUtils.topicObserved("inner-window-nuked");
62 // Check that it can't be accessed after he window has been closed.
63 let result = getThing();
64 ok(/dead object/.test(result),
65 `Result should show a dead wrapper error: ${result}`);
69 policy.active = false;