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

Commit 576dfd1d authored by Ameer Armaly's avatar Ameer Armaly
Browse files

Touch Explorer Unit Test: test touch exploring state.

This state was never tested which is why  handleActionUp was never called as part of code coverage.
Test: atest FrameworksServicesTests:TouchExplorerTest
Bug: 148690104

Change-Id: I10869d30beb547b7344c7e01294e6700a626bcf4
parent 6a556ff2
Loading
Loading
Loading
Loading
+24 −14
Original line number Diff line number Diff line
@@ -17,6 +17,9 @@
package com.android.server.accessibility.gestures;

import static android.view.MotionEvent.ACTION_DOWN;
import static android.view.MotionEvent.ACTION_HOVER_ENTER;
import static android.view.MotionEvent.ACTION_HOVER_EXIT;
import static android.view.MotionEvent.ACTION_HOVER_MOVE;
import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_POINTER_DOWN;
import static android.view.MotionEvent.ACTION_POINTER_UP;
@@ -29,6 +32,7 @@ import static com.android.server.accessibility.gestures.TouchState.STATE_TOUCH_E

import static org.hamcrest.MatcherAssert.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;

import android.content.Context;
@@ -37,6 +41,7 @@ import android.os.SystemClock;
import android.testing.DexmakerShareClassLoaderRule;
import android.view.InputDevice;
import android.view.MotionEvent;
import android.view.ViewConfiguration;

import androidx.test.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
@@ -122,10 +127,23 @@ public class TouchExplorerTest {
        mTouchExplorer.setNext(mCaptor);
    }

    @Test
    public void testOneFingerMove_shouldInjectHoverEvents() {
        goFromStateClearTo(STATE_TOUCH_EXPLORING_1FINGER);
        try {
            Thread.sleep(2 * ViewConfiguration.getDoubleTapTimeout());
        } catch (InterruptedException e) {
            fail("Interrupted while waiting for transition to touch exploring state.");
        }
        moveEachPointers(mLastEvent, p(10, 10));
        send(mLastEvent);
        goToStateClearFrom(STATE_TOUCH_EXPLORING_1FINGER);
        assertCapturedEvents(ACTION_HOVER_ENTER, ACTION_HOVER_MOVE, ACTION_HOVER_EXIT);
    }

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

        assertState(STATE_DELEGATING);
        goToStateClearFrom(STATE_MOVING_2FINGERS);
        assertState(STATE_CLEAR);
@@ -263,25 +281,17 @@ public class TouchExplorerTest {
                    send(upEvent());
                    break;
                case STATE_TOUCH_EXPLORING_2FINGER:
                case STATE_MOVING_2FINGERS:
                case STATE_DRAGGING_2FINGERS:
                case STATE_PINCH_2FINGERS:
                    send(pointerUpEvent());
                    goToStateClearFrom(STATE_TOUCH_EXPLORING_1FINGER);
                    break;
                case STATE_TOUCH_EXPLORING_3FINGER:
                case STATE_MOVING_3FINGERS:
                    send(thirdPointerUpEvent());
                    goToStateClearFrom(STATE_TOUCH_EXPLORING_2FINGER);
                    break;
                case STATE_MOVING_2FINGERS:
                    goToStateClearFrom(STATE_TOUCH_EXPLORING_2FINGER);
                    break;
                case STATE_DRAGGING_2FINGERS:
                    goToStateClearFrom(STATE_TOUCH_EXPLORING_2FINGER);
                    break;
                case STATE_PINCH_2FINGERS:
                    goToStateClearFrom(STATE_DRAGGING_2FINGERS);
                    break;
                case STATE_MOVING_3FINGERS:
                    goToStateClearFrom(STATE_TOUCH_EXPLORING_3FINGER);
                    break;
                default:
                    throw new IllegalArgumentException("Illegal state: " + state);
            }
@@ -337,7 +347,7 @@ public class TouchExplorerTest {
    }

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