1/* 2 * Copyright (C) 2011 Sony Ericsson Mobile Communications AB. 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.arrowscroll.MultiPageTextWithPadding; 20import android.test.ActivityInstrumentationTestCase; 21import android.test.suitebuilder.annotation.LargeTest; 22import android.test.suitebuilder.annotation.MediumTest; 23import android.view.KeyEvent; 24import android.widget.TextView; 25import android.widget.ScrollView; 26 27public class MultiPageTextWithPaddingTest extends 28 ActivityInstrumentationTestCase<MultiPageTextWithPadding> { 29 30 private ScrollView mScrollView; 31 32 private TextView mTextView; 33 34 public MultiPageTextWithPaddingTest() { 35 super("com.android.frameworks.coretests", MultiPageTextWithPadding.class); 36 } 37 38 @Override 39 protected void setUp() throws Exception { 40 super.setUp(); 41 42 mScrollView = getActivity().getScrollView(); 43 mTextView = getActivity().getContentChildAt(0); 44 } 45 46 @MediumTest 47 public void testPreconditions() { 48 assertTrue("text should not fit on screen", 49 mTextView.getHeight() > mScrollView.getHeight()); 50 } 51 52 @LargeTest 53 public void testScrollDownToBottom() throws Exception { 54 // Calculate the number of arrow scrolls needed to reach the bottom 55 int scrollsNeeded = (int)Math.ceil(Math.max(0.0f, 56 (mTextView.getHeight() - mScrollView.getHeight())) 57 / mScrollView.getMaxScrollAmount()); 58 for (int i = 0; i < scrollsNeeded; i++) { 59 sendKeys(KeyEvent.KEYCODE_DPAD_DOWN); 60 } 61 62 assertEquals( 63 "should be fully scrolled to bottom", 64 getActivity().getLinearLayout().getHeight() 65 - (mScrollView.getHeight() - mScrollView.getPaddingTop() - mScrollView 66 .getPaddingBottom()), mScrollView.getScrollY()); 67 } 68} 69