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 const time = Date.now();
11 function testpass(source)
12 {
13 // Should exist.
14 do_check_true(source.hasEntry(FILENAME));
16 var entry = source.getEntry(FILENAME);
17 do_check_neq(entry, null);
19 do_check_false(entry.isDirectory);
21 // Should be stored
22 do_check_eq(entry.compression, ZIP_METHOD_DEFLATE);
24 // File size should match our data size.
25 do_check_eq(entry.realSize, DATA.length);
27 // Check that the CRC is accurate
28 do_check_eq(entry.CRC32, CRC);
29 }
31 function run_test()
32 {
33 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
35 // Shouldn't be there to start with.
36 do_check_false(zipW.hasEntry(FILENAME));
38 do_check_false(zipW.inQueue);
40 var file = do_get_file(DATA_DIR + "emptyfile.txt");
41 zipW.addEntryFile(FILENAME, Ci.nsIZipWriter.COMPRESSION_BEST, file, false);
43 // Check that zip state is right at this stage.
44 testpass(zipW);
45 zipW.close();
47 // Check to see if we get the same results loading afresh.
48 zipW.open(tmpFile, PR_RDWR);
49 testpass(zipW);
50 zipW.close();
52 // Test the stored data with the zipreader
53 var zipR = new ZipReader(tmpFile);
54 testpass(zipR);
55 zipR.test(FILENAME);
56 var stream = Cc["@mozilla.org/scriptableinputstream;1"]
57 .createInstance(Ci.nsIScriptableInputStream);
58 stream.init(zipR.getInputStream(FILENAME));
59 var result = stream.read(DATA.length);
60 stream.close();
61 zipR.close();
63 do_check_eq(result, DATA);
64 }