AI 148054: CTS: refactor failed cases in package anroid.text.
Automated import of CL 148054
diff --git a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
index ff40589..f0f9627 100644
--- a/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
+++ b/tests/tests/text/src/android/text/cts/StaticLayoutTest.java
@@ -47,6 +47,8 @@
private static final Alignment DEFAULT_ALIGN = Alignment.ALIGN_CENTER;
+ private static final int ELLIPSIZE_WIDTH = 8;
+
private StaticLayout mDefaultLayout;
private TextPaint mDefaultPaint;
@@ -66,13 +68,20 @@
DEFAULT_OUTER_WIDTH, DEFAULT_ALIGN, SPACE_MULTI, SPACE_ADD, true);
}
+ private StaticLayout createEllipsizeStaticLayout() {
+ return new StaticLayout(LAYOUT_TEXT, 0, LAYOUT_TEXT.length(), mDefaultPaint,
+ DEFAULT_OUTER_WIDTH, DEFAULT_ALIGN, SPACE_MULTI, SPACE_ADD, true,
+ TextUtils.TruncateAt.MIDDLE, ELLIPSIZE_WIDTH);
+ }
+
/**
* Constructor test
*/
@TestTargets({
@TestTargetNew(
level = TestLevel.COMPLETE,
- method = "StaticLayout", args = {java.lang.CharSequence.class, int.class, int.class,
+ method = "StaticLayout",
+ args = {java.lang.CharSequence.class, int.class, int.class,
android.text.TextPaint.class, int.class, android.text.Layout.Alignment.class,
float.class, float.class, boolean.class}
),
@@ -353,6 +362,7 @@
@ToBeFixed(bug = "1695243", explanation = "should add @throws clause into javadoc "
+ " of StaticLayout#getEllipsisCount(int) when line is out of bound")
public void testGetEllipsisCount() {
+ mDefaultLayout = createEllipsizeStaticLayout();
assertTrue(mDefaultLayout.getEllipsisCount(0) > 0);
assertTrue(mDefaultLayout.getEllipsisCount(1) > 0);
@@ -382,6 +392,7 @@
@ToBeFixed(bug = "1695243", explanation = "should add @throws clause into javadoc "
+ " of StaticLayout#getEllipsisStart(int) when line is out of bound")
public void testGetEllipsisStart() {
+ mDefaultLayout = createEllipsizeStaticLayout();
assertTrue(mDefaultLayout.getEllipsisStart(0) >= 0);
assertTrue(mDefaultLayout.getEllipsisStart(1) >= 0);
diff --git a/tests/tests/text/src/android/text/method/cts/ArrowKeyMovementMethodTest.java b/tests/tests/text/src/android/text/method/cts/ArrowKeyMovementMethodTest.java
index eb08e7b..a7c55a1 100644
--- a/tests/tests/text/src/android/text/method/cts/ArrowKeyMovementMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ArrowKeyMovementMethodTest.java
@@ -48,25 +48,15 @@
@TestTargetClass(ArrowKeyMovementMethod.class)
public class ArrowKeyMovementMethodTest extends ActivityInstrumentationTestCase2<StubActivity> {
private static final String THREE_LINES_TEXT = "first line\nsecond line\nlast line";
-
private static final int END_OF_ALL_TEXT = THREE_LINES_TEXT.length();
-
private static final int END_OF_1ST_LINE = THREE_LINES_TEXT.indexOf('\n');
-
private static final int START_OF_2ND_LINE = END_OF_1ST_LINE + 1;
-
private static final int END_OF_2ND_LINE = THREE_LINES_TEXT.indexOf('\n', START_OF_2ND_LINE);
-
private static final int START_OF_3RD_LINE = END_OF_2ND_LINE + 1;
-
private static final int SPACE_IN_2ND_LINE = THREE_LINES_TEXT.indexOf(' ', START_OF_2ND_LINE);
-
private TextView mTextView;
-
private ArrowKeyMovementMethod mArrowKeyMovementMethod;
-
private Editable mEditable;
-
private MyMetaKeyKeyListener mMetaListener;
public ArrowKeyMovementMethodTest() {
@@ -140,7 +130,7 @@
)
@ToBeFixed(bug = "1695243", explanation = "Android API javadocs are incomplete. There is no "
+ "document about the behaviour of this method.")
- public void testOnTakeFocus() {
+ public void testOnTakeFocus() throws Throwable {
/*
* The following assertions depend on whether the TextView has a layout.
* The text view will not get layout in setContent method but in other
@@ -151,7 +141,7 @@
* and checking the assertion at last.
*/
assertSelection(-1);
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_DOWN);
}
@@ -159,7 +149,7 @@
getInstrumentation().waitForIdleSync();
assertSelection(END_OF_1ST_LINE);
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
Selection.removeSelection(mEditable);
mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_RIGHT);
@@ -168,7 +158,7 @@
getInstrumentation().waitForIdleSync();
assertSelection(END_OF_1ST_LINE);
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
Selection.removeSelection(mEditable);
mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_UP);
@@ -177,7 +167,7 @@
getInstrumentation().waitForIdleSync();
assertSelection(END_OF_ALL_TEXT);
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
Selection.removeSelection(mEditable);
mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_LEFT);
@@ -186,7 +176,7 @@
getInstrumentation().waitForIdleSync();
assertSelection(END_OF_ALL_TEXT);
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
mTextView.setSingleLine();
}
@@ -196,7 +186,7 @@
assertNotNull(mTextView.getLayout());
assertEquals(1, mTextView.getLayout().getLineCount());
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
Selection.removeSelection(mEditable);
mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_DOWN);
@@ -204,7 +194,7 @@
});
assertSelection(END_OF_ALL_TEXT);
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
Selection.removeSelection(mEditable);
mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_RIGHT);
@@ -212,7 +202,7 @@
});
assertSelection(END_OF_ALL_TEXT);
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
Selection.removeSelection(mEditable);
mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_UP);
@@ -220,7 +210,7 @@
});
assertSelection(END_OF_ALL_TEXT);
- getInstrumentation().runOnMainSync(new Runnable() {
+ runTestOnUiThread(new Runnable() {
public void run() {
Selection.removeSelection(mEditable);
mArrowKeyMovementMethod.onTakeFocus(mTextView, mEditable, View.FOCUS_LEFT);
@@ -716,18 +706,17 @@
@UiThreadTest
@ToBeFixed(bug = "1400249", explanation = "There is a side effect that the "
+ "view scroll while dragging on the screen. Should be tested in functional test.")
- public void testOnTouchEvent() {
+ public void testOnTouchEvent() throws Throwable {
long now = SystemClock.currentThreadTimeMillis();
Selection.setSelection(mEditable, SPACE_IN_2ND_LINE);
- assertTrue(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
+ assertFalse(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 1, 1, 0)));
- assertSelection(0);
+ assertSelection(SPACE_IN_2ND_LINE);
- Selection.setSelection(mEditable, SPACE_IN_2ND_LINE);
- assertTrue(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
+ assertFalse(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 1, 1,
KeyEvent.META_SHIFT_ON)));
- assertSelection(0);
+ assertSelection(SPACE_IN_2ND_LINE);
}
@TestTargetNew(
@@ -747,13 +736,9 @@
mTextView.requestFocus();
assertTrue(mTextView.isFocused());
- try {
- mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
- MotionEvent.obtain(0, 0, MotionEvent.ACTION_UP, 1, 1, 0));
- fail("The method did not throw NullPointerException when param textView is null.");
- } catch (NullPointerException e) {
- // expected
- }
+ long now = SystemClock.currentThreadTimeMillis();
+ assertFalse(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
+ MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 1, 1, 0)));
}
@TestTargetNew(
@@ -769,8 +754,9 @@
public void testOnTouchEventWithoutFocus() {
long now = SystemClock.currentThreadTimeMillis();
Selection.setSelection(mEditable, SPACE_IN_2ND_LINE);
- assertTrue(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
+ assertFalse(mArrowKeyMovementMethod.onTouchEvent(mTextView, mEditable,
MotionEvent.obtain(now, now, MotionEvent.ACTION_UP, 1, 1, 0)));
+ assertSelection(SPACE_IN_2ND_LINE);
}
@TestTargetNew(
diff --git a/tests/tests/text/src/android/text/method/cts/ReplacementTransformationMethodTest.java b/tests/tests/text/src/android/text/method/cts/ReplacementTransformationMethodTest.java
index 4b742dd..07e0164 100644
--- a/tests/tests/text/src/android/text/method/cts/ReplacementTransformationMethodTest.java
+++ b/tests/tests/text/src/android/text/method/cts/ReplacementTransformationMethodTest.java
@@ -33,18 +33,12 @@
@TestTargetClass(ReplacementTransformationMethod.class)
public class ReplacementTransformationMethodTest extends
ActivityInstrumentationTestCase2<StubActivity> {
- private static final char[] ORIGINAL = new char[] { '0', '1' };
-
- private static final char[] ORIGINAL_WITH_MORE_CHARS = new char[] { '0', '1', '2' };
-
- private static final char[] ORIGINAL_WITH_SAME_CHARS = new char[] { '0', '0' };
-
- private static final char[] REPLACEMENT = new char[] { '3', '4' };
-
- private static final char[] REPLACEMENT_WITH_MORE_CHARS = new char[] { '3', '4', '5' };
-
- private static final char[] REPLACEMENT_WITH_SAME_CHARS = new char[] { '3', '3' };
-
+ private final char[] ORIGINAL = new char[] { '0', '1' };
+ private final char[] ORIGINAL_WITH_MORE_CHARS = new char[] { '0', '1', '2' };
+ private final char[] ORIGINAL_WITH_SAME_CHARS = new char[] { '0', '0' };
+ private final char[] REPLACEMENT = new char[] { '3', '4' };
+ private final char[] REPLACEMENT_WITH_MORE_CHARS = new char[] { '3', '4', '5' };
+ private final char[] REPLACEMENT_WITH_SAME_CHARS = new char[] { '3', '3' };
private EditText mEditText;
public ReplacementTransformationMethodTest() {
@@ -162,7 +156,7 @@
method.onFocusChanged(null, null, true, 0, null);
}
- private class MyReplacementTransformationMethod extends ReplacementTransformationMethod {
+ private static class MyReplacementTransformationMethod extends ReplacementTransformationMethod {
private char[] mOriginal;
private char[] mReplacement;