PositionOptions.https.html (2926B)
1 <!DOCTYPE html> 2 <meta charset="utf-8" /> 3 <title>Geolocation Test: PositionOptions tests</title> 4 <link 5 rel="help" 6 href="http://www.w3.org/TR/geolocation-API/#position_options_interface" 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 13 <script> 14 promise_setup(async ()=>{ 15 await test_driver.set_permission({ name: "geolocation" }, "granted"); 16 }); 17 18 const invalidValues = ["boom", 321, -Infinity, { foo: 5 }]; 19 20 promise_test(async (t) => { 21 const error = await new Promise((resolve, reject) => { 22 navigator.geolocation.getCurrentPosition(reject, resolve, { 23 timeout: 0, 24 maxAge: 0, 25 }); 26 }); 27 assert_equals(error.code, GeolocationPositionError.TIMEOUT); 28 }, "Set timeout and maximumAge to 0, check that timeout error raised (getCurrentPosition)"); 29 30 promise_test(async (t) => { 31 let watchId; 32 const error = await new Promise((resolve, reject) => { 33 watchId = navigator.geolocation.watchPosition(reject, resolve, { 34 timeout: 0, 35 maxAge: 0, 36 }); 37 }); 38 assert_equals(error.code, GeolocationPositionError.TIMEOUT); 39 navigator.geolocation.clearWatch(watchId); 40 }, "Set timeout and maximumAge to 0, check that timeout error raised (watchPosition)"); 41 42 promise_test(async (t) => { 43 let watchId; 44 const error = await new Promise((resolve, reject) => { 45 watchId = navigator.geolocation.getCurrentPosition(reject, resolve, { 46 timeout: -100, 47 maxAge: -100, 48 }); 49 }); 50 assert_equals(error.code, GeolocationPositionError.TIMEOUT); 51 navigator.geolocation.clearWatch(watchId); 52 }, "Check that a negative timeout and maxAge values are clamped to 0 (getCurrentPosition)"); 53 54 promise_test(async (t) => { 55 let watchId; 56 const error = await new Promise((resolve, reject) => { 57 watchId = navigator.geolocation.watchPosition(reject, resolve, { 58 timeout: -100, 59 maxAge: -100, 60 }); 61 }); 62 assert_equals(error.code, GeolocationPositionError.TIMEOUT); 63 navigator.geolocation.clearWatch(watchId); 64 }, "Check that a negative timeout and maxAge values are clamped to 0 (watchPosition)"); 65 66 promise_test(async (t) => { 67 for (const enableHighAccuracy of invalidValues) { 68 navigator.geolocation.getCurrentPosition(() => {}, null, { 69 enableHighAccuracy, 70 }); 71 } 72 }, "Call getCurrentPosition with wrong type for enableHighAccuracy. No exception expected."); 73 74 promise_test(async (t) => { 75 for (const enableHighAccuracy of invalidValues) { 76 const id = navigator.geolocation.watchPosition(() => {}, null, { 77 enableHighAccuracy, 78 }); 79 navigator.geolocation.clearWatch(id); 80 } 81 }, "Call watchPosition with wrong type for enableHighAccuracy. No exception expected."); 82 83 </script>