mirror of
https://github.com/servo/servo.git
synced 2025-09-03 11:38:22 +01:00
Update web-platform-tests to revision 8a2ceb5f18911302b7a5c1cd2791f4ab50ad4326
This commit is contained in:
parent
462c272380
commit
1f531f66ea
5377 changed files with 174916 additions and 84369 deletions
2
tests/wpt/web-platform-tests/entries-api/OWNERS
Normal file
2
tests/wpt/web-platform-tests/entries-api/OWNERS
Normal file
|
@ -0,0 +1,2 @@
|
|||
@aliams
|
||||
@inexorabletash
|
61
tests/wpt/web-platform-tests/entries-api/errors-manual.html
Normal file
61
tests/wpt/web-platform-tests/entries-api/errors-manual.html
Normal file
|
@ -0,0 +1,61 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: Errors manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="support.js"></script>
|
||||
|
||||
<script>
|
||||
entry_test((t, entry) => {
|
||||
entry.getFile(
|
||||
NOT_FOUND_PATHS[0],
|
||||
{},
|
||||
t.unreached_func('getFile should fail'),
|
||||
t.step_func(error => {
|
||||
assert_equals(typeof error.name, 'string', 'Error has name property');
|
||||
assert_equals(typeof error.message, 'string', 'Error has message property');
|
||||
assert_equals(error.name, 'NotFoundError', 'error is NotFoundError');
|
||||
t.done();
|
||||
}));
|
||||
}, 'Errors - NotFoundError');
|
||||
|
||||
entry_test((t, entry) => {
|
||||
entry.getFile(
|
||||
DIR_PATHS[0],
|
||||
{},
|
||||
t.unreached_func('getFile should fail'),
|
||||
t.step_func(error => {
|
||||
assert_equals(typeof error.name, 'string', 'Error has name property');
|
||||
assert_equals(typeof error.message, 'string', 'Error has message property');
|
||||
assert_equals(error.name, 'TypeMismatchError', 'error is TypeMismatchError');
|
||||
t.done();
|
||||
}));
|
||||
}, 'Errors - TypeMismatchError');
|
||||
|
||||
entry_test((t, entry) => {
|
||||
entry.getFile(
|
||||
FILE_PATHS[0],
|
||||
{create: true},
|
||||
t.unreached_func('getFile should fail'),
|
||||
t.step_func(error => {
|
||||
assert_equals(typeof error.name, 'string', 'Error has name property');
|
||||
assert_equals(typeof error.message, 'string', 'Error has message property');
|
||||
assert_equals(error.name, 'SecurityError', 'error is SecurityError');
|
||||
t.done();
|
||||
}));
|
||||
}, 'Errors - SecurityError');
|
||||
|
||||
entry_test((t, entry) => {
|
||||
const reader = entry.createReader();
|
||||
reader.readEntries(() => {}, t.unreached_func('readEntries should succeed'));
|
||||
reader.readEntries(
|
||||
t.unreached_func('readEntries() should fail if already reading'),
|
||||
t.step_func(error => {
|
||||
assert_equals(typeof error.name, 'string', 'Error has name property');
|
||||
assert_equals(typeof error.message, 'string', 'Error has message property');
|
||||
assert_equals(error.name, 'InvalidStateError', 'error is InvalidStateError');
|
||||
t.done();
|
||||
}));
|
||||
}, 'Errors - InvalidStateError');
|
||||
</script>
|
|
@ -0,0 +1,32 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: File webitRelativePath manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#file-interface">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
|
||||
Select the <b>support/a</b> directory:
|
||||
|
||||
<input type=file multiple webkitdirectory>
|
||||
|
||||
<script>
|
||||
setup({explicit_timeout: true});
|
||||
|
||||
const filesPromise = new Promise(resolve => {
|
||||
const elem = document.querySelector('input[type=file]');
|
||||
elem.addEventListener('change', e => resolve(elem.files));
|
||||
});
|
||||
|
||||
promise_test(t => filesPromise.then(files => {
|
||||
assert_equals(files.length, 3, 'expected 3 items');
|
||||
files = Array.from(files).sort(
|
||||
(a, b) => a.name < b.name ? -1 : b.name < a.name ? 1 : 0);
|
||||
assert_equals(files[0].name, '1.txt');
|
||||
assert_equals(files[1].name, '2.txt');
|
||||
assert_equals(files[0].webkitRelativePath, 'c/d/1.txt');
|
||||
assert_equals(files[1].webkitRelativePath, 'c/d/2.txt');
|
||||
assert_equals(files[2].webkitRelativePath, 'c/3.txt');
|
||||
|
||||
}), 'webkitRelativePath is shortest common ancestor');
|
||||
|
||||
</script>
|
|
@ -0,0 +1,40 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystem manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-domfilesystem">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="support.js"></script>
|
||||
|
||||
<script>
|
||||
entry_test((t, entry) => {
|
||||
const fs = entry.filesystem;
|
||||
|
||||
assert_idl_attribute(fs, 'name', 'has name attribute');
|
||||
assert_equals(typeof fs.name, 'string', 'name is a string');
|
||||
|
||||
assert_idl_attribute(fs, 'root', 'has root attribute');
|
||||
assert_true(fs.root.isDirectory,
|
||||
'FileSystem root is a directory entry');
|
||||
|
||||
assert_equals(fs.root.name, '', 'root name is empty string');
|
||||
|
||||
assert_equals(fs.root.fullPath, '/', 'root path is /');
|
||||
|
||||
t.done();
|
||||
|
||||
}, 'FileSystem - API');
|
||||
|
||||
entry_test((t, entry) => {
|
||||
const fs = entry.filesystem;
|
||||
|
||||
getChildEntry(entry, 'file.txt', t.step_func(child => {
|
||||
const cfs = child.filesystem;
|
||||
assert_not_equals(fs, cfs.filesystem, 'FileSystem objects do not have object identity');
|
||||
assert_equals(fs.name, cfs.name, 'FileSystem names match');
|
||||
|
||||
t.done();
|
||||
}), t.unreached_func('child entry file.txt should be present'));
|
||||
|
||||
}, 'FileSystem - name consistency and object identity');
|
||||
</script>
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemDirectoryEntry attributes manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-directoryentry">
|
||||
<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, 'isFile', 'FileSystemDirectoryEntry has isFile attribute');
|
||||
assert_equals(typeof entry.isFile, 'boolean', 'isFile is boolean');
|
||||
|
||||
assert_idl_attribute(entry, 'isDirectory', 'FileSystemDirectoryEntry has isDirectory attribute');
|
||||
assert_equals(typeof entry.isDirectory, 'boolean', 'isDirectory is boolean');
|
||||
|
||||
assert_idl_attribute(entry, 'name', 'FileSystemDirectoryEntry has name attribute');
|
||||
assert_equals(typeof entry.name, 'string', 'name is a string');
|
||||
|
||||
assert_idl_attribute(entry, 'fullPath', 'FileSystemDirectoryEntry has fullPath attribute');
|
||||
assert_equals(typeof entry.fullPath, 'string', 'fullPath is a string');
|
||||
|
||||
assert_idl_attribute(entry, 'filesystem', 'FileSystemDirectoryEntry has filesystem attribute');
|
||||
assert_equals(typeof entry.filesystem, 'object', 'filesystem is an object');
|
||||
|
||||
t.done();
|
||||
}, 'FileSystemDirectoryEntry - attribute types');
|
||||
|
||||
entry_test((t, entry) => {
|
||||
assert_false(entry.isFile, 'isFile is false');
|
||||
assert_true(entry.isDirectory, 'isDirectory is true');
|
||||
assert_equals(entry.name, 'upload', 'expected directory was uploaded');
|
||||
assert_equals(entry.fullPath, '/upload', 'directory is child of root directory');
|
||||
t.done();
|
||||
}, 'FileSystemDirectoryEntry - attribute values');
|
||||
|
||||
</script>
|
|
@ -0,0 +1,23 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemDirectoryEntry createReader() manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-directoryentry">
|
||||
<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, 'createReader', 'FileSystemDirectoryEntry has createReader');
|
||||
assert_equals(typeof entry.createReader, 'function', 'createReader() is a method');
|
||||
|
||||
t.done();
|
||||
}, 'FileSystemDirectoryEntry - createReader()');
|
||||
|
||||
entry_test((t, entry) => {
|
||||
assert_not_equals(entry.createReader(), entry.createReader(),
|
||||
'createReader() returns a new object each time');
|
||||
t.done();
|
||||
}, 'FileSystemDirectoryEntry - createReader() distinct objects');
|
||||
</script>
|
|
@ -0,0 +1,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>
|
|
@ -0,0 +1,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>
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemDirectoryEntry getParent() manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-directoryentry">
|
||||
<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, 'getParent', 'FileSystemDirectoryEntry has getParent');
|
||||
assert_equals(typeof entry.getParent, 'function', 'getParent() is a method');
|
||||
|
||||
t.done();
|
||||
}, 'FileSystemDirectoryEntry - getParent()');
|
||||
</script>
|
|
@ -0,0 +1,77 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemDirectoryReader manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-directoryreader">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="support.js"></script>
|
||||
|
||||
<script>
|
||||
entry_test((t, entry) => {
|
||||
const reader = entry.createReader();
|
||||
|
||||
assert_idl_attribute(reader, 'readEntries', 'FileSystemDirectoryReader has readEntries');
|
||||
assert_equals(typeof reader.readEntries, 'function', 'readEntries() is a method');
|
||||
|
||||
t.done();
|
||||
}, 'FileSystemDirectoryReader - interface');
|
||||
|
||||
|
||||
entry_test((t, entry) => {
|
||||
getChildEntry(entry, 'subdir', t.step_func(dir => {
|
||||
const reader = dir.createReader();
|
||||
assert_equals(typeof reader.readEntries, 'function');
|
||||
|
||||
const found_names = [];
|
||||
const do_chunk = t.step_func(() =>
|
||||
reader.readEntries(t.step_func(entries => {
|
||||
|
||||
if (entries.length > 0) {
|
||||
entries.forEach(t.step_func(entry => found_names.push(entry.name)));
|
||||
do_chunk();
|
||||
return;
|
||||
}
|
||||
|
||||
found_names.sort();
|
||||
assert_array_equals(found_names, ['1.txt', '2.txt', '3.txt'],
|
||||
'directory contents should match');
|
||||
t.done();
|
||||
})));
|
||||
|
||||
do_chunk();
|
||||
}), t.unreached_func('A child entry should be found'));
|
||||
}, 'FileSystemDirectoryReader - basic enumeration');
|
||||
|
||||
entry_test((t, entry) => {
|
||||
const reader = entry.createReader();
|
||||
reader.readEntries(() => {}, t.unreached_func('readEntries should succeed'));
|
||||
reader.readEntries(
|
||||
t.unreached_func('readEntries() should fail if already reading'),
|
||||
t.step_func(error => {
|
||||
assert_equals(error.name, 'InvalidStateError', 'invalid state if already reading');
|
||||
t.done();
|
||||
}));
|
||||
}, 'FileSystemDirectoryReader - reading flag');
|
||||
|
||||
entry_test((t, entry) => {
|
||||
const reader = entry.createReader();
|
||||
|
||||
const do_chunk = t.step_func(() =>
|
||||
reader.readEntries(t.step_func(entries => {
|
||||
if (entries.length > 0) {
|
||||
do_chunk();
|
||||
return;
|
||||
}
|
||||
reader.readEntries(t.step_func(entries => {
|
||||
assert_equals(
|
||||
entries.length, 0,
|
||||
'calling readEntries() when done should yield and empty sequence');
|
||||
t.done();
|
||||
}));
|
||||
})));
|
||||
|
||||
do_chunk();
|
||||
}, 'FileSystemDirectoryReader - done flag');
|
||||
|
||||
// TODO: Manual tests where directory contents are changed during the test.
|
||||
</script>
|
|
@ -0,0 +1,29 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemEntry attributes manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-entry">
|
||||
<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, 'isFile', 'FileSystemEntry has isFile attribute');
|
||||
assert_equals(typeof entry.isFile, 'boolean', 'isFile is boolean');
|
||||
|
||||
assert_idl_attribute(entry, 'isDirectory', 'FileSystemEntry has isDirectory attribute');
|
||||
assert_equals(typeof entry.isDirectory, 'boolean', 'isFile is boolean');
|
||||
|
||||
assert_idl_attribute(entry, 'name', 'FileSystemEntry has name attribute');
|
||||
assert_equals(typeof entry.name, 'string', 'name is a string');
|
||||
|
||||
assert_idl_attribute(entry, 'fullPath', 'FileSystemEntry has fullPath attribute');
|
||||
assert_equals(typeof entry.fullPath, 'string', 'fullPath is a string');
|
||||
|
||||
assert_idl_attribute(entry, 'filesystem', 'FileSystemEntry has filesystem attribute');
|
||||
assert_equals(typeof entry.filesystem, 'object', 'filesystem is an object');
|
||||
|
||||
t.done();
|
||||
}, 'FileSystemEntry - attribute types');
|
||||
|
||||
</script>
|
|
@ -0,0 +1,27 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemEntry getParent() manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#dom-filesystementry-getparentapi-entry">
|
||||
<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, 'getParent', 'FileSystemEntry has getParent method');
|
||||
assert_equals(typeof entry.getParent, 'function', 'FileSystemEntry has a getParent() method');
|
||||
|
||||
assert_equals(entry.getParent(), void 0, 'getParent() arguments are optional');
|
||||
|
||||
entry.getParent(t.step_func(parent => {
|
||||
assert_true(parent.isDirectory, 'parent should be a directory');
|
||||
|
||||
assert_equals(parent.fullPath, '/', 'parent should be root');
|
||||
assert_equals(parent.name, '', 'root name is empty string');
|
||||
|
||||
t.done();
|
||||
}), t.unreached_func('getParent() should not fail'));
|
||||
}, 'FileSystemEntry - getParent()');
|
||||
|
||||
// TODO: Manual test for getParent() where containing directory is removed before getParent() is called.
|
||||
</script>
|
|
@ -0,0 +1,37 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemFileEntry attributes manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-entry">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="support.js"></script>
|
||||
|
||||
<script>
|
||||
file_entry_test('file.txt', (t, entry) => {
|
||||
|
||||
assert_idl_attribute(entry, 'isFile', 'FileSystemEntry has isFile attribute');
|
||||
assert_equals(typeof entry.isFile, 'boolean', 'isFile is boolean');
|
||||
|
||||
assert_idl_attribute(entry, 'isDirectory', 'FileSystemEntry has isDirectory attribute');
|
||||
assert_equals(typeof entry.isDirectory, 'boolean', 'isFile is boolean');
|
||||
|
||||
assert_idl_attribute(entry, 'name', 'FileSystemEntry has name attribute');
|
||||
assert_equals(typeof entry.name, 'string', 'name is a string');
|
||||
|
||||
assert_idl_attribute(entry, 'fullPath', 'FileSystemEntry has fullPath attribute');
|
||||
assert_equals(typeof entry.fullPath, 'string', 'fullPath is a string');
|
||||
|
||||
assert_idl_attribute(entry, 'filesystem', 'FileSystemEntry has filesystem attribute');
|
||||
|
||||
t.done();
|
||||
}, 'FileSystemFileEntry - attribute types');
|
||||
|
||||
file_entry_test('file.txt', (t, entry) => {
|
||||
assert_true(entry.isFile);
|
||||
assert_false(entry.isDirectory);
|
||||
assert_equals(entry.name, 'file.txt');
|
||||
assert_equals(entry.fullPath, '/upload/file.txt');
|
||||
t.done();
|
||||
}, 'FileSystemFileEntry - attribute values');
|
||||
|
||||
</script>
|
|
@ -0,0 +1,26 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemFileEntry file() manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-entry">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="support.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
file_entry_test('file.txt', (t, entry) => {
|
||||
assert_idl_attribute(entry, 'file', 'FileSystemFileEntry has a file() method');
|
||||
assert_equals(typeof entry.file, 'function', 'FileSystemFileEntry has a file() method');
|
||||
|
||||
assert_throws(TypeError(), () => entry.file(), 'file() has a required argument');
|
||||
entry.file(t.step_func(file => {
|
||||
|
||||
assert_class_string(file, 'File', 'file() should yield a File');
|
||||
assert_equals(entry.name, file.name, 'entry and file names should match');
|
||||
t.done();
|
||||
|
||||
}), t.unreached_func('file() should not fail'));
|
||||
}, 'FileSystemFileEntry - file()');
|
||||
|
||||
// TODO: Manual test where file is replaced with directory before file() called
|
||||
</script>
|
|
@ -0,0 +1,17 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: FileSystemFileEntry getParent() manual test</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#api-entry">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="support.js"></script>
|
||||
|
||||
<script>
|
||||
|
||||
file_entry_test('file.txt', (t, entry) => {
|
||||
assert_idl_attribute(entry, 'getParent', 'FileSystemFileEntry has a getParent method');
|
||||
assert_equals(typeof entry.getParent, 'function', 'FileSystemFileEntry has a getParent() method');
|
||||
t.done();
|
||||
}, 'FileSystemFileEntry - getParent() method');
|
||||
|
||||
</script>
|
|
@ -0,0 +1,54 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: IDL Tests</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#idl-index">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/resources/WebIDLParser.js"></script>
|
||||
<script src="/resources/idlharness.js"></script>
|
||||
<script src="support.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
entry_test((t, entry, item) => {
|
||||
assert_true(entry.isDirectory);
|
||||
Promise.all([
|
||||
getEntriesAsPromise(entry),
|
||||
fetch('interfaces.idl').then(r => r.text())
|
||||
]).then(t.step_func(([entries, idls]) => {
|
||||
window.samples = {
|
||||
item: item,
|
||||
dirEntry: entries.filter(entry => entry.isDirectory)[0],
|
||||
fileEntry: entries.filter(entry => entry.isFile)[0],
|
||||
fileSystem: entry.filesystem,
|
||||
};
|
||||
|
||||
const idl_array = new IdlArray();
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dfn-file
|
||||
idl_array.add_untested_idls('[Exposed=(Window,Worker)] interface File {};');
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement
|
||||
idl_array.add_untested_idls('interface HTMLInputElement {};');
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#datatransferitem
|
||||
idl_array.add_untested_idls('interface DataTransferItem {};');
|
||||
|
||||
idl_array.add_idls(idls);
|
||||
|
||||
idl_array.add_objects({
|
||||
File: ['new File([], "example.txt")'],
|
||||
HTMLInputElement: ['document.createElement("input")'],
|
||||
DataTransferItem: ['samples.item'],
|
||||
FileSystemEntry: [],
|
||||
FileSystemDirectoryEntry: ['samples.dirEntry'],
|
||||
FileSystemDirectoryReader: ['samples.dirEntry.createReader()'],
|
||||
FileSystemFileEntry: ['samples.fileEntry'],
|
||||
FileSystem: ['samples.fileSystem'],
|
||||
});
|
||||
|
||||
idl_array.test();
|
||||
t.done();
|
||||
}));
|
||||
}, 'Entries API: IDL');
|
||||
</script>
|
39
tests/wpt/web-platform-tests/entries-api/interfaces.html
Normal file
39
tests/wpt/web-platform-tests/entries-api/interfaces.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
<!DOCTYPE html>
|
||||
<meta charset=utf-8>
|
||||
<title>Entries API: IDL Tests</title>
|
||||
<link rel=help href="https://wicg.github.io/entries-api/#idl-index">
|
||||
<script src="/resources/testharness.js"></script>
|
||||
<script src="/resources/testharnessreport.js"></script>
|
||||
<script src="/resources/WebIDLParser.js"></script>
|
||||
<script src="/resources/idlharness.js"></script>
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
promise_test(t => {
|
||||
return fetch('interfaces.idl')
|
||||
.then(r => r.text())
|
||||
.then(idls => {
|
||||
|
||||
const idl_array = new IdlArray();
|
||||
|
||||
// https://w3c.github.io/FileAPI/#dfn-file
|
||||
idl_array.add_untested_idls('[Exposed=(Window,Worker)] interface File {};');
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/forms.html#htmlinputelement
|
||||
idl_array.add_untested_idls('interface HTMLInputElement {};');
|
||||
|
||||
// https://html.spec.whatwg.org/multipage/interaction.html#datatransferitem
|
||||
idl_array.add_untested_idls('interface DataTransferItem {};');
|
||||
|
||||
idl_array.add_idls(idls);
|
||||
|
||||
idl_array.add_objects({
|
||||
File: ['new File([], "example.txt")'],
|
||||
HTMLInputElement: ['document.createElement("input")'],
|
||||
});
|
||||
|
||||
idl_array.test();
|
||||
});
|
||||
|
||||
}, 'Entries API: IDL');
|
||||
</script>
|
70
tests/wpt/web-platform-tests/entries-api/interfaces.idl
Normal file
70
tests/wpt/web-platform-tests/entries-api/interfaces.idl
Normal file
|
@ -0,0 +1,70 @@
|
|||
|
||||
partial interface File {
|
||||
readonly attribute USVString webkitRelativePath;
|
||||
};
|
||||
|
||||
partial interface HTMLInputElement {
|
||||
attribute boolean webkitdirectory;
|
||||
readonly attribute FrozenArray<FileSystemEntry> webkitEntries;
|
||||
};
|
||||
|
||||
partial interface DataTransferItem {
|
||||
FileSystemEntry? webkitGetAsEntry();
|
||||
};
|
||||
|
||||
callback interface ErrorCallback {
|
||||
void handleEvent(DOMException err);
|
||||
};
|
||||
|
||||
interface FileSystemEntry {
|
||||
readonly attribute boolean isFile;
|
||||
readonly attribute boolean isDirectory;
|
||||
readonly attribute USVString name;
|
||||
readonly attribute USVString fullPath;
|
||||
readonly attribute FileSystem filesystem;
|
||||
|
||||
void getParent(optional FileSystemEntryCallback successCallback,
|
||||
optional ErrorCallback errorCallback);
|
||||
};
|
||||
|
||||
interface FileSystemDirectoryEntry : FileSystemEntry {
|
||||
FileSystemDirectoryReader createReader();
|
||||
void getFile(optional USVString? path,
|
||||
optional FileSystemFlags options,
|
||||
optional FileSystemEntryCallback successCallback,
|
||||
optional ErrorCallback errorCallback);
|
||||
void getDirectory(optional USVString? path,
|
||||
optional FileSystemFlags options,
|
||||
optional FileSystemEntryCallback successCallback,
|
||||
optional ErrorCallback errorCallback);
|
||||
};
|
||||
|
||||
dictionary FileSystemFlags {
|
||||
boolean create = false;
|
||||
boolean exclusive = false;
|
||||
};
|
||||
|
||||
callback interface FileSystemEntryCallback {
|
||||
void handleEvent(FileSystemEntry entry);
|
||||
};
|
||||
|
||||
interface FileSystemDirectoryReader {
|
||||
void readEntries(FileSystemEntriesCallback successCallback,
|
||||
optional ErrorCallback errorCallback);
|
||||
};
|
||||
callback interface FileSystemEntriesCallback {
|
||||
void handleEvent(sequence<FileSystemEntry> entries);
|
||||
};
|
||||
|
||||
interface FileSystemFileEntry : FileSystemEntry {
|
||||
void file(FileCallback successCallback,
|
||||
optional ErrorCallback errorCallback);
|
||||
};
|
||||
callback interface FileCallback {
|
||||
void handleEvent(File file);
|
||||
};
|
||||
|
||||
interface FileSystem {
|
||||
readonly attribute USVString name;
|
||||
readonly attribute FileSystemDirectoryEntry root;
|
||||
};
|
131
tests/wpt/web-platform-tests/entries-api/support.js
Normal file
131
tests/wpt/web-platform-tests/entries-api/support.js
Normal file
|
@ -0,0 +1,131 @@
|
|||
// ----------------------------------------
|
||||
// Test Utilities
|
||||
// ----------------------------------------
|
||||
|
||||
setup({explicit_timeout: true});
|
||||
|
||||
const tests = [];
|
||||
window.addEventListener('DOMContentLoaded', e => {
|
||||
const header = document.createElement('h1');
|
||||
header.innerText = document.title;
|
||||
document.body.appendChild(header);
|
||||
const elem = document.createElement('div');
|
||||
elem.style.cssText = 'height: 50px; border: 1px dotted red;';
|
||||
elem.innerHTML = 'Drop the <b>support/upload</b> directory here.</div>';
|
||||
document.body.appendChild(elem);
|
||||
elem.addEventListener('dragover', e => {
|
||||
e.preventDefault();
|
||||
});
|
||||
elem.addEventListener('drop', e => {
|
||||
e.preventDefault();
|
||||
for (let i = 0; i < e.dataTransfer.items.length; ++i) {
|
||||
const item = e.dataTransfer.items[i];
|
||||
if (item.kind !== 'file')
|
||||
continue;
|
||||
const entry = item.webkitGetAsEntry();
|
||||
elem.parentElement.removeChild(elem);
|
||||
tests.forEach(f => f(entry, item));
|
||||
break;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
// Registers a test to be run when an entry is dropped. Calls |func|
|
||||
// with (test, entry, item); |func| must call `test.done()` when complete.
|
||||
function entry_test(func, description) {
|
||||
const test = async_test(description);
|
||||
tests.push(test.step_func((entry, item) => func(test, entry, item)));
|
||||
}
|
||||
|
||||
// Registers a test to be run when an entry is dropped. Digs the named
|
||||
// |file| out of the dropped entry and calls |func| with
|
||||
// (test, file_entry); |func| must call `test.done()` when complete.
|
||||
function file_entry_test(name, func, description) {
|
||||
return entry_test((t, entry, item) => {
|
||||
getChildEntry(entry, name,
|
||||
t.step_func((entry) => func(t, entry)),
|
||||
t.unreached_func('Did not find expected file: ' + name));
|
||||
}, description);
|
||||
}
|
||||
|
||||
|
||||
// ----------------------------------------
|
||||
// Paths
|
||||
// ----------------------------------------
|
||||
|
||||
const INVALID_PATHS = [
|
||||
'\x00', 'a-\x00-b',
|
||||
'\\', 'a-\\-b'
|
||||
];
|
||||
const EMPTY_PATHS = ['', null, undefined];
|
||||
const NOT_FOUND_PATHS = [
|
||||
'nope',
|
||||
'/upload/nope',
|
||||
'./nope',
|
||||
'subdir/../nope',
|
||||
'\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f',
|
||||
'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f',
|
||||
];
|
||||
|
||||
const DIR_PATHS = [
|
||||
'subdir',
|
||||
'/upload/subdir',
|
||||
'./subdir',
|
||||
'subdir/.',
|
||||
'subdir/../subdir',
|
||||
'subdir/./../subdir',
|
||||
'subdir/../subdir/.',
|
||||
'//upload/subdir',
|
||||
'/upload//subdir',
|
||||
'.//subdir',
|
||||
'subdir//.',
|
||||
];
|
||||
const FILE_PATHS = [
|
||||
'file.txt',
|
||||
'/upload/file.txt',
|
||||
'subdir/../file.txt',
|
||||
'//upload/file.txt',
|
||||
'/upload//file.txt',
|
||||
'subdir/./../file.txt',
|
||||
];
|
||||
|
||||
// ----------------------------------------
|
||||
// Helpers
|
||||
// ----------------------------------------
|
||||
|
||||
// Wrapper for FileSystemDirectoryReader that yields all entries via a
|
||||
// Promise.
|
||||
|
||||
function getEntriesAsPromise(dirEntry) {
|
||||
return new Promise((resolve, reject) => {
|
||||
const result = [];
|
||||
const reader = dirEntry.createReader();
|
||||
const doBatch = () => {
|
||||
reader.readEntries(entries => {
|
||||
if (entries.length > 0) {
|
||||
entries.forEach(e => result.push(e));
|
||||
doBatch();
|
||||
} else {
|
||||
resolve(result);
|
||||
}
|
||||
}, reject);
|
||||
};
|
||||
doBatch();
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
// Wrapper for FileSystemDirectoryReader that yields a single entry by
|
||||
// name via a callback. Can be used instead of getFile() or
|
||||
// getDirectory() since not all implementations support those.
|
||||
|
||||
function getChildEntry(dirEntry, name, callback, errback) {
|
||||
getEntriesAsPromise(dirEntry)
|
||||
.then(entries => {
|
||||
const entry = entries.filter(entry => entry.name === name)[0];
|
||||
if (!entry)
|
||||
throw new Error('No such file: ' + name);
|
||||
return entry;
|
||||
}).then(callback, errback);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue