blob: 73eb0a8f8e639a26e5ac940171e57ec5ed03ac6f [file] [log] [blame]
The Android Open Source Project9066cfe2009-03-03 19:31:44 -08001/*
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 Nguyen1d3165f2010-01-12 13:26:10 -080017package android.widget.listview;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080018
19import android.graphics.Rect;
20import android.test.ActivityInstrumentationTestCase;
21import android.test.suitebuilder.annotation.LargeTest;
22import android.test.suitebuilder.annotation.MediumTest;
Abodunrinwa Tokif9017762015-07-31 18:13:30 -070023import android.test.suitebuilder.annotation.Suppress;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080024import android.view.View;
25import android.view.KeyEvent;
26import android.widget.ListView;
Neal Nguyen1d3165f2010-01-12 13:26:10 -080027import android.widget.listview.ListOfThinItems;
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080028
29public class ListItemRequestRectAboveThinFirstItemTest
30 extends ActivityInstrumentationTestCase<ListOfThinItems> {
31 private ListView mListView;
32
33 public ListItemRequestRectAboveThinFirstItemTest() {
Neal Nguyen1d3165f2010-01-12 13:26:10 -080034 super("com.android.frameworks.coretests", ListOfThinItems.class);
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080035 }
36
37 protected void setUp() throws Exception {
38 super.setUp();
39 mListView = getActivity().getListView();
40 }
41
42 @MediumTest
Abodunrinwa Tokif9017762015-07-31 18:13:30 -070043 @Suppress // Failing.
The Android Open Source Project9066cfe2009-03-03 19:31:44 -080044 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}