diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index 7062ee287f0..8330e61b9fb 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -741,9 +741,6 @@ nsGeolocationService::HandleMozsettingValue(const bool aValue) { if (!aValue) { // turn things off - for (uint32_t i = 0; i< mGeolocators.Length(); i++) { - mGeolocators[i]->Shutdown(); - } StopDevice(); Update(nullptr); mLastPosition = nullptr; diff --git a/dom/tests/mochitest/geolocation/test_mozsettings.html b/dom/tests/mochitest/geolocation/test_mozsettings.html index bee72ebe742..f3fa3396335 100644 --- a/dom/tests/mochitest/geolocation/test_mozsettings.html +++ b/dom/tests/mochitest/geolocation/test_mozsettings.html @@ -42,30 +42,53 @@ SpecialPowers.addPermission("settings-read", true, document); SpecialPowers.addPermission("settings-write", true, document); SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.jsm"); +ok(navigator.geolocation, "get geolocation object"); + toggleGeolocationSetting(false, function() { ok(true, "turned off geolocation via mozSettings"); setTimeout(function() { - navigator.geolocation.getCurrentPosition(successCallbackAfterMozsetting, failureCallbackAfterMozsetting); + navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOff, + failureCallbackAfterMozsettingOff); }, 500); // need to wait a bit for all of these async callbacks to finish }); -function successCallbackAfterMozsetting(position) { +function successCallbackAfterMozsettingOff(position) { ok(false, "Success callback should not have been called after setting geolocation.enabled to false."); toggleGeolocationSetting(true, function() { - reset_prompt(); - SimpleTest.finish(); + ok(true, "turned on geolocation via mozSettings"); + setTimeout(function() { + navigator.geolocation.getCurrentPosition(successCallbackAfterMozsettingOn, + failureCallbackAfterMozsettingOn); + }, 500); // need to wait a bit for all of these async callbacks to finish }); } -function failureCallbackAfterMozsetting(error) { +function failureCallbackAfterMozsettingOff(error) { ok(true, "Geolocation didn't work after setting geolocation.enabled to false."); toggleGeolocationSetting(true, function() { - reset_prompt(); - SimpleTest.finish(); + ok(true, "turned on geolocation via mozSettings"); + setTimeout(function() { + navigator.geolocation.getCurrentPosition(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."); + + reset_prompt(); + SimpleTest.finish(); +} + +function failureCallbackAfterMozsettingOn(error) { + ok(false, "Geolocation didn't work after setting geolocation.enabled to true."); + + reset_prompt(); + SimpleTest.finish(); +} diff --git a/dom/tests/mochitest/geolocation/test_mozsettingsWatch.html b/dom/tests/mochitest/geolocation/test_mozsettingsWatch.html index b5add802bf5..c143aea36e8 100644 --- a/dom/tests/mochitest/geolocation/test_mozsettingsWatch.html +++ b/dom/tests/mochitest/geolocation/test_mozsettingsWatch.html @@ -42,30 +42,58 @@ SpecialPowers.addPermission("settings-read", true, document); SpecialPowers.addPermission("settings-write", true, document); SpecialPowers.Cu.import("resource://gre/modules/SettingsChangeNotifier.jsm"); +ok(navigator.geolocation, "get geolocation object"); + +var watchId; toggleGeolocationSetting(false, function() { ok(true, "turned off geolocation via mozSettings"); setTimeout(function() { - navigator.geolocation.watchPosition(successCallbackAfterMozsetting, failureCallbackAfterMozsetting); + watchId = navigator.geolocation.watchPosition(successCallbackAfterMozsettingOff, + failureCallbackAfterMozsettingOff); }, 500); // need to wait a bit for all of these async callbacks to finish }); -function successCallbackAfterMozsetting(position) { +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() { - reset_prompt(); - SimpleTest.finish(); + 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 failureCallbackAfterMozsetting(error) { +function failureCallbackAfterMozsettingOff(error) { ok(true, "Geolocation didn't work after setting geolocation.enabled to false."); + navigator.geolocation.clearWatch(watchId); toggleGeolocationSetting(true, function() { - reset_prompt(); - SimpleTest.finish(); + 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(); +}