callback-exception.js revision 545e470e52f0ac6a3a072bf559c796b42c6066b6
1description("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
3var mockLatitude = 51.478;
4var mockLongitude = -0.166;
5var mockAccuracy = 100;
6
7if (window.layoutTestController) {
8    layoutTestController.setGeolocationPermission(true);
9    layoutTestController.setMockGeolocationPosition(mockLatitude,
10                                                    mockLongitude,
11                                                    mockAccuracy);
12} else
13    debug('This test can not be run without the LayoutTestController');
14
15var position;
16navigator.geolocation.getCurrentPosition(function(p) {
17    position = p;
18    shouldBe('position.coords.latitude', 'mockLatitude');
19    shouldBe('position.coords.longitude', 'mockLongitude');
20    shouldBe('position.coords.accuracy', 'mockAccuracy');
21
22    // Yield to allow for the error callback to be invoked. The timer
23    // must be started before the exception is thrown.
24    window.setTimeout(finishJSTest, 0);
25    throw new Error('Exception in success callback');
26}, function(e) {
27    testFailed('Error callback invoked unexpectedly');
28    finishJSTest();
29});
30
31window.jsTestIsAsync = true;
32window.successfullyParsed = true;
33