diff options
Diffstat (limited to 'dom/fs/test')
-rw-r--r-- | dom/fs/test/common/test_writableFileStream.js | 106 | ||||
-rw-r--r-- | dom/fs/test/crashtests/1874334-2.html | 8 | ||||
-rw-r--r-- | dom/fs/test/crashtests/1874334.html | 16 | ||||
-rw-r--r-- | dom/fs/test/crashtests/crashtests.list | 3 | ||||
-rw-r--r-- | dom/fs/test/crashtests/sw1874334-2.js | 12 |
5 files changed, 145 insertions, 0 deletions
diff --git a/dom/fs/test/common/test_writableFileStream.js b/dom/fs/test/common/test_writableFileStream.js index 016c53bf3b..5b6caa0d20 100644 --- a/dom/fs/test/common/test_writableFileStream.js +++ b/dom/fs/test/common/test_writableFileStream.js @@ -2,6 +2,7 @@ http://creativecommons.org/publicdomain/zero/1.0/ */ const allowCreate = { create: true }; +const denyCreate = { create: false }; exported_symbols.test0 = async function () { let root = await navigator.storage.getDirectory(); @@ -145,6 +146,111 @@ exported_symbols.bug1825018 = async function () { } }; +exported_symbols.usageTest = async function () { + const bufferSize = 1024; + const keepData = { keepExistingData: true }; + const fromEmpty = { keepExistingData: false }; + + let root = await navigator.storage.getDirectory(); + Assert.ok(root, "Can we access the root directory?"); + + const baseUsage = await Utils.getCachedOriginUsage(); + Assert.ok(true, "Usage " + baseUsage); + // Create a file. + { + const fileHandle = await root.getFileHandle("usagetest.txt", allowCreate); + Assert.ok(!!fileHandle, "Can we get file handle?"); + + const writable = await fileHandle.createWritable(fromEmpty); + Assert.ok(!!writable, "Can we create writable file stream?"); + + const buffer = new ArrayBuffer(bufferSize); + Assert.ok(!!buffer, "Can we create array buffer?"); + + const result = await writable.write(buffer); + Assert.equal(result, undefined, "Can we write entire buffer?"); + + await writable.close(); + } + + { + const fileUsage = await Utils.getCachedOriginUsage(); + Assert.ok(true, "Usage " + fileUsage); + Assert.ok(fileUsage >= baseUsage + bufferSize); + + const fileHandle = await root.getFileHandle("usagetest.txt", denyCreate); + Assert.ok(!!fileHandle, "Can we get file handle?"); + + { + const usageNow = await Utils.getCachedOriginUsage(); + Assert.equal(usageNow, fileUsage); + } + + const writableA = await fileHandle.createWritable(keepData); + Assert.ok(!!writableA, "Can we create writable file stream?"); + + { + const usageNow = await Utils.getCachedOriginUsage(); + Assert.ok(true, "Usage " + usageNow.usage); + Assert.equal(usageNow, fileUsage + bufferSize); + } + + const writableB = await fileHandle.createWritable(keepData); + Assert.ok(!!writableB, "Can we create writable file stream?"); + + { + const usageNow = await Utils.getCachedOriginUsage(); + Assert.equal(usageNow, fileUsage + 2 * bufferSize); + } + + const writableC = await fileHandle.createWritable(keepData); + Assert.ok(!!writableC, "Can we create writable file stream?"); + + { + const usageNow = await Utils.getCachedOriginUsage(); + Assert.equal(usageNow, fileUsage + 3 * bufferSize); + } + + const writableD = await fileHandle.createWritable(fromEmpty); + Assert.ok(!!writableD, "Can we create writable file stream?"); + + { + const usageNow = await Utils.getCachedOriginUsage(); + // We did not keep existing data for this writable + Assert.equal(usageNow, fileUsage + 3 * bufferSize); + } + + await writableA.abort(); + + { + const usageNow = await Utils.getCachedOriginUsage(); + Assert.equal(usageNow, fileUsage + 2 * bufferSize); + } + + await writableB.close(); + + { + const usageNow = await Utils.getCachedOriginUsage(); + Assert.equal(usageNow, fileUsage + bufferSize); + } + + await writableC.abort(); + + { + const usageNow = await Utils.getCachedOriginUsage(); + Assert.equal(usageNow, fileUsage); + } + + await writableD.close(); + + { + const usageNow = await Utils.getCachedOriginUsage(); + // Buffer was overwritten with nothing. + Assert.equal(usageNow, fileUsage - bufferSize); + } + } +}; + for (const [key, value] of Object.entries(exported_symbols)) { Object.defineProperty(value, "name", { value: key, diff --git a/dom/fs/test/crashtests/1874334-2.html b/dom/fs/test/crashtests/1874334-2.html new file mode 100644 index 0000000000..3d30d7496f --- /dev/null +++ b/dom/fs/test/crashtests/1874334-2.html @@ -0,0 +1,8 @@ +<script> +document.addEventListener("DOMContentLoaded", async () => { + await self.navigator.serviceWorker.register("sw1874334-2.js?318", { }) + await self.navigator.serviceWorker.register("sw1874334-2.js?363", { }) + await self.navigator.serviceWorker.register("sw1874334-2.js?87", { }) + await self.fetch("missing", {"headers": []}) +}) +</script> diff --git a/dom/fs/test/crashtests/1874334.html b/dom/fs/test/crashtests/1874334.html new file mode 100644 index 0000000000..590025a60f --- /dev/null +++ b/dom/fs/test/crashtests/1874334.html @@ -0,0 +1,16 @@ +<script> + +async function stuff() { + let arr = new ArrayBuffer(500000); + let blob = new Blob([arr]); + let file = new File([blob], "", { }); + + let dir = await self.navigator.storage.getDirectory(); + let handle = await dir.getFileHandle("514600c6-596b-4676-ab0c-3e6f1e86759f", {"create": true}); + let wfs = await handle.createWritable({"keepExistingData": true}); + + await file.stream().pipeTo(wfs); +}; + +document.addEventListener("DOMContentLoaded", stuff); +</script> diff --git a/dom/fs/test/crashtests/crashtests.list b/dom/fs/test/crashtests/crashtests.list index a083cb80b2..c5130c4232 100644 --- a/dom/fs/test/crashtests/crashtests.list +++ b/dom/fs/test/crashtests/crashtests.list @@ -1,6 +1,7 @@ # StorageManager isn't enabled on Android defaults skip-if(Android) pref(dom.fs.enabled,true) pref(dom.fs.writable_file_stream.enabled,true) +# Most of the issues here are reproducible only with --verify load 1798773.html load 1800470.html load 1809759.html @@ -8,3 +9,5 @@ load 1816710.html load 1841702.html HTTP load 1844619.html HTTP load 1858820.html +load 1874334.html +HTTP load 1874334-2.html diff --git a/dom/fs/test/crashtests/sw1874334-2.js b/dom/fs/test/crashtests/sw1874334-2.js new file mode 100644 index 0000000000..59d82ebaaa --- /dev/null +++ b/dom/fs/test/crashtests/sw1874334-2.js @@ -0,0 +1,12 @@ +(async () => { + let arr = new ArrayBuffer(43109) + let blob = new Blob([arr, arr, arr, arr, arr]) + let req = new Request("missing", {"headers": []}) + let dir = await self.navigator.storage.getDirectory() + let file = new File([blob, arr], "", { }) + let handle = await dir.getFileHandle("514600c6-596b-4676-ab0c-3e6f1e86759f", {"create": true}) + let wfs = await handle.createWritable({"keepExistingData": true}) + await handle.createWritable({"keepExistingData": true}) + try { await req.json(arr, {"headers": []}) } catch (e) {} + try { await file.stream().pipeTo(wfs, { }) } catch (e) {} +})() |