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

Commit dcbd39ec authored by Evan Rosky's avatar Evan Rosky Committed by Android (Google) Code Review
Browse files

Merge "Fix Transition test logic and consolidate some boilerplate"

parents 44ef8174 ee595457
Loading
Loading
Loading
Loading
+78 −0
Original line number Original line Diff line number Diff line
/*
 * Copyright (C) 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.wm.shell;

import static com.android.dx.mockito.inline.extended.ExtendedMockito.doReturn;

import static org.mockito.Mockito.mock;

import android.app.ActivityManager;
import android.view.SurfaceControl;
import android.view.WindowManager;
import android.window.TransitionInfo;

/**
 * Utility for creating/editing synthetic TransitionInfos for tests.
 */
public class TransitionInfoBuilder {
    final TransitionInfo mInfo;

    public TransitionInfoBuilder(@WindowManager.TransitionType int type) {
        this(type, 0 /* flags */);
    }

    public TransitionInfoBuilder(@WindowManager.TransitionType int type,
            @WindowManager.TransitionFlags int flags) {
        mInfo = new TransitionInfo(type, flags);
        mInfo.setRootLeash(createMockSurface(true /* valid */), 0, 0);
    }

    public TransitionInfoBuilder addChange(@WindowManager.TransitionType int mode,
            @TransitionInfo.ChangeFlags int flags, ActivityManager.RunningTaskInfo taskInfo) {
        final TransitionInfo.Change change = new TransitionInfo.Change(
                taskInfo != null ? taskInfo.token : null, createMockSurface(true /* valid */));
        change.setMode(mode);
        change.setFlags(flags);
        change.setTaskInfo(taskInfo);
        return addChange(change);
    }

    public TransitionInfoBuilder addChange(@WindowManager.TransitionType int mode,
            ActivityManager.RunningTaskInfo taskInfo) {
        return addChange(mode, TransitionInfo.FLAG_NONE, taskInfo);
    }

    public TransitionInfoBuilder addChange(@WindowManager.TransitionType int mode) {
        return addChange(mode, TransitionInfo.FLAG_NONE, null /* taskInfo */);
    }

    public TransitionInfoBuilder addChange(TransitionInfo.Change change) {
        mInfo.addChange(change);
        return this;
    }

    public TransitionInfo build() {
        return mInfo;
    }

    private static SurfaceControl createMockSurface(boolean valid) {
        SurfaceControl sc = mock(SurfaceControl.class);
        doReturn(valid).when(sc).isValid();
        doReturn("TestSurface").when(sc).toString();
        return sc;
    }
}
+8 −8
Original line number Original line Diff line number Diff line
@@ -35,6 +35,8 @@ import android.window.TransitionInfo;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;


import com.android.wm.shell.TransitionInfoBuilder;

import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
@@ -60,10 +62,9 @@ public class ActivityEmbeddingAnimationRunnerTests extends ActivityEmbeddingAnim


    @Test
    @Test
    public void testStartAnimation() {
    public void testStartAnimation() {
        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        final TransitionInfo.Change embeddingChange = createChange();
                .addChange(createChange(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY))
        embeddingChange.setFlags(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY);
                .build();
        info.addChange(embeddingChange);
        doReturn(mAnimator).when(mAnimRunner).createAnimator(any(), any(), any(), any(), any());
        doReturn(mAnimator).when(mAnimRunner).createAnimator(any(), any(), any(), any(), any());


        mAnimRunner.startAnimation(mTransition, info, mStartTransaction, mFinishTransaction);
        mAnimRunner.startAnimation(mTransition, info, mStartTransaction, mFinishTransaction);
@@ -84,10 +85,9 @@ public class ActivityEmbeddingAnimationRunnerTests extends ActivityEmbeddingAnim


    @Test
    @Test
    public void testChangesBehindStartingWindow() {
    public void testChangesBehindStartingWindow() {
        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        final TransitionInfo.Change embeddingChange = createChange();
                .addChange(createChange(FLAG_IS_BEHIND_STARTING_WINDOW))
        embeddingChange.setFlags(FLAG_IS_BEHIND_STARTING_WINDOW);
                .build();
        info.addChange(embeddingChange);
        final Animator animator = mAnimRunner.createAnimator(
        final Animator animator = mAnimRunner.createAnimator(
                info, mStartTransaction, mFinishTransaction,
                info, mStartTransaction, mFinishTransaction,
                () -> mFinishCallback.onTransitionFinished(null /* wct */, null /* wctCB */),
                () -> mFinishCallback.onTransitionFinished(null /* wct */, null /* wctCB */),
+5 −4
Original line number Original line Diff line number Diff line
@@ -82,9 +82,11 @@ abstract class ActivityEmbeddingAnimationTestBase extends ShellTestCase {
    }
    }


    /** Creates a mock {@link TransitionInfo.Change}. */
    /** Creates a mock {@link TransitionInfo.Change}. */
    static TransitionInfo.Change createChange() {
    static TransitionInfo.Change createChange(@TransitionInfo.ChangeFlags int flags) {
        return new TransitionInfo.Change(mock(WindowContainerToken.class),
        TransitionInfo.Change c = new TransitionInfo.Change(mock(WindowContainerToken.class),
                mock(SurfaceControl.class));
                mock(SurfaceControl.class));
        c.setFlags(flags);
        return c;
    }
    }


    /**
    /**
@@ -93,8 +95,7 @@ abstract class ActivityEmbeddingAnimationTestBase extends ShellTestCase {
     */
     */
    static TransitionInfo.Change createEmbeddedChange(@NonNull Rect startBounds,
    static TransitionInfo.Change createEmbeddedChange(@NonNull Rect startBounds,
            @NonNull Rect endBounds, @NonNull Rect taskBounds) {
            @NonNull Rect endBounds, @NonNull Rect taskBounds) {
        final TransitionInfo.Change change = createChange();
        final TransitionInfo.Change change = createChange(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY);
        change.setFlags(FLAG_IN_TASK_WITH_EMBEDDED_ACTIVITY);
        change.setStartAbsBounds(startBounds);
        change.setStartAbsBounds(startBounds);
        change.setEndAbsBounds(endBounds);
        change.setEndAbsBounds(endBounds);
        if (taskBounds.width() == startBounds.width()
        if (taskBounds.width() == startBounds.width()
+24 −26
Original line number Original line Diff line number Diff line
@@ -34,6 +34,8 @@ import android.window.TransitionInfo;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;


import com.android.wm.shell.TransitionInfoBuilder;

import org.junit.Before;
import org.junit.Before;
import org.junit.Test;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runner.RunWith;
@@ -80,12 +82,11 @@ public class ActivityEmbeddingControllerTests extends ActivityEmbeddingAnimation


    @Test
    @Test
    public void testStartAnimation_containsNonActivityEmbeddingChange() {
    public void testStartAnimation_containsNonActivityEmbeddingChange() {
        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        final TransitionInfo.Change embeddingChange = createEmbeddedChange(EMBEDDED_LEFT_BOUNDS,
                .addChange(createEmbeddedChange(
                EMBEDDED_LEFT_BOUNDS, TASK_BOUNDS);
                        EMBEDDED_LEFT_BOUNDS, EMBEDDED_LEFT_BOUNDS, TASK_BOUNDS))
        final TransitionInfo.Change nonEmbeddingChange = createChange();
                .addChange(createChange(0 /* flags */))
        info.addChange(embeddingChange);
                .build();
        info.addChange(nonEmbeddingChange);


        // No-op because it contains non-embedded change.
        // No-op because it contains non-embedded change.
        assertFalse(mController.startAnimation(mTransition, info, mStartTransaction,
        assertFalse(mController.startAnimation(mTransition, info, mStartTransaction,
@@ -98,10 +99,9 @@ public class ActivityEmbeddingControllerTests extends ActivityEmbeddingAnimation


    @Test
    @Test
    public void testStartAnimation_containsOnlyFillTaskActivityEmbeddingChange() {
    public void testStartAnimation_containsOnlyFillTaskActivityEmbeddingChange() {
        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        final TransitionInfo.Change embeddingChange = createEmbeddedChange(TASK_BOUNDS, TASK_BOUNDS,
                .addChange(createEmbeddedChange(TASK_BOUNDS, TASK_BOUNDS, TASK_BOUNDS))
                TASK_BOUNDS);
                .build();
        info.addChange(embeddingChange);


        // No-op because it only contains embedded change that fills the Task. We will let the
        // No-op because it only contains embedded change that fills the Task. We will let the
        // default handler to animate such transition.
        // default handler to animate such transition.
@@ -116,10 +116,10 @@ public class ActivityEmbeddingControllerTests extends ActivityEmbeddingAnimation
    @Test
    @Test
    public void testStartAnimation_containsActivityEmbeddingSplitChange() {
    public void testStartAnimation_containsActivityEmbeddingSplitChange() {
        // Change that occupies only part of the Task.
        // Change that occupies only part of the Task.
        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        final TransitionInfo.Change embeddingChange = createEmbeddedChange(EMBEDDED_LEFT_BOUNDS,
                .addChange(createEmbeddedChange(
                EMBEDDED_LEFT_BOUNDS, TASK_BOUNDS);
                        EMBEDDED_LEFT_BOUNDS, EMBEDDED_LEFT_BOUNDS, TASK_BOUNDS))
        info.addChange(embeddingChange);
                .build();


        // ActivityEmbeddingController will handle such transition.
        // ActivityEmbeddingController will handle such transition.
        assertTrue(mController.startAnimation(mTransition, info, mStartTransaction,
        assertTrue(mController.startAnimation(mTransition, info, mStartTransaction,
@@ -133,10 +133,9 @@ public class ActivityEmbeddingControllerTests extends ActivityEmbeddingAnimation
    @Test
    @Test
    public void testStartAnimation_containsChangeEnterActivityEmbeddingSplit() {
    public void testStartAnimation_containsChangeEnterActivityEmbeddingSplit() {
        // Change that is entering ActivityEmbedding split.
        // Change that is entering ActivityEmbedding split.
        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        final TransitionInfo.Change embeddingChange = createEmbeddedChange(TASK_BOUNDS,
                .addChange(createEmbeddedChange(TASK_BOUNDS, EMBEDDED_LEFT_BOUNDS, TASK_BOUNDS))
                EMBEDDED_LEFT_BOUNDS, TASK_BOUNDS);
                .build();
        info.addChange(embeddingChange);


        // ActivityEmbeddingController will handle such transition.
        // ActivityEmbeddingController will handle such transition.
        assertTrue(mController.startAnimation(mTransition, info, mStartTransaction,
        assertTrue(mController.startAnimation(mTransition, info, mStartTransaction,
@@ -150,10 +149,9 @@ public class ActivityEmbeddingControllerTests extends ActivityEmbeddingAnimation
    @Test
    @Test
    public void testStartAnimation_containsChangeExitActivityEmbeddingSplit() {
    public void testStartAnimation_containsChangeExitActivityEmbeddingSplit() {
        // Change that is exiting ActivityEmbedding split.
        // Change that is exiting ActivityEmbedding split.
        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        final TransitionInfo.Change embeddingChange = createEmbeddedChange(EMBEDDED_RIGHT_BOUNDS,
                .addChange(createEmbeddedChange(EMBEDDED_RIGHT_BOUNDS, TASK_BOUNDS, TASK_BOUNDS))
                TASK_BOUNDS, TASK_BOUNDS);
                .build();
        info.addChange(embeddingChange);


        // ActivityEmbeddingController will handle such transition.
        // ActivityEmbeddingController will handle such transition.
        assertTrue(mController.startAnimation(mTransition, info, mStartTransaction,
        assertTrue(mController.startAnimation(mTransition, info, mStartTransaction,
@@ -170,10 +168,10 @@ public class ActivityEmbeddingControllerTests extends ActivityEmbeddingAnimation
        assertThrows(IllegalStateException.class,
        assertThrows(IllegalStateException.class,
                () -> mController.onAnimationFinished(mTransition));
                () -> mController.onAnimationFinished(mTransition));


        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        final TransitionInfo.Change embeddingChange = createEmbeddedChange(EMBEDDED_LEFT_BOUNDS,
                .addChange(createEmbeddedChange(
                EMBEDDED_LEFT_BOUNDS, TASK_BOUNDS);
                        EMBEDDED_LEFT_BOUNDS, EMBEDDED_LEFT_BOUNDS, TASK_BOUNDS))
        info.addChange(embeddingChange);
                .build();
        mController.startAnimation(mTransition, info, mStartTransaction,
        mController.startAnimation(mTransition, info, mStartTransaction,
                mFinishTransaction, mFinishCallback);
                mFinishTransaction, mFinishCallback);


+17 −16
Original line number Original line Diff line number Diff line
@@ -37,6 +37,7 @@ import android.window.WindowContainerToken;


import androidx.test.filters.SmallTest;
import androidx.test.filters.SmallTest;


import com.android.wm.shell.TransitionInfoBuilder;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.sysui.ShellInit;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.transition.Transitions;
import com.android.wm.shell.windowdecor.WindowDecorViewModel;
import com.android.wm.shell.windowdecor.WindowDecorViewModel;
@@ -94,8 +95,8 @@ public class FreeformTaskTransitionObserverTest {
    public void testCreatesWindowDecorOnOpenTransition_freeform() {
    public void testCreatesWindowDecorOnOpenTransition_freeform() {
        final TransitionInfo.Change change =
        final TransitionInfo.Change change =
                createChange(TRANSIT_OPEN, 1, WINDOWING_MODE_FREEFORM);
                createChange(TRANSIT_OPEN, 1, WINDOWING_MODE_FREEFORM);
        final TransitionInfo info = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        info.addChange(change);
                .addChange(change).build();


        final IBinder transition = mock(IBinder.class);
        final IBinder transition = mock(IBinder.class);
        final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
        final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
@@ -111,8 +112,8 @@ public class FreeformTaskTransitionObserverTest {
    public void testPreparesWindowDecorOnCloseTransition_freeform() {
    public void testPreparesWindowDecorOnCloseTransition_freeform() {
        final TransitionInfo.Change change =
        final TransitionInfo.Change change =
                createChange(TRANSIT_CLOSE, 1, WINDOWING_MODE_FREEFORM);
                createChange(TRANSIT_CLOSE, 1, WINDOWING_MODE_FREEFORM);
        final TransitionInfo info = new TransitionInfo(TRANSIT_CLOSE, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_CLOSE, 0)
        info.addChange(change);
                .addChange(change).build();


        final IBinder transition = mock(IBinder.class);
        final IBinder transition = mock(IBinder.class);
        final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
        final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
@@ -128,8 +129,8 @@ public class FreeformTaskTransitionObserverTest {
    public void testDoesntCloseWindowDecorDuringCloseTransition() throws Exception {
    public void testDoesntCloseWindowDecorDuringCloseTransition() throws Exception {
        final TransitionInfo.Change change =
        final TransitionInfo.Change change =
                createChange(TRANSIT_CLOSE, 1, WINDOWING_MODE_FREEFORM);
                createChange(TRANSIT_CLOSE, 1, WINDOWING_MODE_FREEFORM);
        final TransitionInfo info = new TransitionInfo(TRANSIT_CLOSE, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_CLOSE, 0)
        info.addChange(change);
                .addChange(change).build();


        final IBinder transition = mock(IBinder.class);
        final IBinder transition = mock(IBinder.class);
        final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
        final SurfaceControl.Transaction startT = mock(SurfaceControl.Transaction.class);
@@ -144,8 +145,8 @@ public class FreeformTaskTransitionObserverTest {
    public void testClosesWindowDecorAfterCloseTransition() throws Exception {
    public void testClosesWindowDecorAfterCloseTransition() throws Exception {
        final TransitionInfo.Change change =
        final TransitionInfo.Change change =
                createChange(TRANSIT_CLOSE, 1, WINDOWING_MODE_FREEFORM);
                createChange(TRANSIT_CLOSE, 1, WINDOWING_MODE_FREEFORM);
        final TransitionInfo info = new TransitionInfo(TRANSIT_CLOSE, 0);
        final TransitionInfo info = new TransitionInfoBuilder(TRANSIT_CLOSE, 0)
        info.addChange(change);
                .addChange(change).build();


        final AutoCloseable windowDecor = mock(AutoCloseable.class);
        final AutoCloseable windowDecor = mock(AutoCloseable.class);


@@ -164,8 +165,8 @@ public class FreeformTaskTransitionObserverTest {
        // The playing transition
        // The playing transition
        final TransitionInfo.Change change1 =
        final TransitionInfo.Change change1 =
                createChange(TRANSIT_OPEN, 1, WINDOWING_MODE_FREEFORM);
                createChange(TRANSIT_OPEN, 1, WINDOWING_MODE_FREEFORM);
        final TransitionInfo info1 = new TransitionInfo(TRANSIT_OPEN, 0);
        final TransitionInfo info1 = new TransitionInfoBuilder(TRANSIT_OPEN, 0)
        info1.addChange(change1);
                .addChange(change1).build();


        final IBinder transition1 = mock(IBinder.class);
        final IBinder transition1 = mock(IBinder.class);
        final SurfaceControl.Transaction startT1 = mock(SurfaceControl.Transaction.class);
        final SurfaceControl.Transaction startT1 = mock(SurfaceControl.Transaction.class);
@@ -176,8 +177,8 @@ public class FreeformTaskTransitionObserverTest {
        // The merged transition
        // The merged transition
        final TransitionInfo.Change change2 =
        final TransitionInfo.Change change2 =
                createChange(TRANSIT_CLOSE, 2, WINDOWING_MODE_FREEFORM);
                createChange(TRANSIT_CLOSE, 2, WINDOWING_MODE_FREEFORM);
        final TransitionInfo info2 = new TransitionInfo(TRANSIT_CLOSE, 0);
        final TransitionInfo info2 = new TransitionInfoBuilder(TRANSIT_CLOSE, 0)
        info2.addChange(change2);
                .addChange(change2).build();


        final IBinder transition2 = mock(IBinder.class);
        final IBinder transition2 = mock(IBinder.class);
        final SurfaceControl.Transaction startT2 = mock(SurfaceControl.Transaction.class);
        final SurfaceControl.Transaction startT2 = mock(SurfaceControl.Transaction.class);
@@ -195,8 +196,8 @@ public class FreeformTaskTransitionObserverTest {
        // The playing transition
        // The playing transition
        final TransitionInfo.Change change1 =
        final TransitionInfo.Change change1 =
                createChange(TRANSIT_CLOSE, 1, WINDOWING_MODE_FREEFORM);
                createChange(TRANSIT_CLOSE, 1, WINDOWING_MODE_FREEFORM);
        final TransitionInfo info1 = new TransitionInfo(TRANSIT_CLOSE, 0);
        final TransitionInfo info1 = new TransitionInfoBuilder(TRANSIT_CLOSE, 0)
        info1.addChange(change1);
                .addChange(change1).build();


        final IBinder transition1 = mock(IBinder.class);
        final IBinder transition1 = mock(IBinder.class);
        final SurfaceControl.Transaction startT1 = mock(SurfaceControl.Transaction.class);
        final SurfaceControl.Transaction startT1 = mock(SurfaceControl.Transaction.class);
@@ -207,8 +208,8 @@ public class FreeformTaskTransitionObserverTest {
        // The merged transition
        // The merged transition
        final TransitionInfo.Change change2 =
        final TransitionInfo.Change change2 =
                createChange(TRANSIT_CLOSE, 2, WINDOWING_MODE_FREEFORM);
                createChange(TRANSIT_CLOSE, 2, WINDOWING_MODE_FREEFORM);
        final TransitionInfo info2 = new TransitionInfo(TRANSIT_CLOSE, 0);
        final TransitionInfo info2 = new TransitionInfoBuilder(TRANSIT_CLOSE, 0)
        info2.addChange(change2);
                .addChange(change2).build();


        final IBinder transition2 = mock(IBinder.class);
        final IBinder transition2 = mock(IBinder.class);
        final SurfaceControl.Transaction startT2 = mock(SurfaceControl.Transaction.class);
        final SurfaceControl.Transaction startT2 = mock(SurfaceControl.Transaction.class);
Loading