Bug 717061 - add tests for uncompressed->gzip conversion; r=mossop
authorNathan Froyd <froydnj@mozilla.com>
Mon, 13 Feb 2012 12:05:16 -0800
changeset 87748 75c291e1c27ea96ed0401e2e960b6ea8c059904c
parent 87747 9c63c2df568754cf76fcb1c390b6779a7b342447
child 87749 44241c8e5132cc15a261a5a02f70f78b05ff9f0f
push id22143
push userphilringnalda@gmail.com
push dateSun, 26 Feb 2012 23:12:35 +0000
treeherdermozilla-central@b98fc24ac54b [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersmossop
bugs717061
milestone13.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 717061 - add tests for uncompressed->gzip conversion; r=mossop
modules/libjar/zipwriter/test/unit/data/test_bug717061.gz
modules/libjar/zipwriter/test/unit/data/test_bug717061.html
modules/libjar/zipwriter/test/unit/test_bug717061.js
modules/libjar/zipwriter/test/unit/xpcshell.ini
new file mode 100644
index 0000000000000000000000000000000000000000..f990c6e5195d999ccb98abb300ce36efbee6afcd
GIT binary patch
literal 1275
zc$@+I1O)pZiwFP!000001C3V8ZW~7sJV#&AVXh?ChJ7$(nnofihylfM5*k5{!<iP@
z$j;7c9(p9mzo&X;NmGeo<RWQjryo^a)vMLlmp@%>e*bVqKWu)yrVk&#yMA{;vqjha
z_Tr-JE;pC$#mnWh=d_7tNRlNCrti9|_cNO9a~{vT?*9IMdH-S=;;!5L((SYFUv_;6
ziI*<B+4^jyN9)y|ja#ogXG0pe;M*d1Z)O)^$UNl5=5gd1+4l5imiZyqT(8OQO-!8M
zeB6A$cs2V%ifc3MirJl};bBn{VzT6(*ViGkr*~s2e$}<3RmzV&Q%3cvs7(ks+XnYY
zf1Q1GgG`GX<E4K*r#p_$3}#Lyis@fZZ<GAV=k)y9m~mo5AL2P}dt?8=;}*YmF_ghA
zrZ?YQKD&B#_3HK6-)F0?7GJNr#*NklUE|cJXrJ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@!(A5
zrtYIksYdfwa+CZ-%fJ>Qt_ITt$sjYaT9K=@`NXwJ>lP=_5fomB&G|(0I^@W8pX0)k
z-sQTcxelY1+lvLYL;J9!+9=QiSLNBP9F#mYhlZ8mBOk3lZ=|Xa-UdS_CaY0c!Z)C_
lhE<{(DY~3nSmO;J<;hfC{cmJd{|8&2{R2%b>X$1D001`ibYlPj
new file mode 100644
--- /dev/null
+++ b/modules/libjar/zipwriter/test/unit/data/test_bug717061.html
@@ -0,0 +1,16 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8"><meta http-equiv="Content-Language" content="en-us"><title>Lorem Ipsum</title><style type="text/css">
+body {
+	font-family: verdana, arial;
+	font-size: 10pt;
+	color: black;
+	background-color: #D0E8E8;
+}
+</style></head><body>
+<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.</p>
+
+<p>Sed ut perspiciatis unde omnis iste natus error sit voluptatem accusantium doloremque laudantium, totam rem aperiam, eaque ipsa quae ab illo inventore veritatis et quasi architecto beatae vitae dicta sunt explicabo. Nemo enim ipsam voluptatem quia voluptas sit aspernatur aut odit aut fugit, sed quia consequuntur magni dolores eos qui ratione voluptatem sequi nesciunt. Neque porro quisquam est, qui dolorem ipsum quia dolor sit amet, consectetur, adipisci velit, sed quia non numquam eius modi tempora incidunt ut labore et dolore magnam aliquam quaerat voluptatem. Ut enim ad minima veniam, quis nostrum exercitationem ullam corporis suscipit laboriosam, nisi ut aliquid ex ea commodi consequatur? Quis autem vel eum iure reprehenderit qui in ea voluptate velit esse quam nihil molestiae consequatur, vel illum qui dolorem eum fugiat quo voluptas nulla pariatur?</p>
+
+<p>At vero eos et accusamus et iusto odio dignissimos ducimus qui blanditiis praesentium voluptatum deleniti atque corrupti quos dolores et quas molestias excepturi sint occaecati cupiditate non provident, similique sunt in culpa qui officia deserunt mollitia animi, id est laborum et dolorum fuga. Et harum quidem rerum facilis est et expedita distinctio. Nam libero tempore, cum soluta nobis est eligendi optio cumque nihil impedit quo minus id quod maxime placeat facere possimus, omnis voluptas assumenda est, omnis dolor repellendus. Temporibus autem quibusdam et aut officiis debitis aut rerum necessitatibus saepe eveniet ut et voluptates repudiandae sint et molestiae non recusandae. Itaque earum rerum hic tenetur a sapiente delectus, ut aut reiciendis voluptatibus maiores alias consequatur aut perferendis doloribus asperiores repellat.</p>
+
+</body></html>
new file mode 100644
--- /dev/null
+++ b/modules/libjar/zipwriter/test/unit/test_bug717061.js
@@ -0,0 +1,92 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0
+ */
+
+function BinaryComparer(file, callback) {
+  var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
+                createInstance(Ci.nsIFileInputStream);
+  fstream.init(file, -1, 0, 0);
+  this.length = file.fileSize;
+  this.fileStream = Cc["@mozilla.org/binaryinputstream;1"].
+                    createInstance(Ci.nsIBinaryInputStream);
+  this.fileStream.setInputStream(fstream);
+  this.offset = 0;
+  this.callback = callback;
+}
+
+BinaryComparer.prototype = {
+  fileStream: null,
+  offset: null,
+  length: null,
+  callback: null,
+
+  onStartRequest: function(aRequest, aContext) {
+  },
+
+  onStopRequest: function(aRequest, aContext, aStatusCode) {
+    this.fileStream.close();
+    do_check_eq(aStatusCode, Components.results.NS_OK);
+    do_check_eq(this.offset, this.length);
+    this.callback();
+  },
+
+  onDataAvailable: function(aRequest, aContext, aInputStream, aOffset, aCount) {
+    var stream = Cc["@mozilla.org/binaryinputstream;1"].
+                 createInstance(Ci.nsIBinaryInputStream);
+    stream.setInputStream(aInputStream);
+    var source, actual;
+    for (var i = 0; i < aCount; i++) {
+      try {
+        source = this.fileStream.read8();
+      }
+      catch (e) {
+        do_throw("Unable to read from file at offset " + this.offset + " " + e);
+      }
+      try {
+        actual = stream.read8();
+      }
+      catch (e) {
+        do_throw("Unable to read from converted stream at offset " + this.offset + " " + e);
+      }
+      // The byte at offset 9 is the OS byte (see RFC 1952, section 2.3), which
+      // can legitimately differ when the source is compressed on different
+      // operating systems.  The actual .gz for this test was created on a Unix
+      // system, but we want the test to work correctly everywhere.  So ignore
+      // the byte at offset 9.
+      if (this.offset == 9)
+	;
+      else if (source != actual)
+        do_throw("Invalid value " + actual + " at offset " + this.offset + ", should have been " + source);
+      this.offset++;
+    }
+  }
+}
+
+function comparer_callback()
+{
+  do_test_finished();
+}
+
+function run_test()
+{
+  var source = do_get_file(DATA_DIR + "test_bug717061.html");
+  var comparer = new BinaryComparer(do_get_file(DATA_DIR + "test_bug717061.gz"),
+                                    comparer_callback);
+  
+  // Prepare the stream converter
+  var scs = Cc["@mozilla.org/streamConverters;1"].
+            getService(Ci.nsIStreamConverterService);
+  var converter = scs.asyncConvertData("uncompressed", "gzip", comparer, null);
+
+  // Open the expected output file
+  var fstream = Cc["@mozilla.org/network/file-input-stream;1"].
+                createInstance(Ci.nsIFileInputStream);
+  fstream.init(source, -1, 0, 0);
+
+  // Set up a pump to push data from the file to the stream converter
+  var pump = Cc["@mozilla.org/network/input-stream-pump;1"].
+             createInstance(Ci.nsIInputStreamPump);
+  pump.init(fstream, -1, -1, 0, 0, true);
+  pump.asyncRead(converter, null);
+  do_test_pending();
+}
--- a/modules/libjar/zipwriter/test/unit/xpcshell.ini
+++ b/modules/libjar/zipwriter/test/unit/xpcshell.ini
@@ -17,8 +17,9 @@ tail = tail_zipwriter.js
 [test_deflatedata.js]
 [test_directory.js]
 [test_editexisting.js]
 [test_storedata.js]
 [test_sync.js]
 [test_undochange.js]
 [test_zipcomment.js]
 [test_zippermissions.js]
+[test_bug717061.js]