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();
|
|
|
|
|
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
|
2013-09-20 02:11:25 -07:00
|
|
|
asyncOpenCacheEntry("http://data/",
|
|
|
|
"disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
|
2012-06-12 14:23:32 -07:00
|
|
|
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
|
|
|
|
2013-09-20 02:11:25 -07:00
|
|
|
asyncOpenCacheEntry("http://data/",
|
|
|
|
"disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
|
2012-06-12 14:23:32 -07:00
|
|
|
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
|
|
|
}
|