tor-browser

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

test_jarinput_stream_zipreader_reference.js (1399B)


      1 /* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
      2 /* vim:set ts=2 sw=2 sts=2 et: */
      3 /* This Source Code Form is subject to the terms of the Mozilla Public
      4 * License, v. 2.0. If a copy of the MPL was not distributed with this
      5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
      6 
      7 function wrapInputStream(input) {
      8  var nsIScriptableInputStream = Ci.nsIScriptableInputStream;
      9  var factory = Cc["@mozilla.org/scriptableinputstream;1"];
     10  var wrapper = factory.createInstance(nsIScriptableInputStream);
     11  wrapper.init(input);
     12  return wrapper;
     13 }
     14 
     15 // Check that files can be read from after closing zipreader
     16 function run_test() {
     17  // the build script have created the zip we can test on in the current dir.
     18  var file = do_get_file("data/test_bug333423.zip");
     19 
     20  var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
     21    Ci.nsIZipReader
     22  );
     23  zipreader.open(file);
     24  // do crc stuff
     25  function check_archive_crc() {
     26    zipreader.test(null);
     27    return true;
     28  }
     29  Assert.ok(check_archive_crc());
     30  zipreader.findEntries(null);
     31  var stream = wrapInputStream(
     32    zipreader.getInputStream("modules/libjar/test/Makefile.in")
     33  );
     34  var dirstream = wrapInputStream(
     35    zipreader.getInputStream("modules/libjar/test/")
     36  );
     37  zipreader.close();
     38  zipreader = null;
     39  Cu.forceGC();
     40  Assert.ok(!!stream.read(1024).length);
     41  Assert.ok(!!dirstream.read(100).length);
     42 }