Bug 1684006 - use the temp dir for downloads in uriloader tests, r=mak

This ensures that we don't leave downloads behind in race conditions, and that that
doesn't break future tests.

Differential Revision: https://phabricator.services.mozilla.com/D101041
This commit is contained in:
Gijs Kruitbosch 2021-01-08 17:47:37 +00:00
Родитель ddfec86473
Коммит e2caf16515
3 изменённых файлов: 59 добавлений и 33 удалений

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

@ -169,26 +169,23 @@ async function task_openPanel() {
} }
async function setDownloadDir() { async function setDownloadDir() {
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile); let tmpDir = await PathUtils.getTempDir();
tmpDir.append("testsavedir"); tmpDir = PathUtils.join(
if (!tmpDir.exists()) { tmpDir,
tmpDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755); "testsavedir" + Math.floor(Math.random() * 2 ** 32)
registerCleanupFunction(function() { );
try { // Create this dir if it doesn't exist (ignores existing dirs)
tmpDir.remove(true); await IOUtils.makeDirectory(tmpDir);
} catch (e) { registerCleanupFunction(async function() {
// On Windows debug build this may fail. try {
} await IOUtils.remove(tmpDir, { recursive: true });
}); } catch (e) {
} Cu.reportError(e);
}
await SpecialPowers.pushPrefEnv({
set: [
["browser.download.folderList", 2],
["browser.download.dir", tmpDir.path],
],
}); });
return tmpDir.path; Services.prefs.setIntPref("browser.download.folderList", 2);
Services.prefs.setCharPref("browser.download.dir", tmpDir);
return tmpDir;
} }
let gHttpServer = null; let gHttpServer = null;

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

@ -56,21 +56,23 @@ async function createDownloadedFile(pathname, contents) {
let gDownloadDir; let gDownloadDir;
async function setDownloadDir() { async function setDownloadDir() {
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile); let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile).path;
tmpDir.append("testsavedir"); tmpDir = PathUtils.join(
if (!tmpDir.exists()) { tmpDir,
tmpDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755); "testsavedir" + Math.floor(Math.random() * 2 ** 32)
registerCleanupFunction(function() { );
try { // Create this dir if it doesn't exist (ignores existing dirs)
tmpDir.remove(true); await IOUtils.makeDirectory(tmpDir);
} catch (e) { registerCleanupFunction(async function() {
// On Windows debug build this may fail. try {
} await IOUtils.remove(tmpDir, { recursive: true });
}); } catch (e) {
} Cu.reportError(e);
}
});
Services.prefs.setIntPref("browser.download.folderList", 2); Services.prefs.setIntPref("browser.download.folderList", 2);
Services.prefs.setCharPref("browser.download.dir", tmpDir.path); Services.prefs.setCharPref("browser.download.dir", tmpDir);
return tmpDir.path; return tmpDir;
} }
/** /**

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

@ -248,3 +248,30 @@ function setupMailHandler() {
gHandlerSvc.store(mailHandlerInfo); gHandlerSvc.store(mailHandlerInfo);
}); });
} }
let gDownloadDir;
async function setDownloadDir() {
let tmpDir = await PathUtils.getTempDir();
tmpDir = PathUtils.join(
tmpDir,
"testsavedir" + Math.floor(Math.random() * 2 ** 32)
);
// Create this dir if it doesn't exist (ignores existing dirs)
await IOUtils.makeDirectory(tmpDir);
registerCleanupFunction(async function() {
try {
await IOUtils.remove(tmpDir, { recursive: true });
} catch (e) {
Cu.reportError(e);
}
});
Services.prefs.setIntPref("browser.download.folderList", 2);
Services.prefs.setCharPref("browser.download.dir", tmpDir);
return tmpDir;
}
add_task(async function test_common_initialize() {
gDownloadDir = await setDownloadDir();
Services.prefs.setCharPref("browser.download.loglevel", "Debug");
});