FileDocCategorySizeDatePackage
AutoCompleteTextViewPopup.javaAPI DocAndroid 5.1 API9396Thu Mar 12 22:22:12 GMT 2015android.widget

AutoCompleteTextViewPopup

public class AutoCompleteTextViewPopup extends android.test.ActivityInstrumentationTestCase2
A collection of tests on aspects of the AutoCompleteTextView's popup TODO: tests fail intermittently. Add back MediumTest annotation when fixed

Fields Summary
private static final int
SLEEP_TIME
private static final int
LOOP_AMOUNT
Constructors Summary
public AutoCompleteTextViewPopup()



      
        super("com.android.frameworks.coretests", AutoCompleteTextViewSimple.class);
    
Methods Summary
private voidclearText(AutoCompleteTextView textView)

        runTestOnUiThread(new Runnable() {
            public void run() {
                textView.setText("");
            }
        });
    
public voidtestPopupClearListSelection()
Test that we can clear the selection

        AutoCompleteTextViewSimple theActivity = getActivity();
        final AutoCompleteTextView textView = theActivity.getTextView();
        final Instrumentation instrumentation = getInstrumentation();

        // focus and type
        textView.requestFocus();
        instrumentation.waitForIdleSync();
        sendKeys("A");

        // No initial selection
        waitAssertListSelection(textView, ListView.INVALID_POSITION);

        // check for selection position as expected
        sendKeys("DPAD_DOWN");
        waitAssertListSelection(textView, 0);

        // clear it
        runTestOnUiThread(new Runnable() {
            public void run() {
                textView.clearListSelection();
            }
        });
        instrumentation.waitForIdleSync();
        waitAssertListSelection("setListSelection(ListView.INVALID_POSITION)", textView,
                ListView.INVALID_POSITION);

        // TODO: FlakyTest repeat runs will not currently call setUp, clear state
        clearText(textView);
    
public voidtestPopupGetListSelection()
Test that we can look at the selection as we move around

        AutoCompleteTextViewSimple theActivity = getActivity();
        final AutoCompleteTextView textView = theActivity.getTextView();
        final Instrumentation instrumentation = getInstrumentation();

        // focus and type
        textView.requestFocus();
        instrumentation.waitForIdleSync();
        sendKeys("A");

        // No initial selection
        waitAssertListSelection(textView, ListView.INVALID_POSITION);

        // check for selection position as expected
        sendKeys("DPAD_DOWN");
        waitAssertListSelection("move selection to (0)", textView, 0);

        // Repeat for one more movement
        sendKeys("DPAD_DOWN");
        waitAssertListSelection("move selection to (1)", textView, 1);

        // TODO: FlakyTest repeat runs will not currently call setUp, clear state
        clearText(textView);
    
public voidtestPopupNavigateNoAdapter()
Make sure we handle an empty adapter properly

        AutoCompleteTextViewSimple theActivity = getActivity();
        final AutoCompleteTextView textView = theActivity.getTextView();
        final Instrumentation instrumentation = getInstrumentation();

        // focus and type
        textView.requestFocus();
        instrumentation.waitForIdleSync();
        sendKeys("A");

        // No initial selection
         waitAssertListSelection(textView, ListView.INVALID_POSITION);

        // check for selection position as expected
        sendKeys("DPAD_DOWN");
        waitAssertListSelection(textView, 0);

        // Now get rid of the adapter
        runTestOnUiThread(new Runnable() {
            public void run() {
                textView.setAdapter((ArrayAdapter<?>) null);
            }
        });
        instrumentation.waitForIdleSync();

        // 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);
    
public voidtestPopupSetListSelection()
Test that we can move the selection and it responds as expected

        AutoCompleteTextViewSimple theActivity = getActivity();
        final AutoCompleteTextView textView = theActivity.getTextView();
        final Instrumentation instrumentation = getInstrumentation();

        // focus and type
        textView.requestFocus();
        instrumentation.waitForIdleSync();
        sendKeys("A");

        // No initial selection
        waitAssertListSelection(textView, ListView.INVALID_POSITION);

        // set and check
        runTestOnUiThread(new Runnable() {
            public void run() {
                textView.setListSelection(0);
            }
        });
        instrumentation.waitForIdleSync();
        waitAssertListSelection("set selection to (0)", textView, 0);

        // Use movement to cross-check the movement
        sendKeys("DPAD_DOWN");
        waitAssertListSelection("move selection to (1)", textView, 1);

        // TODO: FlakyTest repeat runs will not currently call setUp, clear state
        clearText(textView);
    
public voidtestPopupShow()
Test the show/hide behavior of the drop-down.

        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
        waitAssertPopupShowState("isPopupShowing() after typing", textView, true);

        // Clear the text
        runTestOnUiThread(new Runnable() {
            public void run() {
                textView.setText("");
            }
        });
        instrumentation.waitForIdleSync();

        // Drop-down should be hidden when text is cleared
        waitAssertPopupShowState("isPopupShowing() after text cleared", textView, false);

        // Set the text, without filtering
        runTestOnUiThread(new Runnable() {
            public void run() {
                textView.setText("a", false);
            }
        });
        instrumentation.waitForIdleSync();

        // Drop-down should still be hidden
        waitAssertPopupShowState("isPopupShowing() after setText(\"a\", false)", textView, false);

        // Set the text, now with filtering
        runTestOnUiThread(new Runnable() {
            public void run() {
                textView.setText("a");
            }
        });
        instrumentation.waitForIdleSync();

        // 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 voidwaitAssertListSelection(AutoCompleteTextView textView, int expected)

        waitAssertListSelection("getListSelection()", textView, expected);
    
private voidwaitAssertListSelection(java.lang.String message, AutoCompleteTextView textView, int expected)

        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 voidwaitAssertPopupShowState(java.lang.String message, AutoCompleteTextView textView, boolean expected)

        for (int i = 0; i < LOOP_AMOUNT; i++) {
            if (textView.isPopupShowing() == expected) {
                return;
            }
            Thread.sleep(SLEEP_TIME);
        }
        assertEquals(message, expected, textView.isPopupShowing());