FileDocCategorySizeDatePackage
VisibilityCallbackTest.javaAPI DocAndroid 5.1 API4014Thu Mar 12 22:22:12 GMT 2015android.view

VisibilityCallbackTest

public class VisibilityCallbackTest extends android.test.ActivityInstrumentationTestCase2
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 VisibilityCallback.MonitoredTextView
mVictim
private android.view.ViewGroup
mParent
private android.widget.Button
mVisible
private android.widget.Button
mInvisible
private android.widget.Button
mGone
Constructors Summary
public VisibilityCallbackTest()

        super("com.android.frameworks.coretests", VisibilityCallback.class);
    
Methods Summary
public voidsetUp()

        super.setUp();

        final VisibilityCallback a = getActivity();
        mRefUp = (TextView) a.findViewById(R.id.refUp);
        mRefDown = (TextView) a.findViewById(R.id.refDown);
        mVictim = (VisibilityCallback.MonitoredTextView) a.findViewById(R.id.victim);
        mParent = (ViewGroup) a.findViewById(R.id.parent);
        mVisible = (Button) a.findViewById(R.id.vis);
        mInvisible = (Button) a.findViewById(R.id.invis);
        mGone = (Button) a.findViewById(R.id.gone);

        mVictim.post(new Runnable() {
            public void run() {
                mVictim.setVisibility(View.INVISIBLE);
            }
        });
        getInstrumentation().waitForIdleSync();
     
public voidtestChild()

        mParent.setVisibility(View.INVISIBLE);
        assertEquals(View.INVISIBLE, mVictim.getLastChangedVisibility());
        assertEquals(mParent, mVictim.getLastVisChangedView());

        mParent.setVisibility(View.GONE);
        assertEquals(View.GONE, mVictim.getLastChangedVisibility());
        assertEquals(mParent, mVictim.getLastVisChangedView());

        mParent.setVisibility(View.VISIBLE);
        assertEquals(View.VISIBLE, mVictim.getLastChangedVisibility());
        assertEquals(mParent, mVictim.getLastVisChangedView());
    
public voidtestDirect()

        mVictim.setVisibility(View.VISIBLE);
        assertEquals(View.VISIBLE, mVictim.getLastChangedVisibility());
        assertEquals(mVictim, mVictim.getLastVisChangedView());

        mVictim.setVisibility(View.INVISIBLE);
        assertEquals(View.INVISIBLE, mVictim.getLastChangedVisibility());
        assertEquals(mVictim, mVictim.getLastVisChangedView());

        mVictim.setVisibility(View.GONE);
        assertEquals(View.GONE, mVictim.getLastChangedVisibility());
        assertEquals(mVictim, mVictim.getLastVisChangedView());
    
public voidtestSetUpConditions()

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

        assertTrue(mVisible.hasFocus());
        assertEquals(View.INVISIBLE, mVictim.getVisibility());
        assertEquals(View.VISIBLE, mParent.getVisibility());