commit ab8461329f5c76c42ff47b9a1b6dc9548756dcf8
parent e829f3a7babe1a5d008f0ec3e20a4cf813568ee1
Author: Kagami Sascha Rosylight <krosylight@proton.me>
Date: Wed, 26 Nov 2025 07:34:40 +0000
Bug 1889956 - Add test for notification icon fetch event r=asuth
Unclear this is what we want given Declarative Web Push ideally shouldn't go through service worker, but for now Chrome does. Having a test should make the behavior difference clear in the dashboard.
Differential Revision: https://phabricator.services.mozilla.com/D273599
Diffstat:
3 files changed, 46 insertions(+), 0 deletions(-)
diff --git a/testing/web-platform/meta/notifications/icon-fetch.tentative.https.window.js.ini b/testing/web-platform/meta/notifications/icon-fetch.tentative.https.window.js.ini
@@ -0,0 +1,4 @@
+[icon-fetch.tentative.https.window.html]
+ expected: TIMEOUT
+ [Icon fetch should cause a corresponding fetch event in the service worker]
+ expected: TIMEOUT
diff --git a/testing/web-platform/tests/notifications/icon-fetch-sw.js b/testing/web-platform/tests/notifications/icon-fetch-sw.js
@@ -0,0 +1,12 @@
+self.addEventListener('activate', (ev) => {
+ // claim() to control fetch immediately.
+ ev.waitUntil(self.clients.claim());
+});
+
+self.addEventListener('fetch', (ev) => {
+ ev.waitUntil((async () => {
+ const client = await self.clients.get(ev.clientId);
+ client.postMessage({ url: ev.request.url });
+ })());
+ ev.respondWith(fetch(ev.request));
+})
diff --git a/testing/web-platform/tests/notifications/icon-fetch.tentative.https.window.js b/testing/web-platform/tests/notifications/icon-fetch.tentative.https.window.js
@@ -0,0 +1,30 @@
+// META: script=/resources/testdriver.js
+// META: script=/resources/testdriver-vendor.js
+// META: script=/service-workers/service-worker/resources/test-helpers.sub.js
+// META: script=resources/helpers.js
+
+let registration;
+
+promise_setup(async () => {
+ await trySettingPermission("granted");
+ registration = await prepareActiveServiceWorker("icon-fetch-sw.js");
+ await new Promise(r => navigator.serviceWorker.addEventListener("controllerchange", r, { once: true }));
+});
+
+promise_test(async t => {
+ const iconUrl = new URL("resources/icon.png", location.href).toString();
+
+ const { promise, resolve } = Promise.withResolvers();
+ navigator.serviceWorker.addEventListener("message", async ev => {
+ if (ev.data.url === iconUrl) {
+ resolve();
+ }
+ }, { signal: t.signal });
+
+ await registration.showNotification("new Notification", {
+ icon: iconUrl
+ });
+ t.add_cleanup(closeAllNotifications);
+
+ await promise;
+}, "Icon fetch should cause a corresponding fetch event in the service worker");