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 17package android.widget.scroll.arrowscroll; 18 19import android.widget.scroll.TallTextAboveButton; 20 21import android.test.ActivityInstrumentationTestCase; 22import android.test.suitebuilder.annotation.MediumTest; 23import android.view.KeyEvent; 24import android.widget.ScrollView; 25import android.widget.TextView; 26 27public class TallTextAboveButtonTest extends ActivityInstrumentationTestCase<TallTextAboveButton> { 28 private ScrollView mScrollView; 29 private TextView mTopText; 30 private TextView mBottomButton; 31 32 @Override 33 protected void setUp() throws Exception { 34 super.setUp(); 35 36 mScrollView = getActivity().getScrollView(); 37 mTopText = getActivity().getContentChildAt(0); 38 mBottomButton = getActivity().getContentChildAt(1); 39 } 40 41 public TallTextAboveButtonTest() { 42 super("com.android.frameworks.coretests", TallTextAboveButton.class); 43 } 44 45 @MediumTest 46 public void testPreconditions() { 47 assertTrue("top text should be larger than screen", 48 mTopText.getHeight() > mScrollView.getHeight()); 49 assertTrue("scroll view should have focus (because nothing else focusable " 50 + "is on screen), but " + getActivity().getScrollView().findFocus() + " does instead", 51 getActivity().getScrollView().isFocused()); 52 } 53 54 @MediumTest 55 public void testGainFocusAsScrolledOntoScreen() { 56 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 57 58 assertTrue("button should have scrolled onto screen", 59 mBottomButton.getBottom() >= mScrollView.getBottom()); 60 assertTrue("button should have gained focus as it was scrolled completely " 61 + "into view", mBottomButton.isFocused()); 62 63 sendKeys(KeyEvent.KEYCODE_DPAD_UP); 64 assertTrue("scroll view should have focus, but " + getActivity().getScrollView().findFocus() + " does instead", 65 getActivity().getScrollView().isFocused()); 66 } 67 68 @MediumTest 69 public void testScrollingButtonOffScreenLosesFocus() { 70 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 71 assertTrue("button should have focus", mBottomButton.isFocused()); 72 sendKeys(KeyEvent.KEYCODE_DPAD_UP); 73 assertTrue("scroll view should have focus, but " + getActivity().getScrollView().findFocus() + " does instead", 74 getActivity().getScrollView().isFocused()); 75 } 76 77 78} 79