diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /netwerk/test/unit/test_bug654926_doom_and_read.js | |
parent | Initial commit. (diff) | |
download | firefox-esr-upstream.tar.xz firefox-esr-upstream.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'netwerk/test/unit/test_bug654926_doom_and_read.js')
-rw-r--r-- | netwerk/test/unit/test_bug654926_doom_and_read.js | 82 |
1 files changed, 82 insertions, 0 deletions
diff --git a/netwerk/test/unit/test_bug654926_doom_and_read.js b/netwerk/test/unit/test_bug654926_doom_and_read.js new file mode 100644 index 0000000000..1ed618e04a --- /dev/null +++ b/netwerk/test/unit/test_bug654926_doom_and_read.js @@ -0,0 +1,82 @@ +"use strict"; + +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 write_datafile(status, entry) { + Assert.equal(status, Cr.NS_OK); + var data = gen_1MiB(); + var os = entry.openOutputStream(0, data.length); + + write_and_check(os, data, data.length); + + os.close(); + entry.close(); + + // open, doom, append, read + asyncOpenCacheEntry( + "http://data/", + "disk", + Ci.nsICacheStorage.OPEN_NORMALLY, + null, + test_read_after_doom + ); +} + +function test_read_after_doom(status, entry) { + Assert.equal(status, Cr.NS_OK); + var data = gen_1MiB(); + var os = entry.openOutputStream(entry.dataSize, data.length); + + entry.asyncDoom(null); + write_and_check(os, data, data.length); + + os.close(); + + var is = entry.openInputStream(0); + pumpReadStream(is, function (read) { + Assert.equal(read.length, 2 * 1024 * 1024); + is.close(); + + entry.close(); + do_test_finished(); + }); +} + +function run_test() { + do_get_profile(); + + // clear the cache + evict_cache_entries(); + + asyncOpenCacheEntry( + "http://data/", + "disk", + Ci.nsICacheStorage.OPEN_NORMALLY, + null, + write_datafile + ); + + do_test_pending(); +} |