Title: [188204] trunk
Revision
188204
Author
[email protected]
Date
2015-08-09 21:14:04 -0700 (Sun, 09 Aug 2015)

Log Message

Page cache doesn't work for pages actively using Geolocation
https://bugs.webkit.org/show_bug.cgi?id=147785
<rdar://problem/11147901>

Reviewed by Darin Adler.

Source/WebCore:

Allow pages actively using Geolocation into the PageCache.

Tests: fast/history/page-cache-geolocation-active-oneshot.html
       fast/history/page-cache-geolocation-active-watcher.html

* Modules/geolocation/Geolocation.cpp:
(WebCore::Geolocation::canSuspendForPageCache):
(WebCore::Geolocation::suspend): Deleted.
* history/PageCache.cpp:

LayoutTests:

Add layout test coverage for page caching of pages actively using
the Geolocation API.

* fast/history/page-cache-geolocation-active-oneshot-expected.txt: Added.
* fast/history/page-cache-geolocation-active-oneshot.html: Added.
* fast/history/page-cache-geolocation-active-watcher-expected.txt: Added.
* fast/history/page-cache-geolocation-active-watcher.html: Added.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (188203 => 188204)


--- trunk/LayoutTests/ChangeLog	2015-08-10 01:53:10 UTC (rev 188203)
+++ trunk/LayoutTests/ChangeLog	2015-08-10 04:14:04 UTC (rev 188204)
@@ -1,3 +1,19 @@
+2015-08-09  Chris Dumez  <[email protected]>
+
+        Page cache doesn't work for pages actively using Geolocation
+        https://bugs.webkit.org/show_bug.cgi?id=147785
+        <rdar://problem/11147901>
+
+        Reviewed by Darin Adler.
+
+        Add layout test coverage for page caching of pages actively using
+        the Geolocation API.
+
+        * fast/history/page-cache-geolocation-active-oneshot-expected.txt: Added.
+        * fast/history/page-cache-geolocation-active-oneshot.html: Added.
+        * fast/history/page-cache-geolocation-active-watcher-expected.txt: Added.
+        * fast/history/page-cache-geolocation-active-watcher.html: Added.
+
 2015-08-09  Nan Wang  <[email protected]>
 
         AX: CSS table display styles can cause malformed, inaccessible AXTables to be exposed to the AX tree

Added: trunk/LayoutTests/fast/history/page-cache-geolocation-active-oneshot-expected.txt (0 => 188204)


--- trunk/LayoutTests/fast/history/page-cache-geolocation-active-oneshot-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/history/page-cache-geolocation-active-oneshot-expected.txt	2015-08-10 04:14:04 UTC (rev 188204)
@@ -0,0 +1,21 @@
+Tests that a page actively using geolocation can go into the page cache.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+pageshow - not from cache
+pagehide - entering cache
+pageshow - from cache
+PASS Page did enter and was restored from the page cache
+PASS testRunner.isGeolocationProviderActive() is false
+Watcher callback called
+PASS testRunner.isGeolocationProviderActive() is true
+PASS stage is "after_restore"
+PASS position.coords.latitude is mockLatitude
+PASS position.coords.longitude is mockLongitude
+PASS position.coords.accuracy is mockAccuracy
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/history/page-cache-geolocation-active-oneshot.html (0 => 188204)


--- trunk/LayoutTests/fast/history/page-cache-geolocation-active-oneshot.html	                        (rev 0)
+++ trunk/LayoutTests/fast/history/page-cache-geolocation-active-oneshot.html	2015-08-10 04:14:04 UTC (rev 188204)
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description('Tests that a page actively using geolocation can go into the page cache.');
+window.jsTestIsAsync = true;
+
+var mockLatitude = 51.478;
+var mockLongitude = -0.166;
+var mockAccuracy = 100.0;
+
+var stage = "before_restore";
+
+if (window.testRunner) {
+    testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
+    testRunner.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
+}
+
+window.addEventListener("pageshow", function(event) {
+    debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
+    if (event.persisted) {
+        stage = "after_restore";
+        testPassed("Page did enter and was restored from the page cache");
+
+        // Going into PageCache should have disabled GPS so the GeolocationProvider should be
+        // temporarily inactive when restoring.
+        shouldBeFalse("testRunner.isGeolocationProviderActive()");
+    }
+}, false);
+
+window.addEventListener("pagehide", function(event) {
+    debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
+    if (!event.persisted) {
+        testFailed("Page did not enter the page cache.");
+        finishJSTest();
+    } else {
+        stage = "in_page_cache";
+
+        // Give permission right before entering the PageCache to make sure that:
+        // 1. The geolocation callback is NOT called while in the page cache.
+        // 2. The geolocation callback DOES get called after restoring from the page cache.
+        testRunner.setGeolocationPermission(true);
+    }
+}, false);
+
+function checkPosition(p) {
+    position = p;
+    shouldBe('position.coords.latitude', 'mockLatitude');
+    shouldBe('position.coords.longitude', 'mockLongitude');
+    shouldBe('position.coords.accuracy', 'mockAccuracy');
+    debug('');
+}
+
+function geolocationCallback(position)
+{
+    debug("Watcher callback called");
+    shouldBeTrue("testRunner.isGeolocationProviderActive()");
+    shouldBeEqualToString('stage', 'after_restore');
+    checkPosition(position);
+    finishJSTest();
+}
+
+window.addEventListener('load', function() {
+    setTimeout(function() {
+      // Force a back navigation back to this page.
+      window.location.href = ""
+    }, 0);
+
+    setTimeout(function() {
+          navigator.geolocation.getCurrentPosition(geolocationCallback, function(e) {
+          testFailed('Error callback invoked unexpectedly');
+          finishJSTest();
+      });
+    }, 0);
+}, false);
+</script>
+<script src=""
+</body>
+</html>

Added: trunk/LayoutTests/fast/history/page-cache-geolocation-active-watcher-expected.txt (0 => 188204)


--- trunk/LayoutTests/fast/history/page-cache-geolocation-active-watcher-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/fast/history/page-cache-geolocation-active-watcher-expected.txt	2015-08-10 04:14:04 UTC (rev 188204)
@@ -0,0 +1,28 @@
+Tests that a page actively using geolocation can go into the page cache.
+
+On success, you will see a series of "PASS" messages, followed by "TEST COMPLETE".
+
+
+pageshow - not from cache
+Watcher callback called
+PASS testRunner.isGeolocationProviderActive() is true
+PASS stage == 'in_page_cache' is false
+PASS position.coords.latitude is mockLatitude
+PASS position.coords.longitude is mockLongitude
+PASS position.coords.accuracy is mockAccuracy
+
+pagehide - entering cache
+pageshow - from cache
+PASS Page did enter and was restored from the page cache
+PASS testRunner.isGeolocationProviderActive() is false
+Watcher callback called
+PASS testRunner.isGeolocationProviderActive() is true
+PASS stage == 'in_page_cache' is false
+PASS position.coords.latitude is mockLatitude
+PASS position.coords.longitude is mockLongitude
+PASS position.coords.accuracy is mockAccuracy
+
+PASS successfullyParsed is true
+
+TEST COMPLETE
+

Added: trunk/LayoutTests/fast/history/page-cache-geolocation-active-watcher.html (0 => 188204)


--- trunk/LayoutTests/fast/history/page-cache-geolocation-active-watcher.html	                        (rev 0)
+++ trunk/LayoutTests/fast/history/page-cache-geolocation-active-watcher.html	2015-08-10 04:14:04 UTC (rev 188204)
@@ -0,0 +1,80 @@
+<!DOCTYPE html>
+<html>
+<body>
+<script src=""
+<script>
+description('Tests that a page actively using geolocation can go into the page cache.');
+window.jsTestIsAsync = true;
+
+var mockLatitude = 51.478;
+var mockLongitude = -0.166;
+var mockAccuracy = 100.0;
+
+var stage = "before_restore";
+
+if (window.testRunner) {
+    testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
+    testRunner.setGeolocationPermission(true);
+    testRunner.setMockGeolocationPosition(mockLatitude, mockLongitude, mockAccuracy);
+}
+
+window.addEventListener("pageshow", function(event) {
+    debug("pageshow - " + (event.persisted ? "" : "not ") + "from cache");
+    if (event.persisted) {
+        stage = "after_restore";
+        testPassed("Page did enter and was restored from the page cache");
+
+        // Going into PageCache should have disabled GPS so the GeolocationProvider should be
+        // temporarily inactive when restoring.
+        shouldBeFalse("testRunner.isGeolocationProviderActive()");
+    }
+}, false);
+
+window.addEventListener("pagehide", function(event) {
+    debug("pagehide - " + (event.persisted ? "" : "not ") + "entering cache");
+    if (!event.persisted) {
+        testFailed("Page did not enter the page cache.");
+        finishJSTest();
+    } else {
+        // Update the position right before going into PageCache to make sure that:
+        // 1. The watcher callback is NOT called while in the PageCache.
+        // 2. The watcher callback DOES get called when restoring from the PageCache.
+        testRunner.setMockGeolocationPosition(++mockLatitude, ++mockLongitude, ++mockAccuracy);
+
+        stage = "in_page_cache";
+    }
+}, false);
+
+function checkPosition(p) {
+    position = p;
+    shouldBe('position.coords.latitude', 'mockLatitude');
+    shouldBe('position.coords.longitude', 'mockLongitude');
+    shouldBe('position.coords.accuracy', 'mockAccuracy');
+    debug('');
+}
+
+function geolocationWatchFunction(position)
+{
+    debug("Watcher callback called");
+    shouldBeTrue("testRunner.isGeolocationProviderActive()");
+    shouldBeFalse("stage == 'in_page_cache'");
+    checkPosition(position);
+
+    if (stage == "before_restore") {
+      // Force a back navigation back to this page.
+      window.location.href = ""
+    } else {
+        finishJSTest();
+    }
+}
+
+window.addEventListener('load', function() {
+    navigator.geolocation.watchPosition(geolocationWatchFunction, function(e) {
+        testFailed('Error callback invoked unexpectedly');
+        finishJSTest();
+    });
+}, false);
+</script>
+<script src=""
+</body>
+</html>

Modified: trunk/Source/WebCore/ChangeLog (188203 => 188204)


--- trunk/Source/WebCore/ChangeLog	2015-08-10 01:53:10 UTC (rev 188203)
+++ trunk/Source/WebCore/ChangeLog	2015-08-10 04:14:04 UTC (rev 188204)
@@ -1,3 +1,21 @@
+2015-08-09  Chris Dumez  <[email protected]>
+
+        Page cache doesn't work for pages actively using Geolocation
+        https://bugs.webkit.org/show_bug.cgi?id=147785
+        <rdar://problem/11147901>
+
+        Reviewed by Darin Adler.
+
+        Allow pages actively using Geolocation into the PageCache.
+
+        Tests: fast/history/page-cache-geolocation-active-oneshot.html
+               fast/history/page-cache-geolocation-active-watcher.html
+
+        * Modules/geolocation/Geolocation.cpp:
+        (WebCore::Geolocation::canSuspendForPageCache):
+        (WebCore::Geolocation::suspend): Deleted.
+        * history/PageCache.cpp:
+
 2015-08-09  Nan Wang  <[email protected]>
 
         AX: CSS table display styles can cause malformed, inaccessible AXTables to be exposed to the AX tree

Modified: trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp (188203 => 188204)


--- trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp	2015-08-10 01:53:10 UTC (rev 188203)
+++ trunk/Source/WebCore/Modules/geolocation/Geolocation.cpp	2015-08-10 04:14:04 UTC (rev 188204)
@@ -164,15 +164,12 @@
 
 bool Geolocation::canSuspendForPageCache() const
 {
-    return !hasListeners();
+    return true;
 }
 
 void Geolocation::suspend(ReasonForSuspension reason)
 {
-    // Allow pages that no longer have listeners to enter the page cache.
-    // Have them stop updating and reset geolocation permissions when the page is resumed.
     if (reason == ActiveDOMObject::PageCache) {
-        ASSERT(!hasListeners());
         stop();
         m_resetOnResume = true;
     }
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to