Add a test for r179736 (programmatic navigation during swipe causing a crash)
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Sep 2015 22:09:57 +0000 (22:09 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Fri, 4 Sep 2015 22:09:57 +0000 (22:09 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148830

Reviewed by Beth Dakin.

* swipe/basic-cached-back-swipe.html:
* swipe/pushState-cached-back-swipe.html:
* swipe/resources/swipe-test.js:
(eventQueue.callAfterEventDispatch):
(initializeSwipeTest):
(initializeLog): Deleted.
* swipe/swipe-start-hysteresis-failures.html:
Refactor some things.
Make sure that we reset the back forward list before testing, because we expect
to start at the "first" item, but there is actually a about:blank before us.

* swipe/pushState-programmatic-back-while-swiping-crash-expected.txt: Added.
* swipe/pushState-programmatic-back-while-swiping-crash.html: Added.
Add a test that ensures that r179736 does not recur.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::beginTesting):
Make sure that TestRunner callbacks don't leak between tests!

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

LayoutTests/ChangeLog
LayoutTests/swipe/basic-cached-back-swipe.html
LayoutTests/swipe/pushState-cached-back-swipe.html
LayoutTests/swipe/pushState-programmatic-back-while-swiping-crash-expected.txt [new file with mode: 0644]
LayoutTests/swipe/pushState-programmatic-back-while-swiping-crash.html [new file with mode: 0644]
LayoutTests/swipe/resources/swipe-test.js
LayoutTests/swipe/swipe-start-hysteresis-failures.html
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/InjectedBundle.cpp

index f91a321..04da590 100644 (file)
@@ -1,3 +1,25 @@
+2015-09-04  Tim Horton  <timothy_horton@apple.com>
+
+        Add a test for r179736 (programmatic navigation during swipe causing a crash)
+        https://bugs.webkit.org/show_bug.cgi?id=148830
+
+        Reviewed by Beth Dakin.
+
+        * swipe/basic-cached-back-swipe.html:
+        * swipe/pushState-cached-back-swipe.html:
+        * swipe/resources/swipe-test.js:
+        (eventQueue.callAfterEventDispatch):
+        (initializeSwipeTest):
+        (initializeLog): Deleted.
+        * swipe/swipe-start-hysteresis-failures.html:
+        Refactor some things.
+        Make sure that we reset the back forward list before testing, because we expect
+        to start at the "first" item, but there is actually a about:blank before us.
+
+        * swipe/pushState-programmatic-back-while-swiping-crash-expected.txt: Added.
+        * swipe/pushState-programmatic-back-while-swiping-crash.html: Added.
+        Add a test that ensures that r179736 does not recur.
+
 2015-09-04  Beth Dakin  <bdakin@apple.com>
 
         Should have a test for selection behavior when force clicking text
index b8769ec..cf7f75c 100644 (file)
@@ -70,9 +70,7 @@ window.onload = function () {
     document.body.innerHTML = isFirstPage() ? "first" : "second";
 
     if (isFirstPage()) {
-        initializeLog();
-
-        testRunner.setNavigationGesturesEnabled(true);
+        initializeSwipeTest();
 
         testRunner.installDidBeginSwipeCallback(didBeginSwipeCallback);
         testRunner.installWillEndSwipeCallback(willEndSwipeCallback);
index d525d4c..56dada4 100644 (file)
@@ -74,9 +74,7 @@ window.onload = function () {
 
     updateContent();
 
-    initializeLog();
-
-    testRunner.setNavigationGesturesEnabled(true);
+    initializeSwipeTest();
 
     testRunner.installDidBeginSwipeCallback(didBeginSwipeCallback);
     testRunner.installWillEndSwipeCallback(willEndSwipeCallback);
diff --git a/LayoutTests/swipe/pushState-programmatic-back-while-swiping-crash-expected.txt b/LayoutTests/swipe/pushState-programmatic-back-while-swiping-crash-expected.txt
new file mode 100644 (file)
index 0000000..dc34e92
--- /dev/null
@@ -0,0 +1,7 @@
+swipe event (delta 0 0, phase 'maybegin')
+scroll event (delta 1 0, phase 'began')
+scroll event (delta 1 0, phase 'changed')
+swipe event (delta 1 0, phase 'changed')
+swipe event (delta 256 0, phase 'changed')
+swipe event (delta 0 0, phase 'ended')
+
diff --git a/LayoutTests/swipe/pushState-programmatic-back-while-swiping-crash.html b/LayoutTests/swipe/pushState-programmatic-back-while-swiping-crash.html
new file mode 100644 (file)
index 0000000..36ef39f
--- /dev/null
@@ -0,0 +1,89 @@
+<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.callAfterEventDispatch(goBack);
+}
+
+function goBack()
+{
+    window.history.back();
+
+    eventQueue.callAfterEventDispatch(continueSwipeGesture);
+}
+
+function continueSwipeGesture()
+{
+    eventQueue.enqueueScrollEvent(1, 0, 'changed');
+
+    eventQueue.callAfterEventDispatch(completeSwipeGesture);
+}
+
+function completeSwipeGesture()
+{
+    eventQueue.enqueueSwipeEvent(1, 0, 'changed');
+    eventQueue.enqueueSwipeEvent(256, 0, 'changed');
+    eventQueue.enqueueSwipeEvent(0, 0, 'ended');
+
+    eventQueue.callAfterEventDispatch(testComplete);
+}
+
+function didBeginSwipeCallback()
+{
+    log("Failed. Should not begin swipe; we've already navigated away from the item where the swipe started, and there is no other back item.");
+}
+
+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();
+
+    initializeSwipeTest();
+
+    testRunner.installDidBeginSwipeCallback(didBeginSwipeCallback);
+
+    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
index 767424d..0838671 100644 (file)
@@ -19,6 +19,15 @@ var eventQueue = {
         return this._queue.length != 0;
     },
 
+    callAfterEventDispatch: function (callback) {
+        var interval = setInterval(function () { 
+        if (!eventQueue.hasPendingEvents()) {
+            clearInterval(interval);
+            callback();
+        }
+    }, 0);
+    },
+
     _queue: [],
 
     _processEventQueue: function () {
@@ -58,9 +67,11 @@ function testComplete()
     window.testRunner.notifyDone();
 }
 
-function initializeLog()
+function initializeSwipeTest()
 {
     window.localStorage["swipeLogging"] = "";
+    testRunner.setNavigationGesturesEnabled(true);
+    testRunner.clearBackForwardList();
 }
 
 function startMeasuringDuration(key)
index 65817d3..e75e67b 100644 (file)
@@ -16,7 +16,7 @@ function doShortSwipeGesture()
     eventQueue.enqueueScrollEvent(0, 0, 'changed');
     eventQueue.enqueueScrollEvent(0, 0, 'ended');
 
-    waitForEventDispatch(doDiagonalSwipeGesture);
+    eventQueue.callAfterEventDispatch(doDiagonalSwipeGesture);
 }
 
 function doDiagonalSwipeGesture()
@@ -28,7 +28,7 @@ function doDiagonalSwipeGesture()
     eventQueue.enqueueScrollEvent(0, 0, 'changed');
     eventQueue.enqueueScrollEvent(0, 0, 'ended');
 
-    waitForEventDispatch(doVerticalSwipeGesture);
+    eventQueue.callAfterEventDispatch(doVerticalSwipeGesture);
 }
 
 function doVerticalSwipeGesture()
@@ -40,7 +40,7 @@ function doVerticalSwipeGesture()
     eventQueue.enqueueScrollEvent(0, 0, 'changed');
     eventQueue.enqueueScrollEvent(0, 0, 'ended');
 
-    waitForEventDispatch(doHorizontalThenVerticalSwipeGesture);
+    eventQueue.callAfterEventDispatch(doHorizontalThenVerticalSwipeGesture);
 }
 
 function doHorizontalThenVerticalSwipeGesture()
@@ -52,7 +52,7 @@ function doHorizontalThenVerticalSwipeGesture()
     eventQueue.enqueueScrollEvent(0, 2, 'changed');
     eventQueue.enqueueScrollEvent(0, 0, 'ended');
 
-    waitForEventDispatch(doRegularSwipeGesture);
+    eventQueue.callAfterEventDispatch(doRegularSwipeGesture);
 }
 
 function doRegularSwipeGesture()
@@ -78,16 +78,6 @@ function doRegularSwipeGesture()
     eventQueue.enqueueScrollEvent(0, 0, 'ended');
 }
 
-function waitForEventDispatch(callback)
-{
-    var interval = setInterval(function () { 
-        if (!eventQueue.hasPendingEvents()) {
-            clearInterval(interval);
-            callback();
-        }
-    }, 0);
-}
-
 function didBeginSwipeNotReachedCallback()
 {
     log("Failure. Should never begin a swipe, because all of the attempted swipes should fail due to the swipe-start hysteresis.");
@@ -107,9 +97,7 @@ window.onload = function () {
     document.body.innerHTML = isFirstPage() ? "first" : "second";
 
     if (isFirstPage()) {
-        initializeLog();
-
-        testRunner.setNavigationGesturesEnabled(true);
+        initializeSwipeTest();
 
         testRunner.installDidBeginSwipeCallback(didBeginSwipeNotReachedCallback);
 
index db6c73c..ff9982a 100644 (file)
@@ -1,3 +1,14 @@
+2015-09-04  Tim Horton  <timothy_horton@apple.com>
+
+        Add a test for r179736 (programmatic navigation during swipe causing a crash)
+        https://bugs.webkit.org/show_bug.cgi?id=148830
+
+        Reviewed by Beth Dakin.
+
+        * WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
+        (WTR::InjectedBundle::beginTesting):
+        Make sure that TestRunner callbacks don't leak between tests!
+
 2015-09-04  Anders Carlsson  <andersca@apple.com>
 
         It should be possible to pass relative HTTP test paths to DumpRenderTree
index 5be6bf9..7dd22c5 100644 (file)
@@ -289,6 +289,7 @@ void InjectedBundle::beginTesting(WKDictionaryRef settings)
     m_testRunner->setCloseRemainingWindowsWhenComplete(false);
     m_testRunner->setAcceptsEditing(true);
     m_testRunner->setTabKeyCyclesThroughElements(true);
+    m_testRunner->clearTestRunnerCallbacks();
 
     if (m_timeout > 0)
         m_testRunner->setCustomTimeout(m_timeout);