Home | History | Annotate | Download | only in arrowscroll
      1 /*
      2  * Copyright (C) 2008 The Android Open Source Project
      3  *
      4  * Licensed under the Apache License, Version 2.0 (the "License");
      5  * you may not use this file except in compliance with the License.
      6  * You may obtain a copy of the License at
      7  *
      8  *      http://www.apache.org/licenses/LICENSE-2.0
      9  *
     10  * Unless required by applicable law or agreed to in writing, software
     11  * distributed under the License is distributed on an "AS IS" BASIS,
     12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
     13  * See the License for the specific language governing permissions and
     14  * limitations under the License.
     15  */
     16 
     17 package android.widget.listview.arrowscroll;
     18 
     19 import android.test.ActivityInstrumentationTestCase2;
     20 import android.test.suitebuilder.annotation.MediumTest;
     21 import android.view.KeyEvent;
     22 import android.view.View;
     23 import android.widget.ListView;
     24 import android.widget.listview.ListWithScreenOfNoSelectables;
     25 
     26 public class ListWithScreenOfNoSelectablesTest extends ActivityInstrumentationTestCase2<ListWithScreenOfNoSelectables> {
     27 
     28     private ListView mListView;
     29 
     30     public ListWithScreenOfNoSelectablesTest() {
     31         super(ListWithScreenOfNoSelectables.class);
     32     }
     33 
     34     @Override
     35     protected void setUp() throws Exception {
     36         super.setUp();
     37         mListView = getActivity().getListView();
     38     }
     39 
     40     @MediumTest
     41     public void testPreconditions() {
     42         assertTrue("expecting first position to be selectable",
     43                 mListView.getAdapter().isEnabled(0));
     44         final int numItems = mListView.getCount();
     45         for (int i = 1; i < numItems; i++) {
     46             assertFalse("expecting item to be unselectable (index " + i +")",
     47                     mListView.getAdapter().isEnabled(i));
     48         }
     49         assertTrue("expecting that not all views fit on screen",
     50                 mListView.getChildCount() < mListView.getCount());
     51     }
     52 
     53 
     54     @MediumTest
     55     public void testGoFromSelectedViewExistsToNoSelectedViewExists() {
     56 
     57         // go down until first (and only selectable) item is off screen
     58         View first = mListView.getChildAt(0);
     59         while (first.getParent() != null) {
     60             sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     61         }
     62 
     63         // nothing should be selected
     64         assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());
     65         assertNull("selected view", mListView.getSelectedView());
     66     }
     67 
     68     @MediumTest
     69     public void testPanDownAcrossUnselectableChildrenToBottom() {
     70         final int lastPosition = mListView.getCount() - 1;
     71         final int maxDowns = 20;
     72         for(int count = 0; count < maxDowns && mListView.getLastVisiblePosition() <= lastPosition; count++) {
     73             sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     74         }
     75         assertEquals("last visible position not the last position in the list even "
     76                 + "after " + maxDowns + " downs", lastPosition, mListView.getLastVisiblePosition());
     77     }
     78 
     79     @MediumTest
     80     public void testGoFromNoSelectionToSelectionExists() {
     81         // go down untile first (and only selectable) item is off screen
     82         View first = mListView.getChildAt(0);
     83         while (first.getParent() != null) {
     84             sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     85         }
     86 
     87         // nothing should be selected
     88         assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());
     89         assertNull("selected view", mListView.getSelectedView());
     90 
     91         // go up once to bring the selectable back on screen
     92         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
     93         assertEquals("first visible position", 0, mListView.getFirstVisiblePosition());
     94         assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition());
     95 
     96 
     97         // up once more should give it selection
     98         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
     99         assertEquals("selected position", 0, mListView.getSelectedItemPosition());
    100 
    101     }
    102 
    103 
    104 }
    105