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

Commit 45e280df authored by Ats Jenk's avatar Ats Jenk
Browse files

Test for removing pending transitions

Check that when removing pending transitions from TaskViewTransitions
then they are removed per task.

Bug: 396315875
Test: atest WMShellUnitTests:TaskViewTransitionsTest
Flag: EXEMPT, updating test only
Change-Id: I9dd68f00cebecc2d279ea80499523d9670ed1945
parent 9c9026ee
Loading
Loading
Loading
Loading
+49 −9
Original line number Diff line number Diff line
@@ -56,6 +56,7 @@ import android.window.WindowContainerTransaction;

import androidx.test.filters.SmallTest;

import com.android.wm.shell.MockToken;
import com.android.wm.shell.ShellTaskOrganizer;
import com.android.wm.shell.ShellTestCase;
import com.android.wm.shell.common.SyncTransactionQueue;
@@ -97,9 +98,7 @@ public class TaskViewTransitionsTest extends ShellTestCase {

    @Mock
    Transitions mTransitions;
    @Mock
    TaskViewTaskController mTaskViewTaskController;
    @Mock
    WindowContainerToken mToken;
    @Mock
    ShellTaskOrganizer mOrganizer;
@@ -122,20 +121,16 @@ public class TaskViewTransitionsTest extends ShellTestCase {
            doReturn(true).when(mTransitions).isRegistered();
        }

        when(mToken.asBinder()).thenReturn(new Binder());
        mToken = new MockToken().token();

        mTaskInfo = new ActivityManager.RunningTaskInfo();
        mTaskInfo.token = mToken;
        mTaskInfo.taskId = 314;
        mTaskInfo.taskDescription = mock(ActivityManager.TaskDescription.class);
        mTaskInfo = createMockTaskInfo(314, mToken);

        mTaskViewRepository = new TaskViewRepository();
        when(mOrganizer.getExecutor()).thenReturn(mExecutor);
        mTaskViewTransitions = spy(new TaskViewTransitions(mTransitions, mTaskViewRepository,
                mOrganizer, mSyncQueue));
        mTaskViewTaskController = createMockTaskController(mTaskInfo);
        mTaskViewTransitions.registerTaskView(mTaskViewTaskController);
        when(mTaskViewTaskController.getTaskInfo()).thenReturn(mTaskInfo);
        when(mTaskViewTaskController.getTaskToken()).thenReturn(mToken);
    }

    @Test
@@ -457,6 +452,51 @@ public class TaskViewTransitionsTest extends ShellTestCase {
        assertThat(mTaskViewTransitions.hasPending()).isFalse();
    }

    @Test
    public void removePendingTransitions_removePerTask() {
        WindowContainerToken otherToken = new MockToken().token();
        ActivityManager.RunningTaskInfo otherTaskInfo = createMockTaskInfo(999, otherToken);
        TaskViewTaskController otherController = createMockTaskController(otherTaskInfo);
        mTaskViewTransitions.registerTaskView(otherController);

        mTaskViewTransitions.setTaskViewVisible(mTaskViewTaskController, true);
        mTaskViewTransitions.setTaskViewVisible(otherController, true);

        // There should be two pending transitions, one for each task
        assertThat(mTaskViewTransitions.hasPending()).isTrue();
        assertThat(mTaskViewTransitions.findPending(mTaskViewTaskController,
                TRANSIT_TO_FRONT)).isNotNull();
        assertThat(mTaskViewTransitions.findPending(otherController, TRANSIT_TO_FRONT)).isNotNull();

        // Remove pending for one task, keep the other
        mTaskViewTransitions.removePendingTransitions(mTaskViewTaskController);
        assertThat(mTaskViewTransitions.hasPending()).isTrue();
        assertThat(mTaskViewTransitions.findPending(mTaskViewTaskController,
                TRANSIT_TO_FRONT)).isNull();
        assertThat(mTaskViewTransitions.findPending(otherController, TRANSIT_TO_FRONT)).isNotNull();

        // Remove the last one
        mTaskViewTransitions.removePendingTransitions(otherController);
        assertThat(mTaskViewTransitions.hasPending()).isFalse();
    }

    private ActivityManager.RunningTaskInfo createMockTaskInfo(int taskId,
            WindowContainerToken token) {
        ActivityManager.RunningTaskInfo taskInfo = new ActivityManager.RunningTaskInfo();
        taskInfo.token = token;
        taskInfo.taskId = taskId;
        taskInfo.taskDescription = mock(ActivityManager.TaskDescription.class);
        return taskInfo;
    }

    private TaskViewTaskController createMockTaskController(
            ActivityManager.RunningTaskInfo taskInfo) {
        TaskViewTaskController controller = mock(TaskViewTaskController.class);
        when(controller.getTaskInfo()).thenReturn(taskInfo);
        when(controller.getTaskToken()).thenReturn(taskInfo.token);
        return controller;
    }

    private SurfaceControl.Transaction createMockTransaction() {
        SurfaceControl.Transaction transaction = mock(SurfaceControl.Transaction.class);
        when(transaction.reparent(any(), any())).thenReturn(transaction);