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

Commit 34bd27c9 authored by Gavin Williams's avatar Gavin Williams
Browse files

Autoclick Tests: Add Long press click type test

- Test that the long press click type can be selected on the Autoclick
  panel.
- Add a new element id for selecting the click type buttons.

Bug: 411185697
Test: atest AutoclickPanelTests
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: I4da4bfa51a4d2f597e4bbb77d85463cc6ac835ab
parent 485b8bcc
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -34,6 +34,7 @@
        android:orientation="horizontal">

        <LinearLayout
            android:id="@+id/accessibility_autoclick_click_type_button_group_container"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
+1 −0
Original line number Diff line number Diff line
@@ -5860,6 +5860,7 @@
  <java-symbol type="dimen" name="accessibility_autoclick_type_panel_divider_width" />
  <java-symbol type="id" name="accessibility_autoclick_type_panel" />
  <java-symbol type="id" name="accessibility_autoclick_button_group_container" />
  <java-symbol type="id" name="accessibility_autoclick_click_type_button_group_container" />
  <java-symbol type="id" name="accessibility_autoclick_left_click_layout" />
  <java-symbol type="id" name="accessibility_autoclick_left_click_button" />
  <java-symbol type="id" name="accessibility_autoclick_right_click_layout" />
+50 −0
Original line number Diff line number Diff line
@@ -35,6 +35,7 @@ import com.android.compatibility.common.util.SettingsStateChangerRule
import com.android.internal.R
import com.android.server.accessibility.Flags
import kotlin.time.Duration.Companion.seconds
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Rule
@@ -92,6 +93,35 @@ class AutoclickPanelTests {
        ).click()
    }

    private fun clickClickTypeButton(id: Int) {
        findObject(
            By.res(context.getResources().getResourceName(id))
        ).click()
        // The delay is needed to let the animation of the panel opening/closing complete before
        // querying for the next element.
        uiDevice.waitForIdle(DELAY_FOR_ANIMATION.inWholeMilliseconds)
    }

    private fun clickLeftClickButton() {
        clickClickTypeButton(R.id.accessibility_autoclick_left_click_layout)
    }

    private fun clickLongPressButton() {
        clickClickTypeButton(R.id.accessibility_autoclick_long_press_layout)
    }

    // The panel is considered open when every click type button is showing.
    private fun isAutoclickPanelOpen(): Boolean {
        val PANEL_OPEN_CLICK_TYPE_COUNT = 6
        val clickTypeButtonGroupContainer = findObject(
            By.res(
                context.getResources()
                    .getResourceName(R.id.accessibility_autoclick_click_type_button_group_container)
            )
        )
        return clickTypeButtonGroupContainer.childCount == PANEL_OPEN_CLICK_TYPE_COUNT
    }

    @Test
    fun togglePauseResumeButton_contentDescriptionReflectsTheState() {
        val autoclickPauseButtonId = context.getResources()
@@ -126,7 +156,27 @@ class AutoclickPanelTests {
        )
    }

    @Test
    fun switchClickType_LongPressClickTypeIsSelected() {
        // Click the left click button to open the panel.
        clickLeftClickButton()

        // Click the long press button then verify only the long press button is visible with all
        // other click type buttons hidden.
        clickLongPressButton()
        assertNotNull(
            findObject(
                By.res(
                    context.getResources()
                        .getResourceName(R.id.accessibility_autoclick_long_press_layout)
                )
            )
        )
        assertFalse(isAutoclickPanelOpen())
    }

    private companion object {
        private val FIND_OBJECT_TIMEOUT = 30.seconds
        private val DELAY_FOR_ANIMATION = 2.seconds
    }
}