1description("Tests that reentrant calls to Geolocation methods from the success callback are OK."); 2 3var mockLatitude = 51.478; 4var mockLongitude = -0.166; 5var mockAccuracy = 100.0; 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 position; 16var successCallbackInvoked = false; 17navigator.geolocation.getCurrentPosition(function(p) { 18 if (successCallbackInvoked) { 19 testFailed('Success callback invoked unexpectedly'); 20 finishJSTest(); 21 } 22 successCallbackInvoked = true; 23 24 position = p; 25 shouldBe('position.coords.latitude', 'mockLatitude'); 26 shouldBe('position.coords.longitude', 'mockLongitude'); 27 shouldBe('position.coords.accuracy', 'mockAccuracy'); 28 debug(''); 29 continueTest(); 30}, function(e) { 31 testFailed('Error callback invoked unexpectedly'); 32 finishJSTest(); 33}); 34 35function continueTest() { 36 if (window.layoutTestController) 37 layoutTestController.setMockGeolocationPosition(++mockLatitude, 38 ++mockLongitude, 39 ++mockAccuracy); 40 41 navigator.geolocation.getCurrentPosition(function(p) { 42 position = p; 43 shouldBe('position.coords.latitude', 'mockLatitude'); 44 shouldBe('position.coords.longitude', 'mockLongitude'); 45 shouldBe('position.coords.accuracy', 'mockAccuracy'); 46 finishJSTest(); 47 }, function(e) { 48 testFailed('Error callback invoked unexpectedly'); 49 finishJSTest(); 50 }); 51} 52 53window.jsTestIsAsync = true; 54window.successfullyParsed = true; 55