| 1 |
// META: global=window-module |
| 2 |
// META: script=/resources/testdriver.js |
| 3 |
// META: script=/resources/testdriver-vendor.js |
| 4 |
// META: script=/notifications/resources/helpers.js |
| 5 |
|
| 6 |
let registration; |
| 7 |
|
| 8 |
promise_setup(async () => { |
| 9 |
await trySettingPermission("granted"); |
| 10 |
registration = await prepareActiveServiceWorker("push-sw.js"); |
| 11 |
}); |
| 12 |
|
| 13 |
promise_test(async (t) => { |
| 14 |
const promise = new Promise(r => { |
| 15 |
navigator.serviceWorker.addEventListener("message", r, { once: true }) |
| 16 |
}); |
| 17 |
|
| 18 |
const subscription = await registration.pushManager.subscribe(); |
| 19 |
t.add_cleanup(() => subscription.unsubscribe()); |
| 20 |
|
| 21 |
// https://w3c.github.io/push-api/#security-and-privacy-considerations |
| 22 |
// When a permission is revoked, the user agent MAY fire the "pushsubscriptionchange" |
| 23 |
// event for subscriptions created with that permission |
| 24 |
// |
| 25 |
// But Firefox fires pushsubscriptionchange on permission regrant instead of revocation. |
| 26 |
// https://github.com/w3c/push-api/issues/236 |
| 27 |
await trySettingPermission("prompt"); |
| 28 |
await trySettingPermission("granted"); |
| 29 |
|
| 30 |
const pushSubscriptionChangeEvent = await promise; |
| 31 |
|
| 32 |
assert_equals(pushSubscriptionChangeEvent.data.type, "pushsubscriptionchange"); |
| 33 |
assert_equals(pushSubscriptionChangeEvent.data.constructor, "PushSubscriptionChangeEvent"); |
| 34 |
assert_object_equals(pushSubscriptionChangeEvent.data.oldSubscription, subscription.toJSON()); |
| 35 |
}, "Fire pushsubscriptionchange event when permission is revoked"); |
| 36 |
|
| 37 |
promise_test(async (t) => { |
| 38 |
const promise = new Promise(r => { |
| 39 |
navigator.serviceWorker.addEventListener("message", r, { once: true }) |
| 40 |
}); |
| 41 |
|
| 42 |
const subscription = await registration.pushManager.subscribe(); |
| 43 |
t.add_cleanup(() => subscription.unsubscribe()); |
| 44 |
|
| 45 |
await SpecialPowers.spawnChrome([], async () => { |
| 46 |
// Bug 1210943: UAID changes should drop existing push subscriptions |
| 47 |
const uaid = await Services.prefs.getStringPref("dom.push.userAgentID"); |
| 48 |
await Services.prefs.setStringPref("dom.push.userAgentID", uaid + "0"); |
| 49 |
}) |
| 50 |
|
| 51 |
const pushSubscriptionChangeEvent = await promise; |
| 52 |
|
| 53 |
assert_equals(pushSubscriptionChangeEvent.data.type, "pushsubscriptionchange"); |
| 54 |
assert_equals(pushSubscriptionChangeEvent.data.constructor, "PushSubscriptionChangeEvent"); |
| 55 |
assert_object_equals(pushSubscriptionChangeEvent.data.oldSubscription, subscription.toJSON()); |
| 56 |
assert_equals(pushSubscriptionChangeEvent.data.newSubscription, undefined); |
| 57 |
}, "Fire pushsubscriptionchange event when UAID changes"); |