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 17package android.widget.listview.arrowscroll; 18 19import android.test.ActivityInstrumentationTestCase2; 20import android.test.suitebuilder.annotation.MediumTest; 21import android.test.suitebuilder.annotation.Suppress; 22import android.view.KeyEvent; 23import android.view.View; 24import android.widget.ListView; 25import android.widget.listview.ListWithScreenOfNoSelectables; 26 27public class ListWithScreenOfNoSelectablesTest extends ActivityInstrumentationTestCase2<ListWithScreenOfNoSelectables> { 28 29 private ListView mListView; 30 31 public ListWithScreenOfNoSelectablesTest() { 32 super(ListWithScreenOfNoSelectables.class); 33 } 34 35 @Override 36 protected void setUp() throws Exception { 37 super.setUp(); 38 mListView = getActivity().getListView(); 39 } 40 41 @MediumTest 42 public void testPreconditions() { 43 assertTrue("expecting first position to be selectable", 44 mListView.getAdapter().isEnabled(0)); 45 final int numItems = mListView.getCount(); 46 for (int i = 1; i < numItems; i++) { 47 assertFalse("expecting item to be unselectable (index " + i +")", 48 mListView.getAdapter().isEnabled(i)); 49 } 50 assertTrue("expecting that not all views fit on screen", 51 mListView.getChildCount() < mListView.getCount()); 52 } 53 54 55 @MediumTest 56 public void testGoFromSelectedViewExistsToNoSelectedViewExists() { 57 58 // go down until first (and only selectable) item is off screen 59 View first = mListView.getChildAt(0); 60 while (first.getParent() != null) { 61 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 62 } 63 64 // nothing should be selected 65 assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition()); 66 assertNull("selected view", mListView.getSelectedView()); 67 } 68 69 @MediumTest 70 public void testPanDownAcrossUnselectableChildrenToBottom() { 71 final int lastPosition = mListView.getCount() - 1; 72 final int maxDowns = 20; 73 for(int count = 0; count < maxDowns && mListView.getLastVisiblePosition() <= lastPosition; count++) { 74 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 75 } 76 assertEquals("last visible position not the last position in the list even " 77 + "after " + maxDowns + " downs", lastPosition, mListView.getLastVisiblePosition()); 78 } 79 80 @MediumTest 81 @Suppress // Failing. 82 public void testGoFromNoSelectionToSelectionExists() { 83 // go down untile first (and only selectable) item is off screen 84 View first = mListView.getChildAt(0); 85 while (first.getParent() != null) { 86 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 87 } 88 89 // nothing should be selected 90 assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition()); 91 assertNull("selected view", mListView.getSelectedView()); 92 93 // go up once to bring the selectable back on screen 94 sendKeys(KeyEvent.KEYCODE_DPAD_UP); 95 assertEquals("first visible position", 0, mListView.getFirstVisiblePosition()); 96 assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition()); 97 98 99 // up once more should give it selection 100 sendKeys(KeyEvent.KEYCODE_DPAD_UP); 101 assertEquals("selected position", 0, mListView.getSelectedItemPosition()); 102 103 } 104 105 106} 107