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