Skip to content

Commit 5eb5d6f

Browse files
a-sullymoz-wptsync-bot
authored andcommitted
Bug 1804109 [wpt PR 37309] - FSA: Make WPTs assert that overwriting file moves are allowed, a=testonly
Automatic update from web-platform-tests FSA: Make WPTs assert that overwriting file moves are allowed This codifies the behavior agreed upon here: whatwg/fs#10 (comment) See go/fsa-overwriting-moves for more context Bug: 1366652, 1381621 Change-Id: I24d8ff94ebd9f6b6a8f2ffe9a0e30623193e7eab Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4076968 Auto-Submit: Austin Sullivan <asully@chromium.org> Reviewed-by: Daseul Lee <dslee@chromium.org> Commit-Queue: Daseul Lee <dslee@chromium.org> Cr-Commit-Position: refs/heads/main@{#1079294} -- wpt-commits: ff43fc72820d7c82f5a3383a466a80ca64a6bb05 wpt-pr: 37309
1 parent 456b05a commit 5eb5d6f

File tree

1 file changed

+41
-14
lines changed

1 file changed

+41
-14
lines changed

testing/web-platform/tests/fs/script-tests/FileSystemFileHandle-move.js

Lines changed: 41 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,21 @@ directory_test(async (t, root) => {
9494
await promise_rejects_dom(
9595
t, 'NoModificationAllowedError', handle.move('file-after'));
9696

97-
// Can't move handle to overwrite an existing file.
9897
await stream.close();
99-
await promise_rejects_dom(
100-
t, 'InvalidModificationError', handle.move('file-after'));
10198
assert_array_equals(
10299
await getSortedDirectoryEntries(root), ['file-after', 'file-before']);
103100
}, 'move(name) while the destination file has an open writable fails');
104101

102+
directory_test(async (t, root) => {
103+
const handle = await createFileWithContents(t, 'file-before', 'abc', root);
104+
const handle_dest =
105+
await createFileWithContents(t, 'file-after', '123', root);
106+
107+
await handle.move('file-after');
108+
assert_array_equals(await getSortedDirectoryEntries(root), ['file-after']);
109+
assert_equals(await getFileContents(handle), 'abc');
110+
assert_equals(await getFileContents(handle_dest), 'abc');
111+
}, 'move(name) can overwrite an existing file');
105112

106113
directory_test(async (t, root) => {
107114
const handle = await createFileWithContents(t, 'file-before', 'foo', root);
@@ -290,13 +297,23 @@ directory_test(async (t, root) => {
290297
// Assert the file is still in the source directory.
291298
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file']);
292299

293-
// Can't move handle to overwrite an existing file.
294300
await stream.close();
295-
await promise_rejects_dom(
296-
t, 'InvalidModificationError', file.move(dir_dest));
297-
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file']);
301+
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file']);
298302
}, 'move(dir) while the destination file has an open writable fails');
299303

304+
directory_test(async (t, root) => {
305+
const dir_src = await root.getDirectoryHandle('dir-src', {create: true});
306+
const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true});
307+
const file = await createFileWithContents(t, 'file', 'abc', dir_src);
308+
const file_dest = await createFileWithContents(t, 'file', '123', dir_dest);
309+
310+
await file.move(dir_dest);
311+
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
312+
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file']);
313+
assert_equals(await getFileContents(file), 'abc');
314+
assert_equals(await getFileContents(file_dest), 'abc');
315+
}, 'move(dir) can overwrite an existing file');
316+
300317
directory_test(async (t, root) => {
301318
const dir_src = await root.getDirectoryHandle('dir-src', {create: true});
302319
const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true});
@@ -314,16 +331,26 @@ directory_test(async (t, root) => {
314331
// Assert the file is still in the source directory.
315332
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file-src']);
316333

317-
// Can't move handle to overwrite an existing file.
318334
await stream.close();
319-
await promise_rejects_dom(
320-
t, 'InvalidModificationError', file.move(dir_dest, 'file-dest'));
321-
// Assert the file is still in the source directory.
322-
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file-src']);
323-
assert_equals(await getFileContents(file), 'abc');
324-
assert_equals(await getFileSize(file), 3);
335+
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file-dest']);
325336
}, 'move(dir, name) while the destination file has an open writable fails');
326337

338+
directory_test(async (t, root) => {
339+
const dir_src = await root.getDirectoryHandle('dir-src', {create: true});
340+
const dir_dest = await root.getDirectoryHandle('dir-dest', {create: true});
341+
const file = await createFileWithContents(t, 'file-src', 'abc', dir_src);
342+
const file_dest =
343+
await createFileWithContents(t, 'file-dest', '123', dir_dest);
344+
345+
await file.move(dir_dest, 'file-dest');
346+
347+
// Assert the file has been moved to the destination directory and renamed.
348+
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
349+
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file-dest']);
350+
assert_equals(await getFileContents(file), 'abc');
351+
assert_equals(await getFileContents(file_dest), 'abc');
352+
}, 'move(dir, name) can overwrite an existing file');
353+
327354
directory_test(async (t, root) => {
328355
const handle =
329356
await createFileWithContents(t, 'file-to-move', '12345', root);

0 commit comments

Comments
 (0)