This page links to a series of test cases for the W3C Geolocation API Specification. It is organised by section, and (more or less) categorizes each test according to which statement in the specification it relates to.
The tests are designed to be run manually, mostly because the specification expects user interaction for allowing the browser to access location information.
User agents must not send location information to Web sites without the express permission of the user. User agents must acquire permission through a user interface, unless they have prearranged trust relationships with users, as described below.
The user interface must include the host component of the document's URI
Those permissions that are acquired through the user interface and that are preserved beyond the current browsing session (i.e. beyond the time when the browsing context [BROWSINGCONTEXT] is navigated to another URL) must be revocable and user agents must respect revoked permissions.
Objects implementing the Navigator interface (e.g. the window.navigator object) must also implement the NavigatorGeolocation interface. An instance of NavigatorGeolocation would be then obtained by using binding-specific casting methods on an instance of Navigator.
The getCurrentPosition() method takes one, two or three arguments ... If successCallback is the null value, then throw a TypeError.
When called, [the getCurrentPosition() method] must immediately return and then asynchronously attempt to obtain the current location of the device.
If the [location] attempt is successful, the successCallback is invoked (i.e. the handleEvent operation is called on the callback object) with a new Position object, reflecting the current location of the device.
If the attempt fails, the errorCallback is invoked with a new PositionError object, reflecting the reason for the failure.
The watchPosition() method takes one, two or three arguments ... If successCallback is the null value, then throw a TypeError.
Test 00058: call watchPosition with no arguments, check that exception is thrown
Test 00015: call watchPosition with null success callback, check that exception is thrown
Test 00017: call watchPosition with null success and error callbacks, check that exception is thrown
Test 00059: call watchPosition() with wrong type for first argument. Exception expected.
Test 00060: call watchPosition() with wrong type for second argument. Exception expected.
Test 00061: call watchPosition() with wrong type for third argument. No exception expected.
When called, [watchPosition] must immediately return a long value that uniquely identifies a watch operation and then asynchronously start the watch operation.
This operation must first attempt to obtain the current location of the device and invoke the appropriate callback.
It then must continue to monitor the position of the device and invoke the appropriate callback every time this position changes.
The watch operation continues until the clearWatch method is called with the corresponding identifier
The successCallback is only invoked when a new position is obtained and this position differs significantly from the previously reported position. The definition of what consitutes a significant difference is left to the implementation.
For both getCurrentPosition and watchPosition, the implementation must never invoke the successCallback without having first obtained permission from the user to share location
If the user grants permission, the appropriate callback must be invoked as described above.
If the user denies permission, the errorCallback (if present) must be invoked with code PERMISSION_DENIED.
The time that is spent obtaining the user permission must not be included in the period covered by the timeout attribute of the PositionOptions parameter. The timeout attribute must only apply to the location acquisition operation.
If the user grants permission, the appropriate callback must be invoked as described above. If the user denies permission, the errorCallback (if present) must be invoked with code PERMISSION_DENIED, irrespective of any other errors encoutered in the above steps.
The clearWatch() method takes one argument. When called, the watch process identified by the watchId argument will be stopped and should not invoke any further callbacks.
In ECMAScript, the enableHighAccuracy, timeout and maximumAge properties are all optional: when creating a PositionOptions object, the developer may specify any of these properties.
The enableHighAccuracy attribute provides a hint that the application would like to receive the best possible results. This may result in slower response times or increased power consumption. The user might also deny this capability, or the device might not be able to provide more accurate results than if the flag wasn't specified.
If the PositionOptions parameter to getCurrentPosition or watchPosition is omitted, the default value used for the enableHighAccuracy attribute is false. The same default value is used in ECMAScript when the enableHighAccuracy property is omitted.
The timeout attribute denotes the maximum length of time (expressed in milliseconds) that is allowed to pass from the call to getCurrentPosition() or watchPosition() until the corresponding successCallback is invoked. If the implementation is unable to successfully acquire a new Position before the given timeout elapses, and no other errors have occurred in this interval, then the corresponding errorCallback must be invoked with a PositionError object whose code attribute is set to TIMEOUT.
If the PositionOptions parameter to getCurrentPosition or watchPosition is omitted, the default value used for the timeout attribute is Infinity.
If a negative value is supplied, the timeout value is considered to be 0.
The same default value is used in ECMAScript when the timeout property is omitted.
In case of a getCurrentPosition() call, the errorCallback would be invoked at most once
In case of a watchPosition(), the errorCallback could be invoked repeatedly: the first timeout is relative to the moment watchPosition() was called or the moment the user's permission was obtained, if that was necessary. Subsequent timeouts are relative to the moment when the implementation determines that the position of the hosting device has changed and a new Position object must be acquired.
The maximumAge attribute indicates that the application is willing to accept a cached position whose age is no greater than the specified time in milliseconds. If maximumAge is set to 0, the implementation must immediately attempt to acquire a new position object. Setting the maximumAge to Infinity will force the implementation to return a cached position regardless of its age. If an implementation does not have a cached position available whose age is no greater than the specified maximumAge, then it must acquire a new position object. In case of a watchPosition(), the maximumAge refers to the first position object returned by the implementation.
If the PositionOptions parameter to getCurrentPosition or watchPosition is omitted, the default value used for the maximumAge attribute is 0. If a negative value is supplied, the maximumAge value is considered to be 0. The same default value is used in ECMAScript when the maximumAge property is omitted.
The timestamp attribute represents the time when the Position object was acquired and is represented as a DOMTimeStamp [DOMTIMESTAMP].
The latitude and longitude attributes are geographic coordinates specified in decimal degrees.
The altitude attribute denotes the height of the position, specified in meters above the [WGS84] ellipsoid. If the implementation cannot provide altitude information, the value of this attribute must be null.
The accuracy attribute denotes the accuracy level of the latitude and longitude coordinates. It is specified in meters and must be supported by all implementations.
The altitudeAccuracy attribute is specified in meters. If the implementation cannot provide altitude information, the value of this attribute must be null.
The heading attribute denotes the direction of travel of the hosting device and is specified in degrees counting clockwise relative to the true north. If the implementation cannot provide heading information, the value of this attribute must be null.
If the hosting device is stationary (i.e. the value of the speed attribute is 0), then the value of the heading attribute must be NaN.
The speed attribute denotes the current ground speed of the hosting device and is specified in meters per second. If the implementation cannot provide speed information, the value of this attribute must be null.
The code attribute must return the appropriate code from the following list: