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

Commit 738ea65a authored by AI test gen's avatar AI test gen Committed by Ang Li
Browse files

Add tests for in-transition back navigation retries

Adds unit tests for the `TransitionIdleRunner` logic, which handles retrying a call to `startBackNavigation` when the system is already in the middle of a transition.

The new tests verify:
- A retry is correctly scheduled and executed when transitions become idle.
- A scheduled retry is correctly cancelled if the back gesture finishes before the retry can be executed.

Please help fill out the survey for feedback: https://docs.google.com/forms/d/e/1FAIpQLSeKFKpHImCAqZIa_OR801cw72HQUreM2oGM25C3mKKT2tBFnw/viewform?usp=pp_url&entry.1586624956=ag/35413236

Please feel free to use your domain knowledge to make changes to the generated tests to make it more valuable for your team.
Original Change: ag/34901827
Test: ATP tests passed http://go/forrest-run/L23200030017392531
Bug: 431235865
Flag: TEST_ONLY

Change-Id: I4654e41f2c8fe18347201dc469d183d428240eda
parent f1b37ca1
Loading
Loading
Loading
Loading
+68 −0
Original line number Diff line number Diff line
@@ -292,6 +292,74 @@ public class BackAnimationControllerTest extends ShellTestCase {
        verify(mTransitions).runOnIdle(any());
    }

    @EnableFlags(Flags.FLAG_PREDICTIVE_BACK_INTERCEPT_TRANSITION)
    @Test
    public void testInTransition_retriesWhenIdle() throws RemoteException {
        // Setup: First call to startBackNavigation returns IN_TRANSITION, second is successful.
        BackNavigationInfo inTransitionInfo = new BackNavigationInfo.Builder()
                .setType(BackNavigationInfo.TYPE_IN_TRANSITION)
                .build();
        BackNavigationInfo successInfo = new BackNavigationInfo.Builder()
                .setType(BackNavigationInfo.TYPE_RETURN_TO_HOME)
                .setOnBackInvokedCallback(mAnimatorCallback)
                .setPrepareRemoteAnimation(true)
                .setOnBackNavigationDone(new RemoteCallback(bundle -> {}))
                .setTouchableRegion(mTouchableRegion)
                .build();
        registerAnimation(BackNavigationInfo.TYPE_RETURN_TO_HOME);
        doReturn(inTransitionInfo)
                .doReturn(successInfo)
                .when(mActivityTaskManager).startBackNavigation(any(), any());

        // Action: Start a gesture
        doStartEvents(0, 100);
        mShellExecutor.flushAll();

        // Verification (Phase 1): Check that a retry has been scheduled.
        verify(mActivityTaskManager).startBackNavigation(any(), any());
        ArgumentCaptor<Runnable> idleRunnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        verify(mTransitions).runOnIdle(idleRunnableCaptor.capture());

        // Action (Phase 2): Trigger the idle callback.
        idleRunnableCaptor.getValue().run();
        mShellExecutor.flushAll();

        // Verification (Phase 2): Check that startBackNavigation is called again and succeeds.
        verify(mActivityTaskManager, times(2)).startBackNavigation(any(), any());

        // Verify that the normal animation flow continues
        simulateRemoteAnimationStart();
        mShellExecutor.flushAll();
        verify(mAnimatorCallback, atLeastOnce()).onBackStarted(any(BackMotionEvent.class));
    }

    @EnableFlags(Flags.FLAG_PREDICTIVE_BACK_INTERCEPT_TRANSITION)
    @Test
    public void testInTransition_retryIsCancelledIfGestureFinished() throws RemoteException {
        // Setup: startBackNavigation returns IN_TRANSITION
        createNavigationInfo(BackNavigationInfo.TYPE_IN_TRANSITION, false, false);

        // Action: Start a gesture
        doStartEvents(0, 100);
        mShellExecutor.flushAll();

        // Verification (Phase 1): Check that a retry has been scheduled.
        verify(mActivityTaskManager).startBackNavigation(any(), any());
        ArgumentCaptor<Runnable> idleRunnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        verify(mTransitions).runOnIdle(idleRunnableCaptor.capture());

        // Action (Phase 2): Finish the gesture before the idle callback runs.
        releaseBackGesture();
        mShellExecutor.flushAll();

        // Action (Phase 3): Trigger the idle callback.
        idleRunnableCaptor.getValue().run();
        mShellExecutor.flushAll();

        // Verification (Phase 3): Check that startBackNavigation is NOT called again.
        verify(mActivityTaskManager, times(1)).startBackNavigation(any(), any());
    }

    @Test
    public void backToHome_dispatchesEvents() throws RemoteException {
        registerAnimation(BackNavigationInfo.TYPE_RETURN_TO_HOME);