|
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 */ |
|
5 |
|
6 // Values taken from using zipinfo to list the test.zip contents |
|
7 var TESTS = [ |
|
8 "test.txt", |
|
9 "test.png" |
|
10 ]; |
|
11 |
|
12 function run_test() |
|
13 { |
|
14 zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE); |
|
15 |
|
16 for (var i = 0; i < TESTS.length; i++) { |
|
17 var source = do_get_file(DATA_DIR + TESTS[i]); |
|
18 zipW.addEntryFile(TESTS[i], Ci.nsIZipWriter.COMPRESSION_NONE, source, |
|
19 false); |
|
20 } |
|
21 |
|
22 try { |
|
23 var source = do_get_file(DATA_DIR + TESTS[0]); |
|
24 zipW.addEntryFile(TESTS[0], Ci.nsIZipWriter.COMPRESSION_NONE, source, |
|
25 false); |
|
26 do_throw("Should not be able to add the same file twice"); |
|
27 } |
|
28 catch (e) { |
|
29 do_check_eq(e.result, Components.results.NS_ERROR_FILE_ALREADY_EXISTS); |
|
30 } |
|
31 |
|
32 // Remove all the tests and see if we are left with an empty zip |
|
33 for (var i = 0; i < TESTS.length; i++) { |
|
34 zipW.removeEntry(TESTS[i], false); |
|
35 } |
|
36 |
|
37 zipW.close(); |
|
38 |
|
39 // Empty zip file should just be the end of central directory marker |
|
40 var newTmpFile = tmpFile.clone(); |
|
41 do_check_eq(newTmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE); |
|
42 } |