From 044fe036fa8dfb0a9b688b7ffe0f870349f24f62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kan-Ru=20Chen=20=28=E9=99=B3=E4=BE=83=E5=A6=82=29?= Date: Wed, 5 Dec 2012 17:20:59 +0800 Subject: [PATCH] Bug 816850 - Don't call nsGeolocation::Shutdown() when disabled via settings. r=dougt --- dom/src/geolocation/nsGeolocation.cpp | 3 -- .../geolocation/test_mozsettings.html | 39 ++++++++++++---- .../geolocation/test_mozsettingsWatch.html | 44 +++++++++++++++---- 3 files changed, 67 insertions(+), 19 deletions(-) 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(); +}