Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | var BASE_URL = "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs"; |
michael@0 | 2 | |
michael@0 | 3 | function sleep(delay) |
michael@0 | 4 | { |
michael@0 | 5 | var start = Date.now(); |
michael@0 | 6 | while (Date.now() < start + delay); |
michael@0 | 7 | } |
michael@0 | 8 | |
michael@0 | 9 | function force_prompt(allow, callback) { |
michael@0 | 10 | SpecialPowers.pushPrefEnv({"set": [["geo.prompt.testing", true], ["geo.prompt.testing.allow", allow]]}, callback); |
michael@0 | 11 | } |
michael@0 | 12 | |
michael@0 | 13 | function start_sending_garbage(callback) |
michael@0 | 14 | { |
michael@0 | 15 | SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=respond-garbage"]]}, function() { |
michael@0 | 16 | // we need to be sure that all location data has been purged/set. |
michael@0 | 17 | sleep(1000); |
michael@0 | 18 | callback.call(); |
michael@0 | 19 | }); |
michael@0 | 20 | } |
michael@0 | 21 | |
michael@0 | 22 | function stop_sending_garbage(callback) |
michael@0 | 23 | { |
michael@0 | 24 | SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, function() { |
michael@0 | 25 | // we need to be sure that all location data has been purged/set. |
michael@0 | 26 | sleep(1000); |
michael@0 | 27 | callback.call(); |
michael@0 | 28 | }); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | function stop_geolocationProvider(callback) |
michael@0 | 32 | { |
michael@0 | 33 | SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=stop-responding"]]}, function() { |
michael@0 | 34 | // we need to be sure that all location data has been purged/set. |
michael@0 | 35 | sleep(1000); |
michael@0 | 36 | callback.call(); |
michael@0 | 37 | }); |
michael@0 | 38 | } |
michael@0 | 39 | |
michael@0 | 40 | function set_network_request_cache_enabled(enabled, callback) |
michael@0 | 41 | { |
michael@0 | 42 | SpecialPowers.pushPrefEnv({"set": [["geo.wifi.debug.requestCache.enabled", enabled]]}, callback); |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | function worse_geolocationProvider(callback) |
michael@0 | 46 | { |
michael@0 | 47 | SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=worse-accuracy"]]}, callback); |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | function resume_geolocationProvider(callback) |
michael@0 | 51 | { |
michael@0 | 52 | SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, callback); |
michael@0 | 53 | } |
michael@0 | 54 | |
michael@0 | 55 | function delay_geolocationProvider(delay, callback) |
michael@0 | 56 | { |
michael@0 | 57 | SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?delay=" + delay]]}, callback); |
michael@0 | 58 | } |
michael@0 | 59 | |
michael@0 | 60 | function send404_geolocationProvider(callback) |
michael@0 | 61 | { |
michael@0 | 62 | set_network_request_cache_enabled(false, function() { |
michael@0 | 63 | SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=send404"]]}, callback);}); |
michael@0 | 64 | } |
michael@0 | 65 | |
michael@0 | 66 | function check_geolocation(location) { |
michael@0 | 67 | |
michael@0 | 68 | ok(location, "Check to see if this location is non-null"); |
michael@0 | 69 | |
michael@0 | 70 | ok("timestamp" in location, "Check to see if there is a timestamp"); |
michael@0 | 71 | |
michael@0 | 72 | // eventually, coords may be optional (eg, when civic addresses are supported) |
michael@0 | 73 | ok("coords" in location, "Check to see if this location has a coords"); |
michael@0 | 74 | |
michael@0 | 75 | var coords = location.coords; |
michael@0 | 76 | |
michael@0 | 77 | ok("latitude" in coords, "Check to see if there is a latitude"); |
michael@0 | 78 | ok("longitude" in coords, "Check to see if there is a longitude"); |
michael@0 | 79 | ok("accuracy" in coords, "Check to see if there is a accuracy"); |
michael@0 | 80 | |
michael@0 | 81 | // optional ok("altitude" in coords, "Check to see if there is a altitude"); |
michael@0 | 82 | // optional ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy"); |
michael@0 | 83 | // optional ok("heading" in coords, "Check to see if there is a heading"); |
michael@0 | 84 | // optional ok("speed" in coords, "Check to see if there is a speed"); |
michael@0 | 85 | |
michael@0 | 86 | ok (Math.abs(location.coords.latitude - 37.41857) < 0.001, "lat matches known value"); |
michael@0 | 87 | ok (Math.abs(location.coords.longitude + 122.08769) < 0.001, "lon matches known value"); |
michael@0 | 88 | // optional ok(location.coords.altitude == 42, "alt matches known value"); |
michael@0 | 89 | // optional ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value"); |
michael@0 | 90 | } |
michael@0 | 91 | |
michael@0 | 92 | function toggleGeolocationSetting(value, callback) { |
michael@0 | 93 | var mozSettings = window.navigator.mozSettings; |
michael@0 | 94 | var lock = mozSettings.createLock(); |
michael@0 | 95 | |
michael@0 | 96 | var geoenabled = {"geolocation.enabled": value}; |
michael@0 | 97 | |
michael@0 | 98 | req = lock.set(geoenabled); |
michael@0 | 99 | req.onsuccess = function () { |
michael@0 | 100 | ok(true, "set done"); |
michael@0 | 101 | callback(); |
michael@0 | 102 | } |
michael@0 | 103 | } |