CTS changes to match those made to a11y api.
Change-Id: I6729bbc93586c8379af0d2b34c8457065be49daf
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
index 2a17486..52af854 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/AccessibilityGestureDispatchTest.java
@@ -17,16 +17,19 @@
import android.accessibilityservice.AccessibilityService;
import android.accessibilityservice.AccessibilityServiceInfo;
import android.accessibilityservice.GestureDescription;
+import android.accessibilityservice.GestureDescription.Builder;
+import android.accessibilityservice.GestureDescription.StrokeDescription;
import android.app.UiAutomation;
import android.content.ContentResolver;
import android.content.Context;
+import android.graphics.Matrix;
+import android.graphics.Path;
import android.graphics.Rect;
import android.os.Bundle;
import android.os.ParcelFileDescriptor;
import android.os.SystemClock;
import android.provider.Settings;
import android.test.ActivityInstrumentationTestCase2;
-import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.ViewConfiguration;
@@ -96,7 +99,7 @@
final int clickYInsideView = 20;
int clickX = clickXInsideView + mViewBounds.left;
int clickY = clickYInsideView + mViewBounds.top;
- GestureDescription click = GestureDescription.createClick(clickX, clickY);
+ GestureDescription click = createClick(clickX, clickY);
assertTrue(StubGestureAccessibilityService.sConnectedInstance
.doDispatchGesture(click, mCallback, null));
mCallback.assertGestureCompletes(GESTURE_COMPLETION_TIMEOUT);
@@ -144,7 +147,7 @@
final int clickYInsideView = 20;
int clickX = clickXInsideView + mViewBounds.left;
int clickY = clickYInsideView + mViewBounds.top;
- GestureDescription longClick = GestureDescription.createLongClick(clickX, clickY);
+ GestureDescription longClick = createLongClick(clickX, clickY);
assertTrue(StubGestureAccessibilityService.sConnectedInstance
.doDispatchGesture(longClick, mCallback, null));
mCallback.assertGestureCompletes(
@@ -186,8 +189,7 @@
int gestureTime = 500;
float swipeTolerance = 2.0f;
- GestureDescription swipe = GestureDescription
- .createSwipe(startX, startY, endX, endY, gestureTime);
+ GestureDescription swipe = createSwipe(startX, startY, endX, endY, gestureTime);
assertTrue(StubGestureAccessibilityService.sConnectedInstance
.doDispatchGesture(swipe, mCallback, null));
mCallback.assertGestureCompletes(gestureTime + GESTURE_COMPLETION_TIMEOUT);
@@ -231,8 +233,7 @@
int endY = endYInsideView + mViewBounds.top;
int gestureTime = 1000;
- GestureDescription swipe = GestureDescription
- .createSwipe(startX, startY, endX, endY, gestureTime);
+ GestureDescription swipe = createSwipe(startX, startY, endX, endY, gestureTime);
assertTrue(StubGestureAccessibilityService.sConnectedInstance
.doDispatchGesture(swipe, mCallback, null));
mCallback.assertGestureCompletes(gestureTime + GESTURE_COMPLETION_TIMEOUT);
@@ -269,7 +270,7 @@
int gestureTime = 500;
float pinchTolerance = 2.0f;
- GestureDescription pinch = GestureDescription.createPinch(centerX, centerY, startSpacing,
+ GestureDescription pinch = createPinch(centerX, centerY, startSpacing,
endSpacing, 45.0F, gestureTime);
assertTrue(StubGestureAccessibilityService.sConnectedInstance
.doDispatchGesture(pinch, mCallback, null));
@@ -481,4 +482,84 @@
}
}
}
+
+ private GestureDescription createClick(int x, int y) {
+ Path clickPath = new Path();
+ clickPath.moveTo(x, y);
+ clickPath.lineTo(x + 1, y);
+ GestureDescription.StrokeDescription clickStroke =
+ new GestureDescription.StrokeDescription(clickPath, 0, ViewConfiguration.getTapTimeout());
+ GestureDescription.Builder clickBuilder = new GestureDescription.Builder();
+ clickBuilder.addStroke(clickStroke);
+ return clickBuilder.build();
+ }
+
+ private GestureDescription createLongClick(int x, int y) {
+ Path clickPath = new Path();
+ clickPath.moveTo(x, y);
+ clickPath.lineTo(x + 1, y);
+ int longPressTime = ViewConfiguration.getLongPressTimeout();
+
+ GestureDescription.StrokeDescription longClickStroke =
+ new GestureDescription.StrokeDescription(clickPath, 0, longPressTime + (longPressTime / 2));
+ GestureDescription.Builder longClickBuilder = new GestureDescription.Builder();
+ longClickBuilder.addStroke(longClickStroke);
+ return longClickBuilder.build();
+ }
+
+ private GestureDescription createSwipe(
+ int startX, int startY, int endX, int endY, long duration) {
+ Path swipePath = new Path();
+ swipePath.moveTo(startX, startY);
+ swipePath.lineTo(endX, endY);
+
+ GestureDescription.StrokeDescription swipeStroke = new GestureDescription.StrokeDescription(swipePath, 0, duration);
+ GestureDescription.Builder swipeBuilder = new GestureDescription.Builder();
+ swipeBuilder.addStroke(swipeStroke);
+ return swipeBuilder.build();
+ }
+
+ private GestureDescription createPinch(int centerX, int centerY, int startSpacing,
+ int endSpacing, float orientation, long duration) {
+ if ((startSpacing < 0) || (endSpacing < 0)) {
+ throw new IllegalArgumentException("Pinch spacing cannot be negative");
+ }
+ float[] startPoint1 = new float[2];
+ float[] endPoint1 = new float[2];
+ float[] startPoint2 = new float[2];
+ float[] endPoint2 = new float[2];
+
+ /* Build points for a horizontal gesture centered at the origin */
+ startPoint1[0] = startSpacing / 2;
+ startPoint1[1] = 0;
+ endPoint1[0] = endSpacing / 2;
+ endPoint1[1] = 0;
+ startPoint2[0] = -startSpacing / 2;
+ startPoint2[1] = 0;
+ endPoint2[0] = -endSpacing / 2;
+ endPoint2[1] = 0;
+
+ /* Rotate and translate the points */
+ Matrix matrix = new Matrix();
+ matrix.setRotate(orientation);
+ matrix.postTranslate(centerX, centerY);
+ matrix.mapPoints(startPoint1);
+ matrix.mapPoints(endPoint1);
+ matrix.mapPoints(startPoint2);
+ matrix.mapPoints(endPoint2);
+
+ Path path1 = new Path();
+ path1.moveTo(startPoint1[0], startPoint1[1]);
+ path1.lineTo(endPoint1[0], endPoint1[1]);
+ Path path2 = new Path();
+ path2.moveTo(startPoint2[0], startPoint2[1]);
+ path2.lineTo(endPoint2[0], endPoint2[1]);
+
+ GestureDescription.StrokeDescription path1Stroke = new GestureDescription.StrokeDescription(path1, 0, duration);
+ GestureDescription.StrokeDescription path2Stroke = new GestureDescription.StrokeDescription(path2, 0, duration);
+ GestureDescription.Builder swipeBuilder = new GestureDescription.Builder();
+ swipeBuilder.addStroke(path1Stroke);
+ swipeBuilder.addStroke(path2Stroke);
+ return swipeBuilder.build();
+ }
}
diff --git a/tests/accessibilityservice/src/android/accessibilityservice/cts/GestureDescriptionTest.java b/tests/accessibilityservice/src/android/accessibilityservice/cts/GestureDescriptionTest.java
index b696cba..b3fa9d2 100644
--- a/tests/accessibilityservice/src/android/accessibilityservice/cts/GestureDescriptionTest.java
+++ b/tests/accessibilityservice/src/android/accessibilityservice/cts/GestureDescriptionTest.java
@@ -119,7 +119,7 @@
public void testAddStroke_allowUpToMaxPaths() {
GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
- for (int i = 0; i < GestureDescription.MAX_STROKE_COUNT; i++) {
+ for (int i = 0; i < GestureDescription.getMaxStrokeCount(); i++) {
Path path = new Path();
path.moveTo(i, i);
path.lineTo(10 + i, 10 + i);
@@ -144,7 +144,7 @@
GestureDescription.Builder gestureBuilder = new GestureDescription.Builder();
try {
gestureBuilder.addStroke(new GestureDescription.StrokeDescription(
- path, 0, GestureDescription.MAX_GESTURE_DURATION_MS + 1));
+ path, 0, GestureDescription.getMaxGestureDuration() + 1));
fail("Missing exception for adding stroke with duration too long.");
} catch (RuntimeException e) {
}
@@ -159,151 +159,6 @@
}
}
-
- public void testClickAt_negativeX_shouldThrow() {
- try {
- GestureDescription.createClick(-1, 0);
- fail("Missing exception for clicking at negative x coordinate.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testClickAt_negativeY_shouldThrow() {
- try {
- GestureDescription.createClick(0, -1);
- fail("Missing exception for clicking at negative y coordinate.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testLongClickAt_negativeX_shouldThrow() {
- try {
- GestureDescription.createLongClick(-1, 0);
- fail("Missing exception for long clicking at negative x coordinate.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testLongClickAt_negativeY_shouldThrow() {
- try {
- GestureDescription.createLongClick(0, -1);
- fail("Missing exception for long clicking at negative y coordinate.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testZeroDurationSwipe_shouldThrow() {
- try {
- GestureDescription.createSwipe(0, 0, 100, 100, 0);
- fail("Missing exception for creating zero duration swipe.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testNegativeDurationSwipe_shouldThrow() {
- try {
- GestureDescription.createSwipe(0, 0, 100, 100, -1);
- fail("Missing exception for creating negative duration swipe.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testZeroLengthSwipe_shouldThrow() {
- try {
- GestureDescription.createSwipe(0, 0, 0, 0, 10);
- fail("Missing exception for creating zero-length swipe.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testSwipe_negativeStartX_shouldThrow() {
- try {
- GestureDescription.createSwipe(-1, 0, 0, 0, 10);
- fail("Missing exception for creating swipe with negative starting x.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testSwipe_negativeStartY_shouldThrow() {
- try {
- GestureDescription.createSwipe(0, -1, 0, 0, 10);
- fail("Missing exception for creating swipe with negative starting y.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testSwipe_negativeEndX_shouldThrow() {
- try {
- GestureDescription.createSwipe(0, 0, -1, 0, 10);
- fail("Missing exception for creating swipe with negative ending x.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testSwipe_negativeEndY_shouldThrow() {
- try {
- GestureDescription.createSwipe(0, 0, 0, -1, 10);
- fail("Missing exception for creating swipe with negative ending y.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testZeroDurationPinch_shouldBeNull() {
- try {
- GestureDescription.createPinch(100, 100, 50, 75, 0, 0);
- fail("Missing exception for creating pinch with zero duration.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testNegativeDurationPinch_shouldBeNull() {
- try {
- GestureDescription.createPinch(100, 100, 50, 75, 0, -1);
- fail("Missing exception for creating pinch with negative duration.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testZeroLengthPinch_shouldThrow() {
- try {
- GestureDescription.createPinch(100, 100, 50, 50, 0, 100);
- fail("Missing exception for creating pinch with zero length.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testPinch_negativeCenterX_shouldThrow() {
- try {
- GestureDescription.createPinch(-100, 100, 50, 75, 0, 100);
- fail("Missing exception for creating pinch with negative center x.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testPinch_negativeCenterY_shouldThrow() {
- try {
- GestureDescription.createPinch(100, -100, 50, 75, 0, 100);
- fail("Missing exception for creating pinch with negative center y.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testPinch_negativeStartSpacing_shouldThrow() {
- try {
- GestureDescription.createPinch(100, 100, -50, 75, 0, 100);
- fail("Missing exception for creating pinch with negative start spacing.");
- } catch (IllegalArgumentException e) {
- }
- }
-
- public void testPinch_negativeEndSpacing_shouldThrow() {
- try {
- GestureDescription.createPinch(100, 100, 50, -75, 0, 100);
- fail("Missing exception for creating pinch with negative end spacing.");
- } catch (IllegalArgumentException e) {
- }
- }
-
public void testStrokeDescriptionGetters_workAsExpected() {
int x = 100;
int startY = 100;