Title: [263929] trunk/Tools
- Revision
- 263929
- Author
- [email protected]
- Date
- 2020-07-03 23:38:53 -0700 (Fri, 03 Jul 2020)
Log Message
[macOS] Tests that show system menu popups may fail when run concurrently
https://bugs.webkit.org/show_bug.cgi?id=213950
<rdar://problem/64551566>
Reviewed by Darin Adler.
Make it possible to run tests that present system modal popups simultaneously, without the possibility of these
tests interfering with each other. Examples include context menus, select menus, and the DOM paste popup. To do
this, we swizzle out codepaths for showing and dimissing popups, and instead dispatch notifications and the
appropriate NSMenuDelegate methods ourselves.
This change has the side effect of fixing several layout tests that are currently timing out only on arm64e
macOS, due to reasons detailed in <rdar://problem/65084503>.
* WebKitTestRunner/mac/TestControllerMac.mm:
(WTR::setSwizzledPopUpMenu):
(WTR::swizzledPopUpContextMenu):
(WTR::swizzledPopUpMenu):
(WTR::swizzledCancelTracking):
(WTR::TestController::platformInitialize):
Modified Paths
Diff
Modified: trunk/Tools/ChangeLog (263928 => 263929)
--- trunk/Tools/ChangeLog 2020-07-04 05:15:52 UTC (rev 263928)
+++ trunk/Tools/ChangeLog 2020-07-04 06:38:53 UTC (rev 263929)
@@ -1,3 +1,26 @@
+2020-07-03 Wenson Hsieh <[email protected]>
+
+ [macOS] Tests that show system menu popups may fail when run concurrently
+ https://bugs.webkit.org/show_bug.cgi?id=213950
+ <rdar://problem/64551566>
+
+ Reviewed by Darin Adler.
+
+ Make it possible to run tests that present system modal popups simultaneously, without the possibility of these
+ tests interfering with each other. Examples include context menus, select menus, and the DOM paste popup. To do
+ this, we swizzle out codepaths for showing and dimissing popups, and instead dispatch notifications and the
+ appropriate NSMenuDelegate methods ourselves.
+
+ This change has the side effect of fixing several layout tests that are currently timing out only on arm64e
+ macOS, due to reasons detailed in <rdar://problem/65084503>.
+
+ * WebKitTestRunner/mac/TestControllerMac.mm:
+ (WTR::setSwizzledPopUpMenu):
+ (WTR::swizzledPopUpContextMenu):
+ (WTR::swizzledPopUpMenu):
+ (WTR::swizzledCancelTracking):
+ (WTR::TestController::platformInitialize):
+
2020-07-03 Sam Weinig <[email protected]>
Remove support for ENABLE_INPUT_TYPE_DATETIME_INCOMPLETE
Modified: trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm (263928 => 263929)
--- trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm 2020-07-04 05:15:52 UTC (rev 263928)
+++ trunk/Tools/WebKitTestRunner/mac/TestControllerMac.mm 2020-07-04 06:38:53 UTC (rev 263929)
@@ -69,6 +69,47 @@
return WTR::PlatformWebView::keyWindow();
}
+static __weak NSMenu *gCurrentPopUpMenu = nil;
+static void setSwizzledPopUpMenu(NSMenu *menu)
+{
+ if (gCurrentPopUpMenu == menu)
+ return;
+
+ if ([menu.delegate respondsToSelector:@selector(menuWillOpen:)])
+ [menu.delegate menuWillOpen:menu];
+
+ gCurrentPopUpMenu = menu;
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[NSNotificationCenter defaultCenter] postNotificationName:NSMenuDidBeginTrackingNotification object:nil];
+ });
+}
+
+static void swizzledPopUpContextMenu(Class, SEL, NSMenu *menu, NSEvent *, NSView *)
+{
+ setSwizzledPopUpMenu(menu);
+}
+
+static void swizzledPopUpMenu(id, SEL, NSMenu *menu, NSPoint, CGFloat, NSView *, NSInteger, NSFont *, NSUInteger, NSDictionary *)
+{
+ setSwizzledPopUpMenu(menu);
+}
+
+static void swizzledCancelTracking(NSMenu *menu, SEL)
+{
+ if (menu != gCurrentPopUpMenu)
+ return;
+
+ gCurrentPopUpMenu = nil;
+
+ if ([menu.delegate respondsToSelector:@selector(menuDidClose:)])
+ [menu.delegate menuDidClose:menu];
+
+ dispatch_async(dispatch_get_main_queue(), ^{
+ [[NSNotificationCenter defaultCenter] postNotificationName:NSMenuDidEndTrackingNotification object:nil];
+ });
+}
+
void TestController::platformInitialize()
{
poseAsClass("WebKitTestRunnerPasteboard", "NSPasteboard");
@@ -87,6 +128,14 @@
}
method_setImplementation(keyWindowMethod, (IMP)wtr_NSApplication_keyWindow);
+
+ static InstanceMethodSwizzler cancelTrackingSwizzler { NSMenu.class, @selector(cancelTracking), reinterpret_cast<IMP>(swizzledCancelTracking) };
+ static ClassMethodSwizzler menuPopUpSwizzler { NSMenu.class, @selector(popUpContextMenu:withEvent:forView:), reinterpret_cast<IMP>(swizzledPopUpContextMenu) };
+ static InstanceMethodSwizzler carbonMenuPopUpSwizzler {
+ NSClassFromString(@"NSCarbonMenuImpl"),
+ NSSelectorFromString(@"popUpMenu:atLocation:width:forView:withSelectedItem:withFont:withFlags:withOptions:"),
+ reinterpret_cast<IMP>(swizzledPopUpMenu)
+ };
}
void TestController::platformDestroy()
_______________________________________________
webkit-changes mailing list
[email protected]
https://lists.webkit.org/mailman/listinfo/webkit-changes