Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Geolocation / script-tests / reentrant-success.js
blob0d53f8ae110cdcb72422d130dd6452bbbf4c60f1
1 description("Tests that reentrant calls to Geolocation methods from the success callback are OK.");
3 var mockLatitude = 51.478;
4 var mockLongitude = -0.166;
5 var mockAccuracy = 100.0;
7 if (!window.testRunner || !window.internals)
8     debug('This test can not run without testRunner or internals');
10 internals.setGeolocationClientMock(document);
11 internals.setGeolocationPermission(document, true);
12 internals.setGeolocationPosition(document,
13                                  mockLatitude,
14                                  mockLongitude,
15                                  mockAccuracy);
17 var position;
18 var successCallbackInvoked = false;
19 navigator.geolocation.getCurrentPosition(function(p) {
20     if (successCallbackInvoked) {
21         testFailed('Success callback invoked unexpectedly');
22         finishJSTest();
23     }
24     successCallbackInvoked = true;
26     position = p;
27     shouldBe('position.coords.latitude', 'mockLatitude');
28     shouldBe('position.coords.longitude', 'mockLongitude');
29     shouldBe('position.coords.accuracy', 'mockAccuracy');
30     debug('');
31     continueTest();
32 }, function(e) {
33     testFailed('Error callback invoked unexpectedly');
34     finishJSTest();
35 });
37 function continueTest() {
38     internals.setGeolocationPosition(document,
39                                      ++mockLatitude,
40                                      ++mockLongitude,
41                                      ++mockAccuracy);
43     navigator.geolocation.getCurrentPosition(function(p) {
44         position = p;
45         shouldBe('position.coords.latitude', 'mockLatitude');
46         shouldBe('position.coords.longitude', 'mockLongitude');
47         shouldBe('position.coords.accuracy', 'mockAccuracy');
48         finishJSTest();
49     }, function(e) {
50         testFailed('Error callback invoked unexpectedly');
51         finishJSTest();
52     });
55 window.jsTestIsAsync = true;