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");
}
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();
}
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);
}
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());
}
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));
}
Aggregations