summaryrefslogtreecommitdiffstats
path: root/dom/tests/mochitest/geolocation
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
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')
-rw-r--r--dom/tests/mochitest/geolocation/chrome.ini6
-rw-r--r--dom/tests/mochitest/geolocation/geolocation.html13
-rw-r--r--dom/tests/mochitest/geolocation/geolocation_common.js92
-rw-r--r--dom/tests/mochitest/geolocation/mochitest.ini28
-rw-r--r--dom/tests/mochitest/geolocation/network_geolocation.sjs78
-rw-r--r--dom/tests/mochitest/geolocation/test_allowCurrent.html41
-rw-r--r--dom/tests/mochitest/geolocation/test_allowWatch.html43
-rw-r--r--dom/tests/mochitest/geolocation/test_cachedPosition.html83
-rw-r--r--dom/tests/mochitest/geolocation/test_cancelCurrent.html45
-rw-r--r--dom/tests/mochitest/geolocation/test_cancelWatch.html49
-rw-r--r--dom/tests/mochitest/geolocation/test_clearWatch.html72
-rw-r--r--dom/tests/mochitest/geolocation/test_clearWatchBeforeAllowing.html59
-rw-r--r--dom/tests/mochitest/geolocation/test_clearWatch_invalid.html47
-rw-r--r--dom/tests/mochitest/geolocation/test_errorcheck.html49
-rw-r--r--dom/tests/mochitest/geolocation/test_garbageWatch.html56
-rw-r--r--dom/tests/mochitest/geolocation/test_geolocation_is_undefined_when_pref_is_off.html35
-rw-r--r--dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html72
-rw-r--r--dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html58
-rw-r--r--dom/tests/mochitest/geolocation/test_manyCurrentSerial.html47
-rw-r--r--dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html57
-rw-r--r--dom/tests/mochitest/geolocation/test_manyWatchSerial.html54
-rw-r--r--dom/tests/mochitest/geolocation/test_manyWindows.html67
-rw-r--r--dom/tests/mochitest/geolocation/test_optional_api_params.html102
-rw-r--r--dom/tests/mochitest/geolocation/test_shutdown.html63
-rw-r--r--dom/tests/mochitest/geolocation/test_timeoutCurrent.html56
-rw-r--r--dom/tests/mochitest/geolocation/test_timeoutWatch.html65
-rw-r--r--dom/tests/mochitest/geolocation/test_timerRestartWatch.html69
-rw-r--r--dom/tests/mochitest/geolocation/test_windowClose.html36
-rw-r--r--dom/tests/mochitest/geolocation/test_worseAccuracyDoesNotBlockCallback.html47
-rw-r--r--dom/tests/mochitest/geolocation/windowTest.html40
30 files changed, 1629 insertions, 0 deletions
diff --git a/dom/tests/mochitest/geolocation/chrome.ini b/dom/tests/mochitest/geolocation/chrome.ini
new file mode 100644
index 000000000..1922074f1
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/chrome.ini
@@ -0,0 +1,6 @@
+[DEFAULT]
+support-files =
+ geolocation_common.js
+ network_geolocation.sjs
+
+[test_handlerSpinsEventLoop.html]
diff --git a/dom/tests/mochitest/geolocation/geolocation.html b/dom/tests/mochitest/geolocation/geolocation.html
new file mode 100644
index 000000000..e62f13e7d
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/geolocation.html
@@ -0,0 +1,13 @@
+<html>
+ <head>
+ <title>Simple access of geolocation</title>
+ <head>
+ <script>
+ function loadedWindow() {
+ opener.postMessage("loaded", "*");
+ }
+ navigator.geolocation.getCurrentPosition(loadedWindow, loadedWindow, {timeout:30000});
+ </script>
+ </head>
+ <body></body>
+</html>
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");
+}
+
diff --git a/dom/tests/mochitest/geolocation/mochitest.ini b/dom/tests/mochitest/geolocation/mochitest.ini
new file mode 100644
index 000000000..1afcc31cb
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/mochitest.ini
@@ -0,0 +1,28 @@
+[DEFAULT]
+support-files =
+ geolocation.html
+ geolocation_common.js
+ network_geolocation.sjs
+ windowTest.html
+
+[test_allowCurrent.html]
+[test_allowWatch.html]
+[test_cachedPosition.html]
+[test_cancelCurrent.html]
+[test_cancelWatch.html]
+[test_clearWatch.html]
+[test_clearWatchBeforeAllowing.html]
+[test_clearWatch_invalid.html]
+[test_errorcheck.html]
+[test_geolocation_is_undefined_when_pref_is_off.html]
+[test_manyCurrentConcurrent.html]
+[test_manyCurrentSerial.html]
+[test_manyWatchConcurrent.html]
+[test_manyWatchSerial.html]
+[test_manyWindows.html]
+[test_optional_api_params.html]
+[test_shutdown.html]
+[test_timeoutCurrent.html]
+[test_timerRestartWatch.html]
+[test_windowClose.html]
+[test_worseAccuracyDoesNotBlockCallback.html]
diff --git a/dom/tests/mochitest/geolocation/network_geolocation.sjs b/dom/tests/mochitest/geolocation/network_geolocation.sjs
new file mode 100644
index 000000000..6c7ca47be
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/network_geolocation.sjs
@@ -0,0 +1,78 @@
+function parseQueryString(str)
+{
+ if (str == "")
+ return {};
+
+ var paramArray = str.split("&");
+ var regex = /^([^=]+)=(.*)$/;
+ var params = {};
+ for (var i = 0, sz = paramArray.length; i < sz; i++)
+ {
+ var match = regex.exec(paramArray[i]);
+ if (!match)
+ throw "Bad parameter in queryString! '" + paramArray[i] + "'";
+ params[decodeURIComponent(match[1])] = decodeURIComponent(match[2]);
+ }
+
+ return params;
+}
+
+function getPosition(action)
+{
+ var response = {
+ status: "OK",
+ location: {
+ lat: 37.41857,
+ lng: -122.08769,
+ },
+ accuracy: (action == "worse-accuracy") ? 100 : 42,
+ };
+
+ return JSON.stringify(response);
+}
+
+var timer;
+function handleRequest(request, response)
+{
+ var params = parseQueryString(request.queryString);
+
+ if (params.action == "stop-responding") {
+ response.processAsync();
+ return;
+ }
+
+ var position = getPosition(params.action);
+
+ if (params.action == "respond-garbage") {
+ // better way?
+ var chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz";
+ position = "";
+ var len = Math.floor(Math.random() * 5000);
+
+ for (var i=0; i< len; i++) {
+ var c = Math.floor(Math.random() * chars.length);
+ position += chars.substring(c, c+1);
+ }
+ }
+
+ var response;
+ response.processAsync();
+ response.setStatusLine("1.0", 200, "OK");
+ response.setHeader("Cache-Control", "no-cache", false);
+ response.setHeader("Content-Type", "aplication/x-javascript", false);
+
+ var delay = 0;
+ if ('delay' in params) {
+ delay = params.delay;
+ }
+ if (params.action === "send404") {
+ response.setStatusLine("1.0", 404, "Not Found");
+ position = '';
+ }
+ timer = Components.classes["@mozilla.org/timer;1"].createInstance(Components.interfaces.nsITimer);
+ timer.initWithCallback(function() {
+ response.write(position);
+ response.finish();
+ }, delay, timer.TYPE_ONE_SHOT);
+}
+
diff --git a/dom/tests/mochitest/geolocation/test_allowCurrent.html b/dom/tests/mochitest/geolocation/test_allowCurrent.html
new file mode 100644
index 000000000..30836fb7b
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_allowCurrent.html
@@ -0,0 +1,41 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=478911
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Mozilla Bug 478911</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+
+function successCallback(position) {
+ check_geolocation(position);
+ SimpleTest.finish();
+}
+
+function test1() {
+ navigator.geolocation.getCurrentPosition(successCallback);
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_allowWatch.html b/dom/tests/mochitest/geolocation/test_allowWatch.html
new file mode 100644
index 000000000..4084e43bb
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_allowWatch.html
@@ -0,0 +1,43 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=478911
+-->
+<head>
+ <title>Test for watchPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Mozilla Bug 478911</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+var watchID;
+
+function successCallback(position) {
+ check_geolocation(position);
+ navigator.geolocation.clearWatch(watchID);
+ SimpleTest.finish();
+}
+
+function test1() {
+ watchID = navigator.geolocation.watchPosition(successCallback, null, null);
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_cachedPosition.html b/dom/tests/mochitest/geolocation/test_cachedPosition.html
new file mode 100644
index 000000000..067bf205f
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_cachedPosition.html
@@ -0,0 +1,83 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=850442
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=850442">Mozilla Bug 850442</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+/*
+The request cache vs. the PositionOptions cache is confusing to the reader, to explain:
+
+Testing uses mochitest httpd, so the network cache must be disabled in order for requests
+to propagate to mochitest httpd. Otherwise, every request looks like a geoip request,
+and the network request cache sees no reason to make a web request for location for geoip
+if it has already made geoip (or better) requests.
+
+We should investigate providing fake wifi and cell scans to the
+network location provider, then the network cache does not need to be shut off
+AND it will get testing coverage.
+
+*/
+resume_geolocationProvider(function() {
+ force_prompt(true, function () {
+ set_network_request_cache_enabled(false, test_cachedPosition)
+ });
+});
+
+function done() {
+ set_network_request_cache_enabled(true, function() {
+ resume_geolocationProvider(function() {
+ SimpleTest.finish();
+ });
+ });
+}
+
+function errorCallback(err) {
+ ok(false, "error callback should not have been called");
+ done();
+}
+
+function areTimesEqual(loc1, loc2) {
+ return loc1.timestamp === loc2.timestamp;
+}
+
+function test_cachedPosition() {
+ var cached = null;
+ navigator.geolocation.getCurrentPosition(function(pos) {
+ // first call is just to warm up the cache
+
+ navigator.geolocation.getCurrentPosition(function(pos) {
+ cached = pos;
+
+ navigator.geolocation.getCurrentPosition(function(pos) {
+ ok(areTimesEqual(pos, cached), "position should be equal to cached position");
+ navigator.geolocation.getCurrentPosition(function(pos) {
+ // force new position, can't be the one we have
+ ok(!areTimesEqual(pos, cached), "position should not be equal to cached position");
+ done();
+ }, errorCallback, {maximumAge: 0});
+ }, errorCallback, {maximumAge: 21600000});
+ }, errorCallback, {maximumAge: 21600000});
+ }, errorCallback, {maximumAge: 21600000});
+ }
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_cancelCurrent.html b/dom/tests/mochitest/geolocation/test_cancelCurrent.html
new file mode 100644
index 000000000..d71cfa350
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_cancelCurrent.html
@@ -0,0 +1,45 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=478911
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Mozilla Bug 478911</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(false, test1);
+});
+
+function failureCallback(error) {
+ ok(error.code == error.PERMISSION_DENIED, "Ensure that the error was PERMISSION_DENIED");
+ SimpleTest.finish();
+}
+
+function successCallback(position){
+ ok(0, "Success was called when it shouldn't have been. major problem");
+ SimpleTest.finish();
+}
+
+function test1() {
+ navigator.geolocation.getCurrentPosition(successCallback, failureCallback, null);
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_cancelWatch.html b/dom/tests/mochitest/geolocation/test_cancelWatch.html
new file mode 100644
index 000000000..493f412aa
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_cancelWatch.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=478911
+-->
+<head>
+ <title>Test for watchPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Mozilla Bug 478911</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(false, test1);
+});
+
+var watchID;
+
+function failureCallback(error) {
+ ok(error.code == error.PERMISSION_DENIED, "Ensure that the error was PERMISSION_DENIED");
+ SimpleTest.finish();
+}
+
+function successCallback(position){
+ ok(0, "Success was called when it shouldn't have been. major problem");
+ SimpleTest.finish();
+}
+
+function test1() {
+ watchID = navigator.geolocation.watchPosition(successCallback, failureCallback, null);
+}
+</script>
+</pre>
+</body>
+</html>
+
+
+
diff --git a/dom/tests/mochitest/geolocation/test_clearWatch.html b/dom/tests/mochitest/geolocation/test_clearWatch.html
new file mode 100644
index 000000000..85f81acd9
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_clearWatch.html
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=478911
+-->
+<head>
+ <title>Test for watchPosition and clearWatch</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Mozilla Bug 478911</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+var hasBeenCleared = false;
+var successWasCalledAfterClear = false;
+var firstCallback = true;
+
+function failureCallback(error)
+{
+ ok(0, "we should not be seeing failures from this watchPosition");
+}
+
+function successCallback(position) {
+ ok(true, "successCallback was called, hasBeenCleared=" + hasBeenCleared +
+ ", successWasCalledAfterClear=" + successWasCalledAfterClear);
+ if (hasBeenCleared == true) {
+ successWasCalledAfterClear = true;
+ }
+ if (firstCallback) {
+ SimpleTest.executeSoon(clearWatch);
+ firstCallback = false;
+ }
+}
+
+function clearWatch() {
+ ok(true, "clearWatch was called, hasBeenCleared=" + hasBeenCleared +
+ ", successWasCalledAfterClear=" + successWasCalledAfterClear);
+ navigator.geolocation.clearWatch(watchID);
+ hasBeenCleared = true;
+ SimpleTest.executeSoon(testAccepted);
+}
+
+function testAccepted() {
+ ok(true, "testAccepted was called, hasBeenCleared=" + hasBeenCleared +
+ ", successWasCalledAfterClear=" + successWasCalledAfterClear);
+ ok(!successWasCalledAfterClear, "The successCallback should not be called after clear");
+ SimpleTest.finish();
+}
+
+function test1() {
+ ok(true, "Getting the watchPosition");
+ watchID = navigator.geolocation.watchPosition(successCallback, failureCallback, null);
+ ok(true, "Waiting");
+}
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/tests/mochitest/geolocation/test_clearWatchBeforeAllowing.html b/dom/tests/mochitest/geolocation/test_clearWatchBeforeAllowing.html
new file mode 100644
index 000000000..25b588959
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_clearWatchBeforeAllowing.html
@@ -0,0 +1,59 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=886026
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank"
+href="https://bugzilla.mozilla.org/show_bug.cgi?id=886026">Mozilla Bug 886026</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+resume_geolocationProvider(function() {
+ force_prompt(true, run_test);
+});
+
+function run_test() {
+ var successCallbackCalled = false,
+ errorCallbackCalled = false;
+
+ var watchId = navigator.geolocation.watchPosition(
+ function(pos) {
+ successCallbackCalled = true;
+ }, function(err) {
+ errorCallbackCalled = true;
+ }
+ );
+
+ navigator.geolocation.getCurrentPosition(
+ function(pos) {
+ SimpleTest.executeSoon(function() {
+ ok(successCallbackCalled == false,
+ "getCurrentPosition : Success callback should not have been called");
+
+ ok(errorCallbackCalled == false,
+ "getCurrentPosition : Error callback should not have been called");
+
+ SimpleTest.finish();
+ });
+ }
+ );
+
+ navigator.geolocation.clearWatch(watchId);
+}
+</script>
+</pre>
+</body>
+</html> \ No newline at end of file
diff --git a/dom/tests/mochitest/geolocation/test_clearWatch_invalid.html b/dom/tests/mochitest/geolocation/test_clearWatch_invalid.html
new file mode 100644
index 000000000..0e2aed61c
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_clearWatch_invalid.html
@@ -0,0 +1,47 @@
+ <!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=463039
+-->
+<head>
+ <title>Test for Bug 463039</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=463039">Mozilla Bug 463039</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+function test1() {
+ navigator.geolocation.watchPosition(function(){});
+
+ // there are no watches, so this should always throw
+ for (x=-10; x<10; x++) {
+ navigator.geolocation.clearWatch(x);
+ ok(1, "clearWatch should not throw");
+ }
+
+ // lets try something huge
+ navigator.geolocation.clearWatch(Number.MAX_VALUE);
+ ok(1, "clearWatch should not throw");
+
+ SimpleTest.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_errorcheck.html b/dom/tests/mochitest/geolocation/test_errorcheck.html
new file mode 100644
index 000000000..ffe5ce882
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_errorcheck.html
@@ -0,0 +1,49 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=684722
+-->
+<head>
+ <title>Test for ErrorChecking </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=684722">Mozilla Bug 684722</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+function test1() {
+ send404_geolocationProvider(test2);
+}
+
+function errorCallback(error) {
+ is(error.code,
+ SpecialPowers.Ci.nsIDOMGeoPositionError.POSITION_UNAVAILABLE, "Geolocation error handler fired");
+ SimpleTest.finish();
+}
+
+function successCallback(position) {
+ test2();
+}
+
+function test2() {
+ navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_garbageWatch.html b/dom/tests/mochitest/geolocation/test_garbageWatch.html
new file mode 100644
index 000000000..167dc286e
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_garbageWatch.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=482260
+-->
+<head>
+ <title>Test for garbage data returned from location provider </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=455327">Mozilla Bug 482260</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+/** Test for Bug **/
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+function test1() {
+ start_sending_garbage(test2);
+}
+
+function successCallback(pos){
+ ok(false, "success should have never been called.");
+ stop_sending_garbage(function() {SimpleTest.finish();});
+}
+
+function errorCallback(err) {
+ ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
+ stop_sending_garbage(function() { SimpleTest.finish(); });
+}
+
+var options = {
+ maximumAge: 0,
+ timeout: 1000,
+};
+
+function test2() {
+ navigator.geolocation.watchPosition(successCallback,
+ errorCallback,
+ options);
+}
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/tests/mochitest/geolocation/test_geolocation_is_undefined_when_pref_is_off.html b/dom/tests/mochitest/geolocation/test_geolocation_is_undefined_when_pref_is_off.html
new file mode 100644
index 000000000..882dacec3
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_geolocation_is_undefined_when_pref_is_off.html
@@ -0,0 +1,35 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=884921
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank"
+href="https://bugzilla.mozilla.org/show_bug.cgi?id=884921">Mozilla Bug 884921</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+SpecialPowers.pushPrefEnv({set: [["geo.enabled", false]]}, function() {
+ is(navigator.geolocation, undefined);
+ is("geolocation" in navigator, false);
+ SimpleTest.finish();
+});
+
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html b/dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html
new file mode 100644
index 000000000..19913d28b
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_handlerSpinsEventLoop.html
@@ -0,0 +1,72 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=911595
+-->
+<head>
+ <title>Test for spinning the event loop inside position handlers</title>
+ <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=911595 ">Mozilla Bug 911595</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+/*
+ * In bug 911595 , spinning the event loop from inside position
+ * handlers could cause both success and error callbacks to be
+ * fired for the same request if that request has a small timeout.
+ */
+
+var { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+var successCallbackCalled = false;
+function successCallback(position) {
+ successCallbackCalled = true;
+ check_geolocation(position);
+ while (!timeoutPassed) {
+ SpecialPowers.spinEventLoop(window);
+ }
+ info("TEST-INFO | successCallback called");
+ check();
+}
+
+var errorCallbackCalled = false;
+function errorCallback(error) {
+ errorCallbackCalled = true;
+ info("TEST-INFO | errorCallback called");
+ check();
+}
+
+function check() {
+ ok(successCallbackCalled != errorCallbackCalled, "Ensure only one callback is called");
+ SimpleTest.finish();
+}
+
+var timeoutPassed = false;
+var timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
+function test1() {
+ SpecialPowers.pushPrefEnv({"set": [["geo.wifi.timeToWaitBeforeSending", 10]]}, function() {
+ navigator.geolocation.getCurrentPosition(successCallback, errorCallback, {timeout: 500});
+ timer.initWithCallback(timer => {
+ timeoutPassed = true;
+ }, 600, Ci.nsITimer.TYPE_ONE_SHOT);
+ });
+}
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html b/dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html
new file mode 100644
index 000000000..3fbccac53
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_manyCurrentConcurrent.html
@@ -0,0 +1,58 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=482260
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=482260">Mozilla Bug 482260</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+var successCallbackCalled = 0;
+var failureCallbackCalled = 0;
+const totalResults = 100;
+
+function successCallback(position) {
+ successCallbackCalled++;
+ testPassed();
+}
+
+function failureCallback(code) {
+ failureCallbackCalled++;
+ testPassed();
+}
+
+function test1() {
+ for (var x = 0; x < totalResults; x++)
+ navigator.geolocation.getCurrentPosition(successCallback, failureCallback);
+}
+
+function testPassed() {
+ if (successCallbackCalled + failureCallbackCalled != totalResults)
+ return;
+ is(failureCallbackCalled, 0, "no failure callbacks should have been received");
+ SimpleTest.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_manyCurrentSerial.html b/dom/tests/mochitest/geolocation/test_manyCurrentSerial.html
new file mode 100644
index 000000000..3a0d96344
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_manyCurrentSerial.html
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=482260
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=482260">Mozilla Bug 482260</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+var keepGoing = 10;
+
+function successCallback(position) {
+ if (keepGoing-- > 0) {
+ setTimeout(function() {navigator.geolocation.getCurrentPosition(successCallback);}, 0);
+ return;
+ }
+
+ ok(1, "100 successful calls");
+ SimpleTest.finish();
+}
+
+function test1() {
+ navigator.geolocation.getCurrentPosition(successCallback);
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html b/dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html
new file mode 100644
index 000000000..f1714e7ab
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_manyWatchConcurrent.html
@@ -0,0 +1,57 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=482260
+-->
+<head>
+ <title>Test for watchPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=482260">Mozilla Bug 482260</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+var successCallbackCalled = 0;
+var failureCallbackCalled = 0;
+const totalResults = 100;
+
+function successCallback(position) {
+ successCallbackCalled++;
+ testPassed();
+}
+
+function failureCallback(code) {
+ failureCallbackCalled++;
+ testPassed();
+}
+
+function test1() {
+ for (var x = 0; x < totalResults; x++)
+ navigator.geolocation.watchPosition(successCallback, failureCallback);
+}
+
+function testPassed() {
+ if (successCallbackCalled + failureCallbackCalled != totalResults)
+ return;
+ is(failureCallbackCalled, 0, "no failure callbacks should have been received");
+ SimpleTest.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/tests/mochitest/geolocation/test_manyWatchSerial.html b/dom/tests/mochitest/geolocation/test_manyWatchSerial.html
new file mode 100644
index 000000000..bb166e7d2
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_manyWatchSerial.html
@@ -0,0 +1,54 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=482260
+-->
+<head>
+ <title>Test for watchPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=482260">Mozilla Bug 482260</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+var watchID = 0;
+var completeCount = 10;
+
+
+function successCallback(position) {
+
+ navigator.geolocation.clearWatch(watchID);
+
+ completeCount--;
+
+ if (completeCount==0) {
+ ok(1, "all watchPosition successCallbacks called");
+ SimpleTest.finish();
+ return;
+ }
+
+ watchID = navigator.geolocation.watchPosition(successCallback);
+}
+
+function test1() {
+ watchID = navigator.geolocation.watchPosition(successCallback);
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_manyWindows.html b/dom/tests/mochitest/geolocation/test_manyWindows.html
new file mode 100644
index 000000000..a2e682ba1
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_manyWindows.html
@@ -0,0 +1,67 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=478911
+-->
+<head>
+ <title>Test for many windows </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank"
+href="https://bugzilla.mozilla.org/show_bug.cgi?id=478911">Crash in Multiple Windows</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+// ensure we are using the right testing provider
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+/** Test for Bug **/
+
+var numberOfWindows = 5; // 20 seems to be the default max popups during the mochitest run
+var loadedWindows = 0;
+
+var windows = new Array(numberOfWindows);
+
+addEventListener("message", function() {
+ ++loadedWindows;
+ if (loadedWindows == numberOfWindows) {
+ SimpleTest.executeSoon(closeWindows);
+ }
+}, false);
+
+function test1() {
+ for(var i = 0; i < numberOfWindows; i++) {
+ windows[i] = window.open("geolocation.html", "_blank", "width=700,height=400");
+ }
+}
+
+function closeWindows()
+{
+ for(var i = 0; i < numberOfWindows; i++) {
+ windows[i].close();
+ }
+ SimpleTest.waitForFocus(done);
+}
+
+SimpleTest.waitForExplicitFinish();
+
+function done()
+{
+ ok(navigator.geolocation, "Opened a bunch of windows and didn't crash.");
+ SimpleTest.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/tests/mochitest/geolocation/test_optional_api_params.html b/dom/tests/mochitest/geolocation/test_optional_api_params.html
new file mode 100644
index 000000000..466024be5
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_optional_api_params.html
@@ -0,0 +1,102 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=452566
+-->
+<head>
+ <title>Test for Bug 452566</title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=452566">Mozilla Bug 452566</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+// ensure we are using the right testing provider
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+/** Test for Bug 452566 **/
+function test1() {
+ ok(navigator.geolocation, "Should have geolocation");
+
+ var exception = null;
+ try {
+ navigator.geolocation.getCurrentPosition();
+ } catch(ex if ex instanceof TypeError) {
+ exception = ex;
+ }
+ ok(exception, "Should have got an exception");
+
+ exception = null;
+ try {
+ navigator.geolocation.getCurrentPosition(function() {});
+ } catch(ex if ex instanceof TypeError) {
+ exception = ex;
+ }
+ ok(!exception, exception);
+
+ exception = null;
+ try {
+ navigator.geolocation.getCurrentPosition(function() {}, function() {});
+ } catch(ex if ex instanceof TypeError) {
+ exception = ex;
+ }
+ ok(!exception, exception);
+
+ exception = null;
+ try {
+ navigator.geolocation.getCurrentPosition(function() {}, function() {}, {});
+ } catch(ex if ex instanceof TypeError) {
+ exception = ex;
+ }
+ ok(!exception, exception);
+
+ exception = null;
+ try {
+ navigator.geolocation.watchPosition();
+ } catch(ex if ex instanceof TypeError) {
+ exception = ex;
+ }
+ ok(exception, "Should have got an exception");
+
+ exception = null;
+ try {
+ navigator.geolocation.watchPosition(function() {});
+ } catch(ex if ex instanceof TypeError) {
+ exception = ex;
+ }
+ ok(!exception, exception);
+
+ exception = null;
+ try {
+ navigator.geolocation.watchPosition(function() {}, function() {});
+ } catch(ex if ex instanceof TypeError) {
+ exception = ex;
+ }
+ ok(!exception, exception);
+
+ exception = null;
+ try {
+ navigator.geolocation.watchPosition(function() {}, function() {}, {});
+ } catch(ex if ex instanceof TypeError) {
+ exception = ex;
+ }
+ ok(!exception, exception);
+
+ SimpleTest.finish();
+}
+
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/tests/mochitest/geolocation/test_shutdown.html b/dom/tests/mochitest/geolocation/test_shutdown.html
new file mode 100644
index 000000000..a837ba30b
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_shutdown.html
@@ -0,0 +1,63 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=716127
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=716127">Mozilla Bug 716127</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+function successCallback(position) {
+ check_geolocation(position);
+
+ SpecialPowers.pushPrefEnv({'set': [['geo.timeout', 100]]}, function() {
+ delay_geolocationProvider(1000, function() {
+ force_prompt(true, function() {
+ navigator.geolocation.getCurrentPosition(success2, handle_error, {maximumAge: 0});
+ });
+ });
+
+ });
+}
+
+function errorCallback() {
+ ok(false, "unexpected error");
+ SimpleTest.finish();
+}
+
+function test1() {
+ navigator.geolocation.getCurrentPosition(successCallback, errorCallback);
+}
+
+function success2(position) {
+ check_geolocation(position);
+ SimpleTest.finish();
+}
+
+function handle_error() {
+ ok(false, "geolocation provider should not have timed out");
+ SimpleTest.finish();
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_timeoutCurrent.html b/dom/tests/mochitest/geolocation/test_timeoutCurrent.html
new file mode 100644
index 000000000..af6cab328
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_timeoutCurrent.html
@@ -0,0 +1,56 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=858827
+-->
+<head>
+ <title>Test for timeout option </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=858827">Mozilla Bug 858827</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+
+function successCallback(position) {
+ ok(false, "we should not be seeing successCallback here.");
+ SimpleTest.finish();
+}
+
+function errorCallback(err) {
+ ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
+ resume_geolocationProvider(function() {
+ SimpleTest.finish();
+ });
+}
+
+
+var options = {
+ maximumAge: 0,
+ timeout: 0
+};
+
+function test1() {
+ navigator.geolocation.getCurrentPosition(successCallback,
+ errorCallback,
+ options);
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_timeoutWatch.html b/dom/tests/mochitest/geolocation/test_timeoutWatch.html
new file mode 100644
index 000000000..f51c0d53b
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_timeoutWatch.html
@@ -0,0 +1,65 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=455327
+-->
+<head>
+ <title>Test for timeout option </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=455327">Mozilla Bug 478911</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+/** Test for Bug **/
+
+// ensure we are using the right testing provider
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+SimpleTest.waitForExplicitFinish();
+
+function test1() {
+ stop_geolocationProvider(test2);
+}
+
+function successCallback(pos){
+ ok(false, "success should have never been called.");
+ resume_geolocationProvider(function() {
+ SimpleTest.finish();
+ });
+}
+
+function errorCallback(err) {
+ if (err.code == err.POSITION_UNAVAILABLE)
+ ok(false, "nothing is hooked up to test against.");
+ else
+ ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
+ resume_geolocationProvider(function() {
+ SimpleTest.finish();
+ });
+}
+
+
+var options = {
+ maximumAge: 0,
+ timeout: 10
+};
+
+function test2() {
+ navigator.geolocation.watchPosition(successCallback,
+ errorCallback,
+ options);
+}
+</script>
+</pre>
+</body>
+</html>
diff --git a/dom/tests/mochitest/geolocation/test_timerRestartWatch.html b/dom/tests/mochitest/geolocation/test_timerRestartWatch.html
new file mode 100644
index 000000000..d24b54e0a
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_timerRestartWatch.html
@@ -0,0 +1,69 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=526326
+-->
+<head>
+ <title>Test for watchPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=526326">Mozilla Bug 526326</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+// ensure we are using the right testing provider
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+var watchID;
+var times = 0;
+
+function errorCallback(err) {
+ ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
+ times++;
+
+ // make sure we got at least 3 times errorCallback
+ if (times >= 3) {
+ navigator.geolocation.clearWatch(watchID);
+ resume_geolocationProvider(function() {
+ set_network_request_cache_enabled(true,
+ function() { SimpleTest.finish(); } );
+ });
+ }
+}
+
+function successCallback(position) {
+ ok(1, "on success");
+ // Now that we got a success callback, lets try to ensure
+ // that we get a timeout error.
+ // The network cache is already off, now stop the sjs from reponding to requests
+ stop_geolocationProvider(function(){});
+}
+
+var options = {
+ maximumAge: 0,
+ timeout: 1000
+};
+
+function test1() {
+ set_network_request_cache_enabled(false,
+ function() {
+ watchID = navigator.geolocation.watchPosition(successCallback, errorCallback, options);
+ });
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_windowClose.html b/dom/tests/mochitest/geolocation/test_windowClose.html
new file mode 100644
index 000000000..bbb5c3f9f
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_windowClose.html
@@ -0,0 +1,36 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=493615
+-->
+<head>
+ <title>Test for geolocation in chrome </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=493615">Mozilla Bug 493615</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+function done() {
+ ok(1, "no crash, so pass.");
+ SimpleTest.finish();
+}
+
+SimpleTest.waitForExplicitFinish();
+force_prompt(true, function() {
+ window.open("windowTest.html");
+});
+
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/test_worseAccuracyDoesNotBlockCallback.html b/dom/tests/mochitest/geolocation/test_worseAccuracyDoesNotBlockCallback.html
new file mode 100644
index 000000000..b2339f888
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/test_worseAccuracyDoesNotBlockCallback.html
@@ -0,0 +1,47 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=494924
+-->
+<head>
+ <title>Test for getCurrentPosition </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=494924">Mozilla Bug 494924</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+
+SimpleTest.waitForExplicitFinish();
+
+resume_geolocationProvider(function() {
+ force_prompt(true, test1);
+});
+
+function successCallback2(position) {
+ check_geolocation(position);
+ SimpleTest.finish();
+}
+
+function successCallback1(position) {
+ check_geolocation(position);
+ worse_geolocationProvider(function() {
+ navigator.geolocation.getCurrentPosition(successCallback2, null, { maximumAge: 0 });
+ });
+}
+
+function test1() {
+ navigator.geolocation.getCurrentPosition(successCallback1, null, { maximumAge: 0 });
+}
+</script>
+</pre>
+</body>
+</html>
+
diff --git a/dom/tests/mochitest/geolocation/windowTest.html b/dom/tests/mochitest/geolocation/windowTest.html
new file mode 100644
index 000000000..235a00639
--- /dev/null
+++ b/dom/tests/mochitest/geolocation/windowTest.html
@@ -0,0 +1,40 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=493615
+-->
+<head>
+ <title>Test for closing a window while it is doing a geolocation request </title>
+ <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="text/javascript" src="geolocation_common.js"></script>
+
+<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=493615">Mozilla Bug 493615</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+<script class="testbody" type="text/javascript">
+var finished = false;
+
+function successCallback(position) {
+ // watchPosition can notify more than once.
+ if (finished) {
+ return;
+ }
+ finished = true;
+
+ var opener = window.opener;
+ window.close();
+ opener.done();
+}
+
+navigator.geolocation.watchPosition(successCallback, null, null);
+</script>
+</pre>
+</body>
+</html>
+