OLD | NEW |
1 description("Tests that when an exception is thrown in the success callback, the
error callback is not invoked. Note that this test throws an exception which is
not caught."); | 1 description("Tests that when an exception is thrown in the success callback, the
error callback is not invoked. Note that this test throws an exception which is
not caught."); |
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; | 5 var mockAccuracy = 100; |
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 navigator.geolocation.getCurrentPosition(function(p) { | |
19 position = p; | |
20 shouldBe('position.coords.latitude', 'mockLatitude'); | |
21 shouldBe('position.coords.longitude', 'mockLongitude'); | |
22 shouldBe('position.coords.accuracy', 'mockAccuracy'); | |
23 | 11 |
24 // Yield to allow for the error callback to be invoked. The timer | 12 geolocationServiceMock.then(mock => { |
25 // must be started before the exception is thrown. | 13 mock.setGeolocationPermission(true); |
26 window.setTimeout(assertWeGotException, 0); | 14 mock.setGeolocationPosition(mockLatitude, |
27 expectError(); | 15 mockLongitude, |
28 throw new Error('Exception in success callback'); | 16 mockAccuracy); |
29 }, function(e) { | 17 navigator.geolocation.getCurrentPosition(function(p) { |
30 testFailed('Error callback invoked unexpectedly'); | 18 position = p; |
31 finishJSTest(); | 19 shouldBe('position.coords.latitude', 'mockLatitude'); |
| 20 shouldBe('position.coords.longitude', 'mockLongitude'); |
| 21 shouldBe('position.coords.accuracy', 'mockAccuracy'); |
| 22 |
| 23 // Yield to allow for the error callback to be invoked. The timer |
| 24 // must be started before the exception is thrown. |
| 25 window.setTimeout(assertWeGotException, 0); |
| 26 expectError(); |
| 27 |
| 28 throw new Error('Exception in success callback'); |
| 29 }, function(e) { |
| 30 testFailed('Error callback invoked unexpectedly'); |
| 31 finishJSTest(); |
| 32 }); |
32 }); | 33 }); |
33 | 34 |
34 function assertWeGotException() | 35 function assertWeGotException() |
35 { | 36 { |
36 shouldHaveHadError(); | 37 shouldHaveHadError(); |
37 finishJSTest(); | 38 finishJSTest(); |
38 } | 39 } |
39 | 40 |
40 window.jsTestIsAsync = true; | 41 window.jsTestIsAsync = true; |
OLD | NEW |