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 = 2; 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 28if (window.layoutTestController) { 29 layoutTestController.setGeolocationPermission(true); 30 layoutTestController.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); 31} else 32 debug('This test can not be run without the LayoutTestController'); 33 34var state = 0; 35navigator.geolocation.watchPosition(function(p) { 36 switch (state++) { 37 case 0: 38 checkPosition(p); 39 if (window.layoutTestController) 40 layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy); 41 break; 42 case 1: 43 checkPosition(p); 44 if (window.layoutTestController) 45 layoutTestController.setMockGeolocationError(mockCode, mockMessage); 46 break; 47 case 3: 48 checkPosition(p); 49 finishJSTest(); 50 break; 51 default: 52 testFailed('Success callback invoked unexpectedly'); 53 finishJSTest(); 54 } 55}, function(e) { 56 switch (state++) { 57 case 2: 58 checkError(e); 59 if (window.layoutTestController) 60 layoutTestController.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy); 61 break; 62 default: 63 testFailed('Error callback invoked unexpectedly'); 64 finishJSTest(); 65 } 66}); 67 68window.jsTestIsAsync = true; 69window.successfullyParsed = true; 70