tor-browser

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

test_bug419769_2.js (1640B)


      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 
     10 function testpass(source) {
     11  // Should exist.
     12  Assert.ok(source.hasEntry(FILENAME));
     13 
     14  var entry = source.getEntry(FILENAME);
     15  Assert.notEqual(entry, null);
     16 
     17  Assert.ok(!entry.isDirectory);
     18 
     19  // Should be stored
     20  Assert.equal(entry.compression, ZIP_METHOD_DEFLATE);
     21 
     22  // File size should match our data size.
     23  Assert.equal(entry.realSize, DATA.length);
     24 
     25  // Check that the CRC is accurate
     26  Assert.equal(entry.CRC32, CRC);
     27 }
     28 
     29 function run_test() {
     30  zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
     31 
     32  // Shouldn't be there to start with.
     33  Assert.ok(!zipW.hasEntry(FILENAME));
     34 
     35  Assert.ok(!zipW.inQueue);
     36 
     37  var file = do_get_file(DATA_DIR + "emptyfile.txt");
     38  zipW.addEntryFile(FILENAME, Ci.nsIZipWriter.COMPRESSION_BEST, file, false);
     39 
     40  // Check that zip state is right at this stage.
     41  testpass(zipW);
     42  zipW.close();
     43 
     44  // Check to see if we get the same results loading afresh.
     45  zipW.open(tmpFile, PR_RDWR);
     46  testpass(zipW);
     47  zipW.close();
     48 
     49  // Test the stored data with the zipreader
     50  var zipR = new ZipReader(tmpFile);
     51  testpass(zipR);
     52  zipR.test(FILENAME);
     53  var stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
     54    Ci.nsIScriptableInputStream
     55  );
     56  stream.init(zipR.getInputStream(FILENAME));
     57  var result = stream.read(DATA.length);
     58  stream.close();
     59  zipR.close();
     60 
     61  Assert.equal(result, DATA);
     62 }