@@ -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
106113directory_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+
300317directory_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+
327354directory_test ( async ( t , root ) => {
328355 const handle =
329356 await createFileWithContents ( t , 'file-to-move' , '12345' , root ) ;
0 commit comments