Home | History | Annotate | Download | only in script-tests
      1 description("Tests that reentrant calls to Geolocation methods from the success callback are OK.");
      2 
      3 var mockLatitude = 51.478;
      4 var mockLongitude = -0.166;
      5 var mockAccuracy = 100.0;
      6 
      7 if (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 
     15 var position;
     16 var successCallbackInvoked = false;
     17 navigator.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 
     35 function 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 
     53 window.jsTestIsAsync = true;
     54 window.successfullyParsed = true;
     55