Skip to content

Commit

Permalink
[iOS] Suppress excessive logging due to calling into `-[UITextInterac…
Browse files Browse the repository at this point in the history
…tionAssistant selectionView]` in API tests

https://bugs.webkit.org/show_bug.cgi?id=263266

Reviewed by Aditya Keerthi.

Swizzle out `-[UITextInteractionAssistant selectionView]` to return `nil` without added logging.
When `UIKit/redesigned_text_cursor` is enabled, this method already returns `nil` anyways, and
the feature flag is enabled by default everywhere where `HAVE(UI_TEXT_SELECTION_DISPLAY_INTERACTION)`
is set.

* Tools/TestRunnerShared/spi/UIKitSPIForTesting.h:
* Tools/TestWebKitAPI/ios/mainIOS.mm:
(overrideSelectionViewToSuppressLogging):
(main):
* Tools/WebKitTestRunner/ios/mainIOS.mm:
(overrideSelectionViewToSuppressLogging):
(main):

Canonical link: https://commits.webkit.org/269422@main
  • Loading branch information
whsieh committed Oct 17, 2023
1 parent 49618d4 commit dc17de8
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 3 deletions.
4 changes: 4 additions & 0 deletions Tools/TestRunnerShared/spi/UIKitSPIForTesting.h
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,10 @@ typedef enum {

// Start of UIKit IPI

@interface UITextInteractionAssistant (IPI)
@property (nonatomic, readonly) UIView *selectionView;
@end

@interface UITextAutofillSuggestion ()
+ (instancetype)autofillSuggestionWithUsername:(NSString *)username password:(NSString *)password;
@end
Expand Down
25 changes: 22 additions & 3 deletions Tools/TestWebKitAPI/ios/mainIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,28 @@
*/

#import "config.h"

#import "TestsController.h"
#import "UIKitMacHelperSPI.h"
#import "UIKitSPIForTesting.h"
#import <objc/runtime.h>
#import <wtf/RetainPtr.h>

#if !defined(BUILDING_TEST_IPC) && !defined(BUILDING_TEST_WTF) && !defined(BUILDING_TEST_WGSL)
#if defined(BUILDING_TEST_IPC) || defined(BUILDING_TEST_WTF) || defined(BUILDING_TEST_WGSL)
#define BUILDING_FOR_UI_TESTING 0
#else
#define BUILDING_FOR_UI_TESTING 1
#endif

#if BUILDING_FOR_UI_TESTING
#import <WebKit/WKProcessPoolPrivate.h>
#if HAVE(UI_TEXT_SELECTION_DISPLAY_INTERACTION)
static UIView *overrideSelectionViewToSuppressLogging(id, SEL)
{
return nil;
}
#endif
#endif // BUILDING_FOR_UI_TESTING

int main(int argc, char** argv)
{
Expand All @@ -49,9 +64,13 @@ int main(int argc, char** argv)

[[NSUserDefaults standardUserDefaults] setVolatileDomain:argumentDomain.get() forName:NSArgumentDomain];

#if !defined(BUILDING_TEST_IPC) && !defined(BUILDING_TEST_WTF) && !defined(BUILDING_TEST_WGSL)
[WKProcessPool _setLinkedOnOrAfterEverythingForTesting];
#if BUILDING_FOR_UI_TESTING
#if HAVE(UI_TEXT_SELECTION_DISPLAY_INTERACTION)
auto method = class_getInstanceMethod(UITextInteractionAssistant.class, @selector(selectionView));
method_setImplementation(method, reinterpret_cast<IMP>(overrideSelectionViewToSuppressLogging));
#endif
[WKProcessPool _setLinkedOnOrAfterEverythingForTesting];
#endif // BUILDING_FOR_UI_TESTING

passed = TestWebKitAPI::TestsController::singleton().run(argc, argv);
}
Expand Down
13 changes: 13 additions & 0 deletions Tools/WebKitTestRunner/ios/mainIOS.mm
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#import "TestController.h"
#import "UIKitSPIForTesting.h"
#import <WebKit/WKProcessPoolPrivate.h>
#import <objc/runtime.h>

static int _argc;
static const char **_argv;
Expand Down Expand Up @@ -64,13 +65,25 @@ - (void)_handleHIDEvent:(IOHIDEventRef)event

@end

#if HAVE(UI_TEXT_SELECTION_DISPLAY_INTERACTION)
static UIView *overrideSelectionViewToSuppressLogging(id, SEL)
{
return nil;
}
#endif

int main(int argc, const char* argv[])
{
_argc = argc;
_argv = argv;

[WKProcessPool _setLinkedOnOrAfterEverythingForTesting];

#if HAVE(UI_TEXT_SELECTION_DISPLAY_INTERACTION)
auto method = class_getInstanceMethod(UITextInteractionAssistant.class, @selector(selectionView));
method_setImplementation(method, reinterpret_cast<IMP>(overrideSelectionViewToSuppressLogging));
#endif

UIApplicationMain(argc, (char**)argv, @"WebKitTestRunnerApp", @"WebKitTestRunnerApp");
return 0;
}

0 comments on commit dc17de8

Please sign in to comment.