michael@0: var BASE_URL = "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"; michael@0: michael@0: function sleep(delay) michael@0: { michael@0: var start = Date.now(); michael@0: while (Date.now() < start + delay); michael@0: } michael@0: michael@0: function force_prompt(allow, callback) { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.prompt.testing", true], ["geo.prompt.testing.allow", allow]]}, callback); michael@0: } michael@0: michael@0: function start_sending_garbage(callback) michael@0: { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=respond-garbage"]]}, function() { michael@0: // we need to be sure that all location data has been purged/set. michael@0: sleep(1000); michael@0: callback.call(); michael@0: }); michael@0: } michael@0: michael@0: function stop_sending_garbage(callback) michael@0: { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, function() { michael@0: // we need to be sure that all location data has been purged/set. michael@0: sleep(1000); michael@0: callback.call(); michael@0: }); michael@0: } michael@0: michael@0: function stop_geolocationProvider(callback) michael@0: { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=stop-responding"]]}, function() { michael@0: // we need to be sure that all location data has been purged/set. michael@0: sleep(1000); michael@0: callback.call(); michael@0: }); michael@0: } michael@0: michael@0: function set_network_request_cache_enabled(enabled, callback) michael@0: { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.wifi.debug.requestCache.enabled", enabled]]}, callback); michael@0: } michael@0: michael@0: function worse_geolocationProvider(callback) michael@0: { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=worse-accuracy"]]}, callback); michael@0: } michael@0: michael@0: function resume_geolocationProvider(callback) michael@0: { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, callback); michael@0: } michael@0: michael@0: function delay_geolocationProvider(delay, callback) michael@0: { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?delay=" + delay]]}, callback); michael@0: } michael@0: michael@0: function send404_geolocationProvider(callback) michael@0: { michael@0: set_network_request_cache_enabled(false, function() { michael@0: SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=send404"]]}, callback);}); michael@0: } michael@0: michael@0: function check_geolocation(location) { michael@0: michael@0: ok(location, "Check to see if this location is non-null"); michael@0: michael@0: ok("timestamp" in location, "Check to see if there is a timestamp"); michael@0: michael@0: // eventually, coords may be optional (eg, when civic addresses are supported) michael@0: ok("coords" in location, "Check to see if this location has a coords"); michael@0: michael@0: var coords = location.coords; michael@0: michael@0: ok("latitude" in coords, "Check to see if there is a latitude"); michael@0: ok("longitude" in coords, "Check to see if there is a longitude"); michael@0: ok("accuracy" in coords, "Check to see if there is a accuracy"); michael@0: michael@0: // optional ok("altitude" in coords, "Check to see if there is a altitude"); michael@0: // optional ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy"); michael@0: // optional ok("heading" in coords, "Check to see if there is a heading"); michael@0: // optional ok("speed" in coords, "Check to see if there is a speed"); michael@0: michael@0: ok (Math.abs(location.coords.latitude - 37.41857) < 0.001, "lat matches known value"); michael@0: ok (Math.abs(location.coords.longitude + 122.08769) < 0.001, "lon matches known value"); michael@0: // optional ok(location.coords.altitude == 42, "alt matches known value"); michael@0: // optional ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value"); michael@0: } michael@0: michael@0: function toggleGeolocationSetting(value, callback) { michael@0: var mozSettings = window.navigator.mozSettings; michael@0: var lock = mozSettings.createLock(); michael@0: michael@0: var geoenabled = {"geolocation.enabled": value}; michael@0: michael@0: req = lock.set(geoenabled); michael@0: req.onsuccess = function () { michael@0: ok(true, "set done"); michael@0: callback(); michael@0: } michael@0: }