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

Commit 51c28c61 authored by AI test gen's avatar AI test gen Committed by Ang Li
Browse files

Add tests for IME user animation request tracking in InsetsController

Adds tests to verify that `ImeTracker` is invoked when a user-controlled animation for the IME is started.

This is verified by checking for the `ImeTracker.Token` that is passed to the `InsetsController.Host` when the animation is initiated.

- `testControlWindowInsetsAnimation_ime_createsStatsToken`: Confirms that a non-null token is created when controlling the IME.
- `testControlWindowInsetsAnimation_nonIme_noStatsToken`: Confirms that a null token is used when controlling other system bars.



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

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/31235794
Test: ATP tests passed http://go/forrest-run/L12800030017395409
Bug: 431235865
Flag: TEST_ONLY

Change-Id: Ia06424087f358f47514592cdaa8d3f6bbe99087e
parent 2062d326
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -534,6 +534,49 @@ public class InsetsControllerTest {
        InstrumentationRegistry.getInstrumentation().waitForIdleSync();
    }

    @Test
    public void testControlWindowInsetsAnimation_ime_createsStatsToken() {
        // Arrange
        prepareControls();
        clearInvocations(mTestHost);

        // Act: Control the IME insets, which should trigger ImeTracker.
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            WindowInsetsAnimationControlListener listener =
                    mock(WindowInsetsAnimationControlListener.class);
            mController.controlWindowInsetsAnimation(ime(), 0, new LinearInterpolator(),
                    null /* cancellationSignal */, listener);
        });

        // Assert: Verify that the host is updated with a non-null stats token.
        ArgumentCaptor<ImeTracker.Token> tokenCaptor =
                ArgumentCaptor.forClass(ImeTracker.Token.class);
        verify(mTestHost).updateRequestedVisibleTypes(anyInt(), tokenCaptor.capture());
        assertNotNull("A statsToken should be created for IME animations", tokenCaptor.getValue());
    }

    @Test
    public void testControlWindowInsetsAnimation_nonIme_noStatsToken() {
        // Arrange
        prepareControls();
        clearInvocations(mTestHost);

        // Act: Control non-IME insets, which should not trigger ImeTracker.
        InstrumentationRegistry.getInstrumentation().runOnMainSync(() -> {
            WindowInsetsAnimationControlListener listener =
                    mock(WindowInsetsAnimationControlListener.class);
            mController.controlWindowInsetsAnimation(statusBars(), 0, new LinearInterpolator(),
                    null /* cancellationSignal */, listener);
        });

        // Assert: Verify that the host is updated with a null stats token.
        ArgumentCaptor<ImeTracker.Token> tokenCaptor =
                ArgumentCaptor.forClass(ImeTracker.Token.class);
        verify(mTestHost).updateRequestedVisibleTypes(anyInt(), tokenCaptor.capture());
        assertNull("No statsToken should be created for non-IME animations",
                tokenCaptor.getValue());
    }

    @Test
    public void testControlImeNotReady() {
        // With the flag on, the IME control should not contain a leash, otherwise the custom