Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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 */
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 ];
20 function run_test()
21 {
22 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
24 var size = 0;
25 for (var i = 0; i < TESTS.length; i++) {
26 var source = do_get_file(DATA_DIR + TESTS[i].name);
27 zipW.addEntryFile(TESTS[i].name, Ci.nsIZipWriter.COMPRESSION_NONE, source,
28 false);
29 size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
30 (ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
31 (TESTS[i].name.length*2) + TESTS[i].size;
32 }
34 zipW.close();
35 size += ZIP_EOCDR_HEADER_SIZE;
37 do_check_eq(size, tmpFile.fileSize);
39 // Test the stored data with the zipreader
40 var zipR = new ZipReader(tmpFile);
42 for (var i = 0; i < TESTS.length; i++) {
43 var source = do_get_file(DATA_DIR + TESTS[i].name);
44 do_check_true(zipR.hasEntry(TESTS[i].name));
46 var entry = zipR.getEntry(TESTS[i].name);
47 do_check_eq(entry.realSize, TESTS[i].size);
48 do_check_eq(entry.size, TESTS[i].size);
49 do_check_eq(entry.CRC32, TESTS[i].crc);
50 do_check_eq(Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
51 Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC));
53 zipR.test(TESTS[i].name);
54 }
56 zipR.close();
57 }