watchPosition_permission_deny.https.html (1645B)
1 <!DOCTYPE html> 2 <meta charset="utf-8" /> 3 <title>Geolocation Test: watchPosition location access denied</title> 4 <link rel="help" href="http://www.w3.org/TR/geolocation-API/#privacy_for_uas" /> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script src="/resources/testdriver.js"></script> 8 <script src="/resources/testdriver-vendor.js"></script> 9 <script> 10 const resetPermission = () => { 11 return test_driver.set_permission({ name: "geolocation" }, "prompt"); 12 }; 13 14 promise_test(async (t) => { 15 t.add_cleanup(resetPermission); 16 await test_driver.set_permission({ name: "geolocation" }, "denied"); 17 let errorCBCalled = false; 18 let id; 19 const errorPromise = new Promise((resolve, reject) => { 20 id = navigator.geolocation.watchPosition(reject, () => { 21 errorCBCalled = true; 22 resolve(); 23 }); 24 }); 25 assert_false( 26 errorCBCalled, 27 "error callback must not be called synchronously" 28 ); 29 await errorPromise; 30 navigator.geolocation.clearWatch(id); 31 }, "Check that watchPosition returns synchronously before any callbacks are invoked."); 32 33 promise_test(async (t) => { 34 t.add_cleanup(resetPermission); 35 await test_driver.set_permission({ name: "geolocation" }, "denied"); 36 const promise = new Promise((resolve, reject) => { 37 navigator.geolocation.watchPosition(reject, resolve); 38 }); 39 const result = await promise; 40 assert_true( 41 result instanceof GeolocationPositionError, 42 "expected GeolocationPositionError" 43 ); 44 }, "User denies access, check that error callback is called."); 45 </script>