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 116 117 118 119 120 121 122 123 124 125 126 127 128
|
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: FileSystemDirectoryEntry.getDirectory() manual test</title>
<link rel=help href="https://wicg.github.io/entries-api/#dom-filesystemdirectoryentry-getdirectory">
<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, 'getDirectory', 'FileSystemDirectoryEntry has getDirectory');
assert_equals(typeof entry.getDirectory, 'function', 'getDirectory() is a method');
t.done();
}, 'FileSystemDirectoryEntry - getDirectory()');
INVALID_PATHS.forEach(path => {
entry_test((t, entry) => {
entry.getDirectory(
path,
{},
t.unreached_func('getDirectory should fail'),
t.step_func(error => {
assert_equals(error.name, 'TypeMismatchError',
'getDirectory() should fail if given invalid path');
t.done();
}));
}, 'FileSystemDirectoryEntry.getDirectory() - invalid path: ' + JSON.stringify(path));
});
EMPTY_PATHS.forEach(path => {
entry_test((t, entry) => {
entry.getDirectory(
path,
{},
t.step_func(dir => {
assert_true(dir.isDirectory,
'empty path should yield FileSystemDirectoryEntry');
assert_equals(dir.name, entry.name,
'empty path should yield same directory');
assert_equals(dir.fullPath, entry.fullPath,
'empty path should yield same directory');
t.done();
}),
t.unreached_func('getDirectory should not fail')
);
}, 'FileSystemDirectoryEntry.getDirectory() - empty path: '
+ JSON.stringify(path) || 'undefined');
});
DIR_PATHS.forEach(path => {
entry_test((t, entry) => {
entry.getDirectory(
path,
{create: true},
t.unreached_func('getDirectory should fail'),
t.step_func(error => {
assert_equals(error.name, 'SecurityError',
'getDirectory() should fail with security error if ' +
'create option is set');
t.done();
}));
}, 'FileSystemDirectoryEntry.getDirectory() - {create:true}: ' + path);
});
NOT_FOUND_PATHS.forEach(path => {
entry_test((t, entry) => {
entry.getDirectory(
path,
{},
t.unreached_func('getDirectory should fail'),
t.step_func(error => {
assert_equals(error.name, 'NotFoundError',
'getDirectory() should fail with not found');
t.done();
}));
}, 'FileSystemDirectoryEntry.getDirectory() - not found: ' + path);
});
FILE_PATHS.forEach(path => {
entry_test((t, entry) => {
entry.getDirectory(
path,
{},
t.unreached_func('getDirectory should fail'),
t.step_func(error => {
assert_equals(error.name, 'TypeMismatchError',
'getDirectory() should fail if type is file');
t.done();
}));
}, 'FileSystemDirectoryEntry.getDirectory() - directory: ' + path);
});
DIR_PATHS.forEach(path => {
entry_test((t, entry) => {
entry.getDirectory(
path,
{},
t.step_func(e => {
assert_false(e.isFile);
assert_true(e.isDirectory);
assert_equals(e.name, 'subdir');
t.done();
}),
t.unreached_func('getDirectory should not fail')
);
}, 'FileSystemDirectoryEntry.getDirectory() - directory: ' + path);
});
[
{path: '.', name: 'upload'},
{path: '/', name: ''}
].forEach(test_case => {
entry_test((t, entry) => {
entry.getDirectory(
test_case.path,
{},
t.step_func(e => {
assert_false(e.isFile);
assert_true(e.isDirectory);
assert_equals(e.name, test_case.name);
t.done();
}),
t.unreached_func('getDirectory should not fail')
);
}, 'FileSystemDirectoryEntry.getDirectory() - directory: ' + test_case.path);
});
</script>
|