diff options
Diffstat (limited to 'dom/notification/test/mochitest/test_notification_permissions.html')
-rw-r--r-- | dom/notification/test/mochitest/test_notification_permissions.html | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/dom/notification/test/mochitest/test_notification_permissions.html b/dom/notification/test/mochitest/test_notification_permissions.html new file mode 100644 index 0000000000..f074ccf58e --- /dev/null +++ b/dom/notification/test/mochitest/test_notification_permissions.html @@ -0,0 +1,70 @@ +<!DOCTYPE HTML> +<html> +<!-- +Tests that the Notification.requestPermission and navigator.permissions.query +return values are consistent with the stored permission. +https://bugzilla.mozilla.org/show_bug.cgi?id=1589754 +--> +<head> + <title>Notification permissions and permissions API</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"> +</head> +<body> + <p id="display"></p> + <div id="content" style="display: none"> + </div> + <pre id="test"> +<script class="testbody"> + +add_task(async function test_notifications_permission() { + await SpecialPowers.clearUserPref("notification.prompt.testing"); + await SpecialPowers.pushPrefEnv({ + set: [ + // Set pref to exercise relevant code path for regression test. + ["permissions.delegation.enabled", true], + // Automatically dismiss the permission request when it appears. + ["dom.webnotifications.requireuserinteraction", true], + ], + }); + + async function testPermissionInWindow(win) { + async function checkPermission(perm, expectedResult, expectedPermission) { + await SpecialPowers.pushPermissions([ + { + type: "desktop-notification", + allow: SpecialPowers.Ci.nsIPermissionManager[perm], + context: document, + }, + ]); + is( + await win.Notification.requestPermission(), + expectedResult, + `expected requestPermission() result for permission ${perm}` + ); + + let result = + await win.navigator.permissions.query({ name: "notifications" }); + is( + result.state, + expectedPermission, + `expected permissions API result for permission ${perm}` + ); + } + + await checkPermission("UNKNOWN_ACTION", "default", "prompt"); + await checkPermission("ALLOW_ACTION", "granted", "granted"); + await checkPermission("DENY_ACTION", "denied", "denied"); + await checkPermission("PROMPT_ACTION", "default", "prompt"); + } + + var win = window.open("blank.html"); + await new Promise(resolve => { win.onload = resolve; }); + await testPermissionInWindow(win); + win.close(); +}); + +</script> + </pre> +</body> +</html> |