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 const DATA = "";
7 const FILENAME = "test.txt";
8 const CRC = 0x00000000;
9 // XXX Must use a constant time here away from DST changes. See bug 402434.
10 const time = 1199145600000; // Jan 1st 2008
12 function testpass(source)
13 {
14 // Should exist.
15 do_check_true(source.hasEntry(FILENAME));
17 var entry = source.getEntry(FILENAME);
18 do_check_neq(entry, null);
20 do_check_false(entry.isDirectory);
22 // Should be stored
23 do_check_eq(entry.compression, ZIP_METHOD_DEFLATE);
25 do_check_eq(entry.lastModifiedTime / PR_USEC_PER_MSEC, time);
27 // File size should match our data size.
28 do_check_eq(entry.realSize, DATA.length);
30 // Check that the CRC is accurate
31 do_check_eq(entry.CRC32, CRC);
32 }
34 function run_test()
35 {
36 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
38 // Shouldn't be there to start with.
39 do_check_false(zipW.hasEntry(FILENAME));
41 do_check_false(zipW.inQueue);
43 var stream = Cc["@mozilla.org/io/string-input-stream;1"]
44 .createInstance(Ci.nsIStringInputStream);
45 stream.setData(DATA, DATA.length);
46 zipW.addEntryStream(FILENAME, time * PR_USEC_PER_MSEC,
47 Ci.nsIZipWriter.COMPRESSION_BEST, stream, false);
49 // Check that zip state is right at this stage.
50 testpass(zipW);
51 zipW.close();
53 // Check to see if we get the same results loading afresh.
54 zipW.open(tmpFile, PR_RDWR);
55 testpass(zipW);
56 zipW.close();
58 // Test the stored data with the zipreader
59 var zipR = new ZipReader(tmpFile);
60 testpass(zipR);
61 zipR.test(FILENAME);
62 var stream = Cc["@mozilla.org/scriptableinputstream;1"]
63 .createInstance(Ci.nsIScriptableInputStream);
64 stream.init(zipR.getInputStream(FILENAME));
65 var result = stream.read(DATA.length);
66 stream.close();
67 zipR.close();
69 do_check_eq(result, DATA);
70 }