non-secure-contexts.http.html (2929B)
1 <!DOCTYPE html> 2 <meta charset="utf-8" /> 3 <title>Geolocation Test: non-secure contexts</title> 4 <link rel="help" href="https://github.com/w3c/geolocation-api/pull/34" /> 5 <script src="/resources/testharness.js"></script> 6 <script src="/resources/testharnessreport.js"></script> 7 <script> 8 promise_test(() => { 9 return new Promise(resolve => { 10 let isAsync = true; 11 const successCallback = () => { 12 assert_unreached( 13 "successCallback must never be invoked in non-secure contexts." 14 ); 15 }; 16 const errorCallBack = () => { 17 isAsync = false; 18 resolve(); 19 }; 20 navigator.geolocation.getCurrentPosition(successCallback, errorCallBack); 21 assert_true( 22 isAsync, 23 "Expected the errorCallback to be called asynchronously." 24 ); 25 }); 26 }, "When in a non-secure context, getCurrentPosition()'s errorCallback is asynchronously called."); 27 28 promise_test(async () => { 29 return new Promise(resolve => { 30 let isAsync = true; 31 const successCallback = () => { 32 assert_unreached( 33 "successCallback must never be invoked in non-secure contexts." 34 ); 35 }; 36 const errorCallBack = () => { 37 isAsync = false; 38 resolve(); 39 }; 40 navigator.geolocation.watchPosition(successCallback, errorCallBack); 41 assert_true(isAsync, "errorCallback must be called asynchronously."); 42 }); 43 }, "When in a non-secure context, watchPosition()'s errorCallback is asynchronously called."); 44 45 promise_test(async () => { 46 const positionErrorPromise = new Promise(errorCallBack => { 47 const successCallback = () => { 48 assert_unreached( 49 "successCallback must never be invoked in non-secure contexts." 50 ); 51 }; 52 navigator.geolocation.getCurrentPosition(successCallback, errorCallBack); 53 }); 54 const positionError = await positionErrorPromise; 55 assert_equals( 56 positionError.code, 57 1, 58 "Expected the value for PERMISSION_DENIED, which is 1." 59 ); 60 }, "When in a non-secure context, the getCurrentPosition() errorCallBack gets a GeolocationPositionError with the correct error code."); 61 62 promise_test(async () => { 63 const positionErrorPromise = new Promise(errorCallBack => { 64 const successCallback = () => { 65 assert_unreached( 66 "successCallback must never be invoked in non-secure contexts." 67 ); 68 }; 69 const id = navigator.geolocation.watchPosition( 70 successCallback, 71 errorCallBack 72 ); 73 assert_true(Number.isInteger(id), "Must return an identifier."); 74 }); 75 const positionError = await positionErrorPromise; 76 assert_equals( 77 positionError.code, 78 1, 79 "Expected the value for PERMISSION_DENIED, which is 1." 80 ); 81 }, "When in a non-secure context, the watchPosition() errorCallBack gets a GeolocationPositionError with the correct error code."); 82 </script>