gecko/dom/tests/mochitest/geolocation/test_mozsettingsWatch.html
Reuben Morais 9fdab01a57 Bug 862353 - Only enable mozSettings in B2G and mochitests. r=gwagner
--HG--
extra : rebase_source : 2b079aa6aca6a65516670cc5adcccf422b5e0261
2013-05-13 18:32:09 -07:00

91 lines
3.0 KiB
HTML

<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=478911
-->
<head>
<title>Test for getCurrentPosition </title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<script type="text/javascript" src="geolocation_common.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=777594">Mozilla Bug 777594</a>
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
<script class="testbody" type="text/javascript">
SimpleTest.waitForExplicitFinish();
resume_geolocationProvider();
force_prompt(true);
if (SpecialPowers.isMainProcess()) {
SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.jsm");
}
SpecialPowers.addPermission("settings-read", true, document);
SpecialPowers.addPermission("settings-write", true, document);
ok(navigator.geolocation, "get geolocation object");
var watchId;
toggleGeolocationSetting(false, function() {
ok(true, "turned off geolocation via mozSettings");
setTimeout(function() {
watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOff,
failureCallbackAfterMozsettingOff);
}, 500); // need to wait a bit for all of these async callbacks to finish
});
function successCallbackAfterMozsettingOff(position) {
ok(false, "Success callback should not have been called after setting geolocation.enabled to false.");
navigator.geolocation.clearWatch(watchId);
toggleGeolocationSetting(true, function() {
ok(true, "turned on geolocation via mozSettings");
setTimeout(function() {
watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOn,
failureCallbackAfterMozsettingOn);
}, 500); // need to wait a bit for all of these async callbacks to finish
});
}
function failureCallbackAfterMozsettingOff(error) {
ok(true, "Geolocation didn't work after setting geolocation.enabled to false.");
navigator.geolocation.clearWatch(watchId);
toggleGeolocationSetting(true, function() {
ok(true, "turned on geolocation via mozSettings");
setTimeout(function() {
watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOn,
failureCallbackAfterMozsettingOn);
}, 500); // need to wait a bit for all of these async callbacks to finish
});
}
function successCallbackAfterMozsettingOn(position) {
ok(true, "Geolocation worked after setting geolocation.enabled to true.");
navigator.geolocation.clearWatch(watchId);
reset_prompt();
SimpleTest.finish();
}
function failureCallbackAfterMozsettingOn(error) {
ok(false, "Geolocation didn't work after setting geolocation.enabled to true.");
navigator.geolocation.clearWatch(watchId);
reset_prompt();
SimpleTest.finish();
}
</script>
</pre>
</body>
</html>