Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 570d6df8 authored by Johannes Gallmann's avatar Johannes Gallmann
Browse files

Fix flaky predictive back test

The reason for the flakiness was that `onBackProgressed` was not called sometimes because the progress was already at 0f. Setting the progress to 0.5f ensures that it is animated back to 0f and thus `onBackProgressed` is definitely called.

Bug: 366251353
Test: WindowOnBackInvokedDispatcherTest
Flag: EXEMPT bugfix
Change-Id: Ia09330f54f6a61245183ce10d762b97931c76245
parent d2ed3a9c
Loading
Loading
Loading
Loading
+14 −9
Original line number Diff line number Diff line
@@ -103,15 +103,7 @@ public class WindowOnBackInvokedDispatcherTest {

    private int mCallbackInfoCalls = 0;

    private final BackMotionEvent mBackEvent = new BackMotionEvent(
            /* touchX = */ 0,
            /* touchY = */ 0,
            /* progress = */ 0,
            /* velocityX = */ 0,
            /* velocityY = */ 0,
            /* triggerBack = */ false,
            /* swipeEdge = */ BackEvent.EDGE_LEFT,
            /* departingAnimationTarget = */ null);
    private final BackMotionEvent mBackEvent = backMotionEventFrom(/* progress */ 0f);
    private final MotionEvent mMotionEvent =
            MotionEvent.obtain(0, 0, MotionEvent.ACTION_MOVE, 100, 100, 0);

@@ -558,6 +550,7 @@ public class WindowOnBackInvokedDispatcherTest {
        OnBackInvokedCallbackInfo callbackInfo = assertSetCallbackInfo();

        callbackInfo.getCallback().onBackStarted(mBackEvent);
        callbackInfo.getCallback().onBackProgressed(backMotionEventFrom(/* progress */ 0.5f));
        waitForIdle();
        assertTrue(mDispatcher.mProgressAnimator.isBackAnimationInProgress());

@@ -575,6 +568,18 @@ public class WindowOnBackInvokedDispatcherTest {
        assertFalse(mDispatcher.mProgressAnimator.isBackAnimationInProgress());
    }

    private BackMotionEvent backMotionEventFrom(float progress) {
        return new BackMotionEvent(
                /* touchX = */ 0,
                /* touchY = */ 0,
                /* progress = */ progress,
                /* velocityX = */ 0,
                /* velocityY = */ 0,
                /* triggerBack = */ false,
                /* swipeEdge = */ BackEvent.EDGE_LEFT,
                /* departingAnimationTarget = */ null);
    }

    private void verifyImeCallackRegistrations() throws RemoteException {
        // verify default callback is replaced with ImeBackAnimationController
        mDispatcher.registerOnBackInvokedCallbackUnchecked(mDefaultImeCallback, PRIORITY_DEFAULT);