From fb099c7fe167752f9a921e99cf7eae2afc609538 Mon Sep 17 00:00:00 2001 From: vadimt Date: Tue, 23 Jun 2020 18:49:41 -0700 Subject: [PATCH] Improving diagnostics when can't find a widget Instead of "exceeded number of attempts" now printing that can't scroll to widget. Change-Id: Ia6f582e038d68fc35f152d94e592f60ef0bc2cf4 --- .../launcher3/testing/TestInformationHandler.java | 6 ++++++ src/com/android/launcher3/testing/TestProtocol.java | 1 + tests/tapl/com/android/launcher3/tapl/Widgets.java | 13 +++++++++++++ 3 files changed, 20 insertions(+) diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 38b3712f6e..d4a132e5ba 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -33,6 +33,7 @@ import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherState; import com.android.launcher3.R; import com.android.launcher3.util.ResourceBasedOverride; +import com.android.launcher3.widget.WidgetsFullSheet; import java.util.concurrent.ExecutionException; import java.util.function.Function; @@ -92,6 +93,11 @@ public class TestInformationHandler implements ResourceBasedOverride { l -> l.getAppsView().getActiveRecyclerView().getCurrentScrollY()); } + case TestProtocol.REQUEST_WIDGETS_SCROLL_Y: { + return getLauncherUIProperty(Bundle::putInt, + l -> WidgetsFullSheet.getWidgetsView(l).getCurrentScrollY()); + } + case TestProtocol.REQUEST_WINDOW_INSETS: { return getUIProperty(Bundle::putParcelable, a -> { WindowInsets insets = a.getWindow() diff --git a/src/com/android/launcher3/testing/TestProtocol.java b/src/com/android/launcher3/testing/TestProtocol.java index 3ca08fd8ec..8165627448 100644 --- a/src/com/android/launcher3/testing/TestProtocol.java +++ b/src/com/android/launcher3/testing/TestProtocol.java @@ -81,6 +81,7 @@ public final class TestProtocol { public static final String REQUEST_UNFREEZE_APP_LIST = "unfreeze-app-list"; public static final String REQUEST_APP_LIST_FREEZE_FLAGS = "app-list-freeze-flags"; public static final String REQUEST_APPS_LIST_SCROLL_Y = "apps-list-scroll-y"; + public static final String REQUEST_WIDGETS_SCROLL_Y = "widgets-scroll-y"; public static final String REQUEST_WINDOW_INSETS = "window-insets"; public static final String REQUEST_PID = "pid"; public static final String REQUEST_TOTAL_PSS_KB = "total_pss"; diff --git a/tests/tapl/com/android/launcher3/tapl/Widgets.java b/tests/tapl/com/android/launcher3/tapl/Widgets.java index 39ac6454b0..49af616b85 100644 --- a/tests/tapl/com/android/launcher3/tapl/Widgets.java +++ b/tests/tapl/com/android/launcher3/tapl/Widgets.java @@ -28,6 +28,7 @@ import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; import com.android.launcher3.tapl.LauncherInstrumentation.GestureScope; +import com.android.launcher3.testing.TestProtocol; import java.util.Collection; @@ -90,6 +91,12 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer { return LauncherInstrumentation.ContainerType.WIDGETS; } + private int getWidgetsScroll() { + return mLauncher.getTestInfo( + TestProtocol.REQUEST_WIDGETS_SCROLL_Y) + .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); + } + public Widget getWidget(String labelText) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer( @@ -136,7 +143,13 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer { } mLauncher.assertTrue("Too many attempts", ++i <= 40); + final int scroll = getWidgetsScroll(); mLauncher.scrollToLastVisibleRow(widgetsContainer, cells, 0); + final int newScroll = getWidgetsScroll(); + mLauncher.assertTrue( + "Scrolled in a wrong direction in Widgets: from " + scroll + " to " + + newScroll, newScroll >= scroll); + mLauncher.assertTrue("Unable to scroll to the widget", newScroll != scroll); } } }