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

Commit 0ebfa996 authored by Treehugger Robot's avatar Treehugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Add flicker test for snap resizing using keyboard shortcuts." into main

parents 3be0a765 bb571abd
Loading
Loading
Loading
Loading
+34 −0
Original line number Diff line number Diff line
@@ -262,6 +262,40 @@ class DesktopModeFlickerScenarios {
                ).associateBy({ it }, { AssertionInvocationGroup.BLOCKING }),
            )

        val SNAP_RESIZE_LEFT_WITH_KEYBOARD =
            FlickerConfigEntry(
                scenarioId = ScenarioId("SNAP_RESIZE_LEFT_WITH_KEYBOARD"),
                extractor =
                    TaggedScenarioExtractorBuilder()
                        .setTargetTag(CujType.CUJ_DESKTOP_MODE_SNAP_RESIZE)
                        .setTransitionMatcher(
                            TaggedCujTransitionMatcher(associatedTransitionRequired = false)
                        )
                        .build(),
                assertions = AssertionTemplates.DESKTOP_MODE_APP_VISIBILITY_ASSERTIONS + listOf(
                    AppWindowCoversLeftHalfScreenAtEnd(
                        DESKTOP_MODE_APP, SNAP_WINDOW_MAX_DIFF_THRESHOLD_RATIO
                    )
                ).associateBy({ it }, { AssertionInvocationGroup.BLOCKING }),
            )

        val SNAP_RESIZE_RIGHT_WITH_KEYBOARD =
            FlickerConfigEntry(
                scenarioId = ScenarioId("SNAP_RESIZE_RIGHT_WITH_KEYBOARD"),
                extractor =
                    TaggedScenarioExtractorBuilder()
                        .setTargetTag(CujType.CUJ_DESKTOP_MODE_SNAP_RESIZE)
                        .setTransitionMatcher(
                            TaggedCujTransitionMatcher(associatedTransitionRequired = false)
                        )
                        .build(),
                assertions = AssertionTemplates.DESKTOP_MODE_APP_VISIBILITY_ASSERTIONS + listOf(
                    AppWindowCoversRightHalfScreenAtEnd(
                        DESKTOP_MODE_APP, SNAP_WINDOW_MAX_DIFF_THRESHOLD_RATIO
                    )
                ).associateBy({ it }, { AssertionInvocationGroup.BLOCKING }),
            )

        val SNAP_RESIZE_LEFT_WITH_DRAG =
            FlickerConfigEntry(
                scenarioId = ScenarioId("SNAP_RESIZE_LEFT_WITH_DRAG"),
+48 −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.SNAP_RESIZE_LEFT_WITH_KEYBOARD
import com.android.wm.shell.scenarios.SnapResizeAppWindowWithKeyboardShortcuts
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Snap resize app window using keyboard shortcut META + [.
 *
 * Assert that the app window fills the left half the display after being snap resized.
 */
@RunWith(FlickerServiceJUnit4ClassRunner::class)
class SnapResizeAppWindowLeftWithKeyboard : SnapResizeAppWindowWithKeyboardShortcuts(toLeft = true) {
    @ExpectedScenarios(["SNAP_RESIZE_LEFT_WITH_KEYBOARD"])
    @Test
    override fun snapResizeAppWindowWithKeyboardShortcuts() =
        super.snapResizeAppWindowWithKeyboardShortcuts()

    companion object {
        @JvmStatic
        @FlickerConfigProvider
        fun flickerConfigProvider(): FlickerConfig =
            FlickerConfig().use(FlickerServiceConfig.DEFAULT).use(SNAP_RESIZE_LEFT_WITH_KEYBOARD)
    }
}
 No newline at end of file
+50 −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.SNAP_RESIZE_RIGHT_WITH_KEYBOARD
import com.android.wm.shell.scenarios.SnapResizeAppWindowWithKeyboardShortcuts
import org.junit.Test
import org.junit.runner.RunWith

/**
 * Snap resize app window using keyboard shortcut META + ].
 *
 * Assert that the app window fills the right half the display after being snap resized.
 */
@RunWith(FlickerServiceJUnit4ClassRunner::class)
class SnapResizeAppWindowRightWithKeyboard : SnapResizeAppWindowWithKeyboardShortcuts(
    toLeft = false
) {
    @ExpectedScenarios(["SNAP_RESIZE_RIGHT_WITH_KEYBOARD"])
    @Test
    override fun snapResizeAppWindowWithKeyboardShortcuts() =
        super.snapResizeAppWindowWithKeyboardShortcuts()

    companion object {
        @JvmStatic
        @FlickerConfigProvider
        fun flickerConfigProvider(): FlickerConfig =
            FlickerConfig().use(FlickerServiceConfig.DEFAULT).use(SNAP_RESIZE_RIGHT_WITH_KEYBOARD)
    }
}
 No newline at end of file
+80 −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.scenarios

import android.app.Instrumentation
import android.tools.NavBar
import android.tools.Rotation
import android.tools.traces.parsers.WindowManagerStateHelper
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.UiDevice
import com.android.launcher3.tapl.LauncherInstrumentation
import com.android.server.wm.flicker.helpers.DesktopModeAppHelper
import com.android.server.wm.flicker.helpers.KeyEventHelper
import com.android.server.wm.flicker.helpers.NonResizeableAppHelper
import com.android.server.wm.flicker.helpers.SimpleAppHelper
import com.android.window.flags.Flags
import com.android.wm.shell.Utils
import org.junit.After
import org.junit.Assume
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test

@Ignore("Test Base Class")
abstract class SnapResizeAppWindowWithKeyboardShortcuts(
    private val toLeft: Boolean = true,
    isResizable: Boolean = true
) {
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val tapl = LauncherInstrumentation()
    private val wmHelper = WindowManagerStateHelper(instrumentation)
    private val keyEventHelper = KeyEventHelper(instrumentation)
    private val device = UiDevice.getInstance(instrumentation)
    private val testApp = if (isResizable) {
        DesktopModeAppHelper(SimpleAppHelper(instrumentation))
    } else {
        DesktopModeAppHelper(NonResizeableAppHelper(instrumentation))
    }

    @Rule
    @JvmField
    val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_90)

    @Before
    fun setup() {
        Assume.assumeTrue(Flags.enableDesktopWindowingMode() &&
                Flags.enableTaskResizingKeyboardShortcuts() && tapl.isTablet)
        testApp.enterDesktopMode(wmHelper, device)
    }

    @Test
    open fun snapResizeAppWindowWithKeyboardShortcuts() {
        testApp.snapResizeWithKeyboard(
            wmHelper,
            instrumentation.context,
            keyEventHelper,
            toLeft,
        )
    }

    @After
    fun teardown() {
        testApp.exit(wmHelper)
    }
}
+23 −0
Original line number Diff line number Diff line
@@ -28,6 +28,9 @@ import android.tools.device.apphelpers.IStandardAppHelper
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_RIGHT_BRACKET
import android.view.KeyEvent.META_META_ON
import android.view.WindowInsets
import android.view.WindowManager
import android.window.DesktopModeFlags
@@ -213,6 +216,26 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) :
                ?: error("Unable to find object with resource id $buttonResId")
        snapResizeButton.click()

        waitAndVerifySnapResize(wmHelper, context, toLeft)
    }

    fun snapResizeWithKeyboard(
        wmHelper: WindowManagerStateHelper,
        context: Context,
        keyEventHelper: KeyEventHelper,
        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)
        waitAndVerifySnapResize(wmHelper, context, toLeft)
    }

    private fun waitAndVerifySnapResize(
        wmHelper: WindowManagerStateHelper,
        context: Context,
        toLeft: Boolean
    ) {
        val displayRect = getDisplayRect(wmHelper)
        val insets = getWindowInsets(
            context, WindowInsets.Type.statusBars() or WindowInsets.Type.navigationBars()
Loading