diff options
Diffstat (limited to 'tests')
8 files changed, 88 insertions, 39 deletions
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index fc3118703..35a9f0151 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -93,8 +93,7 @@ public abstract class AbstractLauncherUiTest { protected LooperExecutor mMainThreadExecutor = MAIN_EXECUTOR; protected final UiDevice mDevice = UiDevice.getInstance(getInstrumentation()); - protected final LauncherInstrumentation mLauncher = - new LauncherInstrumentation(getInstrumentation()); + protected final LauncherInstrumentation mLauncher = new LauncherInstrumentation(); protected Context mTargetContext; protected String mTargetPackage; 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/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index f070280ea..6dced8c8c 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -90,6 +90,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { final UiObject2 allAppsContainer = verifyActiveContainer(); final UiObject2 appListRecycler = mLauncher.waitForObjectInContainer(allAppsContainer, "apps_list_view"); + final UiObject2 searchBox = getSearchBox(allAppsContainer); allAppsContainer.setGestureMargins( 0, getSearchBox(allAppsContainer).getVisibleBounds().bottom + 1, @@ -103,7 +104,11 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { int scroll = getScroll(allAppsContainer); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled")) { while (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector)) { - mLauncher.scroll(allAppsContainer, Direction.DOWN, 0.8f, null, 50); + mLauncher.scrollToLastVisibleRow( + allAppsContainer, + mLauncher.getObjectsInContainer(allAppsContainer, "icon"), + searchBox.getVisibleBounds().bottom - + allAppsContainer.getVisibleBounds().top); final int newScroll = getScroll(allAppsContainer); if (newScroll == scroll) break; @@ -145,7 +150,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS, ++attempts <= MAX_SCROLL_ATTEMPTS); - mLauncher.scroll(allAppsContainer, Direction.UP, 1, margins, 50); + mLauncher.scroll(allAppsContainer, Direction.UP, margins, 50); } try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled up")) { @@ -172,7 +177,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { final UiObject2 allAppsContainer = verifyActiveContainer(); // Start the gesture in the center to avoid starting at elements near the top. mLauncher.scroll( - allAppsContainer, Direction.DOWN, 1, new Rect(0, 0, 0, mHeight / 2), 10); + allAppsContainer, Direction.DOWN, new Rect(0, 0, 0, mHeight / 2), 10); verifyActiveContainer(); } } @@ -186,7 +191,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { final UiObject2 allAppsContainer = verifyActiveContainer(); // Start the gesture in the center, for symmetry with forward. mLauncher.scroll( - allAppsContainer, Direction.UP, 1, new Rect(0, mHeight / 2, 0, 0), 10); + allAppsContainer, Direction.UP, new Rect(0, mHeight / 2, 0, 0), 10); verifyActiveContainer(); } } diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java index 25e6e8c8f..49c0c8908 100644 --- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java @@ -55,7 +55,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final int leftMargin = mLauncher.getTestInfo( TestProtocol.REQUEST_OVERVIEW_LEFT_GESTURE_MARGIN). getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); - mLauncher.scroll(overview, Direction.LEFT, 1, new Rect(leftMargin, 0, 0, 0), 20); + mLauncher.scroll(overview, Direction.LEFT, new Rect(leftMargin, 0, 0, 0), 20); verifyActiveContainer(); } } @@ -93,7 +93,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer { final int rightMargin = mLauncher.getTestInfo( TestProtocol.REQUEST_OVERVIEW_RIGHT_GESTURE_MARGIN). getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); - mLauncher.scroll(overview, Direction.RIGHT, 1, new Rect(0, 0, rightMargin, 0), 20); + mLauncher.scroll(overview, Direction.RIGHT, new Rect(0, 0, rightMargin, 0), 20); verifyActiveContainer(); } } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 306fe4870..d89ec8b5d 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -51,6 +51,7 @@ import android.view.accessibility.AccessibilityEvent; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import androidx.test.InstrumentationRegistry; import androidx.test.uiautomator.By; import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.Configurator; @@ -59,6 +60,7 @@ import androidx.test.uiautomator.UiDevice; import androidx.test.uiautomator.UiObject2; import androidx.test.uiautomator.Until; +import com.android.launcher3.ResourceUtils; import com.android.launcher3.testing.TestProtocol; import com.android.systemui.shared.system.QuickStepContract; @@ -67,6 +69,8 @@ import org.junit.Assert; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.lang.ref.WeakReference; +import java.util.Collection; +import java.util.Collections; import java.util.Deque; import java.util.LinkedList; import java.util.List; @@ -141,6 +145,15 @@ public final class LauncherInstrumentation { /** * Constructs the root of TAPL hierarchy. You get all other objects from it. */ + public LauncherInstrumentation() { + this(InstrumentationRegistry.getInstrumentation()); + } + + /** + * Constructs the root of TAPL hierarchy. You get all other objects from it. + * Deprecated: use the constructor without parameters instead. + */ + @Deprecated public LauncherInstrumentation(Instrumentation instrumentation) { mInstrumentation = instrumentation; mDevice = UiDevice.getInstance(instrumentation); @@ -765,7 +778,36 @@ public final class LauncherInstrumentation { TestProtocol.stateOrdinalToString(parcel.getInt(TestProtocol.STATE_FIELD))); } - void scroll(UiObject2 container, Direction direction, float percent, Rect margins, int steps) { + int getBottomGestureSize() { + return ResourceUtils.getNavbarSize( + ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, getResources()) + 1; + } + + int getBottomGestureMargin(UiObject2 container) { + return container.getVisibleBounds().bottom - getRealDisplaySize().y + + getBottomGestureSize(); + } + + void scrollToLastVisibleRow(UiObject2 container, Collection<UiObject2> items, int topPadding) { + final UiObject2 lowestItem = Collections.max(items, (i1, i2) -> + Integer.compare(i1.getVisibleBounds().top, i2.getVisibleBounds().top)); + + final int gestureStart = lowestItem.getVisibleBounds().top + getTouchSlop(); + final int distance = gestureStart - container.getVisibleBounds().top - topPadding; + final int bottomMargin = container.getVisibleBounds().height() - distance; + + scroll( + container, + Direction.DOWN, + new Rect( + 0, + 0, + 0, + Math.max(bottomMargin, getBottomGestureMargin(container))), + 150); + } + + void scroll(UiObject2 container, Direction direction, Rect margins, int steps) { final Rect rect = container.getVisibleBounds(); if (margins != null) { rect.left += margins.left; @@ -783,7 +825,7 @@ public final class LauncherInstrumentation { case UP: { startX = endX = rect.centerX(); final int vertCenter = rect.centerY(); - final float halfGestureHeight = rect.height() * percent / 2.0f; + final float halfGestureHeight = rect.height() / 2.0f; startY = (int) (vertCenter - halfGestureHeight) + 1; endY = (int) (vertCenter + halfGestureHeight); } @@ -791,7 +833,7 @@ public final class LauncherInstrumentation { case DOWN: { startX = endX = rect.centerX(); final int vertCenter = rect.centerY(); - final float halfGestureHeight = rect.height() * percent / 2.0f; + final float halfGestureHeight = rect.height() / 2.0f; startY = (int) (vertCenter + halfGestureHeight) - 1; endY = (int) (vertCenter - halfGestureHeight); } @@ -799,7 +841,7 @@ public final class LauncherInstrumentation { case LEFT: { startY = endY = rect.centerY(); final int horizCenter = rect.centerX(); - final float halfGestureWidth = rect.width() * percent / 2.0f; + final float halfGestureWidth = rect.width() / 2.0f; startX = (int) (horizCenter - halfGestureWidth) + 1; endX = (int) (horizCenter + halfGestureWidth); } @@ -807,7 +849,7 @@ public final class LauncherInstrumentation { case RIGHT: { startY = endY = rect.centerY(); final int horizCenter = rect.centerX(); - final float halfGestureWidth = rect.width() * percent / 2.0f; + final float halfGestureWidth = rect.width() / 2.0f; startX = (int) (horizCenter + halfGestureWidth) - 1; endX = (int) (horizCenter - halfGestureWidth); } diff --git a/tests/tapl/com/android/launcher3/tapl/Widgets.java b/tests/tapl/com/android/launcher3/tapl/Widgets.java index 7d308afb9..51239c9ac 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; @@ -26,13 +24,12 @@ import androidx.test.uiautomator.BySelector; import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.UiObject2; -import com.android.launcher3.ResourceUtils; +import java.util.Collection; /** * 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,7 +45,11 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer { "want to fling forward in widgets")) { LauncherInstrumentation.log("Widgets.flingForward enter"); final UiObject2 widgetsContainer = verifyActiveContainer(); - mLauncher.scroll(widgetsContainer, Direction.DOWN, 1f, MARGINS, FLING_STEPS); + mLauncher.scroll( + widgetsContainer, + Direction.DOWN, + new Rect(0, 0, 0, mLauncher.getBottomGestureMargin(widgetsContainer)), + FLING_STEPS); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("flung forward")) { verifyActiveContainer(); } @@ -64,7 +65,11 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer { "want to fling backwards in widgets")) { LauncherInstrumentation.log("Widgets.flingBackward enter"); final UiObject2 widgetsContainer = verifyActiveContainer(); - mLauncher.scroll(widgetsContainer, Direction.UP, 1f, MARGINS, FLING_STEPS); + mLauncher.scroll( + widgetsContainer, + Direction.UP, + new Rect(0, 0, widgetsContainer.getVisibleBounds().width(), 0), + FLING_STEPS); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("flung back")) { verifyActiveContainer(); } @@ -78,32 +83,33 @@ 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<UiObject2> 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 - mLauncher.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); + mLauncher.scrollToLastVisibleRow(widgetsContainer, cells, 0); } } } diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index fe27e71f5..ad2feb4b5 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -181,7 +181,7 @@ public final class Workspace extends Home { */ public void flingForward() { final UiObject2 workspace = verifyActiveContainer(); - mLauncher.scroll(workspace, Direction.RIGHT, 1f, + mLauncher.scroll(workspace, Direction.RIGHT, new Rect(0, 0, mLauncher.getEdgeSensitivityWidth(), 0), FLING_STEPS); verifyActiveContainer(); @@ -193,7 +193,7 @@ public final class Workspace extends Home { */ public void flingBackward() { final UiObject2 workspace = verifyActiveContainer(); - mLauncher.scroll(workspace, Direction.LEFT, 1f, + mLauncher.scroll(workspace, Direction.LEFT, new Rect(mLauncher.getEdgeSensitivityWidth(), 0, 0, 0), FLING_STEPS); verifyActiveContainer(); |