diff --git a/build/automation.py.in b/build/automation.py.in index 03e1e7fa80f..685b620d7cf 100644 --- a/build/automation.py.in +++ b/build/automation.py.in @@ -260,6 +260,8 @@ user_pref("media.cache_size", 100); user_pref("security.warn_viewing_mixed", false); user_pref("geo.wifi.uri", "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"); +user_pref("geo.wifi.testing", true); + user_pref("camino.warn_when_closing", false); // Camino-only, harmless to others // Make url-classifier updates so rare that they won't affect tests diff --git a/dom/src/geolocation/NetworkGeolocationProvider.js b/dom/src/geolocation/NetworkGeolocationProvider.js index 60591c001d6..1a03cb14a5c 100644 --- a/dom/src/geolocation/NetworkGeolocationProvider.js +++ b/dom/src/geolocation/NetworkGeolocationProvider.js @@ -4,6 +4,7 @@ const Ci = Components.interfaces; const Cc = Components.classes; var gLoggingEnabled = false; +var gTestingEnabled = false; function nowInSeconds() { @@ -51,10 +52,12 @@ WifiGeoAddressObject.prototype = { flags: Ci.nsIClassInfo.DOM_OBJECT, }; -function WifiGeoCoordsObject(lat, lon, acc) { +function WifiGeoCoordsObject(lat, lon, acc, alt, altacc) { this.latitude = lat; this.longitude = lon; this.accuracy = acc; + this.altitude = alt; + this.altitudeAccuracy = altacc; }; WifiGeoCoordsObject.prototype = { @@ -77,27 +80,29 @@ WifiGeoCoordsObject.prototype = { latitude: 0, longitude: 0, accuracy: 0, - altitude: 0, altitudeAccuracy: 0, - heading: 0, - speed: 0, + }; -function WifiGeoPositionObject(lat, lon, acc, address) { +function WifiGeoPositionObject(location, address) { - this.coords = new WifiGeoCoordsObject(lat, lon, acc); + this.coords = new WifiGeoCoordsObject(location.latitude, + location.longitude, + location.accuracy || 12450, // .5 * circumference of earth. + location.altitude || 0, + location.altitude_accuracy || 0); if (address) { - this.address = new WifiGeoAddressObject(address.street_number, - address.street, - address.premises, - address.city, - address.county, - address.region, - address.country, - address.country_code, - address.postal_code); + this.address = new WifiGeoAddressObject(address.street_number || null, + address.street || null, + address.premises || null, + address.city || null, + address.county || null, + address.region || null, + address.country || null, + address.country_code || null, + address.postal_code || null); } else this.address = null; @@ -132,6 +137,11 @@ function WifiGeoPositionProvider() { try { gLoggingEnabled = this.prefService.getBoolPref("geo.wifi.logging.enabled"); } catch (e) {} + + try { + gTestingEnabled = this.prefService.getBoolPref("geo.wifi.testing"); + } catch (e) {} + }; WifiGeoPositionProvider.prototype = { @@ -165,9 +175,15 @@ WifiGeoPositionProvider.prototype = { LOG("provider url = " + this.provider_url); // if we don't see anything in 5 seconds, kick of one IP geo lookup. + // if we are testing, just hammer this callback so that we are more or less + // always sending data. It doesn't matter if we have an access point or not. this.hasSeenWiFi = false; this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer); - this.timer.initWithCallback(this, 5000, this.timer.TYPE_ONE_SHOT); + if (gTestingEnabled == false) + this.timer.initWithCallback(this, 5000, this.timer.TYPE_ONE_SHOT); + else + this.timer.initWithCallback(this, 200, this.timer.TYPE_REPEATING_SLACK); + let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService); os.addObserver(this, "private-browsing", false); @@ -292,10 +308,7 @@ WifiGeoPositionProvider.prototype = { LOG("No address in response"); } - var newLocation = new WifiGeoPositionObject(response.location.latitude, - response.location.longitude, - response.location.accuracy, - address); + var newLocation = new WifiGeoPositionObject(response.location, address); var update = Cc["@mozilla.org/geolocation/service;1"].getService(Ci.nsIGeolocationUpdate); update.update(newLocation); diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index 775ab633bd5..753a7f900f9 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -275,7 +275,7 @@ nsGeolocationRequest::Allow() PRInt32 tempAge; nsresult rv = mOptions->GetMaximumAge(&tempAge); if (NS_SUCCEEDED(rv)) { - if (tempAge > 0) + if (tempAge >= 0) maximumAge = tempAge; } } diff --git a/dom/tests/mochitest/geolocation/Makefile.in b/dom/tests/mochitest/geolocation/Makefile.in index 2e7bec010e7..1a53396d6fc 100644 --- a/dom/tests/mochitest/geolocation/Makefile.in +++ b/dom/tests/mochitest/geolocation/Makefile.in @@ -45,6 +45,11 @@ include $(DEPTH)/config/autoconf.mk include $(topsrcdir)/config/rules.mk _TEST_FILES = \ + test_manyCurrentSerial.html \ + test_manyCurrentConcurrent.html \ + test_garbageWatch.html \ + test_manyWatchConcurrent.html \ + test_manyWatchSerial.html \ test_manyWindows.html \ test_allowCurrent.html \ test_allowWatch.html \ @@ -56,7 +61,7 @@ _TEST_FILES = \ geolocation_common.js \ geolocation.html \ test_optional_api_params.html \ - network_geolocation.sjs \ + network_geolocation.sjs \ $(NULL) diff --git a/dom/tests/mochitest/geolocation/geolocation_common.js b/dom/tests/mochitest/geolocation/geolocation_common.js index 9c2712300ad..115c05772bb 100644 --- a/dom/tests/mochitest/geolocation/geolocation_common.js +++ b/dom/tests/mochitest/geolocation/geolocation_common.js @@ -1,9 +1,29 @@ + +function start_sending_garbage() +{ + var baseURL = "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"; + var xhr = new XMLHttpRequest(); + xhr.open("GET", baseURL + "?action=start-garbage", false); + xhr.send(null); +} + + +function stop_sending_garbage() +{ + var baseURL = "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"; + var xhr = new XMLHttpRequest(); + xhr.open("GET", baseURL + "?action=stop-garbage", false); + xhr.send(null); +} + + + function stop_geolocationProvider() { var baseURL = "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"; var xhr = new XMLHttpRequest(); - xhr.open("GET", baseURL + "?action=stop-responding&latitude=3.14", false); + xhr.open("GET", baseURL + "?action=stop-responding", false); xhr.send(null); } @@ -31,8 +51,15 @@ function check_geolocation(location) { ok("altitude" in coords, "Check to see if there is a altitude"); ok("accuracy" in coords, "Check to see if there is a accuracy"); ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy"); - ok("heading" in coords, "Check to see if there is a heading"); - ok("speed" in coords, "Check to see if there is a speed"); + + // optional ok("heading" in coords, "Check to see if there is a heading"); + // optional ok("speed" in coords, "Check to see if there is a speed"); + + ok (location.coords.latitude == 37.41857, "lat matches known value"); + ok (location.coords.longitude == -122.08769, "lon matches known value"); + ok(location.coords.altitude == 42, "alt matches known value"); + ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value"); + } diff --git a/dom/tests/mochitest/geolocation/network_geolocation.sjs b/dom/tests/mochitest/geolocation/network_geolocation.sjs index b386b567fb5..61c907bcc02 100644 --- a/dom/tests/mochitest/geolocation/network_geolocation.sjs +++ b/dom/tests/mochitest/geolocation/network_geolocation.sjs @@ -31,19 +31,40 @@ function controlResponse(params) if (params.action == "start-responding") { setState("sendresponse", "true"); } + + if (params.action == "start-garbage") { + setState("garbage", "true"); + } + + if (params.action == "stop-garbage") { + setState("garbage", "false"); + } + } function setPosition(params) { + var address = { + street_number: "street_number", + street: "street", + premises: "premises", + city: "city", + county: "county", + region: "region", + country: "country", + country_code: "country_code", + postal_code: "postal_code", + }; + + // this isnt' the w3c data structure, it is the network location provider structure. + var coords = { latitude: 37.41857, longitude: -122.08769, altitude: 42, accuracy: 42, - altitudeAccuracy: 42, - heading: 42, - speed: 42, + altitude_accuracy: 42, }; var geoposition = { @@ -91,6 +112,19 @@ function handleRequest(request, response) var sendresponse = getState("sendresponse"); var position = getState("coords"); + if (getState("garbage") == "true") { + // better way? + var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz"; + position = ""; + var len = Math.floor(Math.random() * 5000); + + for (var i=0; i< len; i++) { + var c = Math.floor(Math.random() * chars.length); + position += chars.substring(c, c+1); + } + } + + if (sendresponse == "true") { response.setStatusLine("1.0", 200, "OK"); response.setHeader("Cache-Control", "no-cache", false); diff --git a/dom/tests/mochitest/geolocation/test_allowCurrent.html b/dom/tests/mochitest/geolocation/test_allowCurrent.html index efb2aca386c..57520a03007 100644 --- a/dom/tests/mochitest/geolocation/test_allowCurrent.html +++ b/dom/tests/mochitest/geolocation/test_allowCurrent.html @@ -35,8 +35,12 @@ function accept() { SimpleTest.waitForExplicitFinish(); +var options = { + maximumAge: 0, +}; + // one-shot position requests -navigator.geolocation.getCurrentPosition(successCallback, null, null); +navigator.geolocation.getCurrentPosition(successCallback, null, options); setTimeout(accept, 50); diff --git a/dom/tests/mochitest/geolocation/test_cancelWatch.html b/dom/tests/mochitest/geolocation/test_cancelWatch.html index 2a1fc1367cc..1eb03a26d59 100644 --- a/dom/tests/mochitest/geolocation/test_cancelWatch.html +++ b/dom/tests/mochitest/geolocation/test_cancelWatch.html @@ -36,7 +36,7 @@ function successCallback(position){ SimpleTest.waitForExplicitFinish(); -watchID = navigator.geolocation.getCurrentPosition(successCallback, failureCallback, null); +watchID = navigator.geolocation.watchPosition(successCallback, failureCallback, null); // click deny setTimeout(clickNotificationButton, 50, kDenyButton); diff --git a/dom/tests/mochitest/geolocation/test_garbageWatch.html b/dom/tests/mochitest/geolocation/test_garbageWatch.html new file mode 100644 index 00000000000..154a92b822d --- /dev/null +++ b/dom/tests/mochitest/geolocation/test_garbageWatch.html @@ -0,0 +1,55 @@ + + + + + Test for garbage data returned from location provider + + + + + + + +Mozilla Bug 482260 +

+ +
+
+
+ + diff --git a/dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html b/dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html new file mode 100644 index 00000000000..1ae0aa09152 --- /dev/null +++ b/dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html @@ -0,0 +1,62 @@ + + + + + Test for getCurrentPosition + + + + + + + +Mozilla Bug 482260 +

+ +
+
+
+ + + diff --git a/dom/tests/mochitest/geolocation/test_manyCurrentSerial.html b/dom/tests/mochitest/geolocation/test_manyCurrentSerial.html new file mode 100644 index 00000000000..e99c73b046d --- /dev/null +++ b/dom/tests/mochitest/geolocation/test_manyCurrentSerial.html @@ -0,0 +1,55 @@ + + + + + Test for getCurrentPosition + + + + + + + +Mozilla Bug 482260 +

+ +
+
+
+ + + diff --git a/dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html b/dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html new file mode 100644 index 00000000000..dc5dacb594d --- /dev/null +++ b/dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html @@ -0,0 +1,61 @@ + + + + + Test for watchPosition + + + + + + + +Mozilla Bug 482260 +

+ +
+
+
+ + diff --git a/dom/tests/mochitest/geolocation/test_manyWatchSerial.html b/dom/tests/mochitest/geolocation/test_manyWatchSerial.html new file mode 100644 index 00000000000..12b86dfa3c9 --- /dev/null +++ b/dom/tests/mochitest/geolocation/test_manyWatchSerial.html @@ -0,0 +1,62 @@ + + + + + Test for watchPosition + + + + + + + +Mozilla Bug 482260 +

+ +
+
+
+ + +