From 9376be061ac2dabc2f60d54a525d2ca81a60589a Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Thu, 4 Feb 2021 15:32:02 -0800 Subject: [PATCH] [FSA] Allow seeking past the end of a file Currently, we reject all attempts to write past the end of a file. This change makes the API more consistent with the behavior of POSIX. If writing at an offset past the end of a file, the null bytes between the old end of the file and the offset will count towards the file's quota. Adds Quota tests to the SandboxFSW. Bug: 1153385 Change-Id: Iec54acbccecb728f9375931825525ba2fbafd1ca Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2593810 Reviewed-by: Marijn Kruisselbrink Commit-Queue: Austin Sullivan Cr-Commit-Position: refs/heads/master@{#850838} --- .../FileSystemWritableFileStream-write.js | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/file-system-access/script-tests/FileSystemWritableFileStream-write.js b/file-system-access/script-tests/FileSystemWritableFileStream-write.js index 141a9771d2a932..ea4915a1410549 100644 --- a/file-system-access/script-tests/FileSystemWritableFileStream-write.js +++ b/file-system-access/script-tests/FileSystemWritableFileStream-write.js @@ -117,14 +117,12 @@ directory_test(async (t, root) => { const handle = await createEmptyFile(t, 'bad_offset', root); const stream = await handle.createWritable(); - await promise_rejects_dom( - t, 'InvalidStateError', stream.write({type: 'write', position: 4, data: new Blob(['abc'])})); - await promise_rejects_js( - t, TypeError, stream.close(), 'stream is already closed'); + await stream.write({type: 'write', position: 4, data: new Blob(['abc'])}); + await stream.close(); - assert_equals(await getFileContents(handle), ''); - assert_equals(await getFileSize(handle), 0); -}, 'write() called with an invalid offset'); + assert_equals(await getFileContents(handle), '\0\0\0\0abc'); + assert_equals(await getFileSize(handle), 7); +}, 'write() called with an offset beyond the end of the file'); directory_test(async (t, root) => { const handle = await createEmptyFile(t, 'empty_string', root);