Add a test for swiping back after a same-document navigation
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Sep 2015 21:51:41 +0000 (21:51 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Sep 2015 21:51:41 +0000 (21:51 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148751

Reviewed by Beth Dakin.

* swipe/pushState-cached-back-swipe.html: Added.

git-svn-id: https://svn.webkit.org/repository/webkit/trunk@189290 268f45cc-cd09-0410-ab3c-d52691b4dbfc

LayoutTests/ChangeLog
LayoutTests/swipe/pushState-cached-back-swipe-expected.txt [new file with mode: 0644]
LayoutTests/swipe/pushState-cached-back-swipe.html [new file with mode: 0644]

index 199dfaa..d043d55 100644 (file)
@@ -1,3 +1,12 @@
+2015-09-03  Tim Horton  <timothy_horton@apple.com>
+
+        Add a test for swiping back after a same-document navigation
+        https://bugs.webkit.org/show_bug.cgi?id=148751
+
+        Reviewed by Beth Dakin.
+
+        * swipe/pushState-cached-back-swipe.html: Added.
+
 2015-09-03  Andy Estes  <aestes@apple.com>
 
         REGRESSION: http/tests/contentfiltering/block-after-redirect.html is flaky
diff --git a/LayoutTests/swipe/pushState-cached-back-swipe-expected.txt b/LayoutTests/swipe/pushState-cached-back-swipe-expected.txt
new file mode 100644 (file)
index 0000000..e3d3e00
--- /dev/null
@@ -0,0 +1,11 @@
+swipe event (delta 0 0, phase 'maybegin')
+scroll event (delta 1 0, phase 'began')
+scroll event (delta 1 0, phase 'changed')
+didBeginSwipe
+swipe event (delta 1 0, phase 'changed')
+swipe event (delta 256 0, phase 'changed')
+swipe event (delta 0 0, phase 'ended')
+willEndSwipe
+didEndSwipe
+didRemoveSwipeSnapshot
+
diff --git a/LayoutTests/swipe/pushState-cached-back-swipe.html b/LayoutTests/swipe/pushState-cached-back-swipe.html
new file mode 100644 (file)
index 0000000..a6e2665
--- /dev/null
@@ -0,0 +1,107 @@
+<head>
+<style>
+html {
+    font-size: 32pt;
+}
+</style>
+<script src="resources/swipe-test.js"></script>
+<script>
+function startSwipeGesture()
+{
+    eventSender.mouseMoveTo(100, 100);
+
+    eventQueue.enqueueSwipeEvent(0, 0, 'maybegin');
+    eventQueue.enqueueScrollEvent(1, 0, 'began');
+    eventQueue.enqueueScrollEvent(1, 0, 'changed');
+}
+
+function completeSwipeGesture()
+{
+    eventQueue.enqueueSwipeEvent(1, 0, 'changed');
+    eventQueue.enqueueSwipeEvent(256, 0, 'changed');
+    eventQueue.enqueueSwipeEvent(0, 0, 'ended');
+}
+
+function didBeginSwipeCallback()
+{
+    log("didBeginSwipe");
+
+    shouldBe(false, eventQueue.hasPendingEvents(), "Event queue should be empty. Both scroll events should be required to start the swipe because of the swipe-start hysteresis.");
+
+    completeSwipeGesture();
+}
+
+function willEndSwipeCallback()
+{
+    log("willEndSwipe");
+
+    shouldBe(false, isFirstPage(), "The swipe should not yet have navigated away from the second page.");
+}
+
+function didEndSwipeCallback()
+{
+    log("didEndSwipe");
+
+    shouldBe(0, eventQueue.hasPendingEvents(), "Event queue should be empty. The swipe isn't complete until we see the end of the gesture.");
+    startMeasuringDuration("snapshotRemoval");
+}
+
+function didRemoveSwipeSnapshotCallback()
+{
+    log("didRemoveSwipeSnapshot");
+    
+    shouldBe(true, isFirstPage(), "The swipe should have navigated back to the first page.");
+    measuredDurationShouldBeLessThan("snapshotRemoval", 1000, "Because we're using the page cache, it shouldn't be long between the gesture completing and the snapshot being removed.")
+
+    dumpLog();
+    testRunner.notifyDone();
+}
+
+function isFirstPage()
+{
+    return window.location.href.indexOf("second") == -1;
+}
+
+function updateContent()
+{
+    document.body.innerHTML = isFirstPage() ? "first" : "second";
+}
+
+window.onload = function () {
+    if (!window.eventSender || !window.testRunner) {
+        document.body.innerHTML = "This test must be run in WebKitTestRunner.";
+        return;
+    }
+
+    updateContent();
+
+    initializeLog();
+
+    testRunner.setNavigationGesturesEnabled(true);
+
+    testRunner.installDidBeginSwipeCallback(didBeginSwipeCallback);
+    testRunner.installWillEndSwipeCallback(willEndSwipeCallback);
+    testRunner.installDidEndSwipeCallback(didEndSwipeCallback);
+    testRunner.installDidRemoveSwipeSnapshotCallback(didRemoveSwipeSnapshotCallback);
+
+    testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
+    testRunner.dumpAsText();
+    testRunner.waitUntilDone();
+
+    window.addEventListener("popstate", function(e) {
+        updateContent();
+    });
+
+    setTimeout(function () { 
+        history.pushState(null, null, "/second");
+        updateContent();
+
+        setTimeout(function () {
+            startSwipeGesture();
+        }, 0);
+    }, 0);
+};
+</script>
+</head>
+<body>
+</body>
\ No newline at end of file