| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 package org.chromium.chromoting; | 5 package org.chromium.chromoting; |
| 6 | 6 |
| 7 import android.graphics.Point; | 7 import android.graphics.PointF; |
| 8 import android.test.InstrumentationTestCase; | 8 import android.test.InstrumentationTestCase; |
| 9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
| 10 import android.view.MotionEvent; | 10 import android.view.MotionEvent; |
| 11 | 11 |
| 12 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
| 13 import org.chromium.chromoting.jni.TouchEventData; | 13 import org.chromium.chromoting.jni.TouchEventData; |
| 14 | 14 |
| 15 import java.util.LinkedList; | |
| 16 import java.util.Queue; | |
| 17 | |
| 18 /** Tests for {@link TouchInputStrategy}. */ | 15 /** Tests for {@link TouchInputStrategy}. */ |
| 19 public class TouchInputStrategyTest extends InstrumentationTestCase { | 16 public class TouchInputStrategyTest extends InstrumentationTestCase { |
| 20 // Tests are run using a screen which is smaller than the size of the remote
desktop and is | 17 // Tests are run using a screen which is smaller than the size of the remote
desktop and is |
| 21 // translated to the middle of the remote desktop area. This allows us to v
erify that the | 18 // translated to the middle of the remote desktop area. This allows us to v
erify that the |
| 22 // remote events which are 'injected' are correctly mapped and represent the
remote coordinates. | 19 // remote events which are 'injected' are correctly mapped and represent the
remote coordinates. |
| 23 private static final int SCREEN_SIZE_PX = 100; | 20 private static final int SCREEN_SIZE_PX = 100; |
| 24 private static final int REMOTE_DESKTOP_SIZE_PX = 300; | 21 private static final int REMOTE_DESKTOP_SIZE_PX = 300; |
| 25 private static final int TRANSLATE_OFFSET_PX = 100; | 22 private static final int TRANSLATE_OFFSET_PX = 100; |
| 26 | 23 |
| 27 private static class MouseData { | |
| 28 MouseData(int xValue, int yValue, int buttonPressed, boolean buttonDown)
{ | |
| 29 x = xValue; | |
| 30 y = yValue; | |
| 31 button = buttonPressed; | |
| 32 isDown = buttonDown; | |
| 33 } | |
| 34 | |
| 35 public int x; | |
| 36 public int y; | |
| 37 public int button; | |
| 38 public boolean isDown; | |
| 39 } | |
| 40 | |
| 41 private static class TouchData { | |
| 42 TouchData(TouchEventData.EventType type, TouchEventData[] data) { | |
| 43 eventType = type; | |
| 44 eventData = data; | |
| 45 } | |
| 46 | |
| 47 public TouchEventData.EventType eventType; | |
| 48 public TouchEventData[] eventData; | |
| 49 } | |
| 50 | |
| 51 private static class MockRemoteInputInjector implements TouchInputStrategy.R
emoteInputInjector { | |
| 52 private static final float COMPARISON_DELTA = 0.01f; | |
| 53 | |
| 54 private Queue<MouseData> mInjectedMouseEvents; | |
| 55 private Queue<TouchData> mInjectedTouchEvents; | |
| 56 | |
| 57 MockRemoteInputInjector() { | |
| 58 mInjectedMouseEvents = new LinkedList<MouseData>(); | |
| 59 mInjectedTouchEvents = new LinkedList<TouchData>(); | |
| 60 } | |
| 61 | |
| 62 @Override | |
| 63 public void injectMouseEvent(int x, int y, int button, boolean buttonDow
n) { | |
| 64 mInjectedMouseEvents.add(new MouseData(x, y, button, buttonDown)); | |
| 65 } | |
| 66 | |
| 67 @Override | |
| 68 public void injectTouchEvent(TouchEventData.EventType eventType, TouchEv
entData[] data) { | |
| 69 mInjectedTouchEvents.add(new TouchData(eventType, data)); | |
| 70 } | |
| 71 | |
| 72 public void assertTapInjected(int expectedX, int expectedY) { | |
| 73 assertEquals(2, mInjectedTouchEvents.size()); | |
| 74 assertTrue(mInjectedMouseEvents.isEmpty()); | |
| 75 | |
| 76 TouchData downTouchData = mInjectedTouchEvents.remove(); | |
| 77 assertEquals(TouchEventData.EventType.TOUCH_EVENT_START, downTouchDa
ta.eventType); | |
| 78 assertEquals(1, downTouchData.eventData.length); | |
| 79 assertEquals(expectedX, downTouchData.eventData[0].getTouchPointX(),
COMPARISON_DELTA); | |
| 80 assertEquals(expectedY, downTouchData.eventData[0].getTouchPointY(),
COMPARISON_DELTA); | |
| 81 | |
| 82 TouchData upTouchData = mInjectedTouchEvents.remove(); | |
| 83 assertEquals(TouchEventData.EventType.TOUCH_EVENT_END, upTouchData.e
ventType); | |
| 84 assertEquals(1, upTouchData.eventData.length); | |
| 85 assertEquals(expectedX, upTouchData.eventData[0].getTouchPointX(), C
OMPARISON_DELTA); | |
| 86 assertEquals(expectedY, upTouchData.eventData[0].getTouchPointY(), C
OMPARISON_DELTA); | |
| 87 } | |
| 88 | |
| 89 public void assertRightClickInjected(int expectedX, int expectedY) { | |
| 90 assertEquals(2, mInjectedMouseEvents.size()); | |
| 91 assertTrue(mInjectedTouchEvents.isEmpty()); | |
| 92 | |
| 93 MouseData downMouseData = mInjectedMouseEvents.remove(); | |
| 94 assertEquals(expectedX, downMouseData.x); | |
| 95 assertEquals(expectedY, downMouseData.y); | |
| 96 assertEquals(TouchInputHandlerInterface.BUTTON_RIGHT, downMouseData.
button); | |
| 97 assertTrue(downMouseData.isDown); | |
| 98 | |
| 99 MouseData upMouseData = mInjectedMouseEvents.remove(); | |
| 100 assertEquals(expectedX, upMouseData.x); | |
| 101 assertEquals(expectedY, upMouseData.y); | |
| 102 assertEquals(TouchInputHandlerInterface.BUTTON_RIGHT, upMouseData.bu
tton); | |
| 103 assertFalse(upMouseData.isDown); | |
| 104 } | |
| 105 | |
| 106 public void assertTouchEventInjected(TouchEventData.EventType eventType)
{ | |
| 107 // This method is called to verify the correct event type was added,
no verification is | |
| 108 // done for the position of each event. | |
| 109 assertTouchEventInjected(eventType, -1, -1); | |
| 110 } | |
| 111 | |
| 112 public void assertTouchEventInjected( | |
| 113 TouchEventData.EventType eventType, int expectedX, int expectedY
) { | |
| 114 assertEquals(1, mInjectedTouchEvents.size()); | |
| 115 | |
| 116 TouchData touchData = mInjectedTouchEvents.remove(); | |
| 117 assertEquals(eventType, touchData.eventType); | |
| 118 if (expectedX >= 0) { | |
| 119 assertEquals(expectedX, touchData.eventData[0].getTouchPointX(),
COMPARISON_DELTA); | |
| 120 } | |
| 121 if (expectedY >= 0) { | |
| 122 assertEquals(expectedY, touchData.eventData[0].getTouchPointY(),
COMPARISON_DELTA); | |
| 123 } | |
| 124 } | |
| 125 | |
| 126 public void assertTouchMoveEventInjected(int fingerNum, int stepSizeX, i
nt stepSizeY, | |
| 127 int expectedMoveCount) { | |
| 128 TouchData touchData; | |
| 129 Point[] initialLocations = new Point[fingerNum]; | |
| 130 // Verify the correct number of START events were injected. | |
| 131 for (int i = 0; i < fingerNum; i++) { | |
| 132 touchData = mInjectedTouchEvents.remove(); | |
| 133 assertEquals(1, touchData.eventData.length); | |
| 134 assertEquals(TouchEventData.EventType.TOUCH_EVENT_START, touchDa
ta.eventType); | |
| 135 initialLocations[i] = new Point((int) touchData.eventData[0].get
TouchPointX(), | |
| 136 (int) touchData.eventData[0].getTouchPointY()); | |
| 137 } | |
| 138 | |
| 139 // Verify the correct number of MOVE events were injected. | |
| 140 for (int i = 0; i < expectedMoveCount; i++) { | |
| 141 touchData = mInjectedTouchEvents.remove(); | |
| 142 assertEquals(fingerNum, touchData.eventData.length); | |
| 143 assertEquals(TouchEventData.EventType.TOUCH_EVENT_MOVE, touchDat
a.eventType); | |
| 144 | |
| 145 // These tests send a single event for each finger that is moved
. E.G. If we are | |
| 146 // injecting a pan event with two fingers, then every two TouchE
vents represents one | |
| 147 // 'frame' of the motion sequence. Here we determine which iter
ation this event | |
| 148 // represents so we can use that to accurately compare the locat
ions with the | |
| 149 // expected values. | |
| 150 int eventSequenceNum = i / fingerNum; | |
| 151 for (int j = 0; j < fingerNum; j++) { | |
| 152 // We inject one finger at a time which means that finger wi
ll have the correct | |
| 153 // value but other fingers may still be stepSize behind it.
We add a little bit | |
| 154 // of slop here to ensure that the position values are movin
g towards the target | |
| 155 // value and to allow for simpler validation. | |
| 156 assertEquals(initialLocations[j].x + (stepSizeX * eventSeque
nceNum), | |
| 157 touchData.eventData[j].getTouchPointX(), stepSizeX +
COMPARISON_DELTA); | |
| 158 assertEquals(initialLocations[j].y + (stepSizeY * eventSeque
nceNum), | |
| 159 touchData.eventData[j].getTouchPointY(), stepSizeY +
COMPARISON_DELTA); | |
| 160 } | |
| 161 } | |
| 162 } | |
| 163 | |
| 164 public void assertNothingInjected() { | |
| 165 assertTrue(mInjectedMouseEvents.isEmpty()); | |
| 166 assertTrue(mInjectedTouchEvents.isEmpty()); | |
| 167 } | |
| 168 } | |
| 169 | |
| 170 private RenderData mRenderData; | 24 private RenderData mRenderData; |
| 171 private TouchInputStrategy mInputStrategy; | 25 private TouchInputStrategy mInputStrategy; |
| 172 private MockRemoteInputInjector mRemoteInputInjector; | 26 private MockInputStub mInputInjector; |
| 173 private TouchEventGenerator mEventGenerator; | 27 private TouchEventGenerator mEventGenerator; |
| 174 | 28 |
| 175 /** Injects movement of a single finger (keeping other fingers in place). */ | 29 /** Injects movement of a single finger (keeping other fingers in place). */ |
| 176 private void injectMoveEvent(int id, float x, float y) { | 30 private void injectMoveEvent(int id, float x, float y) { |
| 177 MotionEvent event = mEventGenerator.obtainMoveEvent(id, x, y); | 31 MotionEvent event = mEventGenerator.obtainMoveEvent(id, x, y); |
| 178 mInputStrategy.onMotionEvent(event); | 32 mInputStrategy.onMotionEvent(event); |
| 179 event.recycle(); | 33 event.recycle(); |
| 180 } | 34 } |
| 181 | 35 |
| 182 /** Injects a finger-down event (keeping other fingers in place). */ | 36 /** Injects a finger-down event (keeping other fingers in place). */ |
| 183 private void injectDownEvent(int id, float x, float y) { | 37 private void injectDownEvent(int id, float x, float y) { |
| 184 MotionEvent event = mEventGenerator.obtainDownEvent(id, x, y); | 38 MotionEvent event = mEventGenerator.obtainDownEvent(id, x, y); |
| 185 mInputStrategy.onMotionEvent(event); | 39 mInputStrategy.onMotionEvent(event); |
| 186 event.recycle(); | 40 event.recycle(); |
| 187 } | 41 } |
| 188 | 42 |
| 189 /** Injects a finger-up event (keeping other fingers in place). */ | 43 /** Injects a finger-up event (keeping other fingers in place). */ |
| 190 private void injectUpEvent(int id) { | 44 private void injectUpEvent(int id) { |
| 191 MotionEvent event = mEventGenerator.obtainUpEvent(id); | 45 MotionEvent event = mEventGenerator.obtainUpEvent(id); |
| 192 mInputStrategy.onMotionEvent(event); | 46 mInputStrategy.onMotionEvent(event); |
| 193 event.recycle(); | 47 event.recycle(); |
| 194 } | 48 } |
| 195 | 49 |
| 196 @Override | 50 @Override |
| 197 public void setUp() { | 51 public void setUp() { |
| 198 mRenderData = new RenderData(); | 52 mRenderData = new RenderData(); |
| 199 mRemoteInputInjector = new MockRemoteInputInjector(); | 53 mInputInjector = new MockInputStub(); |
| 200 | 54 |
| 201 // TODO(lambroslambrou): Provide a mock Client implementation that doesn
't call out to JNI, | 55 mInputStrategy = |
| 202 // and mock the Client methods instead of using MockRemoteInputInjector
here. | 56 new TouchInputStrategy(mRenderData, new InputEventSender(mInputI
njector)); |
| 203 mInputStrategy = new TouchInputStrategy(mRenderData, null); | |
| 204 mInputStrategy.setRemoteInputInjectorForTest(mRemoteInputInjector); | |
| 205 mEventGenerator = new TouchEventGenerator(); | 57 mEventGenerator = new TouchEventGenerator(); |
| 206 | |
| 207 mRenderData.screenWidth = SCREEN_SIZE_PX; | 58 mRenderData.screenWidth = SCREEN_SIZE_PX; |
| 208 mRenderData.screenHeight = SCREEN_SIZE_PX; | 59 mRenderData.screenHeight = SCREEN_SIZE_PX; |
| 209 mRenderData.imageWidth = REMOTE_DESKTOP_SIZE_PX; | 60 mRenderData.imageWidth = REMOTE_DESKTOP_SIZE_PX; |
| 210 mRenderData.imageHeight = REMOTE_DESKTOP_SIZE_PX; | 61 mRenderData.imageHeight = REMOTE_DESKTOP_SIZE_PX; |
| 211 mRenderData.transform.postTranslate(-TRANSLATE_OFFSET_PX, -TRANSLATE_OFF
SET_PX); | 62 mRenderData.transform.postTranslate(-TRANSLATE_OFFSET_PX, -TRANSLATE_OFF
SET_PX); |
| 212 } | 63 } |
| 213 | 64 |
| 214 @SmallTest | 65 @SmallTest |
| 215 @Feature({"Chromoting"}) | 66 @Feature({"Chromoting"}) |
| 216 public void testOnTapWithNoEvents() throws Exception { | 67 public void testOnTapWithNoEvents() throws Exception { |
| 217 assertFalse(mInputStrategy.onTap(TouchInputHandlerInterface.BUTTON_LEFT)
); | 68 assertFalse(mInputStrategy.onTap(InputStub.BUTTON_LEFT)); |
| 218 mRemoteInputInjector.assertNothingInjected(); | 69 mInputInjector.assertEmpty(); |
| 219 } | 70 } |
| 220 | 71 |
| 221 @SmallTest | 72 @SmallTest |
| 222 @Feature({"Chromoting"}) | 73 @Feature({"Chromoting"}) |
| 223 public void testOneFingerTap() throws Exception { | 74 public void testOneFingerTap() throws Exception { |
| 224 injectDownEvent(0, 0, 0); | 75 injectDownEvent(0, 0, 0); |
| 225 injectUpEvent(0); | 76 injectUpEvent(0); |
| 226 mRemoteInputInjector.assertNothingInjected(); | 77 mInputInjector.assertEmpty(); |
| 227 | 78 |
| 228 assertTrue(mInputStrategy.onTap(TouchInputHandlerInterface.BUTTON_LEFT))
; | 79 assertTrue(mInputStrategy.onTap(InputStub.BUTTON_LEFT)); |
| 229 | 80 |
| 230 mRemoteInputInjector.assertTapInjected(TRANSLATE_OFFSET_PX, TRANSLATE_OF
FSET_PX); | 81 mInputInjector.assertTapInjected(TRANSLATE_OFFSET_PX, TRANSLATE_OFFSET_P
X); |
| 82 mInputInjector.assertEmpty(); |
| 231 } | 83 } |
| 232 | 84 |
| 233 @SmallTest | 85 @SmallTest |
| 234 @Feature({"Chromoting"}) | 86 @Feature({"Chromoting"}) |
| 235 public void testLifoTwoFingerTap() throws Exception { | 87 public void testLifoTwoFingerTap() throws Exception { |
| 236 // Verify that the right click coordinates occur at the point of the fir
st tap when the | 88 // Verify that the right click coordinates occur at the point of the fir
st tap when the |
| 237 // initial finger is lifted up last. | 89 // initial finger is lifted up last. |
| 238 injectDownEvent(0, 0, 0); | 90 injectDownEvent(0, 0, 0); |
| 239 injectDownEvent(1, 25, 25); | 91 injectDownEvent(1, 25, 25); |
| 240 injectUpEvent(1); | 92 injectUpEvent(1); |
| 241 injectUpEvent(0); | 93 injectUpEvent(0); |
| 242 mRemoteInputInjector.assertNothingInjected(); | 94 mInputInjector.assertEmpty(); |
| 243 | 95 |
| 244 assertTrue(mInputStrategy.onTap(TouchInputHandlerInterface.BUTTON_RIGHT)
); | 96 assertTrue(mInputStrategy.onTap(InputStub.BUTTON_RIGHT)); |
| 245 | 97 |
| 246 mRemoteInputInjector.assertRightClickInjected(TRANSLATE_OFFSET_PX, TRANS
LATE_OFFSET_PX); | 98 mInputInjector.assertRightClickInjected(TRANSLATE_OFFSET_PX, TRANSLATE_O
FFSET_PX); |
| 99 mInputInjector.assertEmpty(); |
| 247 } | 100 } |
| 248 | 101 |
| 249 @SmallTest | 102 @SmallTest |
| 250 @Feature({"Chromoting"}) | 103 @Feature({"Chromoting"}) |
| 251 public void testFifoTwoFingerTap() throws Exception { | 104 public void testFifoTwoFingerTap() throws Exception { |
| 252 // Verify that the right click coordinates occur at the point of the fir
st tap when the | 105 // Verify that the right click coordinates occur at the point of the fir
st tap when the |
| 253 // initial finger is lifted up first. | 106 // initial finger is lifted up first. |
| 254 injectDownEvent(0, 0, 0); | 107 injectDownEvent(0, 0, 0); |
| 255 injectDownEvent(1, 25, 25); | 108 injectDownEvent(1, 25, 25); |
| 256 injectUpEvent(0); | 109 injectUpEvent(0); |
| 257 injectUpEvent(1); | 110 injectUpEvent(1); |
| 258 mRemoteInputInjector.assertNothingInjected(); | 111 mInputInjector.assertEmpty(); |
| 259 | 112 |
| 260 assertTrue(mInputStrategy.onTap(TouchInputHandlerInterface.BUTTON_RIGHT)
); | 113 assertTrue(mInputStrategy.onTap(InputStub.BUTTON_RIGHT)); |
| 261 | 114 |
| 262 mRemoteInputInjector.assertRightClickInjected(TRANSLATE_OFFSET_PX, TRANS
LATE_OFFSET_PX); | 115 mInputInjector.assertRightClickInjected(TRANSLATE_OFFSET_PX, TRANSLATE_O
FFSET_PX); |
| 116 mInputInjector.assertEmpty(); |
| 263 } | 117 } |
| 264 | 118 |
| 265 @SmallTest | 119 @SmallTest |
| 266 @Feature({"Chromoting"}) | 120 @Feature({"Chromoting"}) |
| 267 public void testThreeFingerTap() throws Exception { | 121 public void testThreeFingerTap() throws Exception { |
| 268 injectDownEvent(0, 0, 0); | 122 injectDownEvent(0, 0, 0); |
| 269 injectDownEvent(1, 25, 25); | 123 injectDownEvent(1, 25, 25); |
| 270 injectDownEvent(2, 50, 50); | 124 injectDownEvent(2, 50, 50); |
| 271 injectUpEvent(2); | 125 injectUpEvent(2); |
| 272 injectUpEvent(1); | 126 injectUpEvent(1); |
| 273 injectUpEvent(0); | 127 injectUpEvent(0); |
| 274 mRemoteInputInjector.assertNothingInjected(); | 128 mInputInjector.assertEmpty(); |
| 275 | 129 |
| 276 assertFalse(mInputStrategy.onTap(TouchInputHandlerInterface.BUTTON_MIDDL
E)); | 130 assertFalse(mInputStrategy.onTap(InputStub.BUTTON_MIDDLE)); |
| 277 mRemoteInputInjector.assertNothingInjected(); | 131 mInputInjector.assertEmpty(); |
| 278 } | 132 } |
| 279 | 133 |
| 280 @SmallTest | 134 @SmallTest |
| 281 @Feature({"Chromoting"}) | 135 @Feature({"Chromoting"}) |
| 282 public void testOneFingerTapSequence() throws Exception { | 136 public void testOneFingerTapSequence() throws Exception { |
| 283 int tapSequenceCount = 10; | 137 int tapSequenceCount = 10; |
| 284 for (int i = 0; i < tapSequenceCount; i++) { | 138 for (int i = 0; i < tapSequenceCount; i++) { |
| 285 injectDownEvent(0, i, i); | 139 injectDownEvent(0, i, i); |
| 286 injectUpEvent(0); | 140 injectUpEvent(0); |
| 287 mRemoteInputInjector.assertNothingInjected(); | 141 mInputInjector.assertEmpty(); |
| 288 | 142 |
| 289 assertTrue(mInputStrategy.onTap(TouchInputHandlerInterface.BUTTON_LE
FT)); | 143 assertTrue(mInputStrategy.onTap(InputStub.BUTTON_LEFT)); |
| 290 | 144 |
| 291 int remoteOffsetPx = TRANSLATE_OFFSET_PX + i; | 145 int remoteOffsetPx = TRANSLATE_OFFSET_PX + i; |
| 292 mRemoteInputInjector.assertTapInjected(remoteOffsetPx, remoteOffsetP
x); | 146 mInputInjector.assertTapInjected(remoteOffsetPx, remoteOffsetPx); |
| 293 } | 147 } |
| 148 mInputInjector.assertEmpty(); |
| 294 } | 149 } |
| 295 | 150 |
| 296 @SmallTest | 151 @SmallTest |
| 297 @Feature({"Chromoting"}) | 152 @Feature({"Chromoting"}) |
| 298 public void testInvalidThenValidTap() throws Exception { | 153 public void testInvalidThenValidTap() throws Exception { |
| 299 // First an invalid tap, verify it is ignored. | 154 // First an invalid tap, verify it is ignored. |
| 300 injectDownEvent(0, 0, 0); | 155 injectDownEvent(0, 0, 0); |
| 301 injectDownEvent(1, 25, 25); | 156 injectDownEvent(1, 25, 25); |
| 302 injectDownEvent(2, 50, 50); | 157 injectDownEvent(2, 50, 50); |
| 303 injectUpEvent(2); | 158 injectUpEvent(2); |
| 304 injectUpEvent(1); | 159 injectUpEvent(1); |
| 305 injectUpEvent(0); | 160 injectUpEvent(0); |
| 306 mRemoteInputInjector.assertNothingInjected(); | 161 mInputInjector.assertEmpty(); |
| 307 | 162 |
| 308 assertFalse(mInputStrategy.onTap(TouchInputHandlerInterface.BUTTON_MIDDL
E)); | 163 assertFalse(mInputStrategy.onTap(InputStub.BUTTON_MIDDLE)); |
| 309 mRemoteInputInjector.assertNothingInjected(); | 164 mInputInjector.assertEmpty(); |
| 310 | 165 |
| 311 // Next a valid tap, verify it is handled. | 166 // Next a valid tap, verify it is handled. |
| 312 injectDownEvent(0, 0, 0); | 167 injectDownEvent(0, 0, 0); |
| 313 injectUpEvent(0); | 168 injectUpEvent(0); |
| 314 mRemoteInputInjector.assertNothingInjected(); | 169 mInputInjector.assertEmpty(); |
| 315 | 170 |
| 316 assertTrue(mInputStrategy.onTap(TouchInputHandlerInterface.BUTTON_LEFT))
; | 171 assertTrue(mInputStrategy.onTap(InputStub.BUTTON_LEFT)); |
| 317 | 172 |
| 318 mRemoteInputInjector.assertTapInjected(TRANSLATE_OFFSET_PX, TRANSLATE_OF
FSET_PX); | 173 mInputInjector.assertTapInjected(TRANSLATE_OFFSET_PX, TRANSLATE_OFFSET_P
X); |
| 174 mInputInjector.assertEmpty(); |
| 319 } | 175 } |
| 320 | 176 |
| 321 @SmallTest | 177 @SmallTest |
| 322 @Feature({"Chromoting"}) | 178 @Feature({"Chromoting"}) |
| 323 public void testOnPressAndHoldWithNoEvents() throws Exception { | 179 public void testOnPressAndHoldWithNoEvents() throws Exception { |
| 324 assertFalse(mInputStrategy.onPressAndHold(TouchInputHandlerInterface.BUT
TON_LEFT)); | 180 assertFalse(mInputStrategy.onPressAndHold(InputStub.BUTTON_LEFT)); |
| 325 mRemoteInputInjector.assertNothingInjected(); | 181 mInputInjector.assertEmpty(); |
| 326 } | 182 } |
| 327 | 183 |
| 328 @SmallTest | 184 @SmallTest |
| 329 @Feature({"Chromoting"}) | 185 @Feature({"Chromoting"}) |
| 330 public void testOneFingerLongPress() throws Exception { | 186 public void testOneFingerLongPress() throws Exception { |
| 331 injectDownEvent(0, 0, 0); | 187 injectDownEvent(0, 0, 0); |
| 332 mRemoteInputInjector.assertNothingInjected(); | 188 mInputInjector.assertEmpty(); |
| 333 | 189 |
| 334 assertTrue(mInputStrategy.onPressAndHold(TouchInputHandlerInterface.BUTT
ON_LEFT)); | 190 assertTrue(mInputStrategy.onPressAndHold(InputStub.BUTTON_LEFT)); |
| 335 mRemoteInputInjector.assertTouchEventInjected(TouchEventData.EventType.T
OUCH_EVENT_START, | 191 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOUCH_E
VENT_START, |
| 336 TRANSLATE_OFFSET_PX, TRANSLATE_OFFSET_PX); | 192 TRANSLATE_OFFSET_PX, TRANSLATE_OFFSET_PX); |
| 337 | 193 |
| 338 injectUpEvent(0); | 194 injectUpEvent(0); |
| 339 mRemoteInputInjector.assertTouchEventInjected( | 195 mInputInjector.assertTouchEventInjected( |
| 340 TouchEventData.EventType.TOUCH_EVENT_END, TRANSLATE_OFFSET_PX, T
RANSLATE_OFFSET_PX); | 196 TouchEventData.EventType.TOUCH_EVENT_END, TRANSLATE_OFFSET_PX, T
RANSLATE_OFFSET_PX); |
| 197 mInputInjector.assertEmpty(); |
| 341 } | 198 } |
| 342 | 199 |
| 343 @SmallTest | 200 @SmallTest |
| 344 @Feature({"Chromoting"}) | 201 @Feature({"Chromoting"}) |
| 345 public void testOneFingerLongPressThenPan() throws Exception { | 202 public void testOneFingerLongPressThenPan() throws Exception { |
| 346 injectDownEvent(0, 0, 0); | 203 injectDownEvent(0, 0, 0); |
| 347 mRemoteInputInjector.assertNothingInjected(); | 204 mInputInjector.assertEmpty(); |
| 348 | 205 |
| 349 assertTrue(mInputStrategy.onPressAndHold(TouchInputHandlerInterface.BUTT
ON_LEFT)); | 206 assertTrue(mInputStrategy.onPressAndHold(InputStub.BUTTON_LEFT)); |
| 350 mRemoteInputInjector.assertTouchEventInjected(TouchEventData.EventType.T
OUCH_EVENT_START, | 207 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOUCH_E
VENT_START, |
| 351 TRANSLATE_OFFSET_PX, TRANSLATE_OFFSET_PX); | 208 TRANSLATE_OFFSET_PX, TRANSLATE_OFFSET_PX); |
| 352 | 209 |
| 353 int panEventCount = 50; | 210 final int panEventCount = 50; |
| 354 for (int i = 0; i <= 50; i++) { | 211 for (int i = 0; i <= panEventCount; i++) { |
| 355 injectMoveEvent(0, 0, i); | 212 injectMoveEvent(0, 0, i); |
| 356 mRemoteInputInjector.assertTouchEventInjected( | 213 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOU
CH_EVENT_MOVE); |
| 357 TouchEventData.EventType.TOUCH_EVENT_MOVE); | |
| 358 } | 214 } |
| 359 | 215 |
| 360 injectUpEvent(0); | 216 injectUpEvent(0); |
| 361 mRemoteInputInjector.assertTouchEventInjected(TouchEventData.EventType.T
OUCH_EVENT_END, | 217 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOUCH_E
VENT_END, |
| 362 TRANSLATE_OFFSET_PX, TRANSLATE_OFFSET_PX + panEventCount); | 218 TRANSLATE_OFFSET_PX, TRANSLATE_OFFSET_PX + panEventCount); |
| 219 mInputInjector.assertEmpty(); |
| 363 } | 220 } |
| 364 | 221 |
| 365 @SmallTest | 222 @SmallTest |
| 366 @Feature({"Chromoting"}) | 223 @Feature({"Chromoting"}) |
| 367 public void testTwoFingerLongPress() throws Exception { | 224 public void testTwoFingerLongPress() throws Exception { |
| 368 injectDownEvent(0, 0, 0); | 225 injectDownEvent(0, 0, 0); |
| 369 injectDownEvent(1, 1, 1); | 226 injectDownEvent(1, 1, 1); |
| 370 mRemoteInputInjector.assertNothingInjected(); | 227 mInputInjector.assertEmpty(); |
| 371 | 228 |
| 372 assertFalse(mInputStrategy.onPressAndHold(TouchInputHandlerInterface.BUT
TON_RIGHT)); | 229 assertFalse(mInputStrategy.onPressAndHold(InputStub.BUTTON_RIGHT)); |
| 373 mRemoteInputInjector.assertNothingInjected(); | 230 mInputInjector.assertEmpty(); |
| 374 | 231 |
| 375 injectUpEvent(0); | 232 injectUpEvent(0); |
| 376 injectUpEvent(1); | 233 injectUpEvent(1); |
| 377 mRemoteInputInjector.assertNothingInjected(); | 234 mInputInjector.assertEmpty(); |
| 378 } | 235 } |
| 379 | 236 |
| 380 @SmallTest | 237 @SmallTest |
| 381 @Feature({"Chromoting"}) | 238 @Feature({"Chromoting"}) |
| 382 public void testOneFingerPan() throws Exception { | 239 public void testOneFingerPan() throws Exception { |
| 383 injectDownEvent(0, 0, 0); | 240 injectDownEvent(0, 0, 0); |
| 384 | 241 |
| 385 // Inject a few move events to simulate a pan. | 242 // Inject a few move events to simulate a pan. |
| 386 injectMoveEvent(0, 1, 1); | 243 injectMoveEvent(0, 1, 1); |
| 387 injectMoveEvent(0, 2, 2); | 244 injectMoveEvent(0, 2, 2); |
| 388 injectMoveEvent(0, 3, 3); | 245 injectMoveEvent(0, 3, 3); |
| 389 mRemoteInputInjector.assertNothingInjected(); | 246 mInputInjector.assertEmpty(); |
| 390 | 247 |
| 391 injectUpEvent(0); | 248 injectUpEvent(0); |
| 392 mRemoteInputInjector.assertNothingInjected(); | 249 mInputInjector.assertEmpty(); |
| 393 } | 250 } |
| 394 | 251 |
| 395 @SmallTest | 252 @SmallTest |
| 396 @Feature({"Chromoting"}) | 253 @Feature({"Chromoting"}) |
| 397 public void testVerticalTwoFingerPan() throws Exception { | 254 public void testVerticalTwoFingerPan() throws Exception { |
| 398 final int fingerOnePosX = 0; | 255 final int fingerOnePosX = 0; |
| 399 final int fingerTwoPosX = 10; | 256 final int fingerTwoPosX = 10; |
| 400 injectDownEvent(0, fingerOnePosX, 0); | 257 injectDownEvent(0, fingerOnePosX, 0); |
| 401 injectDownEvent(1, fingerTwoPosX, 0); | 258 injectDownEvent(1, fingerTwoPosX, 0); |
| 402 | 259 |
| 403 final int eventNum = 10; | 260 final int eventNum = 10; |
| 404 for (int i = 0; i < eventNum; i++) { | 261 for (int i = 0; i < eventNum; i++) { |
| 405 injectMoveEvent(0, fingerOnePosX, i); | 262 injectMoveEvent(0, fingerOnePosX, i); |
| 406 injectMoveEvent(1, fingerTwoPosX, i); | 263 injectMoveEvent(1, fingerTwoPosX, i); |
| 407 } | 264 } |
| 408 mRemoteInputInjector.assertNothingInjected(); | 265 mInputInjector.assertEmpty(); |
| 409 | 266 |
| 410 mInputStrategy.onScroll(0.0f, 0.0f); | 267 mInputStrategy.onScroll(0.0f, 0.0f); |
| 411 mRemoteInputInjector.assertTouchMoveEventInjected(2, 0, 1, eventNum * 2)
; | 268 mInputInjector.assertTouchMoveEventInjected( |
| 269 new PointF[] { |
| 270 new PointF(fingerOnePosX + TRANSLATE_OFFSET_PX, TRANSLAT
E_OFFSET_PX), |
| 271 new PointF(fingerTwoPosX + TRANSLATE_OFFSET_PX, TRANSLAT
E_OFFSET_PX), |
| 272 }, |
| 273 0, 1, eventNum); |
| 412 | 274 |
| 413 // Verify events are sent in realtime now. | 275 // Verify events are sent in realtime now. |
| 414 for (int i = eventNum; i < eventNum + 5; i++) { | 276 for (int i = eventNum; i < eventNum + 5; i++) { |
| 415 injectMoveEvent(0, fingerOnePosX, i); | 277 injectMoveEvent(0, fingerOnePosX, i); |
| 416 mRemoteInputInjector.assertTouchEventInjected( | 278 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOU
CH_EVENT_MOVE); |
| 417 TouchEventData.EventType.TOUCH_EVENT_MOVE); | |
| 418 | 279 |
| 419 injectMoveEvent(1, fingerTwoPosX, i); | 280 injectMoveEvent(1, fingerTwoPosX, i); |
| 420 mRemoteInputInjector.assertTouchEventInjected( | 281 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOU
CH_EVENT_MOVE); |
| 421 TouchEventData.EventType.TOUCH_EVENT_MOVE); | |
| 422 } | 282 } |
| 423 | 283 |
| 424 injectUpEvent(0); | 284 injectUpEvent(0); |
| 425 mRemoteInputInjector.assertTouchEventInjected( | 285 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOUCH_E
VENT_END); |
| 426 TouchEventData.EventType.TOUCH_EVENT_END); | |
| 427 | 286 |
| 428 injectUpEvent(1); | 287 injectUpEvent(1); |
| 429 mRemoteInputInjector.assertTouchEventInjected( | 288 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOUCH_E
VENT_END); |
| 430 TouchEventData.EventType.TOUCH_EVENT_END); | 289 mInputInjector.assertEmpty(); |
| 431 } | 290 } |
| 432 | 291 |
| 433 @SmallTest | 292 @SmallTest |
| 434 @Feature({"Chromoting"}) | 293 @Feature({"Chromoting"}) |
| 435 public void testHorizontalTwoFingerPan() throws Exception { | 294 public void testHorizontalTwoFingerPan() throws Exception { |
| 436 final int fingerOnePosY = 0; | 295 final int fingerOnePosY = 0; |
| 437 final int fingerTwoPosY = 10; | 296 final int fingerTwoPosY = 10; |
| 438 injectDownEvent(0, 0, fingerOnePosY); | 297 injectDownEvent(0, 0, fingerOnePosY); |
| 439 injectDownEvent(1, 0, fingerTwoPosY); | 298 injectDownEvent(1, 0, fingerTwoPosY); |
| 440 | 299 |
| 441 final int eventNum = 10; | 300 final int eventNum = 10; |
| 442 for (int i = 0; i < eventNum; i++) { | 301 for (int i = 0; i < eventNum; i++) { |
| 443 injectMoveEvent(0, i, fingerOnePosY); | 302 injectMoveEvent(0, i, fingerOnePosY); |
| 444 injectMoveEvent(1, i, fingerTwoPosY); | 303 injectMoveEvent(1, i, fingerTwoPosY); |
| 445 } | 304 } |
| 446 mRemoteInputInjector.assertNothingInjected(); | 305 mInputInjector.assertEmpty(); |
| 447 | 306 |
| 448 mInputStrategy.onScroll(0.0f, 0.0f); | 307 mInputStrategy.onScroll(0.0f, 0.0f); |
| 449 mRemoteInputInjector.assertTouchMoveEventInjected(2, 1, 0, eventNum * 2)
; | 308 mInputInjector.assertTouchMoveEventInjected( |
| 309 new PointF[] { |
| 310 new PointF(TRANSLATE_OFFSET_PX, fingerOnePosY + TRANSLAT
E_OFFSET_PX), |
| 311 new PointF(TRANSLATE_OFFSET_PX, fingerTwoPosY + TRANSLAT
E_OFFSET_PX), |
| 312 }, |
| 313 1, 0, eventNum); |
| 450 | 314 |
| 451 // Verify events are sent in realtime now. | 315 // Verify events are sent in realtime now. |
| 452 for (int i = eventNum; i < eventNum + 5; i++) { | 316 for (int i = eventNum; i < eventNum + 5; i++) { |
| 453 injectMoveEvent(0, i, fingerOnePosY); | 317 injectMoveEvent(0, i, fingerOnePosY); |
| 454 mRemoteInputInjector.assertTouchEventInjected( | 318 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOU
CH_EVENT_MOVE); |
| 455 TouchEventData.EventType.TOUCH_EVENT_MOVE); | |
| 456 | 319 |
| 457 injectMoveEvent(1, i, fingerTwoPosY); | 320 injectMoveEvent(1, i, fingerTwoPosY); |
| 458 mRemoteInputInjector.assertTouchEventInjected( | 321 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOU
CH_EVENT_MOVE); |
| 459 TouchEventData.EventType.TOUCH_EVENT_MOVE); | |
| 460 } | 322 } |
| 461 | 323 |
| 462 injectUpEvent(0); | 324 injectUpEvent(0); |
| 463 mRemoteInputInjector.assertTouchEventInjected( | 325 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOUCH_E
VENT_END); |
| 464 TouchEventData.EventType.TOUCH_EVENT_END); | |
| 465 | 326 |
| 466 injectUpEvent(1); | 327 injectUpEvent(1); |
| 467 mRemoteInputInjector.assertTouchEventInjected( | 328 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOUCH_E
VENT_END); |
| 468 TouchEventData.EventType.TOUCH_EVENT_END); | 329 mInputInjector.assertEmpty(); |
| 469 } | 330 } |
| 470 | 331 |
| 471 @SmallTest | 332 @SmallTest |
| 472 @Feature({"Chromoting"}) | 333 @Feature({"Chromoting"}) |
| 473 public void testCancelledTwoFingerPan() throws Exception { | 334 public void testCancelledTwoFingerPan() throws Exception { |
| 474 final int fingerOnePosX = 0; | 335 final int fingerOnePosX = 0; |
| 475 final int fingerTwoPosX = 10; | 336 final int fingerTwoPosX = 10; |
| 476 injectDownEvent(0, fingerOnePosX, 0); | 337 injectDownEvent(0, fingerOnePosX, 0); |
| 477 injectDownEvent(1, fingerTwoPosX, 0); | 338 injectDownEvent(1, fingerTwoPosX, 0); |
| 478 | 339 |
| 479 final int eventNum = 10; | 340 final int eventNum = 10; |
| 480 for (int i = 0; i < eventNum; i++) { | 341 for (int i = 0; i < eventNum; i++) { |
| 481 injectMoveEvent(0, fingerOnePosX, i); | 342 injectMoveEvent(0, fingerOnePosX, i); |
| 482 injectMoveEvent(1, fingerTwoPosX, i); | 343 injectMoveEvent(1, fingerTwoPosX, i); |
| 483 } | 344 } |
| 484 mRemoteInputInjector.assertNothingInjected(); | 345 mInputInjector.assertEmpty(); |
| 485 | 346 |
| 486 mInputStrategy.onScroll(0.0f, 0.0f); | 347 mInputStrategy.onScroll(0.0f, 0.0f); |
| 487 mRemoteInputInjector.assertTouchMoveEventInjected(2, 0, 1, eventNum * 2)
; | 348 mInputInjector.assertTouchMoveEventInjected( |
| 349 new PointF[] { |
| 350 new PointF(fingerOnePosX + TRANSLATE_OFFSET_PX, TRANSLAT
E_OFFSET_PX), |
| 351 new PointF(fingerTwoPosX + TRANSLATE_OFFSET_PX, TRANSLAT
E_OFFSET_PX), |
| 352 }, |
| 353 0, 1, eventNum); |
| 488 | 354 |
| 489 // Verify events are sent in realtime now. | 355 // Verify events are sent in realtime now. |
| 490 for (int i = eventNum; i < eventNum + 5; i++) { | 356 for (int i = eventNum; i < eventNum + 5; i++) { |
| 491 injectMoveEvent(0, fingerOnePosX, i); | 357 injectMoveEvent(0, fingerOnePosX, i); |
| 492 mRemoteInputInjector.assertTouchEventInjected( | 358 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOU
CH_EVENT_MOVE); |
| 493 TouchEventData.EventType.TOUCH_EVENT_MOVE); | |
| 494 | 359 |
| 495 injectMoveEvent(1, fingerTwoPosX, i); | 360 injectMoveEvent(1, fingerTwoPosX, i); |
| 496 mRemoteInputInjector.assertTouchEventInjected( | 361 mInputInjector.assertTouchEventInjected(TouchEventData.EventType.TOU
CH_EVENT_MOVE); |
| 497 TouchEventData.EventType.TOUCH_EVENT_MOVE); | |
| 498 } | 362 } |
| 499 | 363 |
| 500 // Once a third finger goes down, no more events should be sent. | 364 // Once a third finger goes down, no more events should be sent. |
| 501 injectDownEvent(2, 0, 0); | 365 injectDownEvent(2, 0, 0); |
| 502 mRemoteInputInjector.assertNothingInjected(); | 366 mInputInjector.assertEmpty(); |
| 503 | 367 |
| 504 injectMoveEvent(0, 0, 0); | 368 injectMoveEvent(0, 0, 0); |
| 505 injectMoveEvent(1, 0, 0); | 369 injectMoveEvent(1, 0, 0); |
| 506 injectMoveEvent(2, 0, 0); | 370 injectMoveEvent(2, 0, 0); |
| 507 mRemoteInputInjector.assertNothingInjected(); | 371 mInputInjector.assertEmpty(); |
| 508 | 372 |
| 509 injectUpEvent(2); | 373 injectUpEvent(2); |
| 510 mRemoteInputInjector.assertNothingInjected(); | 374 mInputInjector.assertEmpty(); |
| 511 | 375 |
| 512 injectMoveEvent(0, 5, 5); | 376 injectMoveEvent(0, 5, 5); |
| 513 injectMoveEvent(1, 5, 5); | 377 injectMoveEvent(1, 5, 5); |
| 514 mRemoteInputInjector.assertNothingInjected(); | 378 mInputInjector.assertEmpty(); |
| 515 } | 379 } |
| 516 | 380 |
| 517 @SmallTest | 381 @SmallTest |
| 518 @Feature({"Chromoting"}) | 382 @Feature({"Chromoting"}) |
| 519 public void testTooManyEventsCancelsGesture() throws Exception { | 383 public void testTooManyEventsCancelsGesture() throws Exception { |
| 520 final int fingerOnePosX = 0; | 384 final int fingerOnePosX = 0; |
| 521 final int fingerTwoPosX = 10; | 385 final int fingerTwoPosX = 10; |
| 522 injectDownEvent(0, fingerOnePosX, 0); | 386 injectDownEvent(0, fingerOnePosX, 0); |
| 523 injectDownEvent(1, fingerTwoPosX, 0); | 387 injectDownEvent(1, fingerTwoPosX, 0); |
| 524 | 388 |
| 525 for (int i = 0; i < 10000; i++) { | 389 for (int i = 0; i < 10000; i++) { |
| 526 injectMoveEvent(0, fingerOnePosX, i % 10); | 390 injectMoveEvent(0, fingerOnePosX, i % 10); |
| 527 injectMoveEvent(1, fingerTwoPosX, i % 10); | 391 injectMoveEvent(1, fingerTwoPosX, i % 10); |
| 528 } | 392 } |
| 529 mRemoteInputInjector.assertNothingInjected(); | 393 mInputInjector.assertEmpty(); |
| 530 | 394 |
| 531 mInputStrategy.onScroll(0.0f, 0.0f); | 395 mInputStrategy.onScroll(0.0f, 0.0f); |
| 532 mRemoteInputInjector.assertNothingInjected(); | 396 mInputInjector.assertEmpty(); |
| 533 } | 397 } |
| 534 } | 398 } |
| OLD | NEW |