Title: [231767] trunk/Source/WebKit
Revision
231767
Author
bb...@apple.com
Date
2018-05-14 12:09:12 -0700 (Mon, 14 May 2018)

Log Message

WebDriver: W3C test case actions/key.py::test_lone_keyup_sends_no_events is failing
https://bugs.webkit.org/show_bug.cgi?id=185577
<rdar://problem/40185478>

Reviewed by Timothy Hatcher.

This test is failing because it expects Release Actions to not emit any
events if nothing has changed from the initial state. Because the two code paths
for creating empty states don't actually produce the same empty state, a difference
in location was detected between the two empty states. This generates a mousemove.

To fix this, unify the code that creates an empty state. For mouse input sources, always
initialize the location to (0, 0) so that the mouse input source always has
a location that is valid to click at.

* UIProcess/Automation/SimulatedInputDispatcher.h:
Extract the type enum out of the class to avoid circular definitions of
SimulatedInputSource and SimulatedInputSourceState.

* UIProcess/Automation/SimulatedInputDispatcher.cpp:
(WebKit::SimulatedInputSourceState::emptyStateForSourceType):
Take the input source type when generating an empty state. We always want location
set for a mouse input source, but not set it for other input sources like keys.

(WebKit::SimulatedInputKeyFrame::keyFrameToResetInputSources):
(WebKit::SimulatedInputDispatcher::transitionInputSourceToState):
(WebKit::SimulatedInputSource::create):
(WebKit::SimulatedInputSource::SimulatedInputSource):
(WebKit::SimulatedInputSourceState::emptyState): Deleted.
* UIProcess/Automation/WebAutomationSession.cpp:
(WebKit::WebAutomationSession::WebAutomationSession):
(WebKit::WebAutomationSession::inputSourceForType const):
(WebKit::simulatedInputSourceTypeFromProtocolSourceType):
(WebKit::WebAutomationSession::performInteractionSequence):
* UIProcess/Automation/WebAutomationSession.h:

Modified Paths

Diff

Modified: trunk/Source/WebKit/ChangeLog (231766 => 231767)


--- trunk/Source/WebKit/ChangeLog	2018-05-14 18:19:30 UTC (rev 231766)
+++ trunk/Source/WebKit/ChangeLog	2018-05-14 19:09:12 UTC (rev 231767)
@@ -1,3 +1,41 @@
+2018-05-14  Brian Burg  <bb...@apple.com>
+
+        WebDriver: W3C test case actions/key.py::test_lone_keyup_sends_no_events is failing
+        https://bugs.webkit.org/show_bug.cgi?id=185577
+        <rdar://problem/40185478>
+
+        Reviewed by Timothy Hatcher.
+
+        This test is failing because it expects Release Actions to not emit any
+        events if nothing has changed from the initial state. Because the two code paths
+        for creating empty states don't actually produce the same empty state, a difference
+        in location was detected between the two empty states. This generates a mousemove.
+
+        To fix this, unify the code that creates an empty state. For mouse input sources, always
+        initialize the location to (0, 0) so that the mouse input source always has
+        a location that is valid to click at.
+
+        * UIProcess/Automation/SimulatedInputDispatcher.h:
+        Extract the type enum out of the class to avoid circular definitions of
+        SimulatedInputSource and SimulatedInputSourceState.
+
+        * UIProcess/Automation/SimulatedInputDispatcher.cpp:
+        (WebKit::SimulatedInputSourceState::emptyStateForSourceType):
+        Take the input source type when generating an empty state. We always want location
+        set for a mouse input source, but not set it for other input sources like keys.
+
+        (WebKit::SimulatedInputKeyFrame::keyFrameToResetInputSources):
+        (WebKit::SimulatedInputDispatcher::transitionInputSourceToState):
+        (WebKit::SimulatedInputSource::create):
+        (WebKit::SimulatedInputSource::SimulatedInputSource):
+        (WebKit::SimulatedInputSourceState::emptyState): Deleted.
+        * UIProcess/Automation/WebAutomationSession.cpp:
+        (WebKit::WebAutomationSession::WebAutomationSession):
+        (WebKit::WebAutomationSession::inputSourceForType const):
+        (WebKit::simulatedInputSourceTypeFromProtocolSourceType):
+        (WebKit::WebAutomationSession::performInteractionSequence):
+        * UIProcess/Automation/WebAutomationSession.h:
+
 2018-05-14  Michael Catanzaro  <mcatanz...@igalia.com>
 
         -Wmemset-elt-size warning in LibWebRTCSocket constructor

Modified: trunk/Source/WebKit/UIProcess/Automation/SimulatedInputDispatcher.cpp (231766 => 231767)


--- trunk/Source/WebKit/UIProcess/Automation/SimulatedInputDispatcher.cpp	2018-05-14 18:19:30 UTC (rev 231766)
+++ trunk/Source/WebKit/UIProcess/Automation/SimulatedInputDispatcher.cpp	2018-05-14 19:09:12 UTC (rev 231767)
@@ -32,6 +32,22 @@
 
 namespace WebKit {
 
+SimulatedInputSourceState SimulatedInputSourceState::emptyStateForSourceType(SimulatedInputSourceType type)
+{
+    SimulatedInputSourceState result { };
+    switch (type) {
+    case SimulatedInputSourceType::Null:
+    case SimulatedInputSourceType::Keyboard:
+        break;
+    case SimulatedInputSourceType::Mouse:
+    case SimulatedInputSourceType::Touch:
+        result.location = WebCore::IntPoint();
+    }
+
+    return result;
+}
+
+
 SimulatedInputKeyFrame::SimulatedInputKeyFrame(Vector<StateEntry>&& entries)
     : states(WTFMove(entries))
 {
@@ -66,12 +82,8 @@
     Vector<SimulatedInputKeyFrame::StateEntry> entries;
     entries.reserveCapacity(inputSources.size());
 
-    for (auto& inputSource : inputSources) {
-        auto emptyState = SimulatedInputSourceState::emptyState();
-        // Ensure we reset the location.
-        emptyState.location = WebCore::IntPoint();
-        entries.uncheckedAppend(std::pair<SimulatedInputSource&, SimulatedInputSourceState> { inputSource.get(), WTFMove(emptyState) });
-    }
+    for (auto& inputSource : inputSources)
+        entries.uncheckedAppend(std::pair<SimulatedInputSource&, SimulatedInputSourceState> { inputSource.get(), SimulatedInputSourceState::emptyStateForSourceType(inputSource->type) });
 
     return SimulatedInputKeyFrame(WTFMove(entries));
 }
@@ -228,11 +240,11 @@
     };
 
     switch (inputSource.type) {
-    case SimulatedInputSource::Type::Null:
+    case SimulatedInputSourceType::Null:
         // The maximum duration is handled at the keyframe level by m_keyFrameTransitionDurationTimer.
         eventDispatchFinished(std::nullopt);
         break;
-    case SimulatedInputSource::Type::Mouse: {
+    case SimulatedInputSourceType::Mouse: {
         resolveLocation(a.location.value_or(WebCore::IntPoint()), b.location, b.origin.value_or(MouseMoveOrigin::Viewport), b.nodeHandle, [this, &a, &b, eventDispatchFinished = WTFMove(eventDispatchFinished)](std::optional<WebCore::IntPoint> location, std::optional<AutomationCommandError> error) mutable {
             if (error) {
                 eventDispatchFinished(error);
@@ -253,7 +265,7 @@
         });
         break;
     }
-    case SimulatedInputSource::Type::Keyboard:
+    case SimulatedInputSourceType::Keyboard:
         // The "dispatch a key{Down,Up} action" algorithms (§17.4 Dispatching Actions).
         if ((!a.pressedCharKey && b.pressedCharKey) || (!a.pressedVirtualKey && b.pressedVirtualKey))
             m_client.simulateKeyboardInteraction(m_page, KeyboardInteraction::KeyPress, b.pressedVirtualKey, b.pressedCharKey, WTFMove(eventDispatchFinished));
@@ -262,7 +274,7 @@
         else
             eventDispatchFinished(std::nullopt);
         break;
-    case SimulatedInputSource::Type::Touch:
+    case SimulatedInputSourceType::Touch:
         // Not supported yet.
         ASSERT_NOT_REACHED();
         eventDispatchFinished(AUTOMATION_COMMAND_ERROR_WITH_NAME(NotImplemented));

Modified: trunk/Source/WebKit/UIProcess/Automation/SimulatedInputDispatcher.h (231766 => 231767)


--- trunk/Source/WebKit/UIProcess/Automation/SimulatedInputDispatcher.h	2018-05-14 18:19:30 UTC (rev 231766)
+++ trunk/Source/WebKit/UIProcess/Automation/SimulatedInputDispatcher.h	2018-05-14 19:09:12 UTC (rev 231767)
@@ -57,6 +57,13 @@
 using MouseInteraction = Inspector::Protocol::Automation::MouseInteraction;
 using MouseMoveOrigin = Inspector::Protocol::Automation::MouseMoveOrigin;
 
+enum class SimulatedInputSourceType {
+    Null, // Used to induce a minimum duration.
+    Keyboard,
+    Mouse,
+    Touch,
+};
+
 struct SimulatedInputSourceState {
     std::optional<CharKey> pressedCharKey;
     std::optional<VirtualKey> pressedVirtualKey;
@@ -66,32 +73,25 @@
     std::optional<WebCore::IntPoint> location;
     std::optional<Seconds> duration;
 
-    static SimulatedInputSourceState emptyState() { return SimulatedInputSourceState(); }
+    static SimulatedInputSourceState emptyStateForSourceType(SimulatedInputSourceType);
 };
 
 struct SimulatedInputSource : public RefCounted<SimulatedInputSource> {
 public:
-    enum class Type {
-        Null, // Used to induce a minimum duration.
-        Keyboard,
-        Mouse,
-        Touch,
-    };
+    SimulatedInputSourceType type;
 
-    Type type;
-
     // The last state associated with this input source.
     SimulatedInputSourceState state;
 
-    static Ref<SimulatedInputSource> create(Type type)
+    static Ref<SimulatedInputSource> create(SimulatedInputSourceType type)
     {
         return adoptRef(*new SimulatedInputSource(type));
     }
 
 private:
-    SimulatedInputSource(Type type)
+    SimulatedInputSource(SimulatedInputSourceType type)
         : type(type)
-        , state(SimulatedInputSourceState::emptyState())
+        , state(SimulatedInputSourceState::emptyStateForSourceType(type))
     { }
 };
 

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp (231766 => 231767)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2018-05-14 18:19:30 UTC (rev 231766)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.cpp	2018-05-14 19:09:12 UTC (rev 231767)
@@ -78,9 +78,9 @@
     , m_loadTimer(RunLoop::main(), this, &WebAutomationSession::loadTimerFired)
 {
     // Set up canonical input sources to be used for 'performInteractionSequence' and 'cancelInteractionSequence'.
-    m_inputSources.add(SimulatedInputSource::create(SimulatedInputSource::Type::Mouse));
-    m_inputSources.add(SimulatedInputSource::create(SimulatedInputSource::Type::Keyboard));
-    m_inputSources.add(SimulatedInputSource::create(SimulatedInputSource::Type::Null));
+    m_inputSources.add(SimulatedInputSource::create(SimulatedInputSourceType::Mouse));
+    m_inputSources.add(SimulatedInputSource::create(SimulatedInputSourceType::Keyboard));
+    m_inputSources.add(SimulatedInputSource::create(SimulatedInputSourceType::Null));
 }
 
 WebAutomationSession::~WebAutomationSession()
@@ -1404,7 +1404,7 @@
     }).iterator->value;
 }
 
-SimulatedInputSource* WebAutomationSession::inputSourceForType(SimulatedInputSource::Type type) const
+SimulatedInputSource* WebAutomationSession::inputSourceForType(SimulatedInputSourceType type) const
 {
     // FIXME: this should use something like Vector's findMatching().
     for (auto& inputSource : m_inputSources) {
@@ -1668,17 +1668,17 @@
 }
 
 #if USE(APPKIT) || PLATFORM(GTK)
-static SimulatedInputSource::Type simulatedInputSourceTypeFromProtocolSourceType(Inspector::Protocol::Automation::InputSourceType protocolType)
+static SimulatedInputSourceType simulatedInputSourceTypeFromProtocolSourceType(Inspector::Protocol::Automation::InputSourceType protocolType)
 {
     switch (protocolType) {
     case Inspector::Protocol::Automation::InputSourceType::Null:
-        return SimulatedInputSource::Type::Null;
+        return SimulatedInputSourceType::Null;
     case Inspector::Protocol::Automation::InputSourceType::Keyboard:
-        return SimulatedInputSource::Type::Keyboard;
+        return SimulatedInputSourceType::Keyboard;
     case Inspector::Protocol::Automation::InputSourceType::Mouse:
-        return SimulatedInputSource::Type::Mouse;
+        return SimulatedInputSourceType::Mouse;
     case Inspector::Protocol::Automation::InputSourceType::Touch:
-        return SimulatedInputSource::Type::Touch;
+        return SimulatedInputSourceType::Touch;
     }
 
     RELEASE_ASSERT_NOT_REACHED();
@@ -1701,7 +1701,7 @@
         ASYNC_FAIL_WITH_PREDEFINED_ERROR(FrameNotFound);
 
     HashMap<String, Ref<SimulatedInputSource>> sourceIdToInputSourceMap;
-    HashMap<SimulatedInputSource::Type, String, WTF::IntHash<SimulatedInputSource::Type>, WTF::StrongEnumHashTraits<SimulatedInputSource::Type>> typeToSourceIdMap;
+    HashMap<SimulatedInputSourceType, String, WTF::IntHash<SimulatedInputSourceType>, WTF::StrongEnumHashTraits<SimulatedInputSourceType>> typeToSourceIdMap;
 
     // Parse and validate Automation protocol arguments. By this point, the driver has
     // already performed the steps in §17.3 Processing Actions Requests.
@@ -1725,8 +1725,8 @@
         if (!parsedInputSourceType)
             ASYNC_FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(InvalidParameter, "An input source in the 'inputSources' parameter has an invalid 'sourceType'.");
 
-        SimulatedInputSource::Type inputSourceType = simulatedInputSourceTypeFromProtocolSourceType(*parsedInputSourceType);
-        if (inputSourceType == SimulatedInputSource::Type::Touch)
+        SimulatedInputSourceType inputSourceType = simulatedInputSourceTypeFromProtocolSourceType(*parsedInputSourceType);
+        if (inputSourceType == SimulatedInputSourceType::Touch)
             ASYNC_FAIL_WITH_PREDEFINED_ERROR_AND_DETAILS(NotImplemented, "Touch input sources are not yet supported.");
 
         if (typeToSourceIdMap.contains(inputSourceType))

Modified: trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h (231766 => 231767)


--- trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h	2018-05-14 18:19:30 UTC (rev 231766)
+++ trunk/Source/WebKit/UIProcess/Automation/WebAutomationSession.h	2018-05-14 19:09:12 UTC (rev 231767)
@@ -188,7 +188,7 @@
     // Event Simulation Support.
     bool isSimulatingUserInteraction() const;
     SimulatedInputDispatcher& inputDispatcherForPage(WebPageProxy&);
-    SimulatedInputSource* inputSourceForType(SimulatedInputSource::Type) const;
+    SimulatedInputSource* inputSourceForType(SimulatedInputSourceType) const;
 
 #if PLATFORM(MAC)
     bool wasEventSynthesizedForAutomation(NSEvent *);
_______________________________________________
webkit-changes mailing list
webkit-changes@lists.webkit.org
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to