Skip to content

Commit e3f0c65

Browse files
committed
Bug 1881055 - Remove use of PromptParent.openContentPrompt for handling prompts originated from extensions options page embedded in about:addons. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D202237
1 parent ffcae73 commit e3f0c65

File tree

3 files changed

+50
-48
lines changed

3 files changed

+50
-48
lines changed

browser/actors/PromptParent.sys.mjs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ export class PromptParent extends JSWindowActorParent {
140140
(args.modalType === Ci.nsIPrompt.MODAL_TYPE_CONTENT &&
141141
!lazy.contentPromptSubDialog) ||
142142
(args.modalType === Ci.nsIPrompt.MODAL_TYPE_TAB &&
143-
!lazy.tabChromePromptSubDialog) ||
144-
this.isAboutAddonsOptionsPage(this.browsingContext)
143+
!lazy.tabChromePromptSubDialog)
145144
) {
146145
return this.openContentPrompt(args, id);
147146
}
@@ -262,6 +261,11 @@ export class PromptParent extends JSWindowActorParent {
262261
let browsingContext = this.browsingContext.top;
263262

264263
let browser = browsingContext.embedderElement;
264+
265+
if (this.isAboutAddonsOptionsPage(browsingContext)) {
266+
browser = browser.ownerGlobal.browsingContext.embedderElement;
267+
}
268+
265269
let promptRequiresBrowser =
266270
args.modalType === Services.prompt.MODAL_TYPE_TAB ||
267271
args.modalType === Services.prompt.MODAL_TYPE_CONTENT;

browser/components/extensions/test/browser/browser_ext_optionsPage_modals.js

Lines changed: 42 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,43 @@
22
/* vim: set sts=2 sw=2 et tw=80: */
33
"use strict";
44

5+
ChromeUtils.defineModuleGetter(
6+
this,
7+
"PromptTestUtils",
8+
"resource://testing-common/PromptTestUtils.jsm"
9+
);
10+
11+
async function waitForExtensionModalPrompt(extension) {
12+
const dialog = await PromptTestUtils.waitForPrompt(gBrowser.selectedBrowser, {
13+
modalType: Ci.nsIPrompt.MODAL_TYPE_CONTENT,
14+
});
15+
ok(dialog, "Got an active modal prompt dialog as expected");
16+
Assert.equal(
17+
dialog?.args.promptPrincipal.addonId,
18+
extension.id,
19+
"Got a prompt associated to the expected extension id"
20+
);
21+
22+
const promptTitle = dialog?.ui.infoTitle.textContent;
23+
ok(
24+
/The page at TestExtName says:/.test(promptTitle),
25+
`Got the expect title on the modal prompt dialog: "${promptTitle}"`
26+
);
27+
28+
return {
29+
async closeModalPrompt() {
30+
info("Close the tab modal prompt");
31+
await PromptTestUtils.handlePrompt(dialog);
32+
},
33+
assertClosedModalPrompt() {
34+
ok(
35+
!dialog.args.promptActive,
36+
"modal prompt dialog has been closed as expected"
37+
);
38+
},
39+
};
40+
}
41+
542
add_task(async function test_tab_options_modals() {
643
function backgroundScript() {
744
browser.runtime.openOptionsPage();
@@ -26,6 +63,7 @@ add_task(async function test_tab_options_modals() {
2663
options_ui: {
2764
page: "options.html",
2865
},
66+
name: "TestExtName",
2967
},
3068
files: {
3169
"options.html": `<!DOCTYPE html>
@@ -42,57 +80,15 @@ add_task(async function test_tab_options_modals() {
4280

4381
await BrowserTestUtils.openNewForegroundTab(gBrowser, "about:addons");
4482

83+
const testPromptPromise = waitForExtensionModalPrompt(extension);
4584
await extension.startup();
4685

47-
const onceModalOpened = new Promise(resolve => {
48-
const aboutAddonsBrowser = gBrowser.selectedBrowser;
49-
50-
aboutAddonsBrowser.addEventListener(
51-
"DOMWillOpenModalDialog",
52-
function onModalDialog(event) {
53-
// Wait for the next event tick to make sure the remaining part of the
54-
// testcase runs after the dialog gets opened.
55-
SimpleTest.executeSoon(resolve);
56-
},
57-
{ once: true, capture: true }
58-
);
59-
});
60-
6186
info("Wait the options_ui modal to be opened");
62-
await onceModalOpened;
63-
64-
const optionsBrowser = getInlineOptionsBrowser(gBrowser.selectedBrowser);
65-
66-
// The stack that contains the tabmodalprompt elements is the parent of
67-
// the extensions options_ui browser element.
68-
let stack = optionsBrowser.parentNode;
69-
70-
let dialogs = stack.querySelectorAll("tabmodalprompt");
71-
Assert.equal(
72-
dialogs.length,
73-
1,
74-
"Expect a tab modal opened for the about addons tab"
75-
);
76-
77-
// Verify that the expected stylesheets have been applied on the
78-
// tabmodalprompt element (See Bug 1550529).
79-
const tabmodalStyle = dialogs[0].ownerGlobal.getComputedStyle(dialogs[0]);
80-
is(
81-
tabmodalStyle["background-color"],
82-
"rgba(26, 26, 26, 0.5)",
83-
"Got the expected styles applied to the tabmodalprompt"
84-
);
85-
86-
info("Close the tab modal prompt");
87-
dialogs[0].querySelector(".tabmodalprompt-button0").click();
87+
const testModalPrompt = await testPromptPromise;
8888

89+
testModalPrompt.closeModalPrompt();
8990
await extension.awaitFinish("options-ui-modals");
90-
91-
Assert.equal(
92-
stack.querySelectorAll("tabmodalprompt").length,
93-
0,
94-
"Expect the tab modal to be closed"
95-
);
91+
testModalPrompt.assertClosedModalPrompt();
9692

9793
BrowserTestUtils.removeTab(gBrowser.selectedTab);
9894

toolkit/mozapps/extensions/content/aboutaddons.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1744,6 +1744,8 @@ class InlineOptionsBrowser extends HTMLElement {
17441744
readyPromise = promiseEvent("load", browser, true);
17451745
}
17461746

1747+
// TODO(rpl): we can remove this stack element once we are ripping off
1748+
// the content prompt support (and `prompts.contentPromptSubDialog` pref).
17471749
let stack = document.createXULElement("stack");
17481750
stack.classList.add("inline-options-stack");
17491751
stack.appendChild(browser);

0 commit comments

Comments
 (0)