summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/notifications
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/notifications')
-rw-r--r--testing/web-platform/tests/notifications/resources/helpers.js17
-rw-r--r--testing/web-platform/tests/notifications/resources/shownotification-window-iframe.html8
-rw-r--r--testing/web-platform/tests/notifications/shownotification-window.https.html37
-rw-r--r--testing/web-platform/tests/notifications/shownotification-without-permission.https.window.js12
4 files changed, 64 insertions, 10 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`);
+ }
+}
diff --git a/testing/web-platform/tests/notifications/resources/shownotification-window-iframe.html b/testing/web-platform/tests/notifications/resources/shownotification-window-iframe.html
new file mode 100644
index 0000000000..2a45e79465
--- /dev/null
+++ b/testing/web-platform/tests/notifications/resources/shownotification-window-iframe.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script>
+ async function showNotification() {
+ const registration = await navigator.serviceWorker.ready;
+ await registration.showNotification('foo');
+ }
+</script>
diff --git a/testing/web-platform/tests/notifications/shownotification-window.https.html b/testing/web-platform/tests/notifications/shownotification-window.https.html
new file mode 100644
index 0000000000..b21a5621df
--- /dev/null
+++ b/testing/web-platform/tests/notifications/shownotification-window.https.html
@@ -0,0 +1,37 @@
+<!DOCTYPE html>
+<meta charset="utf-8">
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+<script src="/resources/testdriver.js"></script>
+<script src="/resources/testdriver-vendor.js"></script>
+<script src="resources/helpers.js"></script>
+<iframe id="iframe" src="resources/shownotification-window-iframe.html"></iframe>
+<script>
+/** @type {ServiceWorkerRegistration} */
+let registration;
+
+promise_setup(async (t) => {
+ await trySettingPermission("granted");
+ registration = await getActiveServiceWorker("noop-sw.js");
+ await closeAllNotifications();
+});
+
+promise_test(async (t) => {
+ t.add_cleanup(closeAllNotifications);
+
+ if (iframe.contentDocument.readyState !== "complete") {
+ await new Promise(resolve => iframe.onload = resolve);
+ }
+
+ await iframe.contentWindow.showNotification();
+ let notifications = await registration.getNotifications();
+ assert_equals(notifications.length, 1, "Should persist the notification");
+
+ iframe.contentWindow.location.reload();
+ // Wait for some time for potential notification close requests to be sent
+ await new Promise(resolve => iframe.onload = resolve);
+ notifications = await registration.getNotifications();
+ assert_equals(notifications.length, 1, "Should keep the notification");
+}, 'Refreshing window does not clear persistent notifications');
+</script>
+</body>
diff --git a/testing/web-platform/tests/notifications/shownotification-without-permission.https.window.js b/testing/web-platform/tests/notifications/shownotification-without-permission.https.window.js
index 37b3dbbef6..b09c0460fb 100644
--- a/testing/web-platform/tests/notifications/shownotification-without-permission.https.window.js
+++ b/testing/web-platform/tests/notifications/shownotification-without-permission.https.window.js
@@ -8,20 +8,14 @@
let registration;
promise_setup(async () => {
+ await trySettingPermission("prompt");
registration = await getActiveServiceWorker("noop-sw.js");
+ await closeAllNotifications();
});
-promise_test(async (t) => {
+promise_test(async t => {
t.add_cleanup(closeAllNotifications);
- try {
- await test_driver.set_permission({ name: "notifications" }, "prompt");
- } catch {
- // Not all implementations support this yet, but it may already be "prompt" to be able to continue
- }
-
- assert_equals(Notification.permission, "default", "Should have the default permission to continue");
-
await promise_rejects_js(t, TypeError, registration.showNotification(""), "Should throw TypeError");
const notifications = await registration.getNotifications();
assert_equals(notifications.length, 0, "Should return zero notification");