Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_safeoutputstream_append.js
blob9716001bd2543227c246e0b96d21f39b1c2c76b5
1 /* atomic-file-output-stream and safe-file-output-stream should throw and
2 * exception if PR_APPEND is explicity specified without PR_TRUNCATE. */
3 "use strict";
5 const PR_WRONLY = 0x02;
6 const PR_CREATE_FILE = 0x08;
7 const PR_APPEND = 0x10;
8 const PR_TRUNCATE = 0x20;
10 function check_flag(file, contractID, flags, throws) {
11 let stream = Cc[contractID].createInstance(Ci.nsIFileOutputStream);
13 if (throws) {
14 /* NS_ERROR_INVALID_ARG is reported as NS_ERROR_ILLEGAL_VALUE, since they
15 * are same value. */
16 Assert.throws(
17 () => stream.init(file, flags, 0o644, 0),
18 /NS_ERROR_ILLEGAL_VALUE/
20 } else {
21 stream.init(file, flags, 0o644, 0);
22 stream.close();
26 function run_test() {
27 let filename = "test.txt";
28 let file = Services.dirsvc.get("TmpD", Ci.nsIFile);
29 file.append(filename);
31 let tests = [
32 [PR_WRONLY | PR_CREATE_FILE | PR_APPEND | PR_TRUNCATE, false],
33 [PR_WRONLY | PR_CREATE_FILE | PR_TRUNCATE, false],
34 [PR_WRONLY | PR_CREATE_FILE | PR_APPEND, true],
35 [-1, false],
37 for (let contractID of [
38 "@mozilla.org/network/atomic-file-output-stream;1",
39 "@mozilla.org/network/safe-file-output-stream;1",
40 ]) {
41 for (let [flags, throws] of tests) {
42 check_flag(file, contractID, flags, throws);