@@ -94,14 +94,21 @@ directory_test(async (t, root) => {
94
94
await promise_rejects_dom (
95
95
t , 'NoModificationAllowedError' , handle . move ( 'file-after' ) ) ;
96
96
97
- // Can't move handle to overwrite an existing file.
98
97
await stream . close ( ) ;
99
- await promise_rejects_dom (
100
- t , 'InvalidModificationError' , handle . move ( 'file-after' ) ) ;
101
98
assert_array_equals (
102
99
await getSortedDirectoryEntries ( root ) , [ 'file-after' , 'file-before' ] ) ;
103
100
} , 'move(name) while the destination file has an open writable fails' ) ;
104
101
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' ) ;
105
112
106
113
directory_test ( async ( t , root ) => {
107
114
const handle = await createFileWithContents ( t , 'file-before' , 'foo' , root ) ;
@@ -290,13 +297,23 @@ directory_test(async (t, root) => {
290
297
// Assert the file is still in the source directory.
291
298
assert_array_equals ( await getSortedDirectoryEntries ( dir_src ) , [ 'file' ] ) ;
292
299
293
- // Can't move handle to overwrite an existing file.
294
300
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' ] ) ;
298
302
} , 'move(dir) while the destination file has an open writable fails' ) ;
299
303
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
+
300
317
directory_test ( async ( t , root ) => {
301
318
const dir_src = await root . getDirectoryHandle ( 'dir-src' , { create : true } ) ;
302
319
const dir_dest = await root . getDirectoryHandle ( 'dir-dest' , { create : true } ) ;
@@ -314,16 +331,26 @@ directory_test(async (t, root) => {
314
331
// Assert the file is still in the source directory.
315
332
assert_array_equals ( await getSortedDirectoryEntries ( dir_src ) , [ 'file-src' ] ) ;
316
333
317
- // Can't move handle to overwrite an existing file.
318
334
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' ] ) ;
325
336
} , 'move(dir, name) while the destination file has an open writable fails' ) ;
326
337
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
+
327
354
directory_test ( async ( t , root ) => {
328
355
const handle =
329
356
await createFileWithContents ( t , 'file-to-move' , '12345' , root ) ;
0 commit comments