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

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

Merge "Add test scenario for the move to display keyboard shortcut" into main

parents 2a5f33ba 2bcd2f07
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -42,5 +42,6 @@ java_library {
        "wm-flicker-common-app-helpers",
        "launcher-helper-lib",
        "launcher-aosp-tapl",
        "desktop-test-lib",
    ],
}
+27 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.functional

import android.platform.test.annotations.Postsubmit
import com.android.wm.shell.scenarios.MoveToNextDisplay
import org.junit.runner.RunWith
import org.junit.runners.BlockJUnit4ClassRunner

/* Functional test for [MoveToNextDisplay]. */
@RunWith(BlockJUnit4ClassRunner::class)
@Postsubmit
class MoveToNextDisplayTest : MoveToNextDisplay()
+87 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2025 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.platform.test.annotations.EnableFlags
import android.platform.test.flag.junit.SetFlagsRule
import android.tools.NavBar
import android.tools.Rotation
import android.tools.traces.parsers.WindowManagerStateHelper
import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation
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.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
import platform.test.desktop.SimulatedConnectedDisplayTestRule

/**
 * Base scenario test for moving a task to another display via the keyboard shortcut.
 */
@Ignore("Test Base Class")
@EnableFlags(
    Flags.FLAG_ENABLE_DESKTOP_WINDOWING_MODE,
    Flags.FLAG_ENABLE_MOVE_TO_NEXT_DISPLAY_SHORTCUT
)
abstract class MoveToNextDisplay {
    private val tapl = LauncherInstrumentation()
    private val wmHelper = WindowManagerStateHelper(getInstrumentation())
    private val device = UiDevice.getInstance(getInstrumentation())
    private val testApp = DesktopModeAppHelper(SimpleAppHelper(getInstrumentation()))

    @get:Rule(order = 0) val setFlagsRule = SetFlagsRule()
    @get:Rule(order = 1) val testSetupRule = Utils.testSetupRule(NavBar.MODE_GESTURAL, Rotation.ROTATION_0)
    @get:Rule(order = 2) val connectedDisplayRule = SimulatedConnectedDisplayTestRule()

    @Before
    fun setup() {
        Assume.assumeTrue("isTablet", tapl.isTablet)
    }

    @Test
    open fun moveToNextDisplay() {
        val connectedDisplayId = connectedDisplayRule.setupTestDisplay()
        testApp.enterDesktopMode(wmHelper, device)

        testApp.moveToNextDisplayViaKeyboard(wmHelper)

        wmHelper.StateSyncBuilder().apply {
            add("testApp is on the connected display") { dump ->
                val display = requireNotNull(dump.wmState.getDisplay(connectedDisplayId)) {
                    "Display $connectedDisplayId not found"
                }
                display.containsActivity(testApp)
            }
        }.waitForAndVerify()
    }

    @After
    fun teardown() {
        // TODO(b/405234435): Remove the workaround once b/405229142 is resolved
        // Ensure that the simulated display being removed does not hold the display focus as a
        // workaround for b/405229142
        testApp.launchViaIntent(wmHelper)
        testApp.exit(wmHelper)
    }
}
+7 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ 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_D
import android.view.KeyEvent.KEYCODE_DPAD_DOWN
import android.view.KeyEvent.KEYCODE_DPAD_UP
import android.view.KeyEvent.KEYCODE_EQUALS
@@ -537,6 +538,12 @@ open class DesktopModeAppHelper(private val innerHelper: IStandardAppHelper) :
        wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify()
    }

    fun moveToNextDisplayViaKeyboard(wmHelper: WindowManagerStateHelper) {
        val keyEventHelper = KeyEventHelper(getInstrumentation())
        keyEventHelper.press(KEYCODE_D, META_META_ON or META_CTRL_ON)
        wmHelper.StateSyncBuilder().withAppTransitionIdle().waitForAndVerify()
    }

    private fun getDesktopAppViewByRes(viewResId: String): UiObject2? =
        DeviceHelpers.waitForObj(By.res(SYSTEMUI_PACKAGE, viewResId), TIMEOUT)