Bug 1738372 - Add a pref to control whether the downloads panel opens on every new download. r=Gijs

Differential Revision: https://phabricator.services.mozilla.com/D130931
This commit is contained in:
Molly Howell 2021-11-16 00:03:27 +00:00
Родитель a35fd106db
Коммит 18e12efbad
3 изменённых файлов: 62 добавлений и 1 удалений

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

@ -536,6 +536,10 @@ pref("browser.download.viewableInternally.enabledTypes", "xml,svg,webp,avif,jxl"
// on whether there are downloads to show.
pref("browser.download.autohideButton", true);
// Controls whether to open the downloads panel every time a download begins.
// The first download ever run in a new profile will still open the panel.
pref("browser.download.alwaysOpenPanel", true);
#ifndef XP_MACOSX
pref("browser.helperApps.deleteTempFileOnExit", true);
#endif

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

@ -62,6 +62,10 @@ XPCOMUtils.defineLazyGetter(this, "DownloadsLogger", () => {
return new ConsoleAPI(consoleOptions);
});
XPCOMUtils.defineLazyGetter(this, "gAlwaysOpenPanel", () => {
return Services.prefs.getBoolPref("browser.download.alwaysOpenPanel", true);
});
const kDownloadsStringBundleUrl =
"chrome://browser/locale/downloads/downloads.properties";
@ -952,7 +956,8 @@ DownloadsDataCtor.prototype = {
Services.prefs.getBoolPref(
"browser.download.improvements_to_download_panel"
) &&
DownloadsCommon.summarizeDownloads(this.downloads).numDownloading <= 1;
DownloadsCommon.summarizeDownloads(this.downloads).numDownloading <= 1 &&
gAlwaysOpenPanel;
if (
this.panelHasShownBefore &&

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

@ -24,6 +24,58 @@ add_task(async function test_downloads_panel_opens() {
DownloadsPanel.hidePanel();
});
/**
* Make sure the downloads panel _does not_ open automatically if we set the
* pref telling it not to do that.
*/
add_task(async function test_downloads_panel_opening_pref() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.download.improvements_to_download_panel", true],
["browser.download.alwaysOpenPanel", false],
],
});
registerCleanupFunction(async () => {
await SpecialPowers.popPrefEnv();
});
info("creating a download and setting it to in progress");
await task_addDownloads([{ state: DownloadsCommon.DOWNLOAD_DOWNLOADING }]);
let publicList = await Downloads.getList(Downloads.PUBLIC);
let downloads = await publicList.getAll();
downloads[0].stopped = false;
// Make sure we remove that download at the end of the test.
let oldShowEventNotification = DownloadsIndicatorView.showEventNotification;
registerCleanupFunction(async () => {
for (let download of downloads) {
await publicList.remove(download);
}
DownloadsIndicatorView.showEventNotification = oldShowEventNotification;
});
// Instead of the panel opening, the download notification should be shown.
let promiseDownloadStartedNotification = new Promise(resolve => {
DownloadsIndicatorView.showEventNotification = aType => {
if (aType == "start") {
resolve();
}
};
});
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
is(
DownloadsPanel.isPanelShowing,
false,
"Panel state should indicate it is not preparing to be opened"
);
info("waiting for download to start");
await promiseDownloadStartedNotification;
is(DownloadsPanel.panel.state, "closed", "Panel should be closed");
});
/**
* Make sure the downloads panel opens automatically with new download, only if no other downloads are in progress.
*/