diff --git a/testing/web-platform/meta/fs/FileSystemDirectoryHandle-removeEntry.https.any.js.ini b/testing/web-platform/meta/fs/FileSystemDirectoryHandle-removeEntry.https.any.js.ini index 9c413c62150b..5b68c2a5902d 100644 --- a/testing/web-platform/meta/fs/FileSystemDirectoryHandle-removeEntry.https.any.js.ini +++ b/testing/web-platform/meta/fs/FileSystemDirectoryHandle-removeEntry.https.any.js.ini @@ -26,7 +26,7 @@ [removeEntry() with a path separator should fail.] expected: FAIL - [removeEntry() while the file has an open writable succeeds] + [removeEntry() while the file has an open writable fails] expected: FAIL @@ -58,5 +58,5 @@ [removeEntry() with a path separator should fail.] expected: FAIL - [removeEntry() while the file has an open writable succeeds] + [removeEntry() while the file has an open writable fails] expected: FAIL diff --git a/testing/web-platform/tests/fs/resources/messaging-serialize-helpers.js b/testing/web-platform/tests/fs/resources/messaging-serialize-helpers.js index 063fe4173d98..13c900c0cbcf 100644 --- a/testing/web-platform/tests/fs/resources/messaging-serialize-helpers.js +++ b/testing/web-platform/tests/fs/resources/messaging-serialize-helpers.js @@ -30,12 +30,17 @@ async function serialize_handle(handle) { // serialized properties shared by both FileSystemFileHandle and // FileSystemDirectoryHandle. async function serialize_file_system_handle(handle) { - const read_permission = - await handle.queryPermission({ mode: 'read' }); - - const write_permission = - await handle.queryPermission({ mode: 'readwrite' }) + let read_permission = "granted"; + let write_permission = "granted"; + // query-permission is part of the File System Acecss API + // https://wicg.github.io/file-system-access, which may not be supported + if ("queryPermission" in FileSystemHandle.prototype) { + read_permission = + await handle.queryPermission({ mode: 'read' }); + write_permission = + await handle.queryPermission({ mode: 'readwrite' }) + } return { kind: handle.kind, name: handle.name, diff --git a/testing/web-platform/tests/fs/resources/test-helpers.js b/testing/web-platform/tests/fs/resources/test-helpers.js index 91834e0677a3..e27666a1beb7 100644 --- a/testing/web-platform/tests/fs/resources/test-helpers.js +++ b/testing/web-platform/tests/fs/resources/test-helpers.js @@ -86,3 +86,21 @@ function garbageCollect() { if (self.gc) self.gc(); }; + +async function cleanup(test, value, cleanup_func) { + test.add_cleanup(async () => { + try { + await cleanup_func(); + } catch (e) { + // Ignore any errors when removing files, as tests might already remove + // the file. + } + }); + return value; +} + +async function cleanup_writable(test, value) { + return cleanup(test, value, async () => { + value.close(); + }); +} diff --git a/testing/web-platform/tests/fs/script-tests/FileSystemBaseHandle-IndexedDB.js b/testing/web-platform/tests/fs/script-tests/FileSystemBaseHandle-IndexedDB.js index 855e52f04ddf..15a0c2a3b579 100644 --- a/testing/web-platform/tests/fs/script-tests/FileSystemBaseHandle-IndexedDB.js +++ b/testing/web-platform/tests/fs/script-tests/FileSystemBaseHandle-IndexedDB.js @@ -6,7 +6,6 @@ directory_test(async (t, root_dir) => { const db = await createDatabase(t, db => { const store = db.createObjectStore('store'); }); - t.add_cleanup(() => deleteAllDatabases(t)); const value = handles; @@ -28,7 +27,6 @@ directory_test(async (t, root_dir) => { const db = await createDatabase(t, db => { const store = db.createObjectStore('store'); }); - t.add_cleanup(() => deleteAllDatabases(t)); const value = handles; @@ -53,7 +51,6 @@ directory_test(async (t, root_dir) => { const db = await createDatabase(t, db => { const store = db.createObjectStore('store'); }); - t.add_cleanup(() => deleteAllDatabases(t)); const value = {handles, blob: new Blob(["foobar"])}; @@ -80,7 +77,6 @@ directory_test(async (t, root_dir) => { const db = await createDatabase(t, db => { const store = db.createObjectStore('store'); }); - t.add_cleanup(() => deleteAllDatabases(t)); const value = handles; @@ -107,7 +103,6 @@ directory_test(async (t, root_dir) => { const db = await createDatabase(t, db => { const store = db.createObjectStore('store', {keyPath: 'key'}); }); - t.add_cleanup(() => deleteAllDatabases(t)); const value = handles; let tx = db.transaction('store', 'readwrite'); diff --git a/testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-removeEntry.js b/testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-removeEntry.js index 01e2ebe10889..c28e46ca2e14 100644 --- a/testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-removeEntry.js +++ b/testing/web-platform/tests/fs/script-tests/FileSystemDirectoryHandle-removeEntry.js @@ -23,7 +23,6 @@ directory_test(async (t, root) => { await root.removeEntry('dir-to-remove'); assert_array_equals(await getSortedDirectoryEntries(root), ['file-to-keep']); - await promise_rejects_dom(t, 'NotFoundError', getSortedDirectoryEntries(dir)); }, 'removeEntry() to remove an empty directory'); directory_test(async (t, root) => { @@ -93,11 +92,13 @@ directory_test(async (t, root) => { await createFileWithContents(t, 'file-to-keep', 'abc', root); const writable = await handle.createWritable(); - await root.removeEntry('file-to-remove'); - await promise_rejects_dom(t, 'NotFoundError', getFileContents(handle)); + await promise_rejects_dom( + t, 'InvalidModificationError', root.removeEntry('file-to-remove')); await writable.close(); + await root.removeEntry('file-to-remove'); + assert_array_equals( await getSortedDirectoryEntries(root), - ['file-to-keep', 'file-to-remove']); -}, 'removeEntry() while the file has an open writable succeeds'); + ['file-to-keep']); +}, 'removeEntry() while the file has an open writable fails'); diff --git a/testing/web-platform/tests/fs/script-tests/FileSystemFileHandle-move.js b/testing/web-platform/tests/fs/script-tests/FileSystemFileHandle-move.js index 5b2d25faf345..4057b0f8d46a 100644 --- a/testing/web-platform/tests/fs/script-tests/FileSystemFileHandle-move.js +++ b/testing/web-platform/tests/fs/script-tests/FileSystemFileHandle-move.js @@ -74,7 +74,7 @@ directory_test(async (t, root) => { const handle = await createFileWithContents(t, 'file-before', 'abc', root); // Cannot rename handle with an active writable. - const stream = await handle.createWritable(); + const stream = await cleanup_writable(t, await handle.createWritable()); await promise_rejects_dom( t, 'NoModificationAllowedError', handle.move('file-after')); @@ -90,7 +90,7 @@ directory_test(async (t, root) => { await createFileWithContents(t, 'file-after', '123', root); // Cannot overwrite a handle with an active writable. - const stream = await handle_dest.createWritable(); + const stream = await cleanup_writable(t, await handle_dest.createWritable()); await promise_rejects_dom( t, 'NoModificationAllowedError', handle.move('file-after')); @@ -259,7 +259,7 @@ directory_test(async (t, root) => { const file = await createFileWithContents(t, 'file', 'abc', dir_src); // Cannot move handle with an active writable. - const stream = await file.createWritable(); + const stream = await cleanup_writable(t, await file.createWritable()); await promise_rejects_dom(t, 'NoModificationAllowedError', file.move(dir_dest)); assert_array_equals( @@ -282,7 +282,7 @@ directory_test(async (t, root) => { const file = await createFileWithContents(t, 'file-before', 'abc', dir_src); // Cannot move handle with an active writable. - const stream = await file.createWritable(); + const stream = await cleanup_writable(t, await file.createWritable()); await promise_rejects_dom(t, 'NoModificationAllowedError', file.move(dir_dest)); assert_array_equals( @@ -307,7 +307,7 @@ directory_test(async (t, root) => { const file_dest = await createFileWithContents(t, 'file', '123', dir_dest); // Cannot overwrite handle with an active writable. - const stream = await file_dest.createWritable(); + const stream = await cleanup_writable(t, await file_dest.createWritable()); await promise_rejects_dom(t, 'NoModificationAllowedError', file.move(dir_dest)); assert_array_equals( @@ -334,7 +334,7 @@ directory_test(async (t, root) => { await createFileWithContents(t, 'file-dest', '123', dir_dest); // Cannot overwrite handle with an active writable. - const stream = await file_dest.createWritable(); + const stream = await cleanup_writable(t, await file_dest.createWritable()); await promise_rejects_dom( t, 'NoModificationAllowedError', file.move(dir_dest, 'file-dest'));