Loading libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitPresenter.java +12 −0 Original line number Diff line number Diff line Loading @@ -1359,4 +1359,16 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { return new ParentContainerInfo(taskProperties.getTaskMetrics(), configuration, windowLayoutInfo); } @VisibleForTesting @NonNull static String positionToString(@ContainerPosition int position) { return switch (position) { case CONTAINER_POSITION_LEFT -> "left"; case CONTAINER_POSITION_TOP -> "top"; case CONTAINER_POSITION_RIGHT -> "right"; case CONTAINER_POSITION_BOTTOM -> "bottom"; default -> "Unknown position:" + position; }; } } libs/WindowManager/Jetpack/tests/unittest/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ android_test { ], static_libs: [ "TestParameterInjector", "androidx.window.extensions", "androidx.window.extensions.core_core", "junit", Loading libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/OverlayPresentationTest.java +69 −53 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSI import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSITION_RIGHT; import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSITION_TOP; import static androidx.window.extensions.embedding.SplitPresenter.getOverlayPosition; import static androidx.window.extensions.embedding.SplitPresenter.positionToString; import static androidx.window.extensions.embedding.SplitPresenter.sanitizeBounds; import static androidx.window.extensions.embedding.WindowAttributes.DIM_AREA_ON_TASK; Loading Loading @@ -78,7 +79,6 @@ import android.window.WindowContainerTransaction; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import androidx.window.common.DeviceStateManagerFoldingFeatureProducer; import androidx.window.extensions.layout.WindowLayoutComponentImpl; Loading @@ -86,6 +86,9 @@ import androidx.window.extensions.layout.WindowLayoutInfo; import com.android.window.flags.Flags; import com.google.testing.junit.testparameterinjector.TestParameter; import com.google.testing.junit.testparameterinjector.TestParameterInjector; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading @@ -108,7 +111,7 @@ import java.util.List; @SuppressWarnings("GuardedBy") @Presubmit @SmallTest @RunWith(AndroidJUnit4.class) @RunWith(TestParameterInjector.class) public class OverlayPresentationTest { @Rule public MockitoRule rule = MockitoJUnit.rule(); Loading Loading @@ -875,57 +878,70 @@ public class OverlayPresentationTest { eq(overlayContainer.getTaskFragmentToken()), eq(activityToken)); } // TODO(b/243518738): Rewrite with TestParameter. @Test public void testGetOverlayPosition() { assertWithMessage("It must be position left for left overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left, TASK_BOUNDS.top, TASK_BOUNDS.right / 2, TASK_BOUNDS.bottom), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_LEFT); assertWithMessage("It must be position left for shrunk left overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left, TASK_BOUNDS.top + 20, TASK_BOUNDS.right / 2, TASK_BOUNDS.bottom - 20), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_LEFT); assertWithMessage("It must be position left for top overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left, TASK_BOUNDS.top, TASK_BOUNDS.right, TASK_BOUNDS.bottom / 2), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_TOP); assertWithMessage("It must be position left for shrunk top overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left + 20, TASK_BOUNDS.top, TASK_BOUNDS.right - 20, TASK_BOUNDS.bottom / 2), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_TOP); assertWithMessage("It must be position left for right overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.right / 2, TASK_BOUNDS.top, TASK_BOUNDS.right, TASK_BOUNDS.bottom), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_RIGHT); assertWithMessage("It must be position left for shrunk right overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.right / 2, TASK_BOUNDS.top + 20, TASK_BOUNDS.right, TASK_BOUNDS.bottom - 20), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_RIGHT); assertWithMessage("It must be position left for bottom overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left, TASK_BOUNDS.bottom / 2, TASK_BOUNDS.right, TASK_BOUNDS.bottom), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_BOTTOM); assertWithMessage("It must be position left for shrunk bottom overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left + 20, TASK_BOUNDS.bottom / 20, TASK_BOUNDS.right - 20, TASK_BOUNDS.bottom), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_BOTTOM); @Test public void testGetOverlayPosition(@TestParameter OverlayPositionTestParams params) { final Rect taskBounds = new Rect(TASK_BOUNDS); final Rect overlayBounds = params.toOverlayBounds(); final int overlayPosition = getOverlayPosition(overlayBounds, taskBounds); assertWithMessage("The overlay position must be " + positionToString(params.mPosition) + ", but is " + positionToString(overlayPosition) + ", parent bounds=" + taskBounds + ", overlay bounds=" + overlayBounds) .that(overlayPosition).isEqualTo(params.mPosition); } private enum OverlayPositionTestParams { LEFT_OVERLAY(CONTAINER_POSITION_LEFT, false /* shouldBeShrunk */), LEFT_SHRUNK_OVERLAY(CONTAINER_POSITION_LEFT, true /* shouldBeShrunk */), TOP_OVERLAY(CONTAINER_POSITION_TOP, false /* shouldBeShrunk */), TOP_SHRUNK_OVERLAY(CONTAINER_POSITION_TOP, true /* shouldBeShrunk */), RIGHT_OVERLAY(CONTAINER_POSITION_RIGHT, false /* shouldBeShrunk */), RIGHT_SHRUNK_OVERLAY(CONTAINER_POSITION_RIGHT, true /* shouldBeShrunk */), BOTTOM_OVERLAY(CONTAINER_POSITION_BOTTOM, false /* shouldBeShrunk */), BOTTOM_SHRUNK_OVERLAY(CONTAINER_POSITION_BOTTOM, true /* shouldBeShrunk */); @SplitPresenter.ContainerPosition private final int mPosition; private final boolean mShouldBeShrunk; OverlayPositionTestParams( @SplitPresenter.ContainerPosition int position, boolean shouldBeShrunk) { mPosition = position; mShouldBeShrunk = shouldBeShrunk; } @NonNull private Rect toOverlayBounds() { Rect r = new Rect(TASK_BOUNDS); final int offset = mShouldBeShrunk ? 20 : 0; switch (mPosition) { case CONTAINER_POSITION_LEFT: r.top += offset; r.right /= 2; r.bottom -= offset; break; case CONTAINER_POSITION_TOP: r.left += offset; r.right -= offset; r.bottom /= 2; break; case CONTAINER_POSITION_RIGHT: r.left = r.right / 2; r.top += offset; r.bottom -= offset; break; case CONTAINER_POSITION_BOTTOM: r.left += offset; r.right -= offset; r.top = r.bottom / 2; break; default: throw new IllegalArgumentException("Invalid position: " + mPosition); } return r; } } /** Loading libs/WindowManager/Shell/tests/unittest/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ android_test { ], static_libs: [ "TestParameterInjector", "WindowManager-Shell", "junit", "flag-junit", Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunnerTests.java +73 −61 Original line number Diff line number Diff line Loading @@ -46,12 +46,14 @@ import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.window.TransitionInfo; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.window.flags.Flags; import com.android.wm.shell.transition.TransitionInfoBuilder; import com.google.testing.junit.testparameterinjector.TestParameter; import com.google.testing.junit.testparameterinjector.TestParameterInjector; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading @@ -59,6 +61,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import java.util.ArrayList; import java.util.Arrays; /** * Tests for {@link ActivityEmbeddingAnimationRunner}. Loading @@ -67,7 +70,7 @@ import java.util.ArrayList; * atest WMShellUnitTests:ActivityEmbeddingAnimationRunnerTests */ @SmallTest @RunWith(AndroidJUnit4.class) @RunWith(TestParameterInjector.class) public class ActivityEmbeddingAnimationRunnerTests extends ActivityEmbeddingAnimationTestBase { @Rule Loading Loading @@ -204,15 +207,13 @@ public class ActivityEmbeddingAnimationRunnerTests extends ActivityEmbeddingAnim // TODO(b/243518738): Rewrite with TestParameter @EnableFlags(Flags.FLAG_ACTIVITY_EMBEDDING_OVERLAY_PRESENTATION_FLAG) @Test public void testCalculateParentBounds_flagEnabled() { public void testCalculateParentBounds_flagEnabled_emptyParentSize() { TransitionInfo.Change change; final TransitionInfo.Change stubChange = createChange(0 /* flags */); final Rect actualParentBounds = new Rect(); Rect parentBounds = new Rect(0, 0, 2000, 2000); Rect endAbsBounds = new Rect(0, 0, 2000, 2000); change = prepareChangeForParentBoundsCalculationTest( new Point(0, 0) /* endRelOffset */, endAbsBounds, new Rect(0, 0, 2000, 2000), new Point() /* endParentSize */ ); Loading @@ -220,69 +221,80 @@ public class ActivityEmbeddingAnimationRunnerTests extends ActivityEmbeddingAnim assertTrue("Parent bounds must be empty because end parent size is not set.", actualParentBounds.isEmpty()); } String testString = "Parent start with (0, 0)"; change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); calculateParentBounds(change, stubChange, actualParentBounds); assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); testString = "Container not start with (0, 0)"; parentBounds = new Rect(0, 0, 2000, 2000); endAbsBounds = new Rect(1000, 500, 2000, 1500); change = prepareChangeForParentBoundsCalculationTest( @EnableFlags(Flags.FLAG_ACTIVITY_EMBEDDING_OVERLAY_PRESENTATION_FLAG) @Test public void testCalculateParentBounds_flagEnabled( @TestParameter ParentBoundsTestParameters params) { final TransitionInfo.Change stubChange = createChange(0 /*flags*/); final Rect parentBounds = params.getParentBounds(); final Rect endAbsBounds = params.getEndAbsBounds(); final TransitionInfo.Change change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); final Rect actualParentBounds = new Rect(); calculateParentBounds(change, stubChange, actualParentBounds); assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); testString = "Parent container on the right"; parentBounds = new Rect(1000, 0, 2000, 2000); endAbsBounds = new Rect(1000, 500, 1500, 1500); change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); calculateParentBounds(change, stubChange, actualParentBounds); assertEquals(parentBounds, actualParentBounds); } assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); private enum ParentBoundsTestParameters { PARENT_START_WITH_0_0( new int[]{0, 0, 2000, 2000}, new int[]{0, 0, 2000, 2000}), CONTAINER_NOT_START_WITH_0_0( new int[] {0, 0, 2000, 2000}, new int[] {1000, 500, 1500, 1500}), PARENT_ON_THE_RIGHT( new int[] {1000, 0, 2000, 2000}, new int[] {1000, 500, 1500, 1500}), PARENT_ON_THE_BOTTOM( new int[] {0, 1000, 2000, 2000}, new int[] {500, 1500, 1500, 2000}), PARENT_IN_THE_MIDDLE( new int[] {500, 500, 1500, 1500}, new int[] {1000, 500, 1500, 1000}); testString = "Parent container on the bottom"; parentBounds = new Rect(0, 1000, 2000, 2000); endAbsBounds = new Rect(500, 1500, 1500, 2000); change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); /** * An int array to present {left, top, right, bottom} of the parent {@link Rect bounds}. */ @NonNull private final int[] mParentBounds; calculateParentBounds(change, stubChange, actualParentBounds); /** * An int array to present {left, top, right, bottom} of the absolute container * {@link Rect bounds} after the transition finishes. */ @NonNull private final int[] mEndAbsBounds; assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); ParentBoundsTestParameters( @NonNull int[] parentBounds, @NonNull int[] endAbsBounds) { mParentBounds = parentBounds; mEndAbsBounds = endAbsBounds; } testString = "Parent container in the middle"; parentBounds = new Rect(500, 500, 1500, 1500); endAbsBounds = new Rect(1000, 500, 1500, 1000); change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); @NonNull private Rect getParentBounds() { return asRect(mParentBounds); } calculateParentBounds(change, stubChange, actualParentBounds); @NonNull private Rect getEndAbsBounds() { return asRect(mEndAbsBounds); } assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); @NonNull private static Rect asRect(@NonNull int[] bounds) { if (bounds.length != 4) { throw new IllegalArgumentException("There must be exactly 4 elements in bounds, " + "but found " + bounds.length + ": " + Arrays.toString(bounds)); } return new Rect(bounds[0], bounds[1], bounds[2], bounds[3]); } } @Test Loading Loading
libs/WindowManager/Jetpack/src/androidx/window/extensions/embedding/SplitPresenter.java +12 −0 Original line number Diff line number Diff line Loading @@ -1359,4 +1359,16 @@ class SplitPresenter extends JetpackTaskFragmentOrganizer { return new ParentContainerInfo(taskProperties.getTaskMetrics(), configuration, windowLayoutInfo); } @VisibleForTesting @NonNull static String positionToString(@ContainerPosition int position) { return switch (position) { case CONTAINER_POSITION_LEFT -> "left"; case CONTAINER_POSITION_TOP -> "top"; case CONTAINER_POSITION_RIGHT -> "right"; case CONTAINER_POSITION_BOTTOM -> "bottom"; default -> "Unknown position:" + position; }; } }
libs/WindowManager/Jetpack/tests/unittest/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -32,6 +32,7 @@ android_test { ], static_libs: [ "TestParameterInjector", "androidx.window.extensions", "androidx.window.extensions.core_core", "junit", Loading
libs/WindowManager/Jetpack/tests/unittest/src/androidx/window/extensions/embedding/OverlayPresentationTest.java +69 −53 Original line number Diff line number Diff line Loading @@ -35,6 +35,7 @@ import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSI import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSITION_RIGHT; import static androidx.window.extensions.embedding.SplitPresenter.CONTAINER_POSITION_TOP; import static androidx.window.extensions.embedding.SplitPresenter.getOverlayPosition; import static androidx.window.extensions.embedding.SplitPresenter.positionToString; import static androidx.window.extensions.embedding.SplitPresenter.sanitizeBounds; import static androidx.window.extensions.embedding.WindowAttributes.DIM_AREA_ON_TASK; Loading Loading @@ -78,7 +79,6 @@ import android.window.WindowContainerTransaction; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.test.core.app.ApplicationProvider; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import androidx.window.common.DeviceStateManagerFoldingFeatureProducer; import androidx.window.extensions.layout.WindowLayoutComponentImpl; Loading @@ -86,6 +86,9 @@ import androidx.window.extensions.layout.WindowLayoutInfo; import com.android.window.flags.Flags; import com.google.testing.junit.testparameterinjector.TestParameter; import com.google.testing.junit.testparameterinjector.TestParameterInjector; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading @@ -108,7 +111,7 @@ import java.util.List; @SuppressWarnings("GuardedBy") @Presubmit @SmallTest @RunWith(AndroidJUnit4.class) @RunWith(TestParameterInjector.class) public class OverlayPresentationTest { @Rule public MockitoRule rule = MockitoJUnit.rule(); Loading Loading @@ -875,57 +878,70 @@ public class OverlayPresentationTest { eq(overlayContainer.getTaskFragmentToken()), eq(activityToken)); } // TODO(b/243518738): Rewrite with TestParameter. @Test public void testGetOverlayPosition() { assertWithMessage("It must be position left for left overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left, TASK_BOUNDS.top, TASK_BOUNDS.right / 2, TASK_BOUNDS.bottom), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_LEFT); assertWithMessage("It must be position left for shrunk left overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left, TASK_BOUNDS.top + 20, TASK_BOUNDS.right / 2, TASK_BOUNDS.bottom - 20), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_LEFT); assertWithMessage("It must be position left for top overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left, TASK_BOUNDS.top, TASK_BOUNDS.right, TASK_BOUNDS.bottom / 2), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_TOP); assertWithMessage("It must be position left for shrunk top overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left + 20, TASK_BOUNDS.top, TASK_BOUNDS.right - 20, TASK_BOUNDS.bottom / 2), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_TOP); assertWithMessage("It must be position left for right overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.right / 2, TASK_BOUNDS.top, TASK_BOUNDS.right, TASK_BOUNDS.bottom), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_RIGHT); assertWithMessage("It must be position left for shrunk right overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.right / 2, TASK_BOUNDS.top + 20, TASK_BOUNDS.right, TASK_BOUNDS.bottom - 20), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_RIGHT); assertWithMessage("It must be position left for bottom overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left, TASK_BOUNDS.bottom / 2, TASK_BOUNDS.right, TASK_BOUNDS.bottom), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_BOTTOM); assertWithMessage("It must be position left for shrunk bottom overlay.") .that(getOverlayPosition(new Rect( TASK_BOUNDS.left + 20, TASK_BOUNDS.bottom / 20, TASK_BOUNDS.right - 20, TASK_BOUNDS.bottom), TASK_BOUNDS)).isEqualTo(CONTAINER_POSITION_BOTTOM); @Test public void testGetOverlayPosition(@TestParameter OverlayPositionTestParams params) { final Rect taskBounds = new Rect(TASK_BOUNDS); final Rect overlayBounds = params.toOverlayBounds(); final int overlayPosition = getOverlayPosition(overlayBounds, taskBounds); assertWithMessage("The overlay position must be " + positionToString(params.mPosition) + ", but is " + positionToString(overlayPosition) + ", parent bounds=" + taskBounds + ", overlay bounds=" + overlayBounds) .that(overlayPosition).isEqualTo(params.mPosition); } private enum OverlayPositionTestParams { LEFT_OVERLAY(CONTAINER_POSITION_LEFT, false /* shouldBeShrunk */), LEFT_SHRUNK_OVERLAY(CONTAINER_POSITION_LEFT, true /* shouldBeShrunk */), TOP_OVERLAY(CONTAINER_POSITION_TOP, false /* shouldBeShrunk */), TOP_SHRUNK_OVERLAY(CONTAINER_POSITION_TOP, true /* shouldBeShrunk */), RIGHT_OVERLAY(CONTAINER_POSITION_RIGHT, false /* shouldBeShrunk */), RIGHT_SHRUNK_OVERLAY(CONTAINER_POSITION_RIGHT, true /* shouldBeShrunk */), BOTTOM_OVERLAY(CONTAINER_POSITION_BOTTOM, false /* shouldBeShrunk */), BOTTOM_SHRUNK_OVERLAY(CONTAINER_POSITION_BOTTOM, true /* shouldBeShrunk */); @SplitPresenter.ContainerPosition private final int mPosition; private final boolean mShouldBeShrunk; OverlayPositionTestParams( @SplitPresenter.ContainerPosition int position, boolean shouldBeShrunk) { mPosition = position; mShouldBeShrunk = shouldBeShrunk; } @NonNull private Rect toOverlayBounds() { Rect r = new Rect(TASK_BOUNDS); final int offset = mShouldBeShrunk ? 20 : 0; switch (mPosition) { case CONTAINER_POSITION_LEFT: r.top += offset; r.right /= 2; r.bottom -= offset; break; case CONTAINER_POSITION_TOP: r.left += offset; r.right -= offset; r.bottom /= 2; break; case CONTAINER_POSITION_RIGHT: r.left = r.right / 2; r.top += offset; r.bottom -= offset; break; case CONTAINER_POSITION_BOTTOM: r.left += offset; r.right -= offset; r.top = r.bottom / 2; break; default: throw new IllegalArgumentException("Invalid position: " + mPosition); } return r; } } /** Loading
libs/WindowManager/Shell/tests/unittest/Android.bp +1 −0 Original line number Diff line number Diff line Loading @@ -37,6 +37,7 @@ android_test { ], static_libs: [ "TestParameterInjector", "WindowManager-Shell", "junit", "flag-junit", Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/activityembedding/ActivityEmbeddingAnimationRunnerTests.java +73 −61 Original line number Diff line number Diff line Loading @@ -46,12 +46,14 @@ import android.view.animation.AlphaAnimation; import android.view.animation.Animation; import android.window.TransitionInfo; import androidx.test.ext.junit.runners.AndroidJUnit4; import androidx.test.filters.SmallTest; import com.android.window.flags.Flags; import com.android.wm.shell.transition.TransitionInfoBuilder; import com.google.testing.junit.testparameterinjector.TestParameter; import com.google.testing.junit.testparameterinjector.TestParameterInjector; import org.junit.Before; import org.junit.Rule; import org.junit.Test; Loading @@ -59,6 +61,7 @@ import org.junit.runner.RunWith; import org.mockito.ArgumentCaptor; import java.util.ArrayList; import java.util.Arrays; /** * Tests for {@link ActivityEmbeddingAnimationRunner}. Loading @@ -67,7 +70,7 @@ import java.util.ArrayList; * atest WMShellUnitTests:ActivityEmbeddingAnimationRunnerTests */ @SmallTest @RunWith(AndroidJUnit4.class) @RunWith(TestParameterInjector.class) public class ActivityEmbeddingAnimationRunnerTests extends ActivityEmbeddingAnimationTestBase { @Rule Loading Loading @@ -204,15 +207,13 @@ public class ActivityEmbeddingAnimationRunnerTests extends ActivityEmbeddingAnim // TODO(b/243518738): Rewrite with TestParameter @EnableFlags(Flags.FLAG_ACTIVITY_EMBEDDING_OVERLAY_PRESENTATION_FLAG) @Test public void testCalculateParentBounds_flagEnabled() { public void testCalculateParentBounds_flagEnabled_emptyParentSize() { TransitionInfo.Change change; final TransitionInfo.Change stubChange = createChange(0 /* flags */); final Rect actualParentBounds = new Rect(); Rect parentBounds = new Rect(0, 0, 2000, 2000); Rect endAbsBounds = new Rect(0, 0, 2000, 2000); change = prepareChangeForParentBoundsCalculationTest( new Point(0, 0) /* endRelOffset */, endAbsBounds, new Rect(0, 0, 2000, 2000), new Point() /* endParentSize */ ); Loading @@ -220,69 +221,80 @@ public class ActivityEmbeddingAnimationRunnerTests extends ActivityEmbeddingAnim assertTrue("Parent bounds must be empty because end parent size is not set.", actualParentBounds.isEmpty()); } String testString = "Parent start with (0, 0)"; change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); calculateParentBounds(change, stubChange, actualParentBounds); assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); testString = "Container not start with (0, 0)"; parentBounds = new Rect(0, 0, 2000, 2000); endAbsBounds = new Rect(1000, 500, 2000, 1500); change = prepareChangeForParentBoundsCalculationTest( @EnableFlags(Flags.FLAG_ACTIVITY_EMBEDDING_OVERLAY_PRESENTATION_FLAG) @Test public void testCalculateParentBounds_flagEnabled( @TestParameter ParentBoundsTestParameters params) { final TransitionInfo.Change stubChange = createChange(0 /*flags*/); final Rect parentBounds = params.getParentBounds(); final Rect endAbsBounds = params.getEndAbsBounds(); final TransitionInfo.Change change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); final Rect actualParentBounds = new Rect(); calculateParentBounds(change, stubChange, actualParentBounds); assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); testString = "Parent container on the right"; parentBounds = new Rect(1000, 0, 2000, 2000); endAbsBounds = new Rect(1000, 500, 1500, 1500); change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); calculateParentBounds(change, stubChange, actualParentBounds); assertEquals(parentBounds, actualParentBounds); } assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); private enum ParentBoundsTestParameters { PARENT_START_WITH_0_0( new int[]{0, 0, 2000, 2000}, new int[]{0, 0, 2000, 2000}), CONTAINER_NOT_START_WITH_0_0( new int[] {0, 0, 2000, 2000}, new int[] {1000, 500, 1500, 1500}), PARENT_ON_THE_RIGHT( new int[] {1000, 0, 2000, 2000}, new int[] {1000, 500, 1500, 1500}), PARENT_ON_THE_BOTTOM( new int[] {0, 1000, 2000, 2000}, new int[] {500, 1500, 1500, 2000}), PARENT_IN_THE_MIDDLE( new int[] {500, 500, 1500, 1500}, new int[] {1000, 500, 1500, 1000}); testString = "Parent container on the bottom"; parentBounds = new Rect(0, 1000, 2000, 2000); endAbsBounds = new Rect(500, 1500, 1500, 2000); change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); /** * An int array to present {left, top, right, bottom} of the parent {@link Rect bounds}. */ @NonNull private final int[] mParentBounds; calculateParentBounds(change, stubChange, actualParentBounds); /** * An int array to present {left, top, right, bottom} of the absolute container * {@link Rect bounds} after the transition finishes. */ @NonNull private final int[] mEndAbsBounds; assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); ParentBoundsTestParameters( @NonNull int[] parentBounds, @NonNull int[] endAbsBounds) { mParentBounds = parentBounds; mEndAbsBounds = endAbsBounds; } testString = "Parent container in the middle"; parentBounds = new Rect(500, 500, 1500, 1500); endAbsBounds = new Rect(1000, 500, 1500, 1000); change = prepareChangeForParentBoundsCalculationTest( new Point(endAbsBounds.left - parentBounds.left, endAbsBounds.top - parentBounds.top), endAbsBounds, new Point(parentBounds.width(), parentBounds.height())); @NonNull private Rect getParentBounds() { return asRect(mParentBounds); } calculateParentBounds(change, stubChange, actualParentBounds); @NonNull private Rect getEndAbsBounds() { return asRect(mEndAbsBounds); } assertEquals(testString + ": Parent bounds must be " + parentBounds, parentBounds, actualParentBounds); @NonNull private static Rect asRect(@NonNull int[] bounds) { if (bounds.length != 4) { throw new IllegalArgumentException("There must be exactly 4 elements in bounds, " + "but found " + bounds.length + ": " + Arrays.toString(bounds)); } return new Rect(bounds[0], bounds[1], bounds[2], bounds[3]); } } @Test Loading