permission.https.html (1944B)
1 <!doctype html> 2 <meta charset=utf-8> 3 <title>Test push is a powerful feature via Permissions API</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="/resources/testdriver.js"></script> 7 <script src="/resources/testdriver-vendor.js"></script> 8 <script src="/notifications/resources/helpers.js"></script> 9 10 <script> 11 let registration; 12 13 promise_setup(async () => { 14 registration = await prepareActiveServiceWorker("noop-sw.js"); 15 }); 16 17 promise_test(async (t) => { 18 await trySettingPermission("prompt") 19 const status = await navigator.permissions.query({ name: "push" }); 20 assert_true(status instanceof PermissionStatus); 21 assert_equals(status.name, "push", `permission's name must be "push"`); 22 assert_equals(status.state, "prompt", `permission's state must be "prompt" by default`); 23 }, `Query "push" powerful feature`); 24 25 promise_test(async (t) => { 26 await trySettingPermission("granted") 27 const subscription = await registration.pushManager.subscribe(); 28 t.add_cleanup(() => subscription.unsubscribe()); 29 30 assert_true(subscription instanceof PushSubscription); 31 assert_equals(typeof subscription.endpoint, "string", "endpoint string exists"); 32 assert_equals(new URL(subscription.endpoint).protocol, "https:", "endpoint is a valid https URL") 33 34 assert_true(subscription.getKey("p256dh") instanceof ArrayBuffer, "p256dh key exists"); 35 assert_true(subscription.getKey("p256dh").byteLength > 0, "p256dh key is not empty"); 36 assert_true(subscription.getKey("auth") instanceof ArrayBuffer, "auth key exists"); 37 assert_true(subscription.getKey("auth").byteLength > 0, "auth key is not empty"); 38 }, "Granting permission should allow subscription"); 39 40 promise_test(async (t) => { 41 await trySettingPermission("denied") 42 await promise_rejects_dom(t, "NotAllowedError", registration.pushManager.subscribe()); 43 }, "Denying permission should disallow subscription"); 44 </script>