test_sync.js (1613B)
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 = [ 8 { 9 name: "test.txt", 10 size: 232, 11 crc: 0x0373ac26, 12 }, 13 { 14 name: "test.png", 15 size: 3402, 16 crc: 0x504a5c30, 17 }, 18 ]; 19 20 function run_test() { 21 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); 22 23 var size = 0; 24 for (let i = 0; i < TESTS.length; i++) { 25 let source = do_get_file(DATA_DIR + TESTS[i].name); 26 zipW.addEntryFile( 27 TESTS[i].name, 28 Ci.nsIZipWriter.COMPRESSION_NONE, 29 source, 30 false 31 ); 32 size += 33 ZIP_FILE_HEADER_SIZE + 34 ZIP_CDS_HEADER_SIZE + 35 ZIP_EXTENDED_TIMESTAMP_SIZE * 2 + 36 TESTS[i].name.length * 2 + 37 TESTS[i].size; 38 } 39 40 zipW.close(); 41 size += ZIP_EOCDR_HEADER_SIZE; 42 43 Assert.equal(size, tmpFile.fileSize); 44 45 // Test the stored data with the zipreader 46 var zipR = new ZipReader(tmpFile); 47 48 for (let i = 0; i < TESTS.length; i++) { 49 let source = do_get_file(DATA_DIR + TESTS[i].name); 50 Assert.ok(zipR.hasEntry(TESTS[i].name)); 51 52 var entry = zipR.getEntry(TESTS[i].name); 53 Assert.equal(entry.realSize, TESTS[i].size); 54 Assert.equal(entry.size, TESTS[i].size); 55 Assert.equal(entry.CRC32, TESTS[i].crc); 56 Assert.equal( 57 Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC), 58 Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC) 59 ); 60 61 zipR.test(TESTS[i].name); 62 } 63 64 zipR.close(); 65 }