This commit is contained in:
Doug Turner 2010-02-23 23:11:34 -08:00
commit 6dbfd82c90
6 changed files with 32 additions and 117 deletions

View File

@ -276,7 +276,6 @@ 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("geo.ignore.location_filter", true);
user_pref("camino.warn_when_closing", false); // Camino-only, harmless to others

View File

@ -237,15 +237,24 @@ WifiGeoPositionProvider.prototype = {
prefService: null,
provider_url: null,
wifi_service: null,
timer: null,
protocol: null,
hasSeenWiFi: false,
startup: function() {
LOG("startup called");
LOG("startup called. testing mode is" + gTestingEnabled);
this.provider_url = this.prefService.getCharPref("geo.wifi.uri");
LOG("provider url = " + this.provider_url);
try {
this.protocol = this.prefService.getIntPref("geo.wifi.protocol");
LOG("protocol = " + this.protocol);
} catch (e) {
this.protocol = 0;
}
// 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.
@ -254,7 +263,7 @@ WifiGeoPositionProvider.prototype = {
if (gTestingEnabled == false)
this.timer.initWithCallback(this, 5000, this.timer.TYPE_ONE_SHOT);
else
this.timer.initWithCallback(this, 750, this.timer.TYPE_REPEATING_SLACK);
this.timer.initWithCallback(this, 200, this.timer.TYPE_REPEATING_SLACK);
},
watch: function(c) {
@ -318,22 +327,16 @@ WifiGeoPositionProvider.prototype = {
LOG("onChange called");
this.hasSeenWiFi = true;
// Cache the preferred protocol for use inside the XHR callback
var protocol = this.protocol;
// send our request to a wifi geolocation network provider:
var xhr = Components.classes["@mozilla.org/xmlextras/xmlhttprequest;1"].createInstance(Ci.nsIXMLHttpRequest);
// This is a background load
xhr.mozBackgroundRequest = true;
var provider_url = this.prefService.getCharPref("geo.wifi.uri");
LOG("provider url = " + provider_url);
var protocol = 0;
try {
protocol = this.prefService.getIntPref("geo.wifi.protocol");
} catch (e) {}
LOG("protocol = " + protocol);
xhr.open("POST", provider_url, false);
xhr.open("POST", this.provider_url, false);
// set something so that we can strip cookies
xhr.channel.loadFlags = Ci.nsIChannel.LOAD_ANONYMOUS;
@ -348,7 +351,7 @@ WifiGeoPositionProvider.prototype = {
// if we get a bad response, we will throw and never report a location
var response;
switch (protocol) {
switch (this.protocol) {
case 1:
LOG("service returned: " + req.target.responseXML);
response = HELD.decode(req.target.responseXML);
@ -395,7 +398,7 @@ WifiGeoPositionProvider.prototype = {
update.update(newLocation);
};
var accessToken = this.getAccessTokenForURL(provider_url);
var accessToken = this.getAccessTokenForURL(this.provider_url);
var request = {
version: "1.1.0",
@ -436,14 +439,9 @@ WifiGeoPositionProvider.prototype = {
},
notify: function (timer) {
if (!gTestingEnabled) {
if (this.hasSeenWiFi == false)
this.onChange(null);
this.timer = null;
return;
}
// if we are testing, we need to hammer this.
this.onChange(null);
if (this.hasSeenWiFi == false)
this.onChange(null);
this.timer = null;
},
};

View File

@ -134,6 +134,7 @@ nsGeolocationRequest::nsGeolocationRequest(nsGeolocation* aLocator,
nsIDOMGeoPositionOptions* aOptions)
: mAllowed(PR_FALSE),
mCleared(PR_FALSE),
mHasSentData(PR_FALSE),
mCallback(aCallback),
mErrorCallback(aErrorCallback),
mOptions(aOptions),
@ -190,9 +191,11 @@ nsGeolocationRequest::Notify(nsITimer* aTimer)
// provider yet, cancel the request. Same logic as
// ::Cancel, just a different error
NotifyError(nsIDOMGeoPositionError::TIMEOUT);
// remove ourselves from the locator's callback lists.
mLocator->RemoveRequest(this);
if (!mHasSentData) {
NotifyError(nsIDOMGeoPositionError::TIMEOUT);
// remove ourselves from the locator's callback lists.
mLocator->RemoveRequest(this);
}
mTimeoutTimer = nsnull;
return NS_OK;
@ -274,19 +277,6 @@ nsGeolocationRequest::Allow()
SendLocation(lastPosition);
}
SetTimeoutTimer();
mAllowed = PR_TRUE;
return NS_OK;
}
void
nsGeolocationRequest::SetTimeoutTimer()
{
if (mTimeoutTimer) {
mTimeoutTimer->Cancel();
mTimeoutTimer = nsnull;
}
PRInt32 timeout;
if (mOptions && NS_SUCCEEDED(mOptions->GetTimeout(&timeout)) && timeout > 0) {
@ -296,6 +286,9 @@ nsGeolocationRequest::SetTimeoutTimer()
mTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
mTimeoutTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT);
}
mAllowed = PR_TRUE;
return NS_OK;
}
void
@ -310,11 +303,6 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition)
if (mCleared || !mAllowed)
return;
if (mTimeoutTimer) {
mTimeoutTimer->Cancel();
mTimeoutTimer = nsnull;
}
// we should not pass null back to the DOM.
if (!aPosition) {
NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE);
@ -332,7 +320,7 @@ nsGeolocationRequest::SendLocation(nsIDOMGeoPosition* aPosition)
JSContext* cx;
stack->Pop(&cx);
SetTimeoutTimer();
mHasSentData = PR_TRUE;
}
void
@ -357,8 +345,6 @@ NS_IMPL_THREADSAFE_RELEASE(nsGeolocationService)
static PRBool sGeoEnabled = PR_TRUE;
static PRBool sGeoIgnoreLocationFilter = PR_FALSE;
static int
GeoEnabledChangedCallback(const char *aPrefName, void *aClosure)
{
@ -490,7 +476,7 @@ nsGeolocationService::Update(nsIDOMGeoPosition *aSomewhere)
PRBool
nsGeolocationService::IsBetterPosition(nsIDOMGeoPosition *aSomewhere)
{
{
if (!aSomewhere)
return PR_FALSE;
@ -498,9 +484,6 @@ nsGeolocationService::IsBetterPosition(nsIDOMGeoPosition *aSomewhere)
if (!geoService)
return PR_FALSE;
if (sGeoIgnoreLocationFilter)
return PR_TRUE;
nsCOMPtr<nsIDOMGeoPosition> lastPosition = geoService->GetCachedPosition();
if (!lastPosition)
return PR_TRUE;

View File

@ -80,7 +80,6 @@ class nsGeolocationRequest : public nsIGeolocationRequest, public nsITimerCallba
void SendLocation(nsIDOMGeoPosition* location);
void MarkCleared();
PRBool Allowed() {return mAllowed;}
void SetTimeoutTimer();
~nsGeolocationRequest();
@ -89,6 +88,7 @@ class nsGeolocationRequest : public nsIGeolocationRequest, public nsITimerCallba
void NotifyError(PRInt16 errorCode);
PRPackedBool mAllowed;
PRPackedBool mCleared;
PRPackedBool mHasSentData;
nsCOMPtr<nsITimer> mTimeoutTimer;
nsCOMPtr<nsIDOMGeoPositionCallback> mCallback;

View File

@ -45,7 +45,6 @@ include $(DEPTH)/config/autoconf.mk
include $(topsrcdir)/config/rules.mk
_TEST_FILES = \
test_timerRestartWatch.html \
test_manyCurrentSerial.html \
test_manyCurrentConcurrent.html \
test_garbageWatch.html \

View File

@ -1,64 +0,0 @@
<!DOCTYPE HTML>
<html>
<!--
https://bugzilla.mozilla.org/show_bug.cgi?id=526326
-->
<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=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">
var watchID;
var hasAccepted = false;
function errorCallback(err) {
ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
resume_geolocationProvider();
SimpleTest.finish();
}
function successCallback(position) {
ok(hasAccepted, "Ensure that accept was pressed");
// Now that we got a success callback, lets try to ensure
// that we get a timeout error.
stop_geolocationProvider();
}
function accept() {
hasAccepted = true;
clickNotificationButton(kAcceptButton);
}
/** Test for Bug **/
SimpleTest.waitForExplicitFinish();
var options = {
maximumAge: 0,
timeout: 1000
};
watchID = navigator.geolocation.watchPosition(successCallback, errorCallback, options);
setTimeout(accept, 50);
</script>
</pre>
</body>
</html>