2011-06-22 01:49:35 -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_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();
|
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
write_and_check(os, data, data.length);
|
|
|
|
|
|
|
|
os.close();
|
|
|
|
entry.close();
|
2011-06-22 01:49:35 -07:00
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
// try to open the entry for appending
|
|
|
|
asyncOpenCacheEntry("data",
|
|
|
|
"HTTP",
|
|
|
|
Ci.nsICache.STORE_ON_DISK,
|
|
|
|
Ci.nsICache.ACCESS_READ_WRITE,
|
|
|
|
open_for_readwrite);
|
2011-06-22 01:49:35 -07:00
|
|
|
}
|
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
function open_for_readwrite(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
|
|
|
|
|
|
|
// Opening the entry for appending data calls nsDiskCacheStreamIO::Seek()
|
|
|
|
// which initializes mFD. If no data is written then mBufDirty is false and
|
|
|
|
// mFD won't be closed in nsDiskCacheStreamIO::Flush().
|
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
os.close();
|
|
|
|
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();
|
2011-06-22 01:49:35 -07:00
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
asyncOpenCacheEntry("data",
|
|
|
|
"HTTP",
|
2013-01-03 15:30:48 -08:00
|
|
|
Ci.nsICache.STORE_ON_DISK,
|
2012-06-12 14:23:32 -07:00
|
|
|
Ci.nsICache.ACCESS_WRITE,
|
|
|
|
write_datafile);
|
2011-06-22 01:49:35 -07:00
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
do_test_pending();
|
2011-06-22 01:49:35 -07:00
|
|
|
}
|