2008-09-05 03:31:09 +04:00
|
|
|
|
2010-08-31 20:15:52 +04:00
|
|
|
function sleep(delay)
|
|
|
|
{
|
|
|
|
var start = Date.now();
|
|
|
|
while (Date.now() < start + delay);
|
|
|
|
}
|
|
|
|
|
2013-08-27 19:59:28 +04:00
|
|
|
function force_prompt(allow, callback) {
|
|
|
|
SpecialPowers.pushPrefEnv({"set": [["geo.prompt.testing", true], ["geo.prompt.testing.allow", allow]]}, callback);
|
2010-08-31 20:15:52 +04:00
|
|
|
}
|
|
|
|
|
2013-08-27 19:59:28 +04:00
|
|
|
function start_sending_garbage(callback)
|
2009-08-15 03:12:09 +04:00
|
|
|
{
|
2013-08-27 19:59:28 +04:00
|
|
|
SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=respond-garbage"]]}, function() {
|
|
|
|
// we need to be sure that all location data has been purged/set.
|
|
|
|
sleep(1000);
|
|
|
|
callback.call();
|
|
|
|
});
|
2009-08-15 03:12:09 +04:00
|
|
|
}
|
|
|
|
|
2013-08-27 19:59:28 +04:00
|
|
|
function stop_sending_garbage(callback)
|
2009-08-15 03:12:09 +04:00
|
|
|
{
|
2013-08-27 19:59:28 +04:00
|
|
|
SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"]]}, function() {
|
|
|
|
// we need to be sure that all location data has been purged/set.
|
|
|
|
sleep(1000);
|
|
|
|
callback.call();
|
|
|
|
});
|
2009-08-15 03:12:09 +04:00
|
|
|
}
|
|
|
|
|
2013-08-27 19:59:28 +04:00
|
|
|
function stop_geolocationProvider(callback)
|
2009-03-15 07:03:21 +03:00
|
|
|
{
|
2013-08-27 19:59:28 +04:00
|
|
|
SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=stop-responding"]]}, function() {
|
|
|
|
// we need to be sure that all location data has been purged/set.
|
|
|
|
sleep(1000);
|
|
|
|
callback.call();
|
|
|
|
});
|
2009-03-15 07:03:21 +03:00
|
|
|
}
|
2008-09-05 03:31:09 +04:00
|
|
|
|
2013-08-27 19:59:28 +04:00
|
|
|
function worse_geolocationProvider(callback)
|
2011-01-05 00:25:04 +03:00
|
|
|
{
|
2013-08-27 19:59:28 +04:00
|
|
|
SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=worse-accuracy"]]}, callback);
|
2011-01-05 00:25:04 +03:00
|
|
|
}
|
|
|
|
|
2013-08-27 19:59:28 +04:00
|
|
|
function resume_geolocationProvider(callback)
|
2009-03-15 07:03:21 +03:00
|
|
|
{
|
2013-08-27 19:59:28 +04:00
|
|
|
SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"]]}, callback);
|
2009-03-15 07:03:21 +03:00
|
|
|
}
|
2008-09-05 03:31:09 +04:00
|
|
|
|
2013-08-27 19:59:28 +04:00
|
|
|
function delay_geolocationProvider(delay, callback)
|
2012-01-10 00:27:43 +04:00
|
|
|
{
|
2013-08-27 19:59:28 +04:00
|
|
|
SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?delay=" + delay]]}, callback);
|
2012-01-10 00:27:43 +04:00
|
|
|
}
|
|
|
|
|
2008-07-16 03:37:48 +04:00
|
|
|
function check_geolocation(location) {
|
|
|
|
|
|
|
|
ok(location, "Check to see if this location is non-null");
|
|
|
|
|
2008-09-05 03:31:09 +04:00
|
|
|
ok("timestamp" in location, "Check to see if there is a timestamp");
|
2008-08-14 20:35:49 +04:00
|
|
|
|
2009-01-07 20:44:44 +03:00
|
|
|
// eventually, coords may be optional (eg, when civic addresses are supported)
|
|
|
|
ok("coords" in location, "Check to see if this location has a coords");
|
|
|
|
|
|
|
|
var coords = location.coords;
|
|
|
|
|
|
|
|
ok("latitude" in coords, "Check to see if there is a latitude");
|
|
|
|
ok("longitude" in coords, "Check to see if there is a longitude");
|
|
|
|
ok("accuracy" in coords, "Check to see if there is a accuracy");
|
2011-08-10 00:02:39 +04:00
|
|
|
|
|
|
|
// optional ok("altitude" in coords, "Check to see if there is a altitude");
|
|
|
|
// optional ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy");
|
2009-08-15 03:12:09 +04:00
|
|
|
// 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");
|
2011-08-10 00:02:39 +04:00
|
|
|
// optional ok(location.coords.altitude == 42, "alt matches known value");
|
|
|
|
// optional ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value");
|
2008-09-05 03:31:09 +04:00
|
|
|
}
|
2013-04-17 18:03:29 +04:00
|
|
|
|
|
|
|
function toggleGeolocationSetting(value, callback) {
|
|
|
|
var mozSettings = window.navigator.mozSettings;
|
|
|
|
var lock = mozSettings.createLock();
|
|
|
|
|
|
|
|
var geoenabled = {"geolocation.enabled": value};
|
|
|
|
|
|
|
|
req = lock.set(geoenabled);
|
|
|
|
req.onsuccess = function () {
|
|
|
|
ok(true, "set done");
|
|
|
|
callback();
|
|
|
|
}
|
|
|
|
}
|