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: { michael@0: name: "test.txt", michael@0: size: 232, michael@0: crc: 0x0373ac26, michael@0: time: Date.UTC(2007, 4, 1, 20, 44, 55) michael@0: }, michael@0: { michael@0: name: "test.png", michael@0: size: 3402, michael@0: crc: 0x504a5c30, michael@0: time: Date.UTC(2007, 4, 1, 20, 49, 39) michael@0: } michael@0: ]; michael@0: var BADENTRY = "unknown.txt"; michael@0: michael@0: function run_test() michael@0: { michael@0: // Copy our test zip to the tmp dir so we can modify it michael@0: var testzip = do_get_file(DATA_DIR + "test.zip"); michael@0: testzip.copyTo(tmpDir, tmpFile.leafName); michael@0: michael@0: do_check_true(tmpFile.exists()); michael@0: michael@0: zipW.open(tmpFile, PR_RDWR); michael@0: michael@0: for (var i = 0; i < TESTS.length; i++) { michael@0: do_check_true(zipW.hasEntry(TESTS[i].name)); michael@0: var entry = zipW.getEntry(TESTS[i].name); michael@0: do_check_true(entry != null); michael@0: michael@0: do_check_eq(entry.realSize, TESTS[i].size); michael@0: do_check_eq(entry.CRC32, TESTS[i].crc); michael@0: do_check_eq(entry.lastModifiedTime / PR_USEC_PER_MSEC, TESTS[i].time); michael@0: } michael@0: michael@0: try { michael@0: zipW.removeEntry(BADENTRY, false); michael@0: do_throw("shouldn't be able to remove an entry that doesn't exist"); michael@0: } michael@0: catch (e) { michael@0: do_check_eq(e.result, Components.results.NS_ERROR_FILE_NOT_FOUND); michael@0: } michael@0: michael@0: for (var i = 0; i < TESTS.length; i++) { michael@0: zipW.removeEntry(TESTS[i].name, false); michael@0: } michael@0: michael@0: zipW.close(); michael@0: michael@0: // Certain platforms cache the file size so get a fresh file to check. michael@0: tmpFile = tmpFile.clone(); michael@0: michael@0: // Empty zip file should just be the end of central directory marker michael@0: do_check_eq(tmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE); michael@0: }