1description("Tests that reentrant calls to Geolocation methods from the error callback are OK.");
2
3var mockCode = 2;
4var mockMessage = 'test';
5
6if (window.layoutTestController) {
7    layoutTestController.setGeolocationPermission(true);
8    layoutTestController.setMockGeolocationError(mockCode, mockMessage);
9} else
10    debug('This test can not be run without the LayoutTestController');
11
12var error;
13var errorCallbackInvoked = false;
14navigator.geolocation.getCurrentPosition(function(p) {
15    testFailed('Success callback invoked unexpectedly');
16    finishJSTest();
17}, function(e) {
18    if (errorCallbackInvoked) {
19        testFailed('Error callback invoked unexpectedly');
20        finishJSTest();
21    }
22    errorCallbackInvoked = true;
23
24    error = e;
25    shouldBe('error.code', 'mockCode');
26    shouldBe('error.message', 'mockMessage');
27    debug('');
28    continueTest();
29});
30
31function continueTest() {
32    mockMessage += ' repeat';
33
34    if (window.layoutTestController)
35        layoutTestController.setMockGeolocationError(mockCode, mockMessage);
36
37    navigator.geolocation.getCurrentPosition(function(p) {
38        testFailed('Success callback invoked unexpectedly');
39        finishJSTest();
40    }, function(e) {
41        error = e;
42        shouldBe('error.code', 'mockCode');
43        shouldBe('error.message', 'mockMessage');
44        finishJSTest();
45    });
46}
47
48window.jsTestIsAsync = true;
49window.successfullyParsed = true;
50