From 311d5192921768e3306084bcea02ca4e2c332ff8 Mon Sep 17 00:00:00 2001 From: Jagrut Desai Date: Wed, 13 Sep 2023 10:18:02 -0700 Subject: [PATCH] Fix TaplTestsNexus#testSearchForApp This cl is 1/2 part change We are currently getting StaleObjectException when running this test. We want to implment a synchoronized event beetween test and launcher, so we know that search result adapter is done updating and page will get no more updates of search results. Test: Presubmit Bug: 232008758 Flag: not needed Change-Id: I40cf9b83d231a2487220aabc8f8e8c3ca71f255c --- .../quickstep/util/MotionPauseDetector.java | 5 +++- .../android/quickstep/views/RecentsView.java | 4 ++- .../launcher3/FastScrollRecyclerView.java | 5 +++- src/com/android/launcher3/PagedView.java | 4 ++- .../compat/AccessibilityManagerCompat.java | 30 ++----------------- src/com/android/launcher3/folder/Folder.java | 4 ++- .../testing/shared/TestProtocol.java | 1 + .../launcher3/tapl/SearchResultFromQsb.java | 9 ++++-- 8 files changed, 27 insertions(+), 35 deletions(-) diff --git a/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java b/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java index 4bc41bc4ca..a8a96ce79e 100644 --- a/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java +++ b/quickstep/src/com/android/quickstep/util/MotionPauseDetector.java @@ -15,6 +15,8 @@ */ package com.android.quickstep.util; +import static com.android.launcher3.testing.shared.TestProtocol.PAUSE_DETECTED_MESSAGE; + import android.content.Context; import android.content.res.Resources; import android.util.Log; @@ -201,7 +203,8 @@ public class MotionPauseDetector { ActiveGestureLog.INSTANCE.addLog(logString); boolean isFirstDetectedPause = !mHasEverBeenPaused && mIsPaused; if (mIsPaused) { - AccessibilityManagerCompat.sendPauseDetectedEventToTest(mContext); + AccessibilityManagerCompat.sendTestProtocolEventToTest(mContext, + PAUSE_DETECTED_MESSAGE); mHasEverBeenPaused = true; } if (mOnMotionPauseListener != null) { diff --git a/quickstep/src/com/android/quickstep/views/RecentsView.java b/quickstep/src/com/android/quickstep/views/RecentsView.java index 7cf47ce7dd..c8080b66e6 100644 --- a/quickstep/src/com/android/quickstep/views/RecentsView.java +++ b/quickstep/src/com/android/quickstep/views/RecentsView.java @@ -47,6 +47,7 @@ import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCH import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASK_CLEAR_ALL; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASK_DISMISS_SWIPE_UP; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_TASK_LAUNCH_SWIPE_DOWN; +import static com.android.launcher3.testing.shared.TestProtocol.DISMISS_ANIMATION_ENDS_MESSAGE; import static com.android.launcher3.touch.PagedOrientationHandler.CANVAS_TRANSLATE; import static com.android.launcher3.util.Executors.MAIN_EXECUTOR; import static com.android.launcher3.util.Executors.UI_HELPER_EXECUTOR; @@ -4035,7 +4036,8 @@ public abstract class RecentsView extends ViewGrou */ protected void onPageEndTransition() { mCurrentPageScrollDiff = 0; - AccessibilityManagerCompat.sendScrollFinishedEventToTest(getContext()); + AccessibilityManagerCompat.sendTestProtocolEventToTest(getContext(), + SCROLL_FINISHED_MESSAGE); AccessibilityManagerCompat.sendCustomAccessibilityEvent(getPageAt(mCurrentPage), AccessibilityEvent.TYPE_VIEW_FOCUSED, null); if (mOnPageTransitionEndCallback != null) { diff --git a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java index 24cc0acca4..d37b1f08e3 100644 --- a/src/com/android/launcher3/compat/AccessibilityManagerCompat.java +++ b/src/com/android/launcher3/compat/AccessibilityManagerCompat.java @@ -74,38 +74,12 @@ public class AccessibilityManagerCompat { Log.d(TestProtocol.PERMANENT_DIAG_TAG, "sendStateEventToTest: " + stateOrdinal); } - public static void sendScrollFinishedEventToTest(Context context) { + public static void sendTestProtocolEventToTest(Context context, String testProtocolEvent) { final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context); if (accessibilityManager == null) return; - sendEventToTest(accessibilityManager, context, TestProtocol.SCROLL_FINISHED_MESSAGE, null); + sendEventToTest(accessibilityManager, context, testProtocolEvent, null); } - - public static void sendPauseDetectedEventToTest(Context context) { - final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context); - if (accessibilityManager == null) return; - - sendEventToTest(accessibilityManager, context, TestProtocol.PAUSE_DETECTED_MESSAGE, null); - } - - public static void sendDismissAnimationEndsEventToTest(Context context) { - final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context); - if (accessibilityManager == null) return; - - sendEventToTest(accessibilityManager, context, TestProtocol.DISMISS_ANIMATION_ENDS_MESSAGE, - null); - } - - /** - * Notify running tests of a folder opened. - */ - public static void sendFolderOpenedEventToTest(Context context) { - final AccessibilityManager accessibilityManager = getAccessibilityManagerForTest(context); - if (accessibilityManager == null) return; - - sendEventToTest(accessibilityManager, context, TestProtocol.FOLDER_OPENED_MESSAGE, null); - } - private static void sendEventToTest( AccessibilityManager accessibilityManager, Context context, String eventTag, Bundle data) { diff --git a/src/com/android/launcher3/folder/Folder.java b/src/com/android/launcher3/folder/Folder.java index 55a539a7b6..fc36ce674c 100644 --- a/src/com/android/launcher3/folder/Folder.java +++ b/src/com/android/launcher3/folder/Folder.java @@ -25,6 +25,7 @@ import static com.android.launcher3.compat.AccessibilityManagerCompat.sendCustom import static com.android.launcher3.config.FeatureFlags.ALWAYS_USE_HARDWARE_OPTIMIZATION_FOR_FOLDER_ANIMATIONS; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_FOLDER_LABEL_UPDATED; import static com.android.launcher3.logging.StatsLogManager.LauncherEvent.LAUNCHER_ITEM_DROP_COMPLETED; +import static com.android.launcher3.testing.shared.TestProtocol.FOLDER_OPENED_MESSAGE; import static com.android.launcher3.util.window.RefreshRateTracker.getSingleFrameMs; import android.animation.Animator; @@ -692,7 +693,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo public void onAnimationEnd(Animator animation) { setState(STATE_OPEN); announceAccessibilityChanges(); - AccessibilityManagerCompat.sendFolderOpenedEventToTest(getContext()); + AccessibilityManagerCompat.sendTestProtocolEventToTest(getContext(), + FOLDER_OPENED_MESSAGE); mContent.setFocusOnFirstChild(); } diff --git a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java index 9c95397a1b..d4752c503e 100644 --- a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java +++ b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java @@ -28,6 +28,7 @@ public final class TestProtocol { public static final String PAUSE_DETECTED_MESSAGE = "TAPL_PAUSE_DETECTED"; public static final String DISMISS_ANIMATION_ENDS_MESSAGE = "TAPL_DISMISS_ANIMATION_ENDS"; public static final String FOLDER_OPENED_MESSAGE = "TAPL_FOLDER_OPENED"; + public static final String SEARCH_RESULT_COMPLETE = "SEARCH_RESULT_COMPLETE"; public static final int NORMAL_STATE_ORDINAL = 0; public static final int SPRING_LOADED_STATE_ORDINAL = 1; public static final int OVERVIEW_STATE_ORDINAL = 2; diff --git a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java index 0895d9381c..513d6bb3fa 100644 --- a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java +++ b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java @@ -20,6 +20,8 @@ import android.widget.TextView; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; +import com.android.launcher3.testing.shared.TestProtocol; + import java.util.ArrayList; /** @@ -43,8 +45,11 @@ public class SearchResultFromQsb { public void searchForInput(String input) { try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( "want to search for result with an input"); - LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { - mLauncher.waitForLauncherObject(INPUT_RES).setText(input); + LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { + mLauncher.executeAndWaitForLauncherEvent( + () -> mLauncher.waitForLauncherObject(INPUT_RES).setText(input), + event -> TestProtocol.SEARCH_RESULT_COMPLETE.equals(event.getClassName()), + () -> "Didn't receive a search result completed message", "searching"); } }