Bug 1693133 - Fix resetProfile.xhtml tests r=Gijs

BrowserTestUtils.promiseAlertDialog and friends account for commonDialog.xhtml,
but not other dialogs which go through gDialogBox. This fixes that by adding a
inWindowDialog option to promiseAlertDialog. I don't like this solution very
much - it requires all of these dialogs to fire the event themselves. An
alternative might be putting this code in some file which these all include,
but given how small the code is that feels like overkill. Alternatives welcome.

Differential Revision: https://phabricator.services.mozilla.com/D109674
This commit is contained in:
Doug Thayer 2021-03-25 17:28:56 +00:00
parent a51c508d35
commit ec23c3ca31
7 changed files with 26 additions and 39 deletions

View File

@ -13,32 +13,13 @@ add_UITour_task(async function test_resetFirefox() {
!canReset,
"Shouldn't be able to reset from mochitest's temporary profile."
);
let dialogPromise = new Promise(resolve => {
Services.ww.registerNotification(function onOpen(subj, topic, data) {
if (topic == "domwindowopened" && subj instanceof Ci.nsIDOMWindow) {
subj.addEventListener(
"load",
function() {
if (
subj.document.documentURI ==
"chrome://global/content/resetProfile.xhtml"
) {
Services.ww.unregisterNotification(onOpen);
ok(true, "Observed search manager window open");
is(
subj.opener,
window,
"Reset Firefox event opened a reset profile window."
);
subj.close();
resolve();
}
},
{ once: true }
);
}
});
});
let dialogPromise = BrowserTestUtils.promiseAlertDialog(
"cancel",
"chrome://global/content/resetProfile.xhtml",
{
isSubDialog: true,
}
);
// make reset possible.
let profileService = Cc["@mozilla.org/toolkit/profile-service;1"].getService(

View File

@ -25,7 +25,8 @@ add_task(async function refresh() {
awaitCallback() {
return BrowserTestUtils.promiseAlertDialog(
"cancel",
"chrome://global/content/resetProfile.xhtml"
"chrome://global/content/resetProfile.xhtml",
{ isSubDialog: true }
);
},
});

View File

@ -41,7 +41,8 @@ add_task(async function test() {
awaitCallback() {
return BrowserTestUtils.promiseAlertDialog(
"cancel",
"chrome://global/content/resetProfile.xhtml"
"chrome://global/content/resetProfile.xhtml",
{ isSubDialog: true }
);
},
});

View File

@ -38,10 +38,8 @@ async function clearDownloads() {
*/
function promiseClickDownloadDialogButton(buttonAction) {
const uri = "chrome://mozapps/content/downloads/unknownContentType.xhtml";
return BrowserTestUtils.promiseAlertDialogOpen(
buttonAction,
uri,
async win => {
return BrowserTestUtils.promiseAlertDialogOpen(buttonAction, uri, {
async callback(win) {
// nsHelperAppDlg.js currently uses an eval-based setTimeout(0) to invoke
// its postShowCallback that results in a misleading error to the console
// if we close the dialog before it gets a chance to run. Just a
@ -59,8 +57,8 @@ function promiseClickDownloadDialogButton(buttonAction) {
button.disabled = false;
info(`clicking ${buttonAction} button`);
button.click();
}
);
},
});
}
async function performCanceledDownload(tab, path) {

View File

@ -2308,11 +2308,13 @@ var BrowserTestUtils = {
async promiseAlertDialogOpen(
buttonAction,
uri = "chrome://global/content/commonDialog.xhtml",
func = null
options = { callback: null, isSubDialog: false }
) {
let win;
if (uri == "chrome://global/content/commonDialog.xhtml") {
[win] = await TestUtils.topicObserved("common-dialog-loaded");
} else if (options.isSubDialog) {
[win] = await TestUtils.topicObserved("subdialog-loaded");
} else {
// The test listens for the "load" event which guarantees that the alert
// class has already been added (it is added when "DOMContentLoaded" is
@ -2322,8 +2324,8 @@ var BrowserTestUtils = {
});
}
if (func) {
await func(win);
if (options.callback) {
await options.callback(win);
return win;
}
@ -2351,9 +2353,9 @@ var BrowserTestUtils = {
async promiseAlertDialog(
buttonAction,
uri = "chrome://global/content/commonDialog.xhtml",
func
options = { callback: null, isSubDialog: false }
) {
let win = await this.promiseAlertDialogOpen(buttonAction, uri, func);
let win = await this.promiseAlertDialogOpen(buttonAction, uri, options);
if (!win.docShell.browsingContext.embedderElement) {
return this.windowClosed(win);
}

View File

@ -4,6 +4,8 @@
"use strict";
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
document.addEventListener("dialogaccept", onResetProfileAccepted);
document
.getElementById("refreshProfileLearnMore")

View File

@ -394,6 +394,8 @@ SubDialog.prototype = {
this._frame.contentDocument.body ||
this._frame.contentDocument.documentElement;
a11yDoc.setAttribute("role", "dialog");
Services.obs.notifyObservers(this._frame.contentWindow, "subdialog-loaded");
},
async _onLoad(aEvent) {