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