Skip to content

Commit 4b958f8

Browse files
a-sullychromium-wpt-export-bot
authored andcommitted
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 whatwg/fs#10 (comment) Bug: 1327741 Change-Id: Ifd8457df05aad7f75007ff5eece6237a09098a94
1 parent d2a2a57 commit 4b958f8

File tree

2 files changed

+10
-87
lines changed

2 files changed

+10
-87
lines changed

file-system-access/script-tests/FileSystemDirectoryHandle-move.js

Lines changed: 6 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,14 @@ directory_test(async (t, root) => {
5050
const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true});
5151
const dir_in_dir =
5252
await dir_src.getDirectoryHandle('dir-in-dir', {create: true});
53-
await dir_in_dir.move(dir_dest, "");
53+
await dir_in_dir.move(dir_dest, '');
54+
55+
await promise_rejects_js(t, TypeError, dir_in_dir.move(dir_dest, ''));
5456

5557
assert_array_equals(
56-
await getSortedDirectoryEntries(root), ['dir-dest/', 'dir-src/']);
57-
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
58-
assert_array_equals(
59-
await getSortedDirectoryEntries(dir_dest), ['dir-in-dir/']);
60-
assert_array_equals(await getSortedDirectoryEntries(dir_in_dir), []);
61-
}, 'move(dir, "") to move an empty directory to a new directory');
58+
await getSortedDirectoryEntries(dir_src), ['dir-before/']);
59+
assert_array_equals(await getSortedDirectoryEntries(dir_dest), []);
60+
}, 'move(dir, "") to move a directory to a new directory fails');
6261

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

78-
directory_test(async (t, root) => {
79-
const dir_src = await root.getDirectoryHandle('dir-src', {create: true});
80-
const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true});
81-
const dir_in_dir =
82-
await dir_src.getDirectoryHandle('dir-in-dir', {create: true});
83-
const file =
84-
await createFileWithContents(t, 'file-in-dir', 'abc', dir_in_dir);
85-
await dir_in_dir.move(dir_dest, "");
86-
87-
assert_array_equals(
88-
await getSortedDirectoryEntries(root), ['dir-dest/', 'dir-src/']);
89-
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
90-
assert_array_equals(
91-
await getSortedDirectoryEntries(dir_dest), ['dir-in-dir/']);
92-
assert_array_equals(
93-
await getSortedDirectoryEntries(dir_in_dir), ['file-in-dir']);
94-
// `file` should be invalidated after moving directories.
95-
await promise_rejects_dom(t, 'NotFoundError', getFileContents(file));
96-
}, 'move(dir, "") to move a non-empty directory to a new directory');
97-
9877
directory_test(async (t, root) => {
9978
const dir_src = await root.getDirectoryHandle('dir-src', {create: true});
10079
const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true});
@@ -142,33 +121,6 @@ directory_test(async (t, root) => {
142121
assert_equals(await getFileContents(handle), 'foo');
143122
}, 'move(dir) can be called multiple times');
144123

145-
directory_test(async (t, root) => {
146-
const dir1 = await root.getDirectoryHandle('dir1', {create: true});
147-
const dir2 = await root.getDirectoryHandle('dir2', {create: true});
148-
const handle = await createFileWithContents(t, 'file', 'foo', root);
149-
150-
await handle.move(dir1, "");
151-
assert_array_equals(
152-
await getSortedDirectoryEntries(root), ['dir1/', 'dir2/']);
153-
assert_array_equals(await getSortedDirectoryEntries(dir1), ['file']);
154-
assert_array_equals(await getSortedDirectoryEntries(dir2), []);
155-
assert_equals(await getFileContents(handle), 'foo');
156-
157-
await handle.move(dir2, "");
158-
assert_array_equals(
159-
await getSortedDirectoryEntries(root), ['dir1/', 'dir2/']);
160-
assert_array_equals(await getSortedDirectoryEntries(dir1), []);
161-
assert_array_equals(await getSortedDirectoryEntries(dir2), ['file']);
162-
assert_equals(await getFileContents(handle), 'foo');
163-
164-
await handle.move(root, "");
165-
assert_array_equals(
166-
await getSortedDirectoryEntries(root), ['dir1/', 'dir2/', 'file']);
167-
assert_array_equals(await getSortedDirectoryEntries(dir1), []);
168-
assert_array_equals(await getSortedDirectoryEntries(dir2), []);
169-
assert_equals(await getFileContents(handle), 'foo');
170-
}, 'move(dir, "") can be called multiple times');
171-
172124
directory_test(async (t, root) => {
173125
const dir1 = await root.getDirectoryHandle('dir1', {create: true});
174126
const dir2 = await root.getDirectoryHandle('dir2', {create: true});

fs/script-tests/FileSystemFileHandle-move.js

Lines changed: 4 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -129,15 +129,13 @@ directory_test(async (t, root) => {
129129
const dir_src = await root.getDirectoryHandle('dir-src', {create: true});
130130
const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true});
131131
const file = await createFileWithContents(t, 'file', 'abc', dir_src);
132-
await file.move(dir_dest, '');
132+
await promise_rejects_js(t, TypeError, file.move(dir_dest, ''));
133133

134-
assert_array_equals(
135-
await getSortedDirectoryEntries(root), ['dir-dest/', 'dir-src/']);
136-
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
137-
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file']);
134+
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file']);
138135
assert_equals(await getFileContents(file), 'abc');
139136
assert_equals(await getFileSize(file), 3);
140-
}, 'move(dir, "") to move a file to a new directory');
137+
assert_array_equals(await getSortedDirectoryEntries(dir_dest), []);
138+
}, 'move(dir, "") to move a file to a new directory fails');
141139

142140
directory_test(async (t, root) => {
143141
const dir_src = await root.getDirectoryHandle('dir-src', {create: true});
@@ -182,33 +180,6 @@ directory_test(async (t, root) => {
182180
assert_equals(await getFileContents(handle), 'foo');
183181
}, 'move(dir) can be called multiple times');
184182

185-
directory_test(async (t, root) => {
186-
const dir1 = await root.getDirectoryHandle('dir1', {create: true});
187-
const dir2 = await root.getDirectoryHandle('dir2', {create: true});
188-
const handle = await createFileWithContents(t, 'file', 'foo', root);
189-
190-
await handle.move(dir1, "");
191-
assert_array_equals(
192-
await getSortedDirectoryEntries(root), ['dir1/', 'dir2/']);
193-
assert_array_equals(await getSortedDirectoryEntries(dir1), ['file']);
194-
assert_array_equals(await getSortedDirectoryEntries(dir2), []);
195-
assert_equals(await getFileContents(handle), 'foo');
196-
197-
await handle.move(dir2, "");
198-
assert_array_equals(
199-
await getSortedDirectoryEntries(root), ['dir1/', 'dir2/']);
200-
assert_array_equals(await getSortedDirectoryEntries(dir1), []);
201-
assert_array_equals(await getSortedDirectoryEntries(dir2), ['file']);
202-
assert_equals(await getFileContents(handle), 'foo');
203-
204-
await handle.move(root, "");
205-
assert_array_equals(
206-
await getSortedDirectoryEntries(root), ['dir1/', 'dir2/', 'file']);
207-
assert_array_equals(await getSortedDirectoryEntries(dir1), []);
208-
assert_array_equals(await getSortedDirectoryEntries(dir2), []);
209-
assert_equals(await getFileContents(handle), 'foo');
210-
}, 'move(dir, "") can be called multiple times');
211-
212183
directory_test(async (t, root) => {
213184
const dir1 = await root.getDirectoryHandle('dir1', {create: true});
214185
const dir2 = await root.getDirectoryHandle('dir2', {create: true});

0 commit comments

Comments
 (0)