зеркало из https://github.com/mozilla/pjs.git
Bug 482260. Add more tests cases for geolocation. Also fixes max age not being able to be set to zero. r=mfinkle,jmaher.
This commit is contained in:
Родитель
8e8e5161c4
Коммит
f89258075c
|
@ -260,6 +260,8 @@ user_pref("media.cache_size", 100);
|
|||
user_pref("security.warn_viewing_mixed", false);
|
||||
|
||||
user_pref("geo.wifi.uri", "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
|
||||
user_pref("geo.wifi.testing", true);
|
||||
|
||||
user_pref("camino.warn_when_closing", false); // Camino-only, harmless to others
|
||||
|
||||
// Make url-classifier updates so rare that they won't affect tests
|
||||
|
|
|
@ -4,6 +4,7 @@ const Ci = Components.interfaces;
|
|||
const Cc = Components.classes;
|
||||
|
||||
var gLoggingEnabled = false;
|
||||
var gTestingEnabled = false;
|
||||
|
||||
function nowInSeconds()
|
||||
{
|
||||
|
@ -51,10 +52,12 @@ WifiGeoAddressObject.prototype = {
|
|||
flags: Ci.nsIClassInfo.DOM_OBJECT,
|
||||
};
|
||||
|
||||
function WifiGeoCoordsObject(lat, lon, acc) {
|
||||
function WifiGeoCoordsObject(lat, lon, acc, alt, altacc) {
|
||||
this.latitude = lat;
|
||||
this.longitude = lon;
|
||||
this.accuracy = acc;
|
||||
this.altitude = alt;
|
||||
this.altitudeAccuracy = altacc;
|
||||
};
|
||||
|
||||
WifiGeoCoordsObject.prototype = {
|
||||
|
@ -77,27 +80,29 @@ WifiGeoCoordsObject.prototype = {
|
|||
latitude: 0,
|
||||
longitude: 0,
|
||||
accuracy: 0,
|
||||
|
||||
altitude: 0,
|
||||
altitudeAccuracy: 0,
|
||||
heading: 0,
|
||||
speed: 0,
|
||||
|
||||
};
|
||||
|
||||
function WifiGeoPositionObject(lat, lon, acc, address) {
|
||||
function WifiGeoPositionObject(location, address) {
|
||||
|
||||
this.coords = new WifiGeoCoordsObject(lat, lon, acc);
|
||||
this.coords = new WifiGeoCoordsObject(location.latitude,
|
||||
location.longitude,
|
||||
location.accuracy || 12450, // .5 * circumference of earth.
|
||||
location.altitude || 0,
|
||||
location.altitude_accuracy || 0);
|
||||
|
||||
if (address) {
|
||||
this.address = new WifiGeoAddressObject(address.street_number,
|
||||
address.street,
|
||||
address.premises,
|
||||
address.city,
|
||||
address.county,
|
||||
address.region,
|
||||
address.country,
|
||||
address.country_code,
|
||||
address.postal_code);
|
||||
this.address = new WifiGeoAddressObject(address.street_number || null,
|
||||
address.street || null,
|
||||
address.premises || null,
|
||||
address.city || null,
|
||||
address.county || null,
|
||||
address.region || null,
|
||||
address.country || null,
|
||||
address.country_code || null,
|
||||
address.postal_code || null);
|
||||
}
|
||||
else
|
||||
this.address = null;
|
||||
|
@ -132,6 +137,11 @@ function WifiGeoPositionProvider() {
|
|||
try {
|
||||
gLoggingEnabled = this.prefService.getBoolPref("geo.wifi.logging.enabled");
|
||||
} catch (e) {}
|
||||
|
||||
try {
|
||||
gTestingEnabled = this.prefService.getBoolPref("geo.wifi.testing");
|
||||
} catch (e) {}
|
||||
|
||||
};
|
||||
|
||||
WifiGeoPositionProvider.prototype = {
|
||||
|
@ -165,9 +175,15 @@ WifiGeoPositionProvider.prototype = {
|
|||
LOG("provider url = " + this.provider_url);
|
||||
|
||||
// if we don't see anything in 5 seconds, kick of one IP geo lookup.
|
||||
// if we are testing, just hammer this callback so that we are more or less
|
||||
// always sending data. It doesn't matter if we have an access point or not.
|
||||
this.hasSeenWiFi = false;
|
||||
this.timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
|
||||
this.timer.initWithCallback(this, 5000, this.timer.TYPE_ONE_SHOT);
|
||||
if (gTestingEnabled == false)
|
||||
this.timer.initWithCallback(this, 5000, this.timer.TYPE_ONE_SHOT);
|
||||
else
|
||||
this.timer.initWithCallback(this, 200, this.timer.TYPE_REPEATING_SLACK);
|
||||
|
||||
|
||||
let os = Cc["@mozilla.org/observer-service;1"].getService(Ci.nsIObserverService);
|
||||
os.addObserver(this, "private-browsing", false);
|
||||
|
@ -292,10 +308,7 @@ WifiGeoPositionProvider.prototype = {
|
|||
LOG("No address in response");
|
||||
}
|
||||
|
||||
var newLocation = new WifiGeoPositionObject(response.location.latitude,
|
||||
response.location.longitude,
|
||||
response.location.accuracy,
|
||||
address);
|
||||
var newLocation = new WifiGeoPositionObject(response.location, address);
|
||||
|
||||
var update = Cc["@mozilla.org/geolocation/service;1"].getService(Ci.nsIGeolocationUpdate);
|
||||
update.update(newLocation);
|
||||
|
|
|
@ -275,7 +275,7 @@ nsGeolocationRequest::Allow()
|
|||
PRInt32 tempAge;
|
||||
nsresult rv = mOptions->GetMaximumAge(&tempAge);
|
||||
if (NS_SUCCEEDED(rv)) {
|
||||
if (tempAge > 0)
|
||||
if (tempAge >= 0)
|
||||
maximumAge = tempAge;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -45,6 +45,11 @@ include $(DEPTH)/config/autoconf.mk
|
|||
include $(topsrcdir)/config/rules.mk
|
||||
|
||||
_TEST_FILES = \
|
||||
test_manyCurrentSerial.html \
|
||||
test_manyCurrentConcurrent.html \
|
||||
test_garbageWatch.html \
|
||||
test_manyWatchConcurrent.html \
|
||||
test_manyWatchSerial.html \
|
||||
test_manyWindows.html \
|
||||
test_allowCurrent.html \
|
||||
test_allowWatch.html \
|
||||
|
@ -56,7 +61,7 @@ _TEST_FILES = \
|
|||
geolocation_common.js \
|
||||
geolocation.html \
|
||||
test_optional_api_params.html \
|
||||
network_geolocation.sjs \
|
||||
network_geolocation.sjs \
|
||||
$(NULL)
|
||||
|
||||
|
||||
|
|
|
@ -1,9 +1,29 @@
|
|||
|
||||
|
||||
function start_sending_garbage()
|
||||
{
|
||||
var baseURL = "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs";
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", baseURL + "?action=start-garbage", false);
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
|
||||
function stop_sending_garbage()
|
||||
{
|
||||
var baseURL = "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs";
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", baseURL + "?action=stop-garbage", false);
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
function stop_geolocationProvider()
|
||||
{
|
||||
var baseURL = "http://localhost:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs";
|
||||
var xhr = new XMLHttpRequest();
|
||||
xhr.open("GET", baseURL + "?action=stop-responding&latitude=3.14", false);
|
||||
xhr.open("GET", baseURL + "?action=stop-responding", false);
|
||||
xhr.send(null);
|
||||
}
|
||||
|
||||
|
@ -31,8 +51,15 @@ function check_geolocation(location) {
|
|||
ok("altitude" in coords, "Check to see if there is a altitude");
|
||||
ok("accuracy" in coords, "Check to see if there is a accuracy");
|
||||
ok("altitudeAccuracy" in coords, "Check to see if there is a alt accuracy");
|
||||
ok("heading" in coords, "Check to see if there is a heading");
|
||||
ok("speed" in coords, "Check to see if there is a speed");
|
||||
|
||||
// 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 (location.coords.latitude == 37.41857, "lat matches known value");
|
||||
ok (location.coords.longitude == -122.08769, "lon matches known value");
|
||||
ok(location.coords.altitude == 42, "alt matches known value");
|
||||
ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value");
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -31,19 +31,40 @@ function controlResponse(params)
|
|||
if (params.action == "start-responding") {
|
||||
setState("sendresponse", "true");
|
||||
}
|
||||
|
||||
if (params.action == "start-garbage") {
|
||||
setState("garbage", "true");
|
||||
}
|
||||
|
||||
if (params.action == "stop-garbage") {
|
||||
setState("garbage", "false");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
function setPosition(params)
|
||||
{
|
||||
var address = {
|
||||
street_number: "street_number",
|
||||
street: "street",
|
||||
premises: "premises",
|
||||
city: "city",
|
||||
county: "county",
|
||||
region: "region",
|
||||
country: "country",
|
||||
country_code: "country_code",
|
||||
postal_code: "postal_code",
|
||||
};
|
||||
|
||||
// this isnt' the w3c data structure, it is the network location provider structure.
|
||||
|
||||
var coords = {
|
||||
latitude: 37.41857,
|
||||
longitude: -122.08769,
|
||||
|
||||
altitude: 42,
|
||||
accuracy: 42,
|
||||
altitudeAccuracy: 42,
|
||||
heading: 42,
|
||||
speed: 42,
|
||||
altitude_accuracy: 42,
|
||||
};
|
||||
|
||||
var geoposition = {
|
||||
|
@ -91,6 +112,19 @@ function handleRequest(request, response)
|
|||
var sendresponse = getState("sendresponse");
|
||||
var position = getState("coords");
|
||||
|
||||
if (getState("garbage") == "true") {
|
||||
// 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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (sendresponse == "true") {
|
||||
response.setStatusLine("1.0", 200, "OK");
|
||||
response.setHeader("Cache-Control", "no-cache", false);
|
||||
|
|
|
@ -35,8 +35,12 @@ function accept() {
|
|||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var options = {
|
||||
maximumAge: 0,
|
||||
};
|
||||
|
||||
// one-shot position requests
|
||||
navigator.geolocation.getCurrentPosition(successCallback, null, null);
|
||||
navigator.geolocation.getCurrentPosition(successCallback, null, options);
|
||||
|
||||
setTimeout(accept, 50);
|
||||
|
||||
|
|
|
@ -36,7 +36,7 @@ function successCallback(position){
|
|||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
watchID = navigator.geolocation.getCurrentPosition(successCallback, failureCallback, null);
|
||||
watchID = navigator.geolocation.watchPosition(successCallback, failureCallback, null);
|
||||
|
||||
// click deny
|
||||
setTimeout(clickNotificationButton, 50, kDenyButton);
|
||||
|
|
|
@ -0,0 +1,55 @@
|
|||
<!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="/MochiKit/packed.js"></script>
|
||||
<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();
|
||||
|
||||
start_sending_garbage();
|
||||
|
||||
function successCallback(pos){
|
||||
ok(false, "success should have never been called.");
|
||||
stop_sending_garbage();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function errorCallback(err) {
|
||||
ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
|
||||
stop_sending_garbage();
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
|
||||
var options = {
|
||||
maximumAge: 0,
|
||||
timeout: 1000,
|
||||
};
|
||||
|
||||
navigator.geolocation.watchPosition(successCallback,
|
||||
errorCallback,
|
||||
options);
|
||||
|
||||
setTimeout(clickNotificationButton, 10, kAcceptButton);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=482260
|
||||
-->
|
||||
<head>
|
||||
<title>Test for getCurrentPosition </title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<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">
|
||||
|
||||
var completeCount = 100;
|
||||
|
||||
var hasAccepted = false;
|
||||
|
||||
|
||||
function successCallback(position) {
|
||||
check_geolocation(position);
|
||||
}
|
||||
|
||||
function accept() {
|
||||
hasAccepted = true;
|
||||
clickNotificationButton(kAcceptButton);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// one-shot position requests
|
||||
|
||||
var options = {
|
||||
maximumAge: 0,
|
||||
};
|
||||
|
||||
var y = completeCount;
|
||||
for (var x=0; x< y; x++)
|
||||
navigator.geolocation.getCurrentPosition(successCallback, null, options);
|
||||
|
||||
setTimeout(accept, 50);
|
||||
setTimeout(done, 1000);
|
||||
|
||||
function done() {
|
||||
completeCount--;
|
||||
ok(1, "Saw all successCallbacks");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,55 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=482260
|
||||
-->
|
||||
<head>
|
||||
<title>Test for getCurrentPosition </title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<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">
|
||||
|
||||
var completeCount = 1000;
|
||||
|
||||
var hasAccepted = false;
|
||||
|
||||
function successCallback(position) {
|
||||
check_geolocation(position);
|
||||
completeCount--;
|
||||
if (completeCount > 0)
|
||||
navigator.geolocation.getCurrentPosition(successCallback, null, null);
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
function accept() {
|
||||
hasAccepted = true;
|
||||
clickNotificationButton(kAcceptButton);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
var options = {
|
||||
maximumAge: 0,
|
||||
};
|
||||
|
||||
// one-shot position requests
|
||||
navigator.geolocation.getCurrentPosition(successCallback, null, options);
|
||||
|
||||
setTimeout(accept, 50);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=482260
|
||||
-->
|
||||
<head>
|
||||
<title>Test for watchPosition </title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<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">
|
||||
|
||||
var completeCount = 100;
|
||||
|
||||
var hasAccepted = false;
|
||||
|
||||
|
||||
function successCallback(position) {
|
||||
check_geolocation(position);
|
||||
}
|
||||
|
||||
function accept() {
|
||||
hasAccepted = true;
|
||||
clickNotificationButton(kAcceptButton);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// one-shot position requests
|
||||
|
||||
var options = {
|
||||
maximumAge: 0,
|
||||
};
|
||||
|
||||
var y = completeCount;
|
||||
for (var x=0; x< y; x++)
|
||||
navigator.geolocation.watchPosition(successCallback, null, options);
|
||||
|
||||
setTimeout(accept, 50);
|
||||
setTimeout(done, 1000);
|
||||
|
||||
function done() {
|
||||
completeCount--;
|
||||
ok(1, "Saw all successCallbacks");
|
||||
SimpleTest.finish();
|
||||
}
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
|
@ -0,0 +1,62 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<!--
|
||||
https://bugzilla.mozilla.org/show_bug.cgi?id=482260
|
||||
-->
|
||||
<head>
|
||||
<title>Test for watchPosition </title>
|
||||
<script type="text/javascript" src="/MochiKit/packed.js"></script>
|
||||
<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">
|
||||
|
||||
var hasAccepted = false;
|
||||
var watchID = 0;
|
||||
var completeCount = 10;
|
||||
|
||||
var options = {
|
||||
maximumAge: 0,
|
||||
};
|
||||
|
||||
function successCallback(position) {
|
||||
check_geolocation(position);
|
||||
|
||||
navigator.geolocation.clearWatch(watchID);
|
||||
|
||||
completeCount--;
|
||||
|
||||
if (completeCount==0) {
|
||||
ok(1, "all watchPosition successCallbacks called");
|
||||
SimpleTest.finish();
|
||||
} else {
|
||||
watchID = navigator.geolocation.watchPosition(successCallback, null, options);
|
||||
setTimeout(accept, 50);
|
||||
}
|
||||
}
|
||||
|
||||
function accept() {
|
||||
hasAccepted = true;
|
||||
clickNotificationButton(kAcceptButton);
|
||||
}
|
||||
|
||||
SimpleTest.waitForExplicitFinish();
|
||||
|
||||
// one-shot position requests
|
||||
watchID = navigator.geolocation.watchPosition(successCallback, null, options);
|
||||
setTimeout(accept, 50);
|
||||
|
||||
</script>
|
||||
</pre>
|
||||
</body>
|
||||
</html>
|
||||
|
Загрузка…
Ссылка в новой задаче