Skip to content

Commit a36a45c

Browse files
jhenningerMalek Naffati
authored andcommitted
DO NOT MERGE
TouchTest: ensure scroll amount is larger than touch slop Test failed when the difference between display and text width was less than the touch slop, which could happen for certain display resolutions. Bug: 299950514 Test: atest android.text.method.cts.TouchTest Change-Id: Idd2d54435c6393331911eb147c3e010ab2fba615
1 parent 2349d44 commit a36a45c

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

tests/tests/text/src/android/text/method/cts/TouchTest.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
import android.util.DisplayMetrics;
3030
import android.util.TypedValue;
3131
import android.view.MotionEvent;
32+
import android.view.ViewConfiguration;
3233
import android.view.ViewGroup;
3334
import android.widget.TextView;
3435

@@ -117,17 +118,18 @@ public void testOnTouchEvent() throws Throwable {
117118
// Create a string that is wider than the screen.
118119
DisplayMetrics metrics = mActivity.getResources().getDisplayMetrics();
119120
int screenWidth = metrics.widthPixels;
121+
int touchSlop = ViewConfiguration.get(mActivity).getScaledTouchSlop();
120122
TextPaint paint = mTextView.getPaint();
121123
String text = LONG_TEXT;
122124
int textWidth = Math.round(paint.measureText(text));
123-
while (textWidth < screenWidth) {
125+
while (textWidth < screenWidth + touchSlop) {
124126
text += LONG_TEXT;
125127
textWidth = Math.round(paint.measureText(text));
126128
}
127129

128130
// Drag the difference between the text width and the screen width.
129131
int dragAmount = Math.min(screenWidth, textWidth - screenWidth);
130-
assertTrue(dragAmount > 0);
132+
assertTrue(dragAmount > touchSlop);
131133
final String finalText = text;
132134
final SpannableString spannable = new SpannableString(finalText);
133135
mActivityRule.runOnUiThread(() -> {

0 commit comments

Comments
 (0)