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

Commit 6dff470b authored by Gavin Williams's avatar Gavin Williams Committed by Android (Google) Code Review
Browse files

Merge "Autoclick: Test stability improvements" into main

parents d6b1fe76 e0dda7c4
Loading
Loading
Loading
Loading
+12 −9
Original line number Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.View
import android.widget.Button
import android.widget.LinearLayout
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Configurator
@@ -44,10 +45,9 @@ import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import platform.test.desktop.DesktopMouseTestRule

@RunWith(JUnit4::class)
@RunWith(AndroidJUnit4::class)
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
class AutoclickClickTypeTests {
    @Rule(order = 0)
@@ -56,6 +56,11 @@ class AutoclickClickTypeTests {

    @Rule(order = 1)
    @JvmField
    val activityScenarioRule: ActivityScenarioRule<TestClickActivity> =
        ActivityScenarioRule(TestClickActivity::class.java)

    @Rule(order = 2)
    @JvmField
    val autoclickEnabledSettingRule: SettingsStateChangerRule =
        SettingsStateChangerRule(
            InstrumentationRegistry.getInstrumentation().context,
@@ -63,15 +68,9 @@ class AutoclickClickTypeTests {
            "1"
        )

    @Rule(order = 2)
    @Rule(order = 3)
    @JvmField
    val desktopMouseTestRule = DesktopMouseTestRule()

    @Rule
    @JvmField
    val activityScenarioRule: ActivityScenarioRule<TestClickActivity> =
        ActivityScenarioRule(TestClickActivity::class.java)

    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()

    private lateinit var uiDevice: UiDevice
@@ -85,6 +84,10 @@ class AutoclickClickTypeTests {
        activityScenarioRule.scenario.onActivity { activity ->
            testClickButton = activity.findViewById(TEST_BUTTON_ID)
        }

        initiateAutoclickPanel(
            InstrumentationRegistry.getInstrumentation().context, uiDevice, desktopMouseTestRule
        )
    }

    private fun getViewCenter(view: View): Pair<Int, Int> {
+5 −7
Original line number Diff line number Diff line
@@ -22,7 +22,7 @@ import android.platform.test.annotations.RequiresFlagsEnabled
import android.platform.test.flag.junit.CheckFlagsRule
import android.platform.test.flag.junit.DeviceFlagsValueProvider
import android.provider.Settings
import android.view.Display.DEFAULT_DISPLAY
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Configurator
@@ -34,16 +34,13 @@ import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Ignore
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import platform.test.desktop.DesktopMouseTestRule

@RunWith(JUnit4::class)
@RunWith(AndroidJUnit4::class)
@RequiresFlagsEnabled(Flags.FLAG_ENABLE_AUTOCLICK_INDICATOR)
@Ignore("b/428796322")
class AutoclickPanelTests {
    @Rule(order = 0)
    @JvmField
@@ -71,8 +68,9 @@ class AutoclickPanelTests {
        Configurator.getInstance().setUiAutomationFlags(FLAG_DONT_SUPPRESS_ACCESSIBILITY_SERVICES)
        uiDevice = UiDevice.getInstance(instrumentation)

        // Move the cursor to the edge of the screen once to trigger the Autoclick panel creation.
        desktopMouseTestRule.move(DEFAULT_DISPLAY, 0, 0)
        initiateAutoclickPanel(
            InstrumentationRegistry.getInstrumentation().context, uiDevice, desktopMouseTestRule
        )
    }

    private fun clickPauseButton() {
+39 −19
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@
 */
package com.android.server.accessibility.integration

import android.content.Context
import android.view.Display.DEFAULT_DISPLAY
import android.view.WindowManager
import androidx.test.uiautomator.By
import androidx.test.uiautomator.BySelector
import androidx.test.uiautomator.UiDevice
@@ -47,7 +49,7 @@ val SCROLL_RIGHT_BUTTON_LAYOUT_ID = "android:id/scroll_right"
val CLICK_TYPE_BUTTON_GROUP_ID =
    "android:id/accessibility_autoclick_click_type_button_group_container"
val PAUSE_BUTTON_LAYOUT_ID = "android:id/accessibility_autoclick_pause_button"
val POSITION_BUTTON_LAYOUT_ID = "android:id/accessibility_autoclick_position_layout"
val POSITION_BUTTON_LAYOUT_ID = "android:id/accessibility_autoclick_position_button"
val AUTOCLICK_PANEL_ID = "android:id/accessibility_autoclick_type_panel"

fun findObject(uiDevice: UiDevice, selector: BySelector): UiObject2 {
@@ -58,6 +60,26 @@ fun waitAndAssert(condition: PollingCheck.PollingCheckCondition) {
    waitFor(FIND_OBJECT_TIMEOUT.inWholeMilliseconds, condition)
}

fun initiateAutoclickPanel(
    context: Context,
    uiDevice: UiDevice,
    desktopMouseTestRule: DesktopMouseTestRule
) {
    // Move the mouse across the display to create the panel.
    desktopMouseTestRule.move(DEFAULT_DISPLAY, 0, 0)
    val wm = context.getSystemService(WindowManager::class.java)
    desktopMouseTestRule.move(
        DEFAULT_DISPLAY,
        wm.currentWindowMetrics.bounds.width() / 2,
        wm.currentWindowMetrics.bounds.height() / 2
    )

    // Wait for the panel to close before beginning the tests.
    waitAndAssert {
        !isAutoclickPanelOpen(uiDevice)
    }
}

// The panel is considered open when more than one click type button is visible.
fun isAutoclickPanelOpen(uiDevice: UiDevice): Boolean {
    val clickTypeButtonGroupContainer = findObject(
@@ -71,11 +93,11 @@ fun changeClickType(
    desktopMouseTestRule: DesktopMouseTestRule,
    clickTypeResourceId: String
) {
    // First move the cursor to the edge of the screen so the next move will trigger an
    // autoclick.
    desktopMouseTestRule.move(DEFAULT_DISPLAY, targetXPx = 0, targetYPx = 0)
    // Requested click type is already selected.
    if (uiDevice.findObject(By.res(clickTypeResourceId)) != null) {
        return
    }

    if (!isAutoclickPanelOpen(uiDevice)) {
    // The click type button group starts closed so click it to open the panel.
    val clickTypeButtonGroup = findObject(
        uiDevice, By.res(CLICK_TYPE_BUTTON_GROUP_ID)
@@ -90,9 +112,7 @@ fun changeClickType(
    waitAndAssert {
        isAutoclickPanelOpen(uiDevice)
    }
    }

    desktopMouseTestRule.move(DEFAULT_DISPLAY, targetXPx = 0, targetYPx = 0)
    val targetClickTypeButton = findObject(uiDevice, By.res(clickTypeResourceId))
    desktopMouseTestRule.move(
        DEFAULT_DISPLAY,