diff options
author | Vadim Tryshev <vadimt@google.com> | 2018-08-30 16:01:47 -0700 |
---|---|---|
committer | vadimt <vadimt@google.com> | 2019-05-07 17:53:24 -0700 |
commit | 080f818642ddb9b815b8472a8a54db08a36ac6bf (patch) | |
tree | 2ef3ef6cd7124bf0ed716f2fec64cd901152ae32 /tests | |
parent | bb036f8e5ac8f7b5f02022260aca69eb3c03d240 (diff) | |
download | android_packages_apps_Trebuchet-080f818642ddb9b815b8472a8a54db08a36ac6bf.tar.gz android_packages_apps_Trebuchet-080f818642ddb9b815b8472a8a54db08a36ac6bf.tar.bz2 android_packages_apps_Trebuchet-080f818642ddb9b815b8472a8a54db08a36ac6bf.zip |
Reducing flakiness of swipe gestures
Swipe to home now injects a fixed number of points even if the test
thread wakes up irregularly, and sends model (not actual) time in
events.
Bug: 132173901
Bug: 132107664
Change-Id: I0a19bbc2a0c3312f353ad49ebe496eef1f172276
Diffstat (limited to 'tests')
3 files changed, 34 insertions, 10 deletions
diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index 3b2a7b8d1..60d2850b4 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -78,7 +78,8 @@ public class Background extends LauncherInstrumentation.VisibleContainer { final long downTime = SystemClock.uptimeMillis(); mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start); - mLauncher.movePointer(downTime, ZERO_BUTTON_SWIPE_UP_GESTURE_DURATION, start, end); + mLauncher.movePointer( + downTime, downTime, ZERO_BUTTON_SWIPE_UP_GESTURE_DURATION, start, end); LauncherInstrumentation.sleep(ZERO_BUTTON_SWIPE_UP_HOLD_DURATION); mLauncher.sendPointer( downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, end); diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 87ef0448b..fd2eabbb0 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -70,6 +70,7 @@ public final class LauncherInstrumentation { private static final String TAG = "Tapl"; private static final int ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME = 20; + private static final int GESTURE_STEP_MS = 16; // Types for launcher containers that the user is interacting with. "Background" is a // pseudo-container corresponding to inactive launcher covered by another app. @@ -359,7 +360,7 @@ public final class LauncherInstrumentation { ? NORMAL_STATE_ORDINAL : BACKGROUND_APP_STATE_ORDINAL; final Point displaySize = getRealDisplaySize(); - swipe( + swipeViaMovePointer( displaySize.x / 2, displaySize.y - 1, displaySize.x / 2, 0, finalState, ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME); @@ -543,8 +544,28 @@ public final class LauncherInstrumentation { } void swipe(int startX, int startY, int endX, int endY, int expectedState, int steps) { + changeStateViaGesture(startX, startY, endX, endY, expectedState, + () -> mDevice.swipe(startX, startY, endX, endY, steps)); + } + + void swipeViaMovePointer( + int startX, int startY, int endX, int endY, int expectedState, int steps) { + changeStateViaGesture(startX, startY, endX, endY, expectedState, () -> { + final long downTime = SystemClock.uptimeMillis(); + final Point start = new Point(startX, startY); + final Point end = new Point(endX, endY); + sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, start); + final long endTime = movePointer(downTime, downTime, steps * GESTURE_STEP_MS, start, + end); + sendPointer( + downTime, endTime, MotionEvent.ACTION_UP, end); + }); + } + + private void changeStateViaGesture(int startX, int startY, int endX, int endY, + int expectedState, Runnable gesture) { final Bundle parcel = (Bundle) executeAndWaitForEvent( - () -> mDevice.swipe(startX, startY, endX, endY, steps), + gesture, event -> TestProtocol.SWITCHED_TO_STATE_MESSAGE.equals(event.getClassName()), "Swipe failed to receive an event for the swipe end: " + startX + ", " + startY + ", " + endX + ", " + endY); @@ -589,21 +610,22 @@ public final class LauncherInstrumentation { event.recycle(); } - void movePointer(long downTime, long duration, Point from, Point to) { + long movePointer(long downTime, long startTime, long duration, Point from, Point to) { final Point point = new Point(); - final long startTime = SystemClock.uptimeMillis(); - for (; ; ) { - sleep(16); + long steps = duration / GESTURE_STEP_MS; + long currentTime = startTime; + for (long i = 0; i < steps; ++i) { + sleep(GESTURE_STEP_MS); - final long currentTime = SystemClock.uptimeMillis(); + currentTime += GESTURE_STEP_MS; final float progress = (currentTime - startTime) / (float) duration; - if (progress > 1) return; point.x = from.x + (int) (progress * (to.x - from.x)); point.y = from.y + (int) (progress * (to.y - from.y)); sendPointer(downTime, currentTime, MotionEvent.ACTION_MOVE, point); } + return currentTime; } public static boolean isGesturalMode(Context context) { diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 9a47aef30..e8a0b5468 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -150,7 +150,8 @@ public final class Workspace extends Home { LauncherInstrumentation.log("dragIconToWorkspace: sent down"); launcher.waitForLauncherObject(longPressIndicator); LauncherInstrumentation.log("dragIconToWorkspace: indicator"); - launcher.movePointer(downTime, DRAG_DURACTION, launchableCenter, dest); + launcher.movePointer( + downTime, SystemClock.uptimeMillis(), DRAG_DURACTION, launchableCenter, dest); LauncherInstrumentation.log("dragIconToWorkspace: moved pointer"); launcher.sendPointer( downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, dest); |