Bug 1724319 - fix accessibility test relying on the download modal opening to work with download improvements pref flipped, r=Jamie

Differential Revision: https://phabricator.services.mozilla.com/D127487
This commit is contained in:
Gijs Kruitbosch 2021-10-05 09:04:26 +00:00
Родитель 2a3b5cf56a
Коммит cd8c2be09f
1 изменённых файлов: 38 добавлений и 15 удалений

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

@ -20,6 +20,8 @@
<script type="application/javascript">
const { BrowserTestUtils } = ChromeUtils.import(
"resource://testing-common/BrowserTestUtils.jsm");
const { Downloads } = ChromeUtils.import(
"resource://gre/modules/Downloads.jsm");
function matchDocBusyChange(isBusy) {
return function(event) {
@ -32,6 +34,33 @@
};
}
function getDownloadStartedPromise() {
if (Services.prefs.getBoolPref("browser.download.improvements_to_download_panel", false)) {
return Downloads.getList(Downloads.PUBLIC).then(list => {
return new Promise(resolve => {
list.addView({
onDownloadAdded(download) {
resolve(download);
}
})
});
});
}
return BrowserTestUtils.domWindowOpenedAndLoaded(
null,
win => win.location?.href == "chrome://mozapps/content/downloads/unknownContentType.xhtml"
);
}
async function downloadHandled(downloadResult) {
if (Window.isInstance(downloadResult)) {
return BrowserTestUtils.closeWindow(downloadResult);
}
// downloadResult is a download object.
await downloadResult.finalize(true);
return Downloads.getList(Downloads.PUBLIC).then(list => list.remove(downloadResult));
}
async function doTest() {
// Because of variable timing, there are two acceptable possibilities:
// 1. We get an event for busy and an event for not busy.
@ -40,10 +69,6 @@
// second.
let gotBusy = false;
let gotNotBusy = false;
// We never actually wait on this; we just check the booleans it sets.
// We still need to hold a reference so it doesn't get garbage collected
// before it does anything.
// eslint-disable-next-line no-unused-vars
const busyEvents = async function() {
await waitForEvent(EVENT_STATE_CHANGE, matchDocBusyChange(true));
info("Got busy event");
@ -53,20 +78,18 @@
gotNotBusy = true;
}();
const downloadPromptOpened = BrowserTestUtils.domWindowOpened(null,
async win => {
info("Window opened, waiting for load event");
await BrowserTestUtils.waitForEvent(win, "load");
info("Window loaded, checking if download prompt");
return win.location &&
win.location.href == "chrome://mozapps/content/downloads/unknownContentType.xhtml";
}
);
const downloadStarted = getDownloadStartedPromise();
info("Clicking link to trigger download");
synthesizeMouse(getNode("link"), 1, 1, {});
info("Waiting for download prompt to open");
const downloadWin = await downloadPromptOpened;
const downloadResult = await downloadStarted;
// Once we no longer show a dialog for downloads, the not busy event
// might show up a bit later.
if (gotBusy && !gotNotBusy) {
await busyEvents;
}
// Any busy events should have been fired by the time the download
// prompt has opened.
@ -81,7 +104,7 @@
// Clean up.
info("Closing download prompt");
downloadWin.close();
await downloadHandled(downloadResult);
// We might still be waiting on busy events. Remove any pending observers.
for (let observer of Services.obs.enumerateObservers(
"accessible-event")