tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_editexisting.js (1667B)


      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  {
      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";
     22 
     23 function run_test() {
     24  // Copy our test zip to the tmp dir so we can modify it
     25  var testzip = do_get_file(DATA_DIR + "test.zip");
     26  testzip.copyTo(tmpDir, tmpFile.leafName);
     27 
     28  Assert.ok(tmpFile.exists());
     29 
     30  zipW.open(tmpFile, PR_RDWR);
     31 
     32  for (let i = 0; i < TESTS.length; i++) {
     33    Assert.ok(zipW.hasEntry(TESTS[i].name));
     34    var entry = zipW.getEntry(TESTS[i].name);
     35    Assert.notEqual(entry, null);
     36 
     37    Assert.equal(entry.realSize, TESTS[i].size);
     38    Assert.equal(entry.CRC32, TESTS[i].crc);
     39    Assert.equal(entry.lastModifiedTime / PR_USEC_PER_MSEC, TESTS[i].time);
     40  }
     41 
     42  try {
     43    zipW.removeEntry(BADENTRY, false);
     44    do_throw("shouldn't be able to remove an entry that doesn't exist");
     45  } catch (e) {
     46    Assert.equal(e.result, Cr.NS_ERROR_FILE_NOT_FOUND);
     47  }
     48 
     49  for (let i = 0; i < TESTS.length; i++) {
     50    zipW.removeEntry(TESTS[i].name, false);
     51  }
     52 
     53  zipW.close();
     54 
     55  // Certain platforms cache the file size so get a fresh file to check.
     56  tmpFile = tmpFile.clone();
     57 
     58  // Empty zip file should just be the end of central directory marker
     59  Assert.equal(tmpFile.fileSize, ZIP_EOCDR_HEADER_SIZE);
     60 }