Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Geolocation / script-tests / timestamp.js
blob9cf1dfd82be67a0fd062545e2856e3dc282ac431
1 description("Tests that Geoposition timestamps are well-formed (non-zero and in the same units as Date.getTime).");
3 var mockLatitude = 51.478;
4 var mockLongitude = -0.166;
5 var mockAccuracy = 100.0;
7 var now = new Date().getTime();
8 shouldBeTrue('now != 0');
9 var t = null;
10 var then = null;
12 if (!window.testRunner || !window.internals)
13 debug('This test can not run without testRunner or internals');
15 internals.setGeolocationClientMock(document);
16 internals.setGeolocationPermission(document, true);
17 internals.setGeolocationPosition(document, mockLatitude, mockLongitude, mockAccuracy);
19 function checkPosition(p) {
20 t = p.timestamp;
21 var d = new Date();
22 then = d.getTime();
23 shouldBeTrue('t != 0');
24 shouldBeTrue('then != 0');
25 shouldBeTrue('now - 1 <= t'); // Avoid rounding errors
26 if (now - 1 > t) {
27 debug(" now - 1 = " + (now-1));
28 debug(" t = " + t);
30 shouldBeTrue('t <= then + 1'); // Avoid rounding errors
31 finishJSTest();
34 navigator.geolocation.getCurrentPosition(checkPosition);
35 window.jsTestIsAsync = true;