Skip to content

Commit

Permalink
TestWebKitAPI.WKScrollViewTests.AsynchronousWheelEventHandling fails …
Browse files Browse the repository at this point in the history
…on iOS Simulator

https://bugs.webkit.org/show_bug.cgi?id=273739
rdar://127547694

Reviewed by Abrar Rahman Protyasha and Aditya Keerthi.

The initializer `-[BEScrollViewScrollUpdate initWithScrollEvent:phase:]` is marked `NS_DIRECT` in
BrowserEngineKit, so attempts to initialize a scroll update for testing fail due to invoking an
unrecognized selector (in 273582@main, I'd previously been testing against a local debug build of
BrowserEngineKit that did not inline this initializer, so the test was passing as expected).

Fix this by adjusting the testing strategy, so that we instead initialize a mock Objective-C object
(`WKTestScrollViewScrollUpdate`) which implements identical functionality.

* Tools/TestWebKitAPI/Tests/ios/WKScrollViewTests.mm:
(-[WKTestScrollViewScrollUpdate initWithScrollEvent:phase:]):
(-[WKTestScrollViewScrollUpdate phase]):
(-[WKTestScrollViewScrollUpdate timestamp]):
(-[WKTestScrollViewScrollUpdate locationInView:]):
(-[WKTestScrollViewScrollUpdate translationInView:]):
(createScrollUpdate):
(TEST(WKScrollViewTests, AsynchronousWheelEventHandling)):

Canonical link: https://commits.webkit.org/278426@main
  • Loading branch information
whsieh committed May 6, 2024
1 parent 47876c1 commit 5d88444
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 9 deletions.
2 changes: 2 additions & 0 deletions Tools/TestRunnerShared/spi/UIKitSPIForTesting.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ typedef NS_ENUM(NSUInteger, UIScrollPhase) {
};

@interface UIScrollEvent : UIEvent
- (CGPoint)locationInView:(UIView *)view;
- (CGVector)_adjustedAcceleratedDeltaInView:(UIView *)view;
@end

@interface UITextInteractionAssistant : NSObject <UIResponderStandardEditActions>
Expand Down
69 changes: 60 additions & 9 deletions Tools/TestWebKitAPI/Tests/ios/WKScrollViewTests.mm
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,65 @@
constexpr CGFloat whiteColorComponents[4] = { 1, 1, 1, 1 };

#if HAVE(UISCROLLVIEW_ASYNCHRONOUS_SCROLL_EVENT_HANDLING)

#if USE(BROWSERENGINEKIT)

@interface WKTestScrollViewScrollUpdate : NSObject

- (instancetype)initWithScrollEvent:(UIScrollEvent *)scrollEvent phase:(BEScrollViewScrollUpdatePhase)phase;
- (CGPoint)locationInView:(UIView *)view;
- (CGPoint)translationInView:(UIView *)view;

@property (nonatomic, readonly) NSTimeInterval timestamp;
@property (nonatomic, readonly) BEScrollViewScrollUpdatePhase phase;

@end

@implementation WKTestScrollViewScrollUpdate {
RetainPtr<UIScrollEvent> _scrollEvent;
BEScrollViewScrollUpdatePhase _phase;
}

- (UIScrollEvent *)_scrollEvent
{
return _scrollEvent.get();
}

- (instancetype)initWithScrollEvent:(UIScrollEvent *)scrollEvent phase:(BEScrollViewScrollUpdatePhase)phase
{
if (!(self = [super init]))
return nil;

_scrollEvent = scrollEvent;
_phase = phase;
return self;
}

- (BEScrollViewScrollUpdatePhase)phase
{
return _phase;
}

- (NSTimeInterval)timestamp
{
return [_scrollEvent timestamp];
}

- (CGPoint)locationInView:(UIView *)view
{
return [_scrollEvent locationInView:view];
}

- (CGPoint)translationInView:(UIView *)view
{
CGVector adjustedAcceleratedDelta = [_scrollEvent _adjustedAcceleratedDeltaInView:view];
return CGPointMake(adjustedAcceleratedDelta.dx, adjustedAcceleratedDelta.dy);
}

@end

#endif // USE(BROWSERENGINEKIT)

@interface WKUIScrollEvent : UIScrollEvent

- (instancetype)initWithPhase:(UIScrollPhase)phase location:(CGPoint)location delta:(CGVector)delta;
Expand Down Expand Up @@ -80,14 +139,6 @@ - (CGVector)_adjustedAcceleratedDeltaInView:(UIView *)view

@end

#if USE(BROWSERENGINEKIT)

@interface WKBEScrollViewScrollUpdate (Internal)
- (instancetype)initWithScrollEvent:(UIScrollEvent *)scrollEvent phase:(WKBEScrollViewScrollUpdatePhase)phase;
@end

#endif

inline static UIScrollPhase legacyScrollPhase(WKBEScrollViewScrollUpdatePhase phase)
{
#if USE(BROWSERENGINEKIT)
Expand All @@ -112,7 +163,7 @@ inline static UIScrollPhase legacyScrollPhase(WKBEScrollViewScrollUpdatePhase ph
{
auto event = adoptNS([[WKUIScrollEvent alloc] initWithPhase:legacyScrollPhase(phase) location:location delta:delta]);
#if USE(BROWSERENGINEKIT)
return adoptNS([[WKBEScrollViewScrollUpdate alloc] initWithScrollEvent:event.get() phase:phase]);
return adoptNS(static_cast<BEScrollViewScrollUpdate *>([[WKTestScrollViewScrollUpdate alloc] initWithScrollEvent:event.get() phase:phase]));
#else
return event;
#endif
Expand Down

0 comments on commit 5d88444

Please sign in to comment.