test_crx.js (1707B)
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 let nsIScriptableInputStream = Ci.nsIScriptableInputStream; 9 let factory = Cc["@mozilla.org/scriptableinputstream;1"]; 10 let wrapper = factory.createInstance(nsIScriptableInputStream); 11 wrapper.init(input); 12 return wrapper; 13 } 14 15 function extract_crx(filepath) { 16 let file = do_get_file(filepath); 17 18 let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance( 19 Ci.nsIZipReader 20 ); 21 zipreader.open(file); 22 // do crc stuff 23 function check_archive_crc() { 24 zipreader.test(null); 25 return true; 26 } 27 Assert.ok(check_archive_crc()); 28 zipreader.findEntries(null); 29 let stream = wrapInputStream( 30 zipreader.getInputStream("modules/libjar/test/Makefile.in") 31 ); 32 let dirstream = wrapInputStream( 33 zipreader.getInputStream("modules/libjar/test/") 34 ); 35 zipreader.close(); 36 zipreader = null; 37 Cu.forceGC(); 38 Assert.ok(!!stream.read(1024).length); 39 Assert.ok(!!dirstream.read(100).length); 40 } 41 42 // Make sure that we can read from CRX files as if they were ZIP files. 43 function run_test() { 44 // Note: test_crx_dummy.crx is a dummy crx file created for this test. The 45 // public key and signature fields in the header are both empty. 46 extract_crx("data/test_crx_dummy.crx"); 47 48 // Note: test_crx_v3_dummy.crx is a dummy crx file created for this test. The 49 // header length field is set to 4 bytes. 50 extract_crx("data/test_crx_v3_dummy.crx"); 51 }