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

Commit 679e0b18 authored by Gavin Williams's avatar Gavin Williams
Browse files

Autoclick: Fix position button panel test

This change resolves the test flake by waiting for the autoclick panel
to move as expected before attempting to click the position button
again.

Bug: 422376066
Test: atest AutoclickPanelTests
Flag: com.android.server.accessibility.enable_autoclick_indicator
Change-Id: I163008bc270b0d41b79920da5afe4f9078222ad3
parent 35669e44
Loading
Loading
Loading
Loading
+24 −6
Original line number Diff line number Diff line
@@ -32,12 +32,13 @@ import androidx.test.uiautomator.Configurator
import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiObject2
import androidx.test.uiautomator.Until
import com.android.compatibility.common.util.PollingCheck
import com.android.compatibility.common.util.PollingCheck.waitFor
import com.android.compatibility.common.util.SettingsStateChangerRule
import com.android.server.accessibility.Flags
import kotlin.time.Duration.Companion.seconds
import org.junit.Assert.assertEquals
import org.junit.Assert.assertFalse
import org.junit.Assert.assertNotEquals
import org.junit.Assert.assertNotNull
import org.junit.Before
import org.junit.Rule
@@ -126,6 +127,10 @@ class AutoclickPanelTests {
        ).visibleCenter
    }

    private fun waitAndAssert(condition: PollingCheck.PollingCheckCondition) {
        waitFor(FIND_OBJECT_TIMEOUT.inWholeMilliseconds, condition)
    }

    @Test
    fun togglePauseResumeButton_contentDescriptionReflectsTheState() {
        // Expect the panel to start with the pause button.
@@ -168,21 +173,34 @@ class AutoclickPanelTests {

    @Test
    fun clickPositionButton_autoclickPanelMovesAroundTheScreen() {
        // Capture position of the panel after each click.
        // Capture the position of the panel and confirm it moves after clicking the positio
        // button.
        val startingPosition = getAutoclickPanelPosition()
        clickPositionButton()
        waitAndAssert {
            startingPosition != getAutoclickPanelPosition()
        }

        val secondPosition = getAutoclickPanelPosition()
        clickPositionButton()
        waitAndAssert {
            secondPosition != getAutoclickPanelPosition()
        }

        val thirdPosition = getAutoclickPanelPosition()
        clickPositionButton()
        waitAndAssert {
            thirdPosition != getAutoclickPanelPosition()
        }

        val fourthPosition = getAutoclickPanelPosition()
        clickPositionButton()
        val fifthPosition = getAutoclickPanelPosition()
        waitAndAssert {
            fourthPosition != getAutoclickPanelPosition()
        }

        // Confirm the panel moved around the screen and finished in the starting location.
        assertNotEquals(startingPosition, secondPosition)
        assertNotEquals(secondPosition, thirdPosition)
        assertNotEquals(thirdPosition, fourthPosition)
        val fifthPosition = getAutoclickPanelPosition()
        assertEquals(startingPosition, fifthPosition)
    }