1 /* This Source Code Form is subject to the terms of the Mozilla Public
2 * License, v. 2.0. If a copy of the MPL was not distributed with this
3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
5 const {NetUtil} = ChromeUtils.importESModule("resource://gre/modules/NetUtil.sys.mjs");
6 const {TestUtils} = ChromeUtils.importESModule("resource://testing-common/TestUtils.sys.mjs");
8 function getWindowlessBrowser(url) {
9 let ssm = Services.scriptSecurityManager;
10 let uri = NetUtil.newURI(url);
11 let principal = ssm.createContentPrincipal(uri, {});
12 let webnav = Services.appShell.createWindowlessBrowser(false);
14 let docShell = webnav.docShell;
15 docShell.createAboutBlankDocumentViewer(principal, principal);
17 let document = webnav.document;
18 let video = document.createElement("video");
19 document.documentElement.appendChild(video);
21 let shadowRoot = video.openOrClosedShadowRoot;
22 ok(shadowRoot, "should have shadowRoot");
23 ok(shadowRoot.isUAWidget(), "ShadowRoot should be a UAWidget");
24 equal(Cu.getGlobalForObject(shadowRoot), Cu.getUAWidgetScope(principal),
25 "shadowRoot should be in UAWidget scope");
30 function StubPolicy(id) {
31 return new WebExtensionPolicy({
33 mozExtensionHostname: id,
34 baseURL: `file:///{id}`,
35 allowedOrigins: new MatchPatternSet([]),
36 localizeCallback(string) {},
40 // See https://bugzilla.mozilla.org/show_bug.cgi?id=1588356
41 add_task(async function() {
42 let policy = StubPolicy("foo");
45 let webnav = getWindowlessBrowser("moz-extension://foo/a.html");
48 // Wrappers are nuked asynchronously, so wait for that to happen.
49 await TestUtils.topicObserved("inner-window-nuked");
51 webnav = getWindowlessBrowser("moz-extension://foo/a.html");
54 policy.active = false;