FileDocCategorySizeDatePackage
VisibilityTest.javaAPI DocAndroid 1.5 API5341Wed May 06 22:42:02 BST 2009com.android.frameworktest.view

VisibilityTest

public class VisibilityTest extends android.test.ActivityInstrumentationTestCase
Exercises {@link android.view.View}'s ability to change visibility between GONE, VISIBLE and INVISIBLE.

Fields Summary
private android.widget.TextView
mRefUp
private android.widget.TextView
mRefDown
private android.widget.TextView
mVictim
private android.widget.Button
mVisible
private android.widget.Button
mInvisible
private android.widget.Button
mGone
Constructors Summary
public VisibilityTest()

        super("com.android.frameworktest", Visibility.class);
    
Methods Summary
public voidsetUp()

        super.setUp();

        final Visibility a = getActivity();
        mRefUp = (TextView) a.findViewById(R.id.refUp);
        mRefDown = (TextView) a.findViewById(R.id.refDown);
        mVictim = (TextView) a.findViewById(R.id.victim);
        mVisible = (Button) a.findViewById(R.id.vis);
        mInvisible = (Button) a.findViewById(R.id.invis);
        mGone = (Button) a.findViewById(R.id.gone);
    
public voidtestGoneToInvisible()

        sendKeys("2*DPAD_RIGHT");
        assertTrue(mGone.hasFocus());

        int oldTop = mVictim.getTop();

        sendKeys("DPAD_CENTER");
        assertEquals(View.GONE, mVictim.getVisibility());

        int refDownTop = mRefDown.getTop();
        assertEquals(oldTop, refDownTop);

        sendKeys(KEYCODE_DPAD_LEFT, KEYCODE_DPAD_CENTER);
        assertEquals(View.INVISIBLE, mVictim.getVisibility());

        int newTop = mVictim.getTop();
        assertEquals(oldTop, newTop);
    
public voidtestGoneToVisible()

        sendKeys("2*DPAD_RIGHT");
        assertTrue(mGone.hasFocus());

        int oldTop = mVictim.getTop();

        sendKeys("DPAD_CENTER");
        assertEquals(View.GONE, mVictim.getVisibility());

        int refDownTop = mRefDown.getTop();
        assertEquals(oldTop, refDownTop);

        sendKeys("2*DPAD_LEFT DPAD_CENTER");
        assertEquals(View.VISIBLE, mVictim.getVisibility());

        int newTop = mVictim.getTop();
        assertEquals(oldTop, newTop);
    
public voidtestInvisibleToGone()

        sendKeys("DPAD_RIGHT");        
        assertTrue(mInvisible.hasFocus());

        int oldTop = mVictim.getTop();

        sendKeys("DPAD_CENTER");
        assertEquals(View.INVISIBLE, mVictim.getVisibility());

        int newTop = mVictim.getTop();
        assertEquals(oldTop, newTop);

        sendKeys("DPAD_RIGHT DPAD_CENTER");
        assertEquals(View.GONE, mVictim.getVisibility());

        int refDownTop = mRefDown.getTop();
        assertEquals(oldTop, refDownTop);
    
public voidtestInvisibleToVisible()

        sendKeys("DPAD_RIGHT");
        assertTrue(mInvisible.hasFocus());

        int oldTop = mVictim.getTop();

        sendKeys("DPAD_CENTER");
        assertEquals(View.INVISIBLE, mVictim.getVisibility());

        int newTop = mVictim.getTop();
        assertEquals(oldTop, newTop);

        sendKeys("DPAD_LEFT DPAD_CENTER");
        assertEquals(View.VISIBLE, mVictim.getVisibility());

        newTop = mVictim.getTop();
        assertEquals(oldTop, newTop);
    
public voidtestSetUpConditions()

        assertNotNull(mRefUp);
        assertNotNull(mRefDown);
        assertNotNull(mVictim);
        assertNotNull(mVisible);
        assertNotNull(mInvisible);
        assertNotNull(mGone);

        assertTrue(mVisible.hasFocus());
    
public voidtestVisibleToGone()

        //sendKeys("2*DPAD_RIGHT");
        sendRepeatedKeys(2, KEYCODE_DPAD_RIGHT);
        assertTrue(mGone.hasFocus());

        int oldTop = mVictim.getTop();

        sendKeys("DPAD_CENTER");
        assertEquals(View.GONE, mVictim.getVisibility());

        int refDownTop = mRefDown.getTop();
        assertEquals(oldTop, refDownTop);
    
public voidtestVisibleToInvisible()

        sendKeys("DPAD_RIGHT");
        assertTrue(mInvisible.hasFocus());

        int oldTop = mVictim.getTop();

        sendKeys("DPAD_CENTER");
        assertEquals(View.INVISIBLE, mVictim.getVisibility());

        int newTop = mVictim.getTop();
        assertEquals(oldTop, newTop);