Backed out changeset b71c8c052463 (bug 1943846) for causing mass failures. CLOSED...
[gecko.git] / netwerk / test / unit / test_bug654926.js
blobe2a95ef1f5324f8599a9855f63fab1db6a3a060f
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 2MiB
33 var i;
34 for (i = 0; i < 2; i++) {
35 write_and_check(os, data, data.length);
38 os.close();
40 // now change max_entry_size so that the existing entry is too big
41 Services.prefs.setIntPref("browser.cache.disk.max_entry_size", 1024);
43 // append to entry
44 asyncOpenCacheEntry(
45 "http://data/",
46 "disk",
47 Ci.nsICacheStorage.OPEN_NORMALLY,
48 null,
49 append_datafile
53 function append_datafile(status, entry) {
54 Assert.equal(status, Cr.NS_OK);
55 var os = entry.openOutputStream(entry.dataSize, -1);
56 var data = gen_1MiB();
58 // append 1MiB
59 try {
60 write_and_check(os, data, data.length);
61 do_throw();
62 } catch (ex) {}
64 // closing the ostream should fail in this case
65 try {
66 os.close();
67 do_throw();
68 } catch (ex) {}
70 do_test_finished();
73 function run_test() {
74 do_get_profile();
76 // clear the cache
77 evict_cache_entries();
79 asyncOpenCacheEntry(
80 "http://data/",
81 "disk",
82 Ci.nsICacheStorage.OPEN_NORMALLY,
83 null,
84 write_datafile
87 do_test_pending();