test_clearWatch.html (2106B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=478911 5 --> 6 <head> 7 <title>Test for watchPosition and clearWatch</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <script type="text/javascript" src="geolocation_common.js"></script> 10 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 12 </head> 13 <body> 14 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Mozilla Bug 478911</a> 15 <p id="display"></p> 16 <div id="content" style="display: none"> 17 18 </div> 19 <pre id="test"> 20 <script class="testbody" type="text/javascript"> 21 "use strict"; 22 23 SimpleTest.waitForExplicitFinish(); 24 25 resume_geolocationProvider(function() { 26 force_prompt(true, test1); 27 }); 28 29 var hasBeenCleared = false; 30 var successWasCalledAfterClear = false; 31 var firstCallback = true; 32 33 function failureCallback(_error) 34 { 35 ok(0, "we should not be seeing failures from this watchPosition"); 36 } 37 38 function successCallback(position) { 39 ok(true, "successCallback was called, hasBeenCleared=" + hasBeenCleared + 40 ", successWasCalledAfterClear=" + successWasCalledAfterClear); 41 check_geolocation(position); 42 if (hasBeenCleared) { 43 successWasCalledAfterClear = true; 44 } 45 if (firstCallback) { 46 SimpleTest.executeSoon(clearWatch); 47 firstCallback = false; 48 } 49 } 50 51 let watchID; 52 53 function clearWatch() { 54 ok(true, "clearWatch was called, hasBeenCleared=" + hasBeenCleared + 55 ", successWasCalledAfterClear=" + successWasCalledAfterClear); 56 navigator.geolocation.clearWatch(watchID); 57 hasBeenCleared = true; 58 SimpleTest.executeSoon(testAccepted); 59 } 60 61 function testAccepted() { 62 ok(true, "testAccepted was called, hasBeenCleared=" + hasBeenCleared + 63 ", successWasCalledAfterClear=" + successWasCalledAfterClear); 64 ok(!successWasCalledAfterClear, "The successCallback should not be called after clear"); 65 SimpleTest.finish(); 66 } 67 68 function test1() { 69 ok(true, "Getting the watchPosition"); 70 watchID = navigator.geolocation.watchPosition(successCallback, failureCallback, null); 71 ok(true, "Waiting"); 72 } 73 </script> 74 </pre> 75 </body> 76 </html>