From 26a029d407be480d791972afb5975cf62c9360a6 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Fri, 19 Apr 2024 02:47:55 +0200 Subject: Adding upstream version 124.0.1. Signed-off-by: Daniel Baumann --- dom/file/tests/test_createFile.js | 52 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) create mode 100644 dom/file/tests/test_createFile.js (limited to 'dom/file/tests/test_createFile.js') diff --git a/dom/file/tests/test_createFile.js b/dom/file/tests/test_createFile.js new file mode 100644 index 0000000000..af9f684ca8 --- /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 }); + Assert.notEqual(a.size, 0, "The size is correctly set"); + + let b = await File.createFromNsIFile(unknownFile, { existenceCheck: false }); + Assert.equal(b.size, 0, "The size is 0 for unknown file"); + + let c = await File.createFromNsIFile(existingFile, { existenceCheck: true }); + Assert.notEqual(c.size, 0, "The size is correctly set"); + + let d = await File.createFromNsIFile(unknownFile, { + existenceCheck: true, + }).then( + _ => true, + _ => false + ); + Assert.strictEqual(d, false, "Exception thrown"); + + existingFile.remove(true); + ok(!existingFile.exists(), "exists.js doesn't exist anymore"); +}); -- cgit v1.2.3