Bug 1724319 - Fix tests in toolkit/mozapps/downloads/test + browser_first_download_panel.js when download pref enabled. r=mtigley

Differential Revision: https://phabricator.services.mozilla.com/D125214
This commit is contained in:
Katherine Patenio 2021-09-14 19:45:17 +00:00
Родитель f9724c80fd
Коммит 886ed09b00
4 изменённых файлов: 97 добавлений и 12 удалений

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

@ -49,17 +49,26 @@ add_task(async function test_first_download_panel() {
"Should have recorded that the panel was opened on a download."
);
// Next, make sure that if we start another download, we don't open the
// panel automatically.
let originalOnPopupShown = DownloadsPanel.onPopupShown;
DownloadsPanel.onPopupShown = function() {
originalOnPopupShown.apply(this, arguments);
ok(false, "Should not have opened the downloads panel.");
};
// If browser.download.improvements_to_download_panel is enabled, this will fail
// because we always open a downloads panel as long as there is no other simulatenous
// download. So, first ensure that this pref is already false.
if (
!SpecialPowers.getBoolPref(
"browser.download.improvements_to_download_panel"
)
) {
// Next, make sure that if we start another download, we don't open the
// panel automatically.
let originalOnPopupShown = DownloadsPanel.onPopupShown;
DownloadsPanel.onPopupShown = function() {
originalOnPopupShown.apply(this, arguments);
ok(false, "Should not have opened the downloads panel.");
};
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
DownloadsCommon.getData(window)._notifyDownloadEvent("start");
// Wait 2 seconds to ensure that the panel does not open.
await new Promise(resolve => setTimeout(resolve, 2000));
DownloadsPanel.onPopupShown = originalOnPopupShown;
// Wait 2 seconds to ensure that the panel does not open.
await new Promise(resolve => setTimeout(resolve, 2000));
DownloadsPanel.onPopupShown = originalOnPopupShown;
}
});

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

@ -51,6 +51,30 @@ function waitDelay(delay) {
}
add_task(async function test_unknownContentType_delayedbutton() {
info("Starting browser_unknownContentType_delayedbutton.js...");
// If browser.download.improvements_to_download_panel pref is enabled,
// the unknownContentType will not appear by default.
// So wait an amount of time to ensure it hasn't opened.
let windowOpenDelay = waitDelay(1000);
let uctWindow = await Promise.race([
windowOpenDelay,
UCTObserver.opened.promise,
]);
const prefEnabled = Services.prefs.getBoolPref(
"browser.download.improvements_to_download_panel",
false
);
if (prefEnabled) {
SimpleTest.is(
!uctWindow,
true,
"UnknownContentType window shouldn't open."
);
return;
}
Services.ww.registerNotification(UCTObserver);
await BrowserTestUtils.withNewTab(

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

@ -31,6 +31,13 @@ let tests = [
},
];
function waitDelay(delay) {
return new Promise((resolve, reject) => {
/* eslint-disable mozilla/no-arbitrary-setTimeout */
window.setTimeout(resolve, delay);
});
}
add_task(async function test_unknownContentType_dialog_layout() {
for (let test of tests) {
let UCTObserver = {
@ -72,7 +79,26 @@ add_task(async function test_unknownContentType_dialog_layout() {
waitForStateStop: true,
},
async function() {
let uctWindow = await UCTObserver.opened.promise;
// If browser.download.improvements_to_download_panel pref is enabled,
// the unknownContentType will not appear by default.
// So wait an amount of time to ensure it hasn't opened.
let windowOpenDelay = waitDelay(1000);
let uctWindow = await Promise.race([
windowOpenDelay,
UCTObserver.opened.promise,
]);
const prefEnabled = Services.prefs.getBoolPref(
"browser.download.improvements_to_download_panel"
);
if (prefEnabled) {
SimpleTest.is(
!uctWindow,
true,
"UnknownContentType window shouldn't open."
);
return;
}
for (let [id, props] of Object.entries(test.elements)) {
let elem = uctWindow.dialog.dialogElement(id);

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

@ -8,12 +8,38 @@ const TEST_PATH = getRootDirectory(gTestPath).replace(
"http://example.com"
);
function waitDelay(delay) {
return new Promise((resolve, reject) => {
/* eslint-disable mozilla/no-arbitrary-setTimeout */
window.setTimeout(resolve, delay);
});
}
/**
* Check that case-sensitivity doesn't cause us to duplicate
* file name extensions.
*/
add_task(async function test_download_filename_extension() {
let windowObserver = BrowserTestUtils.domWindowOpenedAndLoaded();
// If browser.download.improvements_to_download_panel pref is enabled,
// the unknownContentType will not appear by default.
// So wait an amount of time to ensure it hasn't opened.
let windowOpenDelay = waitDelay(1000);
let uctWindow = await Promise.race([windowOpenDelay, windowObserver.promise]);
const prefEnabled = Services.prefs.getBoolPref(
"browser.download.improvements_to_download_panel"
);
if (prefEnabled) {
SimpleTest.is(
!uctWindow,
true,
"UnknownContentType window shouldn't open."
);
return;
}
let tab = await BrowserTestUtils.openNewForegroundTab({
gBrowser,
opening: TEST_PATH + "unknownContentType.EXE",