Add a flicker test for entering PiP via navigation to Home

Bug: 216577639
Test: atest WMShellFlickerTests:EnterPipOnUserLeaveHintTest

Change-Id: I59448191a22c31e4591346de58695ff653e3687f
This commit is contained in:
Mateusz Cicheński
2022-05-31 18:36:42 +00:00
parent f295b662ee
commit 25cfccaaa0
5 changed files with 223 additions and 23 deletions

View File

@@ -39,7 +39,7 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
) {
private val mediaSessionManager: MediaSessionManager
get() = context.getSystemService(MediaSessionManager::class.java)
?: error("Could not get MediaSessionManager")
?: error("Could not get MediaSessionManager")
private val mediaController: MediaController?
get() = mediaSessionManager.getActiveSessions(null).firstOrNull {
@@ -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)
)
}
/**
@@ -85,7 +87,7 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
// from "the bottom".
repeat(FOCUS_ATTEMPTS) {
uiDevice.findObject(selector)?.apply { if (isFocusedOrHasFocusedChild) return true }
?: error("The object we try to focus on is gone.")
?: error("The object we try to focus on is gone.")
uiDevice.pressDPadDown()
uiDevice.waitForIdle()
@@ -100,29 +102,62 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
// 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.
// 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 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)
}
fun checkWithCustomActionsCheckbox() = uiDevice
.findObject(By.res(component.packageName, WITH_CUSTOM_ACTIONS_BUTTON_ID))
?.takeIf { it.isCheckable }
?.apply { if (!isChecked) clickObject(WITH_CUSTOM_ACTIONS_BUTTON_ID) }
?: error("'With custom actions' checkbox not found")
.findObject(By.res(component.packageName, WITH_CUSTOM_ACTIONS_BUTTON_ID))
?.takeIf { it.isCheckable }
?.apply { if (!isChecked) clickObject(WITH_CUSTOM_ACTIONS_BUTTON_ID) }
?: error("'With custom actions' checkbox not found")
fun pauseMedia() = mediaController?.transportControls?.pause()
?: error("No active media session found")
?: error("No active media session found")
fun stopMedia() = mediaController?.transportControls?.stop()
?: error("No active media session found")
?: 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()
@@ -152,7 +187,7 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
val dismissSelector = By.res(SYSTEMUI_PACKAGE, "dismiss")
uiDevice.wait(Until.hasObject(dismissSelector), FIND_TIMEOUT)
val dismissPipObject = uiDevice.findObject(dismissSelector)
?: error("PIP window dismiss button not found")
?: error("PIP window dismiss button not found")
val dismissButtonBounds = dismissPipObject.visibleBounds
uiDevice.click(dismissButtonBounds.centerX(), dismissButtonBounds.centerY())
}
@@ -172,7 +207,7 @@ class PipAppHelper(instrumentation: Instrumentation) : BaseAppHelper(
val expandSelector = By.res(SYSTEMUI_PACKAGE, "expand_button")
uiDevice.wait(Until.hasObject(expandSelector), FIND_TIMEOUT)
val expandPipObject = uiDevice.findObject(expandSelector)
?: error("PIP window expand button not found")
?: error("PIP window expand button not found")
val expandButtonBounds = expandPipObject.visibleBounds
uiDevice.click(expandButtonBounds.centerX(), expandButtonBounds.centerY())
wmHelper.waitPipGone()
@@ -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"
}
}

View File

@@ -0,0 +1,113 @@
/*
* 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)
}
}
}
}

View File

@@ -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
)
}
}
}

View File

@@ -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"

View File

@@ -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: