mirror of
https://github.com/mozilla/gecko-dev.git
synced 2025-01-06 00:10:25 +00:00
Bug 1686743 - Fix up CDP tests for when prompts.contentPromptSubDialog is enabled. r=remote-protocol-reviewers,mtigley,jdescottes
Differential Revision: https://phabricator.services.mozilla.com/D110270
This commit is contained in:
parent
6d3a6fbf56
commit
e5940abe8b
@ -30,8 +30,4 @@ const RecommendedPreferences = new Map([
|
||||
"-tp,tpPrivate,cookieBehavior0,-cm,-fp",
|
||||
],
|
||||
["network.cookie.cookieBehavior", 0],
|
||||
|
||||
// Only allow the old modal dialogs. This should be removed when there is
|
||||
// support for the new modal UI (see Bug 1686743).
|
||||
["prompts.contentPromptSubDialog", false],
|
||||
]);
|
||||
|
@ -15,6 +15,13 @@ XPCOMUtils.defineLazyModuleGetters(this, {
|
||||
Services: "resource://gre/modules/Services.jsm",
|
||||
});
|
||||
|
||||
XPCOMUtils.defineLazyPreferenceGetter(
|
||||
this,
|
||||
"contentPromptSubDialog",
|
||||
"prompts.contentPromptSubDialog",
|
||||
false
|
||||
);
|
||||
|
||||
const DIALOG_TYPES = {
|
||||
ALERT: "alert",
|
||||
BEFOREUNLOAD: "beforeunload",
|
||||
@ -38,8 +45,13 @@ class DialogHandler {
|
||||
this._dialog = null;
|
||||
this._browser = browser;
|
||||
|
||||
this._onCommonDialogLoaded = this._onCommonDialogLoaded.bind(this);
|
||||
this._onTabDialogLoaded = this._onTabDialogLoaded.bind(this);
|
||||
|
||||
Services.obs.addObserver(
|
||||
this._onCommonDialogLoaded,
|
||||
"common-dialog-loaded"
|
||||
);
|
||||
Services.obs.addObserver(this._onTabDialogLoaded, "tabmodal-dialog-loaded");
|
||||
}
|
||||
|
||||
@ -47,6 +59,10 @@ class DialogHandler {
|
||||
this._dialog = null;
|
||||
this._pageTarget = null;
|
||||
|
||||
Services.obs.removeObserver(
|
||||
this._onCommonDialogLoaded,
|
||||
"common-dialog-loaded"
|
||||
);
|
||||
Services.obs.removeObserver(
|
||||
this._onTabDialogLoaded,
|
||||
"tabmodal-dialog-loaded"
|
||||
@ -71,7 +87,13 @@ class DialogHandler {
|
||||
|
||||
// 0 corresponds to the OK callback, 1 to the CANCEL callback.
|
||||
if (accept) {
|
||||
this._dialog.onButtonClick(0);
|
||||
if (contentPromptSubDialog) {
|
||||
this._dialog.ui.button0.click();
|
||||
} else {
|
||||
this._dialog.onButtonClick(0);
|
||||
}
|
||||
} else if (contentPromptSubDialog) {
|
||||
this._dialog.ui.button1.click();
|
||||
} else {
|
||||
this._dialog.onButtonClick(1);
|
||||
}
|
||||
@ -103,6 +125,23 @@ class DialogHandler {
|
||||
}
|
||||
}
|
||||
|
||||
_onCommonDialogLoaded(dialogWindow) {
|
||||
const dialogs = this._browser.tabDialogBox.getContentDialogManager()
|
||||
.dialogs;
|
||||
const dialog = dialogs.find(d => d.frameContentWindow === dialogWindow);
|
||||
|
||||
if (!dialog) {
|
||||
// The dialog is not for the current tab.
|
||||
return;
|
||||
}
|
||||
|
||||
this._dialog = dialogWindow.Dialog;
|
||||
const message = this._dialog.args.text;
|
||||
const type = this._getDialogType();
|
||||
|
||||
this.emit("dialog-loaded", { message, type });
|
||||
}
|
||||
|
||||
_onTabDialogLoaded(promptContainer) {
|
||||
const prompts = this._browser.tabModalPromptBox.listPrompts();
|
||||
const prompt = prompts.find(p => p.ui.promptContainer === promptContainer);
|
||||
|
@ -25,13 +25,25 @@ add_task(async function({ client }) {
|
||||
|
||||
// Create a promise that resolve when dialog prompt is created.
|
||||
// It will also take care of closing the dialog.
|
||||
const onOtherPageDialog = new Promise(r => {
|
||||
Services.obs.addObserver(function onDialogLoaded(promptContainer) {
|
||||
Services.obs.removeObserver(onDialogLoaded, "tabmodal-dialog-loaded");
|
||||
promptContainer.querySelector(".tabmodalprompt-button0").click();
|
||||
r();
|
||||
}, "tabmodal-dialog-loaded");
|
||||
});
|
||||
let onOtherPageDialog;
|
||||
|
||||
if (Services.prefs.getBoolPref("prompts.contentPromptSubDialog", false)) {
|
||||
onOtherPageDialog = new Promise(r => {
|
||||
Services.obs.addObserver(function onDialogLoaded(promptWindow) {
|
||||
Services.obs.removeObserver(onDialogLoaded, "common-dialog-loaded");
|
||||
promptWindow.Dialog.ui.button0.click();
|
||||
r();
|
||||
}, "common-dialog-loaded");
|
||||
});
|
||||
} else {
|
||||
onOtherPageDialog = new Promise(r => {
|
||||
Services.obs.addObserver(function onDialogLoaded(promptContainer) {
|
||||
Services.obs.removeObserver(onDialogLoaded, "tabmodal-dialog-loaded");
|
||||
promptContainer.querySelector(".tabmodalprompt-button0").click();
|
||||
r();
|
||||
}, "tabmodal-dialog-loaded");
|
||||
});
|
||||
}
|
||||
|
||||
info("Trigger an alert in the second page");
|
||||
SpecialPowers.spawn(gBrowser.selectedBrowser, [], () => {
|
||||
|
@ -80,6 +80,10 @@ SubDialog.prototype = {
|
||||
_titleElement: null,
|
||||
_closeButton: null,
|
||||
|
||||
get frameContentWindow() {
|
||||
return this._frame?.contentWindow;
|
||||
},
|
||||
|
||||
get _window() {
|
||||
return this._overlay?.ownerGlobal;
|
||||
},
|
||||
@ -987,6 +991,10 @@ class SubDialogManager {
|
||||
return this._dialogs.some(dialog => !dialog._isClosing);
|
||||
}
|
||||
|
||||
get dialogs() {
|
||||
return [...this._dialogs];
|
||||
}
|
||||
|
||||
focusTopDialog() {
|
||||
this._topDialog?.focus();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user