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.gridview.touch;
     18 
     19 import android.test.suitebuilder.annotation.LargeTest;
     20 import android.test.suitebuilder.annotation.MediumTest;
     21 import android.test.TouchUtils;
     22 import android.widget.gridview.GridStackFromBottomMany;
     23 
     24 import android.widget.GridView;
     25 import android.view.View;
     26 import android.test.ActivityInstrumentationTestCase;
     27 
     28 public class GridTouchStackFromBottomManyTest extends ActivityInstrumentationTestCase<GridStackFromBottomMany> {
     29     private GridStackFromBottomMany mActivity;
     30     private GridView mGridView;
     31 
     32     public GridTouchStackFromBottomManyTest() {
     33         super("com.android.frameworks.coretests", GridStackFromBottomMany.class);
     34     }
     35 
     36     @Override
     37     protected void setUp() throws Exception {
     38         super.setUp();
     39 
     40         mActivity = getActivity();
     41         mGridView = getActivity().getGridView();
     42     }
     43 
     44     @MediumTest
     45     public void testPreconditions() {
     46         assertNotNull(mActivity);
     47         assertNotNull(mGridView);
     48 
     49         // Last item should be selected
     50         assertEquals(mGridView.getAdapter().getCount() - 1, mGridView.getSelectedItemPosition());
     51     }
     52 
     53     @LargeTest
     54     public void testScrollToTop() {
     55         View firstChild;
     56         TouchUtils.scrollToTop(this, mGridView);
     57 
     58         // Nothing should be selected
     59         assertEquals("Selection still available after touch", -1,
     60                 mGridView.getSelectedItemPosition());
     61 
     62         firstChild = mGridView.getChildAt(0);
     63 
     64         assertEquals("Item zero not the first child in the grid", 0, firstChild.getId());
     65 
     66         assertEquals("Item zero not at the top of the grid",
     67                 mGridView.getListPaddingTop(), firstChild.getTop());
     68     }
     69 
     70     @LargeTest
     71     public void testScrollToBottom() {
     72         TouchUtils.scrollToBottom(this, mGridView);
     73 
     74         // Nothing should be selected
     75         assertEquals("Selection still available after touch", -1,
     76                 mGridView.getSelectedItemPosition());
     77 
     78         View lastChild = mGridView.getChildAt(mGridView.getChildCount() - 1);
     79 
     80         assertEquals("Grid is not scrolled to the bottom", mGridView.getAdapter().getCount() - 1,
     81                 lastChild.getId());
     82 
     83         assertEquals("Last item is not touching the bottom edge",
     84                 mGridView.getHeight() - mGridView.getListPaddingBottom(), lastChild.getBottom());
     85     }
     86 }
     87