modules/libjar/zipwriter/test/unit/test_editexisting.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.

     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     time: Date.UTC(2007, 4, 1, 20, 44, 55)
    13   },
    14   {
    15     name: "test.png",
    16     size: 3402,
    17     crc: 0x504a5c30,
    18     time: Date.UTC(2007, 4, 1, 20, 49, 39)
    19   }
    20 ];
    21 var BADENTRY = "unknown.txt";
    23 function run_test()
    24 {
    25   // Copy our test zip to the tmp dir so we can modify it
    26   var testzip = do_get_file(DATA_DIR + "test.zip");
    27   testzip.copyTo(tmpDir, tmpFile.leafName);
    29   do_check_true(tmpFile.exists());
    31   zipW.open(tmpFile, PR_RDWR);
    33   for (var i = 0; i < TESTS.length; i++) {
    34     do_check_true(zipW.hasEntry(TESTS[i].name));
    35     var entry = zipW.getEntry(TESTS[i].name);
    36     do_check_true(entry != null);
    38     do_check_eq(entry.realSize, TESTS[i].size);
    39     do_check_eq(entry.CRC32, TESTS[i].crc);
    40     do_check_eq(entry.lastModifiedTime / PR_USEC_PER_MSEC, TESTS[i].time);
    41   }
    43   try {
    44     zipW.removeEntry(BADENTRY, false);
    45     do_throw("shouldn't be able to remove an entry that doesn't exist");
    46   }
    47   catch (e) {
    48     do_check_eq(e.result, Components.results.NS_ERROR_FILE_NOT_FOUND);
    49   }
    51   for (var i = 0; i < TESTS.length; i++) {
    52     zipW.removeEntry(TESTS[i].name, false);
    53   }
    55   zipW.close();
    57   // Certain platforms cache the file size so get a fresh file to check.
    58   tmpFile = tmpFile.clone();
    60   // Empty zip file should just be the end of central directory marker
    61   do_check_eq(tmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE);
    62 }

mercurial