Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1)

Side by Side Diff: third_party/WebKit/LayoutTests/fast/dom/Geolocation/watchPosition-page-visibility.html

Issue 2671933003: Move Geolocation out from fast/dom. (Closed)
Patch Set: . Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <html>
3 <head>
4 <script src="../../../resources/js-test.js"></script>
5 <script src="../../../resources/mojo-helpers.js"></script>
6 <script src="resources/geolocation-mock.js"></script>
7 </head>
8 <body>
9 <script>
10 description("Tests that watchPosition does not report position changes when the page is not visible.");
11 window.jsTestIsAsync = true;
12
13 if (!window.testRunner)
14 debug('This test can not run without testRunner');
15
16 var position;
17 var error;
18 var isPageVisible = true;
19
20 geolocationServiceMock.then(mock => {
21 mock.setGeolocationPermission(true);
22
23 debug("* Page is visible");
24
25 var mockLatitude = 51.478;
26 var mockLongitude = -0.166;
27 var mockAccuracy = 100.0;
28
29 function updatePosition() {
30 if (!window.testRunner)
31 return;
32 ++mockLatitude;
33 ++mockLongitude;
34 mock.setGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
35 debug('device moved to (' + mockLatitude + ', ' + mockLongitude + ')');
36 }
37
38 updatePosition();
39
40 var state = 0;
41
42 function checkPosition(p) {
43 position = p;
44 shouldBe('position.coords.latitude', '' + mockLatitude);
45 shouldBe('position.coords.longitude', '' + mockLongitude);
46 debug('');
47 }
48
49 function showPageAndUpdatePosition() {
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;
75 }
76 case 4:
77 finishJSTest();
78 return;
79 }
80 updatePosition();
81 }, function(e) {
82 testFailed('Error callback invoked unexpectedly');
83 finishJSTest();
84 });
85 });
86
87 </script>
88 </body>
89 </html>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698