mirror of
https://github.com/servo/servo.git
synced 2025-08-06 06:00:15 +01:00
Update web-platform-tests to revision 332b7c4e711d75ead4c0dfbf7f6f0b683206756d
This commit is contained in:
parent
46611b012e
commit
b60afa18f5
389 changed files with 7767 additions and 2421 deletions
|
@ -0,0 +1,111 @@
|
|||
directory_test(async (t, root) => {
|
||||
await promise_rejects(
|
||||
t, 'NotFoundError', root.getDirectory('non-existing-dir'));
|
||||
}, 'getDirectory(create=false) rejects for non-existing directories');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await root.getDirectory('non-existing-dir', {create: true});
|
||||
t.add_cleanup(() => root.removeEntry('non-existing-dir', {recursive: true}));
|
||||
|
||||
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');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const existing_handle =
|
||||
await root.getDirectory('dir-with-contents', {create: true});
|
||||
t.add_cleanup(() => root.removeEntry('dir-with-contents', {recursive: true}));
|
||||
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');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const existing_handle =
|
||||
await root.getDirectory('dir-with-contents', {create: true});
|
||||
t.add_cleanup(() => root.removeEntry('dir-with-contents', {recursive: true}));
|
||||
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');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
await createEmptyFile(t, 'file-name', root);
|
||||
|
||||
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');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
await promise_rejects(
|
||||
t, new TypeError(), dir.getDirectory('', {create: true}));
|
||||
await promise_rejects(
|
||||
t, new TypeError(), dir.getDirectory('', {create: false}));
|
||||
}, 'getDirectory() with empty name');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
await promise_rejects(
|
||||
t, new TypeError(), dir.getDirectory(kCurrentDirectory));
|
||||
await promise_rejects(
|
||||
t, new TypeError(), dir.getDirectory(kCurrentDirectory, {create: true}));
|
||||
}, `getDirectory() with "${kCurrentDirectory}" name`);
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const subdir = await createDirectory(t, 'subdir-name', /*parent=*/ dir);
|
||||
|
||||
await promise_rejects(
|
||||
t, new TypeError(), subdir.getDirectory(kParentDirectory));
|
||||
await promise_rejects(
|
||||
t, new TypeError(),
|
||||
subdir.getDirectory(kParentDirectory, {create: true}));
|
||||
}, `getDirectory() with "${kParentDirectory}" name`);
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const first_subdir_name = 'first-subdir-name';
|
||||
const first_subdir =
|
||||
await createDirectory(t, first_subdir_name, /*parent=*/ dir);
|
||||
|
||||
const second_subdir_name = 'second-subdir-name';
|
||||
const second_subdir =
|
||||
await createDirectory(t, second_subdir_name, /*parent=*/ first_subdir);
|
||||
|
||||
for (let i = 0; i < kPathSeparators.length; ++i) {
|
||||
const path_with_separator =
|
||||
`${first_subdir_name}${kPathSeparators[i]}${second_subdir_name}`;
|
||||
await promise_rejects(
|
||||
t, new TypeError(), dir.getDirectory(path_with_separator),
|
||||
`getDirectory() must reject names containing "${kPathSeparators[i]}"`);
|
||||
}
|
||||
}, 'getDirectory(create=false) with a path separator when the directory exists');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const subdir_name = 'subdir-name';
|
||||
const subdir = await createDirectory(t, subdir_name, /*parent=*/ dir);
|
||||
|
||||
for (let i = 0; i < kPathSeparators.length; ++i) {
|
||||
const path_with_separator = `${subdir_name}${kPathSeparators[i]}file_name`;
|
||||
await promise_rejects(
|
||||
t, new TypeError(),
|
||||
dir.getDirectory(path_with_separator, {create: true}),
|
||||
`getDirectory(true) must reject names containing "${
|
||||
kPathSeparators[i]}"`);
|
||||
}
|
||||
}, 'getDirectory(create=true) with a path separator');
|
|
@ -0,0 +1,100 @@
|
|||
directory_test(async (t, dir) => {
|
||||
await promise_rejects(t, 'NotFoundError', dir.getFile('non-existing-file'));
|
||||
}, 'getFile(create=false) rejects for non-existing files');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const handle = await dir.getFile('non-existing-file', {create: true});
|
||||
t.add_cleanup(() => dir.removeEntry('non-existing-file'));
|
||||
|
||||
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');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const existing_handle = await createFileWithContents(
|
||||
t, 'existing-file', '1234567890', /*parent=*/ dir);
|
||||
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');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const existing_handle = await createFileWithContents(
|
||||
t, 'file-with-contents', '1234567890', /*parent=*/ dir);
|
||||
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');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const dir_handle = await dir.getDirectory('dir-name', {create: true});
|
||||
t.add_cleanup(() => dir.removeEntry('dir-name', {recursive: true}));
|
||||
|
||||
await promise_rejects(t, 'TypeMismatchError', dir.getFile('dir-name'));
|
||||
}, 'getFile(create=false) when a directory already exists with the same name');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const dir_handle = await dir.getDirectory('dir-name', {create: true});
|
||||
t.add_cleanup(() => dir.removeEntry('dir-name', {recursive: true}));
|
||||
|
||||
await promise_rejects(
|
||||
t, 'TypeMismatchError', dir.getFile('dir-name', {create: true}));
|
||||
}, 'getFile(create=true) when a directory already exists with the same name');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
await promise_rejects(t, new TypeError(), dir.getFile('', {create: true}));
|
||||
await promise_rejects(t, new TypeError(), dir.getFile('', {create: false}));
|
||||
}, 'getFile() with empty name');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
await promise_rejects(t, new TypeError(), dir.getFile(kCurrentDirectory));
|
||||
await promise_rejects(
|
||||
t, new TypeError(), dir.getFile(kCurrentDirectory, {create: true}));
|
||||
}, `getFile() with "${kCurrentDirectory}" name`);
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const subdir = await createDirectory(t, 'subdir-name', /*parent=*/ dir);
|
||||
|
||||
await promise_rejects(t, new TypeError(), subdir.getFile(kParentDirectory));
|
||||
await promise_rejects(
|
||||
t, new TypeError(), subdir.getFile(kParentDirectory, {create: true}));
|
||||
}, `getFile() with "${kParentDirectory}" name`);
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const subdir_name = 'subdir-name';
|
||||
const subdir = await createDirectory(t, subdir_name, /*parent=*/ dir);
|
||||
|
||||
const file_name = 'file-name';
|
||||
await createEmptyFile(t, file_name, /*parent=*/ subdir);
|
||||
|
||||
for (let i = 0; i < kPathSeparators.length; ++i) {
|
||||
const path_with_separator =
|
||||
`${subdir_name}${kPathSeparators[i]}${file_name}`;
|
||||
await promise_rejects(
|
||||
t, new TypeError(), dir.getFile(path_with_separator),
|
||||
`getFile() must reject names containing "${kPathSeparators[i]}"`);
|
||||
}
|
||||
}, 'getFile(create=false) with a path separator when the file exists.');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const subdir_name = 'subdir-name';
|
||||
const subdir = await createDirectory(t, subdir_name, /*parent=*/ dir);
|
||||
|
||||
for (let i = 0; i < kPathSeparators.length; ++i) {
|
||||
const path_with_separator = `${subdir_name}${kPathSeparators[i]}file_name`;
|
||||
await promise_rejects(
|
||||
t, new TypeError(), dir.getFile(path_with_separator, {create: true}),
|
||||
`getFile(true) must reject names containing "${kPathSeparators[i]}"`);
|
||||
}
|
||||
}, 'getFile(create=true) with a path separator');
|
|
@ -0,0 +1,69 @@
|
|||
|
||||
directory_test(async (t, root) => {
|
||||
const handle =
|
||||
await createFileWithContents(t, 'file-to-remove', '12345', root);
|
||||
await createFileWithContents(t, 'file-to-keep', 'abc', root);
|
||||
await root.removeEntry('file-to-remove');
|
||||
|
||||
assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']);
|
||||
await promise_rejects(t, 'NotFoundError', getFileContents(handle));
|
||||
}, 'removeEntry() to remove a file');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle =
|
||||
await createFileWithContents(t, 'file-to-remove', '12345', root);
|
||||
await root.removeEntry('file-to-remove');
|
||||
|
||||
await promise_rejects(t, 'NotFoundError', root.removeEntry('file-to-remove'));
|
||||
}, 'removeEntry() on an already removed file should fail');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await root.getDirectory('dir-to-remove', {create: true});
|
||||
await createFileWithContents(t, 'file-to-keep', 'abc', root);
|
||||
await root.removeEntry('dir-to-remove');
|
||||
|
||||
assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']);
|
||||
await promise_rejects(t, 'NotFoundError', getSortedDirectoryEntries(dir));
|
||||
}, 'removeEntry() to remove an empty directory');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await root.getDirectory('dir-to-remove', {create: true});
|
||||
t.add_cleanup(() => root.removeEntry('dir-to-remove', {recursive: true}));
|
||||
await createEmptyFile(t, 'file-in-dir', dir);
|
||||
|
||||
await promise_rejects(
|
||||
t, 'InvalidModificationError', root.removeEntry('dir-to-remove'));
|
||||
assert_array_equals(
|
||||
await getSortedDirectoryEntries(root), ['dir-to-remove/']);
|
||||
assert_array_equals(await getSortedDirectoryEntries(dir), ['file-in-dir']);
|
||||
}, 'removeEntry() on a non-empty directory should fail');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await createDirectory(t, 'dir', root);
|
||||
await promise_rejects(t, new TypeError(), dir.removeEntry(''));
|
||||
}, 'removeEntry() with empty name should fail');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await createDirectory(t, 'dir', root);
|
||||
await promise_rejects(t, new TypeError(), dir.removeEntry(kCurrentDirectory));
|
||||
}, `removeEntry() with "${kCurrentDirectory}" name should fail`);
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await createDirectory(t, 'dir', root);
|
||||
await promise_rejects(t, new TypeError(), dir.removeEntry(kParentDirectory));
|
||||
}, `removeEntry() with "${kParentDirectory}" name should fail`);
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir_name = 'dir-name';
|
||||
const dir = await createDirectory(t, dir_name, root);
|
||||
|
||||
const file_name = 'file-name';
|
||||
await createEmptyFile(t, file_name, dir);
|
||||
|
||||
for (let i = 0; i < kPathSeparators.length; ++i) {
|
||||
const path_with_separator = `${dir_name}${kPathSeparators[i]}${file_name}`;
|
||||
await promise_rejects(
|
||||
t, new TypeError(), root.removeEntry(path_with_separator),
|
||||
`removeEntry() must reject names containing "${kPathSeparators[i]}"`);
|
||||
}
|
||||
}, 'removeEntry() with a path separator should fail.');
|
|
@ -0,0 +1,287 @@
|
|||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'empty_blob', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, new Blob([]));
|
||||
await writer.close();
|
||||
|
||||
assert_equals(await getFileContents(handle), '');
|
||||
assert_equals(await getFileSize(handle), 0);
|
||||
}, 'write() with an empty blob to an empty file');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'valid_blob', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, new Blob(['1234567890']));
|
||||
await writer.close();
|
||||
|
||||
assert_equals(await getFileContents(handle), '1234567890');
|
||||
assert_equals(await getFileSize(handle), 10);
|
||||
}, 'write() a blob to an empty file');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'blob_with_offset', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, new Blob(['1234567890']));
|
||||
await writer.write(4, new Blob(['abc']));
|
||||
await writer.close();
|
||||
|
||||
assert_equals(await getFileContents(handle), '1234abc890');
|
||||
assert_equals(await getFileSize(handle), 10);
|
||||
}, 'write() called with a blob and a valid offset');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'bad_offset', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await promise_rejects(
|
||||
t, 'InvalidStateError', writer.write(4, new Blob(['abc'])));
|
||||
await writer.close();
|
||||
|
||||
assert_equals(await getFileContents(handle), '');
|
||||
assert_equals(await getFileSize(handle), 0);
|
||||
}, 'write() called with an invalid offset');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'empty_string', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, '');
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), '');
|
||||
assert_equals(await getFileSize(handle), 0);
|
||||
}, 'write() with an empty string to an empty file');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'valid_utf8_string', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, 'foo🤘');
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'foo🤘');
|
||||
assert_equals(await getFileSize(handle), 7);
|
||||
}, 'write() with a valid utf-8 string');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'string_with_unix_line_ending', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, 'foo\n');
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'foo\n');
|
||||
assert_equals(await getFileSize(handle), 4);
|
||||
}, 'write() with a string with unix line ending preserved');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle =
|
||||
await createEmptyFile(t, 'string_with_windows_line_ending', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, 'foo\r\n');
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'foo\r\n');
|
||||
assert_equals(await getFileSize(handle), 5);
|
||||
}, 'write() with a string with windows line ending preserved');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'empty_array_buffer', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
let buf = new ArrayBuffer(0);
|
||||
await writer.write(0, buf);
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), '');
|
||||
assert_equals(await getFileSize(handle), 0);
|
||||
}, 'write() with an empty array buffer to an empty file');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle =
|
||||
await createEmptyFile(t, 'valid_string_typed_byte_array', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
let buf = new ArrayBuffer(3);
|
||||
let intView = new Uint8Array(buf);
|
||||
intView[0] = 0x66;
|
||||
intView[1] = 0x6f;
|
||||
intView[2] = 0x6f;
|
||||
await writer.write(0, buf);
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'foo');
|
||||
assert_equals(await getFileSize(handle), 3);
|
||||
}, 'write() with a valid typed array buffer');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'trunc_shrink', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, new Blob(['1234567890']));
|
||||
await writer.truncate(5);
|
||||
await writer.close();
|
||||
|
||||
assert_equals(await getFileContents(handle), '12345');
|
||||
assert_equals(await getFileSize(handle), 5);
|
||||
}, 'truncate() to shrink a file');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'trunc_grow', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, new Blob(['abc']));
|
||||
await writer.truncate(5);
|
||||
await writer.close();
|
||||
|
||||
assert_equals(await getFileContents(handle), 'abc\0\0');
|
||||
assert_equals(await getFileSize(handle), 5);
|
||||
}, 'truncate() to grow a file');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await createDirectory(t, 'parent_dir', root);
|
||||
const file_name = 'create_writer_fails_when_dir_removed.txt';
|
||||
const handle = await createEmptyFile(t, file_name, dir);
|
||||
|
||||
await root.removeEntry('parent_dir', {recursive: true});
|
||||
await promise_rejects(t, 'NotFoundError', handle.createWriter());
|
||||
}, 'createWriter() fails when parent directory is removed');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await createDirectory(t, 'parent_dir', root);
|
||||
const file_name = 'write_fails_when_dir_removed.txt';
|
||||
const handle = await createEmptyFile(t, file_name, dir);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await root.removeEntry('parent_dir', {recursive: true});
|
||||
await promise_rejects(t, 'NotFoundError', writer.write(0, new Blob(['foo'])));
|
||||
}, 'write() fails when parent directory is removed');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await createDirectory(t, 'parent_dir', root);
|
||||
const file_name = 'truncate_fails_when_dir_removed.txt';
|
||||
const handle = await createEmptyFile(t, file_name, dir);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await root.removeEntry('parent_dir', {recursive: true});
|
||||
await promise_rejects(t, 'NotFoundError', writer.truncate(0));
|
||||
}, 'truncate() fails when parent directory is removed');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await createDirectory(t, 'parent_dir', root);
|
||||
const file_name = 'close_fails_when_dir_removed.txt';
|
||||
const handle = await createEmptyFile(t, file_name, dir);
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob(['foo']));
|
||||
|
||||
await root.removeEntry('parent_dir', {recursive: true});
|
||||
await promise_rejects(t, 'NotFoundError', writer.close());
|
||||
}, 'atomic writes: close() fails when parent directory is removed');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'atomic_writes.txt', root);
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob(['foox']));
|
||||
|
||||
const writer2 = await handle.createWriter();
|
||||
await writer2.write(0, new Blob(['bar']));
|
||||
|
||||
assert_equals(await getFileSize(handle), 0);
|
||||
|
||||
await writer2.close();
|
||||
assert_equals(await getFileContents(handle), 'bar');
|
||||
assert_equals(await getFileSize(handle), 3);
|
||||
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'foox');
|
||||
assert_equals(await getFileSize(handle), 4);
|
||||
}, 'atomic writes: writers make atomic changes on close');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'atomic_write_after_close.txt', root);
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob(['foo']));
|
||||
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'foo');
|
||||
assert_equals(await getFileSize(handle), 3);
|
||||
|
||||
await promise_rejects(
|
||||
t, 'InvalidStateError', writer.write(0, new Blob(['abc'])));
|
||||
}, 'atomic writes: write() after close() fails');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle =
|
||||
await createEmptyFile(t, 'atomic_truncate_after_close.txt', root);
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob(['foo']));
|
||||
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'foo');
|
||||
assert_equals(await getFileSize(handle), 3);
|
||||
|
||||
await promise_rejects(t, 'InvalidStateError', writer.truncate(0));
|
||||
}, 'atomic writes: truncate() after close() fails');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'atomic_close_after_close.txt', root);
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob(['foo']));
|
||||
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'foo');
|
||||
assert_equals(await getFileSize(handle), 3);
|
||||
|
||||
await promise_rejects(t, 'InvalidStateError', writer.close());
|
||||
}, 'atomic writes: close() after close() fails');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'there_can_be_only_one.txt', root);
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob(['foo']));
|
||||
|
||||
// This test might be flaky if there is a race condition allowing
|
||||
// close() to be called multiple times.
|
||||
let success_promises =
|
||||
[...Array(100)].map(() => writer.close().then(() => 1).catch(() => 0));
|
||||
let close_attempts = await Promise.all(success_promises);
|
||||
let success_count = close_attempts.reduce((x, y) => x + y);
|
||||
assert_equals(success_count, 1);
|
||||
}, 'atomic writes: only one close() operation may succeed');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createFileWithContents(
|
||||
t, 'atomic_file_is_copied.txt', 'fooks', root);
|
||||
const writer = await handle.createWriter({keepExistingData: true});
|
||||
|
||||
await writer.write(0, new Blob(['bar']));
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'barks');
|
||||
assert_equals(await getFileSize(handle), 5);
|
||||
}, 'createWriter({keepExistingData: true}): atomic writer initialized with source contents');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createFileWithContents(
|
||||
t, 'atomic_file_is_not_copied.txt', 'very long string', root);
|
||||
const writer = await handle.createWriter({keepExistingData: false});
|
||||
|
||||
await writer.write(0, new Blob(['bar']));
|
||||
assert_equals(await getFileContents(handle), 'very long string');
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'bar');
|
||||
assert_equals(await getFileSize(handle), 3);
|
||||
}, 'createWriter({keepExistingData: false}): atomic writer initialized with empty file');
|
||||
|
||||
directory_test(async (t, root) => {
|
||||
const dir = await createDirectory(t, 'parent_dir', root);
|
||||
const file_name = 'atomic_writer_persists_removed.txt';
|
||||
const handle = await createFileWithContents(t, file_name, 'foo', dir);
|
||||
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob(['bar']));
|
||||
|
||||
await dir.removeEntry(file_name);
|
||||
await promise_rejects(t, 'NotFoundError', getFileContents(handle));
|
||||
|
||||
await writer.close();
|
||||
assert_equals(await getFileContents(handle), 'bar');
|
||||
assert_equals(await getFileSize(handle), 3);
|
||||
}, 'atomic writes: writer persists file on close, even if file is removed');
|
Loading…
Add table
Add a link
Reference in a new issue