From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../tests/notifications/getnotifications-sw.js | 56 ++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 testing/web-platform/tests/notifications/getnotifications-sw.js (limited to 'testing/web-platform/tests/notifications/getnotifications-sw.js') 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"); -- cgit v1.2.3