From 461038d5d5dcab545e3553b9ff83ead98cfdbb1b Mon Sep 17 00:00:00 2001 From: Anushree Ganjam Date: Thu, 7 Mar 2024 12:24:14 -0800 Subject: [PATCH] Remove expecting DOWN events in TAPL tests. ACTION_UP is always preceded by ACTION_DOWN which means when launcher receives an UP events, down event is obviously sent. In b/325377690 , we started seeing only in P9 devices the DOWN events didn't reach TAPL. I added InputDispatcher logs which shows both DOWN and UP events are sent by system_server to NexusLauncher. However TAPL doesn't receive it. After spending lot of time debugging this, I think we are safe to remove DOWN event expectation in TAPL. Bug: 325377690 Test: Manual, TAPL presubmits Flag: NA Change-Id: I6d3587c488d45e3dc53d2c1c4f3b6b49285eae94 --- src/com/android/launcher3/testing/TestLogging.java | 9 ++++++++- tests/tapl/com/android/launcher3/tapl/AllApps.java | 4 ---- .../tapl/com/android/launcher3/tapl/BaseOverview.java | 5 ----- .../android/launcher3/tapl/KeyboardQuickSwitch.java | 10 ---------- .../launcher3/tapl/LauncherInstrumentation.java | 4 ---- .../com/android/launcher3/tapl/SelectModeButtons.java | 4 ---- tests/tapl/com/android/launcher3/tapl/Workspace.java | 5 ----- 7 files changed, 8 insertions(+), 33 deletions(-) diff --git a/src/com/android/launcher3/testing/TestLogging.java b/src/com/android/launcher3/testing/TestLogging.java index 60d0e95c90..459fa070e5 100644 --- a/src/com/android/launcher3/testing/TestLogging.java +++ b/src/com/android/launcher3/testing/TestLogging.java @@ -62,7 +62,14 @@ public final class TestLogging { public static void recordKeyEvent(String sequence, String message, KeyEvent event) { if (Utilities.isRunningInTestHarness()) { - recordEventSlow(sequence, message + ": " + event, true); + // This removes expecting ACTION_DOWN key event in the test. ACTION_UP is + // always preceded by ACTION_DOWN. + // Sometimes test doesn't receive ACTION_DOWN key event and we will assume that + // Launcher relies only on ACTION_UP. + // However in the test we will send both ACTION_DOWN and ACTION_UP key events. + // But stop reporting to tapl if action is down. + boolean reportToTapl = event.getAction() != KeyEvent.ACTION_DOWN; + recordEventSlow(sequence, message + ": " + event, reportToTapl); registerEventNotFromTest(event); } } diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index 9591891ba3..847dc4b627 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -56,9 +56,6 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background"; private static final String FAST_SCROLLER_RES_ID = "fast_scroller"; - - private static final Pattern EVENT_ALT_ESC_DOWN = Pattern.compile( - "Key event: KeyEvent.*?action=ACTION_DOWN.*?keyCode=KEYCODE_ESCAPE.*?metaState=0"); private static final Pattern EVENT_ALT_ESC_UP = Pattern.compile( "Key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_ESCAPE.*?metaState=0"); @@ -407,7 +404,6 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer /** Presses the esc key to dismiss AllApps. */ public void dismissByEscKey() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { - mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_DOWN); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_UP); mLauncher.runToState( () -> mLauncher.getDevice().pressKeyCode(KEYCODE_ESCAPE), diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java index 4f20c5757c..3f70bb906f 100644 --- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java @@ -45,9 +45,6 @@ import java.util.stream.Collectors; */ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { protected static final String TASK_RES_ID = "task"; - - private static final Pattern EVENT_ALT_ESC_DOWN = Pattern.compile( - "Key event: KeyEvent.*?action=ACTION_DOWN.*?keyCode=KEYCODE_ESCAPE.*?metaState=0"); private static final Pattern EVENT_ALT_ESC_UP = Pattern.compile( "Key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_ESCAPE.*?metaState=0"); private static final Pattern EVENT_ENTER_DOWN = Pattern.compile( @@ -413,7 +410,6 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { */ public Workspace dismissByEscKey() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { - mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_DOWN); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_UP); mLauncher.runToState( () -> mLauncher.getDevice().pressKeyCode(KEYCODE_ESCAPE), @@ -432,7 +428,6 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { */ public LaunchedAppState launchFocusedTaskByEnterKey(@NonNull String expectedPackageName) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { - mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ENTER_DOWN); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ENTER_UP); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT); diff --git a/tests/tapl/com/android/launcher3/tapl/KeyboardQuickSwitch.java b/tests/tapl/com/android/launcher3/tapl/KeyboardQuickSwitch.java index 5ef82ca897..7ff55fe5cf 100644 --- a/tests/tapl/com/android/launcher3/tapl/KeyboardQuickSwitch.java +++ b/tests/tapl/com/android/launcher3/tapl/KeyboardQuickSwitch.java @@ -37,15 +37,9 @@ public final class KeyboardQuickSwitch { private static final Pattern EVENT_ALT_TAB_UP = Pattern.compile( "KeyboardQuickSwitchView key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_TAB" + ".*?metaState=META_ALT_ON"); - private static final Pattern EVENT_ALT_SHIFT_TAB_DOWN = Pattern.compile( - "KeyboardQuickSwitchView key event: KeyEvent.*?action=ACTION_DOWN.*?keyCode=KEYCODE_TAB" - + ".*?metaState=META_ALT_ON|META_SHIFT_ON"); private static final Pattern EVENT_ALT_SHIFT_TAB_UP = Pattern.compile( "KeyboardQuickSwitchView key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_TAB" + ".*?metaState=META_ALT_ON|META_SHIFT_ON"); - private static final Pattern EVENT_ALT_ESC_DOWN = Pattern.compile( - "KeyboardQuickSwitchView key event: KeyEvent.*?action=ACTION_DOWN" - + ".*?keyCode=KEYCODE_ESCAPE.*?metaState=META_ALT_ON"); private static final Pattern EVENT_ALT_ESC_UP = Pattern.compile( "KeyboardQuickSwitchView key event: KeyEvent.*?action=ACTION_UP" + ".*?keyCode=KEYCODE_ESCAPE.*?metaState=META_ALT_ON"); @@ -87,8 +81,6 @@ public final class KeyboardQuickSwitch { "want to move keyboard quick switch focus forward"); LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { mLauncher.waitForLauncherObject(KEYBOARD_QUICK_SWITCH_RES_ID); - - mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_TAB_DOWN); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_TAB_UP); mLauncher.assertTrue("Failed to press alt+tab", mLauncher.getDevice().pressKeyCode( @@ -122,7 +114,6 @@ public final class KeyboardQuickSwitch { LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { mLauncher.waitForLauncherObject(KEYBOARD_QUICK_SWITCH_RES_ID); - mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_SHIFT_TAB_DOWN); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_SHIFT_TAB_UP); mLauncher.assertTrue("Failed to press alt+shift+tab", mLauncher.getDevice().pressKeyCode( @@ -150,7 +141,6 @@ public final class KeyboardQuickSwitch { LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { mLauncher.waitForLauncherObject(KEYBOARD_QUICK_SWITCH_RES_ID); - mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_DOWN); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_UP); mLauncher.assertTrue("Failed to press alt+tab", mLauncher.getDevice().pressKeyCode( diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 70a53368a5..0e2735f7e1 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -114,9 +114,6 @@ public final class LauncherInstrumentation { static final Pattern EVENT_PILFER_POINTERS = Pattern.compile("pilferPointers"); static final Pattern EVENT_START = Pattern.compile("start:"); - - private static final Pattern EVENT_KEY_BACK_DOWN = - getKeyEventPattern("ACTION_DOWN", "KEYCODE_BACK"); private static final Pattern EVENT_KEY_BACK_UP = getKeyEventPattern("ACTION_UP", "KEYCODE_BACK"); private static final Pattern EVENT_ON_BACK_INVOKED = Pattern.compile("onBackInvoked"); @@ -1218,7 +1215,6 @@ public final class LauncherInstrumentation { .isOnBackInvokedCallbackEnabled()) { expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ON_BACK_INVOKED); } else { - expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_KEY_BACK_DOWN); expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_KEY_BACK_UP); } } diff --git a/tests/tapl/com/android/launcher3/tapl/SelectModeButtons.java b/tests/tapl/com/android/launcher3/tapl/SelectModeButtons.java index e2bc17bfb4..6d2631f4de 100644 --- a/tests/tapl/com/android/launcher3/tapl/SelectModeButtons.java +++ b/tests/tapl/com/android/launcher3/tapl/SelectModeButtons.java @@ -33,9 +33,6 @@ import java.util.regex.Pattern; public class SelectModeButtons { private final UiObject2 mSelectModeButtons; private final LauncherInstrumentation mLauncher; - - private static final Pattern EVENT_ALT_ESC_DOWN = Pattern.compile( - "Key event: KeyEvent.*?action=ACTION_DOWN.*?keyCode=KEYCODE_ESCAPE.*?metaState=0"); private static final Pattern EVENT_ALT_ESC_UP = Pattern.compile( "Key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_ESCAPE.*?metaState=0"); @@ -69,7 +66,6 @@ public class SelectModeButtons { @NonNull public Overview dismissByEscKey() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { - mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_DOWN); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_ALT_ESC_UP); mLauncher.runToState( () -> mLauncher.getDevice().pressKeyCode(KEYCODE_ESCAPE), diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 4e926341b6..d176136e19 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -66,10 +66,6 @@ public final class Workspace extends Home { private static final String DROP_BAR_RES_ID = "drop_target_bar"; private static final String DELETE_TARGET_TEXT_ID = "delete_target_text"; private static final String UNINSTALL_TARGET_TEXT_ID = "uninstall_target_text"; - - static final Pattern EVENT_CTRL_W_DOWN = Pattern.compile( - "Key event: KeyEvent.*?action=ACTION_DOWN.*?keyCode=KEYCODE_W" - + ".*?metaState=META_CTRL_ON"); static final Pattern EVENT_CTRL_W_UP = Pattern.compile( "Key event: KeyEvent.*?action=ACTION_UP.*?keyCode=KEYCODE_W" + ".*?metaState=META_CTRL_ON"); @@ -822,7 +818,6 @@ public final class Workspace extends Home { public Widgets openAllWidgets() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { verifyActiveContainer(); - mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_CTRL_W_DOWN); mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, EVENT_CTRL_W_UP); mLauncher.getDevice().pressKeyCode(KeyEvent.KEYCODE_W, KeyEvent.META_CTRL_ON); try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer("pressed Ctrl+W")) {