summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/fs/script-tests/FileSystemObserver.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 00:47:55 +0000
commit26a029d407be480d791972afb5975cf62c9360a6 (patch)
treef435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/fs/script-tests/FileSystemObserver.js
parentInitial commit. (diff)
downloadfirefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz
firefox-26a029d407be480d791972afb5975cf62c9360a6.zip
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/fs/script-tests/FileSystemObserver.js')
-rw-r--r--testing/web-platform/tests/fs/script-tests/FileSystemObserver.js57
1 files changed, 57 insertions, 0 deletions
diff --git a/testing/web-platform/tests/fs/script-tests/FileSystemObserver.js b/testing/web-platform/tests/fs/script-tests/FileSystemObserver.js
new file mode 100644
index 0000000000..2c8fd57f7c
--- /dev/null
+++ b/testing/web-platform/tests/fs/script-tests/FileSystemObserver.js
@@ -0,0 +1,57 @@
+'use strict';
+
+// This script depends on the following scripts:
+// /fs/resources/messaging-helpers.js
+// /service-worker/resources/test-helpers.sub.js
+
+promise_test(async t => {
+ function dummyCallback(records, observer) {};
+ let success = true;
+ try {
+ const observer = new FileSystemObserver(dummyCallback);
+ } catch (error) {
+ success = false;
+ }
+ assert_true(success);
+}, 'Creating a FileSystemObserver from a window succeeds');
+
+promise_test(async t => {
+ const dedicated_worker =
+ create_dedicated_worker(t, kDedicatedWorkerMessageTarget);
+ dedicated_worker.postMessage({type: 'create-file-system-observer'});
+
+ const event_watcher = new EventWatcher(t, dedicated_worker, 'message');
+ const message_event = await event_watcher.wait_for('message');
+ const response = message_event.data;
+
+ assert_true(response.createObserverSuccess);
+}, 'Creating a FileSystemObserver from a dedicated worker succeeds');
+
+if (self.SharedWorker !== undefined) {
+ promise_test(async t => {
+ const shared_worker = new SharedWorker(kSharedWorkerMessageTarget);
+ shared_worker.port.start();
+ shared_worker.port.postMessage({type: 'create-file-system-observer'});
+
+ const event_watcher = new EventWatcher(t, shared_worker.port, 'message');
+ const message_event = await event_watcher.wait_for('message');
+ const response = message_event.data;
+
+ assert_true(response.createObserverSuccess);
+ }, 'Creating a FileSystemObserver from a shared worker succeeds');
+}
+
+promise_test(async t => {
+ const scope = `${kServiceWorkerMessageTarget}?create-observer`;
+ const registration =
+ await create_service_worker(t, kServiceWorkerMessageTarget, scope);
+ await wait_for_state(t, registration.installing, 'activated');
+
+ registration.active.postMessage({type: 'create-file-system-observer'});
+
+ const event_watcher = new EventWatcher(t, navigator.serviceWorker, 'message');
+ const message_event = await event_watcher.wait_for('message');
+ const response = message_event.data;
+
+ assert_false(response.createObserverSuccess);
+}, 'Creating a FileSystemObserver from a service worker fails');