1/*
2 * Copyright (C) 2008 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.widget.listview.ListWithNoFadingEdge;
20
21import android.test.ActivityInstrumentationTestCase;
22import android.test.suitebuilder.annotation.LargeTest;
23import android.test.suitebuilder.annotation.MediumTest;
24import android.widget.ListView;
25import android.view.KeyEvent;
26
27public class ListWithNoFadingEdgeTest extends ActivityInstrumentationTestCase<ListWithNoFadingEdge> {
28
29    private ListView mListView;
30
31    public ListWithNoFadingEdgeTest() {
32        super("com.android.frameworks.coretests", ListWithNoFadingEdge.class);
33    }
34
35    @Override
36    protected void setUp() throws Exception {
37        super.setUp();
38
39        mListView = getActivity().getListView();
40    }
41
42    @MediumTest
43    public void testPreconditions() {
44        assertNotNull(mListView);
45        assertEquals("listview vertical fading edge", 0, mListView.getVerticalFadingEdgeLength());
46        assertTrue("expecting that not all views fit on screen",
47                mListView.getChildCount() < mListView.getCount());
48    }
49
50    @MediumTest
51    public void testScrollDownToBottom() {
52        final int numItems = mListView.getCount();
53
54        for (int i = 0; i < numItems; i++) {
55            assertEquals("selected position", i, mListView.getSelectedItemPosition());
56            sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
57        }
58        assertEquals("selected position", numItems - 1, mListView.getSelectedItemPosition());
59    }
60
61    @LargeTest
62    public void testScrollFromBottomToTop() {
63        final int numItems = mListView.getCount();
64
65        getActivity().runOnUiThread(new Runnable() {
66            public void run() {
67                mListView.setSelection(numItems - 1);
68            }
69        });
70        getInstrumentation().waitForIdleSync();
71
72        for (int i = numItems - 1; i >=0; i--) {
73            assertEquals(i, mListView.getSelectedItemPosition());
74            sendKeys(KeyEvent.KEYCODE_DPAD_UP);
75        }
76
77        assertEquals("selected position", 0, mListView.getSelectedItemPosition());
78    }
79
80}
81