Bug 867895 - Ensure the geolocation provider's high accuracy flag is reset when all requests that require it are satisfied. r=dougt
☠☠ backed out by 7a2a6d227a71 ☠ ☠
authorJosh Matthews <josh@joshmatthews.net>
Wed, 05 Jun 2013 17:57:26 -0400
changeset 146925 9915f8dae4e56dbd2eb21e54bcb935c0c1cb052b
parent 146924 434432062cbc79422d55bdf6cdbe133d5939d783
child 146926 d1592f77f4598942039bb88f9a1a568116bc60db
push id2697
push userbbajaj@mozilla.com
push dateMon, 05 Aug 2013 18:49:53 +0000
treeherdermozilla-beta@dfec938c7b63 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdougt
bugs867895
milestone24.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 867895 - Ensure the geolocation provider's high accuracy flag is reset when all requests that require it are satisfied. r=dougt
dom/src/geolocation/nsGeolocation.cpp
dom/tests/unit/test_highaccuracy.js
dom/tests/unit/test_highaccuracy_wrap.js
dom/tests/unit/xpcshell.ini
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -504,16 +504,22 @@ nsGeolocationRequest::SetTimeoutTimer()
 void
 nsGeolocationRequest::MarkCleared()
 {
   if (mTimeoutTimer) {
     mTimeoutTimer->Cancel();
     mTimeoutTimer = nullptr;
   }
   mCleared = true;
+
+  // Attempt to save power when possible
+  if (WantsHighAccuracy()) {
+    nsRefPtr<nsGeolocationService> gs = nsGeolocationService::GetGeolocationService();
+    gs->SetHigherAccuracy(false);
+  }
 }
 
 void
 nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition)
 {
   if (mCleared || !mAllowed) {
     return;
   }
new file mode 100644
--- /dev/null
+++ b/dom/tests/unit/test_highaccuracy.js
@@ -0,0 +1,86 @@
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
+const providerContract = "@mozilla.org/geolocation/provider;1";
+
+var provider = {
+  QueryInterface: function eventsink_qi(iid) {
+    if (iid.equals(Components.interfaces.nsISupports) ||
+        iid.equals(Components.interfaces.nsIFactory) ||
+        iid.equals(Components.interfaces.nsIGeolocationProvider))
+      return this;
+    throw Components.results.NS_ERROR_NO_INTERFACE;
+  },
+  createInstance: function eventsink_ci(outer, iid) {
+    if (outer)
+      throw Components.results.NS_ERROR_NO_AGGREGATION;
+    return this.QueryInterface(iid);
+  },
+  lockFactory: function eventsink_lockf(lock) {
+    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  startup: function() {
+  },
+  watch: function(callback, isPrivate) {
+    do_execute_soon(function() {
+      callback.update({coords: {latitude: 42, longitude: 42}, timestamp: 0});
+    });
+  },
+  shutdown: function() {
+  },
+  setHighAccuracy: function(enable) {
+    this._status = enable;
+  },
+  _status: false
+};
+
+let runningInParent = true;
+try {
+  runningInParent = Components.classes["@mozilla.org/xre/runtime;1"].
+                    getService(Components.interfaces.nsIXULRuntime).processType
+                    == Components.interfaces.nsIXULRuntime.PROCESS_TYPE_DEFAULT;
+}
+catch (e) { }
+
+var geolocation;
+
+add_test(function() {
+  geolocation.getCurrentPosition(function() {
+    do_execute_soon(function() {
+      if (runningInParent) {
+        do_check_false(provider._status);
+      }
+      run_next_test();
+    });
+  }, null, {enableHighAccuracy: true, maxAge: 0});           
+});
+
+add_test(function() {
+  var watchId = geolocation.watchPosition(function() {
+    do_execute_soon(function() {
+      geolocation.clearWatch(watchId);
+      if (runningInParent) {
+        do_check_false(provider._status);      
+      }
+      run_next_test();
+    });
+  }, null, {enableHighAccuracy: true, maxAge: 0});           
+});
+
+function run_test()
+{
+  if (runningInParent) {
+    Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
+      "Unit test geo provider", providerContract, provider);
+    var catMan = Components.classes["@mozilla.org/categorymanager;1"]
+                           .getService(Components.interfaces.nsICategoryManager);
+
+    var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
+    prefs.setBoolPref("geo.testing.ignore_ipc_principal", true);
+    prefs.setBoolPref("geo.wifi.scan", false);
+  }
+
+  geolocation = Cc["@mozilla.org/geolocation;1"].createInstance(Ci.nsISupports);
+  run_next_test();
+}
\ No newline at end of file
new file mode 100644
--- /dev/null
+++ b/dom/tests/unit/test_highaccuracy_wrap.js
@@ -0,0 +1,52 @@
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+
+const providerCID = Components.ID("{14aa4b81-e266-45cb-88f8-89595dece114}");
+const providerContract = "@mozilla.org/geolocation/provider;1";
+
+var provider = {
+  QueryInterface: function eventsink_qi(iid) {
+    if (iid.equals(Components.interfaces.nsISupports) ||
+        iid.equals(Components.interfaces.nsIFactory) ||
+        iid.equals(Components.interfaces.nsIGeolocationProvider))
+      return this;
+    throw Components.results.NS_ERROR_NO_INTERFACE;
+  },
+  createInstance: function eventsink_ci(outer, iid) {
+    if (outer)
+      throw Components.results.NS_ERROR_NO_AGGREGATION;
+    return this.QueryInterface(iid);
+  },
+  lockFactory: function eventsink_lockf(lock) {
+    throw Components.results.NS_ERROR_NOT_IMPLEMENTED;
+  },
+  startup: function() {
+  },
+  watch: function(callback, isPrivate) {
+    do_execute_soon(function() {
+      callback.update({coords: {latitude: 42, longitude: 42}, timestamp: 0});
+    });
+  },
+  shutdown: function() {
+  },
+  setHighAccuracy: function(enable) {
+    this._status = enable;
+  },
+  _status: false
+};
+
+function run_test() {
+  Components.manager.nsIComponentRegistrar.registerFactory(providerCID,
+    "Unit test geo provider", providerContract, provider);
+  var catMan = Components.classes["@mozilla.org/categorymanager;1"]
+                         .getService(Components.interfaces.nsICategoryManager);
+
+  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
+  prefs.setBoolPref("geo.testing.ignore_ipc_principal", true);
+  prefs.setBoolPref("geo.wifi.scan", false);
+
+  run_test_in_child("test_highaccuracy.js", function() {
+    do_check_false(provider._status);
+    do_test_finished();
+  });
+}
\ No newline at end of file
--- a/dom/tests/unit/xpcshell.ini
+++ b/dom/tests/unit/xpcshell.ini
@@ -4,10 +4,11 @@ tail =
 
 [test_bug319968.js]
 [test_bug465752.js]
 [test_geolocation_provider.js]
 # Bug 684962: test hangs consistently on Android
 skip-if = os == "android"
 [test_geolocation_timeout.js]
 [test_geolocation_timeout_wrap.js]
-skip-if = os == "mac"
+[test_highaccuracy.js]
+[test_highaccuracy_wrap.js]skip-if = os == "mac"
 skip-if = os == "android"