summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/entries-api/filesystemdirectoryentry-getFile-manual.html
blob: 3acd2fbd763b013150d92afb63184690bb4db4d6 (plain)
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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemDirectoryEntry.getFile() manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getfile">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="support.js"></script>

<script>
entry_test((t, entry) => {
  assert_idl_attribute(entry, 'getFile', 'FileSystemDirectoryEntry has getFile');
  assert_equals(typeof entry.getFile, 'function', 'getFile() is a method');

  t.done();
}, 'FileSystemDirectoryEntry - getFile()');

INVALID_PATHS.forEach(path => {
  entry_test((t, entry) => {
    entry.getFile(
      path,
      {},
      t.unreached_func('getFile should fail'),
      t.step_func(error => {
        assert_equals(error.name, 'TypeMismatchError',
                      'getFile() should fail if given invalid path');
        t.done();
      }));
  }, 'FileSystemDirectoryEntry.getFile() - invalid path: ' + JSON.stringify(path));
});

EMPTY_PATHS.forEach(path => {
  entry_test((t, entry) => {
    entry.getFile(
      path,
      {},
      t.unreached_func('getFile should fail'),
      t.step_func(error => {
        assert_equals(error.name, 'TypeMismatchError',
                      'getFile() on empty path should fail because the ' +
                      'path resolves to the directory itself');
        t.done();
      }));
  }, 'FileSystemDirectoryEntry.getFile() - empty path: ' + JSON.stringify(path) || 'undefined');
});

FILE_PATHS.forEach(path => {
  entry_test((t, entry) => {
    entry.getFile(
      path,
      {create: true},
      t.unreached_func('getFile should fail'),
      t.step_func(error => {
        assert_equals(error.name, 'SecurityError',
                      'getFile() should fail with security error if ' +
                      'create option is set');
        t.done();
      }));
  }, 'FileSystemDirectoryEntry.getFile() - {create:true}: ' + path);
});

NOT_FOUND_PATHS.forEach(path => {
  entry_test((t, entry) => {
    entry.getFile(
      path,
      {},
      t.unreached_func('getFile should fail'),
      t.step_func(error => {
        assert_equals(error.name, 'NotFoundError',
                      'getFile() should fail with not found');
        t.done();
      }));
  }, 'FileSystemDirectoryEntry.getFile() - not found: ' + path);
});

DIR_PATHS.concat(['/', '.']).forEach(path => {
  entry_test((t, entry) => {
    entry.getFile(
      path,
      {},
      t.unreached_func('getFile should fail'),
      t.step_func(error => {
        assert_equals(error.name, 'TypeMismatchError',
                      'getFile() should fail if type is directory');
        t.done();
      }));
  }, 'FileSystemDirectoryEntry.getFile() - directory: ' + path);
});

FILE_PATHS.forEach(path => {
  entry_test((t, entry) => {
    entry.getFile(
      path,
      {},
      t.step_func(e => {
        assert_true(e.isFile);
        assert_false(e.isDirectory);
        assert_equals(e.name, 'file.txt');
        t.done();
      }),
      t.unreached_func('getFile should not fail')
    );
  }, 'FileSystemDirectoryEntry.getFile() - file: ' + path);
});

entry_test((t, entry) => {
  entry.getFile(FILE_PATHS[0], {}, t.step_func(e1 => {
    entry.getFile(FILE_PATHS[0], {}, t.step_func(e2 => {
      assert_equals(e1.name, e2.name, 'names should match');
      assert_equals(e1.fullPath, e2.fullPath, 'names should match');
      assert_not_equals(e1, e2, 'objects should be distinct');
      t.done();
    }), t.unreached_func('getFile should not fail'));
  }), t.unreached_func('getFile should not fail'));
}, 'FileSystemDirectoryEntry.getFile() - object identity');
</script>