diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/periodic-background-sync | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/periodic-background-sync')
4 files changed, 76 insertions, 0 deletions
diff --git a/testing/web-platform/tests/periodic-background-sync/META.yml b/testing/web-platform/tests/periodic-background-sync/META.yml new file mode 100644 index 0000000000..35224c093e --- /dev/null +++ b/testing/web-platform/tests/periodic-background-sync/META.yml @@ -0,0 +1,4 @@ +spec: https://wicg.github.io/periodic-background-sync/ +suggested_reviewers: + - jakearchibald + - mugdhalakhani diff --git a/testing/web-platform/tests/periodic-background-sync/idlharness.https.any.js b/testing/web-platform/tests/periodic-background-sync/idlharness.https.any.js new file mode 100644 index 0000000000..6f3b6fdf87 --- /dev/null +++ b/testing/web-platform/tests/periodic-background-sync/idlharness.https.any.js @@ -0,0 +1,20 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js +// META: timeout=long + +'use strict'; + +// https://wicg.github.io/periodic-background-sync/ + +idl_test( + ['periodic-background-sync'], + ['service-workers', 'html', 'dom'], + async idl_array => { + idl_array.add_objects({ + ServiceWorkerGlobalScope: ['self', 'onperiodicsync'], + ServiceWorkerRegistration: ['registration'], + PeriodicSyncManager: ['registration.periodicSync'], + PeriodicSyncEvent: ['new PeriodicSyncEvent("tag")'], + }); + } +); diff --git a/testing/web-platform/tests/periodic-background-sync/periodicsync.https.window.js b/testing/web-platform/tests/periodic-background-sync/periodicsync.https.window.js new file mode 100644 index 0000000000..b68e4976a8 --- /dev/null +++ b/testing/web-platform/tests/periodic-background-sync/periodicsync.https.window.js @@ -0,0 +1,36 @@ +// META: script=/common/get-host-info.sub.js +// META: script=/service-workers/service-worker/resources/test-helpers.sub.js + +'use strict' + +promise_test(async test => { + const script = 'service_workers/sw.js'; + const scope = 'service_workers' + location.pathname; + + const serviceWorkerRegistration = + await service_worker_unregister_and_register(test, script, scope); + + assert_equals( + serviceWorkerRegistration.active, null, + 'There must not be an activated worker'); + + await promise_rejects_dom( + test, 'InvalidStateError', + serviceWorkerRegistration.periodicSync.register( + 'test_tag'), + 'register() must reject on pending and installing workers'); +}, 'Periodic Background Sync requires an activated Service Worker'); + +promise_test(async test => { + const script = 'service_workers/sw.js'; + const scope = 'service_workers' + location.pathname; + + const serviceWorkerRegistration = + await service_worker_unregister_and_register(test, script, scope); + + assert_equals( + serviceWorkerRegistration.active, null, + 'There must not be an activated worker'); + + await serviceWorkerRegistration.periodicSync.unregister('test_tag'); + }, 'Periodic Background Sync unregister silently succeeds when Service Worker is unactivated'); diff --git a/testing/web-platform/tests/periodic-background-sync/service_workers/sw.js b/testing/web-platform/tests/periodic-background-sync/service_workers/sw.js new file mode 100644 index 0000000000..87351c1d2f --- /dev/null +++ b/testing/web-platform/tests/periodic-background-sync/service_workers/sw.js @@ -0,0 +1,16 @@ +// The source to post setup and completion results to. +let source = null; + +function sendMessageToDocument(msg) { + source.postMessage(msg); +} + +// Notify the document that the SW is registered and ready. +self.addEventListener('message', event => { + source = event.source; + sendMessageToDocument('ready'); +}); + +self.addEventListener('periodicsync', event => { + sendMessageToDocument('periodicsync event received!'); +}); |