OLD | NEW |
1 description("Tests that reentrant calls to Geolocation methods from the success
callback are OK."); | 1 description("Tests that reentrant calls to Geolocation methods from the success
callback are OK."); |
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 if (!window.testRunner || !window.internals) | 7 if (!window.testRunner || !window.mojo) |
8 debug('This test can not run without testRunner or internals'); | 8 debug('This test can not run without testRunner or mojo'); |
9 | |
10 internals.setGeolocationClientMock(document); | |
11 internals.setGeolocationPermission(document, true); | |
12 internals.setGeolocationPosition(document, | |
13 mockLatitude, | |
14 mockLongitude, | |
15 mockAccuracy); | |
16 | 9 |
17 var position; | 10 var position; |
18 var successCallbackInvoked = false; | |
19 navigator.geolocation.getCurrentPosition(function(p) { | |
20 if (successCallbackInvoked) { | |
21 testFailed('Success callback invoked unexpectedly'); | |
22 finishJSTest(); | |
23 } | |
24 successCallbackInvoked = true; | |
25 | 11 |
26 position = p; | 12 geolocationServiceMock.then(mock => { |
27 shouldBe('position.coords.latitude', 'mockLatitude'); | 13 mock.setGeolocationPermission(true); |
28 shouldBe('position.coords.longitude', 'mockLongitude'); | 14 mock.setGeolocationPosition(mockLatitude, |
29 shouldBe('position.coords.accuracy', 'mockAccuracy'); | 15 mockLongitude, |
30 debug(''); | 16 mockAccuracy); |
31 continueTest(); | |
32 }, function(e) { | |
33 testFailed('Error callback invoked unexpectedly'); | |
34 finishJSTest(); | |
35 }); | |
36 | 17 |
37 function continueTest() { | 18 var successCallbackInvoked = false; |
38 internals.setGeolocationPosition(document, | 19 navigator.geolocation.getCurrentPosition(function(p) { |
39 ++mockLatitude, | 20 if (successCallbackInvoked) { |
40 ++mockLongitude, | 21 testFailed('Success callback invoked unexpectedly'); |
41 ++mockAccuracy); | 22 finishJSTest(); |
| 23 } |
| 24 successCallbackInvoked = true; |
42 | 25 |
43 navigator.geolocation.getCurrentPosition(function(p) { | |
44 position = p; | 26 position = p; |
45 shouldBe('position.coords.latitude', 'mockLatitude'); | 27 shouldBe('position.coords.latitude', 'mockLatitude'); |
46 shouldBe('position.coords.longitude', 'mockLongitude'); | 28 shouldBe('position.coords.longitude', 'mockLongitude'); |
47 shouldBe('position.coords.accuracy', 'mockAccuracy'); | 29 shouldBe('position.coords.accuracy', 'mockAccuracy'); |
48 finishJSTest(); | 30 debug(''); |
| 31 continueTest(); |
49 }, function(e) { | 32 }, function(e) { |
50 testFailed('Error callback invoked unexpectedly'); | 33 testFailed('Error callback invoked unexpectedly'); |
51 finishJSTest(); | 34 finishJSTest(); |
52 }); | 35 }); |
53 } | 36 |
| 37 function continueTest() { |
| 38 mock.setGeolocationPosition(++mockLatitude, |
| 39 ++mockLongitude, |
| 40 ++mockAccuracy); |
| 41 |
| 42 navigator.geolocation.getCurrentPosition(function(p) { |
| 43 position = p; |
| 44 shouldBe('position.coords.latitude', 'mockLatitude'); |
| 45 shouldBe('position.coords.longitude', 'mockLongitude'); |
| 46 shouldBe('position.coords.accuracy', 'mockAccuracy'); |
| 47 finishJSTest(); |
| 48 }, function(e) { |
| 49 testFailed('Error callback invoked unexpectedly'); |
| 50 finishJSTest(); |
| 51 }); |
| 52 } |
| 53 }); |
54 | 54 |
55 window.jsTestIsAsync = true; | 55 window.jsTestIsAsync = true; |
OLD | NEW |