|
| 1 | +<!DOCTYPE html> |
| 2 | +<meta charset=utf-8> |
| 3 | +<title>Entries API: DataTransferItem.webkitGetAsEntry() with script-created DataTransfer</title> |
| 4 | +<link rel=help href="https://wicg.github.io/entries-api/#dom-datatransferitem-webkitgetasentry"> |
| 5 | +<link rel="author" title="Euclid Ye" href="mailto:yezhizhenjiakang@gmail.com"> |
| 6 | +<script src="/resources/testharness.js"></script> |
| 7 | +<script src="/resources/testharnessreport.js"></script> |
| 8 | + |
| 9 | +<script> |
| 10 | +test(t => { |
| 11 | + const dt = new DataTransfer(); |
| 12 | + dt.items.add('hello', 'text/plain'); |
| 13 | + const item = dt.items[0]; |
| 14 | + assert_equals(item.kind, 'string'); |
| 15 | + assert_equals(item.webkitGetAsEntry(), null, |
| 16 | + 'webkitGetAsEntry() should return null for non-File items'); |
| 17 | +}, 'webkitGetAsEntry() returns null for text items'); |
| 18 | + |
| 19 | +test(t => { |
| 20 | + const file = new File(['hello world'], 'test.txt', { type: 'text/plain' }); |
| 21 | + const dt = new DataTransfer(); |
| 22 | + dt.items.add(file); |
| 23 | + |
| 24 | + const item = dt.items[0]; |
| 25 | + assert_equals(item.kind, 'file'); |
| 26 | + |
| 27 | + const entry = item.webkitGetAsEntry(); |
| 28 | + assert_not_equals(entry, null); |
| 29 | + assert_true(entry.isFile); |
| 30 | + assert_false(entry.isDirectory); |
| 31 | + assert_equals(entry.name, 'test.txt'); |
| 32 | + assert_equals(entry.fullPath, '/test.txt'); |
| 33 | + assert_true(entry.filesystem instanceof FileSystem); |
| 34 | + assert_true(entry.filesystem.root.isDirectory); |
| 35 | +}, 'webkitGetAsEntry() returns FileSystemFileEntry with correct attributes'); |
| 36 | + |
| 37 | +async_test(t => { |
| 38 | + const file = new File(['hello world'], 'test.txt', { type: 'text/plain' }); |
| 39 | + const dt = new DataTransfer(); |
| 40 | + dt.items.add(file); |
| 41 | + |
| 42 | + const entry = dt.items[0].webkitGetAsEntry(); |
| 43 | + |
| 44 | + entry.file( |
| 45 | + t.step_func_done(f => { |
| 46 | + assert_class_string(f, 'File'); |
| 47 | + assert_equals(f.name, 'test.txt'); |
| 48 | + assert_equals(f.size, 11); |
| 49 | + }), |
| 50 | + t.unreached_func('file() should not invoke the error callback') |
| 51 | + ); |
| 52 | +}, 'FileSystemFileEntry.file() invokes callback with a File'); |
| 53 | +</script> |
0 commit comments