From f7652a6f2c912b7135c6c10c44fb97f5482edad4 Mon Sep 17 00:00:00 2001 From: An An Yu Date: Tue, 2 May 2023 23:11:23 +0000 Subject: [PATCH] [AE Flicker Test] From a split A|B, let A launch C with alwaysExpand=true, expect C to overlay split A|B. Test: atest MainActivityStartsSecondaryWithAlwaysExpand Bug: 238043427 Change-Id: I9e4f06a8ed01352d5442f7d31f0a41fcc0d05c8c --- ...vityStartsSecondaryWithAlwaysExpandTest.kt | 140 ++++++++++++++++++ .../helpers/ActivityEmbeddingAppHelper.kt | 26 ++++ .../test-apps/flickerapp/AndroidManifest.xml | 7 + .../layout/activity_embedding_main_layout.xml | 8 + ...ActivityEmbeddingAlwaysExpandActivity.java | 33 +++++ .../ActivityEmbeddingMainActivity.java | 21 +++ .../wm/flicker/testapp/ActivityOptions.java | 6 + 7 files changed, 241 insertions(+) create mode 100644 tests/FlickerTests/src/com/android/server/wm/flicker/activityembedding/open/MainActivityStartsSecondaryWithAlwaysExpandTest.kt create mode 100644 tests/FlickerTests/test-apps/flickerapp/src/com/android/server/wm/flicker/testapp/ActivityEmbeddingAlwaysExpandActivity.java diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/activityembedding/open/MainActivityStartsSecondaryWithAlwaysExpandTest.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/activityembedding/open/MainActivityStartsSecondaryWithAlwaysExpandTest.kt new file mode 100644 index 0000000000000..00316ea249b7c --- /dev/null +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/activityembedding/open/MainActivityStartsSecondaryWithAlwaysExpandTest.kt @@ -0,0 +1,140 @@ +/* + * 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.server.wm.flicker.activityembedding + +import android.platform.test.annotations.Presubmit +import android.tools.device.flicker.junit.FlickerParametersRunnerFactory +import android.tools.device.flicker.legacy.FlickerBuilder +import android.tools.device.flicker.legacy.FlickerTest +import android.tools.device.flicker.legacy.FlickerTestFactory +import androidx.test.filters.RequiresDevice +import com.android.server.wm.flicker.helpers.ActivityEmbeddingAppHelper +import org.junit.FixMethodOrder +import org.junit.Test +import org.junit.runner.RunWith +import org.junit.runners.MethodSorters +import org.junit.runners.Parameterized +import android.tools.common.datatypes.Rect + +/** + * Test launching an activity with AlwaysExpand rule. + * + * Setup: Launch A|B in split with B being the secondary activity. + * Transitions: + * A start C with alwaysExpand=true, expect C to launch in fullscreen and cover split A|B. + * + * To run this test: `atest FlickerTests:MainActivityStartsSecondaryWithAlwaysExpandTest` + */ +@RequiresDevice +@RunWith(Parameterized::class) +@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class) +@FixMethodOrder(MethodSorters.NAME_ASCENDING) +class MainActivityStartsSecondaryWithAlwaysExpandTest(flicker: FlickerTest) : + ActivityEmbeddingTestBase(flicker) { + + /** {@inheritDoc} */ + override val transition: FlickerBuilder.() -> Unit = { + setup { + tapl.setExpectedRotationCheckEnabled(false) + // Launch a split + testApp.launchViaIntent(wmHelper) + testApp.launchSecondaryActivity(wmHelper) + startDisplayBounds = + wmHelper.currentState.layerState.physicalDisplayBounds ?: error("Display not found") + } + transitions { + // Launch C with alwaysExpand + testApp.launchAlwaysExpandActivity(wmHelper) + } + teardown { + tapl.goHome() + testApp.exit(wmHelper) + } + } + + /** Transition begins with a split. */ + @Presubmit + @Test + fun startsWithSplit() { + flicker.assertWmStart { + this.isAppWindowVisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT) + } + flicker.assertWmStart { + this.isAppWindowVisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT) + } + } + + + /** Main activity should become invisible after being covered by always expand activity. */ + @Presubmit + @Test + fun mainActivityLayerBecomesInvisible() { + flicker.assertLayers { + isVisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT) + .then() + .isInvisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT) + } + } + + /** Secondary activity should become invisible after being covered by always expand activity. */ + @Presubmit + @Test + fun secondaryActivityLayerBecomesInvisible() { + flicker.assertLayers { + isVisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT) + .then() + .isInvisible(ActivityEmbeddingAppHelper.SECONDARY_ACTIVITY_COMPONENT) + } + } + + /** At the end of transition always expand activity is in fullscreen. */ + @Presubmit + @Test + fun endsWithAlwaysExpandActivityCoveringFullScreen() { + flicker.assertWmEnd { + this.visibleRegion(ActivityEmbeddingAppHelper.ALWAYS_EXPAND_ACTIVITY_COMPONENT) + .coversExactly(startDisplayBounds) + } + } + + /** Always expand activity is on top of the split. */ + @Presubmit + @Test + fun endsWithAlwaysExpandActivityOnTop() { + flicker.assertWmEnd { + this.isAppWindowOnTop( + ActivityEmbeddingAppHelper.ALWAYS_EXPAND_ACTIVITY_COMPONENT) + } + } + + companion object { + /** {@inheritDoc} */ + private var startDisplayBounds = Rect.EMPTY + /** + * Creates the test configurations. + * + * See [FlickerTestFactory.nonRotationTests] for configuring screen orientation and + * navigation modes. + */ + @Parameterized.Parameters(name = "{0}") + @JvmStatic + fun getParams(): Collection { + return FlickerTestFactory.nonRotationTests() + } + } +} + diff --git a/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ActivityEmbeddingAppHelper.kt b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ActivityEmbeddingAppHelper.kt index e019b2b226804..a21965e0d7d59 100644 --- a/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ActivityEmbeddingAppHelper.kt +++ b/tests/FlickerTests/src/com/android/server/wm/flicker/helpers/ActivityEmbeddingAppHelper.kt @@ -75,6 +75,29 @@ constructor( .StateSyncBuilder() .withActivityRemoved(SECONDARY_ACTIVITY_COMPONENT) .waitForAndVerify() + } + + /** + * Clicks the button to launch a secondary activity with alwaysExpand enabled, which will launch + * a fullscreen window on top of the visible region. + */ + fun launchAlwaysExpandActivity(wmHelper: WindowManagerStateHelper) { + val launchButton = + uiDevice.wait( + Until.findObject( + By.res(getPackage(), + "launch_always_expand_activity_button")), + FIND_TIMEOUT + ) + require(launchButton != null) { + "Can't find launch always expand activity button on screen." + } + launchButton.click() + wmHelper + .StateSyncBuilder() + .withActivityState(ALWAYS_EXPAND_ACTIVITY_COMPONENT, PlatformConsts.STATE_RESUMED) + .withActivityState(MAIN_ACTIVITY_COMPONENT, PlatformConsts.STATE_PAUSED) + .waitForAndVerify() } /** @@ -105,6 +128,9 @@ constructor( val SECONDARY_ACTIVITY_COMPONENT = ActivityOptions.ActivityEmbedding.SecondaryActivity.COMPONENT.toFlickerComponent() + val ALWAYS_EXPAND_ACTIVITY_COMPONENT = + ActivityOptions.ActivityEmbedding.AlwaysExpandActivity.COMPONENT.toFlickerComponent() + val PLACEHOLDER_PRIMARY_COMPONENT = ActivityOptions.ActivityEmbedding.PlaceholderPrimaryActivity.COMPONENT .toFlickerComponent() diff --git a/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml b/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml index 1ec9ec9b0eda1..dc9ff3b018226 100644 --- a/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml +++ b/tests/FlickerTests/test-apps/flickerapp/AndroidManifest.xml @@ -197,6 +197,13 @@ android:theme="@style/CutoutShortEdges" android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout" android:exported="false"/> + +