test_undochange.js (1263B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. 4 */ 5 6 // Values taken from using zipinfo to list the test.zip contents 7 var TESTS = ["test.txt", "test.png"]; 8 9 function run_test() { 10 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); 11 12 for (let i = 0; i < TESTS.length; i++) { 13 let source = do_get_file(DATA_DIR + TESTS[i]); 14 zipW.addEntryFile( 15 TESTS[i], 16 Ci.nsIZipWriter.COMPRESSION_NONE, 17 source, 18 false 19 ); 20 } 21 22 try { 23 let source = do_get_file(DATA_DIR + TESTS[0]); 24 zipW.addEntryFile( 25 TESTS[0], 26 Ci.nsIZipWriter.COMPRESSION_NONE, 27 source, 28 false 29 ); 30 do_throw("Should not be able to add the same file twice"); 31 } catch (e) { 32 Assert.equal(e.result, Cr.NS_ERROR_FILE_ALREADY_EXISTS); 33 } 34 35 // Remove all the tests and see if we are left with an empty zip 36 for (let i = 0; i < TESTS.length; i++) { 37 zipW.removeEntry(TESTS[i], false); 38 } 39 40 zipW.close(); 41 42 // Empty zip file should just be the end of central directory marker 43 var newTmpFile = tmpFile.clone(); 44 Assert.equal(newTmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE); 45 }