зеркало из https://github.com/mozilla/gecko-dev.git
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:
Родитель
ddfec86473
Коммит
e2caf16515
|
@ -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");
|
||||||
|
});
|
||||||
|
|
Загрузка…
Ссылка в новой задаче