Home | History | Annotate | Download | only in view
      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.view;
     18 
     19 import com.android.frameworks.coretests.R;
     20 import android.view.DrawableBgMinSize;
     21 import android.test.TouchUtils;
     22 import android.test.suitebuilder.annotation.MediumTest;
     23 
     24 import android.graphics.drawable.Drawable;
     25 import android.test.ActivityInstrumentationTestCase;
     26 import android.view.View;
     27 import android.widget.AbsoluteLayout;
     28 import android.widget.Button;
     29 import android.widget.FrameLayout;
     30 import android.widget.LinearLayout;
     31 import android.widget.RelativeLayout;
     32 import android.widget.TextView;
     33 
     34 /**
     35  * {@link DrawableBgMinSize} exercises Views to obey their background drawable's
     36  * minimum sizes.
     37  */
     38 public class DrawableBgMinSizeTest extends
     39         ActivityInstrumentationTestCase<DrawableBgMinSize> {
     40     private Button mChangeBackgroundsButton;
     41 
     42     private Drawable mBackgroundDrawable;
     43     private Drawable mBigBackgroundDrawable;
     44 
     45     private TextView mTextView;
     46     private LinearLayout mLinearLayout;
     47     private RelativeLayout mRelativeLayout;
     48     private FrameLayout mFrameLayout;
     49     private AbsoluteLayout mAbsoluteLayout;
     50 
     51     public DrawableBgMinSizeTest() {
     52         super("com.android.frameworks.coretests", DrawableBgMinSize.class);
     53     }
     54 
     55     @Override
     56     protected void setUp() throws Exception {
     57         super.setUp();
     58 
     59         final DrawableBgMinSize a = getActivity();
     60 
     61         mChangeBackgroundsButton = (Button) a.findViewById(R.id.change_backgrounds);
     62         mBackgroundDrawable = a.getResources().getDrawable(R.drawable.drawable_background);
     63         mBigBackgroundDrawable = a.getResources().getDrawable(R.drawable.big_drawable_background);
     64         mTextView = (TextView) a.findViewById(R.id.text_view);
     65         mLinearLayout = (LinearLayout) a.findViewById(R.id.linear_layout);
     66         mRelativeLayout = (RelativeLayout) a.findViewById(R.id.relative_layout);
     67         mFrameLayout = (FrameLayout) a.findViewById(R.id.frame_layout);
     68         mAbsoluteLayout = (AbsoluteLayout) a.findViewById(R.id.absolute_layout);
     69     }
     70 
     71     @MediumTest
     72     public void testSetUpConditions() throws Exception {
     73         assertNotNull(mChangeBackgroundsButton);
     74         assertNotNull(mBackgroundDrawable);
     75         assertNotNull(mBigBackgroundDrawable);
     76         assertNotNull(mTextView);
     77         assertNotNull(mLinearLayout);
     78         assertNotNull(mRelativeLayout);
     79         assertNotNull(mFrameLayout);
     80         assertNotNull(mAbsoluteLayout);
     81     }
     82 
     83     public void doMinimumSizeTest(View view) throws Exception {
     84         assertTrue(view.getClass().getSimpleName() + " should respect the background Drawable's minimum width",
     85                 view.getWidth() >= mBackgroundDrawable.getMinimumWidth());
     86         assertTrue(view.getClass().getSimpleName() + " should respect the background Drawable's minimum height",
     87                 view.getHeight() >= mBackgroundDrawable.getMinimumHeight());
     88     }
     89 
     90     @MediumTest
     91     public void testTextViewMinimumSize() throws Exception {
     92         doMinimumSizeTest(mTextView);
     93     }
     94 
     95     @MediumTest
     96     public void testLinearLayoutMinimumSize() throws Exception {
     97         doMinimumSizeTest(mLinearLayout);
     98     }
     99 
    100     @MediumTest
    101     public void testRelativeLayoutMinimumSize() throws Exception {
    102         doMinimumSizeTest(mRelativeLayout);
    103     }
    104 
    105     @MediumTest
    106     public void testAbsoluteLayoutMinimumSize() throws Exception {
    107         doMinimumSizeTest(mAbsoluteLayout);
    108     }
    109 
    110     @MediumTest
    111     public void testFrameLayoutMinimumSize() throws Exception {
    112         doMinimumSizeTest(mFrameLayout);
    113     }
    114 
    115     public void doDiffBgMinimumSizeTest(final View view) throws Exception {
    116         // Change to the bigger backgrounds
    117         TouchUtils.tapView(this, mChangeBackgroundsButton);
    118 
    119         assertTrue(view.getClass().getSimpleName()
    120                 + " should respect the different bigger background Drawable's minimum width", view
    121                 .getWidth() >= mBigBackgroundDrawable.getMinimumWidth());
    122         assertTrue(view.getClass().getSimpleName()
    123                 + " should respect the different bigger background Drawable's minimum height", view
    124                 .getHeight() >= mBigBackgroundDrawable.getMinimumHeight());
    125     }
    126 
    127     @MediumTest
    128     public void testTextViewDiffBgMinimumSize() throws Exception {
    129         doDiffBgMinimumSizeTest(mTextView);
    130     }
    131 
    132     @MediumTest
    133     public void testLinearLayoutDiffBgMinimumSize() throws Exception {
    134         doDiffBgMinimumSizeTest(mLinearLayout);
    135     }
    136 
    137     @MediumTest
    138     public void testRelativeLayoutDiffBgMinimumSize() throws Exception {
    139         doDiffBgMinimumSizeTest(mRelativeLayout);
    140     }
    141 
    142     @MediumTest
    143     public void testAbsoluteLayoutDiffBgMinimumSize() throws Exception {
    144         doDiffBgMinimumSizeTest(mAbsoluteLayout);
    145     }
    146 
    147     @MediumTest
    148     public void testFrameLayoutDiffBgMinimumSize() throws Exception {
    149         doDiffBgMinimumSizeTest(mFrameLayout);
    150     }
    151 
    152 }
    153