modules/libjar/zipwriter/test/unit/test_undochange.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

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

mercurial