Backed out changeset 07410d76eca4 (bug 1738601) for causing failures on browser_shows_where_to_save_dialog.js. CLOSED TREE

This commit is contained in:
criss 2021-11-09 03:14:38 +02:00
Родитель 4dbb2de33b
Коммит fc61236ded
2 изменённых файлов: 15 добавлений и 196 удалений

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

@ -2629,10 +2629,18 @@ nsresult nsExternalAppHandler::ContinueSave(nsIFile* aNewFileLocation) {
int32_t action = nsIMIMEInfo::saveToDisk;
mMimeInfo->GetPreferredAction(&action);
mHandleInternally =
bool shouldAutomaticallyHandleInternally =
action == nsIMIMEInfo::handleInternally &&
StaticPrefs::browser_download_improvements_to_download_panel();
if (StaticPrefs::browser_download_improvements_to_download_panel() &&
(action == nsIMIMEInfo::useHelperApp ||
action == nsIMIMEInfo::useSystemDefault ||
shouldAutomaticallyHandleInternally)) {
return LaunchWithApplication(shouldAutomaticallyHandleInternally,
aNewFileLocation);
}
nsresult rv = NS_OK;
nsCOMPtr<nsIFile> fileToUse = aNewFileLocation;
mFinalFileDestination = fileToUse;

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

@ -3,21 +3,14 @@
"use strict";
const { DownloadIntegration } = ChromeUtils.import(
"resource://gre/modules/DownloadIntegration.jsm"
);
const TEST_PATH = getRootDirectory(gTestPath).replace(
"chrome://mochitests/content",
"https://example.com"
);
const { handleInternally, useHelperApp, useSystemDefault } = Ci.nsIHandlerInfo;
let MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
add_task(async function setup() {
// This test ensures that a "Save as..." filepicker dialog is shown for a file
// if useDownloadDir ("Always ask where to save files") is set to false
add_task(async function aDownloadLaunchedWithAppPromptsForFolder() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.download.improvements_to_download_panel", true],
@ -25,23 +18,13 @@ add_task(async function setup() {
],
});
registerCleanupFunction(async () => {
let hiddenPromise = BrowserTestUtils.waitForEvent(
DownloadsPanel.panel,
"popuphidden"
);
DownloadsPanel.hidePanel();
await hiddenPromise;
MockFilePicker.cleanup();
});
});
let MockFilePicker = SpecialPowers.MockFilePicker;
MockFilePicker.init(window);
// This test ensures that a "Save as..." filepicker dialog is shown for a file
// if useDownloadDir ("Always ask where to save files") is set to false
add_task(async function aDownloadLaunchedWithAppPromptsForFolder() {
let publicList = await Downloads.getList(Downloads.PUBLIC);
registerCleanupFunction(async () => {
await publicList.removeFinished();
MockFilePicker.cleanup();
});
let filePickerShown = new Promise(resolve => {
MockFilePicker.showCallback = function(fp) {
@ -60,175 +43,3 @@ add_task(async function aDownloadLaunchedWithAppPromptsForFolder() {
BrowserTestUtils.removeTab(loadingTab);
});
// This test ensures that downloads configured to open internally create only
// one file destination when saved via the filepicker.
add_task(async function testFilesHandledInternally() {
let dir = await setupFilePickerDirectory();
ensureMIMEState({ preferredAction: handleInternally });
let loadingTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "file_pdf_application_pdf.pdf"
);
await TestUtils.waitForCondition(() => {
return gBrowser.tabs[2].label === "file_pdf_application_pdf.pdf";
}, "A new tab for the downloaded pdf wasn't open.");
assertCorrectFile(dir);
// Cleanup
BrowserTestUtils.removeTab(loadingTab);
BrowserTestUtils.removeTab(gBrowser.selectedTab);
});
// This test ensures that downloads configured to open with a system default
// app create only one file destination when saved via the filepicker.
add_task(async function testFilesHandledBySystemDefaultApp() {
let dir = await setupFilePickerDirectory();
ensureMIMEState({ preferredAction: useSystemDefault });
let oldLaunchFile = DownloadIntegration.launchFile;
let launchFileCalled = new Promise(resolve => {
DownloadIntegration.launchFile = async (file, mimeInfo) => {
is(
useSystemDefault,
mimeInfo.preferredAction,
"The file should be launched with a system app handler."
);
resolve();
};
});
let loadingTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "file_pdf_application_pdf.pdf"
);
await launchFileCalled;
assertCorrectFile(dir);
// Cleanup
BrowserTestUtils.removeTab(loadingTab);
DownloadIntegration.launchFile = oldLaunchFile;
});
// This test ensures that downloads configured to open with a helper app create
// only one file destination when saved via the filepicker.
add_task(async function testFilesHandledByHelperApp() {
let dir = await setupFilePickerDirectory();
// Create a custom helper app so we can check that a launcherPath is
// configured for the serialized download.
let appHandler = Cc[
"@mozilla.org/uriloader/local-handler-app;1"
].createInstance(Ci.nsILocalHandlerApp);
appHandler.name = "Dummy Test Handler";
appHandler.executable = Services.dirsvc.get("ProfD", Ci.nsIFile);
appHandler.executable.append("helper_handler_test.exe");
if (!appHandler.executable.exists()) {
appHandler.executable.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o777);
}
ensureMIMEState({
preferredAction: useHelperApp,
preferredHandlerApp: appHandler,
});
let publicDownloads = await Downloads.getList(Downloads.PUBLIC);
let downloadFinishedPromise = new Promise(resolve => {
publicDownloads.addView({
onDownloadChanged(download) {
if (download.succeeded || download.error) {
ok(
download.launcherPath.includes("helper_handler_test.exe"),
"Launcher path is available."
);
resolve();
}
},
});
});
let oldLaunchFile = DownloadIntegration.launchFile;
let launchFileCalled = new Promise(resolve => {
DownloadIntegration.launchFile = async (file, mimeInfo) => {
is(
useHelperApp,
mimeInfo.preferredAction,
"The file should be launched with a helper app handler."
);
resolve();
};
});
let loadingTab = await BrowserTestUtils.openNewForegroundTab(
gBrowser,
TEST_PATH + "file_pdf_application_pdf.pdf"
);
await downloadFinishedPromise;
await launchFileCalled;
assertCorrectFile(dir);
// Cleanup
BrowserTestUtils.removeTab(loadingTab);
DownloadIntegration.launchFile = oldLaunchFile;
});
async function setupFilePickerDirectory() {
let saveDir = createSaveDir();
Services.prefs.setComplexValue("browser.download.dir", Ci.nsIFile, saveDir);
Services.prefs.setIntPref("browser.download.folderList", 2);
MockFilePicker.displayDirectory = saveDir;
MockFilePicker.returnValue = MockFilePicker.returnOK;
MockFilePicker.showCallback = function(fp) {
let file = saveDir.clone();
file.append(fp.defaultString);
MockFilePicker.setFiles([file]);
};
registerCleanupFunction(async () => {
Services.prefs.clearUserPref("browser.download.dir");
Services.prefs.clearUserPref("browser.download.folderList");
try {
await IOUtils.remove(saveDir, { recursive: true });
} catch (e) {
Cu.reportError(e);
}
});
return saveDir;
}
function assertCorrectFile(saveDir) {
info("Make sure additional files haven't been created.");
let iter = saveDir.directoryEntries;
let file = iter.nextFile;
ok(
file.path.includes("file_pdf_application_pdf.pdf"),
"Download has correct filename"
);
ok(!iter.nextFile, "Only one file was created.");
}
function createSaveDir() {
info("Creating save directory.");
let time = new Date().getTime();
let saveDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
saveDir.append(time);
return saveDir;
}
function ensureMIMEState({ preferredAction, preferredHandlerApp = null }) {
const mimeInfo = gMimeSvc.getFromTypeAndExtension("application/pdf", "pdf");
mimeInfo.preferredAction = preferredAction;
mimeInfo.preferredApplicationHandler = preferredHandlerApp;
gHandlerSvc.store(mimeInfo);
}