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 Sep 9, 2022
1 parent d2a2a57 commit 4b958f8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 87 deletions.
60 changes: 6 additions & 54 deletions file-system-access/script-tests/FileSystemDirectoryHandle-move.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,14 @@ directory_test(async (t, root) => {
const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true});
const dir_in_dir =
await dir_src.getDirectoryHandle('dir-in-dir', {create: true});
await dir_in_dir.move(dir_dest, "");
await dir_in_dir.move(dir_dest, '');

await promise_rejects_js(t, TypeError, dir_in_dir.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), ['dir-in-dir/']);
assert_array_equals(await getSortedDirectoryEntries(dir_in_dir), []);
}, 'move(dir, "") to move an empty directory to a new directory');
await getSortedDirectoryEntries(dir_src), ['dir-before/']);
assert_array_equals(await getSortedDirectoryEntries(dir_dest), []);
}, 'move(dir, "") to move a directory to a new directory fails');

directory_test(async (t, root) => {
const dir_src = await root.getDirectoryHandle('dir-src', {create: true});
Expand All @@ -75,26 +74,6 @@ directory_test(async (t, root) => {
assert_array_equals(await getSortedDirectoryEntries(dir_in_dir), []);
}, 'move(dir, name) to move an empty directory to a new directory');

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 dir_in_dir =
await dir_src.getDirectoryHandle('dir-in-dir', {create: true});
const file =
await createFileWithContents(t, 'file-in-dir', 'abc', dir_in_dir);
await dir_in_dir.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), ['dir-in-dir/']);
assert_array_equals(
await getSortedDirectoryEntries(dir_in_dir), ['file-in-dir']);
// `file` should be invalidated after moving directories.
await promise_rejects_dom(t, 'NotFoundError', getFileContents(file));
}, 'move(dir, "") to move a non-empty directory to a new directory');

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});
Expand Down Expand Up @@ -142,33 +121,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
37 changes: 4 additions & 33 deletions fs/script-tests/FileSystemFileHandle-move.js
Original file line number Diff line number Diff line change
Expand Up @@ -129,15 +129,13 @@ 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_equals(await getFileContents(file), 'abc');
assert_equals(await getFileSize(file), 3);
}, 'move(dir, "") to move a file to a new directory');
assert_array_equals(await getSortedDirectoryEntries(dir_dest), []);
}, '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 @@ -182,33 +180,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 4b958f8

Please sign in to comment.