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.ActivityInstrumentationTestCase;
     20 import android.test.suitebuilder.annotation.LargeTest;
     21 import android.test.suitebuilder.annotation.MediumTest;
     22 import android.test.suitebuilder.annotation.Suppress;
     23 import android.widget.ListView;
     24 import android.view.KeyEvent;
     25 import android.widget.listview.ListItemsExpandOnSelection;
     26 
     27 public class ListItemsExpandOnSelectionTest extends ActivityInstrumentationTestCase<ListItemsExpandOnSelection> {
     28     private ListView mListView;
     29     private int mListTop;
     30     private int mListBottom;
     31     private int mExpandedHeight;
     32     private int mNormalHeight;
     33 
     34     public ListItemsExpandOnSelectionTest() {
     35         super("com.android.frameworks.coretests",
     36                 ListItemsExpandOnSelection.class);
     37     }
     38 
     39     @Override
     40     protected void setUp() throws Exception {
     41         super.setUp();
     42         mListView = getActivity().getListView();
     43         mListTop = mListView.getListPaddingTop();
     44         mListBottom = mListView.getHeight() - mListView.getListPaddingBottom();
     45         mExpandedHeight = mListView.getChildAt(0).getHeight();
     46         mNormalHeight = mListView.getChildAt(1).getHeight();
     47     }
     48 
     49     @MediumTest
     50     public void testPreconditions() {
     51         assertEquals(0, mListView.getSelectedItemPosition());
     52         assertEquals("selected item should be 1.5 times taller than the others",
     53                 mExpandedHeight, (int) (mNormalHeight * 1.5));
     54     }
     55 
     56     @MediumTest
     57     public void testMoveSelectionDownNotRequiringScroll() {
     58 
     59         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     60 
     61         assertEquals(1, mListView.getSelectedItemPosition());
     62         assertEquals("first item's top should not have shifted",
     63                 mListTop, mListView.getChildAt(0).getTop());
     64 
     65     }
     66 
     67     @MediumTest
     68     public void testMoveSelectionUpNotRequiringScroll() {
     69         sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     70 
     71         assertEquals(1, mListView.getSelectedItemPosition());
     72         final int oldBottom = mListView.getSelectedView().getBottom();
     73 
     74         sendKeys(KeyEvent.KEYCODE_DPAD_UP);
     75 
     76         assertEquals("bottom of 2nd itme should have stayed the same when " +
     77                 "moving back up",
     78                 oldBottom,
     79                 mListView.getChildAt(1).getBottom());
     80     }
     81 
     82     @MediumTest
     83     @Suppress // Failing.
     84     public void testMoveSelectionDownRequiringScroll() {
     85         int lastItemIndex = mListView.getChildCount() - 1;
     86 
     87         for(int i = 0; i < lastItemIndex; i++) {
     88             sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
     89         }
     90         getInstrumentation().waitForIdleSync();
     91 
     92         assertEquals("list position", lastItemIndex, mListView.getSelectedItemPosition());
     93         assertEquals("expanded height", mExpandedHeight, mListView.getSelectedView().getHeight());
     94         assertEquals("should be above bottom fading edge",
     95                 mListBottom - mListView.getVerticalFadingEdgeLength(),
     96                 mListView.getSelectedView().getBottom());
     97     }
     98 
     99     @LargeTest
    100     @Suppress // Failing.
    101     public void testMoveSelectionUpRequiringScroll() {
    102         int childrenPerScreen = mListView.getChildCount();
    103 
    104         // go down past last child on screen
    105         for(int i = 0; i < childrenPerScreen; i++) {
    106             sendKeys(KeyEvent.KEYCODE_DPAD_DOWN);
    107         }
    108 
    109         // go back up to second to last
    110         for(int i = 0; i < childrenPerScreen - 1; i++) {
    111             sendKeys(KeyEvent.KEYCODE_DPAD_UP);
    112         }
    113         getInstrumentation().waitForIdleSync();
    114 
    115         assertEquals("list position", 1, mListView.getSelectedItemPosition());
    116         assertEquals("expanded height", mExpandedHeight, mListView.getSelectedView().getHeight());
    117         assertEquals("should be below top fading edge",
    118                 mListTop + mListView.getVerticalFadingEdgeLength(),
    119                 mListView.getSelectedView().getTop());
    120     }
    121 }
    122