Files
sousa-gecko/testing/web-platform/tests/notifications/icon-fetch.tentative.https.window.js
T
Kagami Sascha Rosylight ab8461329f 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
2025-11-26 07:37:00 +00:00

31 lines
1012 B
JavaScript

// 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");