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

Commit 3118dae5 authored by Ameer Armaly's avatar Ameer Armaly
Browse files

TouchExplorerTest: insure that no-change move events don't crash the system.

A device will sometimes generate move events that don't change coordinates from the previous event.
We need to be sure that any calculations the system performs can handle zero-change values so we now test that in TouchExplorerTest.
Specifically, we test it in both the touch exploring and dragging states.
Also improved error reporting in MotionEventMatcher to report motion event actions as strings rather than numbers.

Test: atest FrameworksServicesTests:TouchExplorerTest
Change-Id: Id5b551327b54619fcf07f76c503a78e3d5059041

Change-Id: Ic36b80f8eecc3640092ec0a5cf893631d120f6c6
parent f23366a5
Loading
Loading
Loading
Loading
+47 −7
Original line number Diff line number Diff line
@@ -30,7 +30,6 @@ import static com.android.server.accessibility.gestures.TouchState.STATE_DELEGAT
import static com.android.server.accessibility.gestures.TouchState.STATE_DRAGGING;
import static com.android.server.accessibility.gestures.TouchState.STATE_TOUCH_EXPLORING;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@@ -48,7 +47,6 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.server.accessibility.AccessibilityManagerService;
import com.android.server.accessibility.EventStreamTransformation;
import com.android.server.accessibility.utils.MotionEventMatcher;

import org.junit.Before;
import org.junit.Rule;
@@ -101,11 +99,6 @@ public class TouchExplorerTest {
        @Override
        public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
            mEvents.add(0, event.copy());
            // LastEvent may not match if we're clearing the state
            if (mLastEvent != null) {
                MotionEventMatcher lastEventMatcher = new MotionEventMatcher(mLastEvent);
                assertThat(rawEvent, lastEventMatcher);
            }
        }

        @Override
@@ -141,6 +134,53 @@ public class TouchExplorerTest {
        assertCapturedEvents(ACTION_HOVER_ENTER, ACTION_HOVER_MOVE, ACTION_HOVER_EXIT);
    }

    /**
     * Test the case where ACTION_DOWN is followed by a number of ACTION_MOVE events that do not
     * change the coordinates.
     */
    @Test
    public void testOneFingerMoveWithExtraMoveEvents() {
        goFromStateClearTo(STATE_TOUCH_EXPLORING_1FINGER);
        // Inject a set of move events that have the same coordinates as the down event.
        moveEachPointers(mLastEvent, p(0, 0));
        send(mLastEvent);
        try {
            Thread.sleep(2 * ViewConfiguration.getDoubleTapTimeout());
        } catch (InterruptedException e) {
            fail("Interrupted while waiting for transition to touch exploring state.");
        }
        // Now move for real.
        moveEachPointers(mLastEvent, p(10, 10));
        send(mLastEvent);
        // One more move event with no change.
        moveEachPointers(mLastEvent, p(0, 0));
        send(mLastEvent);
        goToStateClearFrom(STATE_TOUCH_EXPLORING_1FINGER);
        assertCapturedEvents(
                ACTION_HOVER_ENTER,
                ACTION_HOVER_MOVE,
                ACTION_HOVER_MOVE,
                ACTION_HOVER_MOVE,
                ACTION_HOVER_EXIT);
    }

    /**
     * Test the case where ACTION_POINTER_DOWN is followed by a number of ACTION_MOVE events that do
     * not change the coordinates.
     */
    @Test
    public void testTwoFingerDragWithExtraMoveEvents() {
        goFromStateClearTo(STATE_DRAGGING_2FINGERS);
        // Inject a set of move events that have the same coordinates as the down event.
        moveEachPointers(mLastEvent, p(0, 0), p(0, 0));
        send(mLastEvent);
        // Now move for real.
        moveEachPointers(mLastEvent, p(10, 10), p(10, 10));
        send(mLastEvent);
        goToStateClearFrom(STATE_DRAGGING_2FINGERS);
        assertCapturedEvents(ACTION_DOWN, ACTION_MOVE, ACTION_MOVE, ACTION_UP);
    }

    @Test
    public void testTwoFingersMove_shouldDelegatingAndInjectActionDownPointerDown() {
        goFromStateClearTo(STATE_MOVING_2FINGERS);
+3 −3
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ public class MotionEventMatcher extends TypeSafeMatcher<MotionEvent> {
    private static final String LOG_TAG = "MotionEventMatcher";
    long mDownTime;
    long mEventTime;
    long mActionMasked;
    int mActionMasked;
    int mX;
    int mY;

@@ -73,9 +73,9 @@ public class MotionEventMatcher extends TypeSafeMatcher<MotionEvent> {
        Log.e(
                LOG_TAG,
                "event.getActionMasked() = "
                        + event.getActionMasked()
                        + MotionEvent.actionToString(event.getActionMasked())
                        + ", expected "
                        + mActionMasked);
                        + MotionEvent.actionToString(mActionMasked));
        Log.e(LOG_TAG, "event.getX() = " + event.getX() + ", expected " + mX);
        Log.e(LOG_TAG, "event.getY() = " + event.getY() + ", expected " + mY);
        return false;