зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1768383 - Remember last per-domain download folder when saving a PDF r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D188988
This commit is contained in:
Родитель
746e764f2c
Коммит
4cf9581714
|
@ -170,3 +170,47 @@ add_task(async function test_pdf_saveas_customname() {
|
|||
);
|
||||
await SpecialPowers.popPrefEnv();
|
||||
});
|
||||
|
||||
/**
|
||||
* Check if the directory where the pdfs are saved is based on the original
|
||||
* domain (see bug 1768383).
|
||||
*/
|
||||
add_task(async function () {
|
||||
await BrowserTestUtils.withNewTab(
|
||||
{ gBrowser, url: "about:blank" },
|
||||
async function (browser) {
|
||||
const downloadLastDir = new DownloadLastDir(null);
|
||||
const destDirs = [];
|
||||
for (let i = 1; i <= 2; i++) {
|
||||
const destDir = createTemporarySaveDirectory(i);
|
||||
destDirs.push(destDir);
|
||||
const url = `http://test${i}.example.com/browser/${RELATIVE_DIR}file_pdfjs_test.pdf`;
|
||||
downloadLastDir.setFile(url, destDir);
|
||||
await TestUtils.waitForTick();
|
||||
}
|
||||
|
||||
const url = `http://test1.example.com/browser/${RELATIVE_DIR}file_pdfjs_hcm.pdf`;
|
||||
await waitForPdfJS(browser, url);
|
||||
|
||||
const fileSavedPromise = new Promise(resolve => {
|
||||
MockFilePicker.showCallback = fp => {
|
||||
MockFilePicker.setFiles([]);
|
||||
MockFilePicker.showCallback = null;
|
||||
resolve(fp.displayDirectory.path);
|
||||
};
|
||||
});
|
||||
registerCleanupFunction(() => {
|
||||
for (const destDir of destDirs) {
|
||||
destDir.remove(true);
|
||||
}
|
||||
});
|
||||
saveBrowser(browser);
|
||||
const dirPath = await fileSavedPromise;
|
||||
is(
|
||||
dirPath,
|
||||
destDirs[0].path,
|
||||
"Proposed directory must be based on the domain"
|
||||
);
|
||||
}
|
||||
);
|
||||
});
|
||||
|
|
|
@ -327,9 +327,9 @@ function changeMimeHandler(preferredAction, alwaysAskBeforeHandling) {
|
|||
return oldAction;
|
||||
}
|
||||
|
||||
function createTemporarySaveDirectory() {
|
||||
function createTemporarySaveDirectory(id = "") {
|
||||
var saveDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
|
||||
saveDir.append("testsavedir");
|
||||
saveDir.append(`testsavedir${id}`);
|
||||
if (!saveDir.exists()) {
|
||||
saveDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
|
||||
}
|
||||
|
|
|
@ -326,7 +326,8 @@ function internalSave(
|
|||
};
|
||||
|
||||
// Find a URI to use for determining last-downloaded-to directory
|
||||
let relatedURI = aReferrerInfo?.originalReferrer || sourceURI;
|
||||
let relatedURI =
|
||||
aOriginalURL || aReferrerInfo?.originalReferrer || sourceURI;
|
||||
|
||||
promiseTargetFile(fpParams, aSkipPrompt, relatedURI)
|
||||
.then(aDialogAccepted => {
|
||||
|
|
Загрузка…
Ссылка в новой задаче