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