multiple-requests.js revision 545e470e52f0ac6a3a072bf559c796b42c6066b6
1description("Tests that Geolocation correctly handles multiple concurrent requests.");
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 watchCallbackInvoked = false;
16var oneShotCallbackInvoked = false;
17
18navigator.geolocation.watchPosition(function(p) {
19    shouldBeFalse('watchCallbackInvoked');
20    watchCallbackInvoked = true;
21    maybeFinishTest(p);
22}, function() {
23    testFailed('Error callback invoked unexpectedly');
24    finishJSTest();
25});
26
27navigator.geolocation.getCurrentPosition(function(p) {
28    shouldBeFalse('oneShotCallbackInvoked');
29    oneShotCallbackInvoked = true;
30    maybeFinishTest(p);
31}, function() {
32    testFailed('Error callback invoked unexpectedly');
33    finishJSTest();
34});
35
36var position;
37function maybeFinishTest(p) {
38    position = p;
39    shouldBe('position.coords.latitude', 'mockLatitude');
40    shouldBe('position.coords.longitude', 'mockLongitude');
41    shouldBe('position.coords.accuracy', 'mockAccuracy');
42    if (watchCallbackInvoked && oneShotCallbackInvoked)
43        finishJSTest();
44}
45
46window.jsTestIsAsync = true;
47window.successfullyParsed = true;
48