зеркало из 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() {
|
||||
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
|
||||
tmpDir.append("testsavedir");
|
||||
if (!tmpDir.exists()) {
|
||||
tmpDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
|
||||
registerCleanupFunction(function() {
|
||||
try {
|
||||
tmpDir.remove(true);
|
||||
} catch (e) {
|
||||
// On Windows debug build this may fail.
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
await SpecialPowers.pushPrefEnv({
|
||||
set: [
|
||||
["browser.download.folderList", 2],
|
||||
["browser.download.dir", tmpDir.path],
|
||||
],
|
||||
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);
|
||||
}
|
||||
});
|
||||
return tmpDir.path;
|
||||
Services.prefs.setIntPref("browser.download.folderList", 2);
|
||||
Services.prefs.setCharPref("browser.download.dir", tmpDir);
|
||||
return tmpDir;
|
||||
}
|
||||
|
||||
let gHttpServer = null;
|
||||
|
|
|
@ -56,21 +56,23 @@ async function createDownloadedFile(pathname, contents) {
|
|||
let gDownloadDir;
|
||||
|
||||
async function setDownloadDir() {
|
||||
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
|
||||
tmpDir.append("testsavedir");
|
||||
if (!tmpDir.exists()) {
|
||||
tmpDir.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
|
||||
registerCleanupFunction(function() {
|
||||
try {
|
||||
tmpDir.remove(true);
|
||||
} catch (e) {
|
||||
// On Windows debug build this may fail.
|
||||
}
|
||||
});
|
||||
}
|
||||
let tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile).path;
|
||||
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.path);
|
||||
return tmpDir.path;
|
||||
Services.prefs.setCharPref("browser.download.dir", tmpDir);
|
||||
return tmpDir;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -248,3 +248,30 @@ function setupMailHandler() {
|
|||
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");
|
||||
});
|
||||
|
|
Загрузка…
Ссылка в новой задаче