Web Automation: mouse buttons are not correctly printed in SimulatedInputDispatcher...
authorbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 16:02:26 +0000 (16:02 +0000)
committerbburg@apple.com <bburg@apple.com@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Thu, 15 Aug 2019 16:02:26 +0000 (16:02 +0000)
https://bugs.webkit.org/show_bug.cgi?id=200729

Reviewed by Devin Rousso.

This was printing out gibberish because it was trying to decode a WebMouseEvent button
as an Automation protocol button. The logging was less useful because of it.

To fix this, push usage of Automation protocol-based MouseButton type alias all the way
to the platform-specific methods. The mouse buttons are the same for WebMouseEvent::Button
and the Automation protocol type, except the automation type has an auto-generated toString.

* UIProcess/Automation/SimulatedInputDispatcher.h:
* UIProcess/Automation/SimulatedInputDispatcher.cpp:
(WebKit::SimulatedInputDispatcher::transitionInputSourceToState):
(WebKit::SimulatedInputDispatcher::run):
Fix types.

* UIProcess/Automation/WebAutomationSession.h:
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::simulateMouseInteraction):
(WebKit::WebAutomationSession::performMouseInteraction):
(WebKit::WebAutomationSession::performInteractionSequence):
(WebKit::protocolMouseButtonToWebMouseEventButton): Deleted.
Fix types.

* UIProcess/Automation/mac/WebAutomationSessionMac.mm:
(WebKit::automationMouseButtonToPlatformMouseButton):
(WebKit::WebAutomationSession::platformSimulateMouseInteraction):
* UIProcess/Automation/gtk/WebAutomationSessionGtk.cpp:
(WebKit::mouseButtonToGdkButton):
(WebKit::WebAutomationSession::platformSimulateMouseInteraction):
* UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp:
(WebKit::mouseButtonToWPEButton):
(WebKit::WebAutomationSession::platformSimulateMouseInteraction):
Move translation between MouseButton and native button values to platform methods.

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

Source/WebKit/ChangeLog
Source/WebKit/UIProcess/Automation/SimulatedInputDispatcher.cpp
Source/WebKit/UIProcess/Automation/SimulatedInputDispatcher.h
Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp
Source/WebKit/UIProcess/Automation/WebAutomationSession.h
Source/WebKit/UIProcess/Automation/gtk/WebAutomationSessionGtk.cpp
Source/WebKit/UIProcess/Automation/mac/WebAutomationSessionMac.mm
Source/WebKit/UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp

index 0d038c6..589e3c4 100644 (file)
@@ -1,3 +1,42 @@
+2019-08-14  Brian Burg  <bburg@apple.com>
+
+        Web Automation: mouse buttons are not correctly printed in SimulatedInputDispatcher log spew
+        https://bugs.webkit.org/show_bug.cgi?id=200729
+
+        Reviewed by Devin Rousso.
+
+        This was printing out gibberish because it was trying to decode a WebMouseEvent button
+        as an Automation protocol button. The logging was less useful because of it.
+
+        To fix this, push usage of Automation protocol-based MouseButton type alias all the way
+        to the platform-specific methods. The mouse buttons are the same for WebMouseEvent::Button
+        and the Automation protocol type, except the automation type has an auto-generated toString.
+
+        * UIProcess/Automation/SimulatedInputDispatcher.h:
+        * UIProcess/Automation/SimulatedInputDispatcher.cpp:
+        (WebKit::SimulatedInputDispatcher::transitionInputSourceToState):
+        (WebKit::SimulatedInputDispatcher::run):
+        Fix types.
+
+        * UIProcess/Automation/WebAutomationSession.h:
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::simulateMouseInteraction):
+        (WebKit::WebAutomationSession::performMouseInteraction):
+        (WebKit::WebAutomationSession::performInteractionSequence):
+        (WebKit::protocolMouseButtonToWebMouseEventButton): Deleted.
+        Fix types.
+
+        * UIProcess/Automation/mac/WebAutomationSessionMac.mm:
+        (WebKit::automationMouseButtonToPlatformMouseButton):
+        (WebKit::WebAutomationSession::platformSimulateMouseInteraction):
+        * UIProcess/Automation/gtk/WebAutomationSessionGtk.cpp:
+        (WebKit::mouseButtonToGdkButton):
+        (WebKit::WebAutomationSession::platformSimulateMouseInteraction):
+        * UIProcess/Automation/wpe/WebAutomationSessionWPE.cpp:
+        (WebKit::mouseButtonToWPEButton):
+        (WebKit::WebAutomationSession::platformSimulateMouseInteraction):
+        Move translation between MouseButton and native button values to platform methods.
+
 2019-08-15  Simon Fraser  <simon.fraser@apple.com>
 
         Use ObjectIdentifier<FrameIdentifierType> for frameIDs
index d8748ee..29fea6a 100644 (file)
@@ -296,7 +296,7 @@ void SimulatedInputDispatcher::transitionInputSourceToState(SimulatedInputSource
             } else if (a.location != b.location) {
                 LOG(Automation, "SimulatedInputDispatcher[%p]: simulating MouseMove from (%d, %d) to (%d, %d) for transition to %d.%d", this, a.location.value().x(), a.location.value().y(), b.location.value().x(), b.location.value().y(), m_keyframeIndex, m_inputSourceStateIndex);
                 // FIXME: This does not interpolate mousemoves per the "perform a pointer move" algorithm (ยง17.4 Dispatching Actions).
-                m_client.simulateMouseInteraction(m_page, MouseInteraction::Move, b.pressedMouseButton.valueOr(MouseButton::NoButton), b.location.value(), WTFMove(eventDispatchFinished));
+                m_client.simulateMouseInteraction(m_page, MouseInteraction::Move, b.pressedMouseButton.valueOr(MouseButton::None), b.location.value(), WTFMove(eventDispatchFinished));
             } else
                 eventDispatchFinished(WTF::nullopt);
         });
@@ -401,7 +401,7 @@ void SimulatedInputDispatcher::run(WebCore::FrameIdentifier frameID, Vector<Simu
     m_keyframes.append(SimulatedInputKeyFrame::keyFrameFromStateOfInputSources(m_inputSources));
     m_keyframes.appendVector(WTFMove(keyFrames));
 
-    LOG(Automation, "SimulatedInputDispatcher[%p]: starting input simulation using %d keyframes", this, m_keyframeIndex);
+    LOG(Automation, "SimulatedInputDispatcher[%p]: starting input simulation using %zu keyframes", this, m_keyframes.size());
 
     transitionToNextKeyFrame();
 }
index b0891a8..aff3f78 100644 (file)
@@ -41,6 +41,7 @@
 namespace Inspector { namespace Protocol { namespace Automation {
 enum class ErrorMessage;
 enum class KeyboardInteractionType;
+enum class MouseButton;
 enum class MouseInteraction;
 enum class MouseMoveOrigin;
 enum class VirtualKey;
@@ -57,7 +58,7 @@ using KeyboardInteraction = Inspector::Protocol::Automation::KeyboardInteraction
 using VirtualKey = Inspector::Protocol::Automation::VirtualKey;
 using VirtualKeySet = HashSet<VirtualKey, WTF::IntHash<VirtualKey>, WTF::StrongEnumHashTraits<VirtualKey>>;
 using CharKey = char; // For WebDriver, this only needs to support ASCII characters on 102-key keyboard.
-using MouseButton = WebMouseEvent::Button;
+using MouseButton = Inspector::Protocol::Automation::MouseButton;
 using MouseInteraction = Inspector::Protocol::Automation::MouseInteraction;
 using MouseMoveOrigin = Inspector::Protocol::Automation::MouseMoveOrigin;
 
@@ -125,7 +126,7 @@ public:
     public:
         virtual ~Client() { }
 #if ENABLE(WEBDRIVER_MOUSE_INTERACTIONS)
-        virtual void simulateMouseInteraction(WebPageProxy&, MouseInteraction, WebMouseEvent::Button, const WebCore::IntPoint& locationInView, AutomationCompletionHandler&&) = 0;
+        virtual void simulateMouseInteraction(WebPageProxy&, MouseInteraction, MouseButton, const WebCore::IntPoint& locationInView, AutomationCompletionHandler&&) = 0;
 #endif
 #if ENABLE(WEBDRIVER_TOUCH_INTERACTIONS)
         virtual void simulateTouchInteraction(WebPageProxy&, TouchInteraction, const WebCore::IntPoint& locationInView, Optional<Seconds> duration, AutomationCompletionHandler&&) = 0;
index cf79afd..2c78df5 100644 (file)
@@ -1482,7 +1482,8 @@ void WebAutomationSession::viewportInViewCenterPointOfElement(WebPageProxy& page
 }
 
 #if ENABLE(WEBDRIVER_MOUSE_INTERACTIONS)
-void WebAutomationSession::simulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, WebMouseEvent::Button mouseButton, const WebCore::IntPoint& locationInViewport, CompletionHandler<void(Optional<AutomationCommandError>)>&& completionHandler)
+
+void WebAutomationSession::simulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, MouseButton mouseButton, const WebCore::IntPoint& locationInViewport, CompletionHandler<void(Optional<AutomationCommandError>)>&& completionHandler)
 {
     page.getWindowFrameWithCallback([this, protectedThis = makeRef(*this), completionHandler = WTFMove(completionHandler), page = makeRef(page), interaction, mouseButton, locationInViewport](WebCore::FloatRect windowFrame) mutable {
         auto clippedX = std::min(std::max(0.0f, (float)locationInViewport.x()), windowFrame.size().width());
@@ -1581,24 +1582,6 @@ static WebEvent::Modifier protocolModifierToWebEventModifier(Inspector::Protocol
 }
 #endif // ENABLE(WEBDRIVER_MOUSE_INTERACTIONS)
 
-#if ENABLE(WEBDRIVER_ACTIONS_API)
-static WebMouseEvent::Button protocolMouseButtonToWebMouseEventButton(Inspector::Protocol::Automation::MouseButton button)
-{
-    switch (button) {
-    case Inspector::Protocol::Automation::MouseButton::None:
-        return WebMouseEvent::NoButton;
-    case Inspector::Protocol::Automation::MouseButton::Left:
-        return WebMouseEvent::LeftButton;
-    case Inspector::Protocol::Automation::MouseButton::Middle:
-        return WebMouseEvent::MiddleButton;
-    case Inspector::Protocol::Automation::MouseButton::Right:
-        return WebMouseEvent::RightButton;
-    }
-
-    RELEASE_ASSERT_NOT_REACHED();
-}
-#endif // ENABLE(WEBDRIVER_ACTIONS_API)
-
 void WebAutomationSession::performMouseInteraction(const String& handle, const JSON::Object& requestedPositionObject, const String& mouseButtonString, const String& mouseInteractionString, const JSON::Array& keyModifierStrings, Ref<PerformMouseInteractionCallback>&& callback)
 {
 #if !ENABLE(WEBDRIVER_MOUSE_INTERACTIONS)
@@ -1659,7 +1642,7 @@ void WebAutomationSession::performMouseInteraction(const String& handle, const J
             callbackInMap(AUTOMATION_COMMAND_ERROR_WITH_NAME(Timeout));
         callbackInMap = WTFMove(mouseEventsFlushedCallback);
 
-        platformSimulateMouseInteraction(page, parsedInteraction.value(), protocolMouseButtonToWebMouseEventButton(parsedButton.value()), locationInViewport, keyModifiers);
+        platformSimulateMouseInteraction(page, parsedInteraction.value(), parsedButton.value(), locationInViewport, keyModifiers);
 
         // If the event location was previously clipped and does not hit test anything in the window, then it will not be processed.
         // For compatibility with pre-W3C driver implementations, don't make this a hard error; just do nothing silently.
@@ -1901,7 +1884,7 @@ void WebAutomationSession::performInteractionSequence(const String& handle, cons
             String pressedButtonString;
             if (stateObject->getString("pressedButton"_s, pressedButtonString)) {
                 auto protocolButton = Inspector::Protocol::AutomationHelpers::parseEnumValueFromString<Inspector::Protocol::Automation::MouseButton>(pressedButtonString);
-                sourceState.pressedMouseButton = protocolMouseButtonToWebMouseEventButton(protocolButton.valueOr(Inspector::Protocol::Automation::MouseButton::None));
+                sourceState.pressedMouseButton = protocolButton.valueOr(MouseButton::None);
             }
 
             String originString;
index 7596fee..93bbc7d 100644 (file)
@@ -145,7 +145,7 @@ public:
 
     // SimulatedInputDispatcher::Client API
 #if ENABLE(WEBDRIVER_MOUSE_INTERACTIONS)
-    void simulateMouseInteraction(WebPageProxy&, MouseInteraction, WebMouseEvent::Button, const WebCore::IntPoint& locationInView, AutomationCompletionHandler&&) final;
+    void simulateMouseInteraction(WebPageProxy&, MouseInteraction, MouseButton, const WebCore::IntPoint& locationInView, AutomationCompletionHandler&&) final;
 #endif
 #if ENABLE(WEBDRIVER_TOUCH_INTERACTIONS)
     void simulateTouchInteraction(WebPageProxy&, TouchInteraction, const WebCore::IntPoint& locationInView, Optional<Seconds> duration, AutomationCompletionHandler&&) final;
@@ -245,7 +245,7 @@ private:
 
     // Platform-dependent implementations.
 #if ENABLE(WEBDRIVER_MOUSE_INTERACTIONS)
-    void platformSimulateMouseInteraction(WebPageProxy&, MouseInteraction, WebMouseEvent::Button, const WebCore::IntPoint& locationInViewport, OptionSet<WebEvent::Modifier>);
+    void platformSimulateMouseInteraction(WebPageProxy&, MouseInteraction, MouseButton, const WebCore::IntPoint& locationInViewport, OptionSet<WebEvent::Modifier>);
 #endif
 #if ENABLE(WEBDRIVER_TOUCH_INTERACTIONS)
     // Simulates a single touch point being pressed, moved, and released.
index 7eae8b2..dd81d1d 100644 (file)
@@ -48,15 +48,15 @@ static unsigned modifiersToEventState(OptionSet<WebEvent::Modifier> modifiers)
     return state;
 }
 
-static unsigned mouseButtonToGdkButton(WebMouseEvent::Button button)
+static unsigned mouseButtonToGdkButton(MouseButton button)
 {
     switch (button) {
-    case WebMouseEvent::NoButton:
-    case WebMouseEvent::LeftButton:
+    case MouseButton::None:
+    case MouseButton::Left:
         return GDK_BUTTON_PRIMARY;
-    case WebMouseEvent::MiddleButton:
+    case MouseButton::Middle:
         return GDK_BUTTON_MIDDLE;
-    case WebMouseEvent::RightButton:
+    case MouseButton::Right:
         return GDK_BUTTON_SECONDARY;
     }
     return GDK_BUTTON_PRIMARY;
@@ -101,7 +101,7 @@ static void doMotionEvent(GtkWidget* widget, const WebCore::IntPoint& location,
     gtk_main_do_event(event.get());
 }
 
-void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, WebMouseEvent::Button button, const WebCore::IntPoint& locationInView, OptionSet<WebEvent::Modifier> keyModifiers)
+void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, MouseButton button, const WebCore::IntPoint& locationInView, OptionSet<WebEvent::Modifier> keyModifiers)
 {
     unsigned gdkButton = mouseButtonToGdkButton(button);
     auto modifier = stateModifierForGdkButton(gdkButton);
index 450014d..df26acd 100644 (file)
@@ -121,9 +121,22 @@ bool WebAutomationSession::wasEventSynthesizedForAutomation(NSEvent *event)
 #pragma mark Platform-dependent Implementations
 
 #if ENABLE(WEBDRIVER_MOUSE_INTERACTIONS)
-void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, WebMouseEvent::Button button, const WebCore::IntPoint& locationInViewport, OptionSet<WebEvent::Modifier> keyModifiers)
+
+static WebMouseEvent::Button automationMouseButtonToPlatformMouseButton(MouseButton button)
+{
+    switch (button) {
+    case MouseButton::Left:   return WebMouseEvent::LeftButton;
+    case MouseButton::Middle: return WebMouseEvent::MiddleButton;
+    case MouseButton::Right:  return WebMouseEvent::RightButton;
+    case MouseButton::None:   return WebMouseEvent::NoButton;
+    default: ASSERT_NOT_REACHED();
+    }
+}
+
+void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, MouseButton button, const WebCore::IntPoint& locationInViewport, OptionSet<WebEvent::Modifier> keyModifiers)
 {
     IntRect windowRect;
+
     IntPoint locationInView = WebCore::IntPoint(locationInViewport.x(), locationInViewport.y() + page.topContentInset());
     page.rootViewToWindow(IntRect(locationInView, IntSize()), windowRect);
     IntPoint locationInWindow = windowRect.location();
@@ -147,7 +160,7 @@ void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page,
     NSEventType downEventType = (NSEventType)0;
     NSEventType dragEventType = (NSEventType)0;
     NSEventType upEventType = (NSEventType)0;
-    switch (button) {
+    switch (automationMouseButtonToPlatformMouseButton(button)) {
     case WebMouseEvent::NoButton:
         downEventType = upEventType = dragEventType = NSEventTypeMouseMoved;
         break;
index d7f3b03..d601f0e 100644 (file)
@@ -44,15 +44,15 @@ static uint32_t modifiersToEventState(OptionSet<WebEvent::Modifier> modifiers)
     return state;
 }
 
-static unsigned mouseButtonToWPEButton(WebMouseEvent::Button button)
+static unsigned mouseButtonToWPEButton(MouseButton button)
 {
     switch (button) {
-    case WebMouseEvent::NoButton:
-    case WebMouseEvent::LeftButton:
+    case MouseButton::None:
+    case MouseButton::Left:
         return 1;
-    case WebMouseEvent::MiddleButton:
+    case MouseButton::Middle:
         return 3;
-    case WebMouseEvent::RightButton:
+    case MouseButton::Right:
         return 2;
     }
     return 1;
@@ -91,7 +91,7 @@ static void doMotionEvent(struct wpe_view_backend* viewBackend, const WebCore::I
     wpe_view_backend_dispatch_pointer_event(viewBackend, &event);
 }
 
-void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, WebMouseEvent::Button button, const WebCore::IntPoint& locationInView, OptionSet<WebEvent::Modifier> keyModifiers)
+void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, MouseInteraction interaction, MouseButton button, const WebCore::IntPoint& locationInView, OptionSet<WebEvent::Modifier> keyModifiers)
 {
     unsigned wpeButton = mouseButtonToWPEButton(button);
     auto modifier = stateModifierForWPEButton(wpeButton);