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