diff --git a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml index d8474b865a365..0d684e8b0ab53 100644 --- a/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml +++ b/libs/WindowManager/Shell/res/layout/tv_pip_menu.xml @@ -15,6 +15,7 @@ limitations under the License. --> > = rotationParams + } +} \ No newline at end of file diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvPipNotificationTests.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvPipNotificationTests.kt index 1d44658d71adc..7a9b33b467425 100644 --- a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvPipNotificationTests.kt +++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvPipNotificationTests.kt @@ -20,7 +20,6 @@ import android.app.Notification import android.app.PendingIntent import android.os.Bundle import android.service.notification.StatusBarNotification -import android.view.Surface import androidx.test.filters.RequiresDevice import com.android.wm.shell.flicker.NotificationListener.Companion.findNotification import com.android.wm.shell.flicker.NotificationListener.Companion.startNotificationListener @@ -32,10 +31,8 @@ import org.junit.Assert.assertNotNull import org.junit.Assert.assertNull import org.junit.Assert.assertTrue import org.junit.Before -import org.junit.FixMethodOrder import org.junit.Test import org.junit.runner.RunWith -import org.junit.runners.MethodSorters import org.junit.runners.Parameterized /** @@ -44,7 +41,6 @@ import org.junit.runners.Parameterized */ @RequiresDevice @RunWith(Parameterized::class) -@FixMethodOrder(MethodSorters.NAME_ASCENDING) class TvPipNotificationTests(rotationName: String, rotation: Int) : TvPipTestBase(rotationName, rotation) { @@ -60,7 +56,6 @@ class TvPipNotificationTests(rotationName: String, rotation: Int) @After override fun tearDown() { stopNotificationListener() - testApp.forceStop() super.tearDown() } @@ -108,7 +103,7 @@ class TvPipNotificationTests(rotationName: String, rotation: Int) notification.contentIntent?.send() ?: fail("Pip notification should contain `content_intent`") - assertTrue("Pip menu should have been shown after sending `content_intent`", + assertNotNull("Pip menu should have been shown after sending `content_intent`", uiDevice.waitForTvPipMenu()) uiDevice.pressBack() @@ -156,18 +151,13 @@ class TvPipNotificationTests(rotationName: String, rotation: Int) testApp.closePipWindow() } - private fun fail(message: String): Nothing = throw AssertionError(message) - companion object { private const val TITLE_MEDIA_SESSION_PLAYING = "TestApp media is playing" private const val TITLE_MEDIA_SESSION_PAUSED = "TestApp media is paused" @Parameterized.Parameters(name = "{0}") @JvmStatic - fun getParams(): Collection> { - val supportedRotations = intArrayOf(Surface.ROTATION_0) - return supportedRotations.map { arrayOf(Surface.rotationToString(it), it) } - } + fun getParams(): Collection> = rotationParams } } diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvPipTestBase.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvPipTestBase.kt index 104248c64dddf..05f4b0b0d918b 100644 --- a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvPipTestBase.kt +++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvPipTestBase.kt @@ -18,6 +18,8 @@ package com.android.wm.shell.flicker.pip.tv import android.content.pm.PackageManager.FEATURE_LEANBACK import android.content.pm.PackageManager.FEATURE_LEANBACK_ONLY +import android.view.Surface.ROTATION_0 +import android.view.Surface.rotationToString import com.android.server.wm.flicker.helpers.wakeUpAndGoToHomeScreen import com.android.wm.shell.flicker.pip.PipTestBase import org.junit.After @@ -40,5 +42,14 @@ abstract class TvPipTestBase(rotationName: String, rotation: Int) @After open fun tearDown() { + testApp.forceStop() + } + + protected fun fail(message: String): Nothing = throw AssertionError(message) + + companion object { + @JvmStatic + protected val rotationParams: Collection> = + listOf(arrayOf(rotationToString(ROTATION_0), ROTATION_0)) } } \ No newline at end of file diff --git a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvUtils.kt b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvUtils.kt index ac9ab130876dc..d9e6ff3aeb099 100644 --- a/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvUtils.kt +++ b/libs/WindowManager/Shell/tests/flicker/src/com/android/wm/shell/flicker/pip/tv/TvUtils.kt @@ -16,11 +16,35 @@ package com.android.wm.shell.flicker.pip.tv +import android.view.KeyEvent import androidx.test.uiautomator.By import androidx.test.uiautomator.UiDevice +import androidx.test.uiautomator.UiObject2 import androidx.test.uiautomator.Until import com.android.wm.shell.flicker.SYSTEM_UI_PACKAGE_NAME -fun UiDevice.waitForTvPipMenu(): Boolean { - return wait(Until.findObject(By.res(SYSTEM_UI_PACKAGE_NAME, "pip_controls")), 3_000) != null +/** Id of the root view in the com.android.wm.shell.pip.tv.PipMenuActivity */ +private const val TV_PIP_MENU_ROOT_ID = "tv_pip_menu" +private const val TV_PIP_MENU_CLOSE_BUTTON_ID = "close_button" +private const val TV_PIP_MENU_FULLSCREEN_BUTTON_ID = "full_button" + +private const val WAIT_TIME_MS = 3_000L + +private val tvPipMenuSelector = By.res(SYSTEM_UI_PACKAGE_NAME, TV_PIP_MENU_ROOT_ID) + +fun UiDevice.pressWindowKey() = pressKeyCode(KeyEvent.KEYCODE_WINDOW) + +fun UiDevice.waitForTvPipMenu(): UiObject2? = + wait(Until.findObject(tvPipMenuSelector), WAIT_TIME_MS) + +fun UiDevice.waitForTvPipMenuToClose(): Boolean = wait(Until.gone(tvPipMenuSelector), WAIT_TIME_MS) + +fun UiDevice.findTvPipMenuCloseButton(): UiObject2? = findObject( + By.res(SYSTEM_UI_PACKAGE_NAME, TV_PIP_MENU_CLOSE_BUTTON_ID)) + +fun UiDevice.findTvPipMenuFullscreenButton(): UiObject2? = findObject( + By.res(SYSTEM_UI_PACKAGE_NAME, TV_PIP_MENU_FULLSCREEN_BUTTON_ID)) + +fun UiObject2.isFullscreen(uiDevice: UiDevice): Boolean = visibleBounds.run { + height() == uiDevice.displayHeight && width() == uiDevice.displayWidth } \ No newline at end of file