Fix errors in AccessibilityGestureDispatchTest
Gesture dispatch has been updated to be more granular for
AccessibilityService instances targeting R or later. The granularity is
determined by the refresh rate of the device. As such it can generate
much smaller slices in time between frames of the gesture. This has
resulted in AccessibilityGestureDispatchTest failing due to the inexact
nature of floating point representations.
Test: atest
Bug: 150190594
Change-Id: I680f8252ec83cc8a01e85c51fd582b0c8b7ba038
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
index aac61c4..10c7542 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
@@ -217,6 +217,7 @@
return;
}
+ float pointTolerance = 1f;
PointF startPoint = new PointF(mStartPoint.x, mStartPoint.y);
PointF endPoint = new PointF(mStartPoint.x + 10, mStartPoint.y + 20);
int gestureTime = 500;
@@ -229,8 +230,9 @@
MotionEvent downEvent = mMotionEvents.get(0);
MotionEvent upEvent = mMotionEvents.get(numEvents - 1);
- assertThat(downEvent, both(IS_ACTION_DOWN).and(isAtPoint(startPoint)));
- assertThat(upEvent, both(IS_ACTION_UP).and(isAtPoint(endPoint)));
+ assertThat(downEvent, both(IS_ACTION_DOWN).and(isAtPoint(startPoint,
+ pointTolerance)));
+ assertThat(upEvent, both(IS_ACTION_UP).and(isAtPoint(endPoint, pointTolerance)));
assertEquals(gestureTime, upEvent.getEventTime() - downEvent.getEventTime());
long lastEventTime = downEvent.getEventTime();
@@ -240,8 +242,9 @@
float fractionOfSwipe =
((float) (moveEvent.getEventTime() - downEvent.getEventTime())) / gestureTime;
PointF intermediatePoint = add(startPoint,
- ceil(times(fractionOfSwipe, diff(endPoint, startPoint))));
- assertThat(moveEvent, both(IS_ACTION_MOVE).and(isAtPoint(intermediatePoint)));
+ times(fractionOfSwipe, diff(endPoint, startPoint)));
+ assertThat(moveEvent, both(IS_ACTION_MOVE).and(
+ isAtPoint(intermediatePoint, pointTolerance)));
lastEventTime = moveEvent.getEventTime();
}
}