Search in sources :

Example 1 with Robolectric.buildActivity

use of org.robolectric.Robolectric.buildActivity in project robolectric by robolectric.

the class ShadowViewTest method removeAllViews_shouldCallOnAttachedToAndDetachedFromWindow.

// todo looks like this is flaky...
@Test
public void removeAllViews_shouldCallOnAttachedToAndDetachedFromWindow() throws Exception {
    MyView parent = new MyView("parent", transcript);
    Activity activity = Robolectric.buildActivity(ContentViewActivity.class).create().get();
    activity.getWindowManager().addView(parent, new WindowManager.LayoutParams(100, 100));
    parent.addView(new MyView("child", transcript));
    parent.addView(new MyView("another child", transcript));
    ShadowLooper.runUiThreadTasks();
    transcript.clear();
    parent.removeAllViews();
    ShadowLooper.runUiThreadTasks();
    assertThat(transcript).containsExactly("another child detached", "child detached");
}
Also used : Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) Test(org.junit.Test)

Example 2 with Robolectric.buildActivity

use of org.robolectric.Robolectric.buildActivity in project robolectric by robolectric.

the class ShadowViewTest method getWindowId_shouldReturnValidObjectWhenAttached.

@Test
@Config(minSdk = JELLY_BEAN_MR2)
public void getWindowId_shouldReturnValidObjectWhenAttached() throws Exception {
    MyView parent = new MyView("parent", transcript);
    MyView child = new MyView("child", transcript);
    parent.addView(child);
    assertThat(parent.getWindowId()).isNull();
    assertThat(child.getWindowId()).isNull();
    Activity activity = Robolectric.buildActivity(ContentViewActivity.class).create().get();
    activity.getWindowManager().addView(parent, new WindowManager.LayoutParams(100, 100));
    WindowId windowId = parent.getWindowId();
    assertThat(windowId).isNotNull();
    assertThat(child.getWindowId()).isSameAs(windowId);
    // equals must work!
    assertThat(child.getWindowId()).isEqualTo(windowId);
    MyView anotherChild = new MyView("another child", transcript);
    parent.addView(anotherChild);
    assertThat(anotherChild.getWindowId()).isEqualTo(windowId);
    parent.removeView(anotherChild);
    assertThat(anotherChild.getWindowId()).isNull();
}
Also used : Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) Test(org.junit.Test) Config(org.robolectric.annotation.Config)

Example 3 with Robolectric.buildActivity

use of org.robolectric.Robolectric.buildActivity in project robolectric by robolectric.

the class ShadowActivityTest method shouldPopulateWindowDecorViewWithMergeLayoutContents.

// unclear what the correct behavior should be here...
@Test
public void shouldPopulateWindowDecorViewWithMergeLayoutContents() throws Exception {
    Activity activity = Robolectric.buildActivity(Activity.class).create().get();
    activity.setContentView(R.layout.toplevel_merge);
    View contentView = activity.findViewById(android.R.id.content);
    assertThat(((ViewGroup) contentView).getChildCount()).isEqualTo(2);
}
Also used : ViewGroup(android.view.ViewGroup) Robolectric.setupActivity(org.robolectric.Robolectric.setupActivity) Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) View(android.view.View) SearchView(android.widget.SearchView) Test(org.junit.Test)

Example 4 with Robolectric.buildActivity

use of org.robolectric.Robolectric.buildActivity in project robolectric by robolectric.

the class ShadowViewTest method shouldCallOnAttachedToAndDetachedFromWindow.

@Test
public void shouldCallOnAttachedToAndDetachedFromWindow() throws Exception {
    MyView parent = new MyView("parent", transcript);
    parent.addView(new MyView("child", transcript));
    assertThat(transcript).isEmpty();
    Activity activity = Robolectric.buildActivity(ContentViewActivity.class).create().get();
    activity.getWindowManager().addView(parent, new WindowManager.LayoutParams(100, 100));
    assertThat(transcript).containsExactly("parent attached", "child attached");
    transcript.clear();
    parent.addView(new MyView("another child", transcript));
    assertThat(transcript).containsExactly("another child attached");
    transcript.clear();
    MyView temporaryChild = new MyView("temporary child", transcript);
    parent.addView(temporaryChild);
    assertThat(transcript).containsExactly("temporary child attached");
    transcript.clear();
    assertTrue(shadowOf(temporaryChild).isAttachedToWindow());
    parent.removeView(temporaryChild);
    assertThat(transcript).containsExactly("temporary child detached");
    assertFalse(shadowOf(temporaryChild).isAttachedToWindow());
}
Also used : Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) Test(org.junit.Test)

Example 5 with Robolectric.buildActivity

use of org.robolectric.Robolectric.buildActivity in project robolectric by robolectric.

the class ShadowViewTest method usesDefaultGlobalVisibleRect.

@Test
public void usesDefaultGlobalVisibleRect() {
    final ActivityController<Activity> activityController = Robolectric.buildActivity(Activity.class);
    final Activity activity = activityController.get();
    activity.setContentView(view, new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT));
    activityController.setup();
    Rect globalVisibleRect = new Rect();
    assertThat(view.getGlobalVisibleRect(globalVisibleRect)).isTrue();
    assertThat(globalVisibleRect).isEqualTo(new Rect(0, 25, 480, 800));
}
Also used : Rect(android.graphics.Rect) Robolectric.buildActivity(org.robolectric.Robolectric.buildActivity) Activity(android.app.Activity) Test(org.junit.Test)

Aggregations

Activity (android.app.Activity)5 Test (org.junit.Test)5 Robolectric.buildActivity (org.robolectric.Robolectric.buildActivity)5 Rect (android.graphics.Rect)1 View (android.view.View)1 ViewGroup (android.view.ViewGroup)1 SearchView (android.widget.SearchView)1 Robolectric.setupActivity (org.robolectric.Robolectric.setupActivity)1 Config (org.robolectric.annotation.Config)1