diff --git a/browser/components/downloads/test/browser/head.js b/browser/components/downloads/test/browser/head.js index 727fcb39092e..a184bd1582d7 100644 --- a/browser/components/downloads/test/browser/head.js +++ b/browser/components/downloads/test/browser/head.js @@ -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; diff --git a/browser/components/downloads/test/unit/head.js b/browser/components/downloads/test/unit/head.js index 6e26b8194526..6769bfe79ab5 100644 --- a/browser/components/downloads/test/unit/head.js +++ b/browser/components/downloads/test/unit/head.js @@ -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; } /** diff --git a/uriloader/exthandler/tests/mochitest/head.js b/uriloader/exthandler/tests/mochitest/head.js index bffd0dc20aae..066dd7beb26b 100644 --- a/uriloader/exthandler/tests/mochitest/head.js +++ b/uriloader/exthandler/tests/mochitest/head.js @@ -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"); +});