[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.KeyEvent;
23import android.widget.listview.ListOfShortTallShort;
24
25public class ListOfShortTallShortTest extends ActivityInstrumentationTestCase<ListOfShortTallShort> {
26    private ListView mListView;
27
28    public ListOfShortTallShortTest() {
29        super("com.android.frameworks.coretests", ListOfShortTallShort.class);
30    }
31
32    @Override
33    protected void setUp() throws Exception {
34        super.setUp();
35
36        mListView = getActivity().getListView();
37    }
38
39    @MediumTest
40    public void testPreconditions() {
41        assertTrue("second item should be taller than screen",
42                mListView.getChildAt(1).getHeight() > mListView.getHeight());
43    }
44
45    @MediumTest
46    public void testGoDownFromShortToTall() {
47        int topBeforeMove = mListView.getChildAt(1).getTop();
48        sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
49
50        assertEquals("selection should have moved to tall item below",
51                1, mListView.getSelectedItemPosition());
52        assertEquals("should not have scrolled; top should be the same.",
53                topBeforeMove,
54                mListView.getSelectedView().getTop());
55    }
56
57    @MediumTest
58    public void testGoUpFromShortToTall() {
59        int maxMoves = 8;
60        while (mListView.getSelectedItemPosition() != 2 && maxMoves > 0) {
61            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
62        }
63        assertEquals("couldn't get to 3rd item",
64                2,
65                mListView.getSelectedItemPosition());
66
67        assertEquals("should only be two items on screen",
68                2, mListView.getChildCount());
69        assertEquals("selected item should be last item on screen",
70                mListView.getChildAt(1), mListView.getSelectedView());
71
72        final int bottomBeforeMove = mListView.getChildAt(0).getBottom();
73        sendKeys(KeyEvent.KEYCODE_DPAD_UP);
74        assertEquals("should have moved selection to tall item above",
75                1, mListView.getSelectedItemPosition());
76        assertEquals("should not have scrolled, top should be the same",
77                bottomBeforeMove,
78                mListView.getChildAt(0).getBottom());
79    }
80}
81