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 android.view.Visibility;
     20 import com.android.frameworks.coretests.R;
     21 
     22 import android.test.ActivityInstrumentationTestCase;
     23 import android.test.suitebuilder.annotation.LargeTest;
     24 import android.test.suitebuilder.annotation.MediumTest;
     25 import android.widget.Button;
     26 import android.widget.TextView;
     27 import android.view.View;
     28 import static android.view.KeyEvent.*;
     29 
     30 /**
     31  * Exercises {@link android.view.View}'s ability to change visibility between
     32  * GONE, VISIBLE and INVISIBLE.
     33  */
     34 public class VisibilityTest extends ActivityInstrumentationTestCase<Visibility> {
     35     private TextView mRefUp;
     36     private TextView mRefDown;
     37     private TextView mVictim;
     38     private Button mVisible;
     39     private Button mInvisible;
     40     private Button mGone;
     41 
     42     public VisibilityTest() {
     43         super("com.android.frameworks.coretests", Visibility.class);
     44     }
     45 
     46     @Override
     47     public void setUp() throws Exception {
     48         super.setUp();
     49 
     50         final Visibility a = getActivity();
     51         mRefUp = (TextView) a.findViewById(R.id.refUp);
     52         mRefDown = (TextView) a.findViewById(R.id.refDown);
     53         mVictim = (TextView) a.findViewById(R.id.victim);
     54         mVisible = (Button) a.findViewById(R.id.vis);
     55         mInvisible = (Button) a.findViewById(R.id.invis);
     56         mGone = (Button) a.findViewById(R.id.gone);
     57     }
     58 
     59     @MediumTest
     60     public void testSetUpConditions() throws Exception {
     61         assertNotNull(mRefUp);
     62         assertNotNull(mRefDown);
     63         assertNotNull(mVictim);
     64         assertNotNull(mVisible);
     65         assertNotNull(mInvisible);
     66         assertNotNull(mGone);
     67 
     68         assertTrue(mVisible.hasFocus());
     69     }
     70 
     71     @MediumTest
     72     public void testVisibleToInvisible() throws Exception {
     73         sendKeys("DPAD_RIGHT");
     74         assertTrue(mInvisible.hasFocus());
     75 
     76         int oldTop = mVictim.getTop();
     77 
     78         sendKeys("DPAD_CENTER");
     79         assertEquals(View.INVISIBLE, mVictim.getVisibility());
     80 
     81         int newTop = mVictim.getTop();
     82         assertEquals(oldTop, newTop);
     83     }
     84 
     85     @MediumTest
     86     public void testVisibleToGone() throws Exception {
     87         //sendKeys("2*DPAD_RIGHT");
     88         sendRepeatedKeys(2, KEYCODE_DPAD_RIGHT);
     89         assertTrue(mGone.hasFocus());
     90 
     91         int oldTop = mVictim.getTop();
     92 
     93         sendKeys("DPAD_CENTER");
     94         assertEquals(View.GONE, mVictim.getVisibility());
     95 
     96         int refDownTop = mRefDown.getTop();
     97         assertEquals(oldTop, refDownTop);
     98     }
     99 
    100     @LargeTest
    101     public void testGoneToVisible() throws Exception {
    102         sendKeys("2*DPAD_RIGHT");
    103         assertTrue(mGone.hasFocus());
    104 
    105         int oldTop = mVictim.getTop();
    106 
    107         sendKeys("DPAD_CENTER");
    108         assertEquals(View.GONE, mVictim.getVisibility());
    109 
    110         int refDownTop = mRefDown.getTop();
    111         assertEquals(oldTop, refDownTop);
    112 
    113         sendKeys("2*DPAD_LEFT DPAD_CENTER");
    114         assertEquals(View.VISIBLE, mVictim.getVisibility());
    115 
    116         int newTop = mVictim.getTop();
    117         assertEquals(oldTop, newTop);
    118     }
    119 
    120     @MediumTest
    121     public void testGoneToInvisible() throws Exception {
    122         sendKeys("2*DPAD_RIGHT");
    123         assertTrue(mGone.hasFocus());
    124 
    125         int oldTop = mVictim.getTop();
    126 
    127         sendKeys("DPAD_CENTER");
    128         assertEquals(View.GONE, mVictim.getVisibility());
    129 
    130         int refDownTop = mRefDown.getTop();
    131         assertEquals(oldTop, refDownTop);
    132 
    133         sendKeys(KEYCODE_DPAD_LEFT, KEYCODE_DPAD_CENTER);
    134         assertEquals(View.INVISIBLE, mVictim.getVisibility());
    135 
    136         int newTop = mVictim.getTop();
    137         assertEquals(oldTop, newTop);
    138     }
    139 
    140     @MediumTest
    141     public void testInvisibleToVisible() throws Exception {
    142         sendKeys("DPAD_RIGHT");
    143         assertTrue(mInvisible.hasFocus());
    144 
    145         int oldTop = mVictim.getTop();
    146 
    147         sendKeys("DPAD_CENTER");
    148         assertEquals(View.INVISIBLE, mVictim.getVisibility());
    149 
    150         int newTop = mVictim.getTop();
    151         assertEquals(oldTop, newTop);
    152 
    153         sendKeys("DPAD_LEFT DPAD_CENTER");
    154         assertEquals(View.VISIBLE, mVictim.getVisibility());
    155 
    156         newTop = mVictim.getTop();
    157         assertEquals(oldTop, newTop);
    158     }
    159 
    160     @MediumTest
    161     public void testInvisibleToGone() throws Exception {
    162         sendKeys("DPAD_RIGHT");
    163         assertTrue(mInvisible.hasFocus());
    164 
    165         int oldTop = mVictim.getTop();
    166 
    167         sendKeys("DPAD_CENTER");
    168         assertEquals(View.INVISIBLE, mVictim.getVisibility());
    169 
    170         int newTop = mVictim.getTop();
    171         assertEquals(oldTop, newTop);
    172 
    173         sendKeys("DPAD_RIGHT DPAD_CENTER");
    174         assertEquals(View.GONE, mVictim.getVisibility());
    175 
    176         int refDownTop = mRefDown.getTop();
    177         assertEquals(oldTop, refDownTop);
    178     }
    179 }
    180