1description("Tests that Geoposition timestamps are well-formed (non-zero and in the same units as Date.getTime).");
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, mockLongitude, mockAccuracy);
10}
11
12var now = new Date().getTime();
13shouldBeTrue('now != 0');
14var t = null;
15var then = null;
16
17function 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
32navigator.geolocation.getCurrentPosition(checkPosition);
33window.jsTestIsAsync = true;
34window.successfullyParsed = true;
35