The spec says notifications are associated with a service worker registration, and getNotifications() is defined to return notifications "whose service worker registration is this". https://notifications.spec.whatwg.org/#dom-serviceworkerregistration-getnotifications But in reality WebKit and Gecko instead use scope for that: * WebKit: https://searchfox.org/wubkat/rev/d477c762a9ecbbc8dedf3ca7a6a2a079577bf60c/Source/WebCore/workers/service/ServiceWorkerRegistration.cpp#351 * Gecko https://searchfox.org/mozilla-central/rev/f19d5bd57655b99f7cd8654674833890c09aed7d/dom/serviceworkers/ServiceWorkerRegistration.cpp#424 while Blink uses registration ID per the spec: https://source.chromium.org/chromium/chromium/src/+/main:third_party/blink/renderer/modules/notifications/service_worker_registration_notifications.cc;l=103-105;drc=b388e927ed4f5c9ef43c899eae909195636af496 This test follows the spec, following the discussion with :asuth. Differential Revision: https://phabricator.services.mozilla.com/D202612
32 lines
1.2 KiB
JavaScript
32 lines
1.2 KiB
JavaScript
// META: script=/resources/testdriver.js
|
|
// META: script=/resources/testdriver-vendor.js
|
|
// META: script=resources/helpers.js
|
|
|
|
"use strict";
|
|
|
|
/** @type {ServiceWorkerRegistration} */
|
|
let registration;
|
|
|
|
promise_setup(async () => {
|
|
registration = await getActiveServiceWorker("noop-sw.js");
|
|
await trySettingPermission("granted");
|
|
});
|
|
|
|
promise_test(async (t) => {
|
|
t.add_cleanup(closeAllNotifications);
|
|
|
|
await registration.showNotification("foo");
|
|
await registration.unregister();
|
|
const newRegistration = await getActiveServiceWorker("noop-sw.js");
|
|
const notifications = await newRegistration.getNotifications();
|
|
|
|
// The spec says notifications should be associated with service worker registration
|
|
// and thus unregistering should dissociate the notification.
|
|
//
|
|
// (Step 5.2 of https://notifications.spec.whatwg.org/#dom-serviceworkerregistration-getnotifications)
|
|
// > Let notifications be a list of all notifications in the list of notifications whose origin
|
|
// > is same origin with origin, whose service worker registration is this, and whose tag, if tag
|
|
// > is not the empty string, is tag.
|
|
assert_equals(notifications.length, 0, "Should return zero notification");
|
|
}, "A new SW registration gets no previous notification");
|