The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 17 | package android.widget.listview; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 18 | |
| 19 | import android.graphics.Rect; |
| 20 | import android.test.ActivityInstrumentationTestCase; |
| 21 | import android.test.suitebuilder.annotation.LargeTest; |
| 22 | import android.test.suitebuilder.annotation.MediumTest; |
Abodunrinwa Toki | f901776 | 2015-07-31 18:13:30 -0700 | [diff] [blame] | 23 | import android.test.suitebuilder.annotation.Suppress; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 24 | import android.view.View; |
| 25 | import android.view.KeyEvent; |
| 26 | import android.widget.ListView; |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 27 | import android.widget.listview.ListOfThinItems; |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 28 | |
| 29 | public class ListItemRequestRectAboveThinFirstItemTest |
| 30 | extends ActivityInstrumentationTestCase<ListOfThinItems> { |
| 31 | private ListView mListView; |
| 32 | |
| 33 | public ListItemRequestRectAboveThinFirstItemTest() { |
Neal Nguyen | 1d3165f | 2010-01-12 13:26:10 -0800 | [diff] [blame] | 34 | super("com.android.frameworks.coretests", ListOfThinItems.class); |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | protected void setUp() throws Exception { |
| 38 | super.setUp(); |
| 39 | mListView = getActivity().getListView(); |
| 40 | } |
| 41 | |
| 42 | @MediumTest |
Abodunrinwa Toki | f901776 | 2015-07-31 18:13:30 -0700 | [diff] [blame] | 43 | @Suppress // Failing. |
The Android Open Source Project | 9066cfe | 2009-03-03 19:31:44 -0800 | [diff] [blame] | 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 | } |