From b8c24dccaa3803f6cf8bb16db67be9f28b610123 Mon Sep 17 00:00:00 2001 From: Austin Sullivan Date: Thu, 13 Oct 2022 09:44:59 -0700 Subject: [PATCH] FSA: Reject moves with empty names move("") rejects with a TypeError, while move(dir, "") succeeds (by ignoring the second arg). Make this consistent by always rejecting if there's an invalid name, as specified in https://wicg.github.io/file-system-access/#valid-file-name See https://github.com/whatwg/fs/pull/10#issuecomment-1236232639 Bug: 1327741 Change-Id: Ifd8457df05aad7f75007ff5eece6237a09098a94 --- fs/script-tests/FileSystemFileHandle-move.js | 35 +++----------------- 1 file changed, 4 insertions(+), 31 deletions(-) diff --git a/fs/script-tests/FileSystemFileHandle-move.js b/fs/script-tests/FileSystemFileHandle-move.js index c914bd82fa9ccee..a65251e4898a355 100644 --- a/fs/script-tests/FileSystemFileHandle-move.js +++ b/fs/script-tests/FileSystemFileHandle-move.js @@ -138,15 +138,15 @@ directory_test(async (t, root) => { const dir_src = await root.getDirectoryHandle('dir-src', {create: true}); const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true}); const file = await createFileWithContents(t, 'file', 'abc', dir_src); - await file.move(dir_dest, ''); + await promise_rejects_js(t, TypeError, file.move(dir_dest, '')); assert_array_equals( await getSortedDirectoryEntries(root), ['dir-dest/', 'dir-src/']); - assert_array_equals(await getSortedDirectoryEntries(dir_src), []); - assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file']); + assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file']); + assert_array_equals(await getSortedDirectoryEntries(dir_dest), []); assert_equals(await getFileContents(file), 'abc'); assert_equals(await getFileSize(file), 3); -}, 'move(dir, "") to move a file to a new directory'); +}, 'move(dir, "") to move a file to a new directory fails'); directory_test(async (t, root) => { const dir_src = await root.getDirectoryHandle('dir-src', {create: true}); @@ -191,33 +191,6 @@ directory_test(async (t, root) => { assert_equals(await getFileContents(handle), 'foo'); }, 'move(dir) can be called multiple times'); -directory_test(async (t, root) => { - const dir1 = await root.getDirectoryHandle('dir1', {create: true}); - const dir2 = await root.getDirectoryHandle('dir2', {create: true}); - const handle = await createFileWithContents(t, 'file', 'foo', root); - - await handle.move(dir1, ""); - assert_array_equals( - await getSortedDirectoryEntries(root), ['dir1/', 'dir2/']); - assert_array_equals(await getSortedDirectoryEntries(dir1), ['file']); - assert_array_equals(await getSortedDirectoryEntries(dir2), []); - assert_equals(await getFileContents(handle), 'foo'); - - await handle.move(dir2, ""); - assert_array_equals( - await getSortedDirectoryEntries(root), ['dir1/', 'dir2/']); - assert_array_equals(await getSortedDirectoryEntries(dir1), []); - assert_array_equals(await getSortedDirectoryEntries(dir2), ['file']); - assert_equals(await getFileContents(handle), 'foo'); - - await handle.move(root, ""); - assert_array_equals( - await getSortedDirectoryEntries(root), ['dir1/', 'dir2/', 'file']); - assert_array_equals(await getSortedDirectoryEntries(dir1), []); - assert_array_equals(await getSortedDirectoryEntries(dir2), []); - assert_equals(await getFileContents(handle), 'foo'); -}, 'move(dir, "") can be called multiple times'); - directory_test(async (t, root) => { const dir1 = await root.getDirectoryHandle('dir1', {create: true}); const dir2 = await root.getDirectoryHandle('dir2', {create: true});