tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_cache2-25-chunk-memory-limit.js (1340B)


      1 "use strict";
      2 
      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;
     10 }
     11 
     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;
     16 
     17 function run_test() {
     18  do_get_profile();
     19 
     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);
     22 
     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));
     33 
     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  );
     51 
     52  do_test_pending();
     53 }