1 description("Tests that the PositionOptions.maximumAge parameter is correctly applied.");
3 var mockLatitude
= 51.478;
4 var mockLongitude
= -0.166;
5 var mockAccuracy
= 100.0;
7 var mockMessage
= 'test';
12 function checkPosition(p
) {
15 shouldBe('position.coords.latitude', 'mockLatitude');
16 shouldBe('position.coords.longitude', 'mockLongitude');
17 shouldBe('position.coords.accuracy', 'mockAccuracy');
20 function checkError(e
) {
23 shouldBe('error.code', 'error.POSITION_UNAVAILABLE');
24 shouldBe('error.message', 'mockMessage');
27 if (!window
.testRunner
|| !window
.internals
)
28 debug('This test can not run without testRunner or internals');
30 internals
.setGeolocationClientMock(document
);
31 internals
.setGeolocationPermission(document
, true);
32 internals
.setGeolocationPosition(document
, mockLatitude
, mockLongitude
, mockAccuracy
);
34 // Initialize the cached Position
35 navigator
.geolocation
.getCurrentPosition(function(p
) {
39 testFailed('Error callback invoked unexpectedly');
43 function testZeroMaximumAge() {
44 // Update the position provided by the mock service.
45 internals
.setGeolocationPosition(document
, ++mockLatitude
, ++mockLongitude
, ++mockAccuracy
);
46 // The default maximumAge is zero, so we expect the updated position from the service.
47 navigator
.geolocation
.getCurrentPosition(function(p
) {
49 testNonZeroMaximumAge();
51 testFailed('Error callback invoked unexpectedly');
56 function testNonZeroMaximumAge() {
57 // Update the mock service to report an error.
58 internals
.setGeolocationPositionUnavailableError(document
, mockMessage
);
59 // The maximumAge is non-zero, so we expect the cached position, not the error from the service.
60 navigator
.geolocation
.getCurrentPosition(function(p
) {
62 testNegativeValueMaximumAge();
64 testFailed('Error callback invoked unexpectedly');
66 }, {maximumAge
: 1000});
69 function testNegativeValueMaximumAge() {
70 // Update the position provided by the mock service.
71 internals
.setGeolocationPosition(document
, ++mockLatitude
, ++mockLongitude
, ++mockAccuracy
);
72 // The maximumAge is same as zero, so we expect the updated position from the service.
73 navigator
.geolocation
.getCurrentPosition(function(p
) {
75 testOverSignedIntMaximumAge();
77 testFailed('Error callback invoked unexpectedly');
79 }, {maximumAge
: -1000});
82 function testOverSignedIntMaximumAge() {
83 // Update the mock service to report an error.
84 internals
.setGeolocationPositionUnavailableError(document
, mockMessage
);
85 // The maximumAge is non-zero, so we expect the cached position, not the error from the service.
86 navigator
.geolocation
.getCurrentPosition(function(p
) {
88 testOverUnsignedIntMaximumAge();
90 testFailed('Error callback invoked unexpectedly');
92 }, {maximumAge
: 2147483648});
95 function testOverUnsignedIntMaximumAge() {
96 // Update the mock service to report an error.
97 internals
.setGeolocationPositionUnavailableError(document
, mockMessage
);
98 // The maximumAge is max-value of unsigned, so we expect the cached position, not the error from the service.
99 navigator
.geolocation
.getCurrentPosition(function(p
) {
101 testZeroMaximumAgeError();
103 testFailed('Error callback invoked unexpectedly');
105 }, {maximumAge
: 4294967296});
108 function testZeroMaximumAgeError() {
109 // The default maximumAge is zero, so we expect the error from the service.
110 navigator
.geolocation
.getCurrentPosition(function(p
) {
111 testFailed('Success callback invoked unexpectedly');
119 window
.jsTestIsAsync
= true;