Skip to content

Commit

Permalink
Bug 1804109 [wpt PR 37309] - FSA: Make WPTs assert that overwriting f…
Browse files Browse the repository at this point in the history
…ile 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 <[email protected]>
Reviewed-by: Daseul Lee <[email protected]>
Commit-Queue: Daseul Lee <[email protected]>
Cr-Commit-Position: refs/heads/main@{#1079294}

--

wpt-commits: ff43fc72820d7c82f5a3383a466a80ca64a6bb05
wpt-pr: 37309
  • Loading branch information
a-sully authored and moz-wptsync-bot committed Dec 11, 2022
1 parent f3ca124 commit 93b9a67
Showing 1 changed file with 41 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,14 +94,21 @@ directory_test(async (t, root) => {
await promise_rejects_dom(
t, 'NoModificationAllowedError', handle.move('file-after'));

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

directory_test(async (t, root) => {
const handle = await createFileWithContents(t, 'file-before', 'abc', root);
const handle_dest =
await createFileWithContents(t, 'file-after', '123', root);

await handle.move('file-after');
assert_array_equals(await getSortedDirectoryEntries(root), ['file-after']);
assert_equals(await getFileContents(handle), 'abc');
assert_equals(await getFileContents(handle_dest), 'abc');
}, 'move(name) can overwrite an existing file');

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

// Can't move handle to overwrite an existing file.
await stream.close();
await promise_rejects_dom(
t, 'InvalidModificationError', file.move(dir_dest));
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file']);
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file']);
}, 'move(dir) while the destination file has an open writable fails');

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);
const file_dest = await createFileWithContents(t, 'file', '123', dir_dest);

await file.move(dir_dest);
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file']);
assert_equals(await getFileContents(file), 'abc');
assert_equals(await getFileContents(file_dest), 'abc');
}, 'move(dir) can overwrite an existing file');

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 All @@ -314,16 +331,26 @@ directory_test(async (t, root) => {
// Assert the file is still in the source directory.
assert_array_equals(await getSortedDirectoryEntries(dir_src), ['file-src']);

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

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-src', 'abc', dir_src);
const file_dest =
await createFileWithContents(t, 'file-dest', '123', dir_dest);

await file.move(dir_dest, 'file-dest');

// Assert the file has been moved to the destination directory and renamed.
assert_array_equals(await getSortedDirectoryEntries(dir_src), []);
assert_array_equals(await getSortedDirectoryEntries(dir_dest), ['file-dest']);
assert_equals(await getFileContents(file), 'abc');
assert_equals(await getFileContents(file_dest), 'abc');
}, 'move(dir, name) can overwrite an existing file');

directory_test(async (t, root) => {
const handle =
await createFileWithContents(t, 'file-to-move', '12345', root);
Expand Down

0 comments on commit 93b9a67

Please sign in to comment.