1/* 2 * Copyright (C) 2007 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.ActivityInstrumentationTestCase; 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.TextView; 26import android.widget.listview.ListWithOffScreenNextSelectable; 27 28@Suppress // Failing. 29public class ListWithOffScreenNextSelectableTest 30 extends ActivityInstrumentationTestCase<ListWithOffScreenNextSelectable> { 31 private ListView mListView; 32 33 public ListWithOffScreenNextSelectableTest() { 34 super("com.android.frameworks.coretests", ListWithOffScreenNextSelectable.class); 35 } 36 37 @Override 38 protected void setUp() throws Exception { 39 super.setUp(); 40 41 mListView = getActivity().getListView(); 42 } 43 44 @MediumTest 45 public void testPreconditions() { 46 assertNotNull(mListView); 47 assertEquals(5, mListView.getAdapter().getCount()); 48 assertFalse(mListView.getAdapter().areAllItemsEnabled()); 49 assertFalse(mListView.getAdapter().isEnabled(1)); 50 assertFalse(mListView.getAdapter().isEnabled(2)); 51 assertFalse(mListView.getAdapter().isEnabled(3)); 52 assertEquals("only 4 children should be on screen (so that next selectable is off " + 53 "screen) for this test to be meaningful.", 54 4, mListView.getChildCount()); 55 assertEquals(0, mListView.getSelectedItemPosition()); 56 } 57 58 // when the next items on screen are not selectable, we pan until the next selectable item 59 // is (partially visible), then we jump to it 60 @MediumTest 61 public void testGoDownToOffScreenSelectable() { 62 63 final int listBottom = mListView.getHeight() - mListView.getListPaddingBottom(); 64 65 final View lastVisibleView = mListView.getChildAt(mListView.getChildCount() - 1); 66 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 67 assertEquals("expecting view to be panned to just above fading edge", 68 listBottom - mListView.getVerticalFadingEdgeLength(), lastVisibleView.getBottom()); 69 assertEquals("selection should not have moved yet", 70 0, mListView.getSelectedItemPosition()); 71 72 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 73 assertEquals("selection should have moved", 74 4, mListView.getSelectedItemPosition()); 75 assertEquals("wrong view created when scrolling", 76 getActivity().getValueAtPosition(4), ((TextView) mListView.getSelectedView()).getText()); 77 assertEquals(listBottom, mListView.getSelectedView().getBottom()); 78 } 79 80 @MediumTest 81 public void testGoUpToOffScreenSelectable() { 82 final int listBottom = mListView.getHeight() - mListView.getListPaddingBottom(); 83 final int listTop = mListView.getListPaddingTop(); 84 85 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 86 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 87 88 assertEquals(4, mListView.getSelectedItemPosition()); 89 assertEquals(listBottom, mListView.getSelectedView().getBottom()); 90 91 // now we have the reverse situation: the next selectable position upward is off screen 92 final View firstVisibleView = mListView.getChildAt(0); 93 sendKeys(KeyEvent.KEYCODE_DPAD_UP); 94 assertEquals("should have panned top view just below vertical fading edge", 95 listTop + mListView.getVerticalFadingEdgeLength(), firstVisibleView.getTop()); 96 assertEquals("selection should not have moved yet", 97 4, mListView.getSelectedItemPosition()); 98 99 sendKeys(KeyEvent.KEYCODE_DPAD_UP); 100 assertEquals("selection should have moved", 101 0, mListView.getSelectedItemPosition()); 102 assertEquals(getActivity().getValueAtPosition(0),((TextView) mListView.getSelectedView()).getText()); 103 assertEquals(listTop, mListView.getSelectedView().getTop()); 104 105 } 106 107} 108