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

Commit e0dda7c4 authored by Gavin Williams's avatar Gavin Williams
Browse files

Autoclick: Test stability improvements

- Re-enable AutoclickPanelTests after completion of
  http://ag/34734535
- Use AndroidJUnit4
- Ensure all the rules have specific
- Start each test with the panel initiated and closed

Bug: 428796322, 434087472
Test: AutoclickClickTypeTests, AutoclickPanelTests
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: I908e03f2966a28b03eb872b67ff094d0796bcb4a
parent 00eb52d9
Loading
Loading
Loading
Loading
+12 −9
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import android.view.View
import android.widget.Button
import android.widget.Button
import android.widget.LinearLayout
import android.widget.LinearLayout
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.rules.ActivityScenarioRule
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By
import androidx.test.uiautomator.By
import androidx.test.uiautomator.Configurator
import androidx.test.uiautomator.Configurator
@@ -44,10 +45,9 @@ import org.junit.BeforeClass
import org.junit.Rule
import org.junit.Rule
import org.junit.Test
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import platform.test.desktop.DesktopMouseTestRule
import platform.test.desktop.DesktopMouseTestRule


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


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

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


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

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

    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()
    private val instrumentation: Instrumentation = InstrumentationRegistry.getInstrumentation()


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

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


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


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


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


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


import android.content.Context
import android.view.Display.DEFAULT_DISPLAY
import android.view.Display.DEFAULT_DISPLAY
import android.view.WindowManager
import androidx.test.uiautomator.By
import androidx.test.uiautomator.By
import androidx.test.uiautomator.BySelector
import androidx.test.uiautomator.BySelector
import androidx.test.uiautomator.UiDevice
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 =
val CLICK_TYPE_BUTTON_GROUP_ID =
    "android:id/accessibility_autoclick_click_type_button_group_container"
    "android:id/accessibility_autoclick_click_type_button_group_container"
val PAUSE_BUTTON_LAYOUT_ID = "android:id/accessibility_autoclick_pause_button"
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"
val AUTOCLICK_PANEL_ID = "android:id/accessibility_autoclick_type_panel"


fun findObject(uiDevice: UiDevice, selector: BySelector): UiObject2 {
fun findObject(uiDevice: UiDevice, selector: BySelector): UiObject2 {
@@ -58,6 +60,26 @@ fun waitAndAssert(condition: PollingCheck.PollingCheckCondition) {
    waitFor(FIND_OBJECT_TIMEOUT.inWholeMilliseconds, condition)
    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.
// The panel is considered open when more than one click type button is visible.
fun isAutoclickPanelOpen(uiDevice: UiDevice): Boolean {
fun isAutoclickPanelOpen(uiDevice: UiDevice): Boolean {
    val clickTypeButtonGroupContainer = findObject(
    val clickTypeButtonGroupContainer = findObject(
@@ -71,11 +93,11 @@ fun changeClickType(
    desktopMouseTestRule: DesktopMouseTestRule,
    desktopMouseTestRule: DesktopMouseTestRule,
    clickTypeResourceId: String
    clickTypeResourceId: String
) {
) {
    // First move the cursor to the edge of the screen so the next move will trigger an
    // Requested click type is already selected.
    // autoclick.
    if (uiDevice.findObject(By.res(clickTypeResourceId)) != null) {
    desktopMouseTestRule.move(DEFAULT_DISPLAY, targetXPx = 0, targetYPx = 0)
        return
    }


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


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