1cfb0617749a64f2e177386b030d46007b8c4b179Steve Blockdescription("Tests that when Geolocation permission has been denied prior to a call to watchPosition, and the watch is cleared in the error callback, there is no crash. This a regression test for https://bugs.webkit.org/show_bug.cgi?id=32111.");
2cfb0617749a64f2e177386b030d46007b8c4b179Steve Block
3cfb0617749a64f2e177386b030d46007b8c4b179Steve Block// Prime the Geolocation instance by denying permission.
4545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdochif (window.layoutTestController) {
5545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    layoutTestController.setGeolocationPermission(false);
6545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    layoutTestController.setMockGeolocationPosition(51.478, -0.166, 100);
7545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch} else
8545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    debug('This test can not be run without the LayoutTestController');
9cfb0617749a64f2e177386b030d46007b8c4b179Steve Block
10cfb0617749a64f2e177386b030d46007b8c4b179Steve Blockvar error;
11cfb0617749a64f2e177386b030d46007b8c4b179Steve Blocknavigator.geolocation.getCurrentPosition(function(p) {
12cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    testFailed('Success callback invoked unexpectedly');
13e78cbe89e6f337f2f1fe40315be88f742b547151Steve Block    finishJSTest();
14cfb0617749a64f2e177386b030d46007b8c4b179Steve Block}, function(e) {
15545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch    error = e;
16cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    shouldBe('error.code', 'error.PERMISSION_DENIED');
17cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    shouldBe('error.message', '"User denied Geolocation"');
18cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    debug('');
19cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    continueTest();
20cfb0617749a64f2e177386b030d46007b8c4b179Steve Block});
21cfb0617749a64f2e177386b030d46007b8c4b179Steve Block
22cfb0617749a64f2e177386b030d46007b8c4b179Steve Blockfunction continueTest()
23cfb0617749a64f2e177386b030d46007b8c4b179Steve Block{
24cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    // Make another request, with permission already denied.
25cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    var watchId = navigator.geolocation.watchPosition(function(p) {
26cfb0617749a64f2e177386b030d46007b8c4b179Steve Block        testFailed('Success callback invoked unexpectedly');
27e78cbe89e6f337f2f1fe40315be88f742b547151Steve Block        finishJSTest();
28cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    }, function(e) {
29545e470e52f0ac6a3a072bf559c796b42c6066b6Ben Murdoch        error = e;
30cfb0617749a64f2e177386b030d46007b8c4b179Steve Block        shouldBe('error.code', 'error.PERMISSION_DENIED');
31cfb0617749a64f2e177386b030d46007b8c4b179Steve Block        shouldBe('error.message', '"User denied Geolocation"');
32cfb0617749a64f2e177386b030d46007b8c4b179Steve Block        navigator.geolocation.clearWatch(watchId);
33e78cbe89e6f337f2f1fe40315be88f742b547151Steve Block        window.setTimeout(finishJSTest, 0);
34cfb0617749a64f2e177386b030d46007b8c4b179Steve Block    });
35cfb0617749a64f2e177386b030d46007b8c4b179Steve Block}
36cfb0617749a64f2e177386b030d46007b8c4b179Steve Block
37e78cbe89e6f337f2f1fe40315be88f742b547151Steve Blockwindow.jsTestIsAsync = true;
38e78cbe89e6f337f2f1fe40315be88f742b547151Steve Blockwindow.successfullyParsed = true;
39