Loading services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java +113 −57 Original line number Diff line number Diff line Loading @@ -16,6 +16,12 @@ package com.android.server.accessibility.gestures; import static android.view.MotionEvent.ACTION_DOWN; import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_POINTER_DOWN; import static android.view.MotionEvent.ACTION_POINTER_UP; import static android.view.MotionEvent.ACTION_UP; import static com.android.server.accessibility.gestures.TouchState.STATE_CLEAR; import static com.android.server.accessibility.gestures.TouchState.STATE_DELEGATING; import static com.android.server.accessibility.gestures.TouchState.STATE_DRAGGING; Loading Loading @@ -98,8 +104,7 @@ public class TouchExplorerTest { } @Override public void setNext(EventStreamTransformation next) { } public void setNext(EventStreamTransformation next) {} @Override public EventStreamTransformation getNext() { Loading @@ -122,9 +127,9 @@ public class TouchExplorerTest { goFromStateClearTo(STATE_MOVING_2FINGERS); assertState(STATE_DELEGATING); assertCapturedEvents( MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN); goToStateClearFrom(STATE_MOVING_2FINGERS); assertState(STATE_CLEAR); assertCapturedEvents(ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_UP); assertCapturedEventsNoHistory(); } Loading @@ -146,11 +151,7 @@ public class TouchExplorerTest { 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); assertCapturedEvents(ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_UP); } @Test Loading @@ -158,7 +159,9 @@ public class TouchExplorerTest { goFromStateClearTo(STATE_DRAGGING_2FINGERS); assertState(STATE_DRAGGING); assertCapturedEvents(MotionEvent.ACTION_DOWN); goToStateClearFrom(STATE_DRAGGING_2FINGERS); assertState(STATE_CLEAR); assertCapturedEvents(ACTION_DOWN, ACTION_UP); assertCapturedEventsNoHistory(); } Loading @@ -166,25 +169,32 @@ public class TouchExplorerTest { public void testTwoFingersNotDrag_shouldDelegatingAndActionUpDownPointerDown() { // only from dragging state, and withMoveHistory no dragging goFromStateClearTo(STATE_PINCH_2FINGERS); assertState(STATE_DELEGATING); goToStateClearFrom(STATE_PINCH_2FINGERS); assertState(STATE_CLEAR); assertCapturedEvents( /* goto dragging state */ MotionEvent.ACTION_DOWN, /* leave dragging state */ MotionEvent.ACTION_UP, MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN); /* goto dragging state */ ACTION_DOWN, /* leave dragging state */ ACTION_UP, ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_UP); assertCapturedEventsNoHistory(); } @Test public void testThreeFingersMove_shouldDelegatingAnd3ActionPointerDown() { goFromStateClearTo(STATE_MOVING_3FINGERS); assertState(STATE_DELEGATING); goToStateClearFrom(STATE_MOVING_3FINGERS); assertState(STATE_CLEAR); assertCapturedEvents( MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN, MotionEvent.ACTION_POINTER_DOWN); ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_POINTER_UP, ACTION_UP); assertCapturedEventsNoHistory(); } Loading @@ -200,54 +210,84 @@ public class TouchExplorerTest { private void goFromStateClearTo(int state) { try { switch (state) { case STATE_CLEAR: { case STATE_CLEAR: mTouchExplorer.onDestroy(); } break; case STATE_TOUCH_EXPLORING_1FINGER: { case STATE_TOUCH_EXPLORING_1FINGER: send(downEvent()); } break; case STATE_TOUCH_EXPLORING_2FINGER: { case STATE_TOUCH_EXPLORING_2FINGER: goFromStateClearTo(STATE_TOUCH_EXPLORING_1FINGER); send(pointerDownEvent()); } break; case STATE_TOUCH_EXPLORING_3FINGER: { case STATE_TOUCH_EXPLORING_3FINGER: goFromStateClearTo(STATE_TOUCH_EXPLORING_2FINGER); send(thirdPointerDownEvent()); } break; case STATE_MOVING_2FINGERS: { case STATE_MOVING_2FINGERS: goFromStateClearTo(STATE_TOUCH_EXPLORING_2FINGER); moveEachPointers(mLastEvent, p(10, 0), p(5, 10)); send(mLastEvent); } break; case STATE_DRAGGING_2FINGERS: { case STATE_DRAGGING_2FINGERS: goFromStateClearTo(STATE_TOUCH_EXPLORING_2FINGER); moveEachPointers(mLastEvent, p(10, 0), p(10, 0)); send(mLastEvent); } break; case STATE_PINCH_2FINGERS: { case STATE_PINCH_2FINGERS: goFromStateClearTo(STATE_DRAGGING_2FINGERS); moveEachPointers(mLastEvent, p(10, 0), p(-10, 1)); send(mLastEvent); } break; case STATE_MOVING_3FINGERS: { case STATE_MOVING_3FINGERS: goFromStateClearTo(STATE_TOUCH_EXPLORING_3FINGER); moveEachPointers(mLastEvent, p(1, 0), p(1, 0), p(1, 0)); send(mLastEvent); break; default: throw new IllegalArgumentException("Illegal state: " + state); } } catch (Throwable t) { throw new RuntimeException( "Failed to go to state " + TouchState.getStateSymbolicName(state), t); } } private void goToStateClearFrom(int state) { try { switch (state) { case STATE_CLEAR: mTouchExplorer.onDestroy(); break; case STATE_TOUCH_EXPLORING_1FINGER: send(upEvent()); break; case STATE_TOUCH_EXPLORING_2FINGER: send(pointerUpEvent()); goToStateClearFrom(STATE_TOUCH_EXPLORING_1FINGER); break; case STATE_TOUCH_EXPLORING_3FINGER: 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); } } catch (Throwable t) { throw new RuntimeException("Failed to go to state " + TouchState.getStateSymbolicName(state), t); throw new RuntimeException( "Failed to go to state " + TouchState.getStateSymbolicName(state), t); } } Loading Loading @@ -292,32 +332,48 @@ public class TouchExplorerTest { private MotionEvent downEvent() { mLastDownTime = SystemClock.uptimeMillis(); return fromTouchscreen( MotionEvent.obtain(mLastDownTime, mLastDownTime, MotionEvent.ACTION_DOWN, DEFAULT_X, DEFAULT_Y, 0)); MotionEvent.obtain( mLastDownTime, mLastDownTime, ACTION_DOWN, DEFAULT_X, DEFAULT_Y, 0)); } private MotionEvent upEvent() { MotionEvent event = downEvent(); event.setAction(MotionEvent.ACTION_UP); event.setAction(ACTION_UP); return event; } private MotionEvent pointerDownEvent() { final int secondPointerId = 0x0100; final int action = MotionEvent.ACTION_POINTER_DOWN | secondPointerId; final int action = ACTION_POINTER_DOWN | secondPointerId; final float[] x = new float[] {DEFAULT_X, DEFAULT_X + 29}; final float[] y = new float[] {DEFAULT_Y, DEFAULT_Y + 28}; return manyPointerEvent(action, x, y); } private MotionEvent pointerUpEvent() { final int secondPointerId = 0x0100; final int action = ACTION_POINTER_UP | secondPointerId; final MotionEvent event = MotionEvent.obtainNoHistory(mLastEvent); event.setAction(action); return event; } private MotionEvent thirdPointerDownEvent() { final int thirdPointerId = 0x0200; final int action = MotionEvent.ACTION_POINTER_DOWN | thirdPointerId; final int action = ACTION_POINTER_DOWN | thirdPointerId; final float[] x = new float[] {DEFAULT_X, DEFAULT_X + 29, DEFAULT_X + 59}; final float[] y = new float[] {DEFAULT_Y, DEFAULT_Y + 28, DEFAULT_Y + 58}; return manyPointerEvent(action, x, y); } private MotionEvent thirdPointerUpEvent() { final int thirdPointerId = 0x0200; final int action = ACTION_POINTER_UP | thirdPointerId; final MotionEvent event = MotionEvent.obtainNoHistory(mLastEvent); event.setAction(action); return event; } private void moveEachPointers(MotionEvent event, PointF... points) { final float[] x = new float[points.length]; final float[] y = new float[points.length]; Loading @@ -325,8 +381,8 @@ public class TouchExplorerTest { x[i] = event.getX(i) + points[i].x; y[i] = event.getY(i) + points[i].y; } MotionEvent newEvent = manyPointerEvent(MotionEvent.ACTION_MOVE, x, y); event.setAction(MotionEvent.ACTION_MOVE); MotionEvent newEvent = manyPointerEvent(ACTION_MOVE, x, y); event.setAction(ACTION_MOVE); // add history count event.addBatch(newEvent); } Loading Loading
services/tests/servicestests/src/com/android/server/accessibility/gestures/TouchExplorerTest.java +113 −57 Original line number Diff line number Diff line Loading @@ -16,6 +16,12 @@ package com.android.server.accessibility.gestures; import static android.view.MotionEvent.ACTION_DOWN; import static android.view.MotionEvent.ACTION_MOVE; import static android.view.MotionEvent.ACTION_POINTER_DOWN; import static android.view.MotionEvent.ACTION_POINTER_UP; import static android.view.MotionEvent.ACTION_UP; import static com.android.server.accessibility.gestures.TouchState.STATE_CLEAR; import static com.android.server.accessibility.gestures.TouchState.STATE_DELEGATING; import static com.android.server.accessibility.gestures.TouchState.STATE_DRAGGING; Loading Loading @@ -98,8 +104,7 @@ public class TouchExplorerTest { } @Override public void setNext(EventStreamTransformation next) { } public void setNext(EventStreamTransformation next) {} @Override public EventStreamTransformation getNext() { Loading @@ -122,9 +127,9 @@ public class TouchExplorerTest { goFromStateClearTo(STATE_MOVING_2FINGERS); assertState(STATE_DELEGATING); assertCapturedEvents( MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN); goToStateClearFrom(STATE_MOVING_2FINGERS); assertState(STATE_CLEAR); assertCapturedEvents(ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_UP); assertCapturedEventsNoHistory(); } Loading @@ -146,11 +151,7 @@ public class TouchExplorerTest { 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); assertCapturedEvents(ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_UP); } @Test Loading @@ -158,7 +159,9 @@ public class TouchExplorerTest { goFromStateClearTo(STATE_DRAGGING_2FINGERS); assertState(STATE_DRAGGING); assertCapturedEvents(MotionEvent.ACTION_DOWN); goToStateClearFrom(STATE_DRAGGING_2FINGERS); assertState(STATE_CLEAR); assertCapturedEvents(ACTION_DOWN, ACTION_UP); assertCapturedEventsNoHistory(); } Loading @@ -166,25 +169,32 @@ public class TouchExplorerTest { public void testTwoFingersNotDrag_shouldDelegatingAndActionUpDownPointerDown() { // only from dragging state, and withMoveHistory no dragging goFromStateClearTo(STATE_PINCH_2FINGERS); assertState(STATE_DELEGATING); goToStateClearFrom(STATE_PINCH_2FINGERS); assertState(STATE_CLEAR); assertCapturedEvents( /* goto dragging state */ MotionEvent.ACTION_DOWN, /* leave dragging state */ MotionEvent.ACTION_UP, MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN); /* goto dragging state */ ACTION_DOWN, /* leave dragging state */ ACTION_UP, ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_UP); assertCapturedEventsNoHistory(); } @Test public void testThreeFingersMove_shouldDelegatingAnd3ActionPointerDown() { goFromStateClearTo(STATE_MOVING_3FINGERS); assertState(STATE_DELEGATING); goToStateClearFrom(STATE_MOVING_3FINGERS); assertState(STATE_CLEAR); assertCapturedEvents( MotionEvent.ACTION_DOWN, MotionEvent.ACTION_POINTER_DOWN, MotionEvent.ACTION_POINTER_DOWN); ACTION_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_DOWN, ACTION_POINTER_UP, ACTION_POINTER_UP, ACTION_UP); assertCapturedEventsNoHistory(); } Loading @@ -200,54 +210,84 @@ public class TouchExplorerTest { private void goFromStateClearTo(int state) { try { switch (state) { case STATE_CLEAR: { case STATE_CLEAR: mTouchExplorer.onDestroy(); } break; case STATE_TOUCH_EXPLORING_1FINGER: { case STATE_TOUCH_EXPLORING_1FINGER: send(downEvent()); } break; case STATE_TOUCH_EXPLORING_2FINGER: { case STATE_TOUCH_EXPLORING_2FINGER: goFromStateClearTo(STATE_TOUCH_EXPLORING_1FINGER); send(pointerDownEvent()); } break; case STATE_TOUCH_EXPLORING_3FINGER: { case STATE_TOUCH_EXPLORING_3FINGER: goFromStateClearTo(STATE_TOUCH_EXPLORING_2FINGER); send(thirdPointerDownEvent()); } break; case STATE_MOVING_2FINGERS: { case STATE_MOVING_2FINGERS: goFromStateClearTo(STATE_TOUCH_EXPLORING_2FINGER); moveEachPointers(mLastEvent, p(10, 0), p(5, 10)); send(mLastEvent); } break; case STATE_DRAGGING_2FINGERS: { case STATE_DRAGGING_2FINGERS: goFromStateClearTo(STATE_TOUCH_EXPLORING_2FINGER); moveEachPointers(mLastEvent, p(10, 0), p(10, 0)); send(mLastEvent); } break; case STATE_PINCH_2FINGERS: { case STATE_PINCH_2FINGERS: goFromStateClearTo(STATE_DRAGGING_2FINGERS); moveEachPointers(mLastEvent, p(10, 0), p(-10, 1)); send(mLastEvent); } break; case STATE_MOVING_3FINGERS: { case STATE_MOVING_3FINGERS: goFromStateClearTo(STATE_TOUCH_EXPLORING_3FINGER); moveEachPointers(mLastEvent, p(1, 0), p(1, 0), p(1, 0)); send(mLastEvent); break; default: throw new IllegalArgumentException("Illegal state: " + state); } } catch (Throwable t) { throw new RuntimeException( "Failed to go to state " + TouchState.getStateSymbolicName(state), t); } } private void goToStateClearFrom(int state) { try { switch (state) { case STATE_CLEAR: mTouchExplorer.onDestroy(); break; case STATE_TOUCH_EXPLORING_1FINGER: send(upEvent()); break; case STATE_TOUCH_EXPLORING_2FINGER: send(pointerUpEvent()); goToStateClearFrom(STATE_TOUCH_EXPLORING_1FINGER); break; case STATE_TOUCH_EXPLORING_3FINGER: 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); } } catch (Throwable t) { throw new RuntimeException("Failed to go to state " + TouchState.getStateSymbolicName(state), t); throw new RuntimeException( "Failed to go to state " + TouchState.getStateSymbolicName(state), t); } } Loading Loading @@ -292,32 +332,48 @@ public class TouchExplorerTest { private MotionEvent downEvent() { mLastDownTime = SystemClock.uptimeMillis(); return fromTouchscreen( MotionEvent.obtain(mLastDownTime, mLastDownTime, MotionEvent.ACTION_DOWN, DEFAULT_X, DEFAULT_Y, 0)); MotionEvent.obtain( mLastDownTime, mLastDownTime, ACTION_DOWN, DEFAULT_X, DEFAULT_Y, 0)); } private MotionEvent upEvent() { MotionEvent event = downEvent(); event.setAction(MotionEvent.ACTION_UP); event.setAction(ACTION_UP); return event; } private MotionEvent pointerDownEvent() { final int secondPointerId = 0x0100; final int action = MotionEvent.ACTION_POINTER_DOWN | secondPointerId; final int action = ACTION_POINTER_DOWN | secondPointerId; final float[] x = new float[] {DEFAULT_X, DEFAULT_X + 29}; final float[] y = new float[] {DEFAULT_Y, DEFAULT_Y + 28}; return manyPointerEvent(action, x, y); } private MotionEvent pointerUpEvent() { final int secondPointerId = 0x0100; final int action = ACTION_POINTER_UP | secondPointerId; final MotionEvent event = MotionEvent.obtainNoHistory(mLastEvent); event.setAction(action); return event; } private MotionEvent thirdPointerDownEvent() { final int thirdPointerId = 0x0200; final int action = MotionEvent.ACTION_POINTER_DOWN | thirdPointerId; final int action = ACTION_POINTER_DOWN | thirdPointerId; final float[] x = new float[] {DEFAULT_X, DEFAULT_X + 29, DEFAULT_X + 59}; final float[] y = new float[] {DEFAULT_Y, DEFAULT_Y + 28, DEFAULT_Y + 58}; return manyPointerEvent(action, x, y); } private MotionEvent thirdPointerUpEvent() { final int thirdPointerId = 0x0200; final int action = ACTION_POINTER_UP | thirdPointerId; final MotionEvent event = MotionEvent.obtainNoHistory(mLastEvent); event.setAction(action); return event; } private void moveEachPointers(MotionEvent event, PointF... points) { final float[] x = new float[points.length]; final float[] y = new float[points.length]; Loading @@ -325,8 +381,8 @@ public class TouchExplorerTest { x[i] = event.getX(i) + points[i].x; y[i] = event.getY(i) + points[i].y; } MotionEvent newEvent = manyPointerEvent(MotionEvent.ACTION_MOVE, x, y); event.setAction(MotionEvent.ACTION_MOVE); MotionEvent newEvent = manyPointerEvent(ACTION_MOVE, x, y); event.setAction(ACTION_MOVE); // add history count event.addBatch(newEvent); } Loading