File: FileSystemDirectoryHandle-removeEntry.js

package info (click to toggle)
firefox-esr 78.15.0esr-1~deb11u1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 3,301,156 kB
  • sloc: cpp: 5,665,905; javascript: 4,798,386; ansic: 2,878,233; python: 977,004; asm: 270,347; xml: 181,456; java: 111,756; sh: 72,926; makefile: 21,819; perl: 13,380; cs: 4,725; yacc: 4,565; objc: 3,026; pascal: 1,787; lex: 1,720; ada: 1,681; exp: 505; php: 436; lisp: 260; awk: 152; ruby: 103; csh: 80; sed: 53; sql: 45
file content (69 lines) | stat: -rw-r--r-- 2,967 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69

directory_test(async (t, root) => {
  const handle =
      await createFileWithContents(t, 'file-to-remove', '12345', root);
  await createFileWithContents(t, 'file-to-keep', 'abc', root);
  await root.removeEntry('file-to-remove');

  assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']);
  await promise_rejects_dom(t, 'NotFoundError', getFileContents(handle));
}, 'removeEntry() to remove a file');

directory_test(async (t, root) => {
  const handle =
      await createFileWithContents(t, 'file-to-remove', '12345', root);
  await root.removeEntry('file-to-remove');

  await promise_rejects_dom(t, 'NotFoundError', root.removeEntry('file-to-remove'));
}, 'removeEntry() on an already removed file should fail');

directory_test(async (t, root) => {
  const dir = await root.getDirectory('dir-to-remove', {create: true});
  await createFileWithContents(t, 'file-to-keep', 'abc', root);
  await root.removeEntry('dir-to-remove');

  assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']);
  await promise_rejects_dom(t, 'NotFoundError', getSortedDirectoryEntries(dir));
}, 'removeEntry() to remove an empty directory');

directory_test(async (t, root) => {
  const dir = await root.getDirectory('dir-to-remove', {create: true});
  t.add_cleanup(() => root.removeEntry('dir-to-remove', {recursive: true}));
  await createEmptyFile(t, 'file-in-dir', dir);

  await promise_rejects_dom(
      t, 'InvalidModificationError', root.removeEntry('dir-to-remove'));
  assert_array_equals(
      await getSortedDirectoryEntries(root), ['dir-to-remove/']);
  assert_array_equals(await getSortedDirectoryEntries(dir), ['file-in-dir']);
}, 'removeEntry() on a non-empty directory should fail');

directory_test(async (t, root) => {
  const dir = await createDirectory(t, 'dir', root);
  await promise_rejects_js(t, TypeError, dir.removeEntry(''));
}, 'removeEntry() with empty name should fail');

directory_test(async (t, root) => {
  const dir = await createDirectory(t, 'dir', root);
  await promise_rejects_js(t, TypeError, dir.removeEntry(kCurrentDirectory));
}, `removeEntry() with "${kCurrentDirectory}" name should fail`);

directory_test(async (t, root) => {
  const dir = await createDirectory(t, 'dir', root);
  await promise_rejects_js(t, TypeError, dir.removeEntry(kParentDirectory));
}, `removeEntry() with "${kParentDirectory}" name should fail`);

directory_test(async (t, root) => {
  const dir_name = 'dir-name';
  const dir = await createDirectory(t, dir_name, root);

  const file_name = 'file-name';
  await createEmptyFile(t, file_name, dir);

  for (let i = 0; i < kPathSeparators.length; ++i) {
    const path_with_separator = `${dir_name}${kPathSeparators[i]}${file_name}`;
    await promise_rejects_js(
        t, TypeError, root.removeEntry(path_with_separator),
        `removeEntry() must reject names containing "${kPathSeparators[i]}"`);
  }
}, 'removeEntry() with a path separator should fail.');