1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/geolocation/test_mozsettingsWatch.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,94 @@ 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 getCurrentPosition </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=777594">Mozilla Bug 777594</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 +if (SpecialPowers.isMainProcess()) { 1.32 + SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.jsm"); 1.33 +} 1.34 + 1.35 +function test1() { 1.36 + //This pushPermissions call is after pushPrefEnv call and pushPrefEnv calls follow after this 1.37 + SpecialPowers.pushPermissions([{'type': 'settings-read', 'allow': true, 'context': document}, {'type': 'settings-write', 'allow': true, 'context': document}], test2); 1.38 +} 1.39 + 1.40 +var watchId; 1.41 +function test2() { 1.42 + ok(navigator.geolocation, "get geolocation object"); 1.43 + 1.44 + toggleGeolocationSetting(false, function() { 1.45 + ok(true, "turned off geolocation via mozSettings"); 1.46 + setTimeout(function() { 1.47 + watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOff, 1.48 + failureCallbackAfterMozsettingOff); 1.49 + }, 500); // need to wait a bit for all of these async callbacks to finish 1.50 + }); 1.51 +} 1.52 + 1.53 +function successCallbackAfterMozsettingOff(position) { 1.54 + ok(false, "Success callback should not have been called after setting geolocation.enabled to false."); 1.55 + 1.56 + navigator.geolocation.clearWatch(watchId); 1.57 + toggleGeolocationSetting(true, function() { 1.58 + ok(true, "turned on geolocation via mozSettings"); 1.59 + setTimeout(function() { 1.60 + watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOn, 1.61 + failureCallbackAfterMozsettingOn); 1.62 + }, 500); // need to wait a bit for all of these async callbacks to finish 1.63 + }); 1.64 +} 1.65 + 1.66 +function failureCallbackAfterMozsettingOff(error) { 1.67 + ok(true, "Geolocation didn't work after setting geolocation.enabled to false."); 1.68 + 1.69 + navigator.geolocation.clearWatch(watchId); 1.70 + toggleGeolocationSetting(true, function() { 1.71 + ok(true, "turned on geolocation via mozSettings"); 1.72 + setTimeout(function() { 1.73 + watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOn, 1.74 + failureCallbackAfterMozsettingOn); 1.75 + }, 500); // need to wait a bit for all of these async callbacks to finish 1.76 + }); 1.77 +} 1.78 + 1.79 +function successCallbackAfterMozsettingOn(position) { 1.80 + ok(true, "Geolocation worked after setting geolocation.enabled to true."); 1.81 + 1.82 + navigator.geolocation.clearWatch(watchId); 1.83 + SimpleTest.finish(); 1.84 +} 1.85 + 1.86 +function failureCallbackAfterMozsettingOn(error) { 1.87 + ok(false, "Geolocation didn't work after setting geolocation.enabled to true."); 1.88 + 1.89 + navigator.geolocation.clearWatch(watchId); 1.90 + SimpleTest.finish(); 1.91 +} 1.92 + 1.93 +</script> 1.94 +</pre> 1.95 +</body> 1.96 +</html> 1.97 +