1description("Tests that watchPosition correctly reports position updates and errors from the Geolocation service.");
2
3var mockLatitude = 51.478;
4var mockLongitude = -0.166;
5var mockAccuracy = 100.0;
6
7var mockCode = 1;
8var mockMessage = 'test';
9
10var position;
11var error;
12
13function checkPosition(p) {
14    position = p;
15    shouldBe('position.coords.latitude', 'mockLatitude');
16    shouldBe('position.coords.longitude', 'mockLongitude');
17    shouldBe('position.coords.accuracy', 'mockAccuracy');
18    debug('');
19}
20
21function checkError(e) {
22    error = e;
23    shouldBe('error.code', 'mockCode');
24    shouldBe('error.message', 'mockMessage');
25    debug('');
26}
27
28window.layoutTestController.setGeolocationPermission(true);
29window.layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
30
31var state = 0;
32navigator.geolocation.watchPosition(function(p) {
33    switch (state++) {
34        case 0:
35            checkPosition(p);
36            window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
37            break;
38        case 1:
39            checkPosition(p);
40            window.layoutTestController.setMockGeolocationError(mockCode, mockMessage);
41            break;
42        case 3:
43            checkPosition(p);
44            debug('<br /><span class="pass">TEST COMPLETE</span>');
45            window.layoutTestController.notifyDone();
46            break;
47        default:
48            testFailed('Success callback invoked unexpectedly');
49            window.layoutTestController.notifyDone();
50    }
51}, function(e) {
52    switch (state++) {
53        case 2:
54            checkError(e);
55            window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
56            break;
57        default:
58            testFailed('Error callback invoked unexpectedly');
59            window.layoutTestController.notifyDone();
60    }
61});
62window.layoutTestController.waitUntilDone();
63
64var isAsynchronous = true;
65var successfullyParsed = true;
66