forked from mirrors/gecko-dev
		
	 918ed6c474
			
		
	
	
		918ed6c474
		
	
	
	
	
		
			
			This was done using the following script:
37e3803c7a/processors/chromeutils-import.jsm
MozReview-Commit-ID: 1Nc3XDu0wGl
--HG--
extra : source : 12fc4dee861c812fd2bd032c63ef17af61800c70
extra : intermediate-source : 34c999fa006bffe8705cf50c54708aa21a962e62
extra : histedit_source : b2be2c5e5d226e6c347312456a6ae339c1e634b0
		
	
			
		
			
				
	
	
		
			42 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
			
		
		
	
	
			42 lines
		
	
	
	
		
			1.4 KiB
		
	
	
	
		
			JavaScript
		
	
	
	
	
	
| /* atomic-file-output-stream and safe-file-output-stream should throw and
 | |
|  * exception if PR_APPEND is explicity specified without PR_TRUNCATE. */
 | |
| 
 | |
| const PR_WRONLY      = 0x02;
 | |
| const PR_CREATE_FILE = 0x08;
 | |
| const PR_APPEND      = 0x10;
 | |
| const PR_TRUNCATE    = 0x20;
 | |
| 
 | |
| const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm", {});
 | |
| 
 | |
| 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);
 | |
|     }
 | |
|   }
 | |
| }
 |