use of com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException in project double-espresso by JakeWharton.
the class RootViewPicker method waitForAtLeastOneActivityToBeResumed.
@SuppressWarnings("unused")
private void waitForAtLeastOneActivityToBeResumed() {
Collection<Activity> resumedActivities = activityLifecycleMonitor.getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.isEmpty()) {
uiController.loopMainThreadUntilIdle();
resumedActivities = activityLifecycleMonitor.getActivitiesInStage(Stage.RESUMED);
}
if (resumedActivities.isEmpty()) {
List<Activity> activities = Lists.newArrayList();
for (Stage s : EnumSet.range(Stage.PRE_ON_CREATE, Stage.RESTARTED)) {
activities.addAll(activityLifecycleMonitor.getActivitiesInStage(s));
}
if (activities.isEmpty()) {
throw new RuntimeException("No activities found. Did you forget to launch the activity " + "by calling getActivity() or startActivitySync or similar?");
}
// well at least there are some activities in the pipeline - lets see if they resume.
long[] waitTimes = { 10, 50, 100, 500, TimeUnit.SECONDS.toMillis(2), TimeUnit.SECONDS.toMillis(30) };
for (int waitIdx = 0; waitIdx < waitTimes.length; waitIdx++) {
Log.w(TAG, "No activity currently resumed - waiting: " + waitTimes[waitIdx] + "ms for one to appear.");
uiController.loopMainThreadForAtLeast(waitTimes[waitIdx]);
resumedActivities = activityLifecycleMonitor.getActivitiesInStage(Stage.RESUMED);
if (!resumedActivities.isEmpty()) {
// one of the pending activities has resumed
return;
}
}
throw new NoActivityResumedException("No activities in stage RESUMED. Did you forget to " + "launch the activity. (test.getActivity() or similar)?");
}
}
use of com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException in project double-espresso by JakeWharton.
the class KeyEventActionIntegrationTest method testClickOnBackFromFragment.
@SuppressWarnings("unchecked")
// uses native fragments.
@SdkSuppress(versions = { 7, 8, 10 }, bugId = -1)
@FlakyTest
public void testClickOnBackFromFragment() {
Intent fragmentStack = new Intent().setClassName(getInstrumentation().getTargetContext(), "com.google.android.apps.common.testing.ui.testapp.FragmentStack");
fragmentStack.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
getInstrumentation().startActivitySync(fragmentStack);
onView(allOf(withParent(withId(R.id.simple_fragment)), isAssignableFrom(TextView.class))).check(matches(withText(containsString("#1"))));
try {
pressBack();
fail("Should have thrown NoActivityResumedException");
} catch (NoActivityResumedException expected) {
}
getInstrumentation().startActivitySync(fragmentStack);
onView(withId(R.id.new_fragment)).perform(click()).perform(click()).perform(click());
onView(allOf(withParent(withId(R.id.simple_fragment)), isAssignableFrom(TextView.class))).check(matches(withText(containsString("#4"))));
pressBack();
onView(allOf(withParent(withId(R.id.simple_fragment)), isAssignableFrom(TextView.class))).check(matches(withText(containsString("#3"))));
pressBack();
onView(allOf(withParent(withId(R.id.simple_fragment)), isAssignableFrom(TextView.class))).check(matches(withText(containsString("#2"))));
pressBack();
onView(allOf(withParent(withId(R.id.simple_fragment)), isAssignableFrom(TextView.class))).check(matches(withText(containsString("#1"))));
try {
pressBack();
fail("Should have thrown NoActivityResumedException");
} catch (NoActivityResumedException expected) {
}
}
use of com.google.android.apps.common.testing.ui.espresso.NoActivityResumedException in project double-espresso by JakeWharton.
the class RootMatchers method getResumedActivityTokens.
private static List<IBinder> getResumedActivityTokens() {
ActivityLifecycleMonitor activityLifecycleMonitor = ActivityLifecycleMonitorRegistry.getInstance();
Collection<Activity> resumedActivities = activityLifecycleMonitor.getActivitiesInStage(Stage.RESUMED);
if (resumedActivities.isEmpty()) {
throw new NoActivityResumedException("At least one activity should be in RESUMED stage.");
}
List<IBinder> tokens = Lists.newArrayList();
for (Activity activity : resumedActivities) {
tokens.add(activity.getWindow().getDecorView().getApplicationWindowToken());
}
return tokens;
}
Aggregations