From 29896284a8c1d4c9306c34ed4048b9a3170024dc Mon Sep 17 00:00:00 2001 From: vadimt Date: Wed, 6 May 2020 19:08:36 -0700 Subject: [PATCH] Likely, fixing view hierarchy changing during pressHome. Test RequestPinItemTest.testPinShortcut doesn't wait for the add-to-home prompt to disappear before proceeding to pressHome. So sometimes pressHome still sees that prompt that disappears while pressHome is executing. Now waiting for the prompt to disappear. Bug: 155926212 Change-Id: I2c7bfe26839ae406da592e81de8836666c373756 --- .../launcher3/tapl/AddToHomeScreenPrompt.java | 9 +++- .../tapl/LauncherInstrumentation.java | 48 +++++++++++-------- .../com/android/launcher3/tapl/Workspace.java | 2 +- 3 files changed, 36 insertions(+), 23 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java b/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java index 5daac394b9..e1fde3ba8b 100644 --- a/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java +++ b/tests/tapl/com/android/launcher3/tapl/AddToHomeScreenPrompt.java @@ -19,6 +19,7 @@ package com.android.launcher3.tapl; import static java.util.regex.Pattern.CASE_INSENSITIVE; import androidx.test.uiautomator.By; +import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.UiObject2; import com.android.launcher3.testing.TestProtocol; @@ -33,11 +34,14 @@ public class AddToHomeScreenPrompt { AddToHomeScreenPrompt(LauncherInstrumentation launcher) { mLauncher = launcher; - mWidgetCell = launcher.waitForLauncherObject(By.clazz( - "com.android.launcher3.widget.WidgetCell")); + mWidgetCell = launcher.waitForLauncherObject(getSelector()); mLauncher.assertNotNull("Can't find widget cell object", mWidgetCell); } + private static BySelector getSelector() { + return By.clazz("com.android.launcher3.widget.WidgetCell"); + } + public void addAutomatically() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { if (mLauncher.getNavigationModel() @@ -53,6 +57,7 @@ public class AddToHomeScreenPrompt { mLauncher.waitForObjectInContainer( mWidgetCell.getParent().getParent().getParent().getParent(), By.text(ADD_AUTOMATICALLY)).click(); + mLauncher.waitUntilLauncherObjectGone(getSelector()); } } } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index dd170c53d2..140e8dd291 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -542,32 +542,32 @@ public final class LauncherInstrumentation { if (mDevice.isNaturalOrientation()) { waitForLauncherObject(APPS_RES_ID); } else { - waitUntilGone(APPS_RES_ID); + waitUntilLauncherObjectGone(APPS_RES_ID); } - waitUntilGone(OVERVIEW_RES_ID); - waitUntilGone(WIDGETS_RES_ID); + waitUntilLauncherObjectGone(OVERVIEW_RES_ID); + waitUntilLauncherObjectGone(WIDGETS_RES_ID); return waitForLauncherObject(WORKSPACE_RES_ID); } case WIDGETS: { - waitUntilGone(WORKSPACE_RES_ID); - waitUntilGone(APPS_RES_ID); - waitUntilGone(OVERVIEW_RES_ID); + waitUntilLauncherObjectGone(WORKSPACE_RES_ID); + waitUntilLauncherObjectGone(APPS_RES_ID); + waitUntilLauncherObjectGone(OVERVIEW_RES_ID); return waitForLauncherObject(WIDGETS_RES_ID); } case ALL_APPS: { - waitUntilGone(WORKSPACE_RES_ID); - waitUntilGone(OVERVIEW_RES_ID); - waitUntilGone(WIDGETS_RES_ID); + waitUntilLauncherObjectGone(WORKSPACE_RES_ID); + waitUntilLauncherObjectGone(OVERVIEW_RES_ID); + waitUntilLauncherObjectGone(WIDGETS_RES_ID); return waitForLauncherObject(APPS_RES_ID); } case OVERVIEW: { if (hasAllAppsInOverview()) { waitForLauncherObject(APPS_RES_ID); } else { - waitUntilGone(APPS_RES_ID); + waitUntilLauncherObjectGone(APPS_RES_ID); } - waitUntilGone(WORKSPACE_RES_ID); - waitUntilGone(WIDGETS_RES_ID); + waitUntilLauncherObjectGone(WORKSPACE_RES_ID); + waitUntilLauncherObjectGone(WIDGETS_RES_ID); return waitForLauncherObject(OVERVIEW_RES_ID); } @@ -575,10 +575,10 @@ public final class LauncherInstrumentation { return waitForFallbackLauncherObject(OVERVIEW_RES_ID); } case BACKGROUND: { - waitUntilGone(WORKSPACE_RES_ID); - waitUntilGone(APPS_RES_ID); - waitUntilGone(OVERVIEW_RES_ID); - waitUntilGone(WIDGETS_RES_ID); + waitUntilLauncherObjectGone(WORKSPACE_RES_ID); + waitUntilLauncherObjectGone(APPS_RES_ID); + waitUntilLauncherObjectGone(OVERVIEW_RES_ID); + waitUntilLauncherObjectGone(WIDGETS_RES_ID); return null; } default: @@ -643,7 +643,7 @@ public final class LauncherInstrumentation { false, GestureScope.INSIDE_TO_OUTSIDE); try (LauncherInstrumentation.Closable c = addContextLayer( "Swiped up from context menu to home")) { - waitUntilGone(CONTEXT_MENU_RES_ID); + waitUntilLauncherObjectGone(CONTEXT_MENU_RES_ID); } } if (hasLauncherObject(WORKSPACE_RES_ID)) { @@ -794,9 +794,17 @@ public final class LauncherInstrumentation { } } - void waitUntilGone(String resId) { - assertTrue("Unexpected launcher object visible: " + resId, - mDevice.wait(Until.gone(getLauncherObjectSelector(resId)), + void waitUntilLauncherObjectGone(String resId) { + waitUntilGoneBySelector(getLauncherObjectSelector(resId)); + } + + void waitUntilLauncherObjectGone(BySelector selector) { + waitUntilGoneBySelector(makeLauncherSelector(selector)); + } + + private void waitUntilGoneBySelector(BySelector launcherSelector) { + assertTrue("Unexpected launcher object visible: " + launcherSelector, + mDevice.wait(Until.gone(launcherSelector), WAIT_TIME_MS)); } diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 9f809173b7..f0e686f77f 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -230,7 +230,7 @@ public final class Workspace extends Home { launcher.expectEvent(TestProtocol.SEQUENCE_MAIN, LauncherInstrumentation.EVENT_START); } LauncherInstrumentation.log("dragIconToWorkspace: end"); - launcher.waitUntilGone("drop_target_bar"); + launcher.waitUntilLauncherObjectGone("drop_target_bar"); } /**