get-current-position-success.html (1334B)
1 <!doctype html> 2 <meta charset="utf-8" /> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/resources/testdriver.js?feature=bidi"></script> 6 <script src="/resources/testdriver-vendor.js"></script> 7 8 <script> 9 promise_setup(async () => { 10 // Ensure permission is granted before proceeding. 11 await test_driver.bidi.permissions.set_permission({ 12 descriptor: { name: 'geolocation' }, 13 state: 'granted', 14 }); 15 }); 16 17 promise_test(async (t) => { 18 t.add_cleanup(async () => { 19 await test_driver.bidi.emulation.set_geolocation_override({ coordinates: null }); 20 }); 21 22 const latitude = 50; 23 const longitude = 0; 24 const accuracy = 100; 25 26 await test_driver.bidi.emulation.set_geolocation_override({ 27 coordinates: { latitude, longitude, accuracy }, 28 }); 29 document.innerHTML += 30 '<geolocation id="geolocation-element" autolocate onlocation="onLocation()"></geolocation>'; 31 }, 'Tests Geolocation element\'s success callback'); 32 33 function onLocation() { 34 let el = document.getElementById('geolocation-element'); 35 assert_equals(el.position.coords.latitude, 50); 36 assert_equals(el.position.coords.longitude, 0); 37 assert_equals(el.position.coords.accuracy, 100); 38 assert_equals(el.error, null); 39 } 40 </script>