aboutsummaryrefslogtreecommitdiffstats
path: root/tests/wpt/web-platform-tests/native-file-system/FileSystemBaseHandle-remove.tentative.window.js
blob: 33ac96038829b249312f7463fc5c072b9f805825 (plain) (blame)
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
// META: script=resources/test-helpers.js
promise_test(async t => cleanupSandboxedFileSystem(),
    'Cleanup to setup test environment');

promise_test(async t => {
    const handle = await createFileWithContents(t, 'file-to-remove', '12345');
    const dir = await handle.getParent();
    await createFileWithContents(t, 'file-to-keep', 'abc');
    await handle.remove();

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

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

    await promise_rejects(t, 'NotFoundError', handle.remove());
}, 'remove() on an already removed file should fail');

promise_test(async t => {
    const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
    const dir = await root.getDirectory('dir-to-remove', { create: true });
    await createFileWithContents(t, 'file-to-keep', 'abc');
    await dir.remove();

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

promise_test(async t => {
    const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
    const dir = await root.getDirectory('dir-to-remove', { create: true });
    t.add_cleanup(() => dir.removeRecursively());
    await createEmptyFile(t, 'file-in-dir', dir);

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