michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: MARIONETTE_TIMEOUT = 10000; michael@0: michael@0: let geolocation = window.navigator.geolocation; michael@0: ok(geolocation); michael@0: michael@0: var sample = []; michael@0: var result = []; michael@0: var wpid; michael@0: michael@0: /** michael@0: * Grant special power to get the geolocation michael@0: */ michael@0: SpecialPowers.addPermission("geolocation", true, document); michael@0: michael@0: /** michael@0: * Disable wifi geolocation provider michael@0: */ michael@0: wifiUri = SpecialPowers.getCharPref("geo.wifi.uri"); michael@0: SpecialPowers.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=stop-responding"); michael@0: michael@0: /** michael@0: * Helper that compares the geolocation against the web API. michael@0: */ michael@0: function verifyLocation() { michael@0: michael@0: log("Sample:" + sample.join(',')); michael@0: log("Result:" + result.join(',')); michael@0: michael@0: for (i in sample) { michael@0: is(sample.pop(), result.pop()); michael@0: } michael@0: michael@0: window.setTimeout(cleanup, 0); michael@0: } michael@0: michael@0: /** michael@0: * Test story begins here. michael@0: */ michael@0: function setup() { michael@0: log("Providing initial setup: set geographic position watcher."); michael@0: michael@0: michael@0: wpid = geolocation.watchPosition(function(position) { michael@0: log("Position changes: (" + position.coords.latitude + "/" + position.coords.longitude + ")"); michael@0: result.push(""+position.coords.latitude + "/" + position.coords.longitude); michael@0: }); michael@0: michael@0: lat = 0; michael@0: lon = 0; michael@0: michael@0: cmd = "geo fix " + lon + " " + lat; michael@0: sample.push(lat+"/"+lon); michael@0: michael@0: runEmulatorCmd(cmd, function(result) { michael@0: window.setTimeout(movePosition_1, 0); michael@0: }); michael@0: } michael@0: michael@0: function movePosition_1() { michael@0: log("Geolocation changes. Move to Position 1."); michael@0: michael@0: lat = 25; michael@0: lon = 121.56499833333334; michael@0: michael@0: cmd = "geo fix " + lon + " " + lat; michael@0: sample.push(lat+"/"+lon); michael@0: michael@0: runEmulatorCmd(cmd, function(result) { michael@0: window.setTimeout(movePosition_2, 0); michael@0: }); michael@0: } michael@0: michael@0: function movePosition_2() { michael@0: log("Geolocation changes to a negative longitude. Move to Position 2."); michael@0: michael@0: lat = 37.393; michael@0: lon = -122.08199833333335; michael@0: michael@0: cmd = "geo fix " + lon + " " + lat; michael@0: sample.push(lat+"/"+lon); michael@0: michael@0: runEmulatorCmd(cmd, function(result) { michael@0: window.setTimeout(movePosition_3, 0); michael@0: }); michael@0: } michael@0: michael@0: function movePosition_3() { michael@0: log("Geolocation changes with WatchPosition. Move to Position 3."); michael@0: michael@0: lat = -22; michael@0: lon = -43; michael@0: michael@0: cmd = "geo fix " + lon + " " + lat; michael@0: sample.push(lat+"/"+lon); michael@0: michael@0: geolocation.getCurrentPosition(function(position) { michael@0: log("getCurrentPosition: Expected location: ("+lat+"/"+lon+"); Current location: (" + position.coords.latitude + "/" + position.coords.longitude + ")"); michael@0: is(lat, position.coords.latitude); michael@0: is(lon, position.coords.longitude); michael@0: }); michael@0: michael@0: runEmulatorCmd(cmd, function(result) { michael@0: window.setTimeout(verifyLocation, 0); michael@0: }); michael@0: } michael@0: michael@0: function cleanup() { michael@0: geolocation.clearWatch(wpid); michael@0: SpecialPowers.removePermission("geolocation", document); michael@0: SpecialPowers.setCharPref("geo.wifi.uri", wifiUri); michael@0: finish(); michael@0: } michael@0: michael@0: setup();