From befcfa40b9445bbbfb36818e0a715a1e9761e9b5 Mon Sep 17 00:00:00 2001 From: vadimt Date: Mon, 19 Dec 2022 18:02:07 -0800 Subject: [PATCH] Not waiting for animations for Launcher clicks Waiting for animations to finish can make the test wait for too long if there is an ongoing animation somewhere, for example, in an app we are trying to swipe from. Test: presubmit Bug: 256567004 Change-Id: Ida494128a18342bee3dbdae6d713c854c86912c1 --- .../launcher3/tapl/AddToHomeScreenPrompt.java | 3 ++- .../tapl/LauncherInstrumentation.java | 23 +++++++++++-------- .../com/android/launcher3/tapl/Workspace.java | 2 +- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java b/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java index 98eb32e818..10afe13d62 100644 --- a/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java +++ b/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java @@ -45,7 +45,8 @@ public class AddToHomeScreenPrompt { mLauncher.clickObject( mLauncher.waitForObjectInContainer( mWidgetCell.getParent().getParent().getParent().getParent(), - By.text(ADD_AUTOMATICALLY))); + By.text(ADD_AUTOMATICALLY)), + LauncherInstrumentation.GestureScope.OUTSIDE_WITHOUT_PILFER); mLauncher.waitUntilLauncherObjectGone(getSelector()); } } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 302fabd92a..ae9ba6787b 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -1466,19 +1466,22 @@ public final class LauncherInstrumentation { return getRealDisplaySize().x - getWindowInsets().right - 1; } - void clickObject(UiObject2 object) { - waitForObjectEnabled(object, "clickObject"); - if (!isLauncher3() && getNavigationModel() != NavigationModel.THREE_BUTTON) { - expectEvent(TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_DOWN_TIS); - expectEvent(TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_UP_TIS); - } - object.click(); + /** + * Click on the ui object right away without waiting for animation. + * + * [UiObject2.click] would wait for all animations finished before clicking. Not waiting for + * animations because in some scenarios there is a playing animations when the click is + * attempted. + */ + void clickObject(UiObject2 uiObject, GestureScope gestureScope) { + final long clickTime = SystemClock.uptimeMillis(); + final Point center = uiObject.getVisibleCenter(); + sendPointer(clickTime, clickTime, MotionEvent.ACTION_DOWN, center, gestureScope); + sendPointer(clickTime, clickTime, MotionEvent.ACTION_UP, center, gestureScope); } void clickLauncherObject(UiObject2 object) { - expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_TOUCH_DOWN); - expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_TOUCH_UP); - clickObject(object); + clickObject(object, GestureScope.INSIDE); } void scrollToLastVisibleRow( diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index b2a2937396..2c82c50eca 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -385,7 +385,7 @@ public final class Workspace extends Home { Until.hasObject(installerAlert), LauncherInstrumentation.WAIT_TIME_MS)); final UiObject2 ok = device.findObject(By.text("OK")); assertNotNull("OK button is not shown", ok); - launcher.clickObject(ok); + launcher.clickObject(ok, LauncherInstrumentation.GestureScope.OUTSIDE_WITHOUT_PILFER); assertTrue("Uninstall alert is not dismissed after clicking OK", device.wait( Until.gone(installerAlert), LauncherInstrumentation.WAIT_TIME_MS));