Update web-platform-tests to revision 20424e735a5e6ac7a474ae35d86c714272aea0e8

This commit is contained in:
WPT Sync Bot 2019-04-17 21:57:51 -04:00
parent eac2607a06
commit 39f4d8b931
94 changed files with 1332 additions and 233 deletions

View file

@ -0,0 +1,72 @@
// META: script=resources/test-helpers.js
promise_test(async t => cleanupSandboxedFileSystem(),
'Cleanup to setup test environment');
promise_test(async t => {
const old_handle = await createFileWithContents(t, 'old-file', '12345');
const dir = await old_handle.getParent();
const new_handle = await old_handle.copyTo(dir, 'new-name');
t.add_cleanup(() => new_handle.remove());
// Verify new file.
assert_true(new_handle.isFile);
assert_false(new_handle.isDirectory);
assert_equals(new_handle.name, 'new-name');
assert_equals(await getFileContents(new_handle), '12345');
// And verify old file is still around as well.
assert_equals(await getFileContents(old_handle), '12345');
// Verify directory entries.
assert_array_equals(await getSortedDirectoryEntries(dir), ['new-name', 'old-file']);
}, 'copyTo() into the same parent directory');
promise_test(async t => {
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const old_handle = await createFileWithContents(t, 'old-file', '12345');
const target_dir = await dir.getDirectory('dir-name', { create: true });
t.add_cleanup(() => target_dir.removeRecursively());
const new_handle = await old_handle.copyTo(target_dir);
// Verify new file.
assert_true(new_handle.isFile);
assert_false(new_handle.isDirectory);
assert_equals(new_handle.name, 'old-file');
assert_equals(await getFileContents(new_handle), '12345');
// And verify old file is still around as well.
assert_equals(await getFileContents(old_handle), '12345');
// Verify directory entries.
assert_array_equals(await getSortedDirectoryEntries(dir), ['dir-name/', 'old-file']);
assert_array_equals(await getSortedDirectoryEntries(target_dir), ['old-file']);
}, 'copyTo() to copy a file into a sub-directory');
promise_test(async t => {
const handle = await createFileWithContents(t, 'old-file', '12345');
const dir = await handle.getParent();
await promise_rejects(t, 'InvalidModificationError', handle.copyTo(dir));
await promise_rejects(t, 'InvalidModificationError', handle.copyTo(dir, handle.name));
// Verify file still exists.
assert_equals(await getFileContents(handle), '12345');
assert_array_equals(await getSortedDirectoryEntries(dir), ['old-file']);
}, 'copyTo() with existing name and parent should fail');
promise_test(async t => {
const handle = await createFileWithContents(t, 'old-file', '12345');
const target_handle = await createFileWithContents(t, 'target', 'abc');
const dir = await handle.getParent();
await handle.copyTo(dir, target_handle.name);
// Verify state of files.
assert_equals(await getFileContents(handle), '12345');
assert_equals(await getFileContents(target_handle), '12345');
assert_array_equals(await getSortedDirectoryEntries(dir), ['old-file', 'target']);
}, 'copyTo() when target file already exists should overwrite target');
// TODO(mek): Tests to copy directories.

View file

@ -0,0 +1,72 @@
// META: script=resources/test-helpers.js
promise_test(async t => cleanupSandboxedFileSystem(),
'Cleanup to setup test environment');
promise_test(async t => {
const old_handle = await createFileWithContents(t, 'old-file', '12345');
const dir = await old_handle.getParent();
const new_handle = await old_handle.moveTo(dir, 'new-name');
t.add_cleanup(() => new_handle.remove());
// Verify new file.
assert_true(new_handle.isFile);
assert_false(new_handle.isDirectory);
assert_equals(new_handle.name, 'new-name');
assert_equals(await getFileContents(new_handle), '12345');
// And verify old file is gone.
await promise_rejects(t, 'NotFoundError', getFileContents(old_handle));
// Verify directory entries.
assert_array_equals(await getSortedDirectoryEntries(dir), ['new-name']);
}, 'moveTo() to rename a file');
promise_test(async t => {
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const old_handle = await createFileWithContents(t, 'old-file', '12345');
const target_dir = await dir.getDirectory('dir-name', { create: true });
t.add_cleanup(() => target_dir.removeRecursively());
const new_handle = await old_handle.moveTo(target_dir);
// Verify new file.
assert_true(new_handle.isFile);
assert_false(new_handle.isDirectory);
assert_equals(new_handle.name, 'old-file');
assert_equals(await getFileContents(new_handle), '12345');
// And verify old file is gone.
await promise_rejects(t, 'NotFoundError', getFileContents(old_handle));
// Verify directory entries.
assert_array_equals(await getSortedDirectoryEntries(dir), ['dir-name/']);
assert_array_equals(await getSortedDirectoryEntries(target_dir), ['old-file']);
}, 'moveTo() to move a file into a sub-directory');
promise_test(async t => {
const handle = await createFileWithContents(t, 'old-file', '12345');
const dir = await handle.getParent();
await promise_rejects(t, 'InvalidModificationError', handle.moveTo(dir));
await promise_rejects(t, 'InvalidModificationError', handle.moveTo(dir, handle.name));
// Verify file still exists.
assert_equals(await getFileContents(handle), '12345');
assert_array_equals(await getSortedDirectoryEntries(dir), ['old-file']);
}, 'moveTo() with existing name and parent should fail');
promise_test(async t => {
const handle = await createFileWithContents(t, 'old-file', '12345');
const target_handle = await createFileWithContents(t, 'target', 'abc');
const dir = await handle.getParent();
await handle.moveTo(dir, target_handle.name);
// Verify state of files.
await promise_rejects(t, 'NotFoundError', getFileContents(handle));
assert_equals(await getFileContents(target_handle), '12345');
assert_array_equals(await getSortedDirectoryEntries(dir), ['target']);
}, 'moveTo() when target file already exists should overwrite target');
// TODO(mek): Tests to move directories.

View file

@ -0,0 +1,41 @@
// META: script=resources/test-helpers.js
promise_test(async t => cleanupSandboxedFileSystem(),
'Cleanup to setup test environment');
promise_test(async t => {
const handle = await createFileWithContents(t, 'file-to-remove', '12345');
const dir = await handle.getParent();
await createFileWithContents(t, 'file-to-keep', 'abc');
await handle.remove();
assert_array_equals(await getSortedDirectoryEntries(dir), ['file-to-keep']);
await promise_rejects(t, 'NotFoundError', getFileContents(handle));
}, 'remove() to remove a file');
promise_test(async t => {
const handle = await createFileWithContents(t, 'file-to-remove', '12345');
await handle.remove();
await promise_rejects(t, 'NotFoundError', handle.remove());
}, 'remove() on an already removed file should fail');
promise_test(async t => {
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const dir = await root.getDirectory('dir-to-remove', { create: true });
await createFileWithContents(t, 'file-to-keep', 'abc');
await dir.remove();
assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']);
await promise_rejects(t, 'NotFoundError', getSortedDirectoryEntries(dir));
}, 'remove() to remove an empty directory');
promise_test(async t => {
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const dir = await root.getDirectory('dir-to-remove', { create: true });
t.add_cleanup(() => dir.removeRecursively());
await createEmptyFile(t, 'file-in-dir', dir);
await promise_rejects(t, 'InvalidModificationError', dir.remove());
assert_array_equals(await getSortedDirectoryEntries(root), ['dir-to-remove/']);
assert_array_equals(await getSortedDirectoryEntries(dir), ['file-in-dir']);
}, 'remove() on a non-empty directory should fail');

View file

@ -0,0 +1,57 @@
// META: script=resources/test-helpers.js
promise_test(async t => cleanupSandboxedFileSystem(),
'Cleanup to setup test environment');
promise_test(async t => {
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
await promise_rejects(t, 'NotFoundError', root.getDirectory('non-existing-dir'));
}, 'getDirectory(create=false) rejects for non-existing directories');
promise_test(async t => {
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const handle = await root.getDirectory('non-existing-dir', { create: true });
t.add_cleanup(() => handle.removeRecursively());
assert_false(handle.isFile);
assert_true(handle.isDirectory);
assert_equals(handle.name, 'non-existing-dir');
assert_equals(await getDirectoryEntryCount(handle), 0);
assert_array_equals(await getSortedDirectoryEntries(root), ['non-existing-dir/']);
}, 'getDirectory(create=true) creates an empty directory');
promise_test(async t => {
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const existing_handle = await root.getDirectory('dir-with-contents', { create: true });
t.add_cleanup(() => existing_handle.removeRecursively());
const file_handle = await createEmptyFile(t, 'test-file', existing_handle);
const handle = await root.getDirectory('dir-with-contents', { create: false });
assert_false(handle.isFile);
assert_true(handle.isDirectory);
assert_equals(handle.name, 'dir-with-contents');
assert_array_equals(await getSortedDirectoryEntries(handle), ['test-file']);
}, 'getDirectory(create=false) returns existing directories');
promise_test(async t => {
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const existing_handle = await root.getDirectory('dir-with-contents', { create: true });
t.add_cleanup(() => existing_handle.removeRecursively());
const file_handle = await existing_handle.getFile('test-file', { create: true });
const handle = await root.getDirectory('dir-with-contents', { create: true });
assert_false(handle.isFile);
assert_true(handle.isDirectory);
assert_equals(handle.name, 'dir-with-contents');
assert_array_equals(await getSortedDirectoryEntries(handle), ['test-file']);
}, 'getDirectory(create=true) returns existing directories without erasing');
promise_test(async t => {
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
await createEmptyFile(t, 'file-name');
await promise_rejects(t, 'TypeMismatchError', root.getDirectory('file-name'));
await promise_rejects(t, 'TypeMismatchError', root.getDirectory('file-name', { create: false }));
await promise_rejects(t, 'TypeMismatchError', root.getDirectory('file-name', { create: true }));
}, 'getDirectory() when a file already exists with the same name');

View file

@ -0,0 +1,62 @@
// META: script=resources/test-helpers.js
promise_test(async t => cleanupSandboxedFileSystem(),
'Cleanup to setup test environment');
promise_test(async t => {
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
await promise_rejects(t, 'NotFoundError', dir.getFile('non-existing-file'));
}, 'getFile(create=false) rejects for non-existing files');
promise_test(async t => {
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const handle = await dir.getFile('non-existing-file', { create: true });
t.add_cleanup(() => handle.remove());
assert_true(handle.isFile);
assert_false(handle.isDirectory);
assert_equals(handle.name, 'non-existing-file');
assert_equals(await getFileSize(handle), 0);
assert_equals(await getFileContents(handle), '');
}, 'getFile(create=true) creates an empty file for non-existing files');
promise_test(async t => {
const existing_handle = await createFileWithContents(t, 'existing-file', '1234567890');
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const handle = await dir.getFile('existing-file');
assert_true(handle.isFile);
assert_false(handle.isDirectory);
assert_equals(handle.name, 'existing-file');
assert_equals(await getFileSize(handle), 10);
assert_equals(await getFileContents(handle), '1234567890');
}, 'getFile(create=false) returns existing files');
promise_test(async t => {
const existing_handle = await createFileWithContents(t, 'file-with-contents', '1234567890');
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const handle = await dir.getFile('file-with-contents', { create: true });
assert_true(handle.isFile);
assert_false(handle.isDirectory);
assert_equals(handle.name, 'file-with-contents');
assert_equals(await getFileSize(handle), 10);
assert_equals(await getFileContents(handle), '1234567890');
}, 'getFile(create=true) returns existing files without erasing');
promise_test(async t => {
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const dir_handle = await dir.getDirectory('dir-name', { create: true });
t.add_cleanup(() => dir_handle.removeRecursively());
await promise_rejects(t, 'TypeMismatchError', dir.getFile('dir-name'));
}, 'getFile(create=false) when a directory already exists with the same name');
promise_test(async t => {
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const dir_handle = await dir.getDirectory('dir-name', { create: true });
t.add_cleanup(() => dir_handle.removeRecursively());
await promise_rejects(t, 'TypeMismatchError', dir.getFile('dir-name', { create: true }));
}, 'getFile(create=true) when a directory already exists with the same name');

View file

@ -0,0 +1,96 @@
// META: script=resources/test-helpers.js
promise_test(async t => cleanupSandboxedFileSystem(),
'Cleanup to setup test environment');
promise_test(async t => {
const handle = await createEmptyFile(t, 'empty_blob');
const writer = await handle.createWriter();
await writer.write(0, new Blob([]));
assert_equals(await getFileContents(handle), '');
assert_equals(await getFileSize(handle), 0);
}, 'write() with an empty blob to an empty file');
promise_test(async t => {
const handle = await createEmptyFile(t, 'valid_blob');
const writer = await handle.createWriter();
await writer.write(0, new Blob(['1234567890']));
assert_equals(await getFileContents(handle), '1234567890');
assert_equals(await getFileSize(handle), 10);
}, 'write() a blob to an empty file');
promise_test(async t => {
const handle = await createEmptyFile(t, 'blob_with_offset');
const writer = await handle.createWriter();
await writer.write(0, new Blob(['1234567890']));
await writer.write(4, new Blob(['abc']));
assert_equals(await getFileContents(handle), '1234abc890');
assert_equals(await getFileSize(handle), 10);
}, 'write() called with a blob and a valid offset');
promise_test(async t => {
const handle = await createEmptyFile(t, 'bad_offset');
const writer = await handle.createWriter();
await promise_rejects(t, 'InvalidStateError', writer.write(4, new Blob(['abc'])));
assert_equals(await getFileContents(handle), '');
assert_equals(await getFileSize(handle), 0);
}, 'write() called with an invalid offset');
promise_test(async t => {
const handle = await createEmptyFile(t, 'trunc_shrink');
const writer = await handle.createWriter();
await writer.write(0, new Blob(['1234567890']));
await writer.truncate(5);
assert_equals(await getFileContents(handle), '12345');
assert_equals(await getFileSize(handle), 5);
}, 'truncate() to shrink a file');
promise_test(async t => {
const handle = await createEmptyFile(t, 'trunc_grow');
const writer = await handle.createWriter();
await writer.write(0, new Blob(['abc']));
await writer.truncate(5);
assert_equals(await getFileContents(handle), 'abc\0\0');
assert_equals(await getFileSize(handle), 5);
}, 'truncate() to grow a file');
promise_test(async t => {
const handle = await createEmptyFile(t, 'write_stream');
const writer = await handle.createWriter();
const stream = new Response('1234567890').body;
await writer.write(0, stream);
assert_equals(await getFileContents(handle), '1234567890');
assert_equals(await getFileSize(handle), 10);
}, 'write() called with a ReadableStream');
promise_test(async t => {
const handle = await createEmptyFile(t, 'write_stream');
const handle_writer = await handle.createWriter();
const { writable, readable } = new TransformStream();
const write_result = handle_writer.write(0, readable);
const stream_writer = writable.getWriter();
stream_writer.write(new Uint8Array([0x73, 0x74, 0x72, 0x65, 0x61, 0x6D, 0x73, 0x21]));
garbageCollect();
stream_writer.write(new Uint8Array([0x21, 0x21]));
stream_writer.close();
await write_result;
assert_equals(await getFileContents(handle), 'streams!!!');
assert_equals(await getFileSize(handle), 10);
}, 'Using a WritableStream writer to write');

View file

@ -0,0 +1,2 @@
This directory contains (tentative) tests for the
[Native File System](https://wicg.github.io/native-file-system/) specification.

View file

@ -0,0 +1,67 @@
async function cleanupSandboxedFileSystem() {
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
for await (let entry of dir.getEntries()) {
if (entry.isDirectory)
await entry.removeRecursively();
else
await entry.remove();
}
}
async function getFileSize(handle) {
const file = await handle.getFile();
return file.size;
}
async function getFileContents(handle) {
const file = await handle.getFile();
return new Response(file).text();
}
async function getDirectoryEntryCount(handle) {
let result = 0;
for await (let entry of handle.getEntries()) {
result++;
}
return result;
}
async function getSortedDirectoryEntries(handle) {
let result = [];
for await (let entry of handle.getEntries()) {
if (entry.isDirectory)
result.push(entry.name + '/');
else
result.push(entry.name);
}
result.sort();
return result;
}
async function createEmptyFile(test, name, parent) {
const dir = parent ? parent : await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
const handle = await dir.getFile(name, { create: true });
test.add_cleanup(async () => {
try {
await handle.remove();
} catch (e) {
// Ignore any errors when removing files, as tests might already remove the file.
}
});
// Make sure the file is empty.
assert_equals(await getFileSize(handle), 0);
return handle;
}
async function createFileWithContents(test, name, contents, parent) {
const handle = await createEmptyFile(test, name, parent);
const writer = await handle.createWriter();
await writer.write(0, new Blob([contents]));
return handle;
}
function garbageCollect() {
// TODO(https://github.com/web-platform-tests/wpt/issues/7899): Change to
// some sort of cross-browser GC trigger.
if (self.gc) self.gc();
};