[go: nahoru, domu]

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.widget.ListView;
22import android.view.View;
23import android.view.KeyEvent;
24import android.widget.listview.ListLastItemPartiallyVisible;
25
26public class ListLastItemPartiallyVisibleTest extends ActivityInstrumentationTestCase<ListLastItemPartiallyVisible> {
27    private ListView mListView;
28    private int mListBottom;
29
30
31    public ListLastItemPartiallyVisibleTest() {
32        super("com.android.frameworks.coretests", ListLastItemPartiallyVisible.class);
33    }
34
35    @Override
36    protected void setUp() throws Exception {
37        super.setUp();
38        mListView = getActivity().getListView();
39        mListBottom = mListView.getHeight() - mListView.getPaddingBottom();
40    }
41
42    @MediumTest
43    public void testPreconditions() {
44        assertEquals("number of elements visible should be the same as number of items " +
45                "in adapter", mListView.getCount(), mListView.getChildCount());
46
47        final View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
48        assertTrue("last item should be partially off screen",
49                lastChild.getBottom() > mListBottom);
50        assertEquals("selected position", 0, mListView.getSelectedItemPosition());
51    }
52
53    // reproduce bug 998094
54    @MediumTest
55    public void testMovingDownToFullyVisibleNoScroll() {
56        final View firstChild = mListView.getChildAt(0);
57        final int firstBottom = firstChild.getBottom();
58        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
59        assertEquals("shouldn't have scrolled: bottom of first child changed.",
60                firstBottom, firstChild.getBottom());
61    }
62
63    // reproduce bug 998094
64    @MediumTest
65    public void testMovingUpToFullyVisibleNoScroll() {
66        int numMovesToLast = mListView.getCount() - 1;
67        for (int i = 0; i < numMovesToLast; i++) {
68            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
69        }
70        assertEquals("should have moved to last position",
71                mListView.getChildCount() - 1, mListView.getSelectedItemPosition());
72
73        final View lastChild = mListView.getSelectedView();
74        final int lastTop = lastChild.getTop();
75        sendKeys(KeyEvent.KEYCODE_DPAD_UP);
76        assertEquals("shouldn't have scrolled: top of last child changed.",
77                lastTop, lastChild.getTop());
78    }
79
80}
81