Bug 1857386 [wpt PR 42383] - Update wpt metadata, a=testonly
[gecko.git] / netwerk / test / unit / test_cache2-25-chunk-memory-limit.js
blob8c5a383ba60dc22199e8b3464e3fa957818c1c59
1 "use strict";
3 function gen_200k() {
4   var i;
5   var data = "0123456789ABCDEFGHIJLKMNO";
6   for (i = 0; i < 13; i++) {
7     data += data;
8   }
9   return data;
12 // Keep the output stream of the first entry in a global variable, so the
13 // CacheFile and its buffer isn't released before we write the data to the
14 // second entry.
15 var oStr;
17 function run_test() {
18   do_get_profile();
20   // set max chunks memory so that only one full chunk fits within the limit
21   Services.prefs.setIntPref("browser.cache.disk.max_chunks_memory_usage", 300);
23   asyncOpenCacheEntry(
24     "http://a/",
25     "disk",
26     Ci.nsICacheStorage.OPEN_NORMALLY,
27     null,
28     function (status, entry) {
29       Assert.equal(status, Cr.NS_OK);
30       var data = gen_200k();
31       oStr = entry.openOutputStream(0, data.length);
32       Assert.equal(data.length, oStr.write(data, data.length));
34       asyncOpenCacheEntry(
35         "http://b/",
36         "disk",
37         Ci.nsICacheStorage.OPEN_NORMALLY,
38         null,
39         function (status1, entry1) {
40           Assert.equal(status1, Cr.NS_OK);
41           var oStr2 = entry1.openOutputStream(0, data.length);
42           do_check_throws_nsIException(
43             () => oStr2.write(data, data.length),
44             "NS_ERROR_OUT_OF_MEMORY"
45           );
46           finish_cache2_test();
47         }
48       );
49     }
50   );
52   do_test_pending();