summaryrefslogtreecommitdiffstats
path: root/netwerk/test/unit/test_cache2-25-chunk-memory-limit.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /netwerk/test/unit/test_cache2-25-chunk-memory-limit.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'netwerk/test/unit/test_cache2-25-chunk-memory-limit.js')
-rw-r--r--netwerk/test/unit/test_cache2-25-chunk-memory-limit.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_cache2-25-chunk-memory-limit.js b/netwerk/test/unit/test_cache2-25-chunk-memory-limit.js
new file mode 100644
index 000000000..0999dc8d2
--- /dev/null
+++ b/netwerk/test/unit/test_cache2-25-chunk-memory-limit.js
@@ -0,0 +1,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();
+}