summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Treehugger Robot <android-test-infra-autosubmit@system.gserviceaccount.com> 2024-03-22 19:59:41 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2024-03-22 19:59:41 +0000
commitc59d69f394910984def664d00b151019e6d8cd5e (patch)
treebc4d3ecfcccae2d633774bf4adf0cac82df7fde2
parent06acd760f91f50efec9c491cb0b644cfff6b2e5a (diff)
parenta4ec543fdcec1777fd5929c48edec6fbd0c15575 (diff)
Merge "Fix tests for handwriting initiator changes" into main
-rw-r--r--core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java10
-rw-r--r--core/tests/coretests/src/android/view/stylus/HandwritingTestUtil.java78
2 files changed, 58 insertions, 30 deletions
diff --git a/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java b/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java
index faad472d4ad6..365f3bfb1873 100644
--- a/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java
+++ b/core/tests/coretests/src/android/view/stylus/HandwritingInitiatorTest.java
@@ -21,7 +21,7 @@ import static android.view.MotionEvent.ACTION_HOVER_MOVE;
import static android.view.MotionEvent.ACTION_MOVE;
import static android.view.MotionEvent.ACTION_UP;
import static android.view.inputmethod.Flags.initiationWithoutInputConnection;
-import static android.view.stylus.HandwritingTestUtil.createView;
+import static android.view.stylus.HandwritingTestUtil.createEditText;
import static com.android.text.flags.Flags.handwritingCursorPosition;
@@ -112,13 +112,13 @@ public class HandwritingInitiatorTest {
mHandwritingInitiator =
spy(new HandwritingInitiator(viewConfiguration, inputMethodManager));
- mTestView1 = createView(sHwArea1, /* autoHandwritingEnabled= */ true,
+ mTestView1 = createEditText(sHwArea1, /* autoHandwritingEnabled= */ true,
/* isStylusHandwritingAvailable= */ true,
HW_BOUNDS_OFFSETS_LEFT_PX,
HW_BOUNDS_OFFSETS_TOP_PX,
HW_BOUNDS_OFFSETS_RIGHT_PX,
HW_BOUNDS_OFFSETS_BOTTOM_PX);
- mTestView2 = createView(sHwArea2, /* autoHandwritingEnabled= */ true,
+ mTestView2 = createEditText(sHwArea2, /* autoHandwritingEnabled= */ true,
/* isStylusHandwritingAvailable= */ true,
HW_BOUNDS_OFFSETS_LEFT_PX,
HW_BOUNDS_OFFSETS_TOP_PX,
@@ -412,7 +412,7 @@ public class HandwritingInitiatorTest {
@Test
public void onTouchEvent_notStartHandwriting_whenHandwritingNotAvailable() {
final Rect rect = new Rect(600, 600, 900, 900);
- final View testView = createView(rect, true /* autoHandwritingEnabled */,
+ final View testView = createEditText(rect, true /* autoHandwritingEnabled */,
false /* isStylusHandwritingAvailable */);
mHandwritingInitiator.updateHandwritingAreasForView(testView);
@@ -717,7 +717,7 @@ public class HandwritingInitiatorTest {
mTestView1.setHandwritingDelegatorCallback(null);
onEditorFocusedOrConnectionCreated(mTestView1);
} else {
- View mockView = createView(sHwArea1, false /* autoHandwritingEnabled */,
+ View mockView = createEditText(sHwArea1, false /* autoHandwritingEnabled */,
true /* isStylusHandwritingAvailable */);
onEditorFocusedOrConnectionCreated(mockView);
}
diff --git a/core/tests/coretests/src/android/view/stylus/HandwritingTestUtil.java b/core/tests/coretests/src/android/view/stylus/HandwritingTestUtil.java
index 3b2ab4c8bb50..2c3ee340cd74 100644
--- a/core/tests/coretests/src/android/view/stylus/HandwritingTestUtil.java
+++ b/core/tests/coretests/src/android/view/stylus/HandwritingTestUtil.java
@@ -33,26 +33,63 @@ import android.widget.EditText;
import androidx.test.platform.app.InstrumentationRegistry;
-public class HandwritingTestUtil {
- public static EditText createView(Rect handwritingArea) {
+class HandwritingTestUtil {
+ static View createView(Rect handwritingArea) {
return createView(handwritingArea, true /* autoHandwritingEnabled */,
true /* isStylusHandwritingAvailable */);
}
- public static EditText createView(Rect handwritingArea, boolean autoHandwritingEnabled,
+ static View createView(Rect handwritingArea, boolean autoHandwritingEnabled,
boolean isStylusHandwritingAvailable) {
return createView(handwritingArea, autoHandwritingEnabled, isStylusHandwritingAvailable,
0, 0, 0, 0);
}
- public static EditText createView(Rect handwritingArea, boolean autoHandwritingEnabled,
+ static View createView(Rect handwritingArea, boolean autoHandwritingEnabled,
boolean isStylusHandwritingAvailable,
float handwritingBoundsOffsetLeft, float handwritingBoundsOffsetTop,
float handwritingBoundsOffsetRight, float handwritingBoundsOffsetBottom) {
final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
final Context context = instrumentation.getTargetContext();
- // mock a parent so that HandwritingInitiator can get visible rect and hit region.
- final ViewGroup parent = new ViewGroup(context) {
+ View view = spy(new View(context));
+ mockSpy(view, handwritingArea, autoHandwritingEnabled, isStylusHandwritingAvailable,
+ handwritingBoundsOffsetLeft, handwritingBoundsOffsetTop,
+ handwritingBoundsOffsetRight, handwritingBoundsOffsetBottom);
+ return view;
+ }
+
+ static EditText createEditText(Rect handwritingArea, boolean autoHandwritingEnabled,
+ boolean isStylusHandwritingAvailable) {
+ return createEditText(handwritingArea, autoHandwritingEnabled, isStylusHandwritingAvailable,
+ 0, 0, 0, 0);
+ }
+
+ static EditText createEditText(Rect handwritingArea, boolean autoHandwritingEnabled,
+ boolean isStylusHandwritingAvailable,
+ float handwritingBoundsOffsetLeft, float handwritingBoundsOffsetTop,
+ float handwritingBoundsOffsetRight, float handwritingBoundsOffsetBottom) {
+ final Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();
+ final Context context = instrumentation.getTargetContext();
+ EditText view = spy(new EditText(context));
+ doAnswer(invocation -> {
+ int[] outLocation = invocation.getArgument(0);
+ outLocation[0] = handwritingArea.left;
+ outLocation[1] = handwritingArea.top;
+ return null;
+ }).when(view).getLocationInWindow(any());
+ when(view.getOffsetForPosition(anyFloat(), anyFloat())).thenReturn(0);
+ mockSpy(view, handwritingArea, autoHandwritingEnabled, isStylusHandwritingAvailable,
+ handwritingBoundsOffsetLeft, handwritingBoundsOffsetTop,
+ handwritingBoundsOffsetRight, handwritingBoundsOffsetBottom);
+ return view;
+ }
+
+ private static void mockSpy(View viewSpy, Rect handwritingArea,
+ boolean autoHandwritingEnabled, boolean isStylusHandwritingAvailable,
+ float handwritingBoundsOffsetLeft, float handwritingBoundsOffsetTop,
+ float handwritingBoundsOffsetRight, float handwritingBoundsOffsetBottom) {
+ // Mock a parent so that HandwritingInitiator can get visible rect and hit region.
+ final ViewGroup parent = new ViewGroup(viewSpy.getContext()) {
@Override
protected void onLayout(boolean changed, int l, int t, int r, int b) {
// We don't layout this view.
@@ -72,24 +109,15 @@ public class HandwritingTestUtil {
}
};
- EditText view = spy(new EditText(context));
- when(view.isAttachedToWindow()).thenReturn(true);
- when(view.isAggregatedVisible()).thenReturn(true);
- when(view.isStylusHandwritingAvailable()).thenReturn(isStylusHandwritingAvailable);
- when(view.getHandwritingArea()).thenReturn(handwritingArea);
- when(view.getHandwritingBoundsOffsetLeft()).thenReturn(handwritingBoundsOffsetLeft);
- when(view.getHandwritingBoundsOffsetTop()).thenReturn(handwritingBoundsOffsetTop);
- when(view.getHandwritingBoundsOffsetRight()).thenReturn(handwritingBoundsOffsetRight);
- when(view.getHandwritingBoundsOffsetBottom()).thenReturn(handwritingBoundsOffsetBottom);
- doAnswer(invocation -> {
- int[] outLocation = invocation.getArgument(0);
- outLocation[0] = handwritingArea.left;
- outLocation[1] = handwritingArea.top;
- return null;
- }).when(view).getLocationInWindow(any());
- when(view.getOffsetForPosition(anyFloat(), anyFloat())).thenReturn(0);
- view.setAutoHandwritingEnabled(autoHandwritingEnabled);
- parent.addView(view);
- return view;
+ when(viewSpy.isAttachedToWindow()).thenReturn(true);
+ when(viewSpy.isAggregatedVisible()).thenReturn(true);
+ when(viewSpy.isStylusHandwritingAvailable()).thenReturn(isStylusHandwritingAvailable);
+ when(viewSpy.getHandwritingArea()).thenReturn(handwritingArea);
+ when(viewSpy.getHandwritingBoundsOffsetLeft()).thenReturn(handwritingBoundsOffsetLeft);
+ when(viewSpy.getHandwritingBoundsOffsetTop()).thenReturn(handwritingBoundsOffsetTop);
+ when(viewSpy.getHandwritingBoundsOffsetRight()).thenReturn(handwritingBoundsOffsetRight);
+ when(viewSpy.getHandwritingBoundsOffsetBottom()).thenReturn(handwritingBoundsOffsetBottom);
+ viewSpy.setAutoHandwritingEnabled(autoHandwritingEnabled);
+ parent.addView(viewSpy);
}
}