Bug 1931425 - Limit how often moz-label's #setStyles runs r=reusable-components-revie...
[gecko.git] / netwerk / test / unit / test_bug654926_doom_and_read.js
blobb7e8c71d804074a4e29959d824c5a212fbaab9e8
1 "use strict";
3 function gen_1MiB() {
4 var i;
5 var data = "x";
6 for (i = 0; i < 20; i++) {
7 data += data;
9 return data;
12 function write_and_check(str, data, len) {
13 var written = str.write(data, len);
14 if (written != len) {
15 do_throw(
16 "str.write has not written all data!\n" +
17 " Expected: " +
18 len +
19 "\n" +
20 " Actual: " +
21 written +
22 "\n"
27 function write_datafile(status, entry) {
28 Assert.equal(status, Cr.NS_OK);
29 var data = gen_1MiB();
30 var os = entry.openOutputStream(0, data.length);
32 write_and_check(os, data, data.length);
34 os.close();
36 // open, doom, append, read
37 asyncOpenCacheEntry(
38 "http://data/",
39 "disk",
40 Ci.nsICacheStorage.OPEN_NORMALLY,
41 null,
42 test_read_after_doom
46 function test_read_after_doom(status, entry) {
47 Assert.equal(status, Cr.NS_OK);
48 var data = gen_1MiB();
49 var os = entry.openOutputStream(entry.dataSize, data.length);
51 entry.asyncDoom(null);
52 write_and_check(os, data, data.length);
54 os.close();
56 var is = entry.openInputStream(0);
57 pumpReadStream(is, function (read) {
58 Assert.equal(read.length, 2 * 1024 * 1024);
59 is.close();
61 do_test_finished();
62 });
65 function run_test() {
66 do_get_profile();
68 // clear the cache
69 evict_cache_entries();
71 asyncOpenCacheEntry(
72 "http://data/",
73 "disk",
74 Ci.nsICacheStorage.OPEN_NORMALLY,
75 null,
76 write_datafile
79 do_test_pending();