Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test has a WPT meta file that expects 1 subtest issues.
- This WPT test may be referenced by the following Test IDs:
- /entries-api/webkitGetAsEntry.html - WPT Dashboard Interop Dashboard
<!DOCTYPE html>
<meta charset=utf-8>
<title>Entries API: DataTransferItem.webkitGetAsEntry() with script-created DataTransfer</title>
<link rel="author" title="Euclid Ye" href="mailto:yezhizhenjiakang@gmail.com">
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="automated-support.js"></script>
<script>
test(t => {
const dt = new DataTransfer();
dt.items.add('hello', 'text/plain');
const item = dt.items[0];
assert_equals(item.kind, 'string');
assert_equals(item.webkitGetAsEntry(), null,
'webkitGetAsEntry() should return null for non-File items');
}, 'webkitGetAsEntry() returns null for text items');
test(t => {
const item = createDataTransferItem();
assert_equals(item.kind, 'file');
const entry = item.webkitGetAsEntry();
assert_not_equals(entry, null);
assert_true(entry.isFile);
assert_false(entry.isDirectory);
assert_equals(entry.name, 'test.txt');
assert_equals(entry.fullPath, '/test.txt');
assert_true(entry.filesystem instanceof FileSystem);
assert_true(entry.filesystem.root.isDirectory);
}, 'webkitGetAsEntry() returns FileSystemFileEntry with correct attributes');
async_test(t => {
const entry = createFileEntry();
entry.file(
t.step_func_done(f => {
assert_class_string(f, 'File');
assert_equals(f.name, 'test.txt');
assert_equals(f.size, 11);
}),
t.unreached_func('file() should not invoke the error callback')
);
}, 'FileSystemFileEntry.file() invokes callback with a File');
promise_test(async () => {
const names = ['a.txt', 'b.txt', 'c.txt'];
const dt = new DataTransfer();
for (const name of names)
dt.items.add(new File(['hello'], name));
const entries = names.map((_, i) => dt.items[i].webkitGetAsEntry());
for (let i = 0; i < entries.length; i++) {
assert_true(entries[i].isFile, 'item ' + i + ' should yield a file entry');
assert_equals(entries[i].name, names[i]);
assert_equals(entries[i].fullPath, '/' + names[i]);
}
assert_not_equals(dt.items[0].webkitGetAsEntry(), entries[0],
'each call returns a new entry object');
const children = await readAll(entries[0].filesystem.root.createReader());
assert_equals(children.length, names.length);
assert_array_equals(children.map(entry => entry.name), names);
}, 'webkitGetAsEntry() places every file item under the drag data store root');
</script>