ListOfTouchablesTest.java revision 1d3165f10b12165f02b7015ac1a817c5f60e6399
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.touch;
18
19import android.test.ActivityInstrumentationTestCase;
20import android.test.suitebuilder.annotation.LargeTest;
21import android.test.suitebuilder.annotation.MediumTest;
22import android.view.Gravity;
23import android.view.View;
24import android.view.ViewConfiguration;
25import android.widget.ListView;
26
27import android.widget.listview.ListOfTouchables;
28import android.test.TouchUtils;
29
30/**
31 * Touch tests for a list where all of the items fit on the screen.
32 */
33public class ListOfTouchablesTest extends ActivityInstrumentationTestCase<ListOfTouchables> {
34    private ListOfTouchables mActivity;
35    private ListView mListView;
36
37    public ListOfTouchablesTest() {
38        super("com.android.frameworks.coretests", ListOfTouchables.class);
39    }
40
41    @Override
42    protected void setUp() throws Exception {
43        super.setUp();
44
45        mActivity = getActivity();
46        mListView = getActivity().getListView();
47    }
48
49    @MediumTest
50    public void testPreconditions() {
51        assertNotNull(mActivity);
52        assertNotNull(mListView);
53    }
54
55    // TODO: needs to be adjusted to pass on non-HVGA displays
56    // @LargeTest
57    public void testShortScroll() {
58        View firstChild = mListView.getChildAt(0);
59        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
60
61        int firstTop = firstChild.getTop();
62
63        TouchUtils.dragViewBy(this, lastChild, Gravity.TOP | Gravity.LEFT,
64                0, -(ViewConfiguration.getTouchSlop() + 1 + 10));
65
66        View newFirstChild = mListView.getChildAt(0);
67
68        assertEquals("View scrolled too early", firstTop, newFirstChild.getTop() + 10);
69        assertEquals("Wrong view in first position", 0, newFirstChild.getId());
70    }
71
72    // TODO: needs to be adjusted to pass on non-HVGA displays
73    // @LargeTest
74    public void testLongScroll() {
75        View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
76
77        int lastTop = lastChild.getTop();
78
79        int distance = TouchUtils.dragViewToY(this, lastChild,
80                Gravity.TOP | Gravity.LEFT, mListView.getTop());
81
82        assertEquals("View scrolled to wrong position",
83                lastTop - (distance - ViewConfiguration.getTouchSlop() - 1), lastChild.getTop());
84    }
85
86}
87