test_permission_granted.html (1625B)
1 <!DOCTYPE html> 2 <!-- 3 Tests PushManager.subscribe behavior based on permission state. 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1847217 5 TODO: Move this to WPT when we get test_driver.set_permission (bug 1524074) and Push testing infra in WPT. 6 --> 7 <meta charset="utf-8"> 8 <title>Push permission granted test</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <script src="/tests/dom/push/test/test_utils.js"></script> 11 <link rel="stylesheet" href="/tests/SimpleTest/test.css"> 12 <script> 13 let registration; 14 add_task(async function start() { 15 const url = "worker.js?caller=test_permission_granted.html"; 16 registration = await navigator.serviceWorker.register(url, { scope: "." }); 17 await waitForActive(registration); 18 }); 19 20 add_task(async function test_notifications_permission_error() { 21 await setPushPermission(false); 22 23 try { 24 await registration.pushManager.subscribe(); 25 ok(false, "No permission, should never proceed"); 26 } catch (err) { 27 is(err.name, "NotAllowedError", "A permission error should occur"); 28 } 29 }); 30 31 add_task(async function test_notifications_permission_granted() { 32 await setPushPermission(true); 33 34 try { 35 await registration.pushManager.subscribe(); 36 ok(false, "For now this should not proceed because of dom.push.connection.enabled=false (default for all tests)"); 37 } catch (err) { 38 is(err.name, "AbortError", "For now a connection error should occur"); 39 } 40 }); 41 42 add_task(async function unregister() { 43 const result = await registration.unregister(); 44 ok(result, "Unregister should return true."); 45 }); 46 </script>