1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/modules/libjar/zipwriter/test/unit/test_undochange.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,42 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. 1.7 + */ 1.8 + 1.9 +// Values taken from using zipinfo to list the test.zip contents 1.10 +var TESTS = [ 1.11 + "test.txt", 1.12 + "test.png" 1.13 +]; 1.14 + 1.15 +function run_test() 1.16 +{ 1.17 + zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); 1.18 + 1.19 + for (var i = 0; i < TESTS.length; i++) { 1.20 + var source = do_get_file(DATA_DIR + TESTS[i]); 1.21 + zipW.addEntryFile(TESTS[i], Ci.nsIZipWriter.COMPRESSION_NONE, source, 1.22 + false); 1.23 + } 1.24 + 1.25 + try { 1.26 + var source = do_get_file(DATA_DIR + TESTS[0]); 1.27 + zipW.addEntryFile(TESTS[0], Ci.nsIZipWriter.COMPRESSION_NONE, source, 1.28 + false); 1.29 + do_throw("Should not be able to add the same file twice"); 1.30 + } 1.31 + catch (e) { 1.32 + do_check_eq(e.result, Components.results.NS_ERROR_FILE_ALREADY_EXISTS); 1.33 + } 1.34 + 1.35 + // Remove all the tests and see if we are left with an empty zip 1.36 + for (var i = 0; i < TESTS.length; i++) { 1.37 + zipW.removeEntry(TESTS[i], false); 1.38 + } 1.39 + 1.40 + zipW.close(); 1.41 + 1.42 + // Empty zip file should just be the end of central directory marker 1.43 + var newTmpFile = tmpFile.clone(); 1.44 + do_check_eq(newTmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE); 1.45 +}