OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 package org.chromium.chromoting; | |
Sergey Ulanov
2013/12/19 19:45:27
Not related to this CL: I think we should rename i
| |
6 | |
7 import android.os.SystemClock; | |
8 import android.test.InstrumentationTestCase; | |
9 import android.test.suitebuilder.annotation.SmallTest; | |
10 import android.view.InputDevice; | |
11 import android.view.MotionEvent; | |
12 | |
13 import org.chromium.base.test.util.Feature; | |
14 | |
15 /** Tests for {@link SwipePinchDetector}. */ | |
16 public class SwipePinchDetectorTest extends InstrumentationTestCase { | |
17 private SwipePinchDetector mDetector; | |
18 private MotionEvent.PointerProperties[] mPointers; | |
19 | |
20 @Override | |
21 public void setUp() { | |
22 mDetector = new SwipePinchDetector(getInstrumentation().getTargetContext ()); | |
23 MotionEvent.PointerProperties pointer0 = new MotionEvent.PointerProperti es(); | |
24 pointer0.id = 0; | |
25 MotionEvent.PointerProperties pointer1 = new MotionEvent.PointerProperti es(); | |
26 pointer1.id = 1; | |
27 mPointers = new MotionEvent.PointerProperties[] {pointer0, pointer1}; | |
28 } | |
29 | |
30 /** Verify that a simple swipe gesture is recognized as a swipe. */ | |
31 @SmallTest | |
32 @Feature({"Chromoting"}) | |
Sergey Ulanov
2013/12/19 19:45:27
RemotingClientUI?
Lambros
2013/12/20 02:52:01
Guidance here: http://www.chromium.org/developers/
| |
33 public void testSwipeRecognition() throws Exception { | |
34 final long eventTime = SystemClock.uptimeMillis(); | |
35 MotionEvent.PointerCoords p0 = new MotionEvent.PointerCoords(); | |
36 MotionEvent.PointerCoords p1 = new MotionEvent.PointerCoords(); | |
37 p0.x = 0; | |
38 p0.y = 0; | |
Sergey Ulanov
2013/12/19 19:45:27
nit: x and y should be initialized to 0 by default
Lambros
2013/12/20 02:52:01
Done. I've kept the p1.y = 0 because it looks real
| |
39 p1.x = 50; | |
40 p1.y = 0; | |
41 MotionEvent.PointerCoords[] pointerCoords = {p0, p1}; | |
42 MotionEvent event = MotionEvent.obtain(eventTime, eventTime, | |
43 MotionEvent.ACTION_POINTER_DOWN, 2, mPointers, pointerCoords, 0, 0, 1, 1, 0, 0, | |
44 InputDevice.SOURCE_TOUCHSCREEN , 0); | |
45 mDetector.onTouchEvent(event); | |
46 assertFalse(mDetector.isSwiping()); | |
47 assertFalse(mDetector.isPinching()); | |
48 | |
49 // Any distance greater than the touch-slop threshold should work. | |
50 p0.y += 100; | |
51 p1.y += 100; | |
52 | |
53 event = MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_MOVE , 2, mPointers, | |
54 pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN , 0); | |
55 mDetector.onTouchEvent(event); | |
56 assertTrue(mDetector.isSwiping()); | |
57 assertFalse(mDetector.isPinching()); | |
58 } | |
59 } | |
OLD | NEW |