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; 18 19import android.graphics.Rect; 20import android.test.ActivityInstrumentationTestCase; 21import android.test.suitebuilder.annotation.LargeTest; 22import android.test.suitebuilder.annotation.MediumTest; 23import android.test.suitebuilder.annotation.Suppress; 24import android.view.View; 25import android.view.KeyEvent; 26import android.widget.ListView; 27import android.widget.listview.ListOfThinItems; 28 29public class ListItemRequestRectAboveThinFirstItemTest 30 extends ActivityInstrumentationTestCase<ListOfThinItems> { 31 private ListView mListView; 32 33 public ListItemRequestRectAboveThinFirstItemTest() { 34 super("com.android.frameworks.coretests", ListOfThinItems.class); 35 } 36 37 protected void setUp() throws Exception { 38 super.setUp(); 39 mListView = getActivity().getListView(); 40 } 41 42 @MediumTest 43 @Suppress // Failing. 44 public void testPreconditions() { 45 46 assertTrue("first child needs to be within fading edge height", 47 mListView.getChildAt(0).getBottom() < mListView.getVerticalFadingEdgeLength()); 48 assertTrue("should be at least two visible children", 49 mListView.getChildCount() >= 2); 50 } 51 52 // reproduce bug 998501: when first item fits within fading edge, 53 // having the second item call requestRectangleOnScreen with a rect above 54 // the bounds of the list, it was scrolling too far 55 @MediumTest 56 public void testSecondItemRequestRectAboveTop() throws Exception { 57 58 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 59 assertEquals("selected position", 1, mListView.getSelectedItemPosition()); 60 61 final View second = mListView.getChildAt(1); 62 final Rect rect = new Rect(); 63 second.getDrawingRect(rect); 64 rect.offset(0, -2 * second.getBottom()); 65 66 getActivity().requestRectangleOnScreen(1, rect); 67 getInstrumentation().waitForIdleSync(); 68 69 assertEquals("top of first item", 70 mListView.getListPaddingTop(), mListView.getChildAt(0).getTop()); 71 72 } 73 74 // same thing, but at bottom 75 @LargeTest 76 public void testSecondToLastItemRequestRectBelowBottom() throws Exception { 77 78 final int secondToLastPos = mListView.getCount() - 2; 79 80 while (mListView.getSelectedItemPosition() < secondToLastPos) { 81 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 82 } 83 assertEquals("selected position", secondToLastPos, 84 mListView.getSelectedItemPosition()); 85 86 final View secondToLast = mListView.getSelectedView(); 87 final Rect rect = new Rect(); 88 secondToLast.getDrawingRect(rect); 89 rect.offset(0, 90 2 * (mListView.getBottom() - secondToLast.getTop())); 91 92 final int secondToLastIndex = mListView.getChildCount() - 2; 93 getActivity().requestRectangleOnScreen(secondToLastIndex, rect); 94 getInstrumentation().waitForIdleSync(); 95 96 int listBottom = mListView.getHeight() - mListView.getPaddingBottom(); 97 assertEquals("bottom of last item should be at bottom of list", 98 listBottom, 99 mListView.getChildAt(mListView.getChildCount() - 1).getBottom()); 100 } 101 102 103 104} 105