Improve how UI events are dispatched by WebKitTestRunner
https://bugs.webkit.org/show_bug.cgi?id=148326

Reviewed by Anders Carlsson.

Source/WebKit2:

Added "fully synchronous mode for testing", in which all messages are dispatched
synchronously.

When an async message is sent in this mode, it is wrapped into a sync one automatically.

A client must opt in, either by using WKBundlePagePostSynchronousMessageForTesting(),
or by calling WKContextConfigurationAllowFullySynchronousModeForTesting().
This makes sure that we don't increase potential for IPC misuse.

* WebProcess/WebPage/WebPage.messages.in: Yay, fewer messages!

* UIProcess/API/C/WKPage.cpp:
(WKPageSetShouldSendEventsSynchronously): Deleted.
* UIProcess/API/C/WKPagePrivate.h:
We no longer need WKPageSetShouldSendEventsSynchronously and associated custom messages.

* WebProcess/WebPage/EventDispatcher.cpp:
(WebKit::EventDispatcher::wheelEvent):
(WebKit::updateWheelEventTestTriggersIfNeeded): Deleted.
Removed code that was only needed to support pseudo-syncronous scrolling in tests.

* Platform/IPC/Connection.cpp:
(IPC::Connection::sendMessage):
(IPC::Connection::dispatchSyncMessage):
(IPC::Connection::dispatchMessage):
* Platform/IPC/Connection.h:
(IPC::Connection::allowFullySynchronousModeForTesting):
(IPC::Connection::sendSync):
* Platform/IPC/MessageDecoder.cpp:
(IPC::MessageDecoder::shouldDispatchMessageWhenWaitingForSyncReply):
(IPC::MessageDecoder::shouldUseFullySynchronousModeForTesting):
(IPC::MessageDecoder::setImportanceAssertion):
(IPC::MessageDecoder::unwrapForTesting):
* Platform/IPC/MessageDecoder.h:
(IPC::MessageDecoder::UUID):
* Platform/IPC/MessageEncoder.cpp:
(IPC::MessageEncoder::setShouldDispatchMessageWhenWaitingForSyncReply):
(IPC::MessageEncoder::setFullySynchronousModeForTesting):
(IPC::MessageEncoder::wrapForTesting):
* Platform/IPC/MessageEncoder.h:
(IPC::MessageEncoder::UUID):
* Platform/IPC/MessageFlags.h:
* UIProcess/API/APIProcessPoolConfiguration.cpp:
(API::ProcessPoolConfiguration::copy):
* UIProcess/API/APIProcessPoolConfiguration.h:
* UIProcess/API/C/WKContextConfigurationRef.cpp:
(WKContextConfigurationSetMediaKeysStorageDirectory):
(WKContextConfigurationAllowFullySynchronousModeForTesting):
* UIProcess/API/C/WKContextConfigurationRef.h:

* UIProcess/WebPageProxy.cpp:
(WebKit::WebPageProxy::WebPageProxy):
(WebKit::WebPageProxy::handleMouseEvent):
(WebKit::WebPageProxy::sendWheelEvent):
(WebKit::WebPageProxy::handleKeyboardEvent):
(WebKit::WebPageProxy::handleTouchEvent):
* UIProcess/WebPageProxy.h:
(WebKit::WebPageProxy::renderTreeSize):
(WebKit::WebPageProxy::setShouldSendEventsSynchronously): Deleted.
* UIProcess/WebProcessPool.cpp:
(WebKit::WebProcessPool::processDidFinishLaunching):
* WebProcess/InjectedBundle/API/c/WKBundlePage.cpp:
(WKBundlePagePostMessage):
(WKBundlePagePostSynchronousMessageForTesting):
(WKBundlePagePostSynchronousMessage): Deleted.
* WebProcess/InjectedBundle/API/c/WKBundlePage.h:
* WebProcess/WebPage/WebPage.cpp:
(WebKit::WebPage::mouseEvent):
(WebKit::handleWheelEvent):
(WebKit::WebPage::wheelEvent):
(WebKit::handleKeyEvent):
(WebKit::WebPage::keyEvent):
(WebKit::WebPage::validateCommand):
(WebKit::WebPage::touchEvent):
(WebKit::WebPage::scroll):
(WebKit::WebPage::postMessage):
(WebKit::WebPage::postSynchronousMessageForTesting):
(WebKit::WebPage::mouseEventSyncForTesting): Deleted.
(WebKit::WebPage::wheelEventSyncForTesting): Deleted.
(WebKit::WebPage::keyEventSyncForTesting): Deleted.
(WebKit::WebPage::touchEventSyncForTesting): Deleted.
(WebKit::WebPage::postSynchronousMessage): Deleted.
* WebProcess/WebPage/WebPage.h:

Tools:

* WebKitTestRunner/InjectedBundle/Bindings/EventSendingController.idl:
* WebKitTestRunner/InjectedBundle/EventSendingController.h:
Removed asyncScrolling from mouseScrollByWithWheelAndMomentumPhases, it's now always
asynchronous (and really, it has always been for the most part).

* WebKitTestRunner/InjectedBundle/EventSendingController.cpp:
(WTR::EventSendingController::mouseDown): Updated for WKBundlePagePostSynchronousMessage renaming.
(WTR::EventSendingController::mouseUp): Ditto.
(WTR::EventSendingController::mouseMoveTo): Ditto.
(WTR::EventSendingController::mouseForceDown): Ditto.
(WTR::EventSendingController::mouseForceUp): Ditto.
(WTR::EventSendingController::mouseForceChanged): Ditto.
(WTR::EventSendingController::leapForward): Ditto.
(WTR::EventSendingController::scheduleAsynchronousClick): Ditto.
(WTR::EventSendingController::keyDown): Ditto.
(WTR::EventSendingController::scheduleAsynchronousKeyDown): Ditto.
(WTR::EventSendingController::mouseScrollBy): Force a scrolling tree commit. It used
to be done in custom WebKit2 code for test wheel event handling.
(WTR::EventSendingController::mouseScrollByWithWheelAndMomentumPhases): Got rid of sync version.
(WTR::EventSendingController::continuousMouseScrollBy): Added a FIXME. This one is weird.
(WTR::EventSendingController::contextClick): Updated for WKBundlePagePostSynchronousMessage renaming.
(WTR::EventSendingController::addTouchPoint): Ditto.
(WTR::EventSendingController::updateTouchPoint): Ditto.
(WTR::EventSendingController::setTouchModifier): Ditto.
(WTR::EventSendingController::setTouchPointRadius): Ditto.
(WTR::EventSendingController::touchStart): Ditto.
(WTR::EventSendingController::touchMove): Ditto.
(WTR::EventSendingController::touchEnd): Ditto.
(WTR::EventSendingController::touchCancel): Ditto.
(WTR::EventSendingController::clearTouchPoints): Ditto.
(WTR::EventSendingController::releaseTouchPoint): Ditto.
(WTR::EventSendingController::cancelTouchPoint): Ditto.

* WebKitTestRunner/InjectedBundle/InjectedBundle.cpp:
(WTR::InjectedBundle::postSetWindowIsKey):
(WTR::InjectedBundle::postSimulateWebNotificationClick):
(WTR::InjectedBundle::isGeolocationProviderActive):
(WTR::InjectedBundle::shouldProcessWorkQueue):
Updated for WKBundlePagePostSynchronousMessage renaming.

* WebKitTestRunner/InjectedBundle/TestRunner.cpp:
(WTR::TestRunner::secureEventInputIsEnabled): Ditto.

* WebKitTestRunner/TestController.cpp:
(WTR::TestController::initialize): Allow handling the new test style messages.
(WTR::TestController::didReceiveKeyDownMessageFromInjectedBundle): Removed calls
to WKPageSetShouldSendEventsSynchronously, which we no longer need.
(WTR::TestController::didReceiveMessageFromInjectedBundle):
(WTR::TestController::didReceiveSynchronousMessageFromInjectedBundle): Moved
"MouseScrollBy" to async section, and got rid of WKPageSetShouldSendEventsSynchronously.

* WebKitTestRunner/mac/EventSenderProxy.mm:
(WTR::EventSenderProxy::mouseMoveTo): Got rid of WKPageSetShouldSendEventsSynchronously.
(WTR::EventSenderProxy::keyDown): Ditto.
(WTR::EventSenderProxy::mouseScrollBy): Ditto.
(WTR::EventSenderProxy::mouseScrollByWithWheelAndMomentumPhases): Ditto.

LayoutTests:

* fast/events/clear-drag-state-expected.txt:
* fast/events/clear-drag-state.html:
* platform/mac-wk2/TestExpectations:
This test used to accidentally pass in WebKit2, but it didn't actually check
for the problem. This patch improves WK2 behavior, which makes the test fail.
Changed the test to not pass accidentally, and added it to WK2 test expectations.
        
* fast/events/scroll-in-scaled-page-with-overflow-hidden-expected.txt:
* fast/events/scroll-in-scaled-page-with-overflow-hidden.html:
Updated the test to be fully async.

* fast/events/wheelevent-basic-expected.txt:
* fast/events/wheelevent-basic.html:
Updated the test to be fully async, got rid of tab characters.

* fast/events/wheelevent-mousewheel-interaction.html: 
* fast/forms/search/search-scroll-hidden-decoration-container-crash.html:
* fast/frames/flattening/scrolling-in-object.html:
Updated these tests to be fully async. Since they check for something that happens
asynchronously, and doesn't have an end event, they have to use setTimeout.

* fast/scrolling/latching/iframe_in_iframe.html:
* fast/scrolling/latching/scroll-div-latched-div.html:
* fast/scrolling/latching/scroll-div-latched-mainframe.html:
* fast/scrolling/latching/scroll-div-no-latching.html:
* fast/scrolling/latching/scroll-div-with-nested-nonscrollable-iframe.html:
* fast/scrolling/latching/scroll-iframe-fragment.html:
* fast/scrolling/latching/scroll-iframe-latched-iframe.html:
* fast/scrolling/latching/scroll-iframe-latched-mainframe.html:
* fast/scrolling/latching/scroll-iframe-webkit1-latching-bug.html:
* fast/scrolling/latching/scroll-latched-nested-div.html:
* fast/scrolling/latching/scroll-nested-iframe.html:
* fast/scrolling/latching/scroll-select-bottom-test.html:
* fast/scrolling/latching/scroll-select-latched-mainframe.html:
* fast/scrolling/latching/scroll-select-latched-select.html:
Removed extra testRunner.mouseScrollByWithWheelAndMomentumPhases() calls.
We no longer need multiple events for scroll snap animation to start, and due to
the way we coalesce events, having multiple events resulted in getting too high velocity.
Removed async scrolling argument form the function calls, because it's now always async.

* platform/mac-wk1/TestExpectations:
* platform/mac/TestExpectations:
Moved fast/scrolling/latching/scroll-div-with-nested-nonscrollable-iframe.html
to WK1 expectations, because the test needn't be skipped on WK2.

* scrollbars/scroll-rtl-or-bt-layer.html: Made the test fully async, and refactored
it for clarity.

* tiled-drawing/scrolling/fast-scroll-div-latched-div-with-handler.html:
* tiled-drawing/scrolling/fast-scroll-div-latched-div.html:
* tiled-drawing/scrolling/fast-scroll-div-latched-mainframe-with-handler.html:
* tiled-drawing/scrolling/fast-scroll-div-latched-mainframe.html:
* tiled-drawing/scrolling/fast-scroll-iframe-latched-iframe-with-handler.html:
* tiled-drawing/scrolling/fast-scroll-iframe-latched-iframe.html:
* tiled-drawing/scrolling/fast-scroll-iframe-latched-mainframe-with-handler.html:
* tiled-drawing/scrolling/fast-scroll-iframe-latched-mainframe.html:
* tiled-drawing/scrolling/fast-scroll-iframe-latched-select.html:
* tiled-drawing/scrolling/fast-scroll-mainframe-zoom.html:
* tiled-drawing/scrolling/fast-scroll-select-latched-mainframe-with-handler.html:
* tiled-drawing/scrolling/fast-scroll-select-latched-mainframe.html:
* tiled-drawing/scrolling/fast-scroll-select-latched-select.html:
* tiled-drawing/scrolling/iframe_in_iframe.html:
* tiled-drawing/scrolling/overflow-scroll-reduced-content.html:
* tiled-drawing/scrolling/overflow-scroll-zero-delta-wheel-events.html:
* tiled-drawing/scrolling/root-overflow-with-mousewheel.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-iframe.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-2d-overflow.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-borders.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-mainframe-horizontal.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-mainframe-slow-horizontal.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-mainframe-slow-vertical.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-mainframe-vertical.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow-stateless.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-overflow.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-padding.html:
* tiled-drawing/scrolling/scroll-snap/scroll-snap-mandatory-rotated.html:
* tiled-drawing/scrolling/wheel-events-with-no-delta.html:
Same testRunner.mouseScrollByWithWheelAndMomentumPhases changes as in fast/scrolling/latching.

* tiled-drawing/scrolling/fast-scroll-select-latched-select-with-handler-expected.txt:
* tiled-drawing/scrolling/fast-scroll-select-latched-select-with-handler.html:
Removed debug output about how many events are received. The number may vary due
to coalescing.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@188793 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/LayoutTests/fast/events/wheelevent-basic.html b/LayoutTests/fast/events/wheelevent-basic.html
index 03d368a..025cf76 100644
--- a/LayoutTests/fast/events/wheelevent-basic.html
+++ b/LayoutTests/fast/events/wheelevent-basic.html
@@ -4,10 +4,12 @@
 <link rel="help" href="http://www.w3.org/TR/DOM-Level-3-Events/#events-WheelEvent">
 <script src="../../resources/js-test-pre.js"></script>
 <script>
-var deltaX = 0;
-var deltaY = 0;
-var expectedDeltaX;
-var expectedDeltaY;
+var eventDeltaX = 0;
+var eventDeltaY = 0;
+var scrollDeltaX;
+var scrollDeltaY;
+
+jsTestIsAsync = true;
 
 var testDiv;
 function runTest() {
@@ -25,12 +27,6 @@
     if (window.eventSender) {
         eventSender.mouseMoveTo(testDiv.offsetLeft + 5, testDiv.offsetTop + 5);
         eventSender.mouseScrollBy(-1, -2);
-	expectedDeltaX = testDiv.scrollLeft;
-	expectedDeltaY = testDiv.scrollTop;
-	shouldBeTrue("deltaX > 0");
-	shouldBe("deltaX", "expectedDeltaX");
-	shouldBeTrue("deltaY > 0");
-	shouldBe("deltaY", "expectedDeltaY");
     } else {
         debug("FAIL: This test requires window.eventSender.");
     }
@@ -38,22 +34,34 @@
 
 var testEvent;
 function wheelHandler(e) {
+    debug("Wheel event fired");
     testEvent = e;
     shouldBe("testEvent.__proto__", "WheelEvent.prototype");
     shouldBe("testEvent.__proto__.__proto__", "MouseEvent.prototype");
-    if (e.deltaX)
-        deltaX = e.deltaX;
-    if (e.deltaY)
-        deltaY = e.deltaY;
+    shouldBeTrue("testEvent.deltaX > 0");
+    shouldBeTrue("testEvent.deltaY > 0");
     shouldBe("testEvent.deltaZ", "0");
     shouldBe("testEvent.deltaMode", "WheelEvent.DOM_DELTA_PIXEL")
+    eventDeltaX = e.deltaX;
+    eventDeltaY = e.deltaY;
+}
+
+function scrollHandler()
+{
+    debug("Scroll event fired");
+    scrollDeltaX = testDiv.scrollLeft;
+    scrollDeltaY = testDiv.scrollTop;
+    shouldBe("eventDeltaX", "scrollDeltaX");
+    shouldBe("eventDeltaY", "scrollDeltaY");
+
+    finishJSTest();
 }
 
 </script>
 </head>
 <body>
 <span id="parent">
-    <div id="target" style="border:solid 1px green; width:100px; height:70px; overflow:scroll; white-space:nowrap;">
+    <div id="target" style="border:solid 1px green; width:100px; height:70px; overflow:scroll; white-space:nowrap;" onscroll="scrollHandler()">
         TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP TOP<br/>
         Scroll mouse wheel over here<br/>
         Scroll mouse wheel over here<br/>