ListWithScreenOfNoSelectablesTest.java revision 1d3165f10b12165f02b7015ac1a817c5f60e6399
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.widget.listview.ListWithScreenOfNoSelectables; 20 21import android.test.ActivityInstrumentationTestCase; 22import android.test.suitebuilder.annotation.LargeTest; 23import android.test.suitebuilder.annotation.MediumTest; 24import android.view.KeyEvent; 25import android.view.View; 26import android.widget.ListView; 27 28public class ListWithScreenOfNoSelectablesTest extends ActivityInstrumentationTestCase<ListWithScreenOfNoSelectables> { 29 30 private ListView mListView; 31 32 public ListWithScreenOfNoSelectablesTest() { 33 super("com.android.frameworks.coretests", ListWithScreenOfNoSelectables.class); 34 } 35 36 @Override 37 protected void setUp() throws Exception { 38 super.setUp(); 39 mListView = getActivity().getListView(); 40 } 41 42 @MediumTest 43 public void testPreconditions() { 44 assertTrue("expecting first position to be selectable", 45 mListView.getAdapter().isEnabled(0)); 46 final int numItems = mListView.getCount(); 47 for (int i = 1; i < numItems; i++) { 48 assertFalse("expecting item to be unselectable (index " + i +")", 49 mListView.getAdapter().isEnabled(i)); 50 } 51 assertTrue("expecting that not all views fit on screen", 52 mListView.getChildCount() < mListView.getCount()); 53 } 54 55 56 @MediumTest 57 public void testGoFromSelectedViewExistsToNoSelectedViewExists() { 58 59 // go down untile first (and only selectable) item is off screen 60 View first = mListView.getChildAt(0); 61 while (first.getParent() != null) { 62 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 63 } 64 65 // nothing should be selected 66 assertEquals("selected position", ListView.INVALID_POSITION, mListView.getSelectedItemPosition()); 67 assertNull("selected view", mListView.getSelectedView()); 68 } 69 70 @LargeTest 71 public void testPanDownAcrossUnselectableChildrenToBottom() { 72 final int lastPosition = mListView.getCount() - 1; 73 final int maxDowns = 20; 74 for(int count = 0; count < maxDowns && mListView.getLastVisiblePosition() <= lastPosition; count++) { 75 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 76 } 77 assertEquals("last visible position not the last position in the list even " 78 + "after " + maxDowns + " downs", lastPosition, mListView.getLastVisiblePosition()); 79 } 80 81 @MediumTest 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