2 // Test that data can be appended to a cache entry even when the data is
3 // compressed by the cache compression feature - bug 648429.
8 function write_and_check(str, data, len) {
9 var written = str.write(data, len);
12 "str.write has not written all data!\n" +
23 function TestAppend(compress, callback) {
24 this._compress = compress;
25 this._callback = callback;
29 TestAppend.prototype = {
34 evict_cache_entries();
38 Ci.nsICacheStorage.OPEN_NORMALLY,
40 this.writeData.bind(this)
44 writeData(status, entry) {
45 Assert.equal(status, Cr.NS_OK);
47 entry.setMetaDataElement("uncompressed-len", "0");
49 var os = entry.openOutputStream(0, 5);
50 write_and_check(os, "12345", 5);
56 Ci.nsICacheStorage.OPEN_NORMALLY,
58 this.appendData.bind(this)
62 appendData(status, entry) {
63 Assert.equal(status, Cr.NS_OK);
64 var os = entry.openOutputStream(entry.storageDataSize, 5);
65 write_and_check(os, "abcde", 5);
72 Ci.nsICacheStorage.OPEN_READONLY,
74 this.checkData.bind(this)
78 checkData(status, entry) {
79 Assert.equal(status, Cr.NS_OK);
81 pumpReadStream(entry.openInputStream(0), function (str) {
82 Assert.equal(str.length, 10);
83 Assert.equal(str, "12345abcde");
86 executeSoon(self._callback);
93 new TestAppend(false, run_test2);
97 function run_test2() {
98 new TestAppend(true, do_test_finished);