Merge change 20144 into donut
* changes: Remove flaky MonitorTest#testInterrupt from continuous, and attempt to make AutoCompletePopup tests more reliable.
This commit is contained in:
@@ -267,7 +267,7 @@ public class MonitorTest extends TestCase {
|
||||
private static Throwable errorException;
|
||||
private static Thread testThread;
|
||||
|
||||
@MediumTest
|
||||
// TODO: Flaky test. Add back MediumTest annotation once fixed
|
||||
public void testInterruptTest() throws Exception {
|
||||
|
||||
|
||||
|
||||
@@ -18,65 +18,75 @@ package android.widget;
|
||||
|
||||
import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.FlakyTest;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
|
||||
public class AutoCompleteTextViewCallbacks
|
||||
public class AutoCompleteTextViewCallbacks
|
||||
extends ActivityInstrumentationTestCase2<AutoCompleteTextViewSimple> {
|
||||
|
||||
private static final int WAIT_TIME = 200;
|
||||
|
||||
public AutoCompleteTextViewCallbacks() {
|
||||
super("com.android.frameworktest", AutoCompleteTextViewSimple.class);
|
||||
}
|
||||
|
||||
/** Test that the initial popup of the suggestions does not select anything.
|
||||
*
|
||||
* TODO: test currently fails. Add back MediumTest annotation when fixed.
|
||||
*/
|
||||
public void testPopupNoSelection() {
|
||||
@MediumTest
|
||||
@FlakyTest(tolerance=3)
|
||||
public void testPopupNoSelection() throws Exception {
|
||||
AutoCompleteTextViewSimple theActivity = getActivity();
|
||||
AutoCompleteTextView textView = theActivity.getTextView();
|
||||
final Instrumentation instrumentation = getInstrumentation();
|
||||
|
||||
|
||||
// focus and type
|
||||
textView.requestFocus();
|
||||
instrumentation.waitForIdleSync();
|
||||
sendKeys("A");
|
||||
|
||||
// give UI time to settle
|
||||
Thread.sleep(WAIT_TIME);
|
||||
|
||||
// now check for selection callbacks. Nothing should be clicked or selected.
|
||||
assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
|
||||
assertFalse("onItemSelected should not be called", theActivity.mItemSelectedCalled);
|
||||
|
||||
|
||||
// arguably, this should be "false", because we aren't deselecting - we shouldn't
|
||||
// really be calling it. But it's not the end of the world, and we might wind up
|
||||
// breaking something if we change this.
|
||||
assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled);
|
||||
//assertTrue("onNothingSelected should be called", theActivity.mNothingSelectedCalled);
|
||||
}
|
||||
|
||||
/** Test that arrow-down into the popup calls the onSelected callback */
|
||||
/** Test that arrow-down into the popup calls the onSelected callback. */
|
||||
@MediumTest
|
||||
public void testPopupEnterSelection() {
|
||||
@FlakyTest(tolerance=3)
|
||||
public void testPopupEnterSelection() throws Exception {
|
||||
AutoCompleteTextViewSimple theActivity = getActivity();
|
||||
AutoCompleteTextView textView = theActivity.getTextView();
|
||||
final Instrumentation instrumentation = getInstrumentation();
|
||||
|
||||
|
||||
// focus and type
|
||||
textView.requestFocus();
|
||||
instrumentation.waitForIdleSync();
|
||||
sendKeys("A");
|
||||
|
||||
|
||||
// prepare to move down into the popup
|
||||
theActivity.resetItemListeners();
|
||||
sendKeys("DPAD_DOWN");
|
||||
|
||||
// give UI time to settle
|
||||
Thread.sleep(WAIT_TIME);
|
||||
|
||||
// now check for selection callbacks.
|
||||
assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
|
||||
assertTrue("onItemSelected should be called", theActivity.mItemSelectedCalled);
|
||||
assertEquals("onItemSelected position", 0, theActivity.mItemSelectedPosition);
|
||||
assertFalse("onNothingSelected should not be called", theActivity.mNothingSelectedCalled);
|
||||
|
||||
|
||||
// try one more time - should move from 0 to 1
|
||||
theActivity.resetItemListeners();
|
||||
sendKeys("DPAD_DOWN");
|
||||
|
||||
// give UI time to settle
|
||||
Thread.sleep(WAIT_TIME);
|
||||
|
||||
// now check for selection callbacks.
|
||||
assertFalse("onItemClick should not be called", theActivity.mItemClickCalled);
|
||||
assertTrue("onItemSelected should be called", theActivity.mItemSelectedCalled);
|
||||
@@ -86,19 +96,20 @@ public class AutoCompleteTextViewCallbacks
|
||||
|
||||
/** Test that arrow-up out of the popup calls the onNothingSelected callback */
|
||||
@MediumTest
|
||||
@FlakyTest(tolerance=3)
|
||||
public void testPopupLeaveSelection() {
|
||||
AutoCompleteTextViewSimple theActivity = getActivity();
|
||||
AutoCompleteTextView textView = theActivity.getTextView();
|
||||
final Instrumentation instrumentation = getInstrumentation();
|
||||
|
||||
|
||||
// focus and type
|
||||
textView.requestFocus();
|
||||
instrumentation.waitForIdleSync();
|
||||
sendKeys("A");
|
||||
|
||||
|
||||
// move down into the popup
|
||||
sendKeys("DPAD_DOWN");
|
||||
|
||||
|
||||
// now move back up out of the popup
|
||||
theActivity.resetItemListeners();
|
||||
sendKeys("DPAD_UP");
|
||||
|
||||
@@ -20,6 +20,7 @@ import android.app.Instrumentation;
|
||||
import android.test.ActivityInstrumentationTestCase2;
|
||||
import android.test.FlakyTest;
|
||||
import android.test.suitebuilder.annotation.MediumTest;
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* A collection of tests on aspects of the AutoCompleteTextView's popup
|
||||
@@ -27,26 +28,33 @@ import android.test.suitebuilder.annotation.MediumTest;
|
||||
public class AutoCompleteTextViewPopup
|
||||
extends ActivityInstrumentationTestCase2<AutoCompleteTextViewSimple> {
|
||||
|
||||
// ms to sleep when checking for intermittent UI state
|
||||
private static final int SLEEP_TIME = 50;
|
||||
// number of times to poll when checking expected UI state
|
||||
// total wait time will be LOOP_AMOUNT * SLEEP_TIME
|
||||
private static final int LOOP_AMOUNT = 10;
|
||||
|
||||
|
||||
public AutoCompleteTextViewPopup() {
|
||||
super("com.android.frameworktest", AutoCompleteTextViewSimple.class);
|
||||
}
|
||||
|
||||
|
||||
/** Test that we can move the selection and it responds as expected */
|
||||
@MediumTest
|
||||
@FlakyTest(tolerance=3)
|
||||
public void testPopupSetListSelection() throws Throwable {
|
||||
AutoCompleteTextViewSimple theActivity = getActivity();
|
||||
final AutoCompleteTextView textView = theActivity.getTextView();
|
||||
final Instrumentation instrumentation = getInstrumentation();
|
||||
|
||||
|
||||
// focus and type
|
||||
textView.requestFocus();
|
||||
instrumentation.waitForIdleSync();
|
||||
sendKeys("A");
|
||||
|
||||
|
||||
// No initial selection
|
||||
assertEquals("getListSelection(-1)",
|
||||
ListView.INVALID_POSITION, textView.getListSelection());
|
||||
|
||||
waitAssertListSelection(textView, ListView.INVALID_POSITION);
|
||||
|
||||
// set and check
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
@@ -54,58 +62,64 @@ public class AutoCompleteTextViewPopup
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertEquals("set selection to (0)", 0, textView.getListSelection());
|
||||
|
||||
waitAssertListSelection("set selection to (0)", textView, 0);
|
||||
|
||||
// Use movement to cross-check the movement
|
||||
sendKeys("DPAD_DOWN");
|
||||
assertEquals("move selection to (1)", 1, textView.getListSelection());
|
||||
waitAssertListSelection("move selection to (1)", textView, 1);
|
||||
|
||||
// TODO: FlakyTest repeat runs will not currently call setUp, clear state
|
||||
clearText(textView);
|
||||
}
|
||||
|
||||
|
||||
/** Test that we can look at the selection as we move around */
|
||||
@MediumTest
|
||||
public void testPopupGetListSelection() {
|
||||
@FlakyTest(tolerance=3)
|
||||
public void testPopupGetListSelection() throws Throwable {
|
||||
AutoCompleteTextViewSimple theActivity = getActivity();
|
||||
AutoCompleteTextView textView = theActivity.getTextView();
|
||||
final AutoCompleteTextView textView = theActivity.getTextView();
|
||||
final Instrumentation instrumentation = getInstrumentation();
|
||||
|
||||
|
||||
// focus and type
|
||||
textView.requestFocus();
|
||||
instrumentation.waitForIdleSync();
|
||||
sendKeys("A");
|
||||
|
||||
|
||||
// No initial selection
|
||||
assertEquals("getListSelection(-1)",
|
||||
ListView.INVALID_POSITION, textView.getListSelection());
|
||||
|
||||
waitAssertListSelection(textView, ListView.INVALID_POSITION);
|
||||
|
||||
// check for selection position as expected
|
||||
sendKeys("DPAD_DOWN");
|
||||
assertEquals("move selection to (0)", 0, textView.getListSelection());
|
||||
|
||||
waitAssertListSelection("move selection to (0)", textView, 0);
|
||||
|
||||
// Repeat for one more movement
|
||||
sendKeys("DPAD_DOWN");
|
||||
assertEquals("move selection to (1)", 1, textView.getListSelection());
|
||||
waitAssertListSelection("move selection to (1)", textView, 1);
|
||||
|
||||
// TODO: FlakyTest repeat runs will not currently call setUp, clear state
|
||||
clearText(textView);
|
||||
}
|
||||
|
||||
|
||||
/** Test that we can clear the selection */
|
||||
@MediumTest
|
||||
@FlakyTest(tolerance=3)
|
||||
public void testPopupClearListSelection() throws Throwable {
|
||||
AutoCompleteTextViewSimple theActivity = getActivity();
|
||||
final AutoCompleteTextView textView = theActivity.getTextView();
|
||||
final Instrumentation instrumentation = getInstrumentation();
|
||||
|
||||
|
||||
// focus and type
|
||||
textView.requestFocus();
|
||||
instrumentation.waitForIdleSync();
|
||||
sendKeys("A");
|
||||
|
||||
|
||||
// No initial selection
|
||||
assertEquals("getListSelection(-1)",
|
||||
ListView.INVALID_POSITION, textView.getListSelection());
|
||||
|
||||
waitAssertListSelection(textView, ListView.INVALID_POSITION);
|
||||
|
||||
// check for selection position as expected
|
||||
sendKeys("DPAD_DOWN");
|
||||
assertEquals("getListSelection(0)", 0, textView.getListSelection());
|
||||
|
||||
waitAssertListSelection(textView, 0);
|
||||
|
||||
// clear it
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
@@ -113,12 +127,16 @@ public class AutoCompleteTextViewPopup
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
assertEquals("setListSelection(ListView.INVALID_POSITION)",
|
||||
ListView.INVALID_POSITION, textView.getListSelection());
|
||||
waitAssertListSelection("setListSelection(ListView.INVALID_POSITION)", textView,
|
||||
ListView.INVALID_POSITION);
|
||||
|
||||
// TODO: FlakyTest repeat runs will not currently call setUp, clear state
|
||||
clearText(textView);
|
||||
}
|
||||
|
||||
/** Make sure we handle an empty adapter properly */
|
||||
@MediumTest
|
||||
@FlakyTest(tolerance=3)
|
||||
public void testPopupNavigateNoAdapter() throws Throwable {
|
||||
AutoCompleteTextViewSimple theActivity = getActivity();
|
||||
final AutoCompleteTextView textView = theActivity.getTextView();
|
||||
@@ -130,12 +148,11 @@ public class AutoCompleteTextViewPopup
|
||||
sendKeys("A");
|
||||
|
||||
// No initial selection
|
||||
assertEquals("getListSelection(-1)",
|
||||
ListView.INVALID_POSITION, textView.getListSelection());
|
||||
waitAssertListSelection(textView, ListView.INVALID_POSITION);
|
||||
|
||||
// check for selection position as expected
|
||||
sendKeys("DPAD_DOWN");
|
||||
assertEquals("getListSelection(0)", 0, textView.getListSelection());
|
||||
waitAssertListSelection(textView, 0);
|
||||
|
||||
// Now get rid of the adapter
|
||||
runTestOnUiThread(new Runnable() {
|
||||
@@ -147,27 +164,30 @@ public class AutoCompleteTextViewPopup
|
||||
|
||||
// now try moving "down" - nothing should happen since there's no longer an adapter
|
||||
sendKeys("DPAD_DOWN");
|
||||
|
||||
// TODO: FlakyTest repeat runs will not currently call setUp, clear state
|
||||
clearText(textView);
|
||||
}
|
||||
|
||||
|
||||
/** Test the show/hide behavior of the drop-down. */
|
||||
@FlakyTest(tolerance=5)
|
||||
@MediumTest
|
||||
@FlakyTest(tolerance=3)
|
||||
public void testPopupShow() throws Throwable {
|
||||
AutoCompleteTextViewSimple theActivity = getActivity();
|
||||
final AutoCompleteTextView textView = theActivity.getTextView();
|
||||
final Instrumentation instrumentation = getInstrumentation();
|
||||
|
||||
|
||||
// Drop-down should not be showing when no text has been entered
|
||||
assertFalse("isPopupShowing() on start", textView.isPopupShowing());
|
||||
|
||||
|
||||
// focus and type
|
||||
textView.requestFocus();
|
||||
instrumentation.waitForIdleSync();
|
||||
sendKeys("A");
|
||||
|
||||
|
||||
// Drop-down should now be visible
|
||||
assertTrue("isPopupShowing() after typing", textView.isPopupShowing());
|
||||
|
||||
waitAssertPopupShowState("isPopupShowing() after typing", textView, true);
|
||||
|
||||
// Clear the text
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
@@ -175,10 +195,10 @@ public class AutoCompleteTextViewPopup
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
|
||||
// Drop-down should be hidden when text is cleared
|
||||
assertFalse("isPopupShowing() after text cleared", textView.isPopupShowing());
|
||||
|
||||
waitAssertPopupShowState("isPopupShowing() after text cleared", textView, false);
|
||||
|
||||
// Set the text, without filtering
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
@@ -186,10 +206,10 @@ public class AutoCompleteTextViewPopup
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
|
||||
// Drop-down should still be hidden
|
||||
assertFalse("isPopupShowing() after setText(\"a\", false)", textView.isPopupShowing());
|
||||
|
||||
waitAssertPopupShowState("isPopupShowing() after setText(\"a\", false)", textView, false);
|
||||
|
||||
// Set the text, now with filtering
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
@@ -197,8 +217,48 @@ public class AutoCompleteTextViewPopup
|
||||
}
|
||||
});
|
||||
instrumentation.waitForIdleSync();
|
||||
|
||||
// Drop-down should show up after setText() with filtering
|
||||
assertTrue("isPopupShowing() after text set", textView.isPopupShowing());
|
||||
|
||||
// Drop-down should show up after setText() with filtering
|
||||
waitAssertPopupShowState("isPopupShowing() after text set", textView, true);
|
||||
|
||||
// TODO: FlakyTest repeat runs will not currently call setUp, clear state
|
||||
clearText(textView);
|
||||
}
|
||||
|
||||
private void waitAssertPopupShowState(String message, AutoCompleteTextView textView,
|
||||
boolean expected) throws InterruptedException {
|
||||
for (int i = 0; i < LOOP_AMOUNT; i++) {
|
||||
if (textView.isPopupShowing() == expected) {
|
||||
return;
|
||||
}
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
}
|
||||
assertEquals(message, expected, textView.isPopupShowing());
|
||||
}
|
||||
|
||||
private void waitAssertListSelection(AutoCompleteTextView textView, int expected)
|
||||
throws Exception {
|
||||
waitAssertListSelection("getListSelection()", textView, expected);
|
||||
}
|
||||
|
||||
private void waitAssertListSelection(String message, AutoCompleteTextView textView,
|
||||
int expected) throws Exception {
|
||||
int currentSelection = ListView.INVALID_POSITION;
|
||||
for (int i = 0; i < LOOP_AMOUNT; i++) {
|
||||
currentSelection = textView.getListSelection();
|
||||
if (expected == currentSelection) {
|
||||
return;
|
||||
}
|
||||
Thread.sleep(SLEEP_TIME);
|
||||
}
|
||||
assertEquals(message, expected, textView.getListSelection());
|
||||
}
|
||||
|
||||
private void clearText(final AutoCompleteTextView textView) throws Throwable {
|
||||
runTestOnUiThread(new Runnable() {
|
||||
public void run() {
|
||||
textView.setText("");
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user