summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorSunny Goyal <sunnygoyal@google.com>2018-09-12 15:47:06 -0700
committerSunny Goyal <sunnygoyal@google.com>2018-09-13 09:50:47 -0700
commit4d8ec15fb51258ffc4d8fc9808756e2e6ea67de0 (patch)
treee28ee06c65c6131fd24996ce38bd990f3b1ff826 /tests
parent05b351dd42072a46bc282707b369c50c2fd5c3e8 (diff)
downloadandroid_packages_apps_Trebuchet-4d8ec15fb51258ffc4d8fc9808756e2e6ea67de0.tar.gz
android_packages_apps_Trebuchet-4d8ec15fb51258ffc4d8fc9808756e2e6ea67de0.tar.bz2
android_packages_apps_Trebuchet-4d8ec15fb51258ffc4d8fc9808756e2e6ea67de0.zip
Using velocity tracker for computing the velocity of motion events
Change-Id: I14f2f970825a2936f4bb285834405d67daf8667c
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/touch/SwipeDetectorTest.java39
1 files changed, 21 insertions, 18 deletions
diff --git a/tests/src/com/android/launcher3/touch/SwipeDetectorTest.java b/tests/src/com/android/launcher3/touch/SwipeDetectorTest.java
index 73b6dafd1..b600473d4 100644
--- a/tests/src/com/android/launcher3/touch/SwipeDetectorTest.java
+++ b/tests/src/com/android/launcher3/touch/SwipeDetectorTest.java
@@ -19,7 +19,6 @@ import androidx.test.InstrumentationRegistry;
import androidx.test.filters.SmallTest;
import androidx.test.runner.AndroidJUnit4;
import android.util.Log;
-import android.view.MotionEvent;
import android.view.ViewConfiguration;
import com.android.launcher3.testcomponent.TouchEventGenerator;
@@ -32,6 +31,7 @@ import org.mockito.MockitoAnnotations;
import static org.mockito.Matchers.anyBoolean;
import static org.mockito.Matchers.anyFloat;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -51,25 +51,28 @@ public class SwipeDetectorTest {
@Mock
private SwipeDetector.Listener mMockListener;
+ @Mock
+ private ViewConfiguration mMockConfig;
+
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
- mGenerator = new TouchEventGenerator(new TouchEventGenerator.Listener() {
- @Override
- public void onTouchEvent(MotionEvent event) {
- mDetector.onTouchEvent(event);
- }
- });
-
- mDetector = new SwipeDetector(mTouchSlop, mMockListener, SwipeDetector.VERTICAL);
+ mGenerator = new TouchEventGenerator((ev) -> mDetector.onTouchEvent(ev));
+ ViewConfiguration orgConfig = ViewConfiguration
+ .get(InstrumentationRegistry.getTargetContext());
+ doReturn(orgConfig.getScaledMaximumFlingVelocity()).when(mMockConfig)
+ .getScaledMaximumFlingVelocity();
+
+ mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.VERTICAL);
mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_BOTH, false);
- mTouchSlop = ViewConfiguration.get(InstrumentationRegistry.getTargetContext())
- .getScaledTouchSlop();
+ mTouchSlop = orgConfig.getScaledTouchSlop();
+ doReturn(mTouchSlop).when(mMockConfig).getScaledTouchSlop();
+
L("mTouchSlop=", mTouchSlop);
}
@Test
- public void testDragStart_vertical() throws Exception {
+ public void testDragStart_vertical() {
mGenerator.put(0, 100, 100);
mGenerator.move(0, 100, 100 + mTouchSlop);
// TODO: actually calculate the following parameters and do exact value checks.
@@ -77,7 +80,7 @@ public class SwipeDetectorTest {
}
@Test
- public void testDragStart_failed() throws Exception {
+ public void testDragStart_failed() {
mGenerator.put(0, 100, 100);
mGenerator.move(0, 100 + mTouchSlop, 100);
// TODO: actually calculate the following parameters and do exact value checks.
@@ -85,8 +88,8 @@ public class SwipeDetectorTest {
}
@Test
- public void testDragStart_horizontal() throws Exception {
- mDetector = new SwipeDetector(mTouchSlop, mMockListener, SwipeDetector.HORIZONTAL);
+ public void testDragStart_horizontal() {
+ mDetector = new SwipeDetector(mMockConfig, mMockListener, SwipeDetector.HORIZONTAL);
mDetector.setDetectableScrollConditions(SwipeDetector.DIRECTION_BOTH, false);
mGenerator.put(0, 100, 100);
@@ -96,15 +99,15 @@ public class SwipeDetectorTest {
}
@Test
- public void testDrag() throws Exception {
+ public void testDrag() {
mGenerator.put(0, 100, 100);
mGenerator.move(0, 100, 100 + mTouchSlop);
// TODO: actually calculate the following parameters and do exact value checks.
- verify(mMockListener).onDrag(anyFloat(), anyFloat());
+ verify(mMockListener).onDrag(anyFloat());
}
@Test
- public void testDragEnd() throws Exception {
+ public void testDragEnd() {
mGenerator.put(0, 100, 100);
mGenerator.move(0, 100, 100 + mTouchSlop);
mGenerator.move(0, 100, 100 + mTouchSlop * 2);