test_geoGetCurrentPositionBlockedInInsecureContext.html (1510B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1269531 5 --> 6 <head> 7 <title>Test for Bug 1269531</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script type="text/javascript" src="geolocation_common.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 11 </head> 12 <body> 13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1269531">Mozilla Bug 1269531</a> 14 <p id="display"></p> 15 <div id="content" style="display: none"> 16 </div> 17 <pre id="test"> 18 <script class="testbody" type="text/javascript"> 19 20 SimpleTest.waitForExplicitFinish(); 21 22 // The test succeeds if the error callback is called because we expect 23 // failure when a getCurrentPosition() request is submitted in a non 24 // secure context. 25 function successCallback(_position) { 26 ok(false, "Success callback is not expected to be called"); 27 SimpleTest.finish(); 28 } 29 30 function errorCallback(error) { 31 ok(true, "Check for the error callback to be called for insecure requests"); 32 is(error.code, error.PERMISSION_DENIED, "Check error code for insecure requests"); 33 SimpleTest.finish(); 34 } 35 36 // Insecure requests should be blocked, for that we enable the relevant pref. 37 SpecialPowers.pushPrefEnv({"set": [["geo.security.allowinsecure", false]]}, function() { 38 force_prompt(true, function() { 39 navigator.geolocation.getCurrentPosition(successCallback, errorCallback); 40 }) 41 }); 42 43 </script> 44 </pre> 45 </body> 46 </html>