summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_compressappend.js
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 /netwerk/test/unit/test_compressappend.js
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 'netwerk/test/unit/test_compressappend.js')
-rw-r--r--netwerk/test/unit/test_compressappend.js80
1 files changed, 80 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_compressappend.js b/netwerk/test/unit/test_compressappend.js
new file mode 100644
index 000000000..275c94433
--- /dev/null
+++ b/netwerk/test/unit/test_compressappend.js
@@ -0,0 +1,80 @@
+//
+// Test that data can be appended to a cache entry even when the data is
+// compressed by the cache compression feature - bug 648429.
+//
+
+function write_and_check(str, data, len)
+{
+ var written = str.write(data, len);
+ if (written != len) {
+ do_throw("str.write has not written all data!\n" +
+ " Expected: " + len + "\n" +
+ " Actual: " + written + "\n");
+ }
+}
+
+function TestAppend(compress, callback)
+{
+ this._compress = compress;
+ this._callback = callback;
+ this.run();
+}
+
+TestAppend.prototype = {
+ _compress: false,
+ _callback: null,
+
+ run: function() {
+ evict_cache_entries();
+ asyncOpenCacheEntry("http://data/",
+ "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
+ this.writeData.bind(this));
+ },
+
+ writeData: function(status, entry) {
+ do_check_eq(status, Cr.NS_OK);
+ if (this._compress)
+ entry.setMetaDataElement("uncompressed-len", "0");
+ var os = entry.openOutputStream(0);
+ write_and_check(os, "12345", 5);
+ os.close();
+ entry.close();
+ asyncOpenCacheEntry("http://data/",
+ "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
+ this.appendData.bind(this));
+ },
+
+ appendData: function(status, entry) {
+ do_check_eq(status, Cr.NS_OK);
+ var os = entry.openOutputStream(entry.storageDataSize);
+ write_and_check(os, "abcde", 5);
+ os.close();
+ entry.close();
+
+ asyncOpenCacheEntry("http://data/",
+ "disk", Ci.nsICacheStorage.OPEN_READONLY, null,
+ this.checkData.bind(this));
+ },
+
+ checkData: function(status, entry) {
+ do_check_eq(status, Cr.NS_OK);
+ var self = this;
+ pumpReadStream(entry.openInputStream(0), function(str) {
+ do_check_eq(str.length, 10);
+ do_check_eq(str, "12345abcde");
+ entry.close();
+
+ do_execute_soon(self._callback);
+ });
+ }
+};
+
+function run_test() {
+ do_get_profile();
+ new TestAppend(false, run_test2);
+ do_test_pending();
+}
+
+function run_test2() {
+ new TestAppend(true, do_test_finished);
+}