|
1 | 1 | 'use strict';
|
2 | 2 |
|
| 3 | +directory_test(async (t, root) => { |
| 4 | + const handle = |
| 5 | + await createFileWithContents(t, 'file-to-remove', '12345', root); |
| 6 | + await createFileWithContents(t, 'file-to-keep', 'abc', root); |
| 7 | + await root.removeEntry('file-to-remove'); |
| 8 | + |
| 9 | + assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']); |
| 10 | + await promise_rejects_dom(t, 'NotFoundError', getFileContents(handle)); |
| 11 | +}, 'removeEntry() to remove a file'); |
| 12 | + |
| 13 | +directory_test(async (t, root) => { |
| 14 | + const handle = |
| 15 | + await createFileWithContents(t, 'file-to-remove', '12345', root); |
| 16 | + await root.removeEntry('file-to-remove'); |
| 17 | + |
| 18 | + await promise_rejects_dom( |
| 19 | + t, 'NotFoundError', root.removeEntry('file-to-remove')); |
| 20 | +}, 'removeEntry() on an already removed file should fail'); |
| 21 | + |
| 22 | +directory_test(async (t, root) => { |
| 23 | + const dir = await root.getDirectoryHandle('dir-to-remove', {create: true}); |
| 24 | + await createFileWithContents(t, 'file-to-keep', 'abc', root); |
| 25 | + await root.removeEntry('dir-to-remove'); |
| 26 | + |
| 27 | + assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']); |
| 28 | +}, 'removeEntry() to remove an empty directory'); |
| 29 | + |
| 30 | +directory_test(async (t, root) => { |
| 31 | + const dir = await createDirectory(t, 'dir-to-remove', root); |
| 32 | + await createFileWithContents(t, 'file-in-dir', 'abc', dir); |
| 33 | + |
| 34 | + await promise_rejects_dom( |
| 35 | + t, 'InvalidModificationError', root.removeEntry('dir-to-remove')); |
| 36 | + assert_array_equals( |
| 37 | + await getSortedDirectoryEntries(root), ['dir-to-remove/']); |
| 38 | + assert_array_equals(await getSortedDirectoryEntries(dir), ['file-in-dir']); |
| 39 | +}, 'removeEntry() on a non-empty directory should fail'); |
| 40 | + |
| 41 | +directory_test(async (t, root) => { |
| 42 | + // root |
| 43 | + // ├──file-to-keep |
| 44 | + // ├──dir-to-remove |
| 45 | + // ├── file0 |
| 46 | + // ├── dir1-in-dir |
| 47 | + // │ └── file1 |
| 48 | + // └── dir2 |
| 49 | + const dir = await root.getDirectoryHandle('dir-to-remove', {create: true}); |
| 50 | + await createFileWithContents(t, 'file-to-keep', 'abc', root); |
| 51 | + await createEmptyFile(t, 'file0', dir); |
| 52 | + const dir1_in_dir = await createDirectory(t, 'dir1-in-dir', dir); |
| 53 | + await createEmptyFile(t, 'file1', dir1_in_dir); |
| 54 | + await createDirectory(t, 'dir2-in-dir', dir); |
| 55 | + |
| 56 | + await root.removeEntry('dir-to-remove', {recursive: true}); |
| 57 | + assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']); |
| 58 | +}, 'removeEntry() on a directory recursively should delete all sub-items'); |
| 59 | + |
| 60 | +directory_test(async (t, root) => { |
| 61 | + const dir = await createDirectory(t, 'dir', root); |
| 62 | + await promise_rejects_js(t, TypeError, dir.removeEntry('')); |
| 63 | +}, 'removeEntry() with empty name should fail'); |
| 64 | + |
| 65 | +directory_test(async (t, root) => { |
| 66 | + const dir = await createDirectory(t, 'dir', root); |
| 67 | + await promise_rejects_js(t, TypeError, dir.removeEntry(kCurrentDirectory)); |
| 68 | +}, `removeEntry() with "${kCurrentDirectory}" name should fail`); |
| 69 | + |
| 70 | +directory_test(async (t, root) => { |
| 71 | + const dir = await createDirectory(t, 'dir', root); |
| 72 | + await promise_rejects_js(t, TypeError, dir.removeEntry(kParentDirectory)); |
| 73 | +}, `removeEntry() with "${kParentDirectory}" name should fail`); |
| 74 | + |
| 75 | +directory_test(async (t, root) => { |
| 76 | + const dir_name = 'dir-name'; |
| 77 | + const dir = await createDirectory(t, dir_name, root); |
| 78 | + |
| 79 | + const file_name = 'file-name'; |
| 80 | + await createEmptyFile(t, file_name, dir); |
| 81 | + |
| 82 | + for (let i = 0; i < kPathSeparators.length; ++i) { |
| 83 | + const path_with_separator = `${dir_name}${kPathSeparators[i]}${file_name}`; |
| 84 | + await promise_rejects_js( |
| 85 | + t, TypeError, root.removeEntry(path_with_separator), |
| 86 | + `removeEntry() must reject names containing "${kPathSeparators[i]}"`); |
| 87 | + } |
| 88 | +}, 'removeEntry() with a path separator should fail.'); |
| 89 | + |
3 | 90 | directory_test(async (t, root) => {
|
4 | 91 | const handle =
|
5 | 92 | await createFileWithContents(t, 'file-to-remove', '12345', root);
|
6 | 93 | await createFileWithContents(t, 'file-to-keep', 'abc', root);
|
7 | 94 |
|
8 | 95 | const writable = await cleanup_writable(t, await handle.createWritable());
|
9 | 96 | await promise_rejects_dom(
|
10 |
| - t, 'InvalidModificationError', root.removeEntry('file-to-remove')); |
| 97 | + t, 'NoModificationAllowedError', root.removeEntry('file-to-remove')); |
11 | 98 |
|
12 | 99 | await writable.close();
|
13 | 100 | await root.removeEntry('file-to-remove');
|
14 | 101 |
|
15 |
| - assert_array_equals( |
16 |
| - await getSortedDirectoryEntries(root), |
17 |
| - ['file-to-keep']); |
| 102 | + assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']); |
18 | 103 | }, 'removeEntry() while the file has an open writable fails');
|
| 104 | + |
| 105 | +directory_test(async (t, root) => { |
| 106 | + const dir_name = 'dir-name'; |
| 107 | + const dir = await createDirectory(t, dir_name, root); |
| 108 | + |
| 109 | + const handle = |
| 110 | + await createFileWithContents(t, 'file-to-remove', '12345', dir); |
| 111 | + await createFileWithContents(t, 'file-to-keep', 'abc', dir); |
| 112 | + |
| 113 | + const writable = await cleanup_writable(t, await handle.createWritable()); |
| 114 | + await promise_rejects_dom( |
| 115 | + t, 'NoModificationAllowedError', root.removeEntry(dir_name)); |
| 116 | + |
| 117 | + await writable.close(); |
| 118 | + assert_array_equals( |
| 119 | + await getSortedDirectoryEntries(dir), ['file-to-keep', 'file-to-remove']); |
| 120 | + |
| 121 | + await dir.removeEntry('file-to-remove'); |
| 122 | + assert_array_equals(await getSortedDirectoryEntries(dir), ['file-to-keep']); |
| 123 | +}, 'removeEntry() of a directory while a containing file has an open writable fails'); |
0 commit comments