4 <script src=
"../../../resources/js-test.js"></script>
8 description("Tests that watchPosition does not report position changes when the page is not visible.");
9 window
.jsTestIsAsync
= true;
11 if (!window
.testRunner
|| !window
.internals
)
12 debug('This test can not run without testRunner or internals');
14 internals
.setGeolocationClientMock(document
);
15 internals
.setGeolocationPermission(document
, true);
17 debug("* Page is visible");
19 var mockLatitude
= 51.478;
20 var mockLongitude
= -0.166;
21 var mockAccuracy
= 100.0;
23 function updatePosition() {
24 if (!window
.testRunner
)
28 internals
.setGeolocationPosition(document
, mockLatitude
, mockLongitude
, mockAccuracy
);
29 debug('device moved to (' + mockLatitude
+ ', ' + mockLongitude
+ ')');
37 var isPageVisible
= true;
39 function checkPosition(p
) {
41 shouldBe('position.coords.latitude', '' + mockLatitude
);
42 shouldBe('position.coords.longitude', '' + mockLongitude
);
46 function showPageAndUpdatePosition() {
47 shouldBeFalse('isPageVisible');
50 if (window
.testRunner
) {
51 debug("*Showing page");
52 testRunner
.setPageVisibility("visible");
58 navigator
.geolocation
.watchPosition(function(p
) {
59 debug("Page is notified of the position change");
60 shouldBeTrue('isPageVisible');
65 if (window
.testRunner
) {
66 debug("* Hiding page");
67 testRunner
.setPageVisibility("hidden");
68 isPageVisible
= false;
70 setTimeout(showPageAndUpdatePosition
, 100);
79 testFailed('Error callback invoked unexpectedly');