summaryrefslogtreecommitdiffstats
path: root/modules/libjar/test
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /modules/libjar/test
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'modules/libjar/test')
-rw-r--r--modules/libjar/test/chrome/chrome.ini9
-rw-r--r--modules/libjar/test/chrome/signed-added.zipbin0 -> 2141 bytes
-rw-r--r--modules/libjar/test/chrome/signed-badca.zipbin0 -> 1964 bytes
-rw-r--r--modules/libjar/test/chrome/signed-tampered.zipbin0 -> 1979 bytes
-rw-r--r--modules/libjar/test/chrome/signed.zipbin0 -> 1957 bytes
-rw-r--r--modules/libjar/test/chrome/test_bug386153.html97
-rw-r--r--modules/libjar/test/chrome/unsigned.zipbin0 -> 174 bytes
-rw-r--r--modules/libjar/test/mochitest/bug403331.zipbin0 -> 239 bytes
-rw-r--r--modules/libjar/test/mochitest/bug403331.zip^headers^1
-rw-r--r--modules/libjar/test/mochitest/mochitest.ini11
-rw-r--r--modules/libjar/test/mochitest/openredirect.sjs5
-rw-r--r--modules/libjar/test/mochitest/test_bug1034143_mapped.html53
-rw-r--r--modules/libjar/test/mochitest/test_bug1173171.html64
-rw-r--r--modules/libjar/test/mochitest/test_bug403331.html47
-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
52 files changed, 1131 insertions, 0 deletions
diff --git a/modules/libjar/test/chrome/chrome.ini b/modules/libjar/test/chrome/chrome.ini
new file mode 100644
index 000000000..b130cbc33
--- /dev/null
+++ b/modules/libjar/test/chrome/chrome.ini
@@ -0,0 +1,9 @@
+[DEFAULT]
+support-files =
+ signed-added.zip
+ signed-badca.zip
+ signed-tampered.zip
+ signed.zip
+ unsigned.zip
+
+[test_bug386153.html]
diff --git a/modules/libjar/test/chrome/signed-added.zip b/modules/libjar/test/chrome/signed-added.zip
new file mode 100644
index 000000000..c90bc250a
--- /dev/null
+++ b/modules/libjar/test/chrome/signed-added.zip
Binary files differ
diff --git a/modules/libjar/test/chrome/signed-badca.zip b/modules/libjar/test/chrome/signed-badca.zip
new file mode 100644
index 000000000..f493cbd1a
--- /dev/null
+++ b/modules/libjar/test/chrome/signed-badca.zip
Binary files differ
diff --git a/modules/libjar/test/chrome/signed-tampered.zip b/modules/libjar/test/chrome/signed-tampered.zip
new file mode 100644
index 000000000..d3b9d16cc
--- /dev/null
+++ b/modules/libjar/test/chrome/signed-tampered.zip
Binary files differ
diff --git a/modules/libjar/test/chrome/signed.zip b/modules/libjar/test/chrome/signed.zip
new file mode 100644
index 000000000..94e114783
--- /dev/null
+++ b/modules/libjar/test/chrome/signed.zip
Binary files differ
diff --git a/modules/libjar/test/chrome/test_bug386153.html b/modules/libjar/test/chrome/test_bug386153.html
new file mode 100644
index 000000000..3fe541a1a
--- /dev/null
+++ b/modules/libjar/test/chrome/test_bug386153.html
@@ -0,0 +1,97 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=386153
+-->
+<head>
+ <title>Test for Bug 386153</title>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=386153">Mozilla Bug 386153</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript">
+
+/** Test for Bug 386153 **/
+
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+// Opens a zip file from the test directory.
+function openZip(path) {
+
+ var location = window.location.href;
+ location = getRootDirectory(location);
+ var jar = getJar(location);
+ if (jar != null) {
+ var resolved = extractJarToTmp(jar);
+ } else {
+ var resolvedURI = getResolvedURI(window.location.href);
+ var resolved = getChromeDir(resolvedURI);
+ }
+ resolved.append(path);
+
+ var zip = Cc["@mozilla.org/libjar/zip-reader;1"].
+ createInstance(Ci.nsIZipReader);
+ zip.open(resolved);
+ return zip;
+}
+
+// Gets the pretty name from the signing cert or null if the zip is unsigned.
+function getSigner(zip) {
+ var signingCert = zip.getSigningCert(null);
+ if (signingCert) {
+ return signingCert.organization;
+ }
+ return null;
+}
+
+function verifySigning(zip) {
+ var signingCert = zip.getSigningCert(null);
+ var count = 0;
+ var entries = zip.findEntries(null);
+ while (entries.hasMore()) {
+ var entry = entries.getNext();
+ // Nothing in META-INF is in the manifest.
+ if (entry.substr(0, 9) == "META-INF/")
+ continue;
+ // Directory entries aren't in the manifest.
+ if (entry.substr(-1) == "/")
+ continue;
+ count++;
+ var entryCert = zip.getSigningCert(entry);
+ if (!entryCert || !signingCert.equals(entryCert)) {
+ return false;
+ }
+ }
+ return zip.manifestEntriesCount == count;
+}
+
+var zip = openZip("unsigned.zip");
+is(getSigner(zip), null, "Should not be signed");
+
+zip = openZip("signed.zip");
+is(getSigner(zip), "Mozilla Testing", "Should be signed by the right cert");
+ok(verifySigning(zip), "Should be correctly signed");
+
+zip = openZip("signed-added.zip");
+is(getSigner(zip), "Mozilla Testing", "Should be signed by the right cert");
+ok(!verifySigning(zip), "Should be incorrectly signed");
+
+zip = openZip("signed-tampered.zip");
+is(getSigner(zip), "Mozilla Testing", "Should be signed by the right cert");
+ok(!verifySigning(zip), "Should be incorrectly signed");
+
+zip = openZip("signed-badca.zip");
+is(getSigner(zip), null, "Should not appear to be signed");
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/modules/libjar/test/chrome/unsigned.zip b/modules/libjar/test/chrome/unsigned.zip
new file mode 100644
index 000000000..f1e26b06a
--- /dev/null
+++ b/modules/libjar/test/chrome/unsigned.zip
Binary files differ
diff --git a/modules/libjar/test/mochitest/bug403331.zip b/modules/libjar/test/mochitest/bug403331.zip
new file mode 100644
index 000000000..48ba268dd
--- /dev/null
+++ b/modules/libjar/test/mochitest/bug403331.zip
Binary files differ
diff --git a/modules/libjar/test/mochitest/bug403331.zip^headers^ b/modules/libjar/test/mochitest/bug403331.zip^headers^
new file mode 100644
index 000000000..28b8aa0a5
--- /dev/null
+++ b/modules/libjar/test/mochitest/bug403331.zip^headers^
@@ -0,0 +1 @@
+Content-Type: application/java-archive
diff --git a/modules/libjar/test/mochitest/mochitest.ini b/modules/libjar/test/mochitest/mochitest.ini
new file mode 100644
index 000000000..0ae466cca
--- /dev/null
+++ b/modules/libjar/test/mochitest/mochitest.ini
@@ -0,0 +1,11 @@
+[DEFAULT]
+support-files =
+ bug403331.zip
+ bug403331.zip^headers^
+ openredirect.sjs
+ !/dom/base/test/file_bug945152.jar
+
+[test_bug403331.html]
+[test_bug1034143_mapped.html]
+run-if = os == 'linux'
+[test_bug1173171.html] \ No newline at end of file
diff --git a/modules/libjar/test/mochitest/openredirect.sjs b/modules/libjar/test/mochitest/openredirect.sjs
new file mode 100644
index 000000000..b6249cadf
--- /dev/null
+++ b/modules/libjar/test/mochitest/openredirect.sjs
@@ -0,0 +1,5 @@
+function handleRequest(request, response)
+{
+ response.setStatusLine(request.httpVersion, 301, "Moved Permanently");
+ response.setHeader("Location", request.queryString, false);
+}
diff --git a/modules/libjar/test/mochitest/test_bug1034143_mapped.html b/modules/libjar/test/mochitest/test_bug1034143_mapped.html
new file mode 100644
index 000000000..d65ae31f2
--- /dev/null
+++ b/modules/libjar/test/mochitest/test_bug1034143_mapped.html
@@ -0,0 +1,53 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1034143
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 945152</title>
+ <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1034143">Mozilla Bug 1034143</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script type="application/javascript;version=1.7">
+// Ensure that XMLHttpRequest's memory-mapping code can handle a case
+// where the nsIJARChannel's jarFile property is null, but which is
+// otherwise eligible for bug 945152's memory-mapping optimization.
+
+function runTest() {
+ const jarURL = "jar:http://example.org/tests/dom/base/test/file_bug945152.jar!/data_1.txt";
+ let xhr = new XMLHttpRequest({ mozAnon: true, mozSystem: true });
+ xhr.open("GET", jarURL);
+ xhr.onerror = function onerror(e) {
+ ok(false, "JAR XHR failed: " + e.status);
+ SimpleTest.finish();
+ };
+ xhr.onload = function onload(e) {
+ ok(xhr.status == 200, "Status is 200");
+ let ct = xhr.getResponseHeader("Content-Type");
+ ok(ct.indexOf("mem-mapped") == -1, "Data is not memory-mapped");
+ SimpleTest.finish();
+ };
+ xhr.responseType = 'arraybuffer';
+ xhr.send();
+}
+
+SimpleTest.waitForExplicitFinish();
+
+addLoadEvent(function() {
+ SpecialPowers.pushPrefEnv({"set": [["dom.mapped_arraybuffer.enabled", true],
+ ["network.jar.block-remote-files", false]]}, function() {
+ SpecialPowers.pushPermissions([{'type': 'systemXHR', 'allow': true, 'context': document}], runTest);
+ });
+});
+</script>
+</pre>
+</body>
+</html>
diff --git a/modules/libjar/test/mochitest/test_bug1173171.html b/modules/libjar/test/mochitest/test_bug1173171.html
new file mode 100644
index 000000000..9fed630b3
--- /dev/null
+++ b/modules/libjar/test/mochitest/test_bug1173171.html
@@ -0,0 +1,64 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=1173171
+-->
+<head>
+ <title>Test for Bug 1173171</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<iframe id="testFrame"></iframe>
+
+<pre id="test">
+<script class="testbody" type="application/javascript;version=1.7">
+
+/** Test for Bug 1173171 **/
+
+// __setPref(key, value)__.
+// Set a pref value asynchronously, returning a prmoise that resolves
+// when it succeeds.
+let pushPref = function (key, value) {
+ return new Promise(function(resolve, reject) {
+ SpecialPowers.pushPrefEnv({"set": [[key, value]]}, resolve);
+ });
+};
+
+// __xhr(method, url, responseType__.
+// A simple async XMLHttpRequest call.
+// Returns a promise with the response.
+let xhr = function (method, url, responseType) {
+ return new Promise(function (resolve, reject) {
+ let xhr = new XMLHttpRequest();
+ xhr.open(method, url, true);
+ xhr.onload = function () {
+ resolve(xhr.response);
+ };
+ xhr.onerror = function() {
+ resolve(null);
+ };
+ xhr.responseType = responseType;
+ xhr.send();
+ });
+};
+
+let jarURL = "jar:http://mochi.test:8888/tests/modules/libjar/test/mochitest/bug403331.zip!/test.html";
+
+// Test behavior when blocking is deactivated and activated.
+add_task(function* () {
+ for (let shouldBlock of [false, true]) {
+ yield pushPref("network.jar.block-remote-files", shouldBlock);
+ let response = yield xhr("GET", jarURL, "document");
+ ok(shouldBlock === (response === null),
+ "Remote jars should be blocked if and only if the 'network.jar.block-remote-files' pref is active.");
+ }
+});
+
+</script>
+</pre>
+
+</body>
+</html>
diff --git a/modules/libjar/test/mochitest/test_bug403331.html b/modules/libjar/test/mochitest/test_bug403331.html
new file mode 100644
index 000000000..b292c4c9b
--- /dev/null
+++ b/modules/libjar/test/mochitest/test_bug403331.html
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=403331
+-->
+<head>
+ <title>Test for Bug 403331</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+
+<iframe id="testFrame"></iframe>
+
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/** Test for Bug 403331 **/
+
+SimpleTest.waitForExplicitFinish();
+
+function runTest() {
+ var testFrame = document.getElementById('testFrame');
+
+ // Try a redirected load from another domain to this one.
+
+ testFrame.onload = function() {
+ // If properly redirected, we'll be able to access elements in the loaded
+ // document.
+ var item = testFrame.contentDocument.getElementById('testitem');
+ is(item.textContent, "testcontents", "Should be able to access the child document");
+
+ SimpleTest.finish();
+ }
+
+ testFrame.src = "jar:http://example.org:80/tests/modules/libjar/test/mochitest/openredirect.sjs?http://mochi.test:8888/tests/modules/libjar/test/mochitest/bug403331.zip!/test.html";
+}
+
+addLoadEvent(function() {
+ SpecialPowers.pushPrefEnv({"set": [["network.jar.block-remote-files", false]]}, runTest);
+});
+
+</script>
+</pre>
+
+</body>
+</html>
diff --git a/modules/libjar/test/unit/data/empty b/modules/libjar/test/unit/data/empty
new file mode 100644
index 000000000..e69de29bb
--- /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 000000000..42662a408
--- /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 000000000..16bd2d6f2
--- /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 000000000..7723568ba
--- /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 000000000..f3c520519
--- /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 000000000..b7b9e65b4
--- /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 000000000..55ce8fff4
--- /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 000000000..5dc8e747e
--- /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 000000000..d32180101
--- /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 000000000..d7f5f42f9
--- /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 000000000..0cfbf0888
--- /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 000000000..86f8d76c9
--- /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 000000000..516e4ff80
--- /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 000000000..d147138e1
--- /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 000000000..192bf1561
--- /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 000000000..d63276b89
--- /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 000000000..cd965b93e
--- /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 000000000..e10dd3c9c
--- /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 000000000..210cf7a15
--- /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 000000000..a6840a577
--- /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 000000000..313d88c64
--- /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 000000000..bc9d805b4
--- /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 000000000..582712337
--- /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 000000000..1fa103e3c
--- /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 000000000..3f32a8923
--- /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 000000000..d7609f78f
--- /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 000000000..52cf13b1d
--- /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 000000000..fe289959f
--- /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 000000000..f0748dbf2
--- /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 000000000..022eb96eb
--- /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 000000000..e06f36323
--- /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 000000000..00f099a4e
--- /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 000000000..46eda8691
--- /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 000000000..741b84b03
--- /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 000000000..f7944cd47
--- /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 000000000..bfaa0eabc
--- /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 000000000..80fbbcee5
--- /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 000000000..ee22f4c24
--- /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]