diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-15 03:34:42 +0000 |
commit | da4c7e7ed675c3bf405668739c3012d140856109 (patch) | |
tree | cdd868dba063fecba609a1d819de271f0d51b23e /dom/fs/test/common/test_writableFileStream.js | |
parent | Adding upstream version 125.0.3. (diff) | |
download | firefox-da4c7e7ed675c3bf405668739c3012d140856109.tar.xz firefox-da4c7e7ed675c3bf405668739c3012d140856109.zip |
Adding upstream version 126.0.upstream/126.0
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/fs/test/common/test_writableFileStream.js')
-rw-r--r-- | dom/fs/test/common/test_writableFileStream.js | 106 |
1 files changed, 106 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, |