2011-06-22 12:49:35 +04: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-13 01:23:32 +04:00
|
|
|
function write_datafile(status, entry)
|
2011-06-22 12:49:35 +04:00
|
|
|
{
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(status, Cr.NS_OK);
|
2011-06-22 12:49:35 +04:00
|
|
|
var data = gen_1MiB();
|
2018-04-25 07:01:00 +03:00
|
|
|
var os = entry.openOutputStream(0, data.length);
|
2011-06-22 12:49:35 +04:00
|
|
|
|
2012-06-13 01:23:32 +04:00
|
|
|
write_and_check(os, data, data.length);
|
|
|
|
|
|
|
|
os.close();
|
|
|
|
entry.close();
|
|
|
|
|
|
|
|
// open, doom, append, read
|
2013-09-20 13:11:25 +04:00
|
|
|
asyncOpenCacheEntry("http://data/",
|
|
|
|
"disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
|
2012-06-13 01:23:32 +04:00
|
|
|
test_read_after_doom);
|
2011-06-22 12:49:35 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2012-06-13 01:23:32 +04:00
|
|
|
function test_read_after_doom(status, entry)
|
2011-06-22 12:49:35 +04:00
|
|
|
{
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(status, Cr.NS_OK);
|
2011-06-22 12:49:35 +04:00
|
|
|
var data = gen_1MiB();
|
2018-04-25 07:01:00 +03:00
|
|
|
var os = entry.openOutputStream(entry.dataSize, data.length);
|
2011-06-22 12:49:35 +04:00
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
entry.asyncDoom(null);
|
2012-06-13 01:23:32 +04:00
|
|
|
write_and_check(os, data, data.length);
|
2011-06-22 12:49:35 +04:00
|
|
|
|
2012-06-13 01:23:32 +04:00
|
|
|
os.close();
|
2011-06-22 12:49:35 +04:00
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
var is = entry.openInputStream(0);
|
|
|
|
pumpReadStream(is, function(read) {
|
2017-12-21 13:08:17 +03:00
|
|
|
Assert.equal(read.length, 2*1024*1024);
|
2013-09-20 13:11:25 +04:00
|
|
|
is.close();
|
2011-06-22 12:49:35 +04:00
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
entry.close();
|
|
|
|
do_test_finished();
|
|
|
|
});
|
2011-06-22 12:49:35 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function run_test() {
|
|
|
|
do_get_profile();
|
|
|
|
|
|
|
|
// clear the cache
|
2012-06-13 01:23:32 +04:00
|
|
|
evict_cache_entries();
|
2011-06-22 12:49:35 +04:00
|
|
|
|
2013-09-20 13:11:25 +04:00
|
|
|
asyncOpenCacheEntry("http://data/",
|
|
|
|
"disk", Ci.nsICacheStorage.OPEN_NORMALLY, null,
|
2012-06-13 01:23:32 +04:00
|
|
|
write_datafile);
|
2011-06-22 12:49:35 +04:00
|
|
|
|
2012-06-13 01:23:32 +04:00
|
|
|
do_test_pending();
|
2011-06-22 12:49:35 +04:00
|
|
|
}
|