From c7564a74934b980bb48e06f016554ad94856b46b Mon Sep 17 00:00:00 2001 From: Mobile DevX Robot Date: Tue, 26 Jul 2022 11:35:38 -0700 Subject: [PATCH] Internal Commit Uploaded PiperOrigin-RevId: 463388614 --- AppFramework/Action/GREYPathGestureUtils.h | 15 +++++++ AppFramework/Action/GREYPathGestureUtils.m | 6 +++ AppFramework/Action/GREYSwipeAction.h | 27 ++++++++++- AppFramework/Action/GREYSwipeAction.m | 52 +++++++++++++++++++--- 4 files changed, 91 insertions(+), 9 deletions(-) diff --git a/AppFramework/Action/GREYPathGestureUtils.h b/AppFramework/Action/GREYPathGestureUtils.h index ed24c3bd5..a3b7e1d26 100644 --- a/AppFramework/Action/GREYPathGestureUtils.h +++ b/AppFramework/Action/GREYPathGestureUtils.h @@ -62,6 +62,21 @@ NSArray *GREYTouchPathForGestureInView(UIView *view, CGPoint startPoi GREYDirection direction, CGFloat length, CGFloat *outRemainingAmountOrNull); +/** + * Generates a touch path in the given @c view from @c startPoint to @c endPoint in view-relative + * coordinates. + * + * @param window The window in which the touch path is generated. + * @param startPointInWindowCoordinates The start point in screen coordinates. + * @param endPointInWindowCoordinates The end point in screen coordinates. + * @param duration How long the gesture should last (in seconds). + * + * @return NSArray of CGPoints that denote the points in the touch path. + */ +NSArray *GREYTouchPathForGestureBetweenPoints(CGPoint startPointInScreenCoordinates, + CGPoint endPointInScreenCoordinates, + CFTimeInterval duration); + /** * Generates a touch path in the @c window from the given @c startPoint and the given @c * endPoint. diff --git a/AppFramework/Action/GREYPathGestureUtils.m b/AppFramework/Action/GREYPathGestureUtils.m index 47932c41f..ec7d28bf0 100644 --- a/AppFramework/Action/GREYPathGestureUtils.m +++ b/AppFramework/Action/GREYPathGestureUtils.m @@ -106,6 +106,12 @@ return GREYGenerateTouchPath(startPointInWindowCoordinates, endPointInWindowCoords, duration, NO); } +NSArray *GREYTouchPathForGestureBetweenPoints(CGPoint startPointInWindowCoordinates, + CGPoint endPointInWindowCoordinates, + CFTimeInterval duration) { + return GREYGenerateTouchPath(startPointInWindowCoordinates, endPointInWindowCoords, duration, NO); +} + NSArray *GREYTouchPathForDragGestureInScreen(CGPoint startPoint, CGPoint endPoint, BOOL cancelInertia) { return GREYGenerateTouchPath(startPoint, endPoint, NAN, cancelInertia); diff --git a/AppFramework/Action/GREYSwipeAction.h b/AppFramework/Action/GREYSwipeAction.h index 8fe15efe7..436f885d1 100644 --- a/AppFramework/Action/GREYSwipeAction.h +++ b/AppFramework/Action/GREYSwipeAction.h @@ -52,8 +52,8 @@ * * @param direction The direction of the swipe. * @param duration The time interval for which the swipe takes place. - * @param startPercents @c startPercents.x sets the value of the x-coordinate of the start point - * by interpolating between left(for 0.0) and right(for 1.0) edge similarly + * @param startPercents @c startPercents.x sets the value of the x coordinate of the start point + * by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly, * @c startPercents.y determines the y coordinate. * * @return An instance of GREYSwipeAction, initialized with the provided direction, duration @@ -62,4 +62,27 @@ - (instancetype)initWithDirection:(GREYDirection)direction duration:(CFTimeInterval)duration startPercents:(CGPoint)startPercents; + +/** + * Performs a swipe in the given @c direction in the given @c duration. The start of the swipe is + * specified by @c startPercents. The end of the swipe is specified by @c endPercents. Because + * swipes must begin inside the element and not on the edge of it, the values in @c startPercents + * must be in the range (0,1) exclusive. All coordinates are relative to the element's visible + * area on-screen (accessibility frame). + * + * @param direction The direction of the swipe. + * @param duration The time interval for which the swipe takes place. + * @param startPercents @c startPercents.x sets the value of the x coordinate of the start point + * by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly, + * @c startPercents.y determines the y coordinate. + * @param endPercents @c endPercents.x sets the value of the x coordinate of the end point + * by interpolating between left(for 0.0) and right(for 1.0) edge. Similarly, + * @c endPercents.y determines the y coordinate. + * + * @return An instance of GREYSwipeAction, initialized with the provided direction, duration + * and information for the start point. + */ +- (instancetype)initWithDuration:(CFTimeInterval)duration + startPercents:(CGPoint)startPercents + endPercents:(CGPoint)startPercents; @end diff --git a/AppFramework/Action/GREYSwipeAction.m b/AppFramework/Action/GREYSwipeAction.m index 2fd0f477e..fa6531159 100644 --- a/AppFramework/Action/GREYSwipeAction.m +++ b/AppFramework/Action/GREYSwipeAction.m @@ -49,15 +49,25 @@ @implementation GREYSwipeAction { * Start point for the swipe specified as percentage of swipped element's accessibility frame. */ CGPoint _startPercents; + /** + * Start point for the swipe specified as percentage of swipped element's accessibility frame. + */ + CGPoint _endPercents; + /** + * YES if end point is specified, else NO. + */ + BOOL _endPointSpecified; } - (instancetype)initWithDirection:(GREYDirection)direction duration:(CFTimeInterval)duration - percentPoint:(CGPoint)percents { - GREYThrowOnFailedConditionWithMessage(percents.x > 0.0f && percents.x < 1.0f, + startPercentPoint:(CGPoint)startPercents + endPercentPoint:(CGPoint)percents + endPointSpecified:(BOOL)endPointSpecified { + GREYThrowOnFailedConditionWithMessage(startPercents.x > 0.0f && startPercents.x < 1.0f, @"xOriginStartPercentage must be between 0 and 1, " @"exclusively"); - GREYThrowOnFailedConditionWithMessage(percents.y > 0.0f && percents.y < 1.0f, + GREYThrowOnFailedConditionWithMessage(startPercents.y > 0.0f && startPercents.y < 1.0f, @"yOriginStartPercentage must be between 0 and 1, " @"exclusively"); @@ -82,20 +92,40 @@ - (instancetype)initWithDirection:(GREYDirection)direction if (self) { _direction = direction; _duration = duration; - _startPercents = percents; + _startPercents = startPercents; + _endPercents = endPercents; + _endPointSpecified = endPointSpecified; } return self; } - (instancetype)initWithDirection:(GREYDirection)direction duration:(CFTimeInterval)duration { // TODO: Pick a visible point instead of picking the center of the view. - return [self initWithDirection:direction duration:duration percentPoint:CGPointMake(0.5, 0.5)]; + return [self initWithDirection:direction + duration:duration + startPercentPoint:CGPointMake(0.5, 0.5) + endPercentPoint:CGPointMake(0.0, 0.0) + endPointSpecified:NO]; } - (instancetype)initWithDirection:(GREYDirection)direction duration:(CFTimeInterval)duration startPercents:(CGPoint)startPercents { - return [self initWithDirection:direction duration:duration percentPoint:startPercents]; + return [self initWithDirection:direction + duration:duration + startPercentPoint:startPercents + endPercentPoint:CGPointMake(0.0, 0.0) + endPointSpecified:NO]; +} + +- (instancetype)initWithDuration:(CFTimeInterval)duration + startPercents:(CGPoint)startPercents + endPercents:(CGPoint)endPercents { + return [self initWithDirection:GREYDirectionLeft + duration:duration + startPercentPoint:startPercents + endPercentPoint:endPercents + endPointSpecified:YES]; } #pragma mark - GREYAction @@ -150,7 +180,15 @@ - (NSArray *)touchPath:(UIView *)element forWindow:(UIWindow *)window { CGPointMake(accessibilityFrame.origin.x + accessibilityFrame.size.width * _startPercents.x, accessibilityFrame.origin.y + accessibilityFrame.size.height * _startPercents.y); - return GREYTouchPathForGestureInWindow(window, startPoint, _direction, _duration); + if (!_endPointSpecified) { + return GREYTouchPathForGestureInWindow(window, startPoint, _direction, _duration); + } + + CGPoint endPoint = + CGPointMake(accessibilityFrame.origin.x + accessibilityFrame.size.width * _endPercents.x, + accessibilityFrame.origin.y + accessibilityFrame.size.height * _endPercents.y); + + return GREYTouchPathForGestureBetweenPoints(startPoint, endPoint, _duration); } - (BOOL)shouldRunOnMainThread {