summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVadim Tryshev <vadimt@google.com>2019-09-26 14:40:40 -0700
committerandroid-build-merger <android-build-merger@google.com>2019-09-26 14:40:40 -0700
commit12db478e464e42b78bf0c491eccb79e83c507cf2 (patch)
tree6e8d1b71ab40c9550dd2d5ea01b9cc79bdfc71e9 /tests
parent7601d12a912a17b88bd7264e7f92aca0bead69db (diff)
parent77f045b607792be845307e931e43a9aed3d05d5b (diff)
downloadandroid_packages_apps_Trebuchet-12db478e464e42b78bf0c491eccb79e83c507cf2.tar.gz
android_packages_apps_Trebuchet-12db478e464e42b78bf0c491eccb79e83c507cf2.tar.bz2
android_packages_apps_Trebuchet-12db478e464e42b78bf0c491eccb79e83c507cf2.zip
Merge "Removing magic constants from TAPL/Widgets" into ub-launcher3-qt-qpr1-dev
am: 77f045b607 Change-Id: I8ea519aca0ef3830f506c91c2086e1eb31b4b6f2
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java6
-rw-r--r--tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java5
-rw-r--r--tests/tapl/com/android/launcher3/tapl/Widgets.java64
3 files changed, 49 insertions, 26 deletions
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 54f730e25..39cb0bf7a 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.
*/
@@ -88,32 +98,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<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 - 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);
}
}
}