mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-12-03 02:25:34 +00:00
Bug 1711381 - correctly handle the browser no longer being present for content and tabmodal prompts, r=pbz
Differential Revision: https://phabricator.services.mozilla.com/D115244
This commit is contained in:
parent
0082aed4d4
commit
276f5ab72c
@ -270,6 +270,15 @@ class PromptParent extends JSWindowActorParent {
|
||||
let browsingContext = this.browsingContext.top;
|
||||
|
||||
let browser = browsingContext.embedderElement;
|
||||
let promptRequiresBrowser =
|
||||
args.modalType === Services.prompt.MODAL_TYPE_TAB ||
|
||||
args.modalType === Services.prompt.MODAL_TYPE_CONTENT;
|
||||
if (promptRequiresBrowser && !browser) {
|
||||
let modal_type =
|
||||
args.modalType === Services.prompt.MODAL_TYPE_TAB ? "tab" : "content";
|
||||
throw new Error(`Cannot ${modal_type}-prompt without a browser!`);
|
||||
}
|
||||
|
||||
let win;
|
||||
|
||||
// If we are a chrome actor we can use the associated chrome win.
|
||||
@ -284,7 +293,7 @@ class PromptParent extends JSWindowActorParent {
|
||||
// passed window is the hidden window).
|
||||
// See bug 875157 comment 30 for more..
|
||||
if (win?.winUtils && !win.winUtils.isParentWindowMainWidgetVisible) {
|
||||
throw new Error("Cannot call openModalWindow on a hidden window");
|
||||
throw new Error("Cannot open a prompt in a hidden window");
|
||||
}
|
||||
|
||||
try {
|
||||
@ -304,18 +313,7 @@ class PromptParent extends JSWindowActorParent {
|
||||
// Convert args object to a prop bag for the dialog to consume.
|
||||
let bag;
|
||||
|
||||
if (
|
||||
(args.modalType === Services.prompt.MODAL_TYPE_TAB ||
|
||||
args.modalType === Services.prompt.MODAL_TYPE_CONTENT) &&
|
||||
win?.gBrowser?.getTabDialogBox
|
||||
) {
|
||||
if (!browser) {
|
||||
let modal_type =
|
||||
args.modalType === Services.prompt.MODAL_TYPE_TAB
|
||||
? "tab"
|
||||
: "content";
|
||||
throw new Error(`Cannot ${modal_type}-prompt without a browser!`);
|
||||
}
|
||||
if (promptRequiresBrowser && win?.gBrowser?.getTabDialogBox) {
|
||||
// Tab or content level prompt
|
||||
let dialogBox = win.gBrowser.getTabDialogBox(browser);
|
||||
|
||||
|
@ -9,5 +9,6 @@ support-files = file_beforeunload_stop.html
|
||||
[browser_openPromptInBackgroundTab.js]
|
||||
support-files = openPromptOffTimeout.html
|
||||
[browser_promptFocus.js]
|
||||
[browser_prompt_closed_window.js]
|
||||
[browser_switchTabPermissionPrompt.js]
|
||||
[browser_windowPrompt.js]
|
||||
|
@ -0,0 +1,35 @@
|
||||
/* Any copyright is dedicated to the Public Domain.
|
||||
http://creativecommons.org/publicdomain/zero/1.0/ */
|
||||
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Check that if we loop prompts from a closed tab, they don't
|
||||
* start showing up as window prompts.
|
||||
*/
|
||||
add_task(async function test_closed_tab_doesnt_show_prompt() {
|
||||
let newWin = await BrowserTestUtils.openNewBrowserWindow();
|
||||
|
||||
// Get a promise for the initial, in-tab prompt:
|
||||
let promptPromise = BrowserTestUtils.promiseAlertDialogOpen();
|
||||
await ContentTask.spawn(newWin.gBrowser.selectedBrowser, [], function() {
|
||||
// Don't want to block, so use setTimeout with 0 timeout:
|
||||
content.setTimeout(
|
||||
() => content.eval('while (!prompt("Prompts forever!"));'),
|
||||
0
|
||||
);
|
||||
});
|
||||
// wait for the first prompt to have appeared:
|
||||
await promptPromise;
|
||||
|
||||
// Now close the containing tab, and check for windowed prompts appearing.
|
||||
let opened = false;
|
||||
let obs = () => {
|
||||
opened = true;
|
||||
};
|
||||
Services.obs.addObserver(obs, "domwindowopened");
|
||||
await BrowserTestUtils.closeWindow(newWin);
|
||||
Services.obs.removeObserver(obs, "domwindowopened");
|
||||
|
||||
ok(!opened, "Should not have opened a prompt when closing the main window.");
|
||||
});
|
Loading…
Reference in New Issue
Block a user