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");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function make_input_stream_scriptable(input) {
|
|
|
|
var wrapper = Cc["@mozilla.org/scriptableinputstream;1"].
|
|
|
|
createInstance(Ci.nsIScriptableInputStream);
|
|
|
|
wrapper.init(input);
|
|
|
|
return wrapper;
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
|
|
|
// open, doom, append, read
|
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
|
|
|
test_read_after_doom);
|
2011-06-22 01:49:35 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-12 14:23:32 -07:00
|
|
|
function test_read_after_doom(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();
|
|
|
|
|
2013-09-20 02:11:25 -07:00
|
|
|
entry.asyncDoom(null);
|
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();
|
2011-06-22 01:49:35 -07:00
|
|
|
|
2013-09-20 02:11:25 -07:00
|
|
|
var is = entry.openInputStream(0);
|
|
|
|
pumpReadStream(is, function(read) {
|
|
|
|
do_check_eq(read.length, 2*1024*1024);
|
|
|
|
is.close();
|
2011-06-22 01:49:35 -07:00
|
|
|
|
2013-09-20 02:11:25 -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();
|
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
|
|
|
}
|