summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 19:33:14 +0000
commit36d22d82aa202bb199967e9512281e9a53db42c9 (patch)
tree105e8c98ddea1c1e4784a60a5a6410fa416be2de /testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js
parentInitial commit. (diff)
downloadfirefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz
firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js')
-rw-r--r--testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js93
1 files changed, 93 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js b/testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js
new file mode 100644
index 0000000000..169364cb44
--- /dev/null
+++ b/testing/web-platform/tests/fs/FileSystemFileHandle-sync-access-handle-writable-lock.https.tentative.worker.js
@@ -0,0 +1,93 @@
+importScripts('/resources/testharness.js');
+importScripts('resources/test-helpers.js');
+importScripts('resources/sandboxed-fs-test-helpers.js');
+importScripts('resources/test-helpers.js');
+
+'use strict';
+
+directory_test(async (t, root_dir) => {
+ const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});
+
+ const syncHandle1 = await fileHandle.createSyncAccessHandle();
+ t.add_cleanup(() => syncHandle1.close());
+ await promise_rejects_dom(
+ t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());
+
+ syncHandle1.close();
+ const syncHandle2 = await fileHandle.createSyncAccessHandle();
+ syncHandle2.close();
+}, 'There can only be one open access handle at any given time');
+
+directory_test(async (t, root_dir) => {
+ const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
+ const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});
+
+ const fooSyncHandle = await fooFileHandle.createSyncAccessHandle();
+ t.add_cleanup(() => fooSyncHandle.close());
+
+ const barSyncHandle1 = await barFileHandle.createSyncAccessHandle();
+ t.add_cleanup(() => barSyncHandle1.close());
+ await promise_rejects_dom(
+ t, 'NoModificationAllowedError', barFileHandle.createSyncAccessHandle());
+
+ barSyncHandle1.close();
+ const barSyncHandle2 = await barFileHandle.createSyncAccessHandle();
+ barSyncHandle2.close();
+}, 'An access handle from one file does not interfere with the creation of an' +
+ ' access handle on another file');
+
+directory_test(async (t, root_dir) => {
+ const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
+ const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});
+
+ const fooWritable = await cleanup_writable(t, await fooFileHandle.createWritable());
+ t.add_cleanup(() => fooWritable.close());
+
+ const barSyncHandle = await barFileHandle.createSyncAccessHandle();
+ t.add_cleanup(() => barSyncHandle.close());
+}, 'A writable stream from one file does not interfere with the creation of an' +
+ ' access handle on another file');
+
+directory_test(async (t, root_dir) => {
+ const fooFileHandle = await root_dir.getFileHandle('foo.test', {create: true});
+ const barFileHandle = await root_dir.getFileHandle('bar.test', {create: true});
+
+ const fooSyncHandle = await fooFileHandle.createSyncAccessHandle();
+ t.add_cleanup(() => fooSyncHandle.close());
+
+ const barWritable = await cleanup_writable(t, await barFileHandle.createWritable());
+ t.add_cleanup(() => barWritable.close());
+}, 'An access handle from one file does not interfere with the creation of a' +
+ ' writable stream on another file');
+
+directory_test(async (t, root_dir) => {
+ const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});
+
+ const syncHandle = await fileHandle.createSyncAccessHandle();
+ t.add_cleanup(() => { syncHandle.close(); });
+ await promise_rejects_dom(
+ t, 'NoModificationAllowedError', cleanup_writable(t, fileHandle.createWritable()));
+
+ syncHandle.close();
+ const writable = await cleanup_writable(t, await fileHandle.createWritable());
+ await writable.close();
+}, 'Writable streams cannot be created if there is an open access handle');
+
+directory_test(async (t, root_dir) => {
+ const fileHandle = await root_dir.getFileHandle('OPFS.test', {create: true});
+
+ const writable1 = await cleanup_writable(t, await fileHandle.createWritable());
+ const writable2 = await cleanup_writable(t, await fileHandle.createWritable());
+ await promise_rejects_dom(
+ t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());
+
+ await writable1.close();
+ await promise_rejects_dom(
+ t, 'NoModificationAllowedError', fileHandle.createSyncAccessHandle());
+
+ await writable2.close();
+ const syncHandle = await fileHandle.createSyncAccessHandle();
+ syncHandle.close();
+}, 'Access handles cannot be created if there are open Writable streams');
+
+done();