Geolocation - WD-geolocation-API-20081222 support. Bug, 468462, 469091, 469715, 470072. r/sr=jst a=bsmedberg
authorDoug Turner <dougt@meer.net>
Thu, 08 Jan 2009 20:04:10 -0800
changeset 22770 75e2dd630582fdec5391bf89e7845edac9ff1275
parent 22769 f9b1c0dfe5eca52966a036389270cc3155c9b9ad
child 22771 881fdb2a350fc140e48928e63e8b2306de614256
push id397
push userdougt@mozilla.com
push dateFri, 09 Jan 2009 04:04:38 +0000
reviewersbsmedberg
bugs20081222, 468462, 469091, 469715, 470072
milestone1.9.1b3pre
Geolocation - WD-geolocation-API-20081222 support. Bug, 468462, 469091, 469715, 470072. r/sr=jst a=bsmedberg
dom/public/idl/geolocation/Makefile.in
dom/public/idl/geolocation/nsIDOMGeoGeolocation.idl
dom/public/idl/geolocation/nsIDOMGeoPosition.idl
dom/public/idl/geolocation/nsIDOMGeoPositionCoords.idl
dom/public/idl/geolocation/nsIDOMGeoPositionOptions.idl
dom/public/idl/geolocation/nsIGeolocationProvider.idl
dom/src/geolocation/MaemoLocationProvider.cpp
dom/src/geolocation/nsGeolocation.cpp
dom/src/geolocation/nsGeolocation.h
dom/tests/mochitest/geolocation/Makefile.in
dom/tests/mochitest/geolocation/geolocation_common.js
dom/tests/mochitest/geolocation/test_allowCurrent.html
dom/tests/mochitest/geolocation/test_allowWatch.html
dom/tests/mochitest/geolocation/test_cancelCurrent.html
dom/tests/mochitest/geolocation/test_cancelWatch.html
dom/tests/mochitest/geolocation/test_clearWatch.html
dom/tests/mochitest/geolocation/test_timeoutWatch.html
--- a/dom/public/idl/geolocation/Makefile.in
+++ b/dom/public/idl/geolocation/Makefile.in
@@ -44,16 +44,17 @@ include $(DEPTH)/config/autoconf.mk
 
 MODULE         = dom
 XPIDL_MODULE   = dom_geolocation
 GRE_MODULE     = 1
 
 XPIDLSRCS =                                    \
             nsIDOMGeoGeolocation.idl           \
             nsIDOMGeoPosition.idl              \
+            nsIDOMGeoPositionCoords.idl        \
             nsIDOMGeoPositionCallback.idl      \
             nsIDOMGeoPositionError.idl         \
             nsIDOMGeoPositionErrorCallback.idl \
             nsIDOMGeoPositionOptions.idl       \
             nsIDOMNavigatorGeolocation.idl     \
             nsIGeolocationProvider.idl         \
             $(NULL)
 
--- a/dom/public/idl/geolocation/nsIDOMGeoGeolocation.idl
+++ b/dom/public/idl/geolocation/nsIDOMGeoGeolocation.idl
@@ -36,21 +36,19 @@
 
 #include "domstubs.idl"
 
 interface nsIDOMGeoPosition;
 interface nsIDOMGeoPositionOptions;
 interface nsIDOMGeoPositionCallback;
 interface nsIDOMGeoPositionErrorCallback;
 
-[scriptable, function, uuid(0EC70F3F-7E15-45E0-84E9-CDE078CB150A)]
+[scriptable, function, uuid(37687DAF-B85F-4E4D-8881-85A0AD24CF78)]
 interface nsIDOMGeoGeolocation : nsISupports
 {
-  readonly attribute nsIDOMGeoPosition lastPosition;
-
   void getCurrentPosition(in nsIDOMGeoPositionCallback successCallback,
                           [optional] in nsIDOMGeoPositionErrorCallback errorCallback,
                           [optional] in nsIDOMGeoPositionOptions options);
 
   long watchPosition(in nsIDOMGeoPositionCallback successCallback,
                      [optional] in nsIDOMGeoPositionErrorCallback errorCallback,
                      [optional] in nsIDOMGeoPositionOptions options);
 
--- a/dom/public/idl/geolocation/nsIDOMGeoPosition.idl
+++ b/dom/public/idl/geolocation/nsIDOMGeoPosition.idl
@@ -31,21 +31,16 @@
  * and other provisions required by the GPL or the LGPL. If you do not delete
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #include "domstubs.idl"
+#include "nsIDOMGeoPositionCoords.idl"
 
-[scriptable, uuid(B31702D0-6DAC-4FA0-B93B-F043E71C8F9A)]
+[scriptable, uuid(76888EB0-5EAB-4BE6-BFE0-489EC4095358)]
 interface nsIDOMGeoPosition : nsISupports
 {
-  readonly attribute double latitude;
-  readonly attribute double longitude;
-  readonly attribute double altitude;
-  readonly attribute double accuracy;
-  readonly attribute double altitudeAccuracy;
-  readonly attribute double heading;
-  readonly attribute double speed;
+  readonly attribute nsIDOMGeoPositionCoords coords;
   readonly attribute DOMTimeStamp timestamp;
 };
new file mode 100644
--- /dev/null
+++ b/dom/public/idl/geolocation/nsIDOMGeoPositionCoords.idl
@@ -0,0 +1,50 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is Geolocation.
+ *
+ * The Initial Developer of the Original Code is Mozilla Corporation
+ * Portions created by the Initial Developer are Copyright (C) 2008
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *  Doug Turner <dougt@meer.net>  (Original Author)
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+
+#include "domstubs.idl"
+
+[scriptable, uuid(B31702D0-6DAC-4FA0-B93B-F043E71C8F9A)]
+interface nsIDOMGeoPositionCoords : nsISupports
+{
+  readonly attribute double latitude;
+  readonly attribute double longitude;
+  readonly attribute double altitude;
+  readonly attribute double accuracy;
+  readonly attribute double altitudeAccuracy;
+  readonly attribute double heading;
+  readonly attribute double speed;
+};
--- a/dom/public/idl/geolocation/nsIDOMGeoPositionOptions.idl
+++ b/dom/public/idl/geolocation/nsIDOMGeoPositionOptions.idl
@@ -32,14 +32,15 @@
  * the provisions above, a recipient may use your version of this file under
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 #include "domstubs.idl"
 
-[scriptable, uuid(74FA3BE6-4CBF-47C7-9BE1-FB9F17DD0D5D)]
+[scriptable, uuid(453B72DE-EA90-4F09-AE16-C2E7EE0DDDC4)]
 interface nsIDOMGeoPositionOptions : nsISupports
 {
   attribute boolean enableHighAccuracy;
-  attribute unsigned long timeout;
+  attribute long timeout;
+  attribute long maximumAge;
 };
--- a/dom/public/idl/geolocation/nsIGeolocationProvider.idl
+++ b/dom/public/idl/geolocation/nsIGeolocationProvider.idl
@@ -87,17 +87,17 @@ interface nsIGeolocationUpdate : nsISupp
 
 
 /**
  * Interface provides location information to the nsGeolocator
  * via the nsIDOMGeolocationCallback interface.  After
  * startup is called, any geo location change should call
  * callback.onRequest().
  */
-[scriptable, uuid(E319BE2D-B1D1-4CA6-AEF4-66178589B63D)]
+[scriptable, uuid(5C819505-8804-496E-9CB2-53089B3DD4EF)]
 interface nsIGeolocationProvider : nsISupports {
 
   /**
    * Start up the provider.  This is called before any other
    * method.  may be called multiple times.
    */
   void startup();
 
@@ -109,24 +109,18 @@ interface nsIGeolocationProvider : nsISu
 
   /**
    * watch
    * When a location change is observed, notify the callback
    */
   void watch(in nsIGeolocationUpdate callback);
 
   /**
-   * currentLocation return the current location as seen by
-   * the provider.  may be null.
-   */
-  readonly attribute nsIDOMGeoPosition currentPosition;
-  
-  /**
    * shutdown
-   * Shuts down the location devices.
+   * Shuts down the location device.
    */
   void shutdown();
 };
 
 %{C++
 /*  
     This must be implemented by geolocation providers.  It
     must support nsIGeolocationProvider.
--- a/dom/src/geolocation/MaemoLocationProvider.cpp
+++ b/dom/src/geolocation/MaemoLocationProvider.cpp
@@ -33,16 +33,18 @@
  * the terms of any one of the MPL, the GPL or the LGPL.
  *
  * ***** END LICENSE BLOCK ***** */
 
 
 
 #include "MaemoLocationProvider.h"
 #include "nsGeolocation.h"
+#include "nsIClassInfo.h"
+#include "nsDOMClassInfoID.h"
 
 
 ////////////////////////////////////////////////////
 // nsGeoPosition
 ////////////////////////////////////////////////////
 
 /**
  * Simple object that holds a single point in space.
--- a/dom/src/geolocation/nsGeolocation.cpp
+++ b/dom/src/geolocation/nsGeolocation.cpp
@@ -231,30 +231,68 @@ nsGeolocationRequest::Cancel()
   // remove ourselves from the locators callback lists.
   mLocator->RemoveRequest(this);
   return NS_OK;
 }
 
 NS_IMETHODIMP
 nsGeolocationRequest::Allow()
 {
+  nsRefPtr<nsGeolocationService> geoService = nsGeolocationService::GetInstance();
+
   // Kick off the geo device, if it isn't already running
-  nsRefPtr<nsGeolocationService> geoService = nsGeolocationService::GetInstance();
   nsresult rv = geoService->StartDevice();
   
   if (NS_FAILED(rv)) {
     // Location provider error
     NotifyError(nsIDOMGeoPositionError::POSITION_UNAVAILABLE);
     return NS_OK;
   }
+  
+  nsCOMPtr<nsIDOMGeoPosition> lastPosition = geoService->GetCachedPosition();
+  DOMTimeStamp cachedPositionTime;
+  if (lastPosition)
+    lastPosition->GetTimestamp(&cachedPositionTime);
 
-  PRUint32 timeout;
+  // check to see if we can use a cached value
+  //
+  // either:
+  // a) the user has specified a maximumAge which allows us to return a cached value,
+  // -or-
+  // b) the cached position time is some reasonable value to return to the user (<30s)
+  
+  PRUint32 maximumAge = 30 * PR_MSEC_PER_SEC;
+  if (mOptions) {
+    PRInt32 tempAge;
+    nsresult rv = mOptions->GetMaximumAge(&tempAge);
+    if (NS_SUCCEEDED(rv)) {
+      if (tempAge > 0)
+        maximumAge = tempAge;
+    }
+  }
+
+  if (lastPosition && maximumAge > 0 && ( (PR_Now() / PR_USEC_PER_MSEC ) - maximumAge <= cachedPositionTime) ) {
+    // okay, we can return a cached position
+    mAllowed = PR_TRUE;
+    
+    // send the cached location
+    SendLocation(lastPosition);
+    
+    // remove ourselves from the locators callback lists.
+    mLocator->RemoveRequest(this);
+  }
+
+  PRInt32 timeout;
   if (mOptions && NS_SUCCEEDED(mOptions->GetTimeout(&timeout)) && timeout > 0) {
-      mTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
-      mTimeoutTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT);
+    
+    if (timeout < 10)
+      timeout = 10;
+
+    mTimeoutTimer = do_CreateInstance("@mozilla.org/timer;1");
+    mTimeoutTimer->InitWithCallback(this, timeout, nsITimer::TYPE_ONE_SHOT);
   }
 
   mAllowed = PR_TRUE;
   return NS_OK;
 }
 
 void
 nsGeolocationRequest::MarkCleared()
@@ -374,16 +412,29 @@ nsGeolocationService::Observe(nsISupport
 NS_IMETHODIMP
 nsGeolocationService::Update(nsIDOMGeoPosition *aSomewhere)
 {
   for (PRUint32 i = 0; i< mGeolocators.Length(); i++)
     mGeolocators[i]->Update(aSomewhere);
   return NS_OK;
 }
 
+
+void
+nsGeolocationService::SetCachedPosition(nsIDOMGeoPosition* aPosition)
+{
+  mLastPosition = aPosition;
+}
+
+nsIDOMGeoPosition*
+nsGeolocationService::GetCachedPosition()
+{
+  return mLastPosition;
+}
+
 PRBool
 nsGeolocationService::HasGeolocationProvider()
 {
   return (mProvider != nsnull);
 }
 
 nsresult
 nsGeolocationService::StartDevice()
@@ -558,16 +609,24 @@ nsGeolocation::Update(nsIDOMGeoPosition 
   // mPendingCallbacks, and mWatchingCallbacks.  Since this
   // function can only be called on the primary thread, we
   // can lock this method with a member var.
 
   if (mUpdateInProgress)
     return;
 
   mUpdateInProgress = PR_TRUE;
+
+  if (aSomewhere)
+  {
+    nsRefPtr<nsGeolocationService> geoService = nsGeolocationService::GetInstance();
+    geoService->SetCachedPosition(aSomewhere);
+  }
+
+
   if (!OwnerStillExists())
   {
     Shutdown();
     return;
   }
 
   // notify anyone that has been waiting
   for (PRUint32 i = 0; i< mPendingCallbacks.Length(); i++)
@@ -577,25 +636,16 @@ nsGeolocation::Update(nsIDOMGeoPosition 
   // notify everyone that is watching
   for (PRUint32 i = 0; i< mWatchingCallbacks.Length(); i++)
     mWatchingCallbacks[i]->SendLocation(aSomewhere);
 
   mUpdateInProgress = PR_FALSE;
 }
 
 NS_IMETHODIMP
-nsGeolocation::GetLastPosition(nsIDOMGeoPosition * *aLastPosition)
-{
-  // we are advocating that this method be removed.
-  NS_ENSURE_ARG_POINTER(aLastPosition);
-  *aLastPosition = nsnull;
-  return NS_OK;
-}
-
-NS_IMETHODIMP
 nsGeolocation::GetCurrentPosition(nsIDOMGeoPositionCallback *callback,
                                   nsIDOMGeoPositionErrorCallback *errorCallback,
                                   nsIDOMGeoPositionOptions *options)
 {
   nsCOMPtr<nsIGeolocationPrompt> prompt = do_GetService(NS_GEOLOCATION_PROMPT_CONTRACTID);
   if (prompt == nsnull)
     return NS_ERROR_NOT_AVAILABLE;
 
--- a/dom/src/geolocation/nsGeolocation.h
+++ b/dom/src/geolocation/nsGeolocation.h
@@ -109,16 +109,19 @@ public:
   NS_DECL_NSIOBSERVER
 
   nsGeolocationService();
 
   // Management of the nsGeolocation objects
   void AddLocator(nsGeolocation* locator);
   void RemoveLocator(nsGeolocation* locator);
 
+  void SetCachedPosition(nsIDOMGeoPosition* aPosition);
+  nsIDOMGeoPosition* GetCachedPosition();
+
   // Returns true if there is a geolocation provider registered.
   PRBool   HasGeolocationProvider();
 
   // Find and startup a geolocation device (gps, nmea, etc.)
   nsresult StartDevice();
 
   // Stop the started geolocation device (gps, nmea, etc.)
   void     StopDevice();
@@ -143,16 +146,19 @@ private:
 
   // A flag that lets us know if the mProvider has been started up.
   PRBool mProviderStarted;
 
   // mGeolocators are not owned here.  Their constructor
   // addes them to this list, and their destructor removes
   // them from this list.
   nsTArray<nsGeolocation*> mGeolocators;
+
+  // This is the last geo position that we have seen.
+  nsCOMPtr<nsIDOMGeoPosition> mLastPosition;
 };
 
 
 /**
  * Can return a geolocation info
  */ 
 class nsGeolocation : public nsIDOMGeoGeolocation
 {
--- a/dom/tests/mochitest/geolocation/Makefile.in
+++ b/dom/tests/mochitest/geolocation/Makefile.in
@@ -40,17 +40,16 @@ srcdir		= @srcdir@
 VPATH		= @srcdir@
 relativesrcdir	= dom/tests/mochitest/geolocation
 
 include $(DEPTH)/config/autoconf.mk
 
 include $(topsrcdir)/config/rules.mk
 
 _TEST_FILES	= \
-		test_lastPosition.html \
 		test_manyWindows.html \
 		test_allowCurrent.html \
 		test_allowWatch.html \
 		test_cancelCurrent.html \
 		test_cancelWatch.html \
 		test_clearWatch.html \
 		test_clearWatch_invalid.html \
 		test_geoPrompt.html \
--- a/dom/tests/mochitest/geolocation/geolocation_common.js
+++ b/dom/tests/mochitest/geolocation/geolocation_common.js
@@ -1,19 +1,13 @@
 // defines for prompt - button position
 const ACCEPT = 0;
 const ACCEPT_FUZZ = 1;
 const DECLINE = 2;
 
-/* Set if testLocationProvider is registered as geolocation provider.
- * To register, copy testLocationProvider.js to components directory 
- * and remove from directory when done. 
- */
-var TEST_PROVIDER = 0; 
-
 // set if there should be a delay before prompt is accepted
 var DELAYED_PROMPT = 0;
 
 var prompt_delay = timeout * 2;
 
 // the prompt that was registered at runtime
 var old_prompt;
 
@@ -32,41 +26,41 @@ var slack = 500;
 
 // time needed for provider to make position changes
 var timeout = num_pos_changes * timer_interval + slack;
 
 function check_geolocation(location) {
 
   ok(location, "Check to see if this location is non-null");
 
-  ok("latitude" in location, "Check to see if there is a latitude");
-  ok("longitude" in location, "Check to see if there is a longitude");
-  ok("altitude" in location, "Check to see if there is a altitude");
-  ok("accuracy" in location, "Check to see if there is a accuracy");
-  ok("altitudeAccuracy" in location, "Check to see if there is a alt accuracy");
-  ok("heading" in location, "Check to see if there is a heading");
-  ok("speed" in location, "Check to see if there is a speed");
   ok("timestamp" in location, "Check to see if there is a timestamp");
 
+  // 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");
+  ok("heading" in coords, "Check to see if there is a heading");
+  ok("speed" in coords, "Check to see if there is a speed");
 }
 
 //TODO: test for fuzzed location when this is implemented
 function check_fuzzed_geolocation(location) {
   check_geolocation(location);
 }
 
 function check_no_geolocation(location) {
    ok(!location, "Check to see if this location is null");
 }
 
-function checkFlags(flags, value, isExact) {
-  for(var i = 0; i < flags.length; i++)
-    ok(isExact ? flags[i] == value : flags[i] >= value, "ensure callbacks called " + value + " times");
-}
-
 function success_callback(position) {
   if(prompted == 0)
     ok(0, "Should not call success callback before prompt accepted");
   if(position == null)
     ok(1, "No geolocation available");
   else {
     switch(promptOption) {
       case ACCEPT:
--- a/dom/tests/mochitest/geolocation/test_allowCurrent.html
+++ b/dom/tests/mochitest/geolocation/test_allowCurrent.html
@@ -29,18 +29,16 @@ for(var i = 0; i < numCallbacks; i++) {
   eval("function successCallback" + i + "(position) {" +
           "callbackCounter[" + i + "]++;" +
           "success_callback(position);" +
        "}"
   );
 }
 
 function testAccepted() {
-  if(TEST_PROVIDER)
-    checkFlags(callbackCounter, 1, true);
   removePrompt();
   SimpleTest.finish();
 }
 
 /** Test for Bug  **/
 
 SimpleTest.waitForExplicitFinish();
 
--- a/dom/tests/mochitest/geolocation/test_allowWatch.html
+++ b/dom/tests/mochitest/geolocation/test_allowWatch.html
@@ -22,17 +22,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script class="testbody" type="text/javascript">
 
 var numCallbacks = 5;
 var callbackCounter = new Array(numCallbacks);
 var watchID = new Array(numCallbacks);
 
 function failureCallback(error)
 {
-  ok(error.code == 2, "Failure was something other than position unavailable");
+  ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
   removePrompt();
   SimpleTest.finish();
 }
 
 
 // define success callbacks
 for(var i = 0; i < numCallbacks; i++) {
   eval("function successCallback" + i + "(position) {" +
@@ -51,18 +51,16 @@ function registerWatches() {
 }
 
 function clearWatches() {
   for(var i = 0; i < numCallbacks; i++)
     navigator.geolocation.clearWatch(watchID[i]);
 }
 
 function testAccepted() {
-  if(TEST_PROVIDER)
-    checkFlags(callbackCounter, num_pos_changes, false);
   clearWatches();
   removePrompt();
   SimpleTest.finish();
 }
 
 /** Test for Bug  **/
 
 SimpleTest.waitForExplicitFinish();
--- a/dom/tests/mochitest/geolocation/test_cancelCurrent.html
+++ b/dom/tests/mochitest/geolocation/test_cancelCurrent.html
@@ -21,17 +21,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 var numCallbacks = 5;
 var callbackCounter = new Array(numCallbacks);
 
 function failureCallback(error)
 {
-  ok(error.code == 2, "Failure was something other than position unavailable");
+  ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
   removePrompt();
   SimpleTest.finish();
 }
 
 // define success callbacks
 for(var i = 0; i < numCallbacks; i++) {
   eval("function successCallback" + i + "(position) {" +
           "callbackCounter[" + i + "]++;" +
--- a/dom/tests/mochitest/geolocation/test_cancelWatch.html
+++ b/dom/tests/mochitest/geolocation/test_cancelWatch.html
@@ -22,17 +22,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script class="testbody" type="text/javascript">
 
 var numCallbacks = 5;
 var callbackCounter = new Array(numCallbacks);
 var watchID = new Array(numCallbacks);
 
 function failureCallback(error)
 {
-  ok(error.code == 2, "Failure was something other than position unavailable");
+  ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
   removePrompt();
   SimpleTest.finish();
 }
 
 // define success callbacks
 for(var i = 0; i < numCallbacks; i++) {
   eval("function successCallback" + i + "(position) {" +
           "callbackCounter[" + i + "]++;" +
--- a/dom/tests/mochitest/geolocation/test_clearWatch.html
+++ b/dom/tests/mochitest/geolocation/test_clearWatch.html
@@ -22,17 +22,17 @@ https://bugzilla.mozilla.org/show_bug.cg
 <script class="testbody" type="text/javascript">
 
 var numCallbacks = 5;
 var callbackCounter = new Array(numCallbacks);
 var watchID = new Array(numCallbacks);
 
 function failureCallback(error)
 {
-  ok(error.code == 2, "Failure was something other than position unavailable");
+  ok(error.code == error.POSITION_UNAVAILABLE, "Failure was something other than position unavailable");
   removePrompt();
   SimpleTest.finish();
 }
 
 // define success callbacks
 for(var i = 0; i < numCallbacks; i++) {
   eval("function successCallback" + i + "(position) {" +
           "callbackCounter[" + i + "]++;" +
@@ -50,18 +50,16 @@ function registerWatches() {
 }
 
 function clearWatches() {
   for(var i = 0; i < numCallbacks; i++)
     navigator.geolocation.clearWatch(watchID[i]);
 }
 
 function testAccepted() {
-  if(TEST_PROVIDER)
-    checkFlags(callbackCounter, num_pos_changes, false);
   clearWatches();
   setTimeout(clearAll, timeout); // now clear flags
 }
 
 function clearAll() {
   for(var i = 0; i < numCallbacks; i++)
     callbackCounter[i] = 0;
   setTimeout(testCleared, timeout); // check to see if watches were cleared
--- a/dom/tests/mochitest/geolocation/test_timeoutWatch.html
+++ b/dom/tests/mochitest/geolocation/test_timeoutWatch.html
@@ -33,23 +33,23 @@ function successCallback(pos){
   ok(0, "success should have never been called.");
   removePrompt();
   SimpleTest.finish();
 }
 
 function errorCallback(err) {
     removePrompt();
 
-    if (err.code == 2) {
+    if (err.code == err.POSITION_UNAVAILABLE) {
         // nothing is hooked up to test against.
         SimpleTest.finish();
         return;
     }
 
-  ok(err.code == 4, "ensure error is a timeout.");
+  ok(err.code == err.TIMEOUT, "ensure error is a timeout.");
   removePrompt();
   SimpleTest.finish();
 }
 
 
 var options = {
     enableHighAccuracy: true,
     timeout: 100