use of com.google.android.apps.common.testing.testrunner.Stage 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.testrunner.Stage in project double-espresso by JakeWharton.
the class EventInjectorTest method testInjectMotionEvent_upEventFailure.
@LargeTest
public void testInjectMotionEvent_upEventFailure() throws InterruptedException {
final CountDownLatch activityStarted = new CountDownLatch(1);
ActivityLifecycleCallback callback = new ActivityLifecycleCallback() {
@Override
public void onActivityLifecycleChanged(Activity activity, Stage stage) {
if (Stage.RESUMED == stage && activity instanceof SendActivity) {
activityStarted.countDown();
}
}
};
ActivityLifecycleMonitorRegistry.getInstance().addLifecycleCallback(callback);
try {
getActivity();
assertTrue(activityStarted.await(20, TimeUnit.SECONDS));
final int[] xy = UiControllerImplIntegrationTest.getCoordinatesInMiddleOfSendButton(getActivity(), getInstrumentation());
getInstrumentation().runOnMainSync(new Runnable() {
@Override
public void run() {
MotionEvent up = MotionEvent.obtain(SystemClock.uptimeMillis(), SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, xy[0], xy[1], 0);
try {
injectEventWorked.set(injector.injectMotionEvent(up));
} catch (InjectEventSecurityException e) {
Log.e(TAG, "injectEvent threw a SecurityException");
}
up.recycle();
latch.countDown();
}
});
latch.await(10, TimeUnit.SECONDS);
assertFalse(injectEventWorked.get());
} finally {
ActivityLifecycleMonitorRegistry.getInstance().removeLifecycleCallback(callback);
}
}
Aggregations