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

Commit c0ad57cc authored by Sergey Nikolaienkov's avatar Sergey Nikolaienkov Committed by Android (Google) Code Review
Browse files

Merge changes I9a138ba9,Ied62beb0

* changes:
  Test PiP on TV with different aspect ratios
  Always run TV PiP tests with 0 rotation
parents 6cdbca61 160bd0f0
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import com.android.wm.shell.flicker.SYSTEM_UI_PACKAGE_NAME
import com.android.wm.shell.flicker.TEST_APP_PIP_ACTIVITY_COMPONENT_NAME
import com.android.wm.shell.flicker.TEST_APP_PIP_ACTIVITY_LABEL
import org.junit.Assert.assertNotNull
import org.junit.Assert.fail

class PipAppHelper(
    instrumentation: Instrumentation
@@ -46,11 +47,12 @@ class PipAppHelper(
            it.packageName == packageName
        }

    fun clickButton(resourceId: String) =
            uiDevice.findObject(By.res(packageName, resourceId))?.click()
                ?: fail("$resourceId button is not found")

    fun clickEnterPipButton() {
        val enterPipButton = uiDevice.findObject(By.res(packageName, "enter_pip"))
        assertNotNull("Pip button not found, this usually happens when the device " +
                "was left in an unknown state (e.g. in split screen)", enterPipButton)
        enterPipButton.click()
        clickButton("enter_pip")

        // TODO(b/172321238): remove this check once hasPipWindow is fixed on TVs
        if (!isTelevision) {
+87 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2020 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.tv

import android.graphics.Rect
import android.util.Rational
import androidx.test.filters.RequiresDevice
import org.junit.Assert.assertEquals
import org.junit.Assert.assertTrue
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Test Pip Menu on TV.
 * To run this test: `atest WMShellFlickerTests:TvPipBasicTest`
 */
@RequiresDevice
@RunWith(Parameterized::class)
class TvPipBasicTest(
    private val radioButtonId: String,
    private val pipWindowRatio: Rational?
) : TvPipTestBase() {

    @Test
    fun enterPip_openMenu_pressBack_closePip() {
        // Launch test app
        testApp.launchViaIntent()

        // Set up ratio and enter Pip
        testApp.clickButton(radioButtonId)
        testApp.clickEnterPipButton()

        val actualRatio: Float = testApp.ui?.visibleBounds?.ratio
                ?: fail("Application UI not found")
        pipWindowRatio?.let { expectedRatio ->
            assertEquals("Wrong Pip window ratio", expectedRatio.toFloat(), actualRatio)
        }

        // Pressing the Window key should bring up Pip menu
        uiDevice.pressWindowKey()
        uiDevice.waitForTvPipMenu() ?: fail("Pip menu should have been shown")

        // Pressing the Back key should close the Pip menu
        uiDevice.pressBack()
        assertTrue("Pip menu should have closed", uiDevice.waitForTvPipMenuToClose())

        // Make sure Pip Window ration remained the same after Pip menu was closed
        testApp.ui?.visibleBounds?.let { newBounds ->
            assertEquals("Pip window ratio has changed", actualRatio, newBounds.ratio)
        } ?: fail("Application UI not found")

        // Close Pip
        testApp.closePipWindow()
    }

    private val Rect.ratio: Float
        get() = width().toFloat() / height()

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): Collection<Array<Any?>> {
            infix fun Int.to(denominator: Int) = Rational(this, denominator)
            return listOf(
                    arrayOf("ratio_default", null),
                    arrayOf("ratio_square", 1 to 1),
                    arrayOf("ratio_wide", 2 to 1),
                    arrayOf("ratio_tall", 1 to 2)
            )
        }
    }
}
 No newline at end of file
+1 −11
Original line number Diff line number Diff line
@@ -23,17 +23,13 @@ import com.android.wm.shell.flicker.wait
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Test Pip Menu on TV.
 * To run this test: `atest WMShellFlickerTests:TvPipMenuTests`
 */
@RequiresDevice
@RunWith(Parameterized::class)
class TvPipMenuTests(rotationName: String, rotation: Int)
    : TvPipTestBase(rotationName, rotation) {
class TvPipMenuTests : TvPipTestBase() {

    private val systemUiResources =
            packageManager.getResourcesForApplication(SYSTEM_UI_PACKAGE_NAME)
@@ -144,10 +140,4 @@ class TvPipMenuTests(rotationName: String, rotation: Int)
        uiDevice.pressWindowKey()
        return uiDevice.waitForTvPipMenu() ?: fail("Pip menu should have been shown")
    }

    companion object {
        @Parameterized.Parameters(name = "{0}")
        @JvmStatic
        fun getParams(): Collection<Array<Any>> = rotationParams
    }
}
 No newline at end of file
+1 −10
Original line number Diff line number Diff line
@@ -32,18 +32,13 @@ import org.junit.Assert.assertNull
import org.junit.Assert.assertTrue
import org.junit.Before
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.Parameterized

/**
 * Test Pip Notifications on TV.
 * To run this test: `atest WMShellFlickerTests:TvPipNotificationTests`
 */
@RequiresDevice
@RunWith(Parameterized::class)
class TvPipNotificationTests(rotationName: String, rotation: Int)
    : TvPipTestBase(rotationName, rotation) {

class TvPipNotificationTests : TvPipTestBase() {
    @Before
    override fun setUp() {
        super.setUp()
@@ -154,10 +149,6 @@ class TvPipNotificationTests(rotationName: String, rotation: Int)
    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<Array<Any>> = rotationParams
    }
}

+1 −6
Original line number Diff line number Diff line
@@ -32,8 +32,7 @@ import org.junit.Assert.assertFalse
import org.junit.Assume
import org.junit.Before

abstract class TvPipTestBase(rotationName: String, rotation: Int)
    : PipTestBase(rotationName, rotation) {
abstract class TvPipTestBase : PipTestBase(rotationToString(ROTATION_0), ROTATION_0) {

    private val isTelevision: Boolean
        get() = packageManager.run {
@@ -93,9 +92,5 @@ abstract class TvPipTestBase(rotationName: String, rotation: Int)

    companion object {
        private const val AFTER_TEXT_PROCESS_CHECK_DELAY = 1_000L // 1 sec

        @JvmStatic
        protected val rotationParams: Collection<Array<Any>> =
                listOf(arrayOf(rotationToString(ROTATION_0), ROTATION_0))
    }
}
 No newline at end of file
Loading