watch.js revision e78cbe89e6f337f2f1fe40315be88f742b547151
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            finishJSTest();
45            break;
46        default:
47            testFailed('Success callback invoked unexpectedly');
48            finishJSTest();
49    }
50}, function(e) {
51    switch (state++) {
52        case 2:
53            checkError(e);
54            window.layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
55            break;
56        default:
57            testFailed('Error callback invoked unexpectedly');
58            finishJSTest();
59    }
60});
61window.layoutTestController.waitUntilDone();
62
63window.jsTestIsAsync = true;
64window.successfullyParsed = true;
65