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

Commit 25cfccaa authored by Mateusz Cicheński's avatar Mateusz Cicheński
Browse files

Add a flicker test for entering PiP via navigation to Home

Bug: 216577639
Test: atest WMShellFlickerTests:EnterPipOnUserLeaveHintTest

Change-Id: I59448191a22c31e4591346de58695ff653e3687f
parent f295b662
Loading
Loading
Loading
Loading
+51 −15
Original line number Diff line number Diff line
@@ -69,8 +69,10 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
        action: String? = null,
        stringExtras: Map<String, String>
    ) {
        launchViaIntentAndWaitShown(wmHelper, expectedWindowName, action, stringExtras,
            waitConditions = arrayOf(WindowManagerStateHelper.pipShownCondition))
        launchViaIntentAndWaitShown(
            wmHelper, expectedWindowName, action, stringExtras,
            waitConditions = arrayOf(WindowManagerStateHelper.pipShownCondition)
        )
    }

    /**
@@ -105,6 +107,37 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
        uiDevice.wait(Until.gone(By.res(SYSTEMUI_PACKAGE, "dismiss")), FIND_TIMEOUT)
    }

    @JvmOverloads
    fun enterPipViaHomeButton(wmHelper: WindowManagerStateHelper) {
        uiDevice.pressHome()

        // Wait on WMHelper or simply wait for 3 seconds
        wmHelper.waitPipShown() ?: SystemClock.sleep(3_000)
        // when entering pip, the dismiss button is visible at the start. to ensure the pip
        // animation is complete, wait until the pip dismiss button is no longer visible.
        // b/176822698: dismiss-only state will be removed in the future
        uiDevice.wait(Until.gone(By.res(SYSTEMUI_PACKAGE, "dismiss")), FIND_TIMEOUT)
    }

    @JvmOverloads
    fun enterPipViaSwipeToHome(wmHelper: WindowManagerStateHelper) {
        uiDevice.swipe(
            uiDevice.displayWidth / 2, uiDevice.displayHeight - 10,
            uiDevice.displayWidth / 2, uiDevice.displayHeight - 300, 3
        )

        // Wait on WMHelper or simply wait for 3 seconds
        wmHelper.waitPipShown() ?: SystemClock.sleep(3_000)
        // when entering pip, the dismiss button is visible at the start. to ensure the pip
        // animation is complete, wait until the pip dismiss button is no longer visible.
        // b/176822698: dismiss-only state will be removed in the future
        uiDevice.wait(Until.gone(By.res(SYSTEMUI_PACKAGE, "dismiss")), FIND_TIMEOUT)
    }

    fun enableEnterPipOnUserLeaveHint() {
        clickObject(ENTER_PIP_ON_USER_LEAVE_HINT)
    }

    fun clickStartMediaSessionButton() {
        clickObject(MEDIA_SESSION_START_RADIO_BUTTON_ID)
    }
@@ -121,8 +154,10 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
    fun stopMedia() = mediaController?.transportControls?.stop()
        ?: error("No active media session found")

    @Deprecated("Use PipAppHelper.closePipWindow(wmHelper) instead",
        ReplaceWith("closePipWindow(wmHelper)"))
    @Deprecated(
        "Use PipAppHelper.closePipWindow(wmHelper) instead",
        ReplaceWith("closePipWindow(wmHelper)")
    )
    fun closePipWindow() {
        if (isTelevision) {
            uiDevice.closeTvPipWindow()
@@ -194,5 +229,6 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
        private const val ENTER_PIP_BUTTON_ID = "enter_pip"
        private const val WITH_CUSTOM_ACTIONS_BUTTON_ID = "with_custom_actions"
        private const val MEDIA_SESSION_START_RADIO_BUTTON_ID = "media_session_start"
        private const val ENTER_PIP_ON_USER_LEAVE_HINT = "enter_pip_on_leave_manual"
    }
}
+113 −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.wm.shell.flicker.pip

import androidx.test.filters.RequiresDevice
import com.android.server.wm.flicker.FlickerParametersRunnerFactory
import com.android.server.wm.flicker.FlickerTestParameter
import com.android.server.wm.flicker.annotation.Group3
import com.android.server.wm.flicker.dsl.FlickerBuilder
import org.junit.Assume
import org.junit.FixMethodOrder
import org.junit.runner.RunWith
import org.junit.runners.MethodSorters
import org.junit.runners.Parameterized

/**
 * Test entering pip from an app via [onUserLeaveHint] and by navigating to home.
 *
 * To run this test: `atest WMShellFlickerTests:EnterPipOnUserLeaveHintTest`
 *
 * Actions:
 *     Launch an app in full screen
 *     Select "Via code behind" radio button
 *     Press Home button to put [pipApp] in pip mode
 *
 * Notes:
 *     1. All assertions are inherited from [EnterPipTest]
 *     2. Part of the test setup occurs automatically via
 *        [com.android.server.wm.flicker.TransitionRunnerWithRules],
 *        including configuring navigation mode, initial orientation and ensuring no
 *        apps are running before setup
 */
@RequiresDevice
@RunWith(Parameterized::class)
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group3
class EnterPipOnUserLeaveHintTest(testSpec: FlickerTestParameter) : EnterPipTest(testSpec) {

    /**
     * Defines the transition used to run the test
     */
    override val transition: FlickerBuilder.() -> Unit
        get() = {
            setupAndTeardown(this)
            setup {
                eachRun {
                    pipApp.launchViaIntent(wmHelper)
                    pipApp.enableEnterPipOnUserLeaveHint()
                }
            }
            teardown {
                eachRun {
                    pipApp.exit(wmHelper)
                }
            }
            transitions {
                when (testSpec.isGesturalNavigation) {
                    true -> pipApp.enterPipViaSwipeToHome(wmHelper)
                    false -> pipApp.enterPipViaHomeButton(wmHelper)
                }
            }
        }

    override fun pipAppLayerAlwaysVisible() {
        if (!testSpec.isGesturalNavigation) super.pipAppLayerAlwaysVisible() else {
            // pip layer in gesture nav will disappear during transition
            testSpec.assertLayers {
                this.isVisible(pipApp.component)
                    .then().isInvisible(pipApp.component)
                    .then().isVisible(pipApp.component)
            }
        }
    }

    override fun pipLayerReduces() {
        // in gestural nav the pip enters through alpha animation
        Assume.assumeFalse(testSpec.isGesturalNavigation)
        super.pipLayerReduces()
    }

    override fun focusChanges() {
        // in gestural nav the focus goes to different activity on swipe up
        Assume.assumeFalse(testSpec.isGesturalNavigation)
        super.focusChanges()
    }

    override fun pipLayerRemainInsideVisibleBounds() {
        if (!testSpec.isGesturalNavigation) super.pipLayerRemainInsideVisibleBounds() else {
            // pip layer in gesture nav will disappear during transition
            testSpec.assertLayersStart {
                this.visibleRegion(pipApp.component).coversAtMost(displayBounds)
            }
            testSpec.assertLayersEnd {
                this.visibleRegion(pipApp.component).coversAtMost(displayBounds)
            }
        }
    }
}
+10 −8
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ import org.junit.runners.Parameterized
 *
 * Notes:
 *     1. Some default assertions (e.g., nav bar, status bar and screen covered)
 *        are inherited [PipTransition]
 *        are inherited from [PipTransition]
 *     2. Part of the test setup occurs automatically via
 *        [com.android.server.wm.flicker.TransitionRunnerWithRules],
 *        including configuring navigation mode, initial orientation and ensuring no
@@ -54,7 +54,7 @@ import org.junit.runners.Parameterized
@Parameterized.UseParametersRunnerFactory(FlickerParametersRunnerFactory::class)
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Group3
class EnterPipTest(testSpec: FlickerTestParameter) : PipTransition(testSpec) {
open class EnterPipTest(testSpec: FlickerTestParameter) : PipTransition(testSpec) {

    /**
     * Defines the transition used to run the test
@@ -98,7 +98,7 @@ class EnterPipTest(testSpec: FlickerTestParameter) : PipTransition(testSpec) {
     */
    @Presubmit
    @Test
    fun pipAppLayerAlwaysVisible() {
    open fun pipAppLayerAlwaysVisible() {
        testSpec.assertLayers {
            this.isVisible(pipApp.component)
        }
@@ -122,7 +122,7 @@ class EnterPipTest(testSpec: FlickerTestParameter) : PipTransition(testSpec) {
     */
    @Presubmit
    @Test
    fun pipLayerRemainInsideVisibleBounds() {
    open fun pipLayerRemainInsideVisibleBounds() {
        testSpec.assertLayersVisibleRegion(pipApp.component) {
            coversAtMost(displayBounds)
        }
@@ -133,7 +133,7 @@ class EnterPipTest(testSpec: FlickerTestParameter) : PipTransition(testSpec) {
     */
    @Presubmit
    @Test
    fun pipLayerReduces() {
    open fun pipLayerReduces() {
        val layerName = pipApp.component.toLayerName()
        testSpec.assertLayers {
            val pipLayerList = this.layers { it.name.contains(layerName) && it.isVisible }
@@ -175,7 +175,7 @@ class EnterPipTest(testSpec: FlickerTestParameter) : PipTransition(testSpec) {
     */
    @Presubmit
    @Test
    fun focusChanges() {
    open fun focusChanges() {
        testSpec.assertEventLog {
            this.focusChanges(pipApp.`package`, "NexusLauncherActivity")
        }
@@ -192,8 +192,10 @@ class EnterPipTest(testSpec: FlickerTestParameter) : PipTransition(testSpec) {
        @JvmStatic
        fun getParams(): List<FlickerTestParameter> {
            return FlickerTestParameterFactory.getInstance()
                .getConfigNonRotationTests(supportedRotations = listOf(Surface.ROTATION_0),
                    repetitions = 3)
                .getConfigNonRotationTests(
                    supportedRotations = listOf(Surface.ROTATION_0),
                    repetitions = 3
                )
        }
    }
}
+26 −0
Original line number Diff line number Diff line
@@ -40,6 +40,32 @@
        android:layout_height="wrap_content"
        android:text="With custom actions"/>

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:checkedButton="@id/enter_pip_on_leave_disabled">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Enter PiP on home press"/>

        <RadioButton
            android:id="@+id/enter_pip_on_leave_disabled"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Disabled"
            android:onClick="onAutoPipSelected"/>

        <RadioButton
            android:id="@+id/enter_pip_on_leave_manual"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="Via code behind"
            android:onClick="onAutoPipSelected"/>
    </RadioGroup>

    <RadioGroup
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
+23 −0
Original line number Diff line number Diff line
@@ -48,6 +48,7 @@ import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.CheckBox;
import android.widget.RadioButton;

import java.util.ArrayList;
import java.util.Arrays;
@@ -201,6 +202,17 @@ public class PipActivity extends Activity {
        super.onDestroy();
    }

    @Override
    protected void onUserLeaveHint() {
        // Only used when auto PiP is disabled. This is to simulate the behavior that an app
        // supports regular PiP but not auto PiP.
        final boolean manuallyEnterPip =
                ((RadioButton) findViewById(R.id.enter_pip_on_leave_manual)).isChecked();
        if (manuallyEnterPip) {
            enterPictureInPictureMode();
        }
    }

    private RemoteAction buildRemoteAction(Icon icon, String label, String action) {
        final Intent intent = new Intent(action);
        final PendingIntent pendingIntent =
@@ -216,6 +228,17 @@ public class PipActivity extends Activity {
        enterPictureInPictureMode(mPipParamsBuilder.build());
    }

    public void onAutoPipSelected(View v) {
        switch (v.getId()) {
            case R.id.enter_pip_on_leave_manual:
                // disable auto enter PiP
            case R.id.enter_pip_on_leave_disabled:
                mPipParamsBuilder.setAutoEnterEnabled(false);
                setPictureInPictureParams(mPipParamsBuilder.build());
                break;
        }
    }

    public void onRatioSelected(View v) {
        switch (v.getId()) {
            case R.id.ratio_default: