Skip to content
Permalink
Browse files
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
git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295451 268f45cc-cd09-0410-ab3c-d52691b4dbfc
  • Loading branch information
patrickangle committed Jun 10, 2022
1 parent 3ac590e commit fc784f4883874f8e3b50a861285d5396859fb4a1
Showing 6 changed files with 20 additions and 9 deletions.
@@ -725,6 +725,8 @@ typedef NS_OPTIONS(NSUInteger, WKDisplayCaptureSurfaces) {

- (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
@@ -1690,6 +1690,11 @@ - (void)_prepareForMoveToWindow:(NSWindow *)targetWindow completionHandler:(void
});
}

- (void)_simulateMouseMove:(NSEvent *)event
{
return _impl->mouseMoved(event);
}

@end // WKWebView (WKPrivateMac)

#endif // PLATFORM(MAC)
@@ -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;
@@ -121,11 +121,6 @@ - (NSMenu *)_activeMenu
return nil;
}

- (void)_simulateMouseMove:(NSEvent *)event
{
return _impl->mouseMoved(event);
}

- (void)_retrieveAccessibilityTreeData:(void (^)(NSData *, NSError *))completionHandler
{
_page->getAccessibilityTreeData([completionHandler = makeBlockPtr(completionHandler)] (API::Data* data) {
@@ -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];
}
}
}

@@ -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>

0 comments on commit fc784f4

Please sign in to comment.