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 var BASE_URL = "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs";
3 function sleep(delay)
4 {
5 var start = Date.now();
6 while (Date.now() < start + delay);
7 }
9 function force_prompt(allow, callback) {
10 SpecialPowers.pushPrefEnv({"set": [["geo.prompt.testing", true], ["geo.prompt.testing.allow", allow]]}, callback);
11 }
13 function start_sending_garbage(callback)
14 {
15 SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=respond-garbage"]]}, function() {
16 // we need to be sure that all location data has been purged/set.
17 sleep(1000);
18 callback.call();
19 });
20 }
22 function stop_sending_garbage(callback)
23 {
24 SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, function() {
25 // we need to be sure that all location data has been purged/set.
26 sleep(1000);
27 callback.call();
28 });
29 }
31 function stop_geolocationProvider(callback)
32 {
33 SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=stop-responding"]]}, function() {
34 // we need to be sure that all location data has been purged/set.
35 sleep(1000);
36 callback.call();
37 });
38 }
40 function set_network_request_cache_enabled(enabled, callback)
41 {
42 SpecialPowers.pushPrefEnv({"set": [["geo.wifi.debug.requestCache.enabled", enabled]]}, callback);
43 }
45 function worse_geolocationProvider(callback)
46 {
47 SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=worse-accuracy"]]}, callback);
48 }
50 function resume_geolocationProvider(callback)
51 {
52 SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, callback);
53 }
55 function delay_geolocationProvider(delay, callback)
56 {
57 SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?delay=" + delay]]}, callback);
58 }
60 function send404_geolocationProvider(callback)
61 {
62 set_network_request_cache_enabled(false, function() {
63 SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=send404"]]}, callback);});
64 }
66 function check_geolocation(location) {
68 ok(location, "Check to see if this location is non-null");
70 ok("timestamp" in location, "Check to see if there is a timestamp");
72 // eventually, coords may be optional (eg, when civic addresses are supported)
73 ok("coords" in location, "Check to see if this location has a coords");
75 var coords = location.coords;
77 ok("latitude" in coords, "Check to see if there is a latitude");
78 ok("longitude" in coords, "Check to see if there is a longitude");
79 ok("accuracy" in coords, "Check to see if there is a accuracy");
81 // optional ok("altitude" in coords, "Check to see if there is a altitude");
82 // optional ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy");
83 // optional ok("heading" in coords, "Check to see if there is a heading");
84 // optional ok("speed" in coords, "Check to see if there is a speed");
86 ok (Math.abs(location.coords.latitude - 37.41857) < 0.001, "lat matches known value");
87 ok (Math.abs(location.coords.longitude + 122.08769) < 0.001, "lon matches known value");
88 // optional ok(location.coords.altitude == 42, "alt matches known value");
89 // optional ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value");
90 }
92 function toggleGeolocationSetting(value, callback) {
93 var mozSettings = window.navigator.mozSettings;
94 var lock = mozSettings.createLock();
96 var geoenabled = {"geolocation.enabled": value};
98 req = lock.set(geoenabled);
99 req.onsuccess = function () {
100 ok(true, "set done");
101 callback();
102 }
103 }