2011-05-20 10:27:11 -07:00
|
|
|
const Cc = Components.classes;
|
|
|
|
const Ci = Components.interfaces;
|
|
|
|
const Cr = Components.results;
|
|
|
|
|
|
|
|
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_big_datafile(status, entry)
|
2011-05-20 10:27:11 -07:00
|
|
|
{
|
2012-06-12 14:23:32 -07:00
|
|
|
do_check_eq(status, Cr.NS_OK);
|
|
|
|
var os = entry.openOutputStream(0);
|
2011-05-20 10:27:11 -07:00
|
|
|
var data = gen_1MiB();
|
|
|
|
|
|
|
|
// >64MiB
|
|
|
|
var i;
|
|
|
|
for (i=0 ; i<65 ; i++)
|
2012-06-12 14:23:32 -07:00
|
|
|
write_and_check(os, data, data.length);
|
2011-05-20 10:27:11 -07:00
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
os.close();
|
|
|
|
entry.close();
|
|
|
|
do_execute_soon(run_test_2);
|
2011-05-20 10:27:11 -07:00
|
|
|
}
|
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
function write_and_doom_big_metafile(status, entry)
|
2011-05-20 10:27:11 -07:00
|
|
|
{
|
2012-06-12 14:23:32 -07:00
|
|
|
do_check_eq(status, Cr.NS_OK);
|
|
|
|
var os = entry.openOutputStream(0);
|
2011-05-20 10:27:11 -07:00
|
|
|
var data = gen_1MiB();
|
|
|
|
|
|
|
|
// >64MiB
|
|
|
|
var i;
|
|
|
|
for (i=0 ; i<65 ; i++)
|
2012-06-12 14:23:32 -07:00
|
|
|
entry.setMetaDataElement("metadata_"+i, data);
|
2011-05-20 10:27:11 -07:00
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
write_and_check(os, data, data.length);
|
2011-05-20 10:27:11 -07:00
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
os.close();
|
|
|
|
entry.doom();
|
|
|
|
entry.close();
|
|
|
|
do_execute_soon(run_test_3);
|
2011-05-20 10:27:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function check_cache_size() {
|
|
|
|
var diskDeviceVisited;
|
|
|
|
var visitor = {
|
|
|
|
visitDevice: function (deviceID, deviceInfo) {
|
|
|
|
if (deviceID == "disk") {
|
|
|
|
diskDeviceVisited = true;
|
|
|
|
do_check_eq(deviceInfo.totalSize, 0)
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
visitEntry: function (deviceID, entryInfo) {
|
|
|
|
do_throw("unexpected call to visitEntry");
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
var cs = get_cache_service();
|
|
|
|
diskDeviceVisited = false;
|
|
|
|
cs.visitEntries(visitor);
|
|
|
|
do_check_true(diskDeviceVisited);
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
var prefBranch = Cc["@mozilla.org/preferences-service;1"].
|
|
|
|
getService(Ci.nsIPrefBranch);
|
|
|
|
prefBranch.setIntPref("browser.cache.disk.capacity", 50000);
|
|
|
|
|
|
|
|
do_get_profile();
|
|
|
|
|
|
|
|
// clear the cache
|
2012-06-12 14:23:32 -07:00
|
|
|
evict_cache_entries();
|
2011-05-20 10:27:11 -07:00
|
|
|
|
|
|
|
// write an entry with data > 64MiB
|
2012-06-12 14:23:32 -07:00
|
|
|
asyncOpenCacheEntry("bigdata",
|
|
|
|
"HTTP",
|
|
|
|
Ci.nsICache.STORE_ON_DISK_AS_FILE,
|
|
|
|
Ci.nsICache.ACCESS_WRITE,
|
|
|
|
write_big_datafile);
|
2011-05-20 10:27:11 -07:00
|
|
|
|
|
|
|
do_test_pending();
|
|
|
|
}
|
|
|
|
|
|
|
|
function run_test_2()
|
|
|
|
{
|
|
|
|
check_cache_size();
|
|
|
|
|
|
|
|
// write an entry with metadata > 64MiB
|
2012-06-12 14:23:32 -07:00
|
|
|
asyncOpenCacheEntry("bigmetadata",
|
|
|
|
"HTTP",
|
|
|
|
Ci.nsICache.STORE_ON_DISK_AS_FILE,
|
|
|
|
Ci.nsICache.ACCESS_WRITE,
|
|
|
|
write_and_doom_big_metafile);
|
2011-05-20 10:27:11 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_test_3()
|
|
|
|
{
|
|
|
|
check_cache_size();
|
|
|
|
|
|
|
|
do_test_finished();
|
|
|
|
}
|