| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <html> | 2 <html> |
| 3 <head> | 3 <head> |
| 4 <script src="../../../resources/js-test.js"></script> | 4 <script src="../../../resources/js-test.js"></script> |
| 5 <script src="../../../resources/mojo-helpers.js"></script> |
| 6 <script src="resources/geolocation-mock.js"></script> |
| 5 </head> | 7 </head> |
| 6 <body> | 8 <body> |
| 7 <script> | 9 <script> |
| 8 description("Tests that watchPosition does not report position changes when the
page is not visible."); | 10 description("Tests that watchPosition does not report position changes when the
page is not visible."); |
| 9 window.jsTestIsAsync = true; | 11 window.jsTestIsAsync = true; |
| 10 | 12 |
| 11 if (!window.testRunner || !window.internals) | 13 if (!window.testRunner || !window.mojo) |
| 12 debug('This test can not run without testRunner or internals'); | 14 debug('This test can not run without testRunner or mojo'); |
| 13 | 15 |
| 14 internals.setGeolocationClientMock(document); | |
| 15 internals.setGeolocationPermission(document, true); | |
| 16 | |
| 17 debug("* Page is visible"); | |
| 18 | |
| 19 var mockLatitude = 51.478; | |
| 20 var mockLongitude = -0.166; | |
| 21 var mockAccuracy = 100.0; | |
| 22 | |
| 23 function updatePosition() { | |
| 24 if (!window.testRunner) | |
| 25 return; | |
| 26 ++mockLatitude; | |
| 27 ++mockLongitude; | |
| 28 internals.setGeolocationPosition(document, mockLatitude, mockLongitude, mock
Accuracy); | |
| 29 debug('device moved to (' + mockLatitude + ', ' + mockLongitude + ')'); | |
| 30 } | |
| 31 | |
| 32 updatePosition(); | |
| 33 | |
| 34 var state = 0; | |
| 35 var position; | 16 var position; |
| 36 var error; | 17 var error; |
| 37 var isPageVisible = true; | 18 var isPageVisible = true; |
| 38 | 19 |
| 39 function checkPosition(p) { | 20 geolocationServiceMock.then(mock => { |
| 40 position = p; | 21 mock.setGeolocationPermission(true); |
| 41 shouldBe('position.coords.latitude', '' + mockLatitude); | |
| 42 shouldBe('position.coords.longitude', '' + mockLongitude); | |
| 43 debug(''); | |
| 44 } | |
| 45 | 22 |
| 46 function showPageAndUpdatePosition() { | 23 debug("* Page is visible"); |
| 47 shouldBeFalse('isPageVisible'); | 24 |
| 48 debug(''); | 25 var mockLatitude = 51.478; |
| 49 state++; | 26 var mockLongitude = -0.166; |
| 50 if (window.testRunner) { | 27 var mockAccuracy = 100.0; |
| 51 debug("*Showing page"); | 28 |
| 52 testRunner.setPageVisibility("visible"); | 29 function updatePosition() { |
| 53 isPageVisible = true; | 30 if (!window.testRunner) |
| 31 return; |
| 32 ++mockLatitude; |
| 33 ++mockLongitude; |
| 34 mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy); |
| 35 debug('device moved to (' + mockLatitude + ', ' + mockLongitude + ')'); |
| 54 } | 36 } |
| 37 |
| 55 updatePosition(); | 38 updatePosition(); |
| 56 } | |
| 57 | 39 |
| 58 navigator.geolocation.watchPosition(function(p) { | 40 var state = 0; |
| 59 debug("Page is notified of the position change"); | 41 |
| 60 shouldBeTrue('isPageVisible'); | 42 function checkPosition(p) { |
| 61 state++; | 43 position = p; |
| 62 checkPosition(p); | 44 shouldBe('position.coords.latitude', '' + mockLatitude); |
| 63 switch(state) { | 45 shouldBe('position.coords.longitude', '' + mockLongitude); |
| 64 case 2: { | 46 debug(''); |
| 65 if (window.testRunner) { | 47 } |
| 66 debug("* Hiding page"); | 48 |
| 67 » testRunner.setPageVisibility("hidden"); | 49 function showPageAndUpdatePosition() { |
| 68 isPageVisible = false; | 50 shouldBeFalse('isPageVisible'); |
| 51 debug(''); |
| 52 state++; |
| 53 if (window.testRunner) { |
| 54 debug("*Showing page"); |
| 55 testRunner.setPageVisibility("visible"); |
| 56 isPageVisible = true; |
| 57 } |
| 58 updatePosition(); |
| 59 } |
| 60 |
| 61 navigator.geolocation.watchPosition(function(p) { |
| 62 debug("Page is notified of the position change"); |
| 63 shouldBeTrue('isPageVisible'); |
| 64 state++; |
| 65 checkPosition(p); |
| 66 switch(state) { |
| 67 case 2: { |
| 68 if (window.testRunner) { |
| 69 debug("* Hiding page"); |
| 70 testRunner.setPageVisibility("hidden"); |
| 71 isPageVisible = false; |
| 72 } |
| 73 setTimeout(showPageAndUpdatePosition, 100); |
| 74 break; |
| 69 } | 75 } |
| 70 setTimeout(showPageAndUpdatePosition, 100); | 76 case 4: |
| 71 break; | 77 finishJSTest(); |
| 78 return; |
| 72 } | 79 } |
| 73 case 4: | 80 updatePosition(); |
| 74 finishJSTest(); | 81 }, function(e) { |
| 75 return; | 82 testFailed('Error callback invoked unexpectedly'); |
| 76 } | 83 finishJSTest(); |
| 77 updatePosition(); | 84 }); |
| 78 }, function(e) { | |
| 79 testFailed('Error callback invoked unexpectedly'); | |
| 80 finishJSTest(); | |
| 81 }); | 85 }); |
| 82 | 86 |
| 83 </script> | 87 </script> |
| 84 </body> | 88 </body> |
| 85 </html> | 89 </html> |
| OLD | NEW |