Merge "Searching for Golden Gate Bridge should show three queries and check if predicted app row and web suggest exists" into tm-qpr-dev am: 8267b7625f

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/20544528

Change-Id: I626dd32e32a52e4f95954c26459d8d46dfa8b0d4
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
diff --git a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java
index ddeeac2..bddb593 100644
--- a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java
+++ b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java
@@ -20,6 +20,8 @@
 import androidx.test.uiautomator.By;
 import androidx.test.uiautomator.UiObject2;
 
+import java.util.ArrayList;
+
 /**
  * Operations on search result page opened from home screen qsb.
  */
@@ -27,6 +29,9 @@
     // The input resource id in the search box.
     private static final String INPUT_RES = "input";
     private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background";
+
+    // This particular ID change should happen with caution
+    private static final String SEARCH_CONTAINER_RES_ID = "search_results_list_view";
     private final LauncherInstrumentation mLauncher;
 
     SearchResultFromQsb(LauncherInstrumentation launcher) {
@@ -49,6 +54,33 @@
         return new AllAppsAppIcon(mLauncher, icon);
     }
 
+    /** Find the web suggestion from search suggestion's title text */
+    public void findWebSuggest(String text) {
+        ArrayList<UiObject2> goldenGateResults =
+                new ArrayList<>(mLauncher.waitForObjectsInContainer(
+                        mLauncher.waitForSystemLauncherObject(SEARCH_CONTAINER_RES_ID),
+                        By.clazz(TextView.class)));
+        boolean found = false;
+        for(UiObject2 uiObject: goldenGateResults) {
+            String currentString = uiObject.getText();
+            if (currentString.equals(text)) {
+                found = true;
+            }
+        }
+        if (!found) {
+            throw new IllegalStateException("Web suggestion title: " + text + " not found");
+        }
+    }
+
+    /** Find the total amount of views being displayed and return the size */
+    public int getSearchResultItemSize() {
+        ArrayList<UiObject2> searchResultItems =
+                new ArrayList<>(mLauncher.waitForObjectsInContainer(
+                        mLauncher.waitForSystemLauncherObject(SEARCH_CONTAINER_RES_ID),
+                        By.clazz(TextView.class)));
+        return searchResultItems.size();
+    }
+
     /**
      * Taps outside bottom sheet to dismiss and return to workspace. Available on tablets only.
      * @param tapRight Tap on the right of bottom sheet if true, or left otherwise.