Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / dom / Geolocation / watchPosition-page-visibility.html
blob944e5635c9e17e9a78b097c3de32eec60c95fd87
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 </head>
6 <body>
7 <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)
25 return;
26 ++mockLatitude;
27 ++mockLongitude;
28 internals.setGeolocationPosition(document, mockLatitude, mockLongitude, mockAccuracy);
29 debug('device moved to (' + mockLatitude + ', ' + mockLongitude + ')');
32 updatePosition();
34 var state = 0;
35 var position;
36 var error;
37 var isPageVisible = true;
39 function checkPosition(p) {
40 position = p;
41 shouldBe('position.coords.latitude', '' + mockLatitude);
42 shouldBe('position.coords.longitude', '' + mockLongitude);
43 debug('');
46 function showPageAndUpdatePosition() {
47 shouldBeFalse('isPageVisible');
48 debug('');
49 state++;
50 if (window.testRunner) {
51 debug("*Showing page");
52 testRunner.setPageVisibility("visible");
53 isPageVisible = true;
55 updatePosition();
58 navigator.geolocation.watchPosition(function(p) {
59 debug("Page is notified of the position change");
60 shouldBeTrue('isPageVisible');
61 state++;
62 checkPosition(p);
63 switch(state) {
64 case 2: {
65 if (window.testRunner) {
66 debug("* Hiding page");
67 testRunner.setPageVisibility("hidden");
68 isPageVisible = false;
70 setTimeout(showPageAndUpdatePosition, 100);
71 break;
73 case 4:
74 finishJSTest();
75 return;
77 updatePosition();
78 }, function(e) {
79 testFailed('Error callback invoked unexpectedly');
80 finishJSTest();
81 });
83 </script>
84 </body>
85 </html>