1 /* 2 * Copyright (C) 2008 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.focus; 18 19 import android.widget.listview.AdjacentListsWithAdjacentISVsInside; 20 import android.util.InternalSelectionView; 21 22 import android.test.ActivityInstrumentationTestCase; 23 import android.test.suitebuilder.annotation.MediumTest; 24 import android.view.KeyEvent; 25 import android.widget.ListView; 26 27 public class AdjacentListsWithAdjacentISVsInsideTest extends ActivityInstrumentationTestCase<AdjacentListsWithAdjacentISVsInside> { 28 29 private ListView mLeftListView; 30 private InternalSelectionView mLeftIsv; 31 private InternalSelectionView mLeftMiddleIsv; 32 private ListView mRightListView; 33 private InternalSelectionView mRightMiddleIsv; 34 private InternalSelectionView mRightIsv; 35 36 public AdjacentListsWithAdjacentISVsInsideTest() { 37 super("com.android.frameworks.coretests", AdjacentListsWithAdjacentISVsInside.class); 38 } 39 40 @Override 41 protected void setUp() throws Exception { 42 super.setUp(); 43 final AdjacentListsWithAdjacentISVsInside a = getActivity(); 44 mLeftListView = a.getLeftListView(); 45 mLeftIsv = a.getLeftIsv(); 46 mLeftMiddleIsv = a.getLeftMiddleIsv(); 47 mRightListView = a.getRightListView(); 48 mRightMiddleIsv = a.getRightMiddleIsv(); 49 mRightIsv = a.getRightIsv(); 50 } 51 52 @MediumTest 53 public void testPreconditions() { 54 assertTrue(mLeftListView.hasFocus()); 55 assertTrue(mLeftIsv.isFocused()); 56 assertEquals(0, mLeftIsv.getSelectedRow()); 57 } 58 59 /** 60 * rockinist test name to date! 61 */ 62 @MediumTest 63 public void testFocusedRectAndFocusHintWorkWithinListItemHorizontal() { 64 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 65 assertEquals(1, mLeftIsv.getSelectedRow()); 66 67 sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT); 68 assertTrue(mLeftListView.hasFocus()); 69 assertTrue(mLeftMiddleIsv.isFocused()); 70 assertEquals("mLeftMiddleIsv.getSelectedRow()", 1, mLeftMiddleIsv.getSelectedRow()); 71 72 sendKeys(KeyEvent.KEYCODE_DPAD_LEFT); 73 assertTrue(mLeftIsv.isFocused()); 74 assertEquals("mLeftIsv.getSelectedRow()", 1, mLeftIsv.getSelectedRow()); 75 } 76 77 @MediumTest 78 public void testFocusTransfersOutsideOfListWhenNoCandidateInsideHorizontal() { 79 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_DOWN, KeyEvent.KEYCODE_DPAD_RIGHT); 80 81 assertTrue(mLeftListView.hasFocus()); 82 assertTrue(mLeftMiddleIsv.isFocused()); 83 assertEquals(2, mLeftMiddleIsv.getSelectedRow()); 84 85 sendKeys(KeyEvent.KEYCODE_DPAD_RIGHT); 86 assertTrue("mRightListView.hasFocus()", mRightListView.hasFocus()); 87 assertTrue("mRightMiddleIsv.isFocused()", mRightMiddleIsv.isFocused()); 88 assertEquals("mRightMiddleIsv.getSelectedRow()", 2, mRightMiddleIsv.getSelectedRow()); 89 } 90 } 91