use of com.google.android.apps.common.testing.ui.espresso.Root in project double-espresso by JakeWharton.
the class RootMatchers method isDialog.
/**
* Matches {@link Root}s that are dialogs (i.e. is not a window of the currently resumed
* activity).
*/
public static Matcher<Root> isDialog() {
return new TypeSafeMatcher<Root>() {
@Override
public void describeTo(Description description) {
description.appendText("is dialog");
}
@Override
public boolean matchesSafely(Root root) {
int type = root.getWindowLayoutParams().get().type;
if ((type != WindowManager.LayoutParams.TYPE_BASE_APPLICATION && type < WindowManager.LayoutParams.LAST_APPLICATION_WINDOW)) {
IBinder windowToken = root.getDecorView().getWindowToken();
IBinder appToken = root.getDecorView().getApplicationWindowToken();
if (windowToken == appToken) {
// therefore it must be a dialog box.
return true;
}
}
return false;
}
};
}
use of com.google.android.apps.common.testing.ui.espresso.Root in project double-espresso by JakeWharton.
the class RootViewPicker method findRoot.
private Root findRoot(Matcher<Root> rootMatcher) {
waitForAtLeastOneActivityToBeResumed();
roots = rootsOracle.get();
// TODO(user): move these checks into the RootsOracle.
if (roots.isEmpty()) {
// Reflection broke
throw new RuntimeException("No root window were discovered.");
}
if (roots.size() > 1) {
// too.
if (Log.isLoggable(TAG, Log.VERBOSE)) {
Log.v(TAG, String.format("Multiple windows detected: %s", roots));
}
}
List<Root> selectedRoots = Lists.newArrayList();
for (Root root : roots) {
if (rootMatcher.matches(root)) {
selectedRoots.add(root);
}
}
if (selectedRoots.isEmpty()) {
throw NoMatchingRootException.create(rootMatcher, roots);
}
return reduceRoots(selectedRoots);
}
use of com.google.android.apps.common.testing.ui.espresso.Root in project double-espresso by JakeWharton.
the class RootViewPicker method get.
@Override
public View get() {
checkState(Looper.getMainLooper().equals(Looper.myLooper()), "must be called on main thread.");
Matcher<Root> rootMatcher = rootMatcherRef.get();
Root root = findRoot(rootMatcher);
// we only want to propagate a root view that the user can interact with and is not
// about to relay itself out. An app should be in this state the majority of the time,
// if we happen not to be in this state at the moment, process the queue some more
// we should come to it quickly enough.
int loops = 0;
while (!isReady(root)) {
if (loops < 3) {
uiController.loopMainThreadUntilIdle();
} else if (loops < 1001) {
// loopUntil idle effectively is polling and pegs the CPU... if we don't have an update to
// process immediately, we might have something coming very very soon.
uiController.loopMainThreadForAtLeast(10);
} else {
// for over 10 seconds. something is wrong.
throw new RuntimeException(String.format("Waited for the root of the view hierarchy to have" + " window focus and not be requesting layout for over 10 seconds. If you specified a" + " non default root matcher, it may be picking a root that never takes focus." + " Otherwise, something is seriously wrong. Selected Root:\n%s\n. All Roots:\n%s", root, Joiner.on("\n").join(roots)));
}
root = findRoot(rootMatcher);
loops++;
}
return root.getDecorView();
}
Aggregations