michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. michael@0: */ michael@0: michael@0: // Values taken from using zipinfo to list the test.zip contents michael@0: var TESTS = [ michael@0: "test.txt", michael@0: "test.png" michael@0: ]; michael@0: michael@0: function run_test() michael@0: { michael@0: zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); michael@0: michael@0: for (var i = 0; i < TESTS.length; i++) { michael@0: var source = do_get_file(DATA_DIR + TESTS[i]); michael@0: zipW.addEntryFile(TESTS[i], Ci.nsIZipWriter.COMPRESSION_NONE, source, michael@0: false); michael@0: } michael@0: michael@0: try { michael@0: var source = do_get_file(DATA_DIR + TESTS[0]); michael@0: zipW.addEntryFile(TESTS[0], Ci.nsIZipWriter.COMPRESSION_NONE, source, michael@0: false); michael@0: do_throw("Should not be able to add the same file twice"); michael@0: } michael@0: catch (e) { michael@0: do_check_eq(e.result, Components.results.NS_ERROR_FILE_ALREADY_EXISTS); michael@0: } michael@0: michael@0: // Remove all the tests and see if we are left with an empty zip michael@0: for (var i = 0; i < TESTS.length; i++) { michael@0: zipW.removeEntry(TESTS[i], false); michael@0: } michael@0: michael@0: zipW.close(); michael@0: michael@0: // Empty zip file should just be the end of central directory marker michael@0: var newTmpFile = tmpFile.clone(); michael@0: do_check_eq(newTmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE); michael@0: }