Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Geolocation / script-tests / watch.js
blobfb2b454c047635e6e9a4396c3befae9dbe4cb56d
1 description("Tests that watchPosition correctly reports position updates and errors from the Geolocation service.");
3 var mockLatitude = 51.478;
4 var mockLongitude = -0.166;
5 var mockAccuracy = 100.0;
7 var mockMessage = 'test';
9 var position;
10 var error;
12 function checkPosition(p) {
13 position = p;
14 shouldBe('position.coords.latitude', 'mockLatitude');
15 shouldBe('position.coords.longitude', 'mockLongitude');
16 shouldBe('position.coords.accuracy', 'mockAccuracy');
17 debug('');
20 function checkError(e) {
21 error = e;
22 shouldBe('error.code', 'error.POSITION_UNAVAILABLE');
23 shouldBe('error.message', 'mockMessage');
24 debug('');
27 if (!window.testRunner || !window.internals)
28 debug('This test can not run without testRunner or internals');
30 internals.setGeolocationClientMock(document);
31 internals.setGeolocationPermission(document, true);
32 internals.setGeolocationPosition(document, mockLatitude, mockLongitude, mockAccuracy);
34 var state = 0;
35 navigator.geolocation.watchPosition(function(p) {
36 switch (state++) {
37 case 0:
38 checkPosition(p);
39 internals.setGeolocationPosition(document, ++mockLatitude, ++mockLongitude, ++mockAccuracy);
40 break;
41 case 1:
42 checkPosition(p);
43 internals.setGeolocationPositionUnavailableError(document, mockMessage);
44 break;
45 case 3:
46 checkPosition(p);
47 finishJSTest();
48 break;
49 default:
50 testFailed('Success callback invoked unexpectedly');
51 finishJSTest();
53 }, function(e) {
54 switch (state++) {
55 case 2:
56 checkError(e);
57 internals.setGeolocationPosition(document, ++mockLatitude, ++mockLongitude, ++mockAccuracy);
58 break;
59 default:
60 testFailed('Error callback invoked unexpectedly');
61 finishJSTest();
63 });
65 window.jsTestIsAsync = true;