summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/geolocation/geolocation_common.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/tests/mochitest/geolocation/geolocation_common.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/tests/mochitest/geolocation/geolocation_common.js')
-rw-r--r--dom/tests/mochitest/geolocation/geolocation_common.js92
1 files changed, 92 insertions, 0 deletions
diff --git a/dom/tests/mochitest/geolocation/geolocation_common.js b/dom/tests/mochitest/geolocation/geolocation_common.js
new file mode 100644
index 000000000..74a4bd34e
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/geolocation_common.js
@@ -0,0 +1,92 @@
+var harness = SimpleTest.harnessParameters.testRoot == "chrome" ? "chrome" : "tests";
+var BASE_URL = "http://mochi.test:8888/" + harness + "/dom/tests/mochitest/geolocation/network_geolocation.sjs";
+
+function sleep(delay)
+{
+ var start = Date.now();
+ while (Date.now() < start + delay);
+}
+
+function force_prompt(allow, callback) {
+ SpecialPowers.pushPrefEnv({"set": [["geo.prompt.testing", true], ["geo.prompt.testing.allow", allow]]}, callback);
+}
+
+function start_sending_garbage(callback)
+{
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=respond-garbage"]]}, function() {
+ // we need to be sure that all location data has been purged/set.
+ sleep(1000);
+ callback.call();
+ });
+}
+
+function stop_sending_garbage(callback)
+{
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, function() {
+ // we need to be sure that all location data has been purged/set.
+ sleep(1000);
+ callback.call();
+ });
+}
+
+function stop_geolocationProvider(callback)
+{
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=stop-responding"]]}, function() {
+ // we need to be sure that all location data has been purged/set.
+ sleep(1000);
+ callback.call();
+ });
+}
+
+function set_network_request_cache_enabled(enabled, callback)
+{
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.debug.requestCache.enabled", enabled]]}, callback);
+}
+
+function worse_geolocationProvider(callback)
+{
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=worse-accuracy"]]}, callback);
+}
+
+function resume_geolocationProvider(callback)
+{
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + ""]]}, callback);
+}
+
+function delay_geolocationProvider(delay, callback)
+{
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?delay=" + delay]]}, callback);
+}
+
+function send404_geolocationProvider(callback)
+{
+ set_network_request_cache_enabled(false, function() {
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.uri", BASE_URL + "?action=send404"]]}, callback);});
+}
+
+function check_geolocation(location) {
+
+ ok(location, "Check to see if this location is non-null");
+
+ ok("timestamp" in location, "Check to see if there is a timestamp");
+
+ // eventually, coords may be optional (eg, when civic addresses are supported)
+ ok("coords" in location, "Check to see if this location has a coords");
+
+ var coords = location.coords;
+
+ ok("latitude" in coords, "Check to see if there is a latitude");
+ ok("longitude" in coords, "Check to see if there is a longitude");
+ ok("accuracy" in coords, "Check to see if there is a accuracy");
+
+ // optional ok("altitude" in coords, "Check to see if there is a altitude");
+ // optional ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy");
+ // optional ok("heading" in coords, "Check to see if there is a heading");
+ // optional ok("speed" in coords, "Check to see if there is a speed");
+
+ ok (Math.abs(location.coords.latitude - 37.41857) < 0.001, "lat matches known value");
+ ok (Math.abs(location.coords.longitude + 122.08769) < 0.001, "lon matches known value");
+ // optional ok(location.coords.altitude == 42, "alt matches known value");
+ // optional ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value");
+}
+