diff options
| author | 2015-12-02 15:02:05 -0800 | |
|---|---|---|
| committer | 2015-12-02 15:02:05 -0800 | |
| commit | 5f71b5afe83ea6a183a9a010c05ce4e1453e264b (patch) | |
| tree | b96a08096475bba1b53b5003938b4597350cf84b | |
| parent | a9292a24c0978c133a30c701b149d0149728b866 (diff) | |
Make drag handle tests stable.
The center position of a drag handle can be outside of the
screen. In such cases, selection handle tests can be failed.
Changed to drag the visible position to deal with it.
Bug: 25730231
Change-Id: Id9270fc03d0f39041f243c9e9d17deca19925e09
| -rw-r--r-- | core/tests/coretests/src/android/widget/espresso/TextViewActions.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/core/tests/coretests/src/android/widget/espresso/TextViewActions.java b/core/tests/coretests/src/android/widget/espresso/TextViewActions.java index 63e310e8af5c..32cc6d648556 100644 --- a/core/tests/coretests/src/android/widget/espresso/TextViewActions.java +++ b/core/tests/coretests/src/android/widget/espresso/TextViewActions.java @@ -315,9 +315,25 @@ public final class TextViewActions { (new TextCoordinates(mIndex)).calculateCoordinates(mTextView); final Rect bounds = new Rect(); view.getBoundsOnScreen(bounds); - final float diffX = bounds.centerX() - currentCoordinates[0]; + final Rect visibleDisplayBounds = new Rect(); + mTextView.getWindowVisibleDisplayFrame(visibleDisplayBounds); + visibleDisplayBounds.right -= 1; + visibleDisplayBounds.bottom -= 1; + if (!visibleDisplayBounds.intersect(bounds)) { + throw new PerformException.Builder() + .withActionDescription(mActionDescription + + " The handle is entirely out of the visible display frame of" + + "the TextView's window.") + .withViewDescription(HumanReadables.describe(view)) + .build(); + } + final float dragPointX = Math.max(Math.min(bounds.centerX(), + visibleDisplayBounds.right), visibleDisplayBounds.left); + final float diffX = dragPointX - currentCoordinates[0]; final float verticalOffset = bounds.height() * 0.7f; - float diffY = bounds.top + verticalOffset - currentCoordinates[1]; + final float dragPointY = Math.max(Math.min(bounds.top + verticalOffset, + visibleDisplayBounds.bottom), visibleDisplayBounds.top); + float diffY = dragPointY - currentCoordinates[1]; if (currentLine > targetLine) { diffY -= mTextView.getLineHeight() * LINE_SLOP_MULTIPLIER; } else if (currentLine < targetLine) { |