mirror of
https://github.com/servo/servo.git
synced 2025-08-06 14:10:11 +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
|
@ -1,76 +0,0 @@
|
|||
// 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' });
|
||||
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');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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');
|
||||
|
||||
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', 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');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
const dir = await createDirectory(t, 'dir', root);
|
||||
await promise_rejects(t, new TypeError(), dir.removeEntry(""));
|
||||
}, 'removeEntry() with empty name should fail');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
const dir = await createDirectory(t, 'dir', root);
|
||||
await promise_rejects(t, new TypeError(), dir.removeEntry(kCurrentDirectory));
|
||||
}, `removeEntry() with "${kCurrentDirectory}" name should fail`);
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
const dir = await createDirectory(t, 'dir', root);
|
||||
await promise_rejects(t, new TypeError(), dir.removeEntry(kParentDirectory));
|
||||
}, `removeEntry() with "${kParentDirectory}" name should fail`);
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
|
||||
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.');
|
|
@ -1,106 +0,0 @@
|
|||
// 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(() => 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');
|
||||
|
||||
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(() => 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');
|
||||
|
||||
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(() => 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');
|
||||
|
||||
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');
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
await promise_rejects(t, new TypeError(), dir.getDirectory("", { create: true }));
|
||||
await promise_rejects(t, new TypeError(), dir.getDirectory("", { create: false }));
|
||||
}, 'getDirectory() with empty name');
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
await promise_rejects(t, new TypeError(), dir.getDirectory(kCurrentDirectory));
|
||||
await promise_rejects(t, new TypeError(), dir.getDirectory(kCurrentDirectory, { create: true }));
|
||||
}, `getDirectory() with "${kCurrentDirectory}" name`);
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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`);
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
|
||||
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');
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
|
||||
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');
|
|
@ -1,111 +0,0 @@
|
|||
// 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(() => 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');
|
||||
|
||||
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.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');
|
||||
|
||||
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.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');
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
await promise_rejects(t, new TypeError(), dir.getFile("", { create: true }));
|
||||
await promise_rejects(t, new TypeError(), dir.getFile("", { create: false }));
|
||||
}, 'getFile() with empty name');
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
await promise_rejects(t, new TypeError(), dir.getFile(kCurrentDirectory));
|
||||
await promise_rejects(t, new TypeError(), dir.getFile(kCurrentDirectory, { create: true }));
|
||||
}, `getFile() with "${kCurrentDirectory}" name`);
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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`);
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
|
||||
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.');
|
||||
|
||||
promise_test(async t => {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
|
||||
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,4 @@
|
|||
// META: script=/resources/testdriver.js
|
||||
// META: script=resources/test-helpers.js
|
||||
// META: script=resources/native-fs-test-helpers.js
|
||||
// META: script=script-tests/FileSystemDirectoryHandle-getDirectory.js
|
|
@ -0,0 +1,4 @@
|
|||
// META: script=/resources/testdriver.js
|
||||
// META: script=resources/test-helpers.js
|
||||
// META: script=resources/native-fs-test-helpers.js
|
||||
// META: script=script-tests/FileSystemDirectoryHandle-getFile.js
|
|
@ -0,0 +1,4 @@
|
|||
// META: script=/resources/testdriver.js
|
||||
// META: script=resources/test-helpers.js
|
||||
// META: script=resources/native-fs-test-helpers.js
|
||||
// META: script=script-tests/FileSystemDirectoryHandle-removeEntry.js
|
|
@ -0,0 +1,4 @@
|
|||
// META: script=/resources/testdriver.js
|
||||
// META: script=resources/test-helpers.js
|
||||
// META: script=resources/native-fs-test-helpers.js
|
||||
// META: script=script-tests/FileSystemWriter.js
|
|
@ -0,0 +1,49 @@
|
|||
// This file defines a directory_test() function that can be used to define
|
||||
// tests that require a FileSystemDirectoryHandle. The implementation of that
|
||||
// function in this file will ask the user to select an empty directory and
|
||||
// uses that directory.
|
||||
//
|
||||
// Another implementation of this function exists in
|
||||
// sandboxed-fs-test-helpers.js, where that version uses the sandboxed file
|
||||
// system instead.
|
||||
|
||||
const directory_promise = (async () => {
|
||||
await new Promise(resolve => {
|
||||
window.addEventListener('DOMContentLoaded', resolve);
|
||||
});
|
||||
|
||||
await window.test_driver.bless(
|
||||
'show a file picker.<br />Please select an empty directory');
|
||||
const entries = await self.chooseFileSystemEntries({type: 'openDirectory'});
|
||||
assert_true(entries instanceof FileSystemHandle);
|
||||
assert_true(entries instanceof FileSystemDirectoryHandle);
|
||||
for await (const entry of entries.getEntries()) {
|
||||
assert_unreached('Selected directory is not empty');
|
||||
}
|
||||
return entries;
|
||||
})();
|
||||
|
||||
function directory_test(func, description) {
|
||||
promise_test(async t => {
|
||||
const directory = await directory_promise;
|
||||
// To be resilient against tests not cleaning up properly, cleanup before
|
||||
// every test.
|
||||
for await (let entry of directory.getEntries()) {
|
||||
await directory.removeEntry(entry.name, {recursive: entry.isDirectory});
|
||||
}
|
||||
await func(t, directory);
|
||||
}, description);
|
||||
}
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
assert_equals(await dir.queryPermission({writable: false}), 'granted');
|
||||
}, 'User succesfully selected an empty directory.');
|
||||
|
||||
directory_test(async (t, dir) => {
|
||||
const status = await dir.queryPermission({writable: true});
|
||||
if (status == 'granted')
|
||||
return;
|
||||
|
||||
await window.test_driver.bless('ask for write permission');
|
||||
assert_equals(await dir.requestPermission({writable: true}), 'granted');
|
||||
}, 'User granted write access.');
|
|
@ -0,0 +1,25 @@
|
|||
// This file defines a directory_test() function that can be used to define
|
||||
// tests that require a FileSystemDirectoryHandle. The implementation of that
|
||||
// function in this file will return an empty directory in the sandboxed file
|
||||
// system.
|
||||
//
|
||||
// Another implementation of this function exists in native-fs-test-helpers.js,
|
||||
// where that version uses the native file system instead.
|
||||
|
||||
async function cleanupSandboxedFileSystem() {
|
||||
const dir =
|
||||
await FileSystemDirectoryHandle.getSystemDirectory({type: 'sandbox'});
|
||||
for await (let entry of dir.getEntries())
|
||||
await dir.removeEntry(entry.name, {recursive: entry.isDirectory});
|
||||
}
|
||||
|
||||
function directory_test(func, description) {
|
||||
promise_test(async t => {
|
||||
// To be extra resilient against bad tests, cleanup before every test.
|
||||
await cleanupSandboxedFileSystem();
|
||||
|
||||
const dir =
|
||||
await FileSystemDirectoryHandle.getSystemDirectory({type: 'sandbox'});
|
||||
await func(t, dir);
|
||||
}, description);
|
||||
}
|
|
@ -1,95 +1,87 @@
|
|||
// A special path component meaning "this directory."
|
||||
const kCurrentDirectory = ".";
|
||||
const kCurrentDirectory = '.';
|
||||
|
||||
// A special path component meaning "the parent directory."
|
||||
const kParentDirectory = "..";
|
||||
const kParentDirectory = '..';
|
||||
|
||||
// Array of separators used to separate components in hierarchical paths.
|
||||
let kPathSeparators;
|
||||
if (navigator.userAgent.includes("Windows NT")) {
|
||||
// Windows uses both '/' and '\' as path separators.
|
||||
kPathSeparators = ['/', '\\' ];
|
||||
if (navigator.userAgent.includes('Windows NT')) {
|
||||
// Windows uses both '/' and '\' as path separators.
|
||||
kPathSeparators = ['/', '\\'];
|
||||
} else {
|
||||
kPathSeparators = [ '/' ];
|
||||
}
|
||||
|
||||
async function cleanupSandboxedFileSystem() {
|
||||
const dir = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
for await (let entry of dir.getEntries())
|
||||
dir.removeEntry(entry.name, { recursive: entry.isDirectory });
|
||||
kPathSeparators = ['/'];
|
||||
}
|
||||
|
||||
async function getFileSize(handle) {
|
||||
const file = await handle.getFile();
|
||||
return file.size;
|
||||
const file = await handle.getFile();
|
||||
return file.size;
|
||||
}
|
||||
|
||||
async function getFileContents(handle) {
|
||||
const file = await handle.getFile();
|
||||
return new Response(file).text();
|
||||
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;
|
||||
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;
|
||||
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 createDirectory(test, name, parent) {
|
||||
const parent_dir_handle = parent ? parent :
|
||||
await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
|
||||
const new_dir_handle = await parent_dir_handle.getDirectory(name, { create: true });
|
||||
const new_dir_handle = await parent.getDirectory(name, {create: true});
|
||||
test.add_cleanup(async () => {
|
||||
try {
|
||||
await parent_dir_handle.removeEntry(name, { recursive: true });
|
||||
} catch (e) {
|
||||
// Ignore any errors when removing directories, as tests might
|
||||
// have already removed the directory.
|
||||
}
|
||||
try {
|
||||
await parent.removeEntry(name, {recursive: true});
|
||||
} catch (e) {
|
||||
// Ignore any errors when removing directories, as tests might
|
||||
// have already removed the directory.
|
||||
}
|
||||
});
|
||||
return new_dir_handle;
|
||||
}
|
||||
|
||||
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 dir.removeEntry(name);
|
||||
} 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;
|
||||
const handle = await parent.getFile(name, {create: true});
|
||||
test.add_cleanup(async () => {
|
||||
try {
|
||||
await parent.removeEntry(name);
|
||||
} 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]));
|
||||
await writer.close();
|
||||
return handle;
|
||||
const handle = await createEmptyFile(test, name, parent);
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob([contents]));
|
||||
await writer.close();
|
||||
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();
|
||||
// TODO(https://github.com/web-platform-tests/wpt/issues/7899): Change to
|
||||
// some sort of cross-browser GC trigger.
|
||||
if (self.gc)
|
||||
self.gc();
|
||||
};
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
// META: script=resources/test-helpers.js
|
||||
// META: script=resources/sandboxed-fs-test-helpers.js
|
||||
// META: script=script-tests/FileSystemDirectoryHandle-getDirectory.js
|
|
@ -0,0 +1,3 @@
|
|||
// META: script=resources/test-helpers.js
|
||||
// META: script=resources/sandboxed-fs-test-helpers.js
|
||||
// META: script=script-tests/FileSystemDirectoryHandle-getFile.js
|
|
@ -0,0 +1,3 @@
|
|||
// META: script=resources/test-helpers.js
|
||||
// META: script=resources/sandboxed-fs-test-helpers.js
|
||||
// META: script=script-tests/FileSystemDirectoryHandle-removeEntry.js
|
|
@ -0,0 +1,3 @@
|
|||
// META: script=resources/test-helpers.js
|
||||
// META: script=resources/sandboxed-fs-test-helpers.js
|
||||
// META: script=script-tests/FileSystemWriter.js
|
|
@ -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.');
|
|
@ -1,54 +1,51 @@
|
|||
// META: script=resources/test-helpers.js
|
||||
promise_test(async t => cleanupSandboxedFileSystem(),
|
||||
'Cleanup to setup test environment');
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'empty_blob', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'empty_blob');
|
||||
const writer = await handle.createWriter();
|
||||
await writer.write(0, new Blob([]));
|
||||
await writer.close();
|
||||
|
||||
await writer.write(0, new Blob([]));
|
||||
await writer.close();
|
||||
|
||||
assert_equals(await getFileContents(handle), '');
|
||||
assert_equals(await getFileSize(handle), 0);
|
||||
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();
|
||||
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();
|
||||
await writer.write(0, new Blob(['1234567890']));
|
||||
await writer.close();
|
||||
|
||||
assert_equals(await getFileContents(handle), '1234567890');
|
||||
assert_equals(await getFileSize(handle), 10);
|
||||
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();
|
||||
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();
|
||||
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);
|
||||
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();
|
||||
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();
|
||||
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);
|
||||
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, 'empty_string');
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'empty_string', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, '');
|
||||
|
@ -57,8 +54,8 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 0);
|
||||
}, 'write() with an empty string to an empty file');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'valid_utf8_string');
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'valid_utf8_string', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
await writer.write(0, 'foo🤘');
|
||||
|
@ -67,8 +64,8 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 7);
|
||||
}, 'write() with a valid utf-8 string');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'string_with_unix_line_ending');
|
||||
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');
|
||||
|
@ -77,8 +74,9 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 4);
|
||||
}, 'write() with a string with unix line ending preserved');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'string_with_windows_line_ending');
|
||||
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');
|
||||
|
@ -87,8 +85,8 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 5);
|
||||
}, 'write() with a string with windows line ending preserved');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'empty_array_buffer');
|
||||
directory_test(async (t, root) => {
|
||||
const handle = await createEmptyFile(t, 'empty_array_buffer', root);
|
||||
const writer = await handle.createWriter();
|
||||
|
||||
let buf = new ArrayBuffer(0);
|
||||
|
@ -98,8 +96,9 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 0);
|
||||
}, 'write() with an empty array buffer to an empty file');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'valid_string_typed_byte_array');
|
||||
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);
|
||||
|
@ -113,32 +112,31 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 3);
|
||||
}, 'write() with a valid typed array buffer');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'trunc_shrink');
|
||||
const writer = await handle.createWriter();
|
||||
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();
|
||||
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);
|
||||
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();
|
||||
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();
|
||||
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);
|
||||
assert_equals(await getFileContents(handle), 'abc\0\0');
|
||||
assert_equals(await getFileSize(handle), 5);
|
||||
}, 'truncate() to grow a file');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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);
|
||||
|
@ -147,8 +145,7 @@ promise_test(async t => {
|
|||
await promise_rejects(t, 'NotFoundError', handle.createWriter());
|
||||
}, 'createWriter() fails when parent directory is removed');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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);
|
||||
|
@ -158,8 +155,7 @@ promise_test(async t => {
|
|||
await promise_rejects(t, 'NotFoundError', writer.write(0, new Blob(['foo'])));
|
||||
}, 'write() fails when parent directory is removed');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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);
|
||||
|
@ -169,8 +165,7 @@ promise_test(async t => {
|
|||
await promise_rejects(t, 'NotFoundError', writer.truncate(0));
|
||||
}, 'truncate() fails when parent directory is removed');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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);
|
||||
|
@ -181,8 +176,8 @@ promise_test(async t => {
|
|||
await promise_rejects(t, 'NotFoundError', writer.close());
|
||||
}, 'atomic writes: close() fails when parent directory is removed');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'atomic_writes.txt');
|
||||
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']));
|
||||
|
||||
|
@ -200,8 +195,8 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 4);
|
||||
}, 'atomic writes: writers make atomic changes on close');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'atomic_write_after_close.txt');
|
||||
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']));
|
||||
|
||||
|
@ -209,11 +204,13 @@ promise_test(async t => {
|
|||
assert_equals(await getFileContents(handle), 'foo');
|
||||
assert_equals(await getFileSize(handle), 3);
|
||||
|
||||
await promise_rejects(t, 'InvalidStateError', writer.write(0, new Blob(['abc'])));
|
||||
await promise_rejects(
|
||||
t, 'InvalidStateError', writer.write(0, new Blob(['abc'])));
|
||||
}, 'atomic writes: write() after close() fails');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'atomic_truncate_after_close.txt');
|
||||
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']));
|
||||
|
||||
|
@ -224,8 +221,8 @@ promise_test(async t => {
|
|||
await promise_rejects(t, 'InvalidStateError', writer.truncate(0));
|
||||
}, 'atomic writes: truncate() after close() fails');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'atomic_close_after_close.txt');
|
||||
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']));
|
||||
|
||||
|
@ -236,24 +233,23 @@ promise_test(async t => {
|
|||
await promise_rejects(t, 'InvalidStateError', writer.close());
|
||||
}, 'atomic writes: close() after close() fails');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createEmptyFile(t, 'there_can_be_only_one.txt');
|
||||
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 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);
|
||||
let success_count = close_attempts.reduce((x, y) => x + y);
|
||||
assert_equals(success_count, 1);
|
||||
}, 'atomic writes: only one close() operation may succeed');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createFileWithContents(t, 'atomic_file_is_copied.txt', 'fooks');
|
||||
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']));
|
||||
|
@ -262,8 +258,9 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 5);
|
||||
}, 'createWriter({keepExistingData: true}): atomic writer initialized with source contents');
|
||||
|
||||
promise_test(async t => {
|
||||
const handle = await createFileWithContents(t, 'atomic_file_is_not_copied.txt', 'very long string');
|
||||
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']));
|
||||
|
@ -273,8 +270,7 @@ promise_test(async t => {
|
|||
assert_equals(await getFileSize(handle), 3);
|
||||
}, 'createWriter({keepExistingData: false}): atomic writer initialized with empty file');
|
||||
|
||||
promise_test(async t => {
|
||||
const root = await FileSystemDirectoryHandle.getSystemDirectory({ type: 'sandbox' });
|
||||
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);
|
Loading…
Add table
Add a link
Reference in a new issue