diff --git a/dom/src/geolocation/nsGeolocation.cpp b/dom/src/geolocation/nsGeolocation.cpp index 32551f516ae5..de72031d07d6 100644 --- a/dom/src/geolocation/nsGeolocation.cpp +++ b/dom/src/geolocation/nsGeolocation.cpp @@ -340,15 +340,22 @@ nsGeolocationRequest::NotifyError(int16_t errorCode) NS_IMETHODIMP nsGeolocationRequest::Notify(nsITimer* aTimer) { - // If we haven't gotten an answer from the geolocation - // provider yet, cancel the request. Same logic as - // ::Cancel, just a different error + if (mCleared) { + return NS_OK; + } + + // If we haven't gotten an answer from the geolocation + // provider yet, fire a TIMEOUT error and reset the timer. + if (!mIsWatchPositionRequest) { + mLocator->RemoveRequest(this); + } - // remove ourselves from the locator's callback lists. - mLocator->RemoveRequest(this); NotifyError(nsIDOMGeoPositionError::TIMEOUT); - mTimeoutTimer = nullptr; + if (mIsWatchPositionRequest) { + SetTimeoutTimer(); + } + return NS_OK; } diff --git a/dom/tests/mochitest/geolocation/test_timerRestartWatch.html b/dom/tests/mochitest/geolocation/test_timerRestartWatch.html index 3c595ac100d0..21d0cb3ee30f 100644 --- a/dom/tests/mochitest/geolocation/test_timerRestartWatch.html +++ b/dom/tests/mochitest/geolocation/test_timerRestartWatch.html @@ -26,12 +26,19 @@ resume_geolocationProvider(); force_prompt(true); var watchID; +var times = 0; function errorCallback(err) { ok(err.code == err.TIMEOUT, "ensure error is a timeout."); - resume_geolocationProvider(); - reset_prompt(); - SimpleTest.finish(); + times++; + + // make sure we got at least 3 times errorCallback + if (times >= 3) { + navigator.geolocation.clearWatch(watchID); + resume_geolocationProvider(); + reset_prompt(); + SimpleTest.finish(); + } } function successCallback(position) {