Add a test for swipe-start hysteresis
authortimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Sep 2015 23:49:09 +0000 (23:49 +0000)
committertimothy_horton@apple.com <timothy_horton@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 3 Sep 2015 23:49:09 +0000 (23:49 +0000)
https://bugs.webkit.org/show_bug.cgi?id=148756

Reviewed by Anders Carlsson.

* swipe/basic-cached-back-swipe.html:
* swipe/pushState-cached-back-swipe.html:
* swipe/resources/swipe-test.js:
(testComplete):
* swipe/swipe-start-hysteresis-failures.html: Added.
* swipe/swipe-start-hysteresis-failures-expected.txt: Added.

* WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::cacheTestRunnerCallback):
(WTR::TestRunner::clearTestRunnerCallbacks):
* WebKitTestRunner/InjectedBundle/TestRunner.h:
Make sure that we log if a client tries to install a callback twice
(since we use .add, the second call would not work).

Also, add clearTestRunnerCallbacks so tests can swap out installed
callbacks.

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

LayoutTests/ChangeLog
LayoutTests/swipe/basic-cached-back-swipe.html
LayoutTests/swipe/pushState-cached-back-swipe.html
LayoutTests/swipe/resources/swipe-test.js
LayoutTests/swipe/swipe-start-hysteresis-failures-expected.txt [new file with mode: 0644]
LayoutTests/swipe/swipe-start-hysteresis-failures.html [new file with mode: 0644]
Tools/ChangeLog
Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl
Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp
Tools/WebKitTestRunner/InjectedBundle/TestRunner.h

index 687b393..29f02d4 100644 (file)
@@ -1,5 +1,19 @@
 2015-09-03  Tim Horton  <timothy_horton@apple.com>
 
+        Add a test for swipe-start hysteresis
+        https://bugs.webkit.org/show_bug.cgi?id=148756
+
+        Reviewed by Anders Carlsson.
+
+        * swipe/basic-cached-back-swipe.html:
+        * swipe/pushState-cached-back-swipe.html:
+        * swipe/resources/swipe-test.js:
+        (testComplete):
+        * swipe/swipe-start-hysteresis-failures.html: Added.
+        * swipe/swipe-start-hysteresis-failures-expected.txt: Added.
+
+2015-09-03  Tim Horton  <timothy_horton@apple.com>
+
         Un-skip swipe tests on Mavericks
 
         * platform/mac-mavericks/TestExpectations:
index aecbab0..b8769ec 100644 (file)
@@ -53,8 +53,7 @@ function didRemoveSwipeSnapshotCallback()
     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();
+    testComplete();
 }
 
 function isFirstPage()
index a6e2665..d525d4c 100644 (file)
@@ -53,8 +53,7 @@ function didRemoveSwipeSnapshotCallback()
     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();
+    testComplete();
 }
 
 function isFirstPage()
index e03a121..767424d 100644 (file)
@@ -52,6 +52,12 @@ function dumpLog()
     window.document.body.innerHTML = window.localStorage["swipeLogging"];
 }
 
+function testComplete()
+{
+    dumpLog();
+    window.testRunner.notifyDone();
+}
+
 function initializeLog()
 {
     window.localStorage["swipeLogging"] = "";
diff --git a/LayoutTests/swipe/swipe-start-hysteresis-failures-expected.txt b/LayoutTests/swipe/swipe-start-hysteresis-failures-expected.txt
new file mode 100644 (file)
index 0000000..02e4f7b
--- /dev/null
@@ -0,0 +1,23 @@
+swipe event (delta 0 0, phase 'maybegin')
+scroll event (delta 1 0, phase 'began')
+scroll event (delta 0 0, phase 'changed')
+scroll event (delta 0 0, phase 'ended')
+swipe event (delta 0 0, phase 'maybegin')
+scroll event (delta 2 2, phase 'began')
+scroll event (delta 0 0, phase 'changed')
+scroll event (delta 0 0, phase 'ended')
+swipe event (delta 0 0, phase 'maybegin')
+scroll event (delta 0 2, phase 'began')
+scroll event (delta 0 0, phase 'changed')
+scroll event (delta 0 0, phase 'ended')
+swipe event (delta 0 0, phase 'maybegin')
+scroll event (delta 1 0, phase 'began')
+scroll event (delta 0 2, phase 'changed')
+scroll event (delta 0 0, phase 'ended')
+swipe event (delta 0 0, phase 'maybegin')
+scroll event (delta 3 1, phase 'began')
+scroll event (delta 0 0, phase 'changed')
+didBeginSwipe
+scroll event (delta 0 0, phase 'ended')
+swipe event (delta 0 0, phase 'ended')
+
diff --git a/LayoutTests/swipe/swipe-start-hysteresis-failures.html b/LayoutTests/swipe/swipe-start-hysteresis-failures.html
new file mode 100644 (file)
index 0000000..6f2df63
--- /dev/null
@@ -0,0 +1,130 @@
+<head>
+<style>
+html {
+    font-size: 32pt;
+}
+</style>
+<script src="resources/swipe-test.js"></script>
+<script>
+function doShortSwipeGesture()
+{
+    eventSender.mouseMoveTo(100, 100);
+
+    // Total delta of 10, 0; should not be enough to start a swipe.
+    eventQueue.enqueueSwipeEvent(0, 0, 'maybegin');
+    eventQueue.enqueueScrollEvent(1, 0, 'began');
+    eventQueue.enqueueScrollEvent(0, 0, 'changed');
+    eventQueue.enqueueScrollEvent(0, 0, 'ended');
+
+    waitForEventDispatch(doDiagonalSwipeGesture);
+}
+
+function doDiagonalSwipeGesture()
+{
+    // Total delta of 20, 20; this is ordinarily sufficient magnitude to start a swipe,
+    // but is too diagonal to start a swipe.
+    eventQueue.enqueueSwipeEvent(0, 0, 'maybegin');
+    eventQueue.enqueueScrollEvent(2, 2, 'began');
+    eventQueue.enqueueScrollEvent(0, 0, 'changed');
+    eventQueue.enqueueScrollEvent(0, 0, 'ended');
+
+    waitForEventDispatch(doVerticalSwipeGesture);
+}
+
+function doVerticalSwipeGesture()
+{
+    // Total delta of 0, 20; this is ordinarily sufficient magnitude to start a swipe,
+    // but is completely vertical, so we won't start a swipe.
+    eventQueue.enqueueSwipeEvent(0, 0, 'maybegin');
+    eventQueue.enqueueScrollEvent(0, 2, 'began');
+    eventQueue.enqueueScrollEvent(0, 0, 'changed');
+    eventQueue.enqueueScrollEvent(0, 0, 'ended');
+
+    waitForEventDispatch(doHorizontalThenVerticalSwipeGesture);
+}
+
+function doHorizontalThenVerticalSwipeGesture()
+{
+    // Total delta of 10, 20; this is ordinarily sufficient magnitude to start a swipe,
+    // but is too vertical, so we won't start a swipe.
+    eventQueue.enqueueSwipeEvent(0, 0, 'maybegin');
+    eventQueue.enqueueScrollEvent(1, 0, 'began');
+    eventQueue.enqueueScrollEvent(0, 2, 'changed');
+    eventQueue.enqueueScrollEvent(0, 0, 'ended');
+
+    waitForEventDispatch(doRegularSwipeGesture);
+}
+
+function doRegularSwipeGesture()
+{
+    // Swap in a different callback that makes sure we *do* reach didBeginSwipe.
+    testRunner.clearTestRunnerCallbacks();
+    testRunner.installDidBeginSwipeCallback(function () {
+        log("didBeginSwipe");
+
+        // Need a swipe-end event to clean up.
+        eventQueue.enqueueSwipeEvent(0, 0, 'ended');
+    });
+
+    testRunner.installDidRemoveSwipeSnapshotCallback(function () {
+        testComplete();
+    });
+
+    // Total delta of 30, 10; this should start a swipe as usual.
+    eventQueue.enqueueSwipeEvent(0, 0, 'maybegin');
+    eventQueue.enqueueScrollEvent(3, 1, 'began');
+    eventQueue.enqueueScrollEvent(0, 0, 'changed');
+    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.");
+}
+
+function isFirstPage()
+{
+    return window.location.href.indexOf("second") == -1;
+}
+
+window.onload = function () {
+    if (!window.eventSender || !window.testRunner) {
+        document.body.innerHTML = "This test must be run in WebKitTestRunner.";
+        return;
+    }
+
+    document.body.innerHTML = isFirstPage() ? "first" : "second";
+
+    if (isFirstPage()) {
+        initializeLog();
+
+        testRunner.setNavigationGesturesEnabled(true);
+
+        testRunner.installDidBeginSwipeCallback(didBeginSwipeNotReachedCallback);
+
+        testRunner.overridePreference("WebKitUsesPageCachePreferenceKey", 1);
+        testRunner.dumpAsText();
+        testRunner.waitUntilDone();
+
+        setTimeout(function () { 
+            window.location.href = window.location.href + "?second";
+        }, 0);
+        return;
+    }
+
+    doShortSwipeGesture();
+};
+</script>
+</head>
+<body>
+</body>
\ No newline at end of file
index 741ba81..a3db6b7 100644 (file)
@@ -1,3 +1,21 @@
+2015-09-03  Tim Horton  <timothy_horton@apple.com>
+
+        Add a test for swipe-start hysteresis
+        https://bugs.webkit.org/show_bug.cgi?id=148756
+
+        Reviewed by Anders Carlsson.
+
+        * WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl:
+        * WebKitTestRunner/InjectedBundle/TestRunner.cpp:
+        (WTR::cacheTestRunnerCallback):
+        (WTR::TestRunner::clearTestRunnerCallbacks):
+        * WebKitTestRunner/InjectedBundle/TestRunner.h:
+        Make sure that we log if a client tries to install a callback twice
+        (since we use .add, the second call would not work).
+
+        Also, add clearTestRunnerCallbacks so tests can swap out installed
+        callbacks.
+
 2015-09-03  Anders Carlsson  <andersca@apple.com>
 
         DumpRenderTree should automatically compute HTTP URLs for HTTP tests
index 75a97d7..7f76993 100644 (file)
@@ -146,6 +146,8 @@ interface TestRunner {
     void removeChromeInputField(object callback);
     void focusWebView(object callback);
 
+    void clearTestRunnerCallbacks();
+
     void setBackingScaleFactor(double backingScaleFactor, object callback);
 
     void setWindowIsKey(boolean isKey);
index cd4791b..46473ef 100644 (file)
@@ -521,6 +521,11 @@ static void cacheTestRunnerCallback(unsigned index, JSValueRef callback)
     if (!callback)
         return;
 
+    if (callbackMap().contains(index)) {
+        InjectedBundle::singleton().outputText(String::format("FAIL: Tried to install a second TestRunner callback for the same event (id %d)\n\n", index));
+        return;
+    }
+
     WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
     JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
     JSValueProtect(context, callback);
@@ -538,6 +543,18 @@ static void callTestRunnerCallback(unsigned index)
     JSValueUnprotect(context, callback);
 }
 
+void TestRunner::clearTestRunnerCallbacks()
+{
+    for (auto& iter : callbackMap()) {
+        WKBundleFrameRef mainFrame = WKBundlePageGetMainFrame(InjectedBundle::singleton().page()->page());
+        JSContextRef context = WKBundleFrameGetJavaScriptContext(mainFrame);
+        JSObjectRef callback = JSValueToObject(context, iter.value, 0);
+        JSValueUnprotect(context, callback);
+    }
+
+    callbackMap().clear();
+}
+
 void TestRunner::addChromeInputField(JSValueRef callback)
 {
     cacheTestRunnerCallback(AddChromeInputFieldCallbackID, callback);
index dd39596..32e6e01 100644 (file)
@@ -296,6 +296,8 @@ public:
     void callDidEndSwipeCallback();
     void callDidRemoveSwipeSnapshotCallback();
 
+    void clearTestRunnerCallbacks();
+
 private:
     TestRunner();