1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/netwerk/test/unit/test_compressappend.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,80 @@ 1.4 +// 1.5 +// Test that data can be appended to a cache entry even when the data is 1.6 +// compressed by the cache compression feature - bug 648429. 1.7 +// 1.8 + 1.9 +function write_and_check(str, data, len) 1.10 +{ 1.11 + var written = str.write(data, len); 1.12 + if (written != len) { 1.13 + do_throw("str.write has not written all data!\n" + 1.14 + " Expected: " + len + "\n" + 1.15 + " Actual: " + written + "\n"); 1.16 + } 1.17 +} 1.18 + 1.19 +function TestAppend(compress, callback) 1.20 +{ 1.21 + this._compress = compress; 1.22 + this._callback = callback; 1.23 + this.run(); 1.24 +} 1.25 + 1.26 +TestAppend.prototype = { 1.27 + _compress: false, 1.28 + _callback: null, 1.29 + 1.30 + run: function() { 1.31 + evict_cache_entries(); 1.32 + asyncOpenCacheEntry("http://data/", 1.33 + "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null, 1.34 + this.writeData.bind(this)); 1.35 + }, 1.36 + 1.37 + writeData: function(status, entry) { 1.38 + do_check_eq(status, Cr.NS_OK); 1.39 + if (this._compress) 1.40 + entry.setMetaDataElement("uncompressed-len", "0"); 1.41 + var os = entry.openOutputStream(0); 1.42 + write_and_check(os, "12345", 5); 1.43 + os.close(); 1.44 + entry.close(); 1.45 + asyncOpenCacheEntry("http://data/", 1.46 + "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null, 1.47 + this.appendData.bind(this)); 1.48 + }, 1.49 + 1.50 + appendData: function(status, entry) { 1.51 + do_check_eq(status, Cr.NS_OK); 1.52 + var os = entry.openOutputStream(entry.storageDataSize); 1.53 + write_and_check(os, "abcde", 5); 1.54 + os.close(); 1.55 + entry.close(); 1.56 + 1.57 + asyncOpenCacheEntry("http://data/", 1.58 + "disk", Ci.nsICacheStorage.OPEN_READONLY, null, 1.59 + this.checkData.bind(this)); 1.60 + }, 1.61 + 1.62 + checkData: function(status, entry) { 1.63 + do_check_eq(status, Cr.NS_OK); 1.64 + var self = this; 1.65 + pumpReadStream(entry.openInputStream(0), function(str) { 1.66 + do_check_eq(str.length, 10); 1.67 + do_check_eq(str, "12345abcde"); 1.68 + entry.close(); 1.69 + 1.70 + do_execute_soon(self._callback); 1.71 + }); 1.72 + } 1.73 +}; 1.74 + 1.75 +function run_test() { 1.76 + do_get_profile(); 1.77 + new TestAppend(false, run_test2); 1.78 + do_test_pending(); 1.79 +} 1.80 + 1.81 +function run_test2() { 1.82 + new TestAppend(true, do_test_finished); 1.83 +}