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

Commit a5bfdb2d authored by Phil Weaver's avatar Phil Weaver
Browse files

Add tests for ending TouchExplorer dragging

Increasing test coverage.

In the process, found a bug in dispatching up events for
multiple fingers. It was sending an action_up for each
pointer rather than a pointer up.

Bug: 148690104
Test: atest TouchExplorerTest
Change-Id: I04353bd4ad222d6bc4096a62de48b1fe00363b3a
parent 52572701
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -301,7 +301,7 @@ class EventDispatcher {
     * @param policyFlags The policy flags associated with the event.
     */
    void sendUpForInjectedDownPointers(MotionEvent prototype, int policyFlags) {
        int pointerIdBits = 0;
        int pointerIdBits = prototype.getPointerIdBits();
        final int pointerCount = prototype.getPointerCount();
        for (int i = 0; i < pointerCount; i++) {
            final int pointerId = prototype.getPointerId(i);
@@ -309,10 +309,10 @@ class EventDispatcher {
            if (!isInjectedPointerDown(pointerId)) {
                continue;
            }
            pointerIdBits |= (1 << pointerId);
            final int action = computeInjectionAction(MotionEvent.ACTION_UP, i);
            final int action = computeInjectionAction(MotionEvent.ACTION_POINTER_UP, i);
            sendMotionEvent(
                    prototype, action, mState.getLastReceivedEvent(), pointerIdBits, policyFlags);
            pointerIdBits &= ~(1 << pointerId);
        }
    }
}
+36 −2
Original line number Diff line number Diff line
@@ -89,10 +89,13 @@ public class TouchExplorerTest {

        @Override
        public void onMotionEvent(MotionEvent event, MotionEvent rawEvent, int policyFlags) {
            MotionEventMatcher lastEventMatcher = new MotionEventMatcher(mLastEvent);
            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
        public void setNext(EventStreamTransformation next) {
@@ -125,6 +128,31 @@ public class TouchExplorerTest {
        assertCapturedEventsNoHistory();
    }

    @Test
    public void upEventWhenInTwoFingerMove_clearsState() {
        goFromStateClearTo(STATE_MOVING_2FINGERS);

        send(upEvent());
        assertState(STATE_CLEAR);
    }

    @Test
    public void clearEventsWhenInTwoFingerMove_clearsStateAndSendsUp() {
        goFromStateClearTo(STATE_MOVING_2FINGERS);

        // Clear last event so we don't try to match against anything when cleanup events are sent
        // for the clear
        mLastEvent = null;
        mTouchExplorer.clearEvents(InputDevice.SOURCE_TOUCHSCREEN);
        assertState(STATE_CLEAR);
        List<MotionEvent> events = getCapturedEvents();
        assertCapturedEvents(
                MotionEvent.ACTION_DOWN,
                MotionEvent.ACTION_POINTER_DOWN,
                MotionEvent.ACTION_POINTER_UP,
                MotionEvent.ACTION_UP);
    }

    @Test
    public void testTwoFingersDrag_shouldDraggingAndActionDown() {
        goFromStateClearTo(STATE_DRAGGING_2FINGERS);
@@ -268,6 +296,12 @@ public class TouchExplorerTest {
                        DEFAULT_Y, 0));
    }

    private MotionEvent upEvent() {
        MotionEvent event = downEvent();
        event.setAction(MotionEvent.ACTION_UP);
        return event;
    }

    private MotionEvent pointerDownEvent() {
        final int secondPointerId = 0x0100;
        final int action = MotionEvent.ACTION_POINTER_DOWN | secondPointerId;