From 5e3e3a9e4955653b835b55a3a2d4a3daad9ef1e0 Mon Sep 17 00:00:00 2001 From: "lambroslambrou@chromium.org" Date: Fri, 20 Dec 2013 10:32:24 +0000 Subject: Add unit instrumentation tests for Chromoting Android code. This adds a new GYP target for building Java unittests for Chromoting, including a simple unittest example. BUG=322095 Review URL: https://codereview.chromium.org/115953003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@242060 0039d316-1c4b-4281-b951-d872f2087c98 --- remoting/android/javatests/AndroidManifest.xml | 22 +++++++++ .../chromoting/SwipePinchDetectorTest.java | 57 ++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 remoting/android/javatests/AndroidManifest.xml create mode 100644 remoting/android/javatests/src/org/chromium/chromoting/SwipePinchDetectorTest.java (limited to 'remoting/android') diff --git a/remoting/android/javatests/AndroidManifest.xml b/remoting/android/javatests/AndroidManifest.xml new file mode 100644 index 0000000..b57228c --- /dev/null +++ b/remoting/android/javatests/AndroidManifest.xml @@ -0,0 +1,22 @@ + + + + + + + + + + + + + diff --git a/remoting/android/javatests/src/org/chromium/chromoting/SwipePinchDetectorTest.java b/remoting/android/javatests/src/org/chromium/chromoting/SwipePinchDetectorTest.java new file mode 100644 index 0000000..1deee92 --- /dev/null +++ b/remoting/android/javatests/src/org/chromium/chromoting/SwipePinchDetectorTest.java @@ -0,0 +1,57 @@ +// Copyright 2013 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +package org.chromium.chromoting; + +import android.os.SystemClock; +import android.test.InstrumentationTestCase; +import android.test.suitebuilder.annotation.SmallTest; +import android.view.InputDevice; +import android.view.MotionEvent; + +import org.chromium.base.test.util.Feature; + +/** Tests for {@link SwipePinchDetector}. */ +public class SwipePinchDetectorTest extends InstrumentationTestCase { + private SwipePinchDetector mDetector; + private MotionEvent.PointerProperties[] mPointers; + + @Override + public void setUp() { + mDetector = new SwipePinchDetector(getInstrumentation().getTargetContext()); + MotionEvent.PointerProperties pointer0 = new MotionEvent.PointerProperties(); + pointer0.id = 0; + MotionEvent.PointerProperties pointer1 = new MotionEvent.PointerProperties(); + pointer1.id = 1; + mPointers = new MotionEvent.PointerProperties[] {pointer0, pointer1}; + } + + /** Verify that a simple swipe gesture is recognized as a swipe. */ + @SmallTest + @Feature({"Chromoting"}) + public void testSwipeRecognition() throws Exception { + final long eventTime = SystemClock.uptimeMillis(); + MotionEvent.PointerCoords p0 = new MotionEvent.PointerCoords(); + MotionEvent.PointerCoords p1 = new MotionEvent.PointerCoords(); + p1.x = 50; + p1.y = 0; + MotionEvent.PointerCoords[] pointerCoords = {p0, p1}; + MotionEvent event = MotionEvent.obtain(eventTime, eventTime, + MotionEvent.ACTION_POINTER_DOWN, 2, mPointers, pointerCoords, 0, 0, 1, 1, 0, 0, + InputDevice.SOURCE_TOUCHSCREEN , 0); + mDetector.onTouchEvent(event); + assertFalse(mDetector.isSwiping()); + assertFalse(mDetector.isPinching()); + + // Any distance greater than the touch-slop threshold should work. + p0.y += 100; + p1.y += 100; + + event = MotionEvent.obtain(eventTime, eventTime, MotionEvent.ACTION_MOVE, 2, mPointers, + pointerCoords, 0, 0, 1, 1, 0, 0, InputDevice.SOURCE_TOUCHSCREEN , 0); + mDetector.onTouchEvent(event); + assertTrue(mDetector.isSwiping()); + assertFalse(mDetector.isPinching()); + } +} -- cgit v1.1