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) { | 7 if (window.testRunner) { |
8 testRunner.setGeolocationPermission(true); | 8 testRunner.setGeolocationPermission(true); |
9 testRunner.setMockGeolocationPosition(mockLatitude, | 9 testRunner.setMockGeolocationPosition(mockLatitude, |
10 mockLongitude, | 10 mockLongitude, |
11 mockAccuracy); | 11 mockAccuracy); |
12 } else | 12 } else |
13 debug('This test can not be run without the testRunner'); | 13 debug('This test can not be run without the testRunner'); |
14 | 14 |
15 var position; | 15 var position; |
16 navigator.geolocation.getCurrentPosition(function(p) { | 16 navigator.geolocation.getCurrentPosition(function(p) { |
17 position = p; | 17 position = p; |
18 shouldBe('position.coords.latitude', 'mockLatitude'); | 18 shouldBe('position.coords.latitude', 'mockLatitude'); |
19 shouldBe('position.coords.longitude', 'mockLongitude'); | 19 shouldBe('position.coords.longitude', 'mockLongitude'); |
20 shouldBe('position.coords.accuracy', 'mockAccuracy'); | 20 shouldBe('position.coords.accuracy', 'mockAccuracy'); |
21 | 21 |
22 // Yield to allow for the error callback to be invoked. The timer | 22 // Yield to allow for the error callback to be invoked. The timer |
23 // must be started before the exception is thrown. | 23 // must be started before the exception is thrown. |
24 window.setTimeout(assertWeGotException, 0); | 24 window.setTimeout(assertWeGotException, 0); |
| 25 expectError(); |
25 throw new Error('Exception in success callback'); | 26 throw new Error('Exception in success callback'); |
26 }, function(e) { | 27 }, function(e) { |
27 testFailed('Error callback invoked unexpectedly'); | 28 testFailed('Error callback invoked unexpectedly'); |
28 finishJSTest(); | 29 finishJSTest(); |
29 }); | 30 }); |
30 | 31 |
31 function assertWeGotException() | 32 function assertWeGotException() |
32 { | 33 { |
33 shouldHaveHadError(); | 34 shouldHaveHadError(); |
34 finishJSTest(); | 35 finishJSTest(); |
35 } | 36 } |
36 | 37 |
37 window.jsTestIsAsync = true; | 38 window.jsTestIsAsync = true; |
OLD | NEW |