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

Commit b7178f24 authored by Evan Rosky's avatar Evan Rosky
Browse files

migrate some tests to shell transitions

Without a transition player registered, the system
(and thus some tests) were still executing parts of
legacy code. With a fallback-player, it means that
shell-transitions is always active.

This migrates some tests which were relying on
legacy logic over to shell transitions logic to unblock
roll-out of the fallback player.

Bug: 365884835
Test: these are the tests
Flag: com.android.window.flags.fallback_transition_player
Change-Id: I53025efb17319a0b2b53a504fd57754ee09e2fe0
parent 80166f36
Loading
Loading
Loading
Loading
+11 −3
Original line number Diff line number Diff line
@@ -1331,14 +1331,18 @@ public class ActivityRecordTests extends WindowTestsBase {
        activity.finishIfPossible("test", false /* oomAdj */);

        verify(activity).setVisibility(eq(false));
        if (Flags.fallbackTransitionPlayer()) {
            assertFalse(mAtm.getTransitionController().getCollectingTransition().allReady());
        } else {
            verify(activity.mDisplayContent, never()).executeAppTransition();
        }
    }

    /**
     * Verify that finish request for paused activity will prepare and execute an app transition.
     */
    @Test
    public void testFinishActivityIfPossible_visibleNotResumedExecutesAppTransition() {
    public void testFinishActivityIfPossible_visibleNotResumedTransitionReady() {
        final ActivityRecord activity = createActivityWithTask();
        clearInvocations(activity.mDisplayContent);
        activity.finishing = false;
@@ -1347,8 +1351,12 @@ public class ActivityRecordTests extends WindowTestsBase {
        activity.finishIfPossible("test", false /* oomAdj */);

        verify(activity, atLeast(1)).setVisibility(eq(false));
        if (Flags.fallbackTransitionPlayer()) {
            assertTrue(mAtm.getTransitionController().getCollectingTransition().allReady());
        } else {
            verify(activity.mDisplayContent).executeAppTransition();
        }
    }

    /**
     * Verify that finish request for non-visible activity will not prepare any transitions.
+2 −0
Original line number Diff line number Diff line
@@ -219,6 +219,7 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase {
    @Test
    public void testRemoveTask() {
        final ActivityRecord activity1 = new ActivityBuilder(mAtm).setCreateTask(true).build();
        activity1.setVisibleRequested(false);
        activity1.setVisible(false);
        activity1.finishing = true;
        activity1.setState(ActivityRecord.State.STOPPING, "test");
@@ -235,6 +236,7 @@ public class ActivityTaskSupervisorTests extends WindowTestsBase {
        assertEquals(ActivityRecord.State.DESTROYING, activity2.getState());
        assertEquals(ActivityRecord.State.STOPPING, activity1.getState());
        assertTrue(mSupervisor.mStoppingActivities.contains(activity1));
        waitHandlerIdle(mAtm.mH);
        // Assume that it is called by scheduleIdle from addToStopping. And because
        // mStoppingActivities remembers the finishing activity, it can continue to destroy.
        mSupervisor.processStoppingAndFinishingActivities(null /* launchedActivity */,
+42 −0
Original line number Diff line number Diff line
@@ -102,6 +102,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.ArgumentMatchers.isNull;
@@ -1939,6 +1940,8 @@ public class DisplayContentTests extends WindowTestsBase {

    @Test
    public void testRemoteRotation() {
        // Shell-transitions version is tested in testRemoteRotationWhenTransitionCombine
        assumeTrue(!Flags.fallbackTransitionPlayer());
        final DisplayRotation dr = mDisplayContent.getDisplayRotation();
        spyOn(dr);
        doReturn((dr.getRotation() + 2) % 4).when(dr).rotationForOrientation(anyInt(), anyInt());
@@ -1971,6 +1974,45 @@ public class DisplayContentTests extends WindowTestsBase {
        assertTrue(continued[0]);
    }

    @Test
    public void testRemoteRotationWhenTransitionCombine() {
        // Create 2 visible activities to verify that they can both receive the new configuration.
        final ActivityRecord activity1 = new ActivityBuilder(mAtm).setCreateTask(true).build();
        doReturn(true).when(activity1).isSyncFinished(any());

        final TestTransitionPlayer testPlayer = registerTestTransitionPlayer();
        final DisplayRotation dr = mDisplayContent.getDisplayRotation();
        spyOn(dr);
        doReturn((dr.getRotation() + 1) % 4).when(dr).rotationForOrientation(anyInt(), anyInt());
        final boolean[] called = new boolean[1];
        mWm.mDisplayChangeController = new IDisplayChangeWindowController.Stub() {
            @Override
            public void onDisplayChange(int displayId, int fromRotation, int toRotation,
                    DisplayAreaInfo newDisplayAreaInfo, IDisplayChangeWindowCallback callback) {
                try {
                    called[0] = true;
                    callback.continueDisplayChange(null);
                } catch (RemoteException e) {
                    fail();
                }
            }
        };

        final int origRot = mDisplayContent.getConfiguration().windowConfiguration.getRotation();
        mDisplayContent.setLastHasContent();

        // Create/collect a transition that will be "interrupted" by the display rotation
        requestTransition(activity1, WindowManager.TRANSIT_CHANGE);

        mWm.updateRotation(true /* alwaysSendConfiguration */, false /* forceRelayout */);
        waitUntilHandlersIdle();
        // Since it got combined (and thus we can't rely on a handleRequest), it should fall-back
        // to the display-change controller
        assertTrue(called[0]);
        assertNotEquals(origRot, mDisplayContent.getConfiguration().windowConfiguration
                .getRotation());
    }

    @Test
    public void testRemoteDisplayChange() {
        mWm.mDisplayChangeController = mock(IDisplayChangeWindowController.class);