tor-browser

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

test_bug419769_1.js (1963B)


      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 const DATA = "";
      7 const FILENAME = "test.txt";
      8 const CRC = 0x00000000;
      9 // XXX Must use a constant time here away from DST changes. See bug 402434.
     10 const time = 1199145600000; // Jan 1st 2008
     11 
     12 function testpass(source) {
     13  // Should exist.
     14  Assert.ok(source.hasEntry(FILENAME));
     15 
     16  var entry = source.getEntry(FILENAME);
     17  Assert.notEqual(entry, null);
     18 
     19  Assert.ok(!entry.isDirectory);
     20 
     21  // Should be stored
     22  Assert.equal(entry.compression, ZIP_METHOD_DEFLATE);
     23 
     24  Assert.equal(entry.lastModifiedTime / PR_USEC_PER_MSEC, time);
     25 
     26  // File size should match our data size.
     27  Assert.equal(entry.realSize, DATA.length);
     28 
     29  // Check that the CRC is accurate
     30  Assert.equal(entry.CRC32, CRC);
     31 }
     32 
     33 function run_test() {
     34  zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
     35 
     36  // Shouldn't be there to start with.
     37  Assert.ok(!zipW.hasEntry(FILENAME));
     38 
     39  Assert.ok(!zipW.inQueue);
     40 
     41  var stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
     42    Ci.nsIStringInputStream
     43  );
     44  stream.setByteStringData(DATA);
     45  zipW.addEntryStream(
     46    FILENAME,
     47    time * PR_USEC_PER_MSEC,
     48    Ci.nsIZipWriter.COMPRESSION_BEST,
     49    stream,
     50    false
     51  );
     52 
     53  // Check that zip state is right at this stage.
     54  testpass(zipW);
     55  zipW.close();
     56 
     57  // Check to see if we get the same results loading afresh.
     58  zipW.open(tmpFile, PR_RDWR);
     59  testpass(zipW);
     60  zipW.close();
     61 
     62  // Test the stored data with the zipreader
     63  var zipR = new ZipReader(tmpFile);
     64  testpass(zipR);
     65  zipR.test(FILENAME);
     66  stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
     67    Ci.nsIScriptableInputStream
     68  );
     69  stream.init(zipR.getInputStream(FILENAME));
     70  var result = stream.read(DATA.length);
     71  stream.close();
     72  zipR.close();
     73 
     74  Assert.equal(result, DATA);
     75 }