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

Commit cb44597d authored by Vania Desmonda's avatar Vania Desmonda Committed by Android (Google) Code Review
Browse files

Merge "Add flicker test for minimizing window using keyboard shortcuts." into main

parents a65aed8b c070cac5
Loading
Loading
Loading
Loading
+51 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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

import android.tools.flicker.FlickerConfig
import android.tools.flicker.annotation.ExpectedScenarios
import android.tools.flicker.annotation.FlickerConfigProvider
import android.tools.flicker.config.FlickerConfig
import android.tools.flicker.config.FlickerServiceConfig
import android.tools.flicker.junit.FlickerServiceJUnit4ClassRunner
import com.android.wm.shell.flicker.DesktopModeFlickerScenarios.Companion.MINIMIZE_APP
import com.android.wm.shell.flicker.DesktopModeFlickerScenarios.Companion.MINIMIZE_LAST_APP
import com.android.wm.shell.scenarios.MinimizeAppWindows
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Minimize app windows by pressing META + -.
 *
 * Assert that the app windows gets hidden.
 */
@RunWith(FlickerServiceJUnit4ClassRunner::class)
class MinimizeAppsWithKeyboard : MinimizeAppWindows(usingKeyboard = true) {
    @ExpectedScenarios(["MINIMIZE_APP", "MINIMIZE_LAST_APP"])
    @Test
    override fun minimizeAllAppWindows() = super.minimizeAllAppWindows()

    companion object {
        @JvmStatic
        @FlickerConfigProvider
        fun flickerConfigProvider(): FlickerConfig =
            FlickerConfig()
                .use(FlickerServiceConfig.DEFAULT)
                .use(MINIMIZE_APP)
                .use(MINIMIZE_LAST_APP)
    }
}
+7 −4
Original line number Diff line number Diff line
@@ -43,7 +43,10 @@ import org.junit.Test
 */
@Ignore("Test Base Class")
abstract class MinimizeAppWindows
constructor(private val rotation: Rotation = Rotation.ROTATION_0) {
constructor(
    private val rotation: Rotation = Rotation.ROTATION_0,
    private val usingKeyboard: Boolean = false
) {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val tapl = LauncherInstrumentation()
    private val wmHelper = WindowManagerStateHelper(instrumentation)
@@ -68,9 +71,9 @@ constructor(private val rotation: Rotation = Rotation.ROTATION_0) {

    @Test
    open fun minimizeAllAppWindows() {
        testApp3.minimizeDesktopApp(wmHelper, device)
        testApp2.minimizeDesktopApp(wmHelper, device)
        testApp1.minimizeDesktopApp(wmHelper, device)
        testApp3.minimizeDesktopApp(wmHelper, device, usingKeyboard = usingKeyboard)
        testApp2.minimizeDesktopApp(wmHelper, device, usingKeyboard = usingKeyboard)
        testApp1.minimizeDesktopApp(wmHelper, device, usingKeyboard = usingKeyboard)
    }

    @After
+17 −6
Original line number Diff line number Diff line
@@ -29,6 +29,7 @@ import android.tools.helpers.SYSTEMUI_PACKAGE
import android.tools.traces.parsers.WindowManagerStateHelper
import android.tools.traces.wm.WindowingMode
import android.view.KeyEvent.KEYCODE_LEFT_BRACKET
import android.view.KeyEvent.KEYCODE_MINUS
import android.view.KeyEvent.KEYCODE_RIGHT_BRACKET
import android.view.KeyEvent.META_META_ON
import android.view.WindowInsets
@@ -160,10 +161,21 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) :
            ?: error("Unable to find resource $MINIMIZE_BUTTON_VIEW\n")
    }

    fun minimizeDesktopApp(wmHelper: WindowManagerStateHelper, device: UiDevice, isPip: Boolean = false) {
    fun minimizeDesktopApp(
        wmHelper: WindowManagerStateHelper,
        device: UiDevice,
        isPip: Boolean = false,
        usingKeyboard: Boolean = false,
    ) {
        if (usingKeyboard) {
            val keyEventHelper = KeyEventHelper(getInstrumentation())
            keyEventHelper.press(KEYCODE_MINUS, META_META_ON)
        } else {
            val caption = getCaptionForTheApp(wmHelper, device)
            val minimizeButton = getMinimizeButtonForTheApp(caption)
            minimizeButton.click()
        }

        wmHelper
            .StateSyncBuilder()
            .withAppTransitionIdle()
@@ -226,8 +238,7 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) :
        toLeft: Boolean,
    ) {
        val bracketKey = if (toLeft) KEYCODE_LEFT_BRACKET else KEYCODE_RIGHT_BRACKET
        keyEventHelper.actionDown(bracketKey, META_META_ON)
        keyEventHelper.actionUp(bracketKey, META_META_ON)
        keyEventHelper.press(bracketKey, META_META_ON)
        waitAndVerifySnapResize(wmHelper, context, toLeft)
    }

+4 −0
Original line number Diff line number Diff line
@@ -29,6 +29,10 @@ import android.view.KeyEvent
class KeyEventHelper(
    private val instr: Instrumentation,
) {
    fun press(keyCode: Int, metaState: Int = 0) {
        actionDown(keyCode, metaState)
        actionUp(keyCode, metaState)
    }

    fun actionDown(keyCode: Int, metaState: Int = 0, time: Long = SystemClock.uptimeMillis()) {
        injectKeyEvent(ACTION_DOWN, keyCode, metaState, downTime = time, eventTime = time)