2011-06-22 01:49:35 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
2011-09-13 12:24:01 -07:00
|
|
|
var _PSvc;
|
|
|
|
function get_pref_service() {
|
|
|
|
if (_PSvc)
|
|
|
|
return _PSvc;
|
|
|
|
|
|
|
|
return _PSvc = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
}
|
|
|
|
|
2011-06-22 01:49:35 -07:00
|
|
|
function gen_1MiB()
|
|
|
|
{
|
|
|
|
var i;
|
|
|
|
var data="x";
|
|
|
|
for (i=0 ; i < 20 ; i++)
|
|
|
|
data+=data;
|
|
|
|
return data;
|
|
|
|
}
|
|
|
|
|
|
|
|
function write_and_check(str, data, len)
|
|
|
|
{
|
|
|
|
var written = str.write(data, len);
|
|
|
|
if (written != len) {
|
|
|
|
do_throw("str.write has not written all data!\n" +
|
|
|
|
" Expected: " + len + "\n" +
|
|
|
|
" Actual: " + written + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
function write_datafile(status, entry)
|
2011-06-22 01:49:35 -07:00
|
|
|
{
|
2012-06-12 14:23:32 -07:00
|
|
|
do_check_eq(status, Cr.NS_OK);
|
|
|
|
var os = entry.openOutputStream(0);
|
2011-06-22 01:49:35 -07:00
|
|
|
var data = gen_1MiB();
|
|
|
|
|
2011-09-13 12:24:01 -07:00
|
|
|
// max size in MB
|
|
|
|
var max_size = get_pref_service().
|
|
|
|
getIntPref("browser.cache.disk.max_entry_size") / 1024;
|
|
|
|
|
|
|
|
// write larger entry than is allowed
|
2011-06-22 01:49:35 -07:00
|
|
|
var i;
|
2011-09-13 12:24:01 -07:00
|
|
|
for (i=0 ; i<(max_size+1) ; i++)
|
2012-06-12 14:23:32 -07:00
|
|
|
write_and_check(os, data, data.length);
|
2011-06-22 01:49:35 -07:00
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
os.close();
|
|
|
|
entry.close();
|
2011-06-22 01:49:35 -07:00
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
// append to entry
|
|
|
|
asyncOpenCacheEntry("data",
|
|
|
|
"HTTP",
|
|
|
|
Ci.nsICache.STORE_ON_DISK,
|
|
|
|
Ci.nsICache.ACCESS_READ_WRITE,
|
|
|
|
append_datafile);
|
2011-06-22 01:49:35 -07:00
|
|
|
}
|
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
function append_datafile(status, entry)
|
2011-06-22 01:49:35 -07:00
|
|
|
{
|
2012-06-12 14:23:32 -07:00
|
|
|
do_check_eq(status, Cr.NS_OK);
|
|
|
|
var os = entry.openOutputStream(entry.dataSize);
|
2011-06-22 01:49:35 -07:00
|
|
|
var data = gen_1MiB();
|
|
|
|
|
|
|
|
// append 1MiB
|
|
|
|
try {
|
2012-06-12 14:23:32 -07:00
|
|
|
write_and_check(os, data, data.length);
|
2011-06-22 01:49:35 -07:00
|
|
|
do_throw();
|
|
|
|
}
|
|
|
|
catch (ex) { }
|
|
|
|
|
|
|
|
// closing the ostream should fail in this case
|
|
|
|
try {
|
2012-06-12 14:23:32 -07:00
|
|
|
os.close();
|
2011-06-22 01:49:35 -07:00
|
|
|
do_throw();
|
|
|
|
}
|
|
|
|
catch (ex) { }
|
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
entry.close();
|
|
|
|
|
|
|
|
do_test_finished();
|
2011-06-22 01:49:35 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
do_get_profile();
|
|
|
|
|
|
|
|
// clear the cache
|
2012-06-12 14:23:32 -07:00
|
|
|
evict_cache_entries();
|
|
|
|
|
|
|
|
// force to write file bigger than 5MiB
|
|
|
|
asyncOpenCacheEntry("data",
|
|
|
|
"HTTP",
|
|
|
|
Ci.nsICache.STORE_ON_DISK_AS_FILE,
|
|
|
|
Ci.nsICache.ACCESS_WRITE,
|
|
|
|
write_datafile);
|
2011-06-22 01:49:35 -07:00
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|