Misc test improvements

Ignoring state events from NexusLauncher in Launcher3 tests.
Improving diags for failed app launch.

Change-Id: I3ffb49c598edef7b6698b48ba7b63e6163ef25b4
This commit is contained in:
vadimt 2020-07-24 17:58:26 -07:00
parent 37c01dc58a
commit f8ceabbcc1
4 changed files with 30 additions and 15 deletions

View File

@ -70,7 +70,8 @@ public class AccessibilityManagerCompat {
final Bundle parcel = new Bundle();
parcel.putInt(TestProtocol.STATE_FIELD, stateOrdinal);
sendEventToTest(accessibilityManager, TestProtocol.SWITCHED_TO_STATE_MESSAGE, parcel);
sendEventToTest(
accessibilityManager, context, TestProtocol.SWITCHED_TO_STATE_MESSAGE, parcel);
Log.d(TestProtocol.PERMANENT_DIAG_TAG, "sendStateEventToTest: " + stateOrdinal);
}
@ -78,22 +79,24 @@ public class AccessibilityManagerCompat {
final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context);
if (accessibilityManager == null) return;
sendEventToTest(accessibilityManager, TestProtocol.SCROLL_FINISHED_MESSAGE, null);
sendEventToTest(accessibilityManager, context, TestProtocol.SCROLL_FINISHED_MESSAGE, null);
}
public static void sendPauseDetectedEventToTest(Context context) {
final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context);
if (accessibilityManager == null) return;
sendEventToTest(accessibilityManager, TestProtocol.PAUSE_DETECTED_MESSAGE, null);
sendEventToTest(accessibilityManager, context, TestProtocol.PAUSE_DETECTED_MESSAGE, null);
}
private static void sendEventToTest(
AccessibilityManager accessibilityManager, String eventTag, Bundle data) {
AccessibilityManager accessibilityManager,
Context context, String eventTag, Bundle data) {
final AccessibilityEvent e = AccessibilityEvent.obtain(
AccessibilityEvent.TYPE_ANNOUNCEMENT);
e.setClassName(eventTag);
e.setParcelableData(data);
e.setPackageName(context.getApplicationContext().getPackageName());
accessibilityManager.sendAccessibilityEvent(e);
}

View File

@ -93,7 +93,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
mLauncher.sendPointer(
downTime, downTime, MotionEvent.ACTION_DOWN, start, gestureScope);
mLauncher.executeAndWaitForEvent(
mLauncher.executeAndWaitForLauncherEvent(
() -> mLauncher.movePointer(
downTime,
downTime,

View File

@ -56,15 +56,18 @@ abstract class Launchable {
private Background launch(BySelector selector) {
LauncherInstrumentation.log("Launchable.launch before click " +
mObject.getVisibleCenter() + " in " + mLauncher.getVisibleBounds(mObject));
final String label = mObject.getText();
mLauncher.executeAndWaitForEvent(
() -> mLauncher.clickLauncherObject(mObject),
() -> {
mLauncher.clickLauncherObject(mObject);
expectActivityStartEvents();
},
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
() -> "Launching an app didn't open a new window: " + mObject.getText());
expectActivityStartEvents();
() -> "Launching an app didn't open a new window: " + label);
mLauncher.assertTrue(
"App didn't start: " + selector,
"App didn't start: " + label,
mLauncher.getDevice().wait(Until.hasObject(selector),
LauncherInstrumentation.WAIT_TIME_MS));
return new Background(mLauncher);

View File

@ -103,6 +103,7 @@ public final class LauncherInstrumentation {
static final Pattern EVENT_TOUCH_DOWN_TIS = getTouchEventPatternTIS("ACTION_DOWN");
static final Pattern EVENT_TOUCH_UP_TIS = getTouchEventPatternTIS("ACTION_UP");
private final String mLauncherPackage;
// Types for launcher containers that the user is interacting with. "Background" is a
// pseudo-container corresponding to inactive launcher covered by another app.
@ -216,11 +217,11 @@ public final class LauncherInstrumentation {
// Launcher package. As during inproc tests the tested launcher may not be selected as the
// current launcher, choosing target package for inproc. For out-of-proc, use the installed
// launcher package.
final String authorityPackage = testPackage.equals(targetPackage) ?
getLauncherPackageName() :
targetPackage;
mLauncherPackage = testPackage.equals(targetPackage)
? getLauncherPackageName()
: targetPackage;
String testProviderAuthority = authorityPackage + ".TestInfo";
String testProviderAuthority = mLauncherPackage + ".TestInfo";
mTestProviderUri = new Uri.Builder()
.scheme(ContentResolver.SCHEME_CONTENT)
.authority(testProviderAuthority)
@ -628,6 +629,14 @@ public final class LauncherInstrumentation {
fail("Launcher didn't initialize");
}
Parcelable executeAndWaitForLauncherEvent(Runnable command,
UiAutomation.AccessibilityEventFilter eventFilter, Supplier<String> message) {
return executeAndWaitForEvent(
command,
e -> mLauncherPackage.equals(e.getPackageName()) && eventFilter.accept(e),
message);
}
Parcelable executeAndWaitForEvent(Runnable command,
UiAutomation.AccessibilityEventFilter eventFilter, Supplier<String> message) {
try {
@ -972,7 +981,7 @@ public final class LauncherInstrumentation {
void runToState(Runnable command, int expectedState) {
final List<Integer> actualEvents = new ArrayList<>();
executeAndWaitForEvent(
executeAndWaitForLauncherEvent(
command,
event -> isSwitchToStateEvent(event, expectedState, actualEvents),
() -> "Failed to receive an event for the state change: expected ["
@ -1087,7 +1096,7 @@ public final class LauncherInstrumentation {
return;
}
executeAndWaitForEvent(
executeAndWaitForLauncherEvent(
() -> linearGesture(
startX, startY, endX, endY, steps, slowDown, GestureScope.INSIDE),
event -> TestProtocol.SCROLL_FINISHED_MESSAGE.equals(event.getClassName()),