dom/system/gonk/tests/marionette/test_geolocation.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /* Any copyright is dedicated to the Public Domain.
michael@0 2 * http://creativecommons.org/publicdomain/zero/1.0/ */
michael@0 3
michael@0 4 MARIONETTE_TIMEOUT = 10000;
michael@0 5
michael@0 6 let geolocation = window.navigator.geolocation;
michael@0 7 ok(geolocation);
michael@0 8
michael@0 9 var sample = [];
michael@0 10 var result = [];
michael@0 11 var wpid;
michael@0 12
michael@0 13 /**
michael@0 14 * Grant special power to get the geolocation
michael@0 15 */
michael@0 16 SpecialPowers.addPermission("geolocation", true, document);
michael@0 17
michael@0 18 /**
michael@0 19 * Disable wifi geolocation provider
michael@0 20 */
michael@0 21 wifiUri = SpecialPowers.getCharPref("geo.wifi.uri");
michael@0 22 SpecialPowers.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=stop-responding");
michael@0 23
michael@0 24 /**
michael@0 25 * Helper that compares the geolocation against the web API.
michael@0 26 */
michael@0 27 function verifyLocation() {
michael@0 28
michael@0 29 log("Sample:" + sample.join(','));
michael@0 30 log("Result:" + result.join(','));
michael@0 31
michael@0 32 for (i in sample) {
michael@0 33 is(sample.pop(), result.pop());
michael@0 34 }
michael@0 35
michael@0 36 window.setTimeout(cleanup, 0);
michael@0 37 }
michael@0 38
michael@0 39 /**
michael@0 40 * Test story begins here.
michael@0 41 */
michael@0 42 function setup() {
michael@0 43 log("Providing initial setup: set geographic position watcher.");
michael@0 44
michael@0 45
michael@0 46 wpid = geolocation.watchPosition(function(position) {
michael@0 47 log("Position changes: (" + position.coords.latitude + "/" + position.coords.longitude + ")");
michael@0 48 result.push(""+position.coords.latitude + "/" + position.coords.longitude);
michael@0 49 });
michael@0 50
michael@0 51 lat = 0;
michael@0 52 lon = 0;
michael@0 53
michael@0 54 cmd = "geo fix " + lon + " " + lat;
michael@0 55 sample.push(lat+"/"+lon);
michael@0 56
michael@0 57 runEmulatorCmd(cmd, function(result) {
michael@0 58 window.setTimeout(movePosition_1, 0);
michael@0 59 });
michael@0 60 }
michael@0 61
michael@0 62 function movePosition_1() {
michael@0 63 log("Geolocation changes. Move to Position 1.");
michael@0 64
michael@0 65 lat = 25;
michael@0 66 lon = 121.56499833333334;
michael@0 67
michael@0 68 cmd = "geo fix " + lon + " " + lat;
michael@0 69 sample.push(lat+"/"+lon);
michael@0 70
michael@0 71 runEmulatorCmd(cmd, function(result) {
michael@0 72 window.setTimeout(movePosition_2, 0);
michael@0 73 });
michael@0 74 }
michael@0 75
michael@0 76 function movePosition_2() {
michael@0 77 log("Geolocation changes to a negative longitude. Move to Position 2.");
michael@0 78
michael@0 79 lat = 37.393;
michael@0 80 lon = -122.08199833333335;
michael@0 81
michael@0 82 cmd = "geo fix " + lon + " " + lat;
michael@0 83 sample.push(lat+"/"+lon);
michael@0 84
michael@0 85 runEmulatorCmd(cmd, function(result) {
michael@0 86 window.setTimeout(movePosition_3, 0);
michael@0 87 });
michael@0 88 }
michael@0 89
michael@0 90 function movePosition_3() {
michael@0 91 log("Geolocation changes with WatchPosition. Move to Position 3.");
michael@0 92
michael@0 93 lat = -22;
michael@0 94 lon = -43;
michael@0 95
michael@0 96 cmd = "geo fix " + lon + " " + lat;
michael@0 97 sample.push(lat+"/"+lon);
michael@0 98
michael@0 99 geolocation.getCurrentPosition(function(position) {
michael@0 100 log("getCurrentPosition: Expected location: ("+lat+"/"+lon+"); Current location: (" + position.coords.latitude + "/" + position.coords.longitude + ")");
michael@0 101 is(lat, position.coords.latitude);
michael@0 102 is(lon, position.coords.longitude);
michael@0 103 });
michael@0 104
michael@0 105 runEmulatorCmd(cmd, function(result) {
michael@0 106 window.setTimeout(verifyLocation, 0);
michael@0 107 });
michael@0 108 }
michael@0 109
michael@0 110 function cleanup() {
michael@0 111 geolocation.clearWatch(wpid);
michael@0 112 SpecialPowers.removePermission("geolocation", document);
michael@0 113 SpecialPowers.setCharPref("geo.wifi.uri", wifiUri);
michael@0 114 finish();
michael@0 115 }
michael@0 116
michael@0 117 setup();

mercurial