diff options
author | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-20 10:32:24 +0000 |
---|---|---|
committer | lambroslambrou@chromium.org <lambroslambrou@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-12-20 10:32:24 +0000 |
commit | 5e3e3a9e4955653b835b55a3a2d4a3daad9ef1e0 (patch) | |
tree | c1500aa3754f7a3ae254b14fc253391bfafa19b6 /remoting/android | |
parent | 830edbed467b7983edbfb867f6ae58c98b5c4ca6 (diff) | |
download | chromium_src-5e3e3a9e4955653b835b55a3a2d4a3daad9ef1e0.zip chromium_src-5e3e3a9e4955653b835b55a3a2d4a3daad9ef1e0.tar.gz chromium_src-5e3e3a9e4955653b835b55a3a2d4a3daad9ef1e0.tar.bz2 |
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
Diffstat (limited to 'remoting/android')
-rw-r--r-- | remoting/android/javatests/AndroidManifest.xml | 22 | ||||
-rw-r--r-- | remoting/android/javatests/src/org/chromium/chromoting/SwipePinchDetectorTest.java | 57 |
2 files changed, 79 insertions, 0 deletions
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 @@ +<?xml version="1.0" encoding="utf-8"?> + <!-- 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 name must be unique so suffix with "tests" so package loader + doesn't ignore this. --> + <manifest xmlns:android="http://schemas.android.com/apk/res/android" + package="org.chromium.chromoting.tests"> + <!-- We add an application tag here just so that we can indicate that this + package needs to link against the android.test library, which is + needed when building test cases. --> + <application> + <uses-library android:name="android.test.runner" /> + </application> + <uses-sdk android:minSdkVersion="14" android:targetSdkVersion="14" /> + <instrumentation android:name="android.test.InstrumentationTestRunner" + android:targetPackage="org.chromium.chromoting" + android:label="Tests for org.chromium.chromoting"/> + <uses-permission android:name="android.permission.RUN_INSTRUMENTATION" /> +</manifest> 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()); + } +} |