• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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;
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
setUp()21     public void setUp() {
22         mDetector = new SwipePinchDetector(getInstrumentation().getTargetContext());
23         MotionEvent.PointerProperties pointer0 = new MotionEvent.PointerProperties();
24         pointer0.id = 0;
25         MotionEvent.PointerProperties pointer1 = new MotionEvent.PointerProperties();
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"})
testSwipeRecognition()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         p1.x = 50;
38         p1.y = 0;
39         MotionEvent.PointerCoords[] pointerCoords = {p0, p1};
40         MotionEvent event = MotionEvent.obtain(eventTime, eventTime,
41                 MotionEvent.ACTION_POINTER_DOWN, 2, mPointers, pointerCoords, 0, 0, 1, 1, 0, 0,
42                 InputDevice.SOURCE_TOUCHSCREEN , 0);
43         mDetector.onTouchEvent(event);
44         assertFalse(mDetector.isSwiping());
45         assertFalse(mDetector.isPinching());
46 
47         // Any distance greater than the touch-slop threshold should work.
48         p0.y += 100;
49         p1.y += 100;
50 
51         event = MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_MOVE, 2, mPointers,
52                 pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN , 0);
53         mDetector.onTouchEvent(event);
54         assertTrue(mDetector.isSwiping());
55         assertFalse(mDetector.isPinching());
56     }
57 }
58