Bug 1887774 convert from MediaEnginePrefs to AudioProcessing config in AudioInputProc...
[gecko.git] / netwerk / test / unit / test_compressappend.js
blob05f19be4b513a0258dd8295485d452098c81a4dd
1 //
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.
4 //
6 "use strict";
8 function write_and_check(str, data, len) {
9   var written = str.write(data, len);
10   if (written != len) {
11     do_throw(
12       "str.write has not written all data!\n" +
13         "  Expected: " +
14         len +
15         "\n" +
16         "  Actual: " +
17         written +
18         "\n"
19     );
20   }
23 function TestAppend(compress, callback) {
24   this._compress = compress;
25   this._callback = callback;
26   this.run();
29 TestAppend.prototype = {
30   _compress: false,
31   _callback: null,
33   run() {
34     evict_cache_entries();
35     asyncOpenCacheEntry(
36       "http://data/",
37       "disk",
38       Ci.nsICacheStorage.OPEN_NORMALLY,
39       null,
40       this.writeData.bind(this)
41     );
42   },
44   writeData(status, entry) {
45     Assert.equal(status, Cr.NS_OK);
46     if (this._compress) {
47       entry.setMetaDataElement("uncompressed-len", "0");
48     }
49     var os = entry.openOutputStream(0, 5);
50     write_and_check(os, "12345", 5);
51     os.close();
52     entry.close();
53     asyncOpenCacheEntry(
54       "http://data/",
55       "disk",
56       Ci.nsICacheStorage.OPEN_NORMALLY,
57       null,
58       this.appendData.bind(this)
59     );
60   },
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);
66     os.close();
67     entry.close();
69     asyncOpenCacheEntry(
70       "http://data/",
71       "disk",
72       Ci.nsICacheStorage.OPEN_READONLY,
73       null,
74       this.checkData.bind(this)
75     );
76   },
78   checkData(status, entry) {
79     Assert.equal(status, Cr.NS_OK);
80     var self = this;
81     pumpReadStream(entry.openInputStream(0), function (str) {
82       Assert.equal(str.length, 10);
83       Assert.equal(str, "12345abcde");
84       entry.close();
86       executeSoon(self._callback);
87     });
88   },
91 function run_test() {
92   do_get_profile();
93   new TestAppend(false, run_test2);
94   do_test_pending();
97 function run_test2() {
98   new TestAppend(true, do_test_finished);