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.
michael@0 | 1 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 2 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 3 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. |
michael@0 | 4 | */ |
michael@0 | 5 | |
michael@0 | 6 | // Values taken from using zipinfo to list the test.zip contents |
michael@0 | 7 | var TESTS = [ |
michael@0 | 8 | { |
michael@0 | 9 | name: "test.txt", |
michael@0 | 10 | size: 232, |
michael@0 | 11 | crc: 0x0373ac26 |
michael@0 | 12 | }, |
michael@0 | 13 | { |
michael@0 | 14 | name: "test.png", |
michael@0 | 15 | size: 3402, |
michael@0 | 16 | crc: 0x504a5c30 |
michael@0 | 17 | } |
michael@0 | 18 | ]; |
michael@0 | 19 | |
michael@0 | 20 | var size = 0; |
michael@0 | 21 | |
michael@0 | 22 | var observer = { |
michael@0 | 23 | onStartRequest: function(request, context) |
michael@0 | 24 | { |
michael@0 | 25 | }, |
michael@0 | 26 | |
michael@0 | 27 | onStopRequest: function(request, context, status) |
michael@0 | 28 | { |
michael@0 | 29 | do_check_eq(status, Components.results.NS_OK); |
michael@0 | 30 | |
michael@0 | 31 | zipW.close(); |
michael@0 | 32 | size += ZIP_EOCDR_HEADER_SIZE; |
michael@0 | 33 | |
michael@0 | 34 | do_check_eq(size, tmpFile.fileSize); |
michael@0 | 35 | |
michael@0 | 36 | // Test the stored data with the zipreader |
michael@0 | 37 | var zipR = new ZipReader(tmpFile); |
michael@0 | 38 | |
michael@0 | 39 | for (var i = 0; i < TESTS.length; i++) { |
michael@0 | 40 | var source = do_get_file(DATA_DIR + TESTS[i].name); |
michael@0 | 41 | for (let method in methods) { |
michael@0 | 42 | var entryName = method + "/" + TESTS[i].name; |
michael@0 | 43 | do_check_true(zipR.hasEntry(entryName)); |
michael@0 | 44 | |
michael@0 | 45 | var entry = zipR.getEntry(entryName); |
michael@0 | 46 | do_check_eq(entry.realSize, TESTS[i].size); |
michael@0 | 47 | do_check_eq(entry.size, TESTS[i].size); |
michael@0 | 48 | do_check_eq(entry.CRC32, TESTS[i].crc); |
michael@0 | 49 | do_check_eq(Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC), |
michael@0 | 50 | Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC)); |
michael@0 | 51 | |
michael@0 | 52 | zipR.test(entryName); |
michael@0 | 53 | } |
michael@0 | 54 | } |
michael@0 | 55 | |
michael@0 | 56 | zipR.close(); |
michael@0 | 57 | do_test_finished(); |
michael@0 | 58 | } |
michael@0 | 59 | }; |
michael@0 | 60 | |
michael@0 | 61 | var methods = { |
michael@0 | 62 | file: function method_file(entry, source) |
michael@0 | 63 | { |
michael@0 | 64 | zipW.addEntryFile(entry, Ci.nsIZipWriter.COMPRESSION_NONE, source, |
michael@0 | 65 | true); |
michael@0 | 66 | }, |
michael@0 | 67 | channel: function method_channel(entry, source) |
michael@0 | 68 | { |
michael@0 | 69 | zipW.addEntryChannel(entry, source.lastModifiedTime * PR_MSEC_PER_SEC, |
michael@0 | 70 | Ci.nsIZipWriter.COMPRESSION_NONE, |
michael@0 | 71 | ioSvc.newChannelFromURI(ioSvc.newFileURI(source)), true); |
michael@0 | 72 | }, |
michael@0 | 73 | stream: function method_stream(entry, source) |
michael@0 | 74 | { |
michael@0 | 75 | zipW.addEntryStream(entry, source.lastModifiedTime * PR_MSEC_PER_SEC, |
michael@0 | 76 | Ci.nsIZipWriter.COMPRESSION_NONE, |
michael@0 | 77 | ioSvc.newChannelFromURI(ioSvc.newFileURI(source)).open(), true); |
michael@0 | 78 | } |
michael@0 | 79 | } |
michael@0 | 80 | |
michael@0 | 81 | function run_test() |
michael@0 | 82 | { |
michael@0 | 83 | zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); |
michael@0 | 84 | |
michael@0 | 85 | for (var i = 0; i < TESTS.length; i++) { |
michael@0 | 86 | var source = do_get_file(DATA_DIR+TESTS[i].name); |
michael@0 | 87 | for (let method in methods) { |
michael@0 | 88 | var entry = method + "/" + TESTS[i].name; |
michael@0 | 89 | methods[method](entry, source); |
michael@0 | 90 | size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE + |
michael@0 | 91 | (ZIP_EXTENDED_TIMESTAMP_SIZE * 2) + |
michael@0 | 92 | (entry.length*2) + TESTS[i].size; |
michael@0 | 93 | } |
michael@0 | 94 | } |
michael@0 | 95 | do_test_pending(); |
michael@0 | 96 | zipW.processQueue(observer, null); |
michael@0 | 97 | do_check_true(zipW.inQueue); |
michael@0 | 98 | } |