From 2aa4a82499d4becd2284cdb482213d541b8804dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 28 Apr 2024 16:29:10 +0200 Subject: Adding upstream version 86.0.1. Signed-off-by: Daniel Baumann --- js/xpconnect/tests/unit/test_uawidget_scope.js | 57 ++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) create mode 100644 js/xpconnect/tests/unit/test_uawidget_scope.js (limited to 'js/xpconnect/tests/unit/test_uawidget_scope.js') diff --git a/js/xpconnect/tests/unit/test_uawidget_scope.js b/js/xpconnect/tests/unit/test_uawidget_scope.js new file mode 100644 index 0000000000..7aed7bdbb9 --- /dev/null +++ b/js/xpconnect/tests/unit/test_uawidget_scope.js @@ -0,0 +1,57 @@ +/* This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ + +ChromeUtils.import("resource://gre/modules/Timer.jsm"); +const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm"); +const {NetUtil} = ChromeUtils.import("resource://gre/modules/NetUtil.jsm"); +const {TestUtils} = ChromeUtils.import("resource://testing-common/TestUtils.jsm"); + +function getWindowlessBrowser(url) { + let ssm = Services.scriptSecurityManager; + let uri = NetUtil.newURI(url); + let principal = ssm.createContentPrincipal(uri, {}); + let webnav = Services.appShell.createWindowlessBrowser(false); + + let docShell = webnav.docShell; + docShell.createAboutBlankContentViewer(principal, principal); + + let document = webnav.document; + let video = document.createElement("video"); + document.documentElement.appendChild(video); + + let shadowRoot = video.openOrClosedShadowRoot; + ok(shadowRoot, "should have shadowRoot"); + ok(shadowRoot.isUAWidget(), "ShadowRoot should be a UAWidget"); + equal(Cu.getGlobalForObject(shadowRoot), Cu.getUAWidgetScope(principal), + "shadowRoot should be in UAWidget scope"); + + return webnav; +} + +function StubPolicy(id) { + return new WebExtensionPolicy({ + id, + mozExtensionHostname: id, + baseURL: `file:///{id}`, + allowedOrigins: new MatchPatternSet([]), + localizeCallback(string) {}, + }); +} + +// See https://bugzilla.mozilla.org/show_bug.cgi?id=1588356 +add_task(async function() { + let policy = StubPolicy("foo"); + policy.active = true; + + let webnav = getWindowlessBrowser("moz-extension://foo/a.html"); + webnav.close(); + + // Wrappers are nuked asynchronously, so wait for that to happen. + await TestUtils.topicObserved("inner-window-nuked"); + + webnav = getWindowlessBrowser("moz-extension://foo/a.html"); + webnav.close(); + + policy.active = false; +}); -- cgit v1.2.3