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 var size = 0;
22 var observer = {
23 onStartRequest: function(request, context)
24 {
25 },
27 onStopRequest: function(request, context, status)
28 {
29 do_check_eq(status, Components.results.NS_OK);
31 zipW.close();
32 size += ZIP_EOCDR_HEADER_SIZE;
34 do_check_eq(size, tmpFile.fileSize);
36 // Test the stored data with the zipreader
37 var zipR = new ZipReader(tmpFile);
39 for (var i = 0; i < TESTS.length; i++) {
40 var source = do_get_file(DATA_DIR + TESTS[i].name);
41 for (let method in methods) {
42 var entryName = method + "/" + TESTS[i].name;
43 do_check_true(zipR.hasEntry(entryName));
45 var entry = zipR.getEntry(entryName);
46 do_check_eq(entry.realSize, TESTS[i].size);
47 do_check_eq(entry.size, TESTS[i].size);
48 do_check_eq(entry.CRC32, TESTS[i].crc);
49 do_check_eq(Math.floor(entry.lastModifiedTime / PR_USEC_PER_SEC),
50 Math.floor(source.lastModifiedTime / PR_MSEC_PER_SEC));
52 zipR.test(entryName);
53 }
54 }
56 zipR.close();
57 do_test_finished();
58 }
59 };
61 var methods = {
62 file: function method_file(entry, source)
63 {
64 zipW.addEntryFile(entry, Ci.nsIZipWriter.COMPRESSION_NONE, source,
65 true);
66 },
67 channel: function method_channel(entry, source)
68 {
69 zipW.addEntryChannel(entry, source.lastModifiedTime * PR_MSEC_PER_SEC,
70 Ci.nsIZipWriter.COMPRESSION_NONE,
71 ioSvc.newChannelFromURI(ioSvc.newFileURI(source)), true);
72 },
73 stream: function method_stream(entry, source)
74 {
75 zipW.addEntryStream(entry, source.lastModifiedTime * PR_MSEC_PER_SEC,
76 Ci.nsIZipWriter.COMPRESSION_NONE,
77 ioSvc.newChannelFromURI(ioSvc.newFileURI(source)).open(), true);
78 }
79 }
81 function run_test()
82 {
83 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
85 for (var i = 0; i < TESTS.length; i++) {
86 var source = do_get_file(DATA_DIR+TESTS[i].name);
87 for (let method in methods) {
88 var entry = method + "/" + TESTS[i].name;
89 methods[method](entry, source);
90 size += ZIP_FILE_HEADER_SIZE + ZIP_CDS_HEADER_SIZE +
91 (ZIP_EXTENDED_TIMESTAMP_SIZE * 2) +
92 (entry.length*2) + TESTS[i].size;
93 }
94 }
95 do_test_pending();
96 zipW.processQueue(observer, null);
97 do_check_true(zipW.inQueue);
98 }