Bug 1698526 - Ensure we call SubDialog close callbacks when closing a SubDialog that has not fully opened. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D109063
This commit is contained in:
Paul Zuehlcke 2021-03-19 12:56:22 +00:00
Родитель 9441435604
Коммит 8cfe56f0d0
2 изменённых файлов: 44 добавлений и 7 удалений

Просмотреть файл

@ -200,3 +200,31 @@ add_task(async function test_check_multiple_prompts() {
ok(!menu.disabled, `Menu ${menu.id} should not be disabled anymore.`);
}
});
/**
* Tests that we get a closed callback even when closing the prompt before the
* underlying SubDialog has fully opened.
*/
add_task(async function test_closed_callback() {
await SpecialPowers.pushPrefEnv({
set: [["prompts.windowPromptSubDialog", true]],
});
let promptClosedPromise = Services.prompt.asyncAlert(
window.browsingContext,
Services.prompt.MODAL_TYPE_INTERNAL_WINDOW,
"Hello",
"Hello, World!"
);
let dialog = gDialogBox._dialog;
ok(dialog, "gDialogBox should have a dialog");
// Directly close the dialog without waiting for it to initialize.
dialog.close();
info("Waiting for prompt close");
await promptClosedPromise;
ok(!gDialogBox._dialog, "gDialogBox should no longer have a dialog");
});

Просмотреть файл

@ -118,6 +118,21 @@ SubDialog.prototype = {
});
this._frame._dialogReady = this._dialogReady;
// Assign close callbacks sync to ensure we can always callback even if the
// SubDialog is closed directly after opening.
let dialog = null;
if (closingCallback) {
this._closingCallback = (...args) => {
closingCallback.apply(dialog, args);
};
}
if (closedCallback) {
this._closedCallback = (...args) => {
closedCallback.apply(dialog, args);
};
}
// Wait until frame is ready to prevent browser crash in tests
await this._frameCreated;
@ -152,18 +167,12 @@ SubDialog.prototype = {
dialogFeatures = `${features},${dialogFeatures}`;
}
let dialog = this._window.openDialog(
dialog = this._window.openDialog(
aURL,
`dialogFrame-${this._id}`,
dialogFeatures,
...aParams
);
if (closingCallback) {
this._closingCallback = closingCallback.bind(dialog);
}
if (closedCallback) {
this._closedCallback = closedCallback.bind(dialog);
}
this._closingEvent = null;
this._isClosing = false;