Bug 824432 - Don't cancel request if it's a watch request. r=jdm
authorKan-Ru Chen (陳侃如) <kanru@kanru.info>
Fri, 28 Dec 2012 14:46:57 +0800
changeset 126255 4aeb2bd7b186e7f54951e1151f657f260d732071
parent 126254 787938d80556e28fe1075f79d79170929ddc39b2
child 126256 06c61e9f344a7c251a6696a1eea6ac5a77b14693
push id2151
push userlsblakk@mozilla.com
push dateTue, 19 Feb 2013 18:06:57 +0000
treeherdermozilla-beta@4952e88741ec [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjdm
bugs824432
milestone20.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 824432 - Don't cancel request if it's a watch request. r=jdm
dom/src/geolocation/nsGeolocation.cpp
dom/tests/mochitest/geolocation/test_timerRestartWatch.html
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -335,25 +335,32 @@ nsGeolocationRequest::NotifyError(int16_
 
   positionError->NotifyCallback(mErrorCallback);
 }
 
 
 NS_IMETHODIMP
 nsGeolocationRequest::Notify(nsITimer* aTimer)
 {
+  if (mCleared) {
+    return NS_OK;
+  }
+
   // If we haven't gotten an answer from the geolocation
-  // provider yet, cancel the request.  Same logic as
-  // ::Cancel, just a different error
+  // 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;
 }
 
 NS_IMETHODIMP
 nsGeolocationRequest::GetPrincipal(nsIPrincipal * *aRequestingPrincipal)
 {
   NS_ENSURE_ARG_POINTER(aRequestingPrincipal);
 
--- a/dom/tests/mochitest/geolocation/test_timerRestartWatch.html
+++ b/dom/tests/mochitest/geolocation/test_timerRestartWatch.html
@@ -21,22 +21,29 @@ https://bugzilla.mozilla.org/show_bug.cg
 
 SimpleTest.waitForExplicitFinish();
 
 // ensure we are using the right testing provider
 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) {
   // Now that we got a success callback, lets try to ensure
   // that we get a timeout error.
   stop_geolocationProvider();
 }