summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_cache2-25-chunk-memory-limit.js
blob: 0999dc8d2f3346f680817c08d7b253d04ba877b4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Components.utils.import('resource://gre/modules/LoadContextInfo.jsm');

function gen_200k()
{
  var i;
  var data="0123456789ABCDEFGHIJLKMNO";
  for (i=0; i<13; i++)
    data+=data;
  return data;
}

// Keep the output stream of the first entry in a global variable, so the
// CacheFile and its buffer isn't released before we write the data to the
// second entry.
var oStr;

function run_test()
{
  do_get_profile();

  if (!newCacheBackEndUsed()) {
    do_check_true(true, "This test doesn't run when the old cache back end is used since the behavior is different");
    return;
  }

  var prefBranch = Cc["@mozilla.org/preferences-service;1"].
                     getService(Ci.nsIPrefBranch);

  // set max chunks memory so that only one full chunk fits within the limit
  prefBranch.setIntPref("browser.cache.disk.max_chunks_memory_usage", 300);

  asyncOpenCacheEntry("http://a/", "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
    function(status, entry) {
      do_check_eq(status, Cr.NS_OK);
      oStr = entry.openOutputStream(0);
      var data = gen_200k();
      do_check_eq(data.length, oStr.write(data, data.length));

      asyncOpenCacheEntry("http://b/", "disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
        function(status, entry) {
          do_check_eq(status, Cr.NS_OK);
          var oStr2 = entry.openOutputStream(0);
          do_check_throws_nsIException(() => oStr2.write(data, data.length), 'NS_ERROR_OUT_OF_MEMORY');
          finish_cache2_test();
        }
      );
    }
  );

  do_test_pending();
}