2008-09-04 16:31:09 -07:00
|
|
|
|
2009-08-14 16:12:09 -07: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-12 13:53:36 -08:00
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=respond-garbage");
|
2009-08-14 16:12:09 -07: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-12 13:53:36 -08:00
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
|
2009-08-14 16:12:09 -07:00
|
|
|
}
|
|
|
|
|
2009-03-14 21:03:21 -07:00
|
|
|
function stop_geolocationProvider()
|
|
|
|
{
|
2009-08-14 16:12:09 -07:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2010-03-12 13:53:36 -08:00
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs?action=stop-responding");
|
2009-03-14 21:03:21 -07:00
|
|
|
}
|
2008-09-04 16:31:09 -07:00
|
|
|
|
2009-03-14 21:03:21 -07:00
|
|
|
function resume_geolocationProvider()
|
|
|
|
{
|
2009-08-14 16:12:09 -07:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
|
|
|
|
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
|
2010-03-12 13:53:36 -08:00
|
|
|
prefs.setCharPref("geo.wifi.uri", "http://mochi.test:8888/tests/dom/tests/mochitest/geolocation/network_geolocation.sjs");
|
2009-03-14 21:03:21 -07:00
|
|
|
}
|
2008-09-04 16:31:09 -07:00
|
|
|
|
2008-07-15 16:37:48 -07:00
|
|
|
function check_geolocation(location) {
|
|
|
|
|
|
|
|
ok(location, "Check to see if this location is non-null");
|
|
|
|
|
2008-09-04 16:31:09 -07:00
|
|
|
ok("timestamp" in location, "Check to see if there is a timestamp");
|
2008-08-14 09:35:49 -07:00
|
|
|
|
2009-01-07 09:44:44 -08: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("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");
|
2009-08-14 16:12:09 -07: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");
|
|
|
|
ok(location.coords.altitude == 42, "alt matches known value");
|
|
|
|
ok(location.coords.altitudeAccuracy == 42, "alt acc matches known value");
|
|
|
|
|
2008-09-04 16:31:09 -07:00
|
|
|
}
|
|
|
|
|
2008-08-14 09:35:49 -07:00
|
|
|
|
2010-04-09 10:45:25 -07:00
|
|
|
function getChromeWindow()
|
2009-03-14 21:03:21 -07:00
|
|
|
{
|
|
|
|
const Ci = Components.interfaces;
|
2010-04-09 10:45:25 -07:00
|
|
|
var chromeWin = window.top
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIWebNavigation)
|
|
|
|
.QueryInterface(Ci.nsIDocShellTreeItem)
|
|
|
|
.rootTreeItem
|
|
|
|
.QueryInterface(Ci.nsIInterfaceRequestor)
|
|
|
|
.getInterface(Ci.nsIDOMWindow)
|
|
|
|
.QueryInterface(Ci.nsIDOMChromeWindow);
|
|
|
|
return chromeWin;
|
|
|
|
}
|
2009-03-14 21:03:21 -07:00
|
|
|
|
2010-04-09 10:45:25 -07:00
|
|
|
function getNotificationBox()
|
|
|
|
{
|
|
|
|
var chromeWin = getChromeWindow();
|
2010-06-23 01:07:48 -07:00
|
|
|
var notifyBox = chromeWin.getNotificationBox(window.top);
|
2009-03-14 21:03:21 -07:00
|
|
|
|
|
|
|
return notifyBox;
|
2008-09-04 16:31:09 -07:00
|
|
|
}
|
|
|
|
|
2009-03-31 09:35:55 -07:00
|
|
|
function clickNotificationButton(aButtonIndex) {
|
2008-09-04 16:31:09 -07:00
|
|
|
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
|
2009-03-14 21:03:21 -07:00
|
|
|
|
2010-04-09 10:45:25 -07:00
|
|
|
// First, check for new-style Firefox notifications
|
|
|
|
var chromeWin = getChromeWindow();
|
|
|
|
if (chromeWin.PopupNotifications) {
|
|
|
|
var panel = chromeWin.PopupNotifications.panel;
|
2010-08-27 20:02:18 -07:00
|
|
|
var notificationEl = panel.getElementsByAttribute("id", "geolocation-notification")[0];
|
2010-04-09 10:45:25 -07:00
|
|
|
if (aButtonIndex == kAcceptButton)
|
|
|
|
notificationEl.button.doCommand();
|
|
|
|
else if (aButtonIndex == kDenyButton)
|
|
|
|
throw "clickNotificationButton(kDenyButton) isn't supported in Firefox";
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Otherwise, fall back to looking for a notificationbox
|
2009-03-14 21:03:21 -07:00
|
|
|
// This is a bit of a hack. The notification doesn't have an API to
|
|
|
|
// trigger buttons, so we dive down into the implementation and twiddle
|
|
|
|
// the buttons directly.
|
2009-03-31 09:35:55 -07:00
|
|
|
var box = getNotificationBox();
|
|
|
|
ok(box, "Got notification box");
|
|
|
|
var bar = box.getNotificationWithValue("geolocation");
|
|
|
|
ok(bar, "Got geolocation notification");
|
|
|
|
var button = bar.getElementsByTagName("button").item(aButtonIndex);
|
|
|
|
ok(button, "Got button");
|
|
|
|
button.doCommand();
|
2008-09-04 16:31:09 -07:00
|
|
|
}
|
2008-07-15 16:37:48 -07:00
|
|
|
|
2009-03-31 09:35:55 -07:00
|
|
|
const kAcceptButton = 0;
|
|
|
|
const kDenyButton = 1;
|