From 471ad8400f9ba1ef508dc05eae998bd6b8175cc0 Mon Sep 17 00:00:00 2001 From: Andy Wickham Date: Sat, 22 Feb 2025 02:20:55 +0000 Subject: [PATCH] Update NavHandle tests to use more conservative timings. On some devices, the long press would trigger due to an overly long wait in the test. Separately, the small slop tests were using a slop that would trigger the second stage if that flag was enabled, so the trigger didn't happen (WAI). We already test 2 stage, so I updated these tests to use a smaller slop that should not trigger with or without 2 stage. Test: atest NexusLauncherTests:com.android.quickstep.inputconsumers.NavHandleLongPressInputConsumerTest -- --abi arm64-v8a Flag: EXEMPT tests Fix: 398216382 Change-Id: Iec633d01eff63eac8ba072fef4ac1e7b452d8242 --- .../NavHandleLongPressInputConsumerTest.java | 75 +++++++------------ 1 file changed, 29 insertions(+), 46 deletions(-) diff --git a/quickstep/tests/multivalentTests/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumerTest.java b/quickstep/tests/multivalentTests/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumerTest.java index de6920bd46..99a34ea69c 100644 --- a/quickstep/tests/multivalentTests/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumerTest.java +++ b/quickstep/tests/multivalentTests/src/com/android/quickstep/inputconsumers/NavHandleLongPressInputConsumerTest.java @@ -28,6 +28,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH import static com.android.launcher3.logging.StatsLogManager.LauncherLatencyEvent.LAUNCHER_LATENCY_CONTEXTUAL_SEARCH_LPNH_ABANDON; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.quickstep.DeviceConfigWrapper.DEFAULT_LPNH_TIMEOUT_MS; +import static com.android.quickstep.inputconsumers.NavHandleLongPressInputConsumer.MIN_TIME_TO_LOG_ABANDON_MS; import static com.google.common.truth.Truth.assertThat; @@ -147,8 +148,7 @@ public class NavHandleLongPressInputConsumerTest { public void testDelegateDisallowsTouchInterceptAfterTouchDown() { // Touch down and wait the minimum abandonment time. mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - SystemClock.sleep(NavHandleLongPressInputConsumer.MIN_TIME_TO_LOG_ABANDON_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(MIN_TIME_TO_LOG_ABANDON_MS); // Delegate should still get touches unless long press is triggered. verify(mDelegate).onMotionEvent(any()); @@ -173,8 +173,7 @@ public class NavHandleLongPressInputConsumerTest { @Test public void testLongPressTriggered() { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_ACTIVE); assertTrue(mLongPressTriggered.get()); @@ -191,10 +190,8 @@ public class NavHandleLongPressInputConsumerTest { @Test public void testLongPressTriggeredWithSlightVerticalMovement() { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - mUnderTest.onMotionEvent(generateCenteredMotionEventWithYOffset(ACTION_MOVE, - -(TOUCH_SLOP - 1))); - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + mUnderTest.onMotionEvent(generateCenteredMotionEventWithYOffset(ACTION_MOVE, 1)); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_ACTIVE); assertTrue(mLongPressTriggered.get()); @@ -207,10 +204,8 @@ public class NavHandleLongPressInputConsumerTest { @Test public void testLongPressTriggeredWithSlightHorizontalMovement() { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - mUnderTest.onMotionEvent(generateMotionEvent(ACTION_MOVE, - mScreenWidth / 2f - (TOUCH_SLOP - 1), 0)); - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + mUnderTest.onMotionEvent(generateMotionEvent(ACTION_MOVE, mScreenWidth / 2f + 1, 0)); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_ACTIVE); assertTrue(mLongPressTriggered.get()); @@ -230,8 +225,7 @@ public class NavHandleLongPressInputConsumerTest { mUnderTest.onMotionEvent(generateMotionEvent(ACTION_MOVE, mScreenWidth / 2f - (TOUCH_SLOP - 1), 0)); // We have entered the second stage, so the normal timeout shouldn't trigger. - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -241,9 +235,8 @@ public class NavHandleLongPressInputConsumerTest { // After an extended time, the long press should trigger. float extendedDurationMultiplier = (DeviceConfigWrapper.get().getTwoStageDurationPercentage() / 100f); - SystemClock.sleep((long) (DEFAULT_LPNH_TIMEOUT_MS + sleep((long) (DEFAULT_LPNH_TIMEOUT_MS * (extendedDurationMultiplier - 1))); // -1 because we already waited 1x - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_ACTIVE); assertTrue(mLongPressTriggered.get()); @@ -264,8 +257,7 @@ public class NavHandleLongPressInputConsumerTest { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); // We have not entered the second stage, so the normal timeout should trigger. - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_ACTIVE); assertTrue(mLongPressTriggered.get()); @@ -281,16 +273,14 @@ public class NavHandleLongPressInputConsumerTest { @Test public void testLongPressAbortedByTouchUp() { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS - 10); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(MIN_TIME_TO_LOG_ABANDON_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_UP)); // Wait past the long press timeout, to be extra sure it wouldn't have triggered. - SystemClock.sleep(20); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -303,16 +293,14 @@ public class NavHandleLongPressInputConsumerTest { @Test public void testLongPressAbortedByTouchCancel() { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS - 10); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(MIN_TIME_TO_LOG_ABANDON_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_CANCEL)); // Wait past the long press timeout, to be extra sure it wouldn't have triggered. - SystemClock.sleep(20); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -325,8 +313,7 @@ public class NavHandleLongPressInputConsumerTest { @Test public void testLongPressAbortedByTouchSlopPassedVertically() { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS - 10); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(MIN_TIME_TO_LOG_ABANDON_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -334,8 +321,7 @@ public class NavHandleLongPressInputConsumerTest { mUnderTest.onMotionEvent(generateCenteredMotionEventWithYOffset(ACTION_MOVE, -(TOUCH_SLOP + 1))); // Wait past the long press timeout, to be extra sure it wouldn't have triggered. - SystemClock.sleep(20); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -348,8 +334,7 @@ public class NavHandleLongPressInputConsumerTest { @Test public void testLongPressAbortedByTouchSlopPassedHorizontally() { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS - 10); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(MIN_TIME_TO_LOG_ABANDON_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -357,8 +342,7 @@ public class NavHandleLongPressInputConsumerTest { mUnderTest.onMotionEvent(generateMotionEvent(ACTION_MOVE, mScreenWidth / 2f - (TOUCH_SLOP + 1), 0)); // Wait past the long press timeout, to be extra sure it wouldn't have triggered. - SystemClock.sleep(20); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -379,8 +363,7 @@ public class NavHandleLongPressInputConsumerTest { mUnderTest.onMotionEvent(generateCenteredMotionEventWithYOffset(ACTION_MOVE, -(TOUCH_SLOP - 1))); // Normal duration shouldn't trigger. - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -391,9 +374,8 @@ public class NavHandleLongPressInputConsumerTest { // Wait past the extended long press timeout, to be sure it wouldn't have triggered. float extendedDurationMultiplier = (DeviceConfigWrapper.get().getTwoStageDurationPercentage() / 100f); - SystemClock.sleep((long) (DEFAULT_LPNH_TIMEOUT_MS + sleep((long) (DEFAULT_LPNH_TIMEOUT_MS * (extendedDurationMultiplier - 1))); // -1 because we already waited 1x - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -418,8 +400,7 @@ public class NavHandleLongPressInputConsumerTest { mUnderTest.onMotionEvent(generateMotionEvent(ACTION_MOVE, mScreenWidth / 2f - (TOUCH_SLOP - 1), 0)); // Normal duration shouldn't trigger. - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -430,9 +411,8 @@ public class NavHandleLongPressInputConsumerTest { // Wait past the extended long press timeout, to be sure it wouldn't have triggered. float extendedDurationMultiplier = (DeviceConfigWrapper.get().getTwoStageDurationPercentage() / 100f); - SystemClock.sleep((long) (DEFAULT_LPNH_TIMEOUT_MS + sleep((long) (DEFAULT_LPNH_TIMEOUT_MS * (extendedDurationMultiplier - 1))); // -1 because we already waited 1x - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); assertFalse(mLongPressTriggered.get()); @@ -450,8 +430,7 @@ public class NavHandleLongPressInputConsumerTest { public void testTouchOutsideNavHandleIgnored() { // Touch the far left side of the screen. (y=0 is top of navbar region, picked arbitrarily) mUnderTest.onMotionEvent(generateMotionEvent(ACTION_DOWN, 0, 0)); - SystemClock.sleep(DEFAULT_LPNH_TIMEOUT_MS); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(DEFAULT_LPNH_TIMEOUT_MS); // Should be ignored because the x position was not centered in the navbar region. assertThat(mUnderTest.mState).isEqualTo(DelegateInputConsumer.STATE_INACTIVE); @@ -484,8 +463,7 @@ public class NavHandleLongPressInputConsumerTest { @Test public void testNoLogsForShortTouch() { mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_DOWN)); - SystemClock.sleep(10); - InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + sleep(10); mUnderTest.onMotionEvent(generateCenteredMotionEvent(ACTION_UP)); verifyNoMoreInteractions(mStatsLogManager); verifyNoMoreInteractions(mStatsLogger); @@ -509,6 +487,11 @@ public class NavHandleLongPressInputConsumerTest { mDownTimeMs = 0; } + private static void sleep(long sleepMs) { + SystemClock.sleep(sleepMs); + InstrumentationRegistry.getInstrumentation().waitForIdleSync(); + } + /** Generate a motion event centered horizontally in the screen. */ private MotionEvent generateCenteredMotionEvent(int motionAction) { return generateCenteredMotionEventWithYOffset(motionAction, 0);