diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/unit/test_safeoutputstream_append.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_safeoutputstream_append.js')
-rw-r--r-- | netwerk/test/unit/test_safeoutputstream_append.js | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_safeoutputstream_append.js b/netwerk/test/unit/test_safeoutputstream_append.js new file mode 100644 index 0000000000..9716001bd2 --- /dev/null +++ b/netwerk/test/unit/test_safeoutputstream_append.js @@ -0,0 +1,45 @@ +/* atomic-file-output-stream and safe-file-output-stream should throw and + * exception if PR_APPEND is explicity specified without PR_TRUNCATE. */ +"use strict"; + +const PR_WRONLY = 0x02; +const PR_CREATE_FILE = 0x08; +const PR_APPEND = 0x10; +const PR_TRUNCATE = 0x20; + +function check_flag(file, contractID, flags, throws) { + let stream = Cc[contractID].createInstance(Ci.nsIFileOutputStream); + + if (throws) { + /* NS_ERROR_INVALID_ARG is reported as NS_ERROR_ILLEGAL_VALUE, since they + * are same value. */ + Assert.throws( + () => stream.init(file, flags, 0o644, 0), + /NS_ERROR_ILLEGAL_VALUE/ + ); + } else { + stream.init(file, flags, 0o644, 0); + stream.close(); + } +} + +function run_test() { + let filename = "test.txt"; + let file = Services.dirsvc.get("TmpD", Ci.nsIFile); + file.append(filename); + + let tests = [ + [PR_WRONLY | PR_CREATE_FILE | PR_APPEND | PR_TRUNCATE, false], + [PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, false], + [PR_WRONLY | PR_CREATE_FILE | PR_APPEND, true], + [-1, false], + ]; + for (let contractID of [ + "@mozilla.org/network/atomic-file-output-stream;1", + "@mozilla.org/network/safe-file-output-stream;1", + ]) { + for (let [flags, throws] of tests) { + check_flag(file, contractID, flags, throws); + } + } +} |