Title: [200278] trunk/Source/WebKit2
Revision
200278
Author
[email protected]
Date
2016-04-29 19:37:01 -0700 (Fri, 29 Apr 2016)

Log Message

Web Automation: use a magic eventNumber as a fallback for detecting NSEvents synthesized for automation
https://bugs.webkit.org/show_bug.cgi?id=157222

Reviewed by Timothy Hatcher.

Sometimes events are copied and redelivered in a way that can't be reliably intercepted,
so use eventNumber as an alternate means of detecting synthesized mouse NSEvents.

* UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
(WebKit::WebAutomationSession::wasEventSynthesizedForAutomation):
If it's a mouse-related event, check the eventNumber if the associated object was missing.

(WebKit::WebAutomationSession::platformSimulateMouseInteraction):
Most real events from input devices fill in eventNumber with a non-zero value.
In my testing, using zero did not seem to adversely affect event delivery.

Modified Paths

Diff

Modified: trunk/Source/WebKit2/ChangeLog (200277 => 200278)


--- trunk/Source/WebKit2/ChangeLog	2016-04-30 01:50:42 UTC (rev 200277)
+++ trunk/Source/WebKit2/ChangeLog	2016-04-30 02:37:01 UTC (rev 200278)
@@ -1,3 +1,21 @@
+2016-04-29  Brian Burg  <[email protected]>
+
+        Web Automation: use a magic eventNumber as a fallback for detecting NSEvents synthesized for automation
+        https://bugs.webkit.org/show_bug.cgi?id=157222
+
+        Reviewed by Timothy Hatcher.
+
+        Sometimes events are copied and redelivered in a way that can't be reliably intercepted,
+        so use eventNumber as an alternate means of detecting synthesized mouse NSEvents.
+
+        * UIProcess/Cocoa/WebAutomationSessionCocoa.mm:
+        (WebKit::WebAutomationSession::wasEventSynthesizedForAutomation):
+        If it's a mouse-related event, check the eventNumber if the associated object was missing.
+
+        (WebKit::WebAutomationSession::platformSimulateMouseInteraction):
+        Most real events from input devices fill in eventNumber with a non-zero value.
+        In my testing, using zero did not seem to adversely affect event delivery.
+
 2016-04-29  Joseph Pecoraro  <[email protected]>
 
         Web Inspector: Issues inspecting the inspector, pausing on breakpoints causes content to not load

Modified: trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm (200277 => 200278)


--- trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm	2016-04-30 01:50:42 UTC (rev 200277)
+++ trunk/Source/WebKit2/UIProcess/Cocoa/WebAutomationSessionCocoa.mm	2016-04-30 02:37:01 UTC (rev 200278)
@@ -43,6 +43,7 @@
 
 #if USE(APPKIT)
 
+static const NSInteger synthesizedMouseEventMagicEventNumber = 0;
 static const void *synthesizedAutomationEventAssociatedObjectKey = &synthesizedAutomationEventAssociatedObjectKey;
 
 void WebAutomationSession::sendSynthesizedEventsToPage(WebPageProxy& page, NSArray *eventsToSend)
@@ -58,7 +59,28 @@
 bool WebAutomationSession::wasEventSynthesizedForAutomation(NSEvent *event)
 {
     NSString *senderSessionIdentifier = objc_getAssociatedObject(event, &synthesizedAutomationEventAssociatedObjectKey);
-    return [senderSessionIdentifier isEqualToString:m_sessionIdentifier];
+    if ([senderSessionIdentifier isEqualToString:m_sessionIdentifier])
+        return true;
+
+    switch (event.type) {
+    case NSEventTypeLeftMouseDown:
+    case NSEventTypeLeftMouseDragged:
+    case NSEventTypeLeftMouseUp:
+    case NSEventTypeMouseMoved:
+    case NSEventTypeOtherMouseDown:
+    case NSEventTypeOtherMouseDragged:
+    case NSEventTypeOtherMouseUp:
+    case NSEventTypeRightMouseDown:
+    case NSEventTypeRightMouseDragged:
+    case NSEventTypeRightMouseUp:
+        // Use this as a backup for checking mouse events, which are frequently copied
+        // and/or faked by AppKit, causing them to lose their associated object tag.
+        return event.eventNumber == synthesizedMouseEventMagicEventNumber;
+    default:
+        break;
+    }
+
+    return false;
 }
 
 void WebAutomationSession::platformSimulateMouseInteraction(WebPageProxy& page, const WebCore::IntPoint& viewPosition, Inspector::Protocol::Automation::MouseInteraction interaction, Inspector::Protocol::Automation::MouseButton button, WebEvent::Modifiers keyModifiers)
@@ -106,32 +128,34 @@
 
     auto eventsToBeSent = adoptNS([[NSMutableArray alloc] init]);
 
+    NSInteger eventNumber = synthesizedMouseEventMagicEventNumber;
+
     switch (interaction) {
     case Inspector::Protocol::Automation::MouseInteraction::Move:
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:dragEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:0 pressure:0.0f]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:dragEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:0 pressure:0.0f]];
         break;
     case Inspector::Protocol::Automation::MouseInteraction::Down:
         // Hard-code the click count to one, since clients don't expect successive simulated
         // down/up events to be potentially counted as a double click event.
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
         break;
     case Inspector::Protocol::Automation::MouseInteraction::Up:
         // Hard-code the click count to one, since clients don't expect successive simulated
         // down/up events to be potentially counted as a double click event.
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
         break;
     case Inspector::Protocol::Automation::MouseInteraction::SingleClick:
         // Send separate down and up events. WebCore will see this as a single-click event.
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
         break;
     case Inspector::Protocol::Automation::MouseInteraction::DoubleClick:
         // Send multiple down and up events with proper click count.
         // WebCore will see this as a single-click event then double-click event.
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:WebCore::ForceAtClick]];
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:1 pressure:0.0f]];
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:2 pressure:WebCore::ForceAtClick]];
-        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:0 clickCount:2 pressure:0.0f]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:WebCore::ForceAtClick]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:1 pressure:0.0f]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:downEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:2 pressure:WebCore::ForceAtClick]];
+        [eventsToBeSent addObject:[NSEvent mouseEventWithType:upEventType location:windowPosition modifierFlags:modifiers timestamp:timestamp windowNumber:windowNumber context:nil eventNumber:eventNumber clickCount:2 pressure:0.0f]];
     }
 
     sendSynthesizedEventsToPage(page, eventsToBeSent.get());
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to