summaryrefslogtreecommitdiffstats
path: root/modules/libjar/test/unit
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /modules/libjar/test/unit
parentInitial commit. (diff)
downloadfirefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz
firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
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_1801102.jarbin0 -> 141 bytes
-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_empty_file.zipbin0 -> 166 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_bug1328865.js50
-rw-r--r--modules/libjar/test/unit/test_bug1550815.js32
-rw-r--r--modules/libjar/test/unit/test_bug278262.js32
-rw-r--r--modules/libjar/test/unit/test_bug333423.js24
-rw-r--r--modules/libjar/test/unit/test_bug336691.js10
-rw-r--r--modules/libjar/test/unit/test_bug370103.js25
-rw-r--r--modules/libjar/test/unit/test_bug379841.js23
-rw-r--r--modules/libjar/test/unit/test_bug453254.js17
-rw-r--r--modules/libjar/test/unit/test_bug458158.js16
-rw-r--r--modules/libjar/test/unit/test_bug589292.js23
-rw-r--r--modules/libjar/test/unit/test_bug597702.js35
-rw-r--r--modules/libjar/test/unit/test_bug637286.js26
-rw-r--r--modules/libjar/test/unit/test_bug658093.js23
-rw-r--r--modules/libjar/test/unit/test_corrupt_1211262.js28
-rw-r--r--modules/libjar/test/unit/test_corrupt_1801102.js20
-rw-r--r--modules/libjar/test/unit/test_corrupt_536911.js32
-rw-r--r--modules/libjar/test/unit/test_corrupt_541828.js21
-rw-r--r--modules/libjar/test/unit/test_crx.js43
-rw-r--r--modules/libjar/test/unit/test_dirjar_bug525755.js23
-rw-r--r--modules/libjar/test/unit/test_empty_jar_telemetry.js154
-rw-r--r--modules/libjar/test/unit/test_fault_handler.js138
-rw-r--r--modules/libjar/test/unit/test_jarchannel.js204
-rw-r--r--modules/libjar/test/unit/test_jarinput_stream_zipreader_reference.js42
-rw-r--r--modules/libjar/test/unit/test_not_found.js18
-rw-r--r--modules/libjar/test/unit/test_umlaute.js37
-rw-r--r--modules/libjar/test/unit/test_uncompressed.js10
-rw-r--r--modules/libjar/test/unit/xpcshell.ini55
44 files changed, 1162 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_1801102.jar b/modules/libjar/test/unit/data/test_1801102.jar
new file mode 100644
index 0000000000..c3cd11112d
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_1801102.jar
Binary files differ
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_empty_file.zip b/modules/libjar/test/unit/data/test_empty_file.zip
new file mode 100644
index 0000000000..b613b60c02
--- /dev/null
+++ b/modules/libjar/test/unit/data/test_empty_file.zip
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_bug1328865.js b/modules/libjar/test/unit/test_bug1328865.js
new file mode 100644
index 0000000000..3c973cb77c
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug1328865.js
@@ -0,0 +1,50 @@
+/* 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/. */
+
+"use strict";
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+// Check that reading non existant inner jars results in the right error
+
+add_task(async function () {
+ var file = do_get_file("data/test_bug597702.zip");
+ var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
+ var goodSpec =
+ "jar:" + outerJarBase + "inner.jar!/hello#!/ignore%20this%20part";
+ var goodChannel = NetUtil.newChannel({
+ uri: goodSpec,
+ loadUsingSystemPrincipal: true,
+ });
+ var instr = goodChannel.open();
+
+ ok(!!instr, "Should be able to open channel");
+});
+
+add_task(async function () {
+ var file = do_get_file("data/test_bug597702.zip");
+ var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
+ var goodSpec =
+ "jar:" + outerJarBase + "inner.jar!/hello?ignore%20this%20part!/";
+ var goodChannel = NetUtil.newChannel({
+ uri: goodSpec,
+ loadUsingSystemPrincipal: true,
+ });
+ var instr = goodChannel.open();
+
+ ok(!!instr, "Should be able to open channel");
+});
+
+add_task(async function () {
+ var file = do_get_file("data/test_bug597702.zip");
+ var outerJarBase = "jar:" + Services.io.newFileURI(file).spec + "!/";
+ var goodSpec = "jar:" + outerJarBase + "inner.jar!/hello?ignore#this!/part";
+ var goodChannel = NetUtil.newChannel({
+ uri: goodSpec,
+ loadUsingSystemPrincipal: true,
+ });
+ var instr = goodChannel.open();
+
+ ok(!!instr, "Should be able to open channel");
+});
diff --git a/modules/libjar/test/unit/test_bug1550815.js b/modules/libjar/test/unit/test_bug1550815.js
new file mode 100644
index 0000000000..cb6264de7a
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug1550815.js
@@ -0,0 +1,32 @@
+// Test checks SIGBUS handling on Linux. The test cannot be used to check page
+// error exception on Windows because the file cannot be truncated while it's
+// being used by zipreader.
+function run_test() {
+ var file = do_get_file("data/test_bug333423.zip");
+ var tmpFile = do_get_tempdir();
+
+ file.copyTo(tmpFile, "bug1550815.zip");
+ tmpFile.append("bug1550815.zip");
+
+ var zipReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
+ Ci.nsIZipReader
+ );
+ zipReader.open(tmpFile);
+
+ // Truncate the file
+ var ostream = Cc["@mozilla.org/network/file-output-stream;1"].createInstance(
+ Ci.nsIFileOutputStream
+ );
+ ostream.init(tmpFile, -1, -1, 0);
+ ostream.close();
+
+ try {
+ zipReader.test("modules/libjar/test/Makefile.in");
+ Assert.ok(false, "Should not reach here.");
+ } catch (e) {
+ Assert.equal(e.result, Cr.NS_ERROR_FILE_NOT_FOUND);
+ }
+
+ zipReader.close();
+ tmpFile.remove(false);
+}
diff --git a/modules/libjar/test/unit/test_bug278262.js b/modules/libjar/test/unit/test_bug278262.js
new file mode 100644
index 0000000000..3a5e7e951c
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug278262.js
@@ -0,0 +1,32 @@
+// Regression test for bug 278262 - JAR URIs should resolve relative URIs in the base section.
+
+const path = "data/test_bug333423.zip";
+
+function test_relative_sub() {
+ var ios = Services.io;
+ var spec = "jar:" + ios.newFileURI(do_get_file(path)).spec + "!/";
+ var base = ios.newURI(spec);
+ 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";
+
+ Assert.equal(uri.spec, expected);
+}
+
+function test_relative_base() {
+ var ios = Services.io;
+ 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 + "!/";
+
+ Assert.equal(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..e2fc535020
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug333423.js
@@ -0,0 +1,24 @@
+/* -*- 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() {
+ // 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();
+ // this should error out and not crash
+ Assert.throws(
+ () => zipreader.findEntries("*.*"),
+ /NS_ERROR_FAILURE/,
+ "Should error out on a closed zipreader"
+ );
+}
diff --git a/modules/libjar/test/unit/test_bug336691.js b/modules/libjar/test/unit/test_bug336691.js
new file mode 100644
index 0000000000..3740335acc
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug336691.js
@@ -0,0 +1,10 @@
+// Regression test for bug 336691 - nsZipArchive::Test shouldn't try to ExtractFile on directories.
+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..d9d0e3e6a2
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug370103.js
@@ -0,0 +1,25 @@
+const { NetUtil } = ChromeUtils.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 file = do_get_file("data/test_bug370103.jar");
+ var url = Services.io.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.asyncOpen(null);
+ } catch (e) {
+ exception = true;
+ }
+
+ Assert.ok(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..c8bd026bb3
--- /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
+
+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_bug453254.js b/modules/libjar/test/unit/test_bug453254.js
new file mode 100644
index 0000000000..150a15daa3
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug453254.js
@@ -0,0 +1,17 @@
+function run_test() {
+ const zipCache = Cc["@mozilla.org/libjar/zip-reader-cache;1"].createInstance(
+ Ci.nsIZipReaderCache
+ );
+ zipCache.init(1024);
+ try {
+ zipCache.getZip(null);
+ do_throw("Shouldn't get here!");
+ } catch (e) {
+ if (
+ !(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_INVALID_POINTER)
+ ) {
+ throw e;
+ }
+ // 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..15e327fba5
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug458158.js
@@ -0,0 +1,16 @@
+function run_test() {
+ var zReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
+ Ci.nsIZipReader
+ );
+ try {
+ zReader.open(null);
+ do_throw("Shouldn't get here!");
+ } catch (e) {
+ if (
+ !(e instanceof Ci.nsIException && e.result == Cr.NS_ERROR_NULL_POINTER)
+ ) {
+ throw e;
+ }
+ // 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..07b43d2973
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug589292.js
@@ -0,0 +1,23 @@
+// Make sure we behave appropriately when asking for content-disposition
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+const path = "data/test_bug589292.zip";
+
+function run_test() {
+ var spec =
+ "jar:" + Services.io.newFileURI(do_get_file(path)).spec + "!/foo.txt";
+ var channel = NetUtil.newChannel({
+ uri: spec,
+ loadUsingSystemPrincipal: true,
+ });
+ channel.open();
+ try {
+ channel.contentDisposition;
+ Assert.ok(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
+ Assert.ok(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..8514c593f1
--- /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/. */
+
+const { NetUtil } = ChromeUtils.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 outerJarBase = "jar:" + Services.io.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 {
+ goodChannel.open();
+ } catch (e) {
+ do_throw("Failed to open file in inner jar");
+ }
+
+ try {
+ badChannel.open();
+ do_throw("Failed to report that file doesn't exist");
+ } catch (e) {
+ Assert.ok(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..114e6b19f2
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug637286.js
@@ -0,0 +1,26 @@
+/* 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/. */
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+// Check that the zip cache can expire entries from nested jars
+
+function open_inner_zip(base, idx) {
+ var spec = "jar:" + base + "inner" + idx + ".zip!/foo";
+ var channel = NetUtil.newChannel({
+ uri: spec,
+ loadUsingSystemPrincipal: true,
+ });
+ channel.open();
+}
+
+function run_test() {
+ var file = do_get_file("data/test_bug637286.zip");
+ var outerJarBase = "jar:" + Services.io.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..92b7654775
--- /dev/null
+++ b/modules/libjar/test/unit/test_bug658093.js
@@ -0,0 +1,23 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+// Check that we don't crash on reading a directory entry signature
+
+function run_test() {
+ var file = do_get_file("data/test_bug658093.zip");
+ var spec = "jar:" + Services.io.newFileURI(file).spec + "!/0000";
+ var channel = NetUtil.newChannel({
+ uri: spec,
+ loadUsingSystemPrincipal: true,
+ });
+ var failed = false;
+ try {
+ channel.open();
+ } catch (e) {
+ failed = true;
+ }
+ Assert.ok(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..c6fc6b2761
--- /dev/null
+++ b/modules/libjar/test/unit/test_corrupt_1211262.js
@@ -0,0 +1,28 @@
+/* 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() {
+ 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 failed = false;
+ for (let entryPath of zipreader.findEntries("*")) {
+ let entry = zipreader.getEntry(entryPath);
+ if (!entry.isDirectory) {
+ try {
+ zipreader.getInputStream(entryPath);
+ } catch (e) {
+ failed = true;
+ }
+ }
+ }
+
+ Assert.ok(failed);
+}
diff --git a/modules/libjar/test/unit/test_corrupt_1801102.js b/modules/libjar/test/unit/test_corrupt_1801102.js
new file mode 100644
index 0000000000..395cf36c7f
--- /dev/null
+++ b/modules/libjar/test/unit/test_corrupt_1801102.js
@@ -0,0 +1,20 @@
+/* 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.
+
+add_task(async function test1801102() {
+ let file = do_get_file("data/test_1801102.jar");
+
+ let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
+ Ci.nsIZipReader
+ );
+ zipreader.open(file);
+ Assert.throws(
+ () => zipreader.test(""),
+ /NS_ERROR_FILE_CORRUPTED/,
+ "must throw"
+ );
+});
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..1b8bb9d7e4
--- /dev/null
+++ b/modules/libjar/test/unit/test_corrupt_536911.js
@@ -0,0 +1,32 @@
+/* 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 = Ci.nsIScriptableInputStream;
+ var factory = Cc["@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() {
+ // 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;
+ }
+ Assert.ok(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..dfd0ace015
--- /dev/null
+++ b/modules/libjar/test/unit/test_corrupt_541828.js
@@ -0,0 +1,21 @@
+/* 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() {
+ // 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;
+ }
+ Assert.ok(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..7e48c3c893
--- /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 = Ci.nsIScriptableInputStream;
+ let factory = Cc["@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() {
+ // 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());
+ 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;
+ Cu.forceGC();
+ Assert.ok(!!stream.read(1024).length);
+ Assert.ok(!!dirstream.read(100).length);
+}
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..4e718e927d
--- /dev/null
+++ b/modules/libjar/test/unit/test_dirjar_bug525755.js
@@ -0,0 +1,23 @@
+/* -*- 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() {
+ // 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;
+ }
+ Assert.ok(failed);
+ zipreader = null;
+}
diff --git a/modules/libjar/test/unit/test_empty_jar_telemetry.js b/modules/libjar/test/unit/test_empty_jar_telemetry.js
new file mode 100644
index 0000000000..f63b4028d7
--- /dev/null
+++ b/modules/libjar/test/unit/test_empty_jar_telemetry.js
@@ -0,0 +1,154 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+"use strict";
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+const { TelemetryTestUtils } = ChromeUtils.importESModule(
+ "resource://testing-common/TelemetryTestUtils.sys.mjs"
+);
+
+const nsIBinaryInputStream = Components.Constructor(
+ "@mozilla.org/binaryinputstream;1",
+ "nsIBinaryInputStream",
+ "setInputStream"
+);
+
+// Enable the collection (during test) for all products so even products
+// that don't collect the data will be able to run the test without failure.
+Services.prefs.setBoolPref(
+ "toolkit.telemetry.testing.overrideProductsCheck",
+ true
+);
+
+Services.prefs.setBoolPref("network.jar.record_failure_reason", true);
+
+const fileBase = "test_empty_file.zip";
+const file = do_get_file("data/" + fileBase);
+const tmpDir = Services.dirsvc.get("TmpD", Ci.nsIFile);
+var copy;
+
+function setup() {
+ copy = tmpDir.clone();
+ copy.append("zzdxphd909dbc6r2bxtqss2m000017");
+ copy.append("zzdxphd909dbc6r2bxtqss2m000017");
+ copy.append(fileBase);
+ file.copyTo(copy.parent, copy.leafName);
+}
+
+setup();
+
+registerCleanupFunction(async () => {
+ Services.prefs.clearUserPref("network.jar.record_failure_reason");
+ try {
+ copy.remove(false);
+ } catch (e) {}
+});
+
+function Listener(callback) {
+ this._callback = callback;
+}
+Listener.prototype = {
+ gotStartRequest: false,
+ available: -1,
+ gotStopRequest: false,
+ QueryInterface: ChromeUtils.generateQI(["nsIRequestObserver"]),
+ onDataAvailable(request, stream, offset, count) {
+ try {
+ this.available = stream.available();
+ Assert.equal(this.available, count);
+ // Need to consume stream to avoid assertion
+ new nsIBinaryInputStream(stream).readBytes(count);
+ } catch (ex) {
+ do_throw(ex);
+ }
+ },
+ onStartRequest(request) {
+ this.gotStartRequest = true;
+ },
+ onStopRequest(request, status) {
+ this.gotStopRequest = true;
+ Assert.equal(status, 0);
+ if (this._callback) {
+ this._callback.call(null, this);
+ }
+ },
+};
+
+const TELEMETRY_EVENTS_FILTERS = {
+ category: "zero_byte_load",
+ method: "load",
+};
+
+function makeChan() {
+ var uri = "jar:" + Services.io.newFileURI(copy).spec + "!/test.txt";
+ var chan = NetUtil.newChannel({ uri, loadUsingSystemPrincipal: true });
+ return chan;
+}
+
+add_task(async function test_empty_jar_file_async() {
+ var chan = makeChan();
+
+ Services.telemetry.setEventRecordingEnabled("zero_byte_load", true);
+ Services.telemetry.clearEvents();
+
+ await new Promise(resolve => {
+ chan.asyncOpen(
+ new Listener(function (l) {
+ Assert.ok(chan.contentLength == 0);
+ resolve();
+ })
+ );
+ });
+
+ TelemetryTestUtils.assertEvents(
+ [
+ {
+ category: "zero_byte_load",
+ method: "load",
+ object: "others",
+ value: null,
+ extra: {
+ sync: "false",
+ file_name: `${fileBase}!/test.txt`,
+ status: "NS_OK",
+ cancelled: "false",
+ },
+ },
+ ],
+ TELEMETRY_EVENTS_FILTERS
+ );
+});
+
+add_task(async function test_empty_jar_file_sync() {
+ var chan = makeChan();
+
+ Services.telemetry.setEventRecordingEnabled("zero_byte_load", true);
+ Services.telemetry.clearEvents();
+
+ await new Promise(resolve => {
+ let stream = chan.open();
+ Assert.equal(stream.available(), 0);
+ resolve();
+ });
+
+ TelemetryTestUtils.assertEvents(
+ [
+ {
+ category: "zero_byte_load",
+ method: "load",
+ object: "others",
+ value: null,
+ extra: {
+ sync: "true",
+ file_name: `${fileBase}!/test.txt`,
+ status: "NS_OK",
+ cancelled: "false",
+ },
+ },
+ ],
+ TELEMETRY_EVENTS_FILTERS
+ );
+});
diff --git a/modules/libjar/test/unit/test_fault_handler.js b/modules/libjar/test/unit/test_fault_handler.js
new file mode 100644
index 0000000000..4c2dfd6353
--- /dev/null
+++ b/modules/libjar/test/unit/test_fault_handler.js
@@ -0,0 +1,138 @@
+/* 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/. */
+
+"use strict";
+
+// This test checks that we properly handle exceptions occuring when a
+// network mapped drive is disconnected while we're reading from mmaped
+// file on that drive.
+// Because sharing folders requires network priviledges, this test cannot
+// be completely automated. It will create the necessary files and wait
+// while you run a `net share sharedfolder=...path...` in a CMD terminal
+// with Administator priviledges.
+// See bug 1551562 and bug 1707853
+
+/* import-globals-from ../../zipwriter/test/unit/head_zipwriter.js */
+
+function wrapInputStream(input) {
+ let wrapper = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(
+ Ci.nsIScriptableInputStream
+ );
+ wrapper.init(input);
+ return wrapper;
+}
+
+const { Subprocess } = ChromeUtils.importESModule(
+ "resource://gre/modules/Subprocess.sys.mjs"
+);
+
+const XPI_NAME = "testjar.xpi";
+const SHARE_NAME = "sharedfolder";
+
+async function net(args, silent = false) {
+ if (!silent) {
+ info(`Executing "net ${args.join(" ")}"`);
+ }
+ let proc = await Subprocess.call({
+ command: "C:\\Windows\\System32\\net.exe",
+ arguments: args,
+ environmentAppend: true,
+ stderr: "stdout",
+ });
+ let { exitCode } = await proc.wait();
+ let stdout = await proc.stdout.readString();
+ if (!silent) {
+ info(`stdout: ${stdout}`);
+ equal(exitCode, 0);
+ }
+
+ // Introduce a small delay so we're sure the command effects are visible
+ await new Promise(resolve => do_timeout(500, resolve));
+ return stdout;
+}
+
+const time = 1199145600000; // Jan 1st 2008
+
+add_task(async function test() {
+ let tmpFile = do_get_profile().clone();
+ tmpFile.append("sharedfolder");
+ tmpFile.create(Ci.nsIFile.DIRECTORY_TYPE, 0o755);
+ let tmpDir = tmpFile.clone();
+ tmpFile.append(XPI_NAME);
+
+ let DATA = "a".repeat(1024 * 1024 * 10); // 10Mb
+
+ zipW.open(tmpFile, PR_RDWR | PR_CREATE_FILE | PR_TRUNCATE);
+ let stream = Cc["@mozilla.org/io/string-input-stream;1"].createInstance(
+ Ci.nsIStringInputStream
+ );
+ stream.setData(DATA, DATA.length);
+ zipW.addEntryStream(
+ "data",
+ time * PR_USEC_PER_MSEC,
+ Ci.nsIZipWriter.COMPRESSION_NONE,
+ stream,
+ false
+ );
+ zipW.close();
+
+ // find the computer name
+ let lines = await net(["config", "workstation"], true);
+ let COMPUTER_NAME;
+ for (let l of lines.split("\n")) {
+ if (l.startsWith("Computer name")) {
+ COMPUTER_NAME = l.split("\\\\")[1].trim();
+ }
+ }
+ ok(COMPUTER_NAME);
+
+ dump(
+ `\n\n-------\nNow in a CMD with Administrator priviledges please run:\nnet share ${SHARE_NAME}=${tmpDir.path.replaceAll(
+ "\\\\",
+ "\\"
+ )} /grant:everyone,READ\n\n-------\n`
+ );
+
+ info("waiting while you run command");
+ while (true) {
+ let output = await net(["share"], true);
+ if (output.includes(SHARE_NAME)) {
+ break;
+ }
+ }
+
+ // Map the network share to a X: drive
+ await net(["use", "x:", `\\\\${COMPUTER_NAME}\\${SHARE_NAME}`]);
+
+ // the build script have created the zip we can test on in the current dir.
+ let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
+ file.initWithPath(`X:\\${XPI_NAME}`);
+ info(file.path);
+ ok(file.exists());
+
+ let zipreader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
+ Ci.nsIZipReader
+ );
+ zipreader.open(file);
+ stream = wrapInputStream(zipreader.getInputStream("data"));
+
+ // Delete the X: drive
+ await net(["use", "x:", "/delete", "/y"]);
+
+ // Checks that we get the expected failure
+ Assert.throws(
+ () => {
+ while (true) {
+ Assert.ok(!!stream.read(1024).length);
+ }
+ },
+ /NS_ERROR_FAILURE/,
+ "Got fault handler exception"
+ );
+
+ // This part is optional, but it's good to clean up.
+ dump(
+ `\n\n-------\nNow in a CMD with Administrator priviledges please run:\nnet share ${SHARE_NAME} /delete\n\n-------\n`
+ );
+});
diff --git a/modules/libjar/test/unit/test_jarchannel.js b/modules/libjar/test/unit/test_jarchannel.js
new file mode 100644
index 0000000000..1af6d18854
--- /dev/null
+++ b/modules/libjar/test/unit/test_jarchannel.js
@@ -0,0 +1,204 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/
+ */
+
+/**
+ * Tests some basic jar channel functionality
+ */
+
+const { Constructor: ctor } = Components;
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+
+const ios = Services.io;
+const dirSvc = Services.dirsvc;
+const obs = Services.obs;
+
+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: ChromeUtils.generateQI(["nsIRequestObserver"]),
+ onDataAvailable(request, stream, offset, count) {
+ try {
+ this.available = stream.available();
+ Assert.equal(this.available, count);
+ // Need to consume stream to avoid assertion
+ new nsIBinaryInputStream(stream).readBytes(count);
+ } catch (ex) {
+ do_throw(ex);
+ }
+ },
+ onStartRequest(request) {
+ this.gotStartRequest = true;
+ },
+ onStopRequest(request, status) {
+ this.gotStopRequest = true;
+ Assert.equal(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, loadUsingSystemPrincipal: true });
+ Assert.ok(chan.contentLength < 0);
+ chan.asyncOpen(
+ new Listener(function (l) {
+ Assert.ok(chan.contentLength > 0);
+ Assert.ok(l.gotStartRequest);
+ Assert.ok(l.gotStopRequest);
+ Assert.equal(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,
+ loadUsingSystemPrincipal: true,
+ }).QueryInterface(Ci.nsIJARChannel);
+ var entry = chan.zipEntry;
+ Assert.ok(entry.CRC32 == 0x8b635486);
+ Assert.ok(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, loadUsingSystemPrincipal: true });
+ var stream = chan.open();
+ Assert.ok(chan.contentLength > 0);
+ Assert.equal(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, loadUsingSystemPrincipal: true });
+ var stream = chan.open();
+ Assert.ok(chan.contentLength > 0);
+ Assert.equal(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, loadUsingSystemPrincipal: true });
+ chan.asyncOpen(
+ new Listener(function (l) {
+ Assert.ok(chan.contentLength > 0);
+ Assert.ok(l.gotStartRequest);
+ Assert.ok(l.gotStopRequest);
+ Assert.equal(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, loadUsingSystemPrincipal: true });
+ var stream = chan.open();
+ Assert.ok(chan.contentLength > 0);
+ stream.close();
+
+ // Drop any jar caches
+ obs.notifyObservers(null, "chrome-flush-caches");
+
+ 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, loadUsingSystemPrincipal: true });
+
+ chan.asyncOpen(
+ new Listener(function (l) {
+ Assert.ok(chan.contentLength > 0);
+
+ // Drop any jar caches
+ obs.notifyObservers(null, "chrome-flush-caches");
+
+ 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..66d9bb873c
--- /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 = Ci.nsIScriptableInputStream;
+ var factory = Cc["@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() {
+ // 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;
+ }
+ Assert.ok(check_archive_crc());
+ 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;
+ Cu.forceGC();
+ Assert.ok(!!stream.read(1024).length);
+ Assert.ok(!!dirstream.read(100).length);
+}
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..90c298e64a
--- /dev/null
+++ b/modules/libjar/test/unit/test_not_found.js
@@ -0,0 +1,18 @@
+// Should report file not found on non-existent files
+
+const { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
+const path = "data/test_bug333423.zip";
+
+function run_test() {
+ var spec = "jar:" + Services.io.newFileURI(do_get_file(path)).spec + "!/";
+ var channel = NetUtil.newChannel({
+ uri: spec + "file_that_isnt_in.archive",
+ loadUsingSystemPrincipal: true,
+ });
+ try {
+ channel.open();
+ do_throw("Failed to report that file doesn't exist");
+ } catch (e) {
+ Assert.ok(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..93e43529cd
--- /dev/null
+++ b/modules/libjar/test/unit/test_umlaute.js
@@ -0,0 +1,37 @@
+function run_test() {
+ var tmpDir = Services.dirsvc.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);
+ Assert.ok(entries.hasMore());
+
+ var entryName = entries.getNext();
+ Assert.equal(entryName, "test_\u00FC.txt");
+
+ Assert.ok(zipreader.hasEntry(entryName));
+
+ var target = tmpDir.clone();
+ target.append(entryName);
+ target.create(Ci.nsIFile.NORMAL_FILE_TYPE, 0o640); // 0640
+
+ zipreader.extract(entryName, target);
+
+ var entry = zipreader.getEntry(entryName);
+ Assert.ok(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..2b0e4820e9
--- /dev/null
+++ b/modules/libjar/test/unit/test_uncompressed.js
@@ -0,0 +1,10 @@
+// Make sure uncompressed files pass crc
+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..31285a4c00
--- /dev/null
+++ b/modules/libjar/test/unit/xpcshell.ini
@@ -0,0 +1,55 @@
+[DEFAULT]
+head =
+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_1801102.jar
+ data/test_corrupt.zip
+ data/test_corrupt2.zip
+ data/test_corrupt3.zip
+ data/test_crx_dummy.crx
+ data/test_umlaute.zip
+ data/uncompressed.zip
+ data/test_empty_file.zip
+
+[test_jarchannel.js]
+skip-if = os == "mac"
+[test_bug278262.js]
+[test_bug333423.js]
+[test_bug336691.js]
+[test_bug370103.js]
+[test_bug379841.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_corrupt_1801102.js]
+[test_crx.js]
+[test_dirjar_bug525755.js]
+[test_jarinput_stream_zipreader_reference.js]
+[test_not_found.js]
+[test_uncompressed.js]
+[test_umlaute.js]
+[test_bug1328865.js]
+[test_bug1550815.js]
+# recovering from SIGBUS is temporarily disabled by bug 1583735
+skip-if = true
+[test_empty_jar_telemetry.js]
+[test_fault_handler.js]
+head = ../../zipwriter/test/unit/head_zipwriter.js
+skip-if =
+ os != "win" # tests windows specific exception handling
+ true # Requires elevated priviledges. See bug 1707853 and comments in test