Home | History | Annotate | Download | only in touch
      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 
     17 package android.widget.listview.touch;
     18 
     19 import android.test.ActivityInstrumentationTestCase;
     20 import android.test.suitebuilder.annotation.MediumTest;
     21 import android.test.TouchUtils;
     22 import android.view.View;
     23 import android.widget.ListView;
     24 
     25 import android.widget.listview.ListBottomGravity;
     26 
     27 /**
     28  * Touch tests for a list where all of the items fit on the screen, and the list
     29  * stacks from the bottom.
     30  */
     31 public class ListTouchBottomGravityTest extends ActivityInstrumentationTestCase<ListBottomGravity> {
     32     private ListBottomGravity mActivity;
     33     private ListView mListView;
     34 
     35     public ListTouchBottomGravityTest() {
     36         super("com.android.frameworks.coretests", ListBottomGravity.class);
     37     }
     38 
     39     @Override
     40     protected void setUp() throws Exception {
     41         super.setUp();
     42 
     43         mActivity = getActivity();
     44         mListView = getActivity().getListView();
     45     }
     46 
     47     @MediumTest
     48     public void testPreconditions() {
     49         assertNotNull(mActivity);
     50         assertNotNull(mListView);
     51 
     52         // First item should be selected
     53         assertEquals(mListView.getAdapter().getCount() - 1, mListView.getSelectedItemPosition());
     54     }
     55 
     56     @MediumTest
     57     public void testPullDown() {
     58         View firstChild = mListView.getChildAt(0);
     59 
     60         TouchUtils.dragViewToBottom(this, firstChild);
     61 
     62         View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
     63 
     64         // Nothing should be selected
     65         assertEquals("Selection still available after touch", -1,
     66                 mListView.getSelectedItemPosition());
     67 
     68         assertEquals("List is not scrolled to the bottom", mListView.getAdapter().getCount() - 1,
     69                 lastChild.getId());
     70 
     71         assertEquals("Last item is not touching the bottom edge",
     72                 mListView.getHeight() - mListView.getListPaddingBottom(), lastChild.getBottom());
     73     }
     74 
     75     @MediumTest
     76     public void testPushUp() {
     77         View lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
     78 
     79         TouchUtils.dragViewToTop(this, lastChild);
     80 
     81         lastChild = mListView.getChildAt(mListView.getChildCount() - 1);
     82 
     83         // Nothing should be selected
     84         assertEquals("Selection still available after touch", -1,
     85                 mListView.getSelectedItemPosition());
     86 
     87         assertEquals("List is not scrolled to the bottom", mListView.getAdapter().getCount() - 1,
     88                 lastChild.getId());
     89 
     90         assertEquals("Last item is not touching the bottom edge",
     91                 mListView.getHeight() - mListView.getListPaddingBottom(), lastChild.getBottom());
     92     }
     93 
     94 }
     95