summaryrefslogtreecommitdiffstats
path: root/dom/system/gonk/tests/marionette/test_geolocation.js
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /dom/system/gonk/tests/marionette/test_geolocation.js
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/system/gonk/tests/marionette/test_geolocation.js')
-rw-r--r--dom/system/gonk/tests/marionette/test_geolocation.js117
1 files changed, 117 insertions, 0 deletions
diff --git a/dom/system/gonk/tests/marionette/test_geolocation.js b/dom/system/gonk/tests/marionette/test_geolocation.js
new file mode 100644
index 000000000..201c8b3e3
--- /dev/null
+++ b/dom/system/gonk/tests/marionette/test_geolocation.js
@@ -0,0 +1,117 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+MARIONETTE_TIMEOUT = 10000;
+
+var geolocation = window.navigator.geolocation;
+ok(geolocation);
+
+var sample = [];
+var result = [];
+var wpid;
+
+/**
+ * Grant special power to get the geolocation
+ */
+SpecialPowers.addPermission("geolocation", true, document);
+
+/**
+ * Disable wifi geolocation provider
+ */
+wifiUri = SpecialPowers.getCharPref("geo.wifi.uri");
+SpecialPowers.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=stop-responding");
+
+/**
+ * Helper that compares the geolocation against the web API.
+ */
+function verifyLocation() {
+
+ log("Sample:" + sample.join(','));
+ log("Result:" + result.join(','));
+
+ for (i in sample) {
+ is(sample.pop(), result.pop());
+ }
+
+ window.setTimeout(cleanup, 0);
+}
+
+/**
+ * Test story begins here.
+ */
+function setup() {
+ log("Providing initial setup: set geographic position watcher.");
+
+
+ wpid = geolocation.watchPosition(function(position) {
+ log("Position changes: (" + position.coords.latitude + "/" + position.coords.longitude + ")");
+ result.push(""+position.coords.latitude + "/" + position.coords.longitude);
+ });
+
+ lat = 0;
+ lon = 0;
+
+ cmd = "geo fix " + lon + " " + lat;
+ sample.push(lat+"/"+lon);
+
+ runEmulatorCmd(cmd, function(result) {
+ window.setTimeout(movePosition_1, 0);
+ });
+}
+
+function movePosition_1() {
+ log("Geolocation changes. Move to Position 1.");
+
+ lat = 25;
+ lon = 121.56499833333334;
+
+ cmd = "geo fix " + lon + " " + lat;
+ sample.push(lat+"/"+lon);
+
+ runEmulatorCmd(cmd, function(result) {
+ window.setTimeout(movePosition_2, 0);
+ });
+}
+
+function movePosition_2() {
+ log("Geolocation changes to a negative longitude. Move to Position 2.");
+
+ lat = 37.393;
+ lon = -122.08199833333335;
+
+ cmd = "geo fix " + lon + " " + lat;
+ sample.push(lat+"/"+lon);
+
+ runEmulatorCmd(cmd, function(result) {
+ window.setTimeout(movePosition_3, 0);
+ });
+}
+
+function movePosition_3() {
+ log("Geolocation changes with WatchPosition. Move to Position 3.");
+
+ lat = -22;
+ lon = -43;
+
+ cmd = "geo fix " + lon + " " + lat;
+ sample.push(lat+"/"+lon);
+
+ geolocation.getCurrentPosition(function(position) {
+ log("getCurrentPosition: Expected location: ("+lat+"/"+lon+"); Current location: (" + position.coords.latitude + "/" + position.coords.longitude + ")");
+ is(lat, position.coords.latitude);
+ is(lon, position.coords.longitude);
+ });
+
+ runEmulatorCmd(cmd, function(result) {
+ window.setTimeout(verifyLocation, 0);
+ });
+}
+
+function cleanup() {
+ geolocation.clearWatch(wpid);
+ SpecialPowers.removePermission("geolocation", document);
+ SpecialPowers.setCharPref("geo.wifi.uri", wifiUri);
+ finish();
+}
+
+setup();