Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
[ iOS ] editing/selection/ios/show-callout-bar-after-selecting-word.h…
…tml is a flaky timeout https://bugs.webkit.org/show_bug.cgi?id=240544 rdar://93458507 Reviewed by Aditya Keerthi. Currently, any LayoutTest that attempts to wait for (or interact with) the callout bar after selecting text fails, due to the fact that on iOS 16, the callout bar is implemented using a `UIEditMenuInteraction` on the content view, which doesn't use the extant classes for managing and observing callout bar UI -- i.e. `UIMenuController`, `UICalloutBar` and the associated global notifications. Unfortunately, when using iOS 16, there are no longer any global notifications that the test harness can listen for to detect when the callout bar has been presented or dismissed. To keep these tests passing on iOS 16, we introduce a mechanism to the test harness to intercept edit menu interaction delegate method calls, and notify `TestController` when the edit menu has completed its presention or dismissal animations. Also, tweak a flaky layout test that exercises this logic to be more robust — see below for more detail. * LayoutTests/editing/selection/ios/show-callout-bar-after-selecting-word.html: Additionally, adjust this layout test to explicitly wait for the 'Select' menu action before trying to select that item -- this might mitigate potential flakiness on iOS 15, due to calling `UIHelper.chooseMenuAction()` too early. * Source/WTF/wtf/PlatformHave.h: Add a new build-time flag to guard the availability of `UIEditMenuInteraction`. * Tools/WebKitTestRunner/TestController.h: * Tools/WebKitTestRunner/WebKitTestRunner.xcodeproj/project.pbxproj: * Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.h: * Tools/WebKitTestRunner/cocoa/TestRunnerWKWebView.mm: (-[TestRunnerWKWebView textEffectsWindow]): Add a helper method to return the web view's associated text effects window. This is used below in `TestController` when recursively searching the view hierarchy for callout menu buttons with a given label string (e.g. "Select", "Select All", "Copy", etc.), because these buttons and labels now exist within the view hierarchy of the `UITextEffectsWindow` on iOS 16, when using the edit menu interaction. (-[TestRunnerWKWebView currentEditMenuInteraction]): Add a helper method to grab the edit menu interaction corresponding to text selection on the content view. (-[TestRunnerWKWebView didPresentEditMenuInteraction:]): (-[TestRunnerWKWebView didDismissEditMenuInteraction:]): Plumb into the existing `-_didHideMenu` and `-_didShowMenu` methods, which we currently use to observe callout bar presentation and dismissal. This allows the test harness to simultaneously support iOS 15 and iOS 16, for layout tests that exercise the callout bar. (-[TestRunnerWKWebView immediatelyDismissEditMenuInteractionIfNeeded]): Add a hook to immediately dismiss the callout bar between layout tests, that is compatible with UIEditMenuInteraction-backed callout bars. * Tools/WebKitTestRunner/ios/EditMenuInteractionSwizzler.h: Added. * Tools/WebKitTestRunner/ios/EditMenuInteractionSwizzler.mm: Added. Add a helper class to swizzle `-[UIEditMenuInteraction initWithDelegate:]`, and call the original method implementation with an object that wraps the given `UIEditMenuInteractionDelegate` in another object (`EditMenuInteractionDelegateWrapper`) that forwards all selector invocations to the original delegate (in practice: `_UIContextMenuInteractionBasedTextContextInteraction`), but additionally implements the `-willPresentMenuForConfiguration:` and `-willDismissMenuForConfiguration:` delegate hooks and adds animation completion blocks that call out to the global `TestController`. This allows us to passively observe calls to `-editMenuInteraction:(will|did)PresentMenuForConfiguration:animator:`, without affecting the internal UIKit implementation of the text interaction assistant's edit menu interaction. (-[EditMenuInteractionDelegateWrapper initWithDelegate:]): (-[EditMenuInteractionDelegateWrapper forwardInvocation:]): (-[EditMenuInteractionDelegateWrapper respondsToSelector:]): (-[EditMenuInteractionDelegateWrapper methodSignatureForSelector:]): (-[EditMenuInteractionDelegateWrapper editMenuInteraction:willPresentMenuForConfiguration:animator:]): (-[EditMenuInteractionDelegateWrapper editMenuInteraction:willDismissMenuForConfiguration:animator:]): (-[UIEditMenuInteraction swizzled_initWithDelegate:]): (WTR::EditMenuInteractionSwizzler::EditMenuInteractionSwizzler): (WTR::EditMenuInteractionSwizzler::~EditMenuInteractionSwizzler): * Tools/WebKitTestRunner/ios/TestControllerIOS.mm: (WTR::TestController::platformInitialize): Initialize the edit menu interaction swizzler. (WTR::TestController::platformResetStateToConsistentValues): (WTR::TestController::didPresentEditMenuInteraction): (WTR::TestController::didDismissEditMenuInteraction): * Tools/WebKitTestRunner/ios/UIScriptControllerIOS.mm: (WTR::UIScriptControllerIOS::rectForMenuAction const): Canonical link: https://commits.webkit.org/251737@main git-svn-id: https://svn.webkit.org/repository/webkit/trunk@295732 268f45cc-cd09-0410-ab3c-d52691b4dbfc
- Loading branch information