summaryrefslogtreecommitdiffstats
path: root/toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 09:22:09 +0000
commit43a97878ce14b72f0981164f87f2e35e14151312 (patch)
tree620249daf56c0258faa40cbdcf9cfba06de2a846 /toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js
parentInitial commit. (diff)
downloadfirefox-upstream.tar.xz
firefox-upstream.zip
Adding upstream version 110.0.1.upstream/110.0.1upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js')
-rw-r--r--toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js54
1 files changed, 54 insertions, 0 deletions
diff --git a/toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js b/toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js
new file mode 100644
index 0000000000..a81463bc7f
--- /dev/null
+++ b/toolkit/components/osfile/tests/xpcshell/test_removeEmptyDir.js
@@ -0,0 +1,54 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+"use strict";
+
+const { OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
+
+registerCleanupFunction(function() {
+ Services.prefs.setBoolPref("toolkit.osfile.log", false);
+});
+
+function run_test() {
+ Services.prefs.setBoolPref("toolkit.osfile.log", true);
+
+ run_next_test();
+}
+
+/**
+ * Test OS.File.removeEmptyDir
+ */
+add_task(async function() {
+ // Set up profile. We create the directory in the profile, because the profile
+ // is removed after every test run.
+ do_get_profile();
+
+ let dir = OS.Path.join(OS.Constants.Path.profileDir, "directory");
+
+ // Sanity checking for the test
+ Assert.equal(false, await OS.File.exists(dir));
+
+ // Remove non-existent directory
+ await OS.File.removeEmptyDir(dir);
+
+ // Remove non-existent directory with ignoreAbsent
+ await OS.File.removeEmptyDir(dir, { ignoreAbsent: true });
+
+ // Remove non-existent directory with ignoreAbsent false
+ let exception = null;
+ try {
+ await OS.File.removeEmptyDir(dir, { ignoreAbsent: false });
+ } catch (ex) {
+ exception = ex;
+ }
+
+ Assert.ok(!!exception);
+ Assert.ok(exception instanceof OS.File.Error);
+ Assert.ok(exception.becauseNoSuchFile);
+
+ // Remove empty directory
+ await OS.File.makeDir(dir);
+ await OS.File.removeEmptyDir(dir);
+ Assert.equal(false, await OS.File.exists(dir));
+});