2 * Copyright (C) 2007 The Android Open Source Project
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
17 package android.widget.listview.touch;
19 import android.test.ActivityInstrumentationTestCase;
20 import android.test.suitebuilder.annotation.LargeTest;
21 import android.test.suitebuilder.annotation.MediumTest;
22 import android.view.Gravity;
23 import android.view.View;
24 import android.view.ViewConfiguration;
25 import android.widget.ListView;
27 import android.widget.listview.ListOfTouchables;
28 import android.test.TouchUtils;
31 * Touch tests for a list where all of the items fit on the screen.
33 public class ListOfTouchablesTest extends ActivityInstrumentationTestCase<ListOfTouchables> {
34 private ListOfTouchables mActivity;
35 private ListView mListView;
37 public ListOfTouchablesTest() {
38 super("com.android.frameworks.coretests", ListOfTouchables.class);
42 protected void setUp() throws Exception {
45 mActivity = getActivity();
46 mListView = getActivity().getListView();
50 public void testPreconditions() {
51 assertNotNull(mActivity);
52 assertNotNull(mListView);
55 // TODO: needs to be adjusted to pass on non-HVGA displays
57 public void testShortScroll() {
58 View firstChild = mListView.getChildAt(0);
59 View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
61 int firstTop = firstChild.getTop();
63 TouchUtils.dragViewBy(this, lastChild, Gravity.TOP | Gravity.LEFT,
64 0, -(ViewConfiguration.getTouchSlop() + 1 + 10));
66 View newFirstChild = mListView.getChildAt(0);
68 assertEquals("View scrolled too early", firstTop, newFirstChild.getTop() + 10);
69 assertEquals("Wrong view in first position", 0, newFirstChild.getId());
72 // TODO: needs to be adjusted to pass on non-HVGA displays
74 public void testLongScroll() {
75 View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
77 int lastTop = lastChild.getTop();
79 int distance = TouchUtils.dragViewToY(this, lastChild,
80 Gravity.TOP | Gravity.LEFT, mListView.getTop());
82 assertEquals("View scrolled to wrong position",
83 lastTop - (distance - ViewConfiguration.getTouchSlop() - 1), lastChild.getTop());