getCurrentPosition_permission_allow.https.html (1803B)
1 <!DOCTYPE html> 2 <meta charset="utf-8" /> 3 <title>Geolocation Test: getCurrentPosition() location access</title> 4 <link 5 rel="help" 6 href="https://www.w3.org/TR/geolocation/#getcurrentposition-method" 7 /> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src="/resources/testdriver.js"></script> 11 <script src="/resources/testdriver-vendor.js"></script> 12 <script> 13 promise_test(async (t) => { 14 t.add_cleanup(() => { 15 return test_driver.set_permission({ name: "geolocation" }, "prompt"); 16 }); 17 await test_driver.set_permission({ name: "geolocation" }, "granted"); 18 const position = await new Promise((resolve, reject) => { 19 let calledAsync = false; 20 navigator.geolocation.getCurrentPosition( 21 t.step_func((position) => { 22 assert_true( 23 calledAsync, 24 "Expected callback to be called asynchronously" 25 ); 26 resolve(position); 27 }), 28 reject 29 ); 30 calledAsync = true; 31 }); 32 assert_true( 33 position instanceof GeolocationPosition, 34 "Expected GeolocationPosition" 35 ); 36 }, "User allows access, check that success callback is called."); 37 38 promise_test(async (t) => { 39 t.add_cleanup(() => { 40 return test_driver.set_permission({ name: "geolocation" }, "prompt"); 41 }); 42 await test_driver.set_permission({ name: "geolocation" }, "granted"); 43 const position = await new Promise((resolve, reject) => { 44 try { 45 navigator.geolocation.getCurrentPosition(resolve, null); 46 } catch (err) { 47 reject(err); 48 } 49 }); 50 assert_true( 51 position instanceof GeolocationPosition, 52 "Expected GeolocationPosition" 53 ); 54 }, "Error callback is nullable for getCurrentPosition()."); 55 </script>