summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/notifications/getnotifications-sw.js
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 17:32:43 +0000
commit6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch)
treea68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/notifications/getnotifications-sw.js
parentInitial commit. (diff)
downloadthunderbird-upstream.tar.xz
thunderbird-upstream.zip
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/notifications/getnotifications-sw.js')
-rw-r--r--testing/web-platform/tests/notifications/getnotifications-sw.js56
1 files changed, 56 insertions, 0 deletions
diff --git a/testing/web-platform/tests/notifications/getnotifications-sw.js b/testing/web-platform/tests/notifications/getnotifications-sw.js
new file mode 100644
index 0000000000..331913b993
--- /dev/null
+++ b/testing/web-platform/tests/notifications/getnotifications-sw.js
@@ -0,0 +1,56 @@
+importScripts("/resources/testharness.js");
+
+async function cleanup() {
+ for (const n of await registration.getNotifications()) {
+ n.close();
+ }
+}
+
+async function test_notification(t, title) {
+ t.add_cleanup(cleanup);
+
+ const notifications = await registration.getNotifications();
+
+ assert_equals(
+ notifications.length,
+ 1,
+ "There should be one stored notification"
+ );
+ const notification = notifications[0];
+ assert_true(notification instanceof Notification, "Should be a Notification");
+ assert_equals(notification.title, title, "Title should match");
+}
+
+async function postAll(data) {
+ const clients = await self.clients.matchAll({ includeUncontrolled: true });
+ assert_true(clients.length > 0, "clients.length");
+ for (const client of clients) {
+ client.postMessage(data);
+ }
+}
+
+async function untilActivate() {
+ if (registration.active) {
+ return;
+ }
+ return new Promise(resolve => {
+ addEventListener("activate", resolve, { once: true });
+ });
+}
+
+promise_test(async t => {
+ await new Promise((resolve, reject) => {
+ self.addEventListener("message", ev => {
+ if (ev.data === "notification-created") {
+ resolve();
+ }
+ });
+ untilActivate().then(() => postAll("notification-create")).catch(reject);
+ });
+ await test_notification(t, "Created from window");
+}, "Get notification created from window");
+
+promise_test(async t => {
+ await registration.showNotification("Created here");
+ await test_notification(t, "Created here");
+}, "Create and get notification within service worker");