1description("Tests that the PositionOptions.maximumAge parameter is correctly applied."); 2 3var mockLatitude = 51.478; 4var mockLongitude = -0.166; 5var mockAccuracy = 100.0; 6 7var mockCode = 1; 8var mockMessage = 'test'; 9 10var position; 11var error; 12 13function checkPosition(p) { 14 debug(''); 15 position = p; 16 shouldBe('position.coords.latitude', 'mockLatitude'); 17 shouldBe('position.coords.longitude', 'mockLongitude'); 18 shouldBe('position.coords.accuracy', 'mockAccuracy'); 19} 20 21function checkError(e) { 22 debug(''); 23 error = e; 24 shouldBe('error.code', 'mockCode'); 25 shouldBe('error.message', 'mockMessage'); 26} 27 28window.layoutTestController.setGeolocationPermission(true); 29window.layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); 30 31// Initialize the cached Position 32navigator.geolocation.getCurrentPosition(function(p) { 33 checkPosition(p); 34 testZeroMaximumAge(); 35}, function(e) { 36 testFailed('Error callback invoked unexpectedly'); 37 window.layoutTestController.notifyDone(); 38}); 39 40function testZeroMaximumAge() { 41 // Update the position provided by the mock service. 42 window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy); 43 // The default maximumAge is zero, so we expect the updated position from the service. 44 navigator.geolocation.getCurrentPosition(function(p) { 45 checkPosition(p); 46 testNonZeroMaximumAge(); 47 }, function(e) { 48 testFailed('Error callback invoked unexpectedly'); 49 window.layoutTestController.notifyDone(); 50 }); 51} 52 53function testNonZeroMaximumAge() { 54 // Update the mock service to report an error. 55 window.layoutTestController.setMockGeolocationError(mockCode, mockMessage); 56 // The maximumAge is non-zero, so we expect the cached position, not the error from the service. 57 navigator.geolocation.getCurrentPosition(function(p) { 58 checkPosition(p); 59 testZeroMaximumAgeError(); 60 }, function(e) { 61 testFailed('Error callback invoked unexpectedly'); 62 window.layoutTestController.notifyDone(); 63 }, {maximumAge: 1000}); 64} 65 66function testZeroMaximumAgeError() { 67 // The default maximumAge is zero, so we expect the error from the service. 68 navigator.geolocation.getCurrentPosition(function(p) { 69 testFailed('Success callback invoked unexpectedly'); 70 window.layoutTestController.notifyDone(); 71 }, function(e) { 72 checkError(e); 73 debug('<br /><span class="pass">TEST COMPLETE</span>'); 74 window.layoutTestController.notifyDone(); 75 }); 76} 77 78window.layoutTestController.waitUntilDone(); 79 80var isAsynchronous = true; 81var successfullyParsed = true; 82