summaryrefslogtreecommitdiffstats
path: root/dom/file/tests/test_createFile.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/file/tests/test_createFile.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/file/tests/test_createFile.js')
-rw-r--r--dom/file/tests/test_createFile.js52
1 files changed, 52 insertions, 0 deletions
diff --git a/dom/file/tests/test_createFile.js b/dom/file/tests/test_createFile.js
new file mode 100644
index 0000000000..ebda3d4dae
--- /dev/null
+++ b/dom/file/tests/test_createFile.js
@@ -0,0 +1,52 @@
+add_task(async function () {
+ do_get_profile();
+
+ let existingFile = Services.dirsvc
+ .QueryInterface(Ci.nsIProperties)
+ .get("ProfD", Ci.nsIFile);
+ existingFile.append("exists.js");
+ existingFile.createUnique(Ci.nsIFile.NORMAL_FILE_TYPE, 0o600);
+
+ var outStream = Cc[
+ "@mozilla.org/network/file-output-stream;1"
+ ].createInstance(Ci.nsIFileOutputStream);
+ outStream.init(
+ existingFile,
+ 0x02 | 0x08 | 0x20, // write, create, truncate
+ 0o666,
+ 0
+ );
+
+ var fileData = "Hello World!";
+ outStream.write(fileData, fileData.length);
+ outStream.close();
+
+ ok(existingFile.exists(), "exists.js exists");
+
+ let unknownFile = Services.dirsvc
+ .QueryInterface(Ci.nsIProperties)
+ .get("TmpD", Ci.nsIFile);
+ unknownFile.append("wow.txt");
+
+ ok(!unknownFile.exists(), unknownFile.path + " doesn't exist");
+
+ let a = await File.createFromNsIFile(existingFile, { existenceCheck: false });
+ ok(a.size != 0, "The size is correctly set");
+
+ let b = await File.createFromNsIFile(unknownFile, { existenceCheck: false });
+ ok(b.size == 0, "The size is 0 for unknown file");
+
+ let c = await File.createFromNsIFile(existingFile, { existenceCheck: true });
+ ok(c.size != 0, "The size is correctly set");
+
+ let d = await File.createFromNsIFile(unknownFile, {
+ existenceCheck: true,
+ }).then(
+ _ => true,
+ _ => false
+ );
+ ok(d === false, "Exception thrown");
+
+ existingFile.remove(true);
+ ok(!existingFile.exists(), "exists.js doesn't exist anymore");
+});