Home | History | Annotate | Download | only in script-tests
      1 description("Tests that Geolocation correctly handles multiple concurrent requests.");
      2 
      3 var mockLatitude = 51.478;
      4 var mockLongitude = -0.166;
      5 var mockAccuracy = 100;
      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 watchCallbackInvoked = false;
     16 var oneShotCallbackInvoked = false;
     17 
     18 navigator.geolocation.watchPosition(function(p) {
     19     shouldBeFalse('watchCallbackInvoked');
     20     watchCallbackInvoked = true;
     21     maybeFinishTest(p);
     22 }, function() {
     23     testFailed('Error callback invoked unexpectedly');
     24     finishJSTest();
     25 });
     26 
     27 navigator.geolocation.getCurrentPosition(function(p) {
     28     shouldBeFalse('oneShotCallbackInvoked');
     29     oneShotCallbackInvoked = true;
     30     maybeFinishTest(p);
     31 }, function() {
     32     testFailed('Error callback invoked unexpectedly');
     33     finishJSTest();
     34 });
     35 
     36 var position;
     37 function maybeFinishTest(p) {
     38     position = p;
     39     shouldBe('position.coords.latitude', 'mockLatitude');
     40     shouldBe('position.coords.longitude', 'mockLongitude');
     41     shouldBe('position.coords.accuracy', 'mockAccuracy');
     42     if (watchCallbackInvoked && oneShotCallbackInvoked)
     43         finishJSTest();
     44 }
     45 
     46 window.jsTestIsAsync = true;
     47 window.successfullyParsed = true;
     48