2008-09-05 03:31:09 +04:00
|
|
|
|
2010-08-31 20:15:52 +04:00
|
|
|
function sleep(delay)
|
|
|
|
{
|
|
|
|
var start = Date.now();
|
|
|
|
while (Date.now() < start + delay);
|
|
|
|
}
|
|
|
|
|
|
|
|
function force_prompt(allow) {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
prefs.setBoolPref("geo.prompt.testing", true);
|
|
|
|
prefs.setBoolPref("geo.prompt.testing.allow", allow);
|
|
|
|
}
|
|
|
|
|
|
|
|
function reset_prompt() {
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
prefs.setBoolPref("geo.prompt.testing", false);
|
|
|
|
prefs.setBoolPref("geo.prompt.testing.allow", false);
|
|
|
|
}
|
|
|
|
|
2009-08-15 03:12:09 +04:00
|
|
|
|
|
|
|
function start_sending_garbage()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2010-03-13 00:53:36 +03:00
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=respond-garbage");
|
2010-08-31 20:15:52 +04:00
|
|
|
|
|
|
|
// we need to be sure that all location data has been purged/set.
|
|
|
|
sleep(1000);
|
2009-08-15 03:12:09 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function stop_sending_garbage()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2010-03-13 00:53:36 +03:00
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
|
2010-08-31 20:15:52 +04:00
|
|
|
|
|
|
|
// we need to be sure that all location data has been purged/set.
|
|
|
|
sleep(1000);
|
2009-08-15 03:12:09 +04:00
|
|
|
}
|
|
|
|
|
2009-03-15 07:03:21 +03:00
|
|
|
function stop_geolocationProvider()
|
|
|
|
{
|
2009-08-15 03:12:09 +04:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2010-03-13 00:53:36 +03:00
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=stop-responding");
|
2010-08-31 20:15:52 +04:00
|
|
|
|
|
|
|
// we need to be sure that all location data has been purged/set.
|
|
|
|
sleep(1000);
|
2009-03-15 07:03:21 +03:00
|
|
|
}
|
2008-09-05 03:31:09 +04:00
|
|
|
|
2011-01-05 00:25:04 +03:00
|
|
|
function worse_geolocationProvider()
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=worse-accuracy");
|
|
|
|
}
|
|
|
|
|
2009-03-15 07:03:21 +03:00
|
|
|
function resume_geolocationProvider()
|
|
|
|
{
|
2009-08-15 03:12:09 +04:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2010-03-13 00:53:36 +03:00
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
|
2009-03-15 07:03:21 +03:00
|
|
|
}
|
2008-09-05 03:31:09 +04:00
|
|
|
|
2012-01-10 00:27:43 +04:00
|
|
|
function delay_geolocationProvider(delay)
|
|
|
|
{
|
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?delay=" + delay);
|
|
|
|
}
|
|
|
|
|
2008-07-16 03:37:48 +04:00
|
|
|
function check_geolocation(location) {
|
|
|
|
|
|
|
|
ok(location, "Check to see if this location is non-null");
|
|
|
|
|
2008-09-05 03:31:09 +04:00
|
|
|
ok("timestamp" in location, "Check to see if there is a timestamp");
|
2008-08-14 20:35:49 +04:00
|
|
|
|
2009-01-07 20:44:44 +03:00
|
|
|
// 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");
|
2011-08-10 00:02:39 +04:00
|
|
|
|
|
|
|
// 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");
|
2009-08-15 03:12:09 +04:00
|
|
|
// 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");
|
2011-08-10 00:02:39 +04:00
|
|
|
// optional ok(location.coords.altitude == 42, "alt matches known value");
|
|
|
|
// optional ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value");
|
2008-09-05 03:31:09 +04:00
|
|
|
}
|