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

RemoteViewsActivityTest

public class RemoteViewsActivityTest extends android.test.ActivityInstrumentationTestCase

Fields Summary
Constructors Summary
public RemoteViewsActivityTest()

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

        super.setUp();
    
public voidtestDerivedClass()

        final RemoteViewsActivity activity = getActivity();
        
        RemoteViews orig = new RemoteViews("com.android.frameworktest",
                R.layout.remote_view_test_bad_1);
        Parcel p = Parcel.obtain();
        orig.writeToParcel(p, 0);
        p.setDataPosition(0);
        
        RemoteViews r = RemoteViews.CREATOR.createFromParcel(p);
        
        ViewGroup parent = (ViewGroup) activity.findViewById(R.id.parent);
        
        boolean exceptionThrown = false;
        View result = null;
        
        try {
            result = r.apply(activity, parent);
        } catch (InflateException e) {
            exceptionThrown = true;
        }
        
        p.recycle();
        
        assertTrue("Derived class (EditText) allowed to be inflated", exceptionThrown);
        assertNull("Derived class (EditText) allowed to be inflated", result);
    
public voidtestGood()

        final RemoteViewsActivity activity = getActivity();

        RemoteViews orig = new RemoteViews("com.android.frameworktest",
                R.layout.remote_view_test_good);
        Parcel p = Parcel.obtain();
        orig.writeToParcel(p, 0);
        p.setDataPosition(0);
        
        RemoteViews r = RemoteViews.CREATOR.createFromParcel(p);
        
        ViewGroup parent = (ViewGroup) activity.findViewById(R.id.parent);
        
        View result = r.apply(activity, parent);
        
        p.recycle();
        
        assertTrue("LinearLayout not inflated", result.findViewById(R.id.linear) != null);
        assertTrue("TextView not inflated", result.findViewById(R.id.text) != null);
        assertTrue("ImageView not inflated", result.findViewById(R.id.image) != null);
        assertTrue("FrameLayout not inflated", result.findViewById(R.id.frame) != null);
        assertTrue("RelateiveLayout not inflated", result.findViewById(R.id.relative) != null);
        assertTrue("AbsoluteLayout not inflated", result.findViewById(R.id.absolute) != null);
        assertTrue("ProgressBar not inflated", result.findViewById(R.id.progress) != null);
        assertTrue("ImageButton not inflated", result.findViewById(R.id.image_button) != null);
        assertTrue("Button not inflated", result.findViewById(R.id.button) != null);
    
public voidtestWebView()

        final RemoteViewsActivity activity = getActivity();
        
        RemoteViews orig = new RemoteViews("com.android.frameworktest",
                R.layout.remote_view_test_bad_2);
        Parcel p = Parcel.obtain();
        orig.writeToParcel(p, 0);
        p.setDataPosition(0);
        
        RemoteViews r = RemoteViews.CREATOR.createFromParcel(p);
        
        ViewGroup parent = (ViewGroup) activity.findViewById(R.id.parent);
        
        boolean exceptionThrown = false;
        View result = null;
        
        try {
            result = r.apply(activity, parent);
        } catch (InflateException e) {
            exceptionThrown = true;
        }
        
        p.recycle();
        
        assertTrue("WebView allowed to be inflated", exceptionThrown);
        assertNull("WebView allowed to be inflated", result);