test_geoWatchPositionBlockedInInsecureContext.html (1604B)
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 var wid; 23 24 // The test succeeds if the error callback is called because we expect 25 // failure when a watchPosition() request is submitted in a non 26 // secure context. 27 function successCallback(_position) { 28 ok(false, "Success callback is not expected to be called"); 29 navigator.geolocation.clearWatch(wid); 30 SimpleTest.finish(); 31 } 32 33 function errorCallback(error) { 34 ok(true, "Check for the error callback to be called for insecure requests"); 35 is(error.code, error.PERMISSION_DENIED, "Check error code for insecure requests"); 36 navigator.geolocation.clearWatch(wid); 37 SimpleTest.finish(); 38 } 39 40 // Insecure requests should be blocked, for that we enable the relevant pref. 41 SpecialPowers.pushPrefEnv({"set": [["geo.security.allowinsecure", false]]}, function() { 42 force_prompt(true, function() { 43 wid = navigator.geolocation.watchPosition(successCallback, errorCallback); 44 }) 45 }); 46 47 </script> 48 </pre> 49 </body> 50 </html>