| OLD | NEW |
| 1 description("Tests that watchPosition correctly reports position updates and err
ors from the Geolocation service."); | 1 description("Tests that watchPosition correctly reports position updates and err
ors from the Geolocation service."); |
| 2 | 2 |
| 3 var mockLatitude = 51.478; | 3 var mockLatitude = 51.478; |
| 4 var mockLongitude = -0.166; | 4 var mockLongitude = -0.166; |
| 5 var mockAccuracy = 100.0; | 5 var mockAccuracy = 100.0; |
| 6 | 6 |
| 7 var mockMessage = 'test'; | 7 var mockMessage = 'test'; |
| 8 | 8 |
| 9 var position; | 9 var position; |
| 10 var error; | 10 var error; |
| 11 | 11 |
| 12 function checkPosition(p) { | 12 function checkPosition(p) { |
| 13 position = p; | 13 position = p; |
| 14 shouldBe('position.coords.latitude', 'mockLatitude'); | 14 shouldBe('position.coords.latitude', 'mockLatitude'); |
| 15 shouldBe('position.coords.longitude', 'mockLongitude'); | 15 shouldBe('position.coords.longitude', 'mockLongitude'); |
| 16 shouldBe('position.coords.accuracy', 'mockAccuracy'); | 16 shouldBe('position.coords.accuracy', 'mockAccuracy'); |
| 17 debug(''); | 17 debug(''); |
| 18 } | 18 } |
| 19 | 19 |
| 20 function checkError(e) { | 20 function checkError(e) { |
| 21 error = e; | 21 error = e; |
| 22 shouldBe('error.code', 'error.POSITION_UNAVAILABLE'); | 22 shouldBe('error.code', 'error.POSITION_UNAVAILABLE'); |
| 23 shouldBe('error.message', 'mockMessage'); | 23 shouldBe('error.message', 'mockMessage'); |
| 24 debug(''); | 24 debug(''); |
| 25 } | 25 } |
| 26 | 26 |
| 27 if (!window.testRunner || !window.mojo) | |
| 28 debug('This test can not run without testRunner or mojo'); | |
| 29 | |
| 30 geolocationServiceMock.then(mock => { | 27 geolocationServiceMock.then(mock => { |
| 31 mock.setGeolocationPermission(true); | 28 mock.setGeolocationPermission(true); |
| 32 mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); | 29 mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); |
| 33 | 30 |
| 34 var state = 0; | 31 var state = 0; |
| 35 navigator.geolocation.watchPosition(function(p) { | 32 navigator.geolocation.watchPosition(function(p) { |
| 36 switch (state++) { | 33 switch (state++) { |
| 37 case 0: | 34 case 0: |
| 38 checkPosition(p); | 35 checkPosition(p); |
| 39 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++m
ockAccuracy); | 36 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++m
ockAccuracy); |
| (...skipping 17 matching lines...) Expand all Loading... |
| 57 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++m
ockAccuracy); | 54 mock.setGeolocationPosition(++mockLatitude, ++mockLongitude, ++m
ockAccuracy); |
| 58 break; | 55 break; |
| 59 default: | 56 default: |
| 60 testFailed('Error callback invoked unexpectedly'); | 57 testFailed('Error callback invoked unexpectedly'); |
| 61 finishJSTest(); | 58 finishJSTest(); |
| 62 } | 59 } |
| 63 }); | 60 }); |
| 64 }); | 61 }); |
| 65 | 62 |
| 66 window.jsTestIsAsync = true; | 63 window.jsTestIsAsync = true; |
| OLD | NEW |