| OLD | NEW |
| (Empty) |
| 1 description("Tests that the PositionOptions.maximumAge parameter is correctly ap
plied."); | |
| 2 | |
| 3 var mockLatitude = 51.478; | |
| 4 var mockLongitude = -0.166; | |
| 5 var mockAccuracy = 100.0; | |
| 6 | |
| 7 var mockMessage = 'test'; | |
| 8 | |
| 9 var position; | |
| 10 var error; | |
| 11 | |
| 12 function checkPosition(p) { | |
| 13 debug(''); | |
| 14 position = p; | |
| 15 shouldBe('position.coords.latitude', 'mockLatitude'); | |
| 16 shouldBe('position.coords.longitude', 'mockLongitude'); | |
| 17 shouldBe('position.coords.accuracy', 'mockAccuracy'); | |
| 18 } | |
| 19 | |
| 20 function checkError(e) { | |
| 21 debug(''); | |
| 22 error = e; | |
| 23 shouldBe('error.code', 'error.POSITION_UNAVAILABLE'); | |
| 24 shouldBe('error.message', 'mockMessage'); | |
| 25 } | |
| 26 | |
| 27 geolocationServiceMock.then(mock => { | |
| 28 mock.setGeolocationPermission(true); | |
| 29 mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); | |
| 30 | |
| 31 // Initialize the cached Position | |
| 32 navigator.geolocation.getCurrentPosition(function(p) { | |
| 33 checkPosition(p); | |
| 34 testZeroMaximumAge(); | |
| 35 }, function(e) { | |
| 36 testFailed('Error callback invoked unexpectedly'); | |
| 37 finishJSTest(); | |
| 38 }); | |
| 39 | |
| 40 function testZeroMaximumAge() { | |
| 41 // Update the position provided by the mock service. | |
| 42 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccur
acy); | |
| 43 // The default maximumAge is zero, so we expect the updated position fro
m the service. | |
| 44 navigator.geolocation.getCurrentPosition(function(p) { | |
| 45 checkPosition(p); | |
| 46 testNonZeroMaximumAge(); | |
| 47 }, function(e) { | |
| 48 testFailed('Error callback invoked unexpectedly'); | |
| 49 finishJSTest(); | |
| 50 }); | |
| 51 } | |
| 52 | |
| 53 function testNonZeroMaximumAge() { | |
| 54 // Update the mock service to report an error. | |
| 55 mock.setGeolocationPositionUnavailableError(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 testNegativeValueMaximumAge(); | |
| 60 }, function(e) { | |
| 61 testFailed('Error callback invoked unexpectedly'); | |
| 62 finishJSTest(); | |
| 63 }, {maximumAge: 1000}); | |
| 64 } | |
| 65 | |
| 66 function testNegativeValueMaximumAge() { | |
| 67 // Update the position provided by the mock service. | |
| 68 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccur
acy); | |
| 69 // The maximumAge is same as zero, so we expect the updated position fro
m the service. | |
| 70 navigator.geolocation.getCurrentPosition(function(p) { | |
| 71 checkPosition(p); | |
| 72 testOverSignedIntMaximumAge(); | |
| 73 }, function(e) { | |
| 74 testFailed('Error callback invoked unexpectedly'); | |
| 75 finishJSTest(); | |
| 76 }, {maximumAge: -1000}); | |
| 77 } | |
| 78 | |
| 79 function testOverSignedIntMaximumAge() { | |
| 80 // Update the mock service to report an error. | |
| 81 mock.setGeolocationPositionUnavailableError(mockMessage); | |
| 82 // The maximumAge is non-zero, so we expect the cached position, not the
error from the service. | |
| 83 navigator.geolocation.getCurrentPosition(function(p) { | |
| 84 checkPosition(p); | |
| 85 testOverUnsignedIntMaximumAge(); | |
| 86 }, function(e) { | |
| 87 testFailed('Error callback invoked unexpectedly'); | |
| 88 finishJSTest(); | |
| 89 }, {maximumAge: 2147483648}); | |
| 90 } | |
| 91 | |
| 92 function testOverUnsignedIntMaximumAge() { | |
| 93 // Update the mock service to report an error. | |
| 94 mock.setGeolocationPositionUnavailableError(mockMessage); | |
| 95 // The maximumAge is max-value of unsigned, so we expect the cached posi
tion, not the error from the service. | |
| 96 navigator.geolocation.getCurrentPosition(function(p) { | |
| 97 checkPosition(p); | |
| 98 testZeroMaximumAgeError(); | |
| 99 }, function(e) { | |
| 100 testFailed('Error callback invoked unexpectedly'); | |
| 101 finishJSTest(); | |
| 102 }, {maximumAge: 4294967296}); | |
| 103 } | |
| 104 | |
| 105 function testZeroMaximumAgeError() { | |
| 106 // The default maximumAge is zero, so we expect the error from the servi
ce. | |
| 107 navigator.geolocation.getCurrentPosition(function(p) { | |
| 108 testFailed('Success callback invoked unexpectedly'); | |
| 109 finishJSTest(); | |
| 110 }, function(e) { | |
| 111 checkError(e); | |
| 112 finishJSTest(); | |
| 113 }); | |
| 114 } | |
| 115 }); | |
| 116 | |
| 117 window.jsTestIsAsync = true; | |
| OLD | NEW |