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

Commit dd99ca09 authored by Chris Li's avatar Chris Li Committed by Android (Google) Code Review
Browse files

Merge "Add flicker test for ActivityEmbedding (1/n)"

parents a5eef891 d498d2f4
Loading
Loading
Loading
Loading
+17 −0
Original line number Diff line number Diff line
@@ -46,6 +46,7 @@ android_test {
        "launcher-helper-lib",
        "launcher-aosp-tapl",
        "platform-test-annotations",
        "wm-flicker-window-extensions",
    ],
}

@@ -83,5 +84,21 @@ java_library {
        "flickertestapplib",
        "truth-prebuilt",
        "app-helpers-core",
        "wm-flicker-window-extensions",
    ],
}

android_library_import {
    name: "wm-flicker-window-extensions_nodeps",
    aars: ["libs/window-extensions-release.aar"],
    sdk_version: "current",
}

java_library {
    name: "wm-flicker-window-extensions",
    sdk_version: "current",
    static_libs: [
        "wm-flicker-window-extensions_nodeps",
    ],
    installable: false,
}
+1 −0
Original line number Diff line number Diff line
@@ -43,6 +43,7 @@
    <!-- Allow the test to write directly to /sdcard/ -->
    <application android:requestLegacyExternalStorage="true">
        <uses-library android:name="android.test.runner"/>
        <uses-library android:name="androidx.window.extensions" android:required="false"/>
    </application>

    <instrumentation android:name="androidx.test.runner.AndroidJUnitRunner"
+18.8 KiB

File added.

No diff preview for this file type.

+33 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.app.Instrumentation
import androidx.test.platform.app.InstrumentationRegistry
import com.android.server.wm.flicker.helpers.ActivityEmbeddingAppHelper
import org.junit.Before

abstract class ActivityEmbeddingTestBase {
    val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    val testApp = ActivityEmbeddingAppHelper(instrumentation)

    @Before
    fun assumeActivityEmbeddingSupported() {
        // The test should only be run on devices that support ActivityEmbedding.
        ActivityEmbeddingAppHelper.assumeActivityEmbeddingSupportedDevice()
    }
}
+114 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 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.view.Surface
import android.view.WindowManagerPolicyConstants
import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.FlickerBuilderProvider
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.FlickerTestParameterFactory
import com.android.server.wm.flicker.dsl.FlickerBuilder
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

/**
 * Test opening an activity that will launch another activity as ActivityEmbedding placeholder in
 * split.
 *
 * To run this test: `atest FlickerTests:OpenActivityEmbeddingPlaceholderSplit`
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
class OpenActivityEmbeddingPlaceholderSplit(private val testSpec: FlickerTestParameter) :
    ActivityEmbeddingTestBase() {

    @FlickerBuilderProvider
    fun buildFlicker(): FlickerBuilder {
        return FlickerBuilder(instrumentation).apply {
            setup {
                eachRun {
                    testApp.launchViaIntent(wmHelper)
                }
            }
            transitions {
                testApp.launchPlaceholderSplit(wmHelper)
            }
            teardown {
                test {
                    device.pressHome()
                    testApp.exit(wmHelper)
                }
            }
        }
    }

    @Presubmit
    @Test
    fun mainActivityBecomesInvisible() {
        testSpec.assertLayers {
            isVisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
                    .then()
                    .isInvisible(ActivityEmbeddingAppHelper.MAIN_ACTIVITY_COMPONENT)
        }
    }

    @Presubmit
    @Test
    fun placeholderSplitBecomesVisible() {
        testSpec.assertLayers {
            isInvisible(ActivityEmbeddingAppHelper.PLACEHOLDER_PRIMARY_COMPONENT)
                    .then()
                    .isVisible(ActivityEmbeddingAppHelper.PLACEHOLDER_PRIMARY_COMPONENT)
        }
        testSpec.assertLayers {
            isInvisible(ActivityEmbeddingAppHelper.PLACEHOLDER_SECONDARY_COMPONENT)
                    .then()
                    .isVisible(ActivityEmbeddingAppHelper.PLACEHOLDER_SECONDARY_COMPONENT)
        }
    }

    companion object {
        /**
         * Creates the test configurations.
         *
         * See [FlickerTestParameterFactory.getConfigNonRotationTests] for configuring
         * repetitions, screen orientation and navigation modes.
         */
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): Collection<FlickerTestParameter> {
            return FlickerTestParameterFactory.getInstance()
                    .getConfigNonRotationTests(
                            repetitions = 1,
                            supportedRotations = listOf(Surface.ROTATION_0, Surface.ROTATION_90),
                            supportedNavigationModes = listOf(
                                    WindowManagerPolicyConstants.NAV_BAR_MODE_3BUTTON_OVERLAY,
                                    WindowManagerPolicyConstants.NAV_BAR_MODE_GESTURAL_OVERLAY
                            )
                    )
        }
    }
}
Loading