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

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/modules/libjar/zipwriter/test/unit/test_editexisting.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,62 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/.
     1.7 + */
     1.8 +
     1.9 +// Values taken from using zipinfo to list the test.zip contents
    1.10 +var TESTS = [
    1.11 +  {
    1.12 +    name: "test.txt",
    1.13 +    size: 232,
    1.14 +    crc: 0x0373ac26,
    1.15 +    time: Date.UTC(2007, 4, 1, 20, 44, 55)
    1.16 +  },
    1.17 +  {
    1.18 +    name: "test.png",
    1.19 +    size: 3402,
    1.20 +    crc: 0x504a5c30,
    1.21 +    time: Date.UTC(2007, 4, 1, 20, 49, 39)
    1.22 +  }
    1.23 +];
    1.24 +var BADENTRY = "unknown.txt";
    1.25 +
    1.26 +function run_test()
    1.27 +{
    1.28 +  // Copy our test zip to the tmp dir so we can modify it
    1.29 +  var testzip = do_get_file(DATA_DIR + "test.zip");
    1.30 +  testzip.copyTo(tmpDir, tmpFile.leafName);
    1.31 +
    1.32 +  do_check_true(tmpFile.exists());
    1.33 +
    1.34 +  zipW.open(tmpFile, PR_RDWR);
    1.35 +
    1.36 +  for (var i = 0; i < TESTS.length; i++) {
    1.37 +    do_check_true(zipW.hasEntry(TESTS[i].name));
    1.38 +    var entry = zipW.getEntry(TESTS[i].name);
    1.39 +    do_check_true(entry != null);
    1.40 +
    1.41 +    do_check_eq(entry.realSize, TESTS[i].size);
    1.42 +    do_check_eq(entry.CRC32, TESTS[i].crc);
    1.43 +    do_check_eq(entry.lastModifiedTime / PR_USEC_PER_MSEC, TESTS[i].time);
    1.44 +  }
    1.45 +
    1.46 +  try {
    1.47 +    zipW.removeEntry(BADENTRY, false);
    1.48 +    do_throw("shouldn't be able to remove an entry that doesn't exist");
    1.49 +  }
    1.50 +  catch (e) {
    1.51 +    do_check_eq(e.result, Components.results.NS_ERROR_FILE_NOT_FOUND);
    1.52 +  }
    1.53 +
    1.54 +  for (var i = 0; i < TESTS.length; i++) {
    1.55 +    zipW.removeEntry(TESTS[i].name, false);
    1.56 +  }
    1.57 +
    1.58 +  zipW.close();
    1.59 +
    1.60 +  // Certain platforms cache the file size so get a fresh file to check.
    1.61 +  tmpFile = tmpFile.clone();
    1.62 +
    1.63 +  // Empty zip file should just be the end of central directory marker
    1.64 +  do_check_eq(tmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE);
    1.65 +}

mercurial