Adding more diags for TAPL actions

Ones that change Launcher state.

Test: presubmit
Bug: 187761685
Change-Id: I11a29956613a4a211d49ee3df6d78e0000b80ced
This commit is contained in:
vadimt
2021-07-01 18:27:05 -07:00
committed by Vadim Tryshev
parent 3c7bde72f7
commit 7bd2a77144
5 changed files with 85 additions and 81 deletions
@@ -99,12 +99,12 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
end,
gestureScope),
event -> TestProtocol.PAUSE_DETECTED_MESSAGE.equals(event.getClassName()),
() -> "Pause wasn't detected");
() -> "Pause wasn't detected", "swiping and holding");
mLauncher.runToState(
() -> mLauncher.sendPointer(
downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, end,
gestureScope),
OVERVIEW_STATE_ORDINAL);
OVERVIEW_STATE_ORDINAL, "sending UP event");
break;
}
@@ -143,7 +143,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT);
mLauncher.runToState(
() -> mLauncher.waitForNavigationUiObject("recent_apps").click(),
OVERVIEW_STATE_ORDINAL);
OVERVIEW_STATE_ORDINAL, "clicking Recents button");
break;
}
expectSwitchToOverviewEvents();
@@ -224,7 +224,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
() -> mLauncher.linearGesture(
startX, startY, endX, endY, 20, false, gestureScope),
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
() -> "Quick switch gesture didn't change window state");
() -> "Quick switch gesture didn't change window state", "swiping");
break;
}
@@ -238,7 +238,8 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
LauncherInstrumentation.EVENT_TOUCH_UP);
}
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT);
mLauncher.runToState(() -> recentsButton.click(), OVERVIEW_STATE_ORDINAL);
mLauncher.runToState(() -> recentsButton.click(), OVERVIEW_STATE_ORDINAL,
"clicking Recents button for the first time");
mLauncher.getOverview();
if (mLauncher.isTablet()) {
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
@@ -250,7 +251,8 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
mLauncher.executeAndWaitForEvent(
() -> recentsButton.click(),
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
() -> "Pressing recents button didn't change window state");
() -> "Pressing recents button didn't change window state",
"clicking Recents button for the second time");
break;
}
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT);
@@ -56,26 +56,24 @@ abstract class Launchable {
protected abstract String launchableType();
private Background launch(BySelector selector) {
try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
"clicking " + launchableType())) {
LauncherInstrumentation.log("Launchable.launch before click "
+ mObject.getVisibleCenter() + " in " + mLauncher.getVisibleBounds(mObject));
final String label = mObject.getText();
LauncherInstrumentation.log("Launchable.launch before click "
+ mObject.getVisibleCenter() + " in " + mLauncher.getVisibleBounds(mObject));
final String label = mObject.getText();
mLauncher.executeAndWaitForEvent(
() -> {
mLauncher.clickLauncherObject(mObject);
expectActivityStartEvents();
},
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
() -> "Launching an app didn't open a new window: " + label);
mLauncher.executeAndWaitForEvent(
() -> {
mLauncher.clickLauncherObject(mObject);
expectActivityStartEvents();
},
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
() -> "Launching an app didn't open a new window: " + label,
"clicking " + launchableType());
mLauncher.assertTrue(
"App didn't start: " + label + " (" + selector + ")",
TestHelpers.wait(Until.hasObject(selector),
LauncherInstrumentation.WAIT_TIME_MS));
return new Background(mLauncher);
}
mLauncher.assertTrue(
"App didn't start: " + label + " (" + selector + ")",
TestHelpers.wait(Until.hasObject(selector),
LauncherInstrumentation.WAIT_TIME_MS));
return new Background(mLauncher);
}
/**
@@ -666,26 +666,30 @@ public final class LauncherInstrumentation {
}
Parcelable executeAndWaitForLauncherEvent(Runnable command,
UiAutomation.AccessibilityEventFilter eventFilter, Supplier<String> message) {
UiAutomation.AccessibilityEventFilter eventFilter, Supplier<String> message,
String actionName) {
return executeAndWaitForEvent(
command,
e -> mLauncherPackage.equals(e.getPackageName()) && eventFilter.accept(e),
message);
message, actionName);
}
Parcelable executeAndWaitForEvent(Runnable command,
UiAutomation.AccessibilityEventFilter eventFilter, Supplier<String> message) {
try {
final AccessibilityEvent event =
mInstrumentation.getUiAutomation().executeAndWaitForEvent(
command, eventFilter, WAIT_TIME_MS);
assertNotNull("executeAndWaitForEvent returned null (this can't happen)", event);
final Parcelable parcelableData = event.getParcelableData();
event.recycle();
return parcelableData;
} catch (TimeoutException e) {
fail(message.get());
return null;
UiAutomation.AccessibilityEventFilter eventFilter, Supplier<String> message,
String actionName) {
try (LauncherInstrumentation.Closable c = addContextLayer(actionName)) {
try {
final AccessibilityEvent event =
mInstrumentation.getUiAutomation().executeAndWaitForEvent(
command, eventFilter, WAIT_TIME_MS);
assertNotNull("executeAndWaitForEvent returned null (this can't happen)", event);
final Parcelable parcelableData = event.getParcelableData();
event.recycle();
return parcelableData;
} catch (TimeoutException e) {
fail(message.get());
return null;
}
}
}
@@ -731,37 +735,34 @@ public final class LauncherInstrumentation {
dumpViewHierarchy();
action = "swiping up to home";
try (LauncherInstrumentation.Closable c = addContextLayer(action)) {
swipeToState(
displaySize.x / 2, displaySize.y - 1,
displaySize.x / 2, 0,
ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME, NORMAL_STATE_ORDINAL,
launcherWasVisible
? GestureScope.INSIDE_TO_OUTSIDE
: GestureScope.OUTSIDE_WITH_PILFER);
}
swipeToState(
displaySize.x / 2, displaySize.y - 1,
displaySize.x / 2, 0,
ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME, NORMAL_STATE_ORDINAL,
launcherWasVisible
? GestureScope.INSIDE_TO_OUTSIDE
: GestureScope.OUTSIDE_WITH_PILFER);
}
} else {
log("Hierarchy before clicking home:");
dumpViewHierarchy();
action = "clicking home button";
try (LauncherInstrumentation.Closable c = addContextLayer(action)) {
if (!isLauncher3() && getNavigationModel() == NavigationModel.TWO_BUTTON) {
expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_DOWN_TIS);
expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_UP_TIS);
}
if (isTablet()) {
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_TOUCH_DOWN);
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_TOUCH_UP);
}
runToState(
waitForNavigationUiObject("home")::click,
NORMAL_STATE_ORDINAL,
!hasLauncherObject(WORKSPACE_RES_ID)
&& (hasLauncherObject(APPS_RES_ID)
|| hasLauncherObject(OVERVIEW_RES_ID)));
if (!isLauncher3() && getNavigationModel() == NavigationModel.TWO_BUTTON) {
expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_DOWN_TIS);
expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_UP_TIS);
}
if (isTablet()) {
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_TOUCH_DOWN);
expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_TOUCH_UP);
}
runToState(
waitForNavigationUiObject("home")::click,
NORMAL_STATE_ORDINAL,
!hasLauncherObject(WORKSPACE_RES_ID)
&& (hasLauncherObject(APPS_RES_ID)
|| hasLauncherObject(OVERVIEW_RES_ID)),
action);
}
try (LauncherInstrumentation.Closable c = addContextLayer(
"performed action to switch to Home - " + action)) {
@@ -953,7 +954,7 @@ public final class LauncherInstrumentation {
void waitForObjectEnabled(UiObject2 object, String waitReason) {
try {
assertTrue("Timed out waiting for object to be enabled for " + waitReason + " "
+ object.getResourceName(),
+ object.getResourceName(),
object.wait(Until.enabled(true), WAIT_TIME_MS));
} catch (StaleObjectException e) {
fail("The object disappeared from screen");
@@ -1056,22 +1057,23 @@ public final class LauncherInstrumentation {
+ "]";
}
void runToState(Runnable command, int expectedState, boolean requireEvent) {
void runToState(Runnable command, int expectedState, boolean requireEvent, String actionName) {
if (requireEvent) {
runToState(command, expectedState);
runToState(command, expectedState, actionName);
} else {
command.run();
}
}
void runToState(Runnable command, int expectedState) {
void runToState(Runnable command, int expectedState, String actionName) {
final List<Integer> actualEvents = new ArrayList<>();
executeAndWaitForLauncherEvent(
command,
event -> isSwitchToStateEvent(event, expectedState, actualEvents),
() -> "Failed to receive an event for the state change: expected ["
+ TestProtocol.stateOrdinalToString(expectedState)
+ "], actual: " + eventListToString(actualEvents));
+ "], actual: " + eventListToString(actualEvents),
actionName);
}
private boolean isSwitchToStateEvent(
@@ -1088,7 +1090,8 @@ public final class LauncherInstrumentation {
GestureScope gestureScope) {
runToState(
() -> linearGesture(startX, startY, endX, endY, steps, false, gestureScope),
expectedState);
expectedState,
"swiping");
}
private int getBottomGestureSize() {
@@ -1196,7 +1199,8 @@ public final class LauncherInstrumentation {
startX, startY, endX, endY, steps, slowDown, GestureScope.INSIDE),
event -> TestProtocol.SCROLL_FINISHED_MESSAGE.equals(event.getClassName()),
() -> "Didn't receive a scroll end message: " + startX + ", " + startY
+ ", " + endX + ", " + endY);
+ ", " + endX + ", " + endY,
"scrolling");
}
// Inject a swipe gesture. Inject exactly 'steps' motion points, incrementing event time by a
@@ -71,15 +71,13 @@ public final class OverviewTask {
public Background open() {
try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
verifyActiveContainer();
try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
"clicking an overview task")) {
mLauncher.executeAndWaitForEvent(
() -> mLauncher.clickLauncherObject(mTask),
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
() -> "Launching task didn't open a new window: "
+ mTask.getParent().getContentDescription());
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT);
}
mLauncher.executeAndWaitForEvent(
() -> mLauncher.clickLauncherObject(mTask),
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
() -> "Launching task didn't open a new window: "
+ mTask.getParent().getContentDescription(),
"clicking an overview task");
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT);
return new Background(mLauncher);
}
}
@@ -190,13 +190,15 @@ public final class Workspace extends Home {
launcher.movePointer(launchableCenter, dest, 10, downTime, true,
LauncherInstrumentation.GestureScope.INSIDE);
},
SPRING_LOADED_STATE_ORDINAL);
SPRING_LOADED_STATE_ORDINAL,
"long-pressing and moving");
LauncherInstrumentation.log("dragIconToWorkspace: moved pointer");
launcher.runToState(
() -> launcher.sendPointer(
downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, dest,
LauncherInstrumentation.GestureScope.INSIDE),
NORMAL_STATE_ORDINAL);
NORMAL_STATE_ORDINAL,
"sending UP event");
if (startsActivity || isWidgetShortcut) {
launcher.expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_START);
}