Home | History | Annotate | Download | only in arrowscroll
      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.arrowscroll;
     18 
     19 import android.test.ActivityInstrumentationTestCase2;
     20 import android.test.suitebuilder.annotation.MediumTest;
     21 import android.test.suitebuilder.annotation.Suppress;
     22 import android.util.ListUtil;
     23 import android.view.KeyEvent;
     24 import android.widget.ListView;
     25 import android.widget.listview.ListOfShortShortTallShortShort;
     26 
     27 public class ListOfShortShortTallShortShortTest extends ActivityInstrumentationTestCase2<ListOfShortShortTallShortShort> {
     28     private ListView mListView;
     29     private ListUtil mListUtil;
     30 
     31     public ListOfShortShortTallShortShortTest() {
     32         super(ListOfShortShortTallShortShort.class);
     33     }
     34 
     35     @Override
     36     protected void setUp() throws Exception {
     37         super.setUp();
     38         mListView = getActivity().getListView();
     39         mListUtil = new ListUtil(mListView, getInstrumentation());
     40     }
     41 
     42     @MediumTest
     43     @Suppress // Failing.
     44     public void testPreconditions() {
     45         assertEquals("list item count", 5, mListView.getCount());
     46         assertEquals("list visible child count", 3, mListView.getChildCount());
     47         int firstTwoHeight = mListView.getChildAt(0).getHeight() + mListView.getChildAt(1).getHeight();
     48         assertTrue("first two items should fit within fading edge",
     49                 firstTwoHeight <= mListView.getVerticalFadingEdgeLength());
     50         assertTrue("first two items should fit within list max scroll",
     51                 firstTwoHeight <= mListView.getMaxScrollAmount());
     52     }
     53 
     54     @MediumTest
     55     public void testFadeTopTwoItemsOut() {
     56         // put 2nd item selected
     57         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     58         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     59 
     60         // one more to get two items scrolled off
     61         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     62 
     63         assertEquals("selected item position", 2, mListView.getSelectedItemPosition());
     64         assertTrue("selected item top should be above list top",
     65                 mListView.getSelectedView().getTop() < mListUtil.getListTop());
     66         assertTrue("selected item bottom should be below list bottom",
     67                 mListView.getSelectedView().getBottom() > mListUtil.getListBottom());
     68         assertEquals("should only be 1 child of list (2 should have been scrolled off and removed",
     69                 1, mListView.getChildCount());
     70     }
     71 
     72     @MediumTest
     73     @Suppress // Failing.
     74     public void testFadeInTwoBottomItems() {
     75         // put 2nd item selected
     76         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     77         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     78 
     79         // one more to get two items scrolled off
     80         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     81         assertEquals("number of list children", 1, mListView.getChildCount());
     82 
     83         // last down brings bottom two items into view
     84         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     85         assertEquals("should have scrolled two extra views onto screen",
     86                 3, mListView.getChildCount());
     87         assertEquals("new view position", 3, mListView.getChildAt(1).getId());
     88         assertEquals("new view position", 4, mListView.getChildAt(2).getId());
     89 
     90         assertTrue("bottom most view shouldn't be above list bottom",
     91                 mListView.getChildAt(2).getBottom() >= mListUtil.getListBottom());
     92     }
     93 
     94     @MediumTest
     95     public void testFadeOutBottomTwoItems() throws Exception {
     96         mListUtil.arrowScrollToSelectedPosition(4);
     97 
     98         // go up to tall item
     99         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    100         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    101 
    102         // one more time to scroll off bottom two items
    103         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    104 
    105 
    106         assertEquals("selected item position", 2, mListView.getSelectedItemPosition());
    107         assertTrue("selected item top should be at or above list top",
    108                 mListView.getSelectedView().getTop() <= mListUtil.getListTop());
    109         assertTrue("selected item bottom should be below list bottom",
    110                 mListView.getSelectedView().getBottom() > mListUtil.getListBottom());
    111         assertEquals("should only be 1 child of list (2 should have been scrolled off and removed",
    112                 1, mListView.getChildCount());
    113     }
    114 
    115     @MediumTest
    116     @Suppress // Failing.
    117     public void testFadeInTopTwoItems() throws Exception {
    118         mListUtil.arrowScrollToSelectedPosition(4);
    119 
    120         // put 2nd item selected
    121         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    122         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    123 
    124         // one more to get two items scrolled off
    125         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    126         assertEquals("number of list children", 1, mListView.getChildCount());
    127 
    128         // last down brings top two items into view
    129         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    130         assertEquals("should have scrolled two extra views onto screen",
    131                 3, mListView.getChildCount());
    132         assertEquals("new view position", 0, mListView.getChildAt(0).getId());
    133         assertEquals("new view position", 1, mListView.getChildAt(1).getId());
    134 
    135         assertTrue("top most view shouldn't be above list top",
    136                 mListView.getChildAt(0).getTop() <= mListUtil.getListTop());
    137     }
    138 
    139 
    140 }
    141