Title: [295451] trunk
Revision
295451
Author
[email protected]
Date
2022-06-10 07:51:23 -0700 (Fri, 10 Jun 2022)

Log Message

WebDriver: [Cocoa] Regression(r290743) Automated mouse movement does not result in JS mouse event being fired
https://bugs.webkit.org/show_bug.cgi?id=241484
rdar://94026001

Reviewed by Devin Rousso.

r290743 changed WKWebView on macOS to no longer forward NSEventTypeMouseMoved events to the underlying view
implementation since it does its own mouse tracking. Unfortuantely, this means that WebDriver on Cocoa platforms can not
just dispatch an event to the window and have that event reach the WKWebView's underlying view implementation. This
change was made because events for genuine cursor movement were being received twice by the underlying view previously.
We need to explicitly tell the underlying view about automated mouse movements (as well as the NSWindow to maintain any
existing behavior caused by the mouse move event being sent to the window).

This patch was verified by comparing WPT test results for tests in /webdriver/tests/perform_actions and
/webdriver/tests/release_actions and ensuring that results now match Safari 15.5 again, which does not have the
regressing change included.

* Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h:
* Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm:
(-[WKWebView _simulateMouseMove:]):
* Source/WebKit/UIProcess/API/mac/WKWebViewPrivateForTestingMac.h:
* Source/WebKit/UIProcess/API/mac/WKWebViewTestingMac.mm:
(-[WKWebView _simulateMouseMove:]): Deleted.
- Move _simulateMouseMove to be private instead of private for testing.

* Source/WebKit/UIProcess/Automation/mac/WebAutomationSessionMac.mm:
(WebKit::WebAutomationSession::sendSynthesizedEventsToPage):
- For mouse move events, make sure the view implementation receives the events.

* Tools/WebKitTestRunner/mac/EventSenderProxy.mm:

Canonical link: https://commits.webkit.org/251457@main

Modified Paths

Diff

Modified: trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h (295450 => 295451)


--- trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2022-06-10 12:26:02 UTC (rev 295450)
+++ trunk/Source/WebKit/UIProcess/API/Cocoa/WKWebViewPrivate.h	2022-06-10 14:51:23 UTC (rev 295451)
@@ -725,6 +725,8 @@
 
 - (void)_prepareForMoveToWindow:(NSWindow *)targetWindow completionHandler:(void(^)(void))completionHandler WK_API_AVAILABLE(macos(10.13));
 
+- (void)_simulateMouseMove:(NSEvent *)event WK_API_AVAILABLE(macos(13.0));
+
 @end
 
 #endif // !TARGET_OS_IPHONE

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm (295450 => 295451)


--- trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm	2022-06-10 12:26:02 UTC (rev 295450)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKWebViewMac.mm	2022-06-10 14:51:23 UTC (rev 295451)
@@ -1690,6 +1690,11 @@
     });
 }
 
+- (void)_simulateMouseMove:(NSEvent *)event
+{
+    return _impl->mouseMoved(event);
+}
+
 @end // WKWebView (WKPrivateMac)
 
 #endif // PLATFORM(MAC)

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKWebViewPrivateForTestingMac.h (295450 => 295451)


--- trunk/Source/WebKit/UIProcess/API/mac/WKWebViewPrivateForTestingMac.h	2022-06-10 12:26:02 UTC (rev 295450)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKWebViewPrivateForTestingMac.h	2022-06-10 14:51:23 UTC (rev 295451)
@@ -52,7 +52,6 @@
 - (void)_setFooterBannerHeight:(int)height;
 - (NSSet<NSView *> *)_pdfHUDs;
 
-- (void)_simulateMouseMove:(NSEvent *)event;
 - (void)_retrieveAccessibilityTreeData:(void (^)(NSData *, NSError *))completionHandler;
 
 @property (nonatomic, readonly) BOOL _secureEventInputEnabledForTesting;

Modified: trunk/Source/WebKit/UIProcess/API/mac/WKWebViewTestingMac.mm (295450 => 295451)


--- trunk/Source/WebKit/UIProcess/API/mac/WKWebViewTestingMac.mm	2022-06-10 12:26:02 UTC (rev 295450)
+++ trunk/Source/WebKit/UIProcess/API/mac/WKWebViewTestingMac.mm	2022-06-10 14:51:23 UTC (rev 295451)
@@ -121,11 +121,6 @@
     return nil;
 }
 
-- (void)_simulateMouseMove:(NSEvent *)event
-{
-    return _impl->mouseMoved(event);
-}
-
 - (void)_retrieveAccessibilityTreeData:(void (^)(NSData *, NSError *))completionHandler
 {
     _page->getAccessibilityTreeData([completionHandler = makeBlockPtr(completionHandler)] (API::Data* data) {

Modified: trunk/Source/WebKit/UIProcess/Automation/mac/WebAutomationSessionMac.mm (295450 => 295451)


--- trunk/Source/WebKit/UIProcess/Automation/mac/WebAutomationSessionMac.mm	2022-06-10 12:26:02 UTC (rev 295450)
+++ trunk/Source/WebKit/UIProcess/Automation/mac/WebAutomationSessionMac.mm	2022-06-10 14:51:23 UTC (rev 295451)
@@ -32,6 +32,7 @@
 #import "WebAutomationSessionMacros.h"
 #import "WebInspectorUIProxy.h"
 #import "WebPageProxy.h"
+#import "WKWebViewPrivate.h"
 #import "_WKAutomationSession.h"
 #import <Carbon/Carbon.h>
 #import <WebCore/IntPoint.h>
@@ -73,8 +74,7 @@
 void WebAutomationSession::sendSynthesizedEventsToPage(WebPageProxy& page, NSArray *eventsToSend)
 {
     NSWindow *window = page.platformWindow();
-    [window makeKeyAndOrderFront:nil];
-    page.makeFirstResponder();
+    auto webView = page.cocoaView();
 
     for (NSEvent *event in eventsToSend) {
         LOG(Automation, "Sending event[%p] to window[%p]: %@", event, window, event);
@@ -86,6 +86,16 @@
 
         markEventAsSynthesizedForAutomation(event);
         [window sendEvent:event];
+
+        // NSEventTypeMouseMoved events are not forwarded from the WKWebView to the underlying view implementation,
+        // which prevents these synthetic events from being dispatched as events in _javascript_. We still dispatch the
+        // event to the window as well to avoid any side effects of providing incomplete events to other parts of the
+        // window. NSEventTypeMouseEntered and NSEventTypeMouseExited events are also affected, but we do not currently
+        // dispatch events with those types.
+        if (event.type == NSEventTypeMouseMoved) {
+            LOG(Automation, "Simulating event[%p] of type NSEventTypeMouseMoved for web view[%p]: %@", event, webView.get(), event);
+            [webView _simulateMouseMove:event];
+        }
     }
 }
 

Modified: trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm (295450 => 295451)


--- trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm	2022-06-10 12:26:02 UTC (rev 295450)
+++ trunk/Tools/WebKitTestRunner/mac/EventSenderProxy.mm	2022-06-10 14:51:23 UTC (rev 295451)
@@ -38,7 +38,7 @@
 #import <WebKit/WKString.h>
 #import <WebKit/WKPagePrivate.h>
 #import <WebKit/WKWebView.h>
-#import <WebKit/WKWebViewPrivateForTestingMac.h>
+#import <WebKit/WKWebViewPrivate.h>
 #import <pal/spi/cocoa/IOKitSPI.h>
 #import <wtf/RetainPtr.h>
 #import <wtf/cocoa/TypeCastsCocoa.h>
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes

Reply via email to