Home | History | Annotate | Download | only in script-tests
      1 description("Tests that Geoposition timestamps are well-formed (non-zero and in the same units as Date.getTime).");
      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, mockLongitude, mockAccuracy);
     10 }
     11 
     12 var now = new Date().getTime();
     13 shouldBeTrue('now != 0');
     14 var t = null;
     15 var then = null;
     16 
     17 function checkPosition(p) {
     18     t = p.timestamp;
     19     var d = new Date();
     20     then = d.getTime();
     21     shouldBeTrue('t != 0');
     22     shouldBeTrue('then != 0');
     23     shouldBeTrue('now - 1 <= t'); // Avoid rounding errors
     24     if (now - 1 > t) {
     25         debug("  now - 1 = " + (now-1));
     26         debug("  t = " + t);
     27     }
     28     shouldBeTrue('t <= then + 1'); // Avoid rounding errors
     29     finishJSTest();
     30 }
     31 
     32 navigator.geolocation.getCurrentPosition(checkPosition);
     33 window.jsTestIsAsync = true;
     34 window.successfullyParsed = true;
     35