diff options
author | Maurice Lam <yukl@google.com> | 2018-04-06 14:27:41 -0700 |
---|---|---|
committer | Maurice Lam <yukl@google.com> | 2018-04-06 14:33:22 -0700 |
commit | e58194099d9133ce7b2e19fe7c717679b62fddb2 (patch) | |
tree | d2d7c1d8bf6b97d6ff16f5504a472f6249cfa52c /library/test/robotest | |
parent | a6d66b41b08b2d612da1a3e27c651053ceb7a871 (diff) | |
download | setupwizard-e58194099d9133ce7b2e19fe7c717679b62fddb2.tar.gz |
Revert "Revert "Add workaround for touch event propagation""
This reverts commit b268a8c365a4c9dcb7b1382a7ce3ec5607b22de0.
Rolling forward with suppress for the lint errors
Test: ./gradlew lint
Bug: 77338508
Change-Id: I9582bfbb4c73ae60a15e8285facf20da458b9690
Diffstat (limited to 'library/test/robotest')
-rw-r--r-- | library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java b/library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java index 2e28b48..f77de68 100644 --- a/library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java +++ b/library/test/robotest/src/com/android/setupwizardlib/view/RichTextViewTest.java @@ -16,11 +16,14 @@ package com.android.setupwizardlib.view; +import static com.google.common.truth.Truth.assertThat; + import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertSame; import static org.junit.Assert.assertTrue; import static org.mockito.Matchers.eq; +import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.spy; import static org.mockito.Mockito.verify; @@ -35,10 +38,12 @@ import android.text.Annotation; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.TextAppearanceSpan; +import android.view.MotionEvent; import com.android.setupwizardlib.robolectric.SuwLibRobolectricTestRunner; import com.android.setupwizardlib.span.LinkSpan; import com.android.setupwizardlib.span.LinkSpan.OnLinkClickListener; +import com.android.setupwizardlib.view.TouchableMovementMethod.TouchableLinkMovementMethod; import org.junit.Test; import org.junit.runner.RunWith; @@ -62,6 +67,8 @@ public class RichTextViewTest { final CharSequence text = textView.getText(); assertTrue("Text should be spanned", text instanceof Spanned); + assertThat(textView.getMovementMethod()).isInstanceOf(TouchableLinkMovementMethod.class); + Object[] spans = ((Spanned) text).getSpans(0, text.length(), Annotation.class); assertEquals("Annotation should be removed " + Arrays.toString(spans), 0, spans.length); @@ -112,6 +119,44 @@ public class RichTextViewTest { } @Test + public void onTouchEvent_clickOnLinks_shouldReturnTrue() { + Annotation link = new Annotation("link", "foobar"); + SpannableStringBuilder ssb = new SpannableStringBuilder("Hello world"); + ssb.setSpan(link, 0, 2, 0 /* flags */); + + RichTextView textView = new RichTextView(application); + textView.setText(ssb); + + TouchableLinkMovementMethod mockMovementMethod = mock(TouchableLinkMovementMethod.class); + textView.setMovementMethod(mockMovementMethod); + + MotionEvent motionEvent = + MotionEvent.obtain(123, 22, MotionEvent.ACTION_DOWN, 0, 0, 0); + doReturn(motionEvent).when(mockMovementMethod).getLastTouchEvent(); + doReturn(true).when(mockMovementMethod).isLastTouchEventHandled(); + assertThat(textView.onTouchEvent(motionEvent)).isTrue(); + } + + @Test + public void onTouchEvent_clickOutsideLinks_shouldReturnFalse() { + Annotation link = new Annotation("link", "foobar"); + SpannableStringBuilder ssb = new SpannableStringBuilder("Hello world"); + ssb.setSpan(link, 0, 2, 0 /* flags */); + + RichTextView textView = new RichTextView(application); + textView.setText(ssb); + + TouchableLinkMovementMethod mockMovementMethod = mock(TouchableLinkMovementMethod.class); + textView.setMovementMethod(mockMovementMethod); + + MotionEvent motionEvent = + MotionEvent.obtain(123, 22, MotionEvent.ACTION_DOWN, 0, 0, 0); + doReturn(motionEvent).when(mockMovementMethod).getLastTouchEvent(); + doReturn(false).when(mockMovementMethod).isLastTouchEventHandled(); + assertThat(textView.onTouchEvent(motionEvent)).isFalse(); + } + + @Test public void testTextStyle() { Annotation link = new Annotation("textAppearance", "foobar"); SpannableStringBuilder ssb = new SpannableStringBuilder("Hello world"); |