Title: [189321] trunk
Revision
189321
Author
[email protected]
Date
2015-09-03 16:49:09 -0700 (Thu, 03 Sep 2015)

Log Message

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.

* 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.

Modified Paths

Added Paths

Diff

Modified: trunk/LayoutTests/ChangeLog (189320 => 189321)


--- trunk/LayoutTests/ChangeLog	2015-09-03 23:44:51 UTC (rev 189320)
+++ trunk/LayoutTests/ChangeLog	2015-09-03 23:49:09 UTC (rev 189321)
@@ -1,5 +1,19 @@
 2015-09-03  Tim Horton  <[email protected]>
 
+        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  <[email protected]>
+
         Un-skip swipe tests on Mavericks
 
         * platform/mac-mavericks/TestExpectations:

Modified: trunk/LayoutTests/swipe/basic-cached-back-swipe.html (189320 => 189321)


--- trunk/LayoutTests/swipe/basic-cached-back-swipe.html	2015-09-03 23:44:51 UTC (rev 189320)
+++ trunk/LayoutTests/swipe/basic-cached-back-swipe.html	2015-09-03 23:49:09 UTC (rev 189321)
@@ -53,8 +53,7 @@
     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()

Modified: trunk/LayoutTests/swipe/pushState-cached-back-swipe.html (189320 => 189321)


--- trunk/LayoutTests/swipe/pushState-cached-back-swipe.html	2015-09-03 23:44:51 UTC (rev 189320)
+++ trunk/LayoutTests/swipe/pushState-cached-back-swipe.html	2015-09-03 23:49:09 UTC (rev 189321)
@@ -53,8 +53,7 @@
     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()

Modified: trunk/LayoutTests/swipe/resources/swipe-test.js (189320 => 189321)


--- trunk/LayoutTests/swipe/resources/swipe-test.js	2015-09-03 23:44:51 UTC (rev 189320)
+++ trunk/LayoutTests/swipe/resources/swipe-test.js	2015-09-03 23:49:09 UTC (rev 189321)
@@ -52,6 +52,12 @@
     window.document.body.innerHTML = window.localStorage["swipeLogging"];
 }
 
+function testComplete()
+{
+    dumpLog();
+    window.testRunner.notifyDone();
+}
+
 function initializeLog()
 {
     window.localStorage["swipeLogging"] = "";

Added: trunk/LayoutTests/swipe/swipe-start-hysteresis-failures-expected.txt (0 => 189321)


--- trunk/LayoutTests/swipe/swipe-start-hysteresis-failures-expected.txt	                        (rev 0)
+++ trunk/LayoutTests/swipe/swipe-start-hysteresis-failures-expected.txt	2015-09-03 23:49:09 UTC (rev 189321)
@@ -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')
+

Added: trunk/LayoutTests/swipe/swipe-start-hysteresis-failures.html (0 => 189321)


--- trunk/LayoutTests/swipe/swipe-start-hysteresis-failures.html	                        (rev 0)
+++ trunk/LayoutTests/swipe/swipe-start-hysteresis-failures.html	2015-09-03 23:49:09 UTC (rev 189321)
@@ -0,0 +1,130 @@
+<head>
+<style>
+html {
+    font-size: 32pt;
+}
+</style>
+<script src=""
+<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 = "" + "?second";
+        }, 0);
+        return;
+    }
+
+    doShortSwipeGesture();
+};
+</script>
+</head>
+<body>
+</body>
\ No newline at end of file

Modified: trunk/Tools/ChangeLog (189320 => 189321)


--- trunk/Tools/ChangeLog	2015-09-03 23:44:51 UTC (rev 189320)
+++ trunk/Tools/ChangeLog	2015-09-03 23:49:09 UTC (rev 189321)
@@ -1,3 +1,21 @@
+2015-09-03  Tim Horton  <[email protected]>
+
+        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  <[email protected]>
 
         DumpRenderTree should automatically compute HTTP URLs for HTTP tests

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl (189320 => 189321)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2015-09-03 23:44:51 UTC (rev 189320)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/Bindings/TestRunner.idl	2015-09-03 23:49:09 UTC (rev 189321)
@@ -146,6 +146,8 @@
     void removeChromeInputField(object callback);
     void focusWebView(object callback);
 
+    void clearTestRunnerCallbacks();
+
     void setBackingScaleFactor(double backingScaleFactor, object callback);
 
     void setWindowIsKey(boolean isKey);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp (189320 => 189321)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2015-09-03 23:44:51 UTC (rev 189320)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.cpp	2015-09-03 23:49:09 UTC (rev 189321)
@@ -521,6 +521,11 @@
     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 @@
     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);

Modified: trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h (189320 => 189321)


--- trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2015-09-03 23:44:51 UTC (rev 189320)
+++ trunk/Tools/WebKitTestRunner/InjectedBundle/TestRunner.h	2015-09-03 23:49:09 UTC (rev 189321)
@@ -296,6 +296,8 @@
     void callDidEndSwipeCallback();
     void callDidRemoveSwipeSnapshotCallback();
 
+    void clearTestRunnerCallbacks();
+
 private:
     TestRunner();
 
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to