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

Unified Diff: LayoutTests/fast/dom/Geolocation/watchPosition-page-visibility.html

Issue 27368003: Add page visibility observer for Geolocation (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Fix nit Created 7 years, 2 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | LayoutTests/fast/dom/Geolocation/watchPosition-page-visibility-expected.txt » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: LayoutTests/fast/dom/Geolocation/watchPosition-page-visibility.html
diff --git a/LayoutTests/fast/dom/Geolocation/watchPosition-page-visibility.html b/LayoutTests/fast/dom/Geolocation/watchPosition-page-visibility.html
new file mode 100644
index 0000000000000000000000000000000000000000..905e657b181d63092d243d2df79a8d89fa91134f
--- /dev/null
+++ b/LayoutTests/fast/dom/Geolocation/watchPosition-page-visibility.html
@@ -0,0 +1,84 @@
+<!DOCTYPE html>
+<html>
+<head>
+<script src="../../js/resources/js-test-pre.js"></script>
+</head>
+<body>
+<script>
+description("Tests that watchPosition does not report position changes when the page is not visible.");
+window.jsTestIsAsync = true;
+
+var mockLatitude = 51.478;
+var mockLongitude = -0.166;
+var mockAccuracy = 100.0;
+
+debug("* Page is visible");
+
+function updatePosition() {
+ if (!window.testRunner)
+ return;
+ ++mockLatitude;
+ ++mockLongitude;
+ testRunner.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
+ debug('device moved to (' + mockLatitude + ', ' + mockLongitude + ')');
+}
+
+if (window.testRunner) {
+ testRunner.setGeolocationPermission(true);
+ updatePosition();
+} else
+ debug('This test can not be run without the testRunner');
+
+var state = 0;
+var position;
+var error;
+var isPageVisible = true;
+
+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>
+<script src="../../js/resources/js-test-post.js"></script>
+</body>
+</html>
« no previous file with comments | « no previous file | LayoutTests/fast/dom/Geolocation/watchPosition-page-visibility-expected.txt » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698