summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/notifications/resources/helpers.js
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/notifications/resources/helpers.js')
-rw-r--r--testing/web-platform/tests/notifications/resources/helpers.js17
1 files changed, 16 insertions, 1 deletions
diff --git a/testing/web-platform/tests/notifications/resources/helpers.js b/testing/web-platform/tests/notifications/resources/helpers.js
index 8c30173336..ca44e32f7f 100644
--- a/testing/web-platform/tests/notifications/resources/helpers.js
+++ b/testing/web-platform/tests/notifications/resources/helpers.js
@@ -12,9 +12,24 @@ async function getActiveServiceWorker(script) {
return reg;
}
-
async function closeAllNotifications() {
for (const n of await registration.getNotifications()) {
n.close();
}
}
+
+async function trySettingPermission(perm) {
+ try {
+ await test_driver.set_permission({ name: "notifications" }, perm);
+ } catch {
+ // Not all implementations support this yet, but the permission may already be set to be able to continue
+ }
+
+ // Using Notification.permission instead of permissions.query() as
+ // some implementation without set_permission support overrides
+ // Notification.permission.
+ const permission = Notification.permission === "default" ? "prompt" : Notification.permission;
+ if (permission !== perm) {
+ throw new Error(`Should have the permission ${perm} to continue`);
+ }
+}