summaryrefslogtreecommitdiff
path: root/modules/libjar/test/unit
diff options
context:
space:
mode:
Diffstat (limited to 'modules/libjar/test/unit')
-rw-r--r--modules/libjar/test/unit/data/empty0
-rw-r--r--modules/libjar/test/unit/data/test_bug333423.zipbin0 -> 1086 bytes
-rw-r--r--modules/libjar/test/unit/data/test_bug336691.zipbin0 -> 789 bytes
-rw-r--r--modules/libjar/test/unit/data/test_bug370103.jarbin0 -> 128 bytes
-rw-r--r--modules/libjar/test/unit/data/test_bug379841.zipbin0 -> 140 bytes
-rw-r--r--modules/libjar/test/unit/data/test_bug589292.zipbin0 -> 168 bytes
-rw-r--r--modules/libjar/test/unit/data/test_bug597702.zipbin0 -> 253 bytes
-rw-r--r--modules/libjar/test/unit/data/test_bug637286.zipbin0 -> 12958 bytes
-rw-r--r--modules/libjar/test/unit/data/test_bug658093.zipbin0 -> 4096 bytes
-rw-r--r--modules/libjar/test/unit/data/test_corrupt.zipbin0 -> 142 bytes
-rw-r--r--modules/libjar/test/unit/data/test_corrupt2.zip1
-rw-r--r--modules/libjar/test/unit/data/test_corrupt3.zipbin0 -> 121 bytes
-rw-r--r--modules/libjar/test/unit/data/test_crx_dummy.crxbin0 -> 1102 bytes
-rw-r--r--modules/libjar/test/unit/data/test_umlaute.zipbin0 -> 179 bytes
-rw-r--r--modules/libjar/test/unit/data/uncompressed.zipbin0 -> 142 bytes
-rw-r--r--modules/libjar/test/unit/test_bug278262.js39
-rw-r--r--modules/libjar/test/unit/test_bug333423.js22
-rw-r--r--modules/libjar/test/unit/test_bug336691.js12
-rw-r--r--modules/libjar/test/unit/test_bug370103.js28
-rw-r--r--modules/libjar/test/unit/test_bug379841.js23
-rw-r--r--modules/libjar/test/unit/test_bug407303.js42
-rw-r--r--modules/libjar/test/unit/test_bug453254.js12
-rw-r--r--modules/libjar/test/unit/test_bug458158.js11
-rw-r--r--modules/libjar/test/unit/test_bug589292.js25
-rw-r--r--modules/libjar/test/unit/test_bug597702.js35
-rw-r--r--modules/libjar/test/unit/test_bug637286.js29
-rw-r--r--modules/libjar/test/unit/test_bug658093.js25
-rw-r--r--modules/libjar/test/unit/test_corrupt_1211262.js34
-rw-r--r--modules/libjar/test/unit/test_corrupt_536911.js36
-rw-r--r--modules/libjar/test/unit/test_corrupt_541828.js24
-rw-r--r--modules/libjar/test/unit/test_crx.js43
-rw-r--r--modules/libjar/test/unit/test_dirjar_bug525755.js25
-rw-r--r--modules/libjar/test/unit/test_jarchannel.js216
-rw-r--r--modules/libjar/test/unit/test_jarinput_stream_zipreader_reference.js42
-rw-r--r--modules/libjar/test/unit/test_not_found.js24
-rw-r--r--modules/libjar/test/unit/test_umlaute.js40
-rw-r--r--modules/libjar/test/unit/test_uncompressed.js12
-rw-r--r--modules/libjar/test/unit/xpcshell.ini44
38 files changed, 844 insertions, 0 deletions
diff --git a/modules/libjar/test/unit/data/empty b/modules/libjar/test/unit/data/empty
new file mode 100644
index 0000000000..e69de29bb2
--- /dev/null
+++ b/modules/libjar/test/unit/data/empty
diff --git a/modules/libjar/test/unit/data/test_bug333423.zip b/modules/libjar/test/unit/data/test_bug333423.zip
new file mode 100644
index 0000000000..42662a4085
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_bug333423.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_bug336691.zip b/modules/libjar/test/unit/data/test_bug336691.zip
new file mode 100644
index 0000000000..16bd2d6f2c
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_bug336691.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_bug370103.jar b/modules/libjar/test/unit/data/test_bug370103.jar
new file mode 100644
index 0000000000..7723568bad
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_bug370103.jar
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_bug379841.zip b/modules/libjar/test/unit/data/test_bug379841.zip
new file mode 100644
index 0000000000..f3c5205197
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_bug379841.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_bug589292.zip b/modules/libjar/test/unit/data/test_bug589292.zip
new file mode 100644
index 0000000000..b7b9e65b47
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_bug589292.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_bug597702.zip b/modules/libjar/test/unit/data/test_bug597702.zip
new file mode 100644
index 0000000000..55ce8fff42
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_bug597702.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_bug637286.zip b/modules/libjar/test/unit/data/test_bug637286.zip
new file mode 100644
index 0000000000..5dc8e747ea
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_bug637286.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_bug658093.zip b/modules/libjar/test/unit/data/test_bug658093.zip
new file mode 100644
index 0000000000..d32180101a
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_bug658093.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_corrupt.zip b/modules/libjar/test/unit/data/test_corrupt.zip
new file mode 100644
index 0000000000..d7f5f42f93
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_corrupt.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_corrupt2.zip b/modules/libjar/test/unit/data/test_corrupt2.zip
new file mode 100644
index 0000000000..0cfbf08886
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_corrupt2.zip
@@ -0,0 +1 @@
+2
diff --git a/modules/libjar/test/unit/data/test_corrupt3.zip b/modules/libjar/test/unit/data/test_corrupt3.zip
new file mode 100644
index 0000000000..86f8d76c9e
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_corrupt3.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_crx_dummy.crx b/modules/libjar/test/unit/data/test_crx_dummy.crx
new file mode 100644
index 0000000000..516e4ff807
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_crx_dummy.crx
Binary files differ
diff --git a/modules/libjar/test/unit/data/test_umlaute.zip b/modules/libjar/test/unit/data/test_umlaute.zip
new file mode 100644
index 0000000000..d147138e18
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_umlaute.zip
Binary files differ
diff --git a/modules/libjar/test/unit/data/uncompressed.zip b/modules/libjar/test/unit/data/uncompressed.zip
new file mode 100644
index 0000000000..192bf15616
--- /dev/null
+++ b/modules/libjar/test/unit/data/uncompressed.zip
Binary files differ
diff --git a/modules/libjar/test/unit/test_bug278262.js b/modules/libjar/test/unit/test_bug278262.js
new file mode 100644
index 0000000000..d63276b896
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug278262.js
@@ -0,0 +1,39 @@
+// Regression test for bug 278262 - JAR URIs should resolve relative URIs in the base section.
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+const path = "data/test_bug333423.zip";
+
+function test_relative_sub() {
+ var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+
+ var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
+ var base = ios.newURI(spec, null, null);
+ var uri = ios.newURI("../modules/libjar", null, base);
+
+ // This is the URI we expect to see.
+ var expected = "jar:" + ios.newFileURI(do_get_file(path)).spec +
+ "!/modules/libjar";
+
+ do_check_eq(uri.spec, expected);
+}
+
+function test_relative_base() {
+ var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+
+ var base = ios.newFileURI(do_get_file("data/empty"));
+ var uri = ios.newURI("jar:../" + path + "!/", null, base);
+
+ // This is the URI we expect to see.
+ var expected = "jar:" + ios.newFileURI(do_get_file(path)).spec +
+ "!/";
+
+ do_check_eq(uri.spec, expected);
+}
+
+function run_test() {
+ test_relative_sub();
+ test_relative_base();
+}
diff --git a/modules/libjar/test/unit/test_bug333423.js b/modules/libjar/test/unit/test_bug333423.js
new file mode 100644
index 0000000000..cd965b93e0
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug333423.js
@@ -0,0 +1,22 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Regression test for bug 333423 - crash enumerating entries of a
+// closed nsIZipReader
+function run_test() {
+ const Cc = Components.classes;
+ const Ci = Components.interfaces;
+
+ // the build script have created the zip we can test on in the current dir.
+ var file = do_get_file("data/test_bug333423.zip");
+
+ var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zipreader.open(file);
+ zipreader.close();
+ var entries = zipreader.findEntries('*.*');
+ do_check_true(!entries.hasMore()); // this shouldn't crash
+}
diff --git a/modules/libjar/test/unit/test_bug336691.js b/modules/libjar/test/unit/test_bug336691.js
new file mode 100644
index 0000000000..e10dd3c9cb
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug336691.js
@@ -0,0 +1,12 @@
+// Regression test for bug 336691 - nsZipArchive::Test shouldn't try to ExtractFile on directories.
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+
+function run_test() {
+ var file = do_get_file("data/test_bug336691.zip");
+ var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zipReader.open(file);
+ zipReader.test(null); // We shouldn't crash here.
+ zipReader.close();
+}
diff --git a/modules/libjar/test/unit/test_bug370103.js b/modules/libjar/test/unit/test_bug370103.js
new file mode 100644
index 0000000000..210cf7a153
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug370103.js
@@ -0,0 +1,28 @@
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+// Regression test for bug 370103 - crash when passing a null listener to
+// nsIChannel.asyncOpen
+function run_test() {
+ // Compose the jar: url
+ var ioService = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+ var file = do_get_file("data/test_bug370103.jar");
+ var url = ioService.newFileURI(file).spec;
+ url = "jar:" + url + "!/test_bug370103";
+
+ // Try opening channel with null listener
+ var channel = NetUtil.newChannel({uri: url, loadUsingSystemPrincipal: true});
+
+ var exception = false;
+ try {
+ channel.asyncOpen2(null);
+ }
+ catch(e) {
+ exception = true;
+ }
+
+ do_check_true(exception); // should throw exception instead of crashing
+}
diff --git a/modules/libjar/test/unit/test_bug379841.js b/modules/libjar/test/unit/test_bug379841.js
new file mode 100644
index 0000000000..a6840a5775
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug379841.js
@@ -0,0 +1,23 @@
+// Regression test for bug 379841 - nsIZipReader's last modified time ignores seconds
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+const path = "data/test_bug379841.zip";
+// Retrieved time should be within 2 seconds of original file's time.
+const MAX_TIME_DIFF = 2000000;
+
+var ENTRY_NAME = "test";
+// Actual time of file was 07 May 2007 13:35:49 UTC
+var ENTRY_TIME = new Date(Date.UTC(2007, 4, 7, 13, 35, 49, 0));
+
+function run_test() {
+ var file = do_get_file(path);
+ var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zipReader.open(file);
+ var entry = zipReader.getEntry(ENTRY_NAME);
+ var diff = Math.abs(entry.lastModifiedTime - ENTRY_TIME.getTime()*1000);
+ zipReader.close();
+ if (diff >= MAX_TIME_DIFF)
+ do_throw(diff);
+}
diff --git a/modules/libjar/test/unit/test_bug407303.js b/modules/libjar/test/unit/test_bug407303.js
new file mode 100644
index 0000000000..313d88c641
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug407303.js
@@ -0,0 +1,42 @@
+// Regression test for bug 407303 - A failed channel should not be checked
+// for an unsafe content type.
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+// XXX: NS_ERROR_UNKNOWN_HOST is not in Components.results
+const NS_ERROR_UNKNOWN_HOST = 0x804B001E;
+
+var listener = {
+ QueryInterface: function(iid) {
+ if (iid.equals(Ci.nsISupports) ||
+ iid.equals(Ci.nsIRequestObserver))
+ return this;
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+
+ onStartRequest: function(request, context) {
+ },
+
+ onDataAvailable: function(request, context, stream, offset, count) {
+ do_throw("shouldn't get data!");
+ },
+
+ onStopRequest: function(request, context, status) {
+ do_check_eq(status, NS_ERROR_UNKNOWN_HOST);
+ do_test_finished();
+ }
+};
+
+function run_test() {
+ Services.prefs.setBoolPref("network.jar.block-remote-files", false);
+ var channel = NetUtil.newChannel({
+ uri: "jar:http://test.invalid/test.jar!/index.html",
+ loadUsingSystemPrincipal: true}
+ );
+ channel.asyncOpen2(listener);
+ do_test_pending();
+}
diff --git a/modules/libjar/test/unit/test_bug453254.js b/modules/libjar/test/unit/test_bug453254.js
new file mode 100644
index 0000000000..bc9d805b43
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug453254.js
@@ -0,0 +1,12 @@
+function run_test() {
+ const zipCache = Components.classes["@mozilla.org/libjar/zip-reader-cache;1"]
+ .createInstance(Components.interfaces.nsIZipReaderCache);
+ zipCache.init(1024);
+ try {
+ zipCache.getZip(null);
+ do_throw("Shouldn't get here!");
+ } catch (e if ((e instanceof Components.interfaces.nsIException) &&
+ (e.result == Components.results.NS_ERROR_INVALID_POINTER))) {
+ // do nothing, this test passes
+ }
+}
diff --git a/modules/libjar/test/unit/test_bug458158.js b/modules/libjar/test/unit/test_bug458158.js
new file mode 100644
index 0000000000..5827123372
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug458158.js
@@ -0,0 +1,11 @@
+function run_test() {
+ var zReader = Components.classes["@mozilla.org/libjar/zip-reader;1"]
+ .createInstance(Components.interfaces.nsIZipReader);
+ try {
+ zReader.open(null);
+ do_throw("Shouldn't get here!");
+ } catch (e if (e instanceof Components.interfaces.nsIException &&
+ e.result == Components.results.NS_ERROR_NULL_POINTER)) {
+ // do nothing, this test passes
+ }
+}
diff --git a/modules/libjar/test/unit/test_bug589292.js b/modules/libjar/test/unit/test_bug589292.js
new file mode 100644
index 0000000000..1fa103e3c8
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug589292.js
@@ -0,0 +1,25 @@
+// Make sure we behave appropriately when asking for content-disposition
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+const path = "data/test_bug589292.zip";
+
+function run_test() {
+ var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+ var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/foo.txt";
+ var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
+ instr = channel.open2();
+ var val;
+ try {
+ val = channel.contentDisposition;
+ do_check_true(false, "The channel has content disposition?!");
+ } catch (e) {
+ // This is what we want to happen - there's no underlying channel, so no
+ // content-disposition header is available
+ do_check_true(true, "How are you reading this?!");
+ }
+}
diff --git a/modules/libjar/test/unit/test_bug597702.js b/modules/libjar/test/unit/test_bug597702.js
new file mode 100644
index 0000000000..3f32a89234
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug597702.js
@@ -0,0 +1,35 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+// Check that reading non existant inner jars results in the right error
+
+function run_test() {
+ var file = do_get_file("data/test_bug597702.zip");
+ var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+ var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
+ var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello";
+ var badSpec = "jar:" + outerJarBase + "jar_that_isnt_in_the.jar!/hello";
+ var goodChannel = NetUtil.newChannel({uri: goodSpec, loadUsingSystemPrincipal: true});
+ var badChannel = NetUtil.newChannel({uri: badSpec, loadUsingSystemPrincipal: true});
+
+ try {
+ instr = goodChannel.open2();
+ } catch (e) {
+ do_throw("Failed to open file in inner jar");
+ }
+
+ try {
+ instr = badChannel.open2();
+ do_throw("Failed to report that file doesn't exist");
+ } catch (e) {
+ do_check_true(e.name == "NS_ERROR_FILE_NOT_FOUND");
+ }
+}
+
diff --git a/modules/libjar/test/unit/test_bug637286.js b/modules/libjar/test/unit/test_bug637286.js
new file mode 100644
index 0000000000..d7609f78f1
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug637286.js
@@ -0,0 +1,29 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+// Check that the zip cache can expire entries from nested jars
+var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+
+function open_inner_zip(base, idx) {
+ var spec = "jar:" + base + "inner" + idx + ".zip!/foo";
+ var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
+ var stream = channel.open2();
+}
+
+function run_test() {
+ var file = do_get_file("data/test_bug637286.zip");
+ var outerJarBase = "jar:" + ios.newFileURI(file).spec + "!/";
+
+ for (var i = 0; i < 40; i++) {
+ open_inner_zip(outerJarBase, i);
+ gc();
+ }
+}
+
diff --git a/modules/libjar/test/unit/test_bug658093.js b/modules/libjar/test/unit/test_bug658093.js
new file mode 100644
index 0000000000..52cf13b1d8
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug658093.js
@@ -0,0 +1,25 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+// Check that we don't crash on reading a directory entry signature
+var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+
+function run_test() {
+ var file = do_get_file("data/test_bug658093.zip");
+ var spec = "jar:" + ios.newFileURI(file).spec + "!/0000";
+ var channel = NetUtil.newChannel({uri: spec, loadUsingSystemPrincipal: true});
+ var failed = false;
+ try {
+ var stream = channel.open2();
+ } catch (e) {
+ failed = true;
+ }
+ do_check_true(failed);
+}
diff --git a/modules/libjar/test/unit/test_corrupt_1211262.js b/modules/libjar/test/unit/test_corrupt_1211262.js
new file mode 100644
index 0000000000..fe289959fc
--- /dev/null
+++ b/modules/libjar/test/unit/test_corrupt_1211262.js
@@ -0,0 +1,34 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+// Regression test ensuring that that a STORED entry with differing compressed
+// and uncompressed sizes is considered to be corrupt.
+function run_test() {
+ const Cc = Components.classes;
+ const Ci = Components.interfaces;
+
+ var file = do_get_file("data/test_corrupt3.zip");
+
+ var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zipreader.open(file);
+
+ var entries = zipreader.findEntries('*');
+ var failed = false;
+
+ while (entries.hasMore()) {
+ let entryPath = entries.getNext();
+ let entry = zipreader.getEntry(entryPath);
+ if (!entry.isDirectory) {
+ try {
+ let inputStream = zipreader.getInputStream(entryPath);
+ } catch (e) {
+ failed = true;
+ }
+ }
+ }
+
+ do_check_true(failed);
+}
+
diff --git a/modules/libjar/test/unit/test_corrupt_536911.js b/modules/libjar/test/unit/test_corrupt_536911.js
new file mode 100644
index 0000000000..f0748dbf27
--- /dev/null
+++ b/modules/libjar/test/unit/test_corrupt_536911.js
@@ -0,0 +1,36 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+function wrapInputStream(input)
+{
+ var nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
+ var factory = Components.classes["@mozilla.org/scriptableinputstream;1"];
+ var wrapper = factory.createInstance(nsIScriptableInputStream);
+ wrapper.init(input);
+ return wrapper;
+}
+
+// Check that files can be read from after closing zipreader
+function run_test() {
+ const Cc = Components.classes;
+ const Ci = Components.interfaces;
+
+ // the build script have created the zip we can test on in the current dir.
+ var file = do_get_file("data/test_corrupt.zip");
+
+ var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zipreader.open(file);
+ // var entries = zipreader.findEntries(null);
+ // the signature for file is corrupt, should not segfault
+ var failed = false;
+ try {
+ var stream = wrapInputStream(zipreader.getInputStream("file"));
+ stream.read(1024);
+ } catch (ex) {
+ failed = true;
+ }
+ do_check_true(failed);
+}
+
diff --git a/modules/libjar/test/unit/test_corrupt_541828.js b/modules/libjar/test/unit/test_corrupt_541828.js
new file mode 100644
index 0000000000..022eb96eb7
--- /dev/null
+++ b/modules/libjar/test/unit/test_corrupt_541828.js
@@ -0,0 +1,24 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Check that files can be read from after closing zipreader
+function run_test() {
+ const Cc = Components.classes;
+ const Ci = Components.interfaces;
+
+ // the build script have created the zip we can test on in the current dir.
+ var file = do_get_file("data/test_corrupt2.zip");
+
+ var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ var failed = false;
+ try {
+ zipreader.open(file);
+ // corrupt files should trigger an exception
+ } catch (ex) {
+ failed = true;
+ }
+ do_check_true(failed);
+}
+
diff --git a/modules/libjar/test/unit/test_crx.js b/modules/libjar/test/unit/test_crx.js
new file mode 100644
index 0000000000..e06f36323a
--- /dev/null
+++ b/modules/libjar/test/unit/test_crx.js
@@ -0,0 +1,43 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+function wrapInputStream(input)
+{
+ let nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
+ let factory = Components.classes["@mozilla.org/scriptableinputstream;1"];
+ let wrapper = factory.createInstance(nsIScriptableInputStream);
+ wrapper.init(input);
+ return wrapper;
+}
+
+// Make sure that we can read from CRX files as if they were ZIP files.
+function run_test() {
+ const Cc = Components.classes;
+ const Ci = Components.interfaces;
+
+ // Note: test_crx_dummy.crx is a dummy crx file created for this test. The
+ // public key and signature fields in the header are both empty.
+ let file = do_get_file("data/test_crx_dummy.crx");
+
+ let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zipreader.open(file);
+ // do crc stuff
+ function check_archive_crc() {
+ zipreader.test(null);
+ return true;
+ }
+ Assert.ok(check_archive_crc())
+ let entries = zipreader.findEntries(null);
+ let stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"))
+ let dirstream= wrapInputStream(zipreader.getInputStream("modules/libjar/test/"))
+ zipreader.close();
+ zipreader = null;
+ Components.utils.forceGC();
+ Assert.ok(stream.read(1024).length > 0);
+ Assert.ok(dirstream.read(100).length > 0);
+}
+
diff --git a/modules/libjar/test/unit/test_dirjar_bug525755.js b/modules/libjar/test/unit/test_dirjar_bug525755.js
new file mode 100644
index 0000000000..00f099a4e1
--- /dev/null
+++ b/modules/libjar/test/unit/test_dirjar_bug525755.js
@@ -0,0 +1,25 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+// Check that we refuse to open weird files
+function run_test() {
+ const Cc = Components.classes;
+ const Ci = Components.interfaces;
+ // open a bogus file
+ var file = do_get_file("/");
+
+ var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ var failed = false;
+ try {
+ zipreader.open(file);
+ } catch (e) {
+ failed = true;
+ }
+ do_check_true(failed);
+ zipreader = null;
+}
+
diff --git a/modules/libjar/test/unit/test_jarchannel.js b/modules/libjar/test/unit/test_jarchannel.js
new file mode 100644
index 0000000000..46eda86914
--- /dev/null
+++ b/modules/libjar/test/unit/test_jarchannel.js
@@ -0,0 +1,216 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * Tests some basic jar channel functionality
+ */
+
+
+const {classes: Cc,
+ interfaces: Ci,
+ results: Cr,
+ utils: Cu,
+ Constructor: ctor
+ } = Components;
+
+Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource://gre/modules/NetUtil.jsm");
+
+const ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+const dirSvc = Cc["@mozilla.org/file/directory_service;1"].
+ getService(Ci.nsIProperties);
+const obs = Cc["@mozilla.org/observer-service;1"].
+ getService(Ci.nsIObserverService);
+
+const nsIBinaryInputStream = ctor("@mozilla.org/binaryinputstream;1",
+ "nsIBinaryInputStream",
+ "setInputStream"
+ );
+
+const fileBase = "test_bug637286.zip";
+const file = do_get_file("data/" + fileBase);
+const jarBase = "jar:" + ios.newFileURI(file).spec + "!";
+const tmpDir = dirSvc.get("TmpD", Ci.nsIFile);
+
+function Listener(callback) {
+ this._callback = callback;
+}
+Listener.prototype = {
+ gotStartRequest: false,
+ available: -1,
+ gotStopRequest: false,
+ QueryInterface: function(iid) {
+ if (iid.equals(Ci.nsISupports) ||
+ iid.equals(Ci.nsIRequestObserver))
+ return this;
+ throw Cr.NS_ERROR_NO_INTERFACE;
+ },
+ onDataAvailable: function(request, ctx, stream, offset, count) {
+ try {
+ this.available = stream.available();
+ do_check_eq(this.available, count);
+ // Need to consume stream to avoid assertion
+ new nsIBinaryInputStream(stream).readBytes(count);
+ }
+ catch (ex) {
+ do_throw(ex);
+ }
+ },
+ onStartRequest: function(request, ctx) {
+ this.gotStartRequest = true;
+ },
+ onStopRequest: function(request, ctx, status) {
+ this.gotStopRequest = true;
+ do_check_eq(status, 0);
+ if (this._callback) {
+ this._callback.call(null, this);
+ }
+ }
+};
+
+/**
+ * Basic reading test for asynchronously opened jar channel
+ */
+function testAsync() {
+ var uri = jarBase + "/inner40.zip";
+ var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
+ do_check_true(chan.contentLength < 0);
+ chan.asyncOpen2(new Listener(function(l) {
+ do_check_true(chan.contentLength > 0);
+ do_check_true(l.gotStartRequest);
+ do_check_true(l.gotStopRequest);
+ do_check_eq(l.available, chan.contentLength);
+
+ run_next_test();
+ }));
+}
+
+add_test(testAsync);
+// Run same test again so we test the codepath for a zipcache hit
+add_test(testAsync);
+
+/**
+ * Basic test for nsIZipReader.
+ */
+function testZipEntry() {
+ var uri = jarBase + "/inner40.zip";
+ var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true})
+ .QueryInterface(Ci.nsIJARChannel);
+ var entry = chan.zipEntry;
+ do_check_true(entry.CRC32 == 0x8b635486);
+ do_check_true(entry.realSize == 184);
+ run_next_test();
+}
+
+add_test(testZipEntry);
+
+
+/**
+ * Basic reading test for synchronously opened jar channels
+ */
+add_test(function testSync() {
+ var uri = jarBase + "/inner40.zip";
+ var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
+ var stream = chan.open2();
+ do_check_true(chan.contentLength > 0);
+ do_check_eq(stream.available(), chan.contentLength);
+ stream.close();
+ stream.close(); // should still not throw
+
+ run_next_test();
+});
+
+
+/**
+ * Basic reading test for synchronously opened, nested jar channels
+ */
+add_test(function testSyncNested() {
+ var uri = "jar:" + jarBase + "/inner40.zip!/foo";
+ var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
+ var stream = chan.open2();
+ do_check_true(chan.contentLength > 0);
+ do_check_eq(stream.available(), chan.contentLength);
+ stream.close();
+ stream.close(); // should still not throw
+
+ run_next_test();
+});
+
+/**
+ * Basic reading test for asynchronously opened, nested jar channels
+ */
+add_test(function testAsyncNested(next) {
+ var uri = "jar:" + jarBase + "/inner40.zip!/foo";
+ var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
+ chan.asyncOpen2(new Listener(function(l) {
+ do_check_true(chan.contentLength > 0);
+ do_check_true(l.gotStartRequest);
+ do_check_true(l.gotStopRequest);
+ do_check_eq(l.available, chan.contentLength);
+
+ run_next_test();
+ }));
+});
+
+/**
+ * Verify that file locks are released when closing a synchronously
+ * opened jar channel stream
+ */
+add_test(function testSyncCloseUnlocks() {
+ var copy = tmpDir.clone();
+ copy.append(fileBase);
+ file.copyTo(copy.parent, copy.leafName);
+ var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
+ var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
+ var stream = chan.open2();
+ do_check_true(chan.contentLength > 0);
+ stream.close();
+
+ // Drop any jar caches
+ obs.notifyObservers(null, "chrome-flush-caches", null);
+
+ try {
+ copy.remove(false);
+ }
+ catch (ex) {
+ do_throw(ex);
+ }
+
+ run_next_test();
+});
+
+/**
+ * Verify that file locks are released when closing an asynchronously
+ * opened jar channel stream
+ */
+add_test(function testAsyncCloseUnlocks() {
+ var copy = tmpDir.clone();
+ copy.append(fileBase);
+ file.copyTo(copy.parent, copy.leafName);
+
+ var uri = "jar:" + ios.newFileURI(copy).spec + "!/inner40.zip";
+ var chan = NetUtil.newChannel({uri: uri, loadUsingSystemPrincipal: true});
+
+ chan.asyncOpen2(new Listener(function (l) {
+ do_check_true(chan.contentLength > 0);
+
+ // Drop any jar caches
+ obs.notifyObservers(null, "chrome-flush-caches", null);
+
+ try {
+ copy.remove(false);
+ }
+ catch (ex) {
+ do_throw(ex);
+ }
+
+ run_next_test();
+ }));
+});
+
+
+function run_test() {
+ return run_next_test();
+}
diff --git a/modules/libjar/test/unit/test_jarinput_stream_zipreader_reference.js b/modules/libjar/test/unit/test_jarinput_stream_zipreader_reference.js
new file mode 100644
index 0000000000..741b84b03f
--- /dev/null
+++ b/modules/libjar/test/unit/test_jarinput_stream_zipreader_reference.js
@@ -0,0 +1,42 @@
+/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
+/* vim:set ts=2 sw=2 sts=2 et: */
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+function wrapInputStream(input)
+{
+ var nsIScriptableInputStream = Components.interfaces.nsIScriptableInputStream;
+ var factory = Components.classes["@mozilla.org/scriptableinputstream;1"];
+ var wrapper = factory.createInstance(nsIScriptableInputStream);
+ wrapper.init(input);
+ return wrapper;
+}
+
+// Check that files can be read from after closing zipreader
+function run_test() {
+ const Cc = Components.classes;
+ const Ci = Components.interfaces;
+
+ // the build script have created the zip we can test on in the current dir.
+ var file = do_get_file("data/test_bug333423.zip");
+
+ var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zipreader.open(file);
+ // do crc stuff
+ function check_archive_crc() {
+ zipreader.test(null);
+ return true;
+ }
+ do_check_true(check_archive_crc())
+ var entries = zipreader.findEntries(null);
+ var stream = wrapInputStream(zipreader.getInputStream("modules/libjar/test/Makefile.in"))
+ var dirstream= wrapInputStream(zipreader.getInputStream("modules/libjar/test/"))
+ zipreader.close();
+ zipreader = null;
+ Components.utils.forceGC();
+ do_check_true(stream.read(1024).length > 0);
+ do_check_true(dirstream.read(100).length > 0);
+}
+
diff --git a/modules/libjar/test/unit/test_not_found.js b/modules/libjar/test/unit/test_not_found.js
new file mode 100644
index 0000000000..f7944cd47f
--- /dev/null
+++ b/modules/libjar/test/unit/test_not_found.js
@@ -0,0 +1,24 @@
+// Should report file not found on non-existent files
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+var Cu = Components.utils;
+
+Cu.import("resource://gre/modules/NetUtil.jsm");
+const path = "data/test_bug333423.zip";
+
+function run_test() {
+ var ios = Cc["@mozilla.org/network/io-service;1"].
+ getService(Ci.nsIIOService);
+ var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
+ var channel = NetUtil.newChannel({
+ uri: spec + "file_that_isnt_in.archive",
+ loadUsingSystemPrincipal: true
+ });
+ try {
+ instr = channel.open2();
+ do_throw("Failed to report that file doesn't exist")
+ } catch (e) {
+ do_check_true(e.name == "NS_ERROR_FILE_NOT_FOUND")
+ }
+}
diff --git a/modules/libjar/test/unit/test_umlaute.js b/modules/libjar/test/unit/test_umlaute.js
new file mode 100644
index 0000000000..bfaa0eabc4
--- /dev/null
+++ b/modules/libjar/test/unit/test_umlaute.js
@@ -0,0 +1,40 @@
+
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+
+function run_test() {
+ var dirService = Cc["@mozilla.org/file/directory_service;1"].getService(Ci.nsIProperties);
+ var tmpDir = dirService.get("TmpD", Ci.nsIFile);
+
+ var zipfile = do_get_file("data/test_umlaute.zip");
+
+ var testFile = tmpDir.clone();
+ testFile.append("test_\u00FC.txt");
+ if (testFile.exists()) {
+ testFile.remove(false);
+ }
+
+ var zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(Ci.nsIZipReader);
+ zipreader.open(zipfile);
+
+ var entries = zipreader.findEntries(null);
+ do_check_true(entries.hasMore());
+
+ var entryName = entries.getNext();
+ do_check_eq(entryName, "test_\u00FC.txt");
+
+ do_check_true(zipreader.hasEntry(entryName));
+
+ var target = tmpDir.clone();
+ target.append(entryName);
+ target.create(Ci.nsILocalFile.NORMAL_FILE_TYPE, 0o640); // 0640
+
+ zipreader.extract(entryName, target);
+
+ var entry = zipreader.getEntry(entryName);
+ do_check_true(entry != null);
+
+ zipreader.test(entryName);
+
+ zipreader.close();
+}
diff --git a/modules/libjar/test/unit/test_uncompressed.js b/modules/libjar/test/unit/test_uncompressed.js
new file mode 100644
index 0000000000..80fbbcee59
--- /dev/null
+++ b/modules/libjar/test/unit/test_uncompressed.js
@@ -0,0 +1,12 @@
+// Make sure uncompressed files pass crc
+var Cc = Components.classes;
+var Ci = Components.interfaces;
+
+function run_test() {
+ var file = do_get_file("data/uncompressed.zip");
+ var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zipReader.open(file);
+ zipReader.test("hello");
+ zipReader.close();
+}
diff --git a/modules/libjar/test/unit/xpcshell.ini b/modules/libjar/test/unit/xpcshell.ini
new file mode 100644
index 0000000000..ee22f4c24a
--- /dev/null
+++ b/modules/libjar/test/unit/xpcshell.ini
@@ -0,0 +1,44 @@
+[DEFAULT]
+head =
+tail =
+skip-if = toolkit == 'android'
+support-files =
+ data/empty
+ data/test_bug333423.zip
+ data/test_bug336691.zip
+ data/test_bug370103.jar
+ data/test_bug379841.zip
+ data/test_bug589292.zip
+ data/test_bug597702.zip
+ data/test_bug637286.zip
+ data/test_bug658093.zip
+ data/test_corrupt.zip
+ data/test_corrupt2.zip
+ data/test_corrupt3.zip
+ data/test_crx_dummy.crx
+ data/test_umlaute.zip
+ data/uncompressed.zip
+
+[test_jarchannel.js]
+skip-if = os == "mac"
+[test_bug278262.js]
+[test_bug333423.js]
+[test_bug336691.js]
+[test_bug370103.js]
+[test_bug379841.js]
+[test_bug407303.js]
+[test_bug453254.js]
+[test_bug458158.js]
+[test_bug589292.js]
+[test_bug597702.js]
+[test_bug637286.js]
+[test_bug658093.js]
+[test_corrupt_536911.js]
+[test_corrupt_541828.js]
+[test_corrupt_1211262.js]
+[test_crx.js]
+[test_dirjar_bug525755.js]
+[test_jarinput_stream_zipreader_reference.js]
+[test_not_found.js]
+[test_uncompressed.js]
+[test_umlaute.js]