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.MediumTest; 21import android.test.TouchUtils; 22import android.view.View; 23import android.widget.ListView; 24 25import android.widget.listview.ListTopGravity; 26 27/** 28 * Touch tests for a list where all of the items fit on the screen. 29 */ 30public class ListTouchTest extends ActivityInstrumentationTestCase<ListTopGravity> { 31 private ListTopGravity mActivity; 32 private ListView mListView; 33 34 public ListTouchTest() { 35 super("com.android.frameworks.coretests", ListTopGravity.class); 36 } 37 38 @Override 39 protected void setUp() throws Exception { 40 super.setUp(); 41 42 mActivity = getActivity(); 43 mListView = getActivity().getListView(); 44 } 45 46 @MediumTest 47 public void testPreconditions() { 48 assertNotNull(mActivity); 49 assertNotNull(mListView); 50 51 // First item should be selected 52 assertEquals(0, mListView.getSelectedItemPosition()); 53 } 54 55 @MediumTest 56 public void testPullDown() { 57 View firstChild = mListView.getChildAt(0); 58 59 TouchUtils.dragViewToBottom(this, firstChild); 60 61 // Nothing should be selected 62 assertEquals("Selection still available after touch", -1, 63 mListView.getSelectedItemPosition()); 64 65 firstChild = mListView.getChildAt(0); 66 67 assertEquals("Item zero not the first child in the list", 0, firstChild.getId()); 68 69 assertEquals("Item zero not at the top of the list", mListView.getListPaddingTop(), 70 firstChild.getTop()); 71 } 72 73 @MediumTest 74 public void testPushUp() { 75 View lastChild = mListView.getChildAt(mListView.getChildCount() - 1); 76 77 TouchUtils.dragViewToTop(this, lastChild); 78 79 // Nothing should be selected 80 assertEquals("Selection still available after touch", -1, 81 mListView.getSelectedItemPosition()); 82 83 View firstChild = mListView.getChildAt(0); 84 85 assertEquals("Item zero not the first child in the list", 0, firstChild.getId()); 86 87 assertEquals("Item zero not at the top of the list", mListView.getListPaddingTop(), 88 firstChild.getTop()); 89 } 90 91} 92