From 9960884744d7f439628c7a38fdfe258e7c2350af Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 1 Jul 2021 18:27:05 -0700 Subject: [PATCH] Adding more diags for TAPL actions that change Launcher state Test: presubmit Bug: 187761685 Change-Id: Ia3effe12d9c0448fe3b15909662755ee35b8ef51 Merged-In: I11a29956613a4a211d49ee3df6d78e0000b80ced --- .../android/launcher3/tapl/Background.java | 14 +-- .../android/launcher3/tapl/Launchable.java | 34 ++++---- .../tapl/LauncherInstrumentation.java | 86 ++++++++++--------- .../android/launcher3/tapl/OverviewTask.java | 16 ++-- .../com/android/launcher3/tapl/Workspace.java | 6 +- 5 files changed, 80 insertions(+), 76 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java index e86be2af1e..4b1610efdd 100644 --- a/tests/tapl/com/android/launcher3/tapl/Background.java +++ b/tests/tapl/com/android/launcher3/tapl/Background.java @@ -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; } @@ -137,7 +137,7 @@ public class Background extends LauncherInstrumentation.VisibleContainer { mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT); mLauncher.runToState( () -> mLauncher.waitForSystemUiObject("recent_apps").click(), - OVERVIEW_STATE_ORDINAL); + OVERVIEW_STATE_ORDINAL, "clicking Recents button"); break; } expectSwitchToOverviewEvents(); @@ -218,7 +218,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; } @@ -226,13 +226,15 @@ public class Background extends LauncherInstrumentation.VisibleContainer { // Double press the recents button. UiObject2 recentsButton = mLauncher.waitForSystemUiObject("recent_apps"); 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(); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT); 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); diff --git a/tests/tapl/com/android/launcher3/tapl/Launchable.java b/tests/tapl/com/android/launcher3/tapl/Launchable.java index ec0a740dca..a15131dbfc 100644 --- a/tests/tapl/com/android/launcher3/tapl/Launchable.java +++ b/tests/tapl/com/android/launcher3/tapl/Launchable.java @@ -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); } /** diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index af3617529a..13576588ef 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -655,26 +655,30 @@ public final class LauncherInstrumentation { } Parcelable executeAndWaitForLauncherEvent(Runnable command, - UiAutomation.AccessibilityEventFilter eventFilter, Supplier message) { + UiAutomation.AccessibilityEventFilter eventFilter, Supplier 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 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 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; + } } } @@ -720,33 +724,30 @@ 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); - } - - runToState( - waitForSystemUiObject("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); } + + runToState( + waitForSystemUiObject("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)) { @@ -1022,22 +1023,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 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( @@ -1054,7 +1056,8 @@ public final class LauncherInstrumentation { GestureScope gestureScope) { runToState( () -> linearGesture(startX, startY, endX, endY, steps, false, gestureScope), - expectedState); + expectedState, + "swiping"); } private int getBottomGestureSize() { @@ -1161,7 +1164,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 diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java index b2359190ba..657b74d116 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java @@ -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); } } diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 1ea0922029..43134d95ad 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -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); }