| <!DOCTYPE html> |
| <html> |
| <head> |
| <script src="../resources/js-test.js"></script> |
| <script src="file:///gen/layout_test_data/mojo/public/js/mojo_bindings.js"></script> |
| <script src="file:///gen/device/geolocation/public/interfaces/geolocation.mojom.js"></script> |
| <script src="file:///gen/third_party/blink/public/platform/modules/geolocation/geolocation_service.mojom.js"></script> |
| <script src="file:///gen/third_party/blink/public/platform/modules/permissions/permission.mojom.js"></script> |
| <script src="resources/geolocation-mock.js"></script> |
| </head> |
| <body> |
| <script> |
| description("Tests that watchPosition does not report position changes when the page is not visible."); |
| window.jsTestIsAsync = true; |
| |
| if (!window.testRunner) |
| debug('This test can not run without testRunner'); |
| |
| var position; |
| var error; |
| var isPageVisible = true; |
| |
| let mock = geolocationMock; |
| mock.setGeolocationPermission(true); |
| |
| debug("* Page is visible"); |
| |
| var mockLatitude = 51.478; |
| var mockLongitude = -0.166; |
| var mockAccuracy = 100.0; |
| |
| function updatePosition() { |
| if (!window.testRunner) |
| return; |
| ++mockLatitude; |
| ++mockLongitude; |
| mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); |
| debug('device moved to (' + mockLatitude + ', ' + mockLongitude + ')'); |
| } |
| |
| updatePosition(); |
| |
| var state = 0; |
| |
| function checkPosition(p) { |
| position = p; |
| shouldBe('position.coords.latitude', '' + mockLatitude); |
| shouldBe('position.coords.longitude', '' + mockLongitude); |
| debug(''); |
| } |
| |
| function showPageAndUpdatePosition() { |
| shouldBeFalse('isPageVisible'); |
| debug(''); |
| state++; |
| if (window.testRunner) { |
| debug("*Showing page"); |
| testRunner.setPageVisibility("visible"); |
| isPageVisible = true; |
| } |
| updatePosition(); |
| } |
| |
| navigator.geolocation.watchPosition(function(p) { |
| debug("Page is notified of the position change"); |
| shouldBeTrue('isPageVisible'); |
| state++; |
| checkPosition(p); |
| switch(state) { |
| case 2: { |
| if (window.testRunner) { |
| debug("* Hiding page"); |
| testRunner.setPageVisibility("hidden"); |
| isPageVisible = false; |
| } |
| setTimeout(showPageAndUpdatePosition, 100); |
| break; |
| } |
| case 4: |
| finishJSTest(); |
| return; |
| } |
| updatePosition(); |
| }, function(e) { |
| testFailed('Error callback invoked unexpectedly'); |
| finishJSTest(); |
| }); |
| |
| </script> |
| </body> |
| </html> |