FileDocCategorySizeDatePackage
ListWithScreenOfNoSelectablesTest.javaAPI DocAndroid 1.5 API4055Wed May 06 22:42:02 BST 2009com.android.frameworktest.listview.arrowscroll

ListWithScreenOfNoSelectablesTest

public class ListWithScreenOfNoSelectablesTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
private android.widget.ListView
mListView
Constructors Summary
public ListWithScreenOfNoSelectablesTest()

        super("com.android.frameworktest", ListWithScreenOfNoSelectables.class);
    
Methods Summary
protected voidsetUp()

        super.setUp();
        mListView = getActivity().getListView();
    
public voidtestGoFromNoSelectionToSelectionExists()

        // go down untile first (and only selectable) item is off screen
        View first = mListView.getChildAt(0);
        while (first.getParent() != null) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }

        // nothing should be selected
        assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());
        assertNull("selected view", mListView.getSelectedView());

        // go up once to bring the selectable back on screen
        sendKeys(KeyEvent.KEYCODE_DPAD_UP);
        assertEquals("first visible position", 0, mListView.getFirstVisiblePosition());
        assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());


        // up once more should give it selection
        sendKeys(KeyEvent.KEYCODE_DPAD_UP);
        assertEquals("selected position", 0, mListView.getSelectedItemPosition());

    
public voidtestGoFromSelectedViewExistsToNoSelectedViewExists()


        // go down untile first (and only selectable) item is off screen
        View first = mListView.getChildAt(0);
        while (first.getParent() != null) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }

        // nothing should be selected
        assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());
        assertNull("selected view", mListView.getSelectedView());
    
public voidtestPanDownAcrossUnselectableChildrenToBottom()

        final int lastPosition = mListView.getCount() - 1;
        final int maxDowns = 20;
        for(int count = 0; count < maxDowns && mListView.getLastVisiblePosition() <= lastPosition; count++) {
            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
        }
        assertEquals("last visible position not the last position in the list even "
                + "after " + maxDowns + " downs", lastPosition, mListView.getLastVisiblePosition());
    
public voidtestPreconditions()

        assertTrue("expecting first position to be selectable",
                mListView.getAdapter().isEnabled(0));
        final int numItems = mListView.getCount();
        for (int i = 1; i < numItems; i++) {
            assertFalse("expecting item to be unselectable (index " + i +")",
                    mListView.getAdapter().isEnabled(i));
        }
        assertTrue("expecting that not all views fit on screen",
                mListView.getChildCount() < mListView.getCount());