Bug 1177871 - Timeout added to XHR request of WifiGeoPositionProvider. r=jdm
☠☠ backed out by eefa8e4699d2 ☠ ☠
authorAidin Gharibnavaz <aidin@aidinhut.com>
Thu, 30 Jul 2015 07:01:00 -0400
changeset 287322 8010e0cbd2288eb3846533febcd6d523c573d667
parent 287321 2f028ee4e97cc1b96d38dc212c9dec680ecc2d61
child 287323 96bb759922a1cdf2b9ce3642ec6de84c80ae0741
push id5067
push userraliiev@mozilla.com
push dateMon, 21 Sep 2015 14:04:52 +0000
treeherdermozilla-beta@14221ffe5b2f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs1177871
milestone42.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 1177871 - Timeout added to XHR request of WifiGeoPositionProvider. r=jdm CLOSED TREE
dom/system/NetworkGeolocationProvider.js
dom/tests/unit/test_geolocation_provider_timeout.js
dom/tests/unit/xpcshell.ini
modules/libpref/init/all.js
--- a/dom/system/NetworkGeolocationProvider.js
+++ b/dom/system/NetworkGeolocationProvider.js
@@ -500,16 +500,22 @@ WifiGeoPositionProvider.prototype = {
       this.notifyListener("notifyError",
                           [POSITION_UNAVAILABLE]);
       return;
     }
     xhr.setRequestHeader("Content-Type", "application/json; charset=UTF-8");
     xhr.responseType = "json";
     xhr.mozBackgroundRequest = true;
     xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
+    xhr.timeout = Services.prefs.getIntPref("geo.wifi.xhr.timeout");
+    xhr.ontimeout = (function() {
+      LOG("Location request XHR timed out.")
+      this.notifyListener("notifyError",
+                          [POSITION_UNAVAILABLE]);
+    }).bind(this);
     xhr.onerror = (function() {
       this.notifyListener("notifyError",
                           [POSITION_UNAVAILABLE]);
     }).bind(this);
     xhr.onload = (function() {
       LOG("server returned status: " + xhr.status + " --> " +  JSON.stringify(xhr.response));
       if ((xhr.channel instanceof Ci.nsIHttpChannel && xhr.status != 200) ||
           !xhr.response || !xhr.response.location) {
new file mode 100644
--- /dev/null
+++ b/dom/tests/unit/test_geolocation_provider_timeout.js
@@ -0,0 +1,48 @@
+const Cc = Components.classes;
+const Ci = Components.interfaces;
+const Cu = Components.utils;
+
+Cu.import("resource://testing-common/httpd.js");
+
+var httpserver = null;
+var geolocation = null;
+
+function geoHandler(metadata, response)
+{
+  response.processAsync();
+}
+
+function successCallback() {
+  // The call shouldn't be sucessful.
+  do_check_true(false);
+  do_test_finished();
+}
+
+function errorCallback() {
+  do_check_true(true);
+  do_test_finished();
+}
+
+function run_test()
+{
+  do_test_pending();
+
+  // XPCShell does not get a profile by default. The geolocation service
+  // depends on the settings service which uses IndexedDB and IndexedDB
+  // needs a place where it can store databases.
+  do_get_profile();
+
+  httpserver = new HttpServer();
+  httpserver.registerPathHandler("/geo", geoHandler);
+  httpserver.start(-1);
+  var prefs = Cc["@mozilla.org/preferences-service;1"].getService(Ci.nsIPrefBranch);
+  prefs.setCharPref("geo.wifi.uri", "http://localhost:" +
+                      httpserver.identity.primaryPort + "/geo");
+  prefs.setBoolPref("dom.testing.ignore_ipc_principal", true);
+
+  // Setting timeout to a very low value to ensure time out will happen.
+  prefs.setIntPref("geo.wifi.xhr.timeout", 5);
+
+  geolocation = Cc["@mozilla.org/geolocation;1"].getService(Ci.nsISupports);
+  geolocation.getCurrentPosition(successCallback, errorCallback);
+}
--- a/dom/tests/unit/xpcshell.ini
+++ b/dom/tests/unit/xpcshell.ini
@@ -19,8 +19,10 @@ skip-if = os == "android"
 [test_geolocation_reset_accuracy_wrap.js]
 skip-if = os == "mac" || os == "android"
 [test_geolocation_position_unavailable.js]
 skip-if = os == "android"
 [test_geolocation_position_unavailable_wrap.js]
 skip-if = os == "mac" || os == "android"
 [test_PromiseDebugging.js]
 [test_xhr_init.js]
+[test_geolocation_provider_timeout.js]
+skip-if = os == "android"
--- a/modules/libpref/init/all.js
+++ b/modules/libpref/init/all.js
@@ -4330,16 +4330,19 @@ pref("layers.force-active", false);
 pref("layers.gralloc.disable", false);
 
 // Don't use compositor-lru on this platform
 pref("layers.compositor-lru-size", 0);
 
 // Enable/Disable the geolocation API for content
 pref("geo.enabled", true);
 
+// Timeout for outbound network geolocation provider XHR
+pref("geo.wifi.xhr.timeout", 60000);
+
 // Enable/Disable the orientation API for content
 pref("device.sensors.enabled", true);
 
 // Enable/Disable the device storage API for content
 pref("device.storage.enabled", false);
 
 // Toggle which thread the HTML5 parser uses for stream parsing
 pref("html5.offmainthread", true);