From aca7e6da5b46bb02b08bf54fb5f62e61a3b21bf6 Mon Sep 17 00:00:00 2001 From: vadimt Date: Wed, 25 Sep 2019 18:13:23 -0700 Subject: Removing magic constants from TAPL/Widgets Bug: 123904290 Change-Id: I8abc6cde6be8a51b38782f5c94749fe0c33384c1 --- .../launcher3/ui/widget/AddConfigWidgetTest.java | 6 +- .../android/launcher3/ui/widget/AddWidgetTest.java | 5 +- tests/tapl/com/android/launcher3/tapl/Widgets.java | 64 +++++++++++++++------- 3 files changed, 49 insertions(+), 26 deletions(-) (limited to 'tests') diff --git a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java index 3f35a3a73..e1b3edeb5 100644 --- a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java @@ -41,7 +41,6 @@ import com.android.launcher3.util.Wait; import com.android.launcher3.util.rule.ShellCommandRule; import org.junit.Before; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -53,7 +52,8 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class AddConfigWidgetTest extends AbstractLauncherUiTest { - @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); + @Rule + public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); private LauncherAppWidgetProviderInfo mWidgetInfo; private AppWidgetManager mAppWidgetManager; @@ -70,14 +70,12 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest { @Test @PortraitLandscape - @org.junit.Ignore public void testWidgetConfig() throws Throwable { runTest(true); } @Test @PortraitLandscape - @org.junit.Ignore public void testConfigCancelled() throws Throwable { runTest(false); } diff --git a/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java index 1edce22ec..b8ca5ded3 100644 --- a/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java @@ -30,7 +30,6 @@ import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.ui.TestViewHelpers; import com.android.launcher3.util.rule.ShellCommandRule; -import org.junit.Ignore; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -42,11 +41,11 @@ import org.junit.runner.RunWith; @RunWith(AndroidJUnit4.class) public class AddWidgetTest extends AbstractLauncherUiTest { - @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); + @Rule + public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grantWidgetBind(); @Test @PortraitLandscape - @org.junit.Ignore public void testDragIcon() throws Throwable { clearHomescreen(); mDevice.pressHome(); diff --git a/tests/tapl/com/android/launcher3/tapl/Widgets.java b/tests/tapl/com/android/launcher3/tapl/Widgets.java index 2a04d46cb..0cd6c385f 100644 --- a/tests/tapl/com/android/launcher3/tapl/Widgets.java +++ b/tests/tapl/com/android/launcher3/tapl/Widgets.java @@ -16,8 +16,6 @@ package com.android.launcher3.tapl; -import static org.junit.Assert.fail; - import android.graphics.Point; import android.graphics.Rect; @@ -28,11 +26,13 @@ import androidx.test.uiautomator.UiObject2; import com.android.launcher3.ResourceUtils; +import java.util.Collection; +import java.util.Collections; + /** * All widgets container. */ public final class Widgets extends LauncherInstrumentation.VisibleContainer { - private static final Rect MARGINS = new Rect(100, 100, 100, 100); private static final int FLING_STEPS = 10; Widgets(LauncherInstrumentation launcher) { @@ -48,12 +48,12 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer { "want to fling forward in widgets")) { LauncherInstrumentation.log("Widgets.flingForward enter"); final UiObject2 widgetsContainer = verifyActiveContainer(); - final int margin = widgetsContainer.getVisibleBounds().bottom - - mLauncher.getRealDisplaySize().y + - ResourceUtils.getNavbarSize( - ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()); mLauncher.scroll( - widgetsContainer, Direction.DOWN, 1f, new Rect(0, 0, 0, margin), FLING_STEPS); + widgetsContainer, + Direction.DOWN, + 1f, + new Rect(0, 0, 0, getBottomGestureMargin(widgetsContainer)), + FLING_STEPS); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("flung forward")) { verifyActiveContainer(); } @@ -61,6 +61,16 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer { } } + private int getBottomGestureMargin(UiObject2 widgetsContainer) { + return widgetsContainer.getVisibleBounds().bottom - mLauncher.getRealDisplaySize().y + + getBottomGestureSize(); + } + + private int getBottomGestureSize() { + return ResourceUtils.getNavbarSize( + ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1; + } + /** * Flings backward (up) and waits the fling's end. */ @@ -83,32 +93,48 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer { } public Widget getWidget(String labelText) { - final int margin = ResourceUtils.getNavbarSize( - ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1; final UiObject2 widgetsContainer = verifyActiveContainer(); - widgetsContainer.setGestureMargins(0, 0, 0, margin); - final Point displaySize = mLauncher.getRealDisplaySize(); + final BySelector labelSelector = By.clazz("android.widget.TextView").text(labelText); int i = 0; - final BySelector selector = By.clazz("android.widget.TextView").text(labelText); - for (; ; ) { - final UiObject2 label = mLauncher.tryWaitForLauncherObject(selector, 300); - if (label != null) { + final Collection cells = mLauncher.getObjectsInContainer( + widgetsContainer, "widgets_cell_list_container"); + mLauncher.assertTrue("Widgets doesn't have 2 rows", cells.size() >= 2); + for (UiObject2 cell : cells) { + final UiObject2 label = cell.findObject(labelSelector); + if (label == null) continue; + final UiObject2 widget = label.getParent().getParent(); mLauncher.assertEquals( "View is not WidgetCell", "com.android.launcher3.widget.WidgetCell", widget.getClassName()); - if (widget.getVisibleBounds().bottom <= displaySize.y - margin) { + if (widget.getVisibleBounds().bottom <= displaySize.y - getBottomGestureSize()) { return new Widget(mLauncher, widget); } } - if (++i > 40) fail("Too many attempts"); - mLauncher.scroll(widgetsContainer, Direction.DOWN, 0.7f, MARGINS, 50); + mLauncher.assertTrue("Too many attempts", ++i <= 40); + final UiObject2 lowestCell = Collections.max(cells, (c1, c2) -> + Integer.compare(c1.getVisibleBounds().top, c2.getVisibleBounds().top)); + + final int gestureStart = lowestCell.getVisibleBounds().top + mLauncher.getTouchSlop(); + final int distance = gestureStart - widgetsContainer.getVisibleBounds().top; + final int bottomMargin = widgetsContainer.getVisibleBounds().height() - distance; + + mLauncher.scroll( + widgetsContainer, + Direction.DOWN, + 1f, + new Rect( + 0, + 0, + 0, + Math.max(bottomMargin, getBottomGestureMargin(widgetsContainer))), + 150); } } } -- cgit v1.2.3