Skip to content

Commit

Permalink
FSA: Reject moves with empty names
Browse files Browse the repository at this point in the history
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 whatwg/fs#10 (comment)

Bug: 1327741
Change-Id: Ifd8457df05aad7f75007ff5eece6237a09098a94
  • Loading branch information
a-sully authored and chromium-wpt-export-bot committed Oct 13, 2022
1 parent 0d962f9 commit b8c24dc
Showing 1 changed file with 4 additions and 31 deletions.
35 changes: 4 additions & 31 deletions fs/script-tests/FileSystemFileHandle-move.js
Original file line number Diff line number Diff line change
Expand Up @@ -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});
Expand Down Expand Up @@ -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});
Expand Down

0 comments on commit b8c24dc

Please sign in to comment.