1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/geolocation/test_clearWatch.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,72 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +https://bugzilla.mozilla.org/show_bug.cgi?id=478911 1.8 +--> 1.9 +<head> 1.10 + <title>Test for watchPosition and clearWatch</title> 1.11 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.12 + <script type="text/javascript" src="geolocation_common.js"></script> 1.13 + 1.14 +<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.15 +</head> 1.16 +<body> 1.17 +<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Mozilla Bug 478911</a> 1.18 +<p id="display"></p> 1.19 +<div id="content" style="display: none"> 1.20 + 1.21 +</div> 1.22 +<pre id="test"> 1.23 +<script class="testbody" type="text/javascript"> 1.24 + 1.25 +SimpleTest.waitForExplicitFinish(); 1.26 + 1.27 +resume_geolocationProvider(function() { 1.28 + force_prompt(true, test1); 1.29 +}); 1.30 + 1.31 +var hasBeenCleared = false; 1.32 +var successWasCalledAfterClear = false; 1.33 +var firstCallback = true; 1.34 + 1.35 +function failureCallback(error) 1.36 +{ 1.37 + ok(0, "we should not be seeing failures from this watchPosition"); 1.38 +} 1.39 + 1.40 +function successCallback(position) { 1.41 + ok(true, "successCallback was called, hasBeenCleared=" + hasBeenCleared + 1.42 + ", successWasCalledAfterClear=" + successWasCalledAfterClear); 1.43 + if (hasBeenCleared == true) { 1.44 + successWasCalledAfterClear = true; 1.45 + } 1.46 + if (firstCallback) { 1.47 + SimpleTest.executeSoon(clearWatch); 1.48 + firstCallback = false; 1.49 + } 1.50 +} 1.51 + 1.52 +function clearWatch() { 1.53 + ok(true, "clearWatch was called, hasBeenCleared=" + hasBeenCleared + 1.54 + ", successWasCalledAfterClear=" + successWasCalledAfterClear); 1.55 + navigator.geolocation.clearWatch(watchID); 1.56 + hasBeenCleared = true; 1.57 + SimpleTest.executeSoon(testAccepted); 1.58 +} 1.59 + 1.60 +function testAccepted() { 1.61 + ok(true, "testAccepted was called, hasBeenCleared=" + hasBeenCleared + 1.62 + ", successWasCalledAfterClear=" + successWasCalledAfterClear); 1.63 + ok(!successWasCalledAfterClear, "The successCallback should not be called after clear"); 1.64 + SimpleTest.finish(); 1.65 +} 1.66 + 1.67 +function test1() { 1.68 + ok(true, "Getting the watchPosition"); 1.69 + watchID = navigator.geolocation.watchPosition(successCallback, failureCallback, null); 1.70 + ok(true, "Waiting"); 1.71 +} 1.72 +</script> 1.73 +</pre> 1.74 +</body> 1.75 +</html>