Reenabling some widget tests

Bug: 140837771
Change-Id: I437f39b4a7f4b518551a157858c9b1a4812ee65d
This commit is contained in:
vadimt 2019-09-10 18:37:28 -07:00
parent d81f60f324
commit 599b1fc4d3
4 changed files with 16 additions and 12 deletions

View File

@ -70,14 +70,12 @@ public class AddConfigWidgetTest extends AbstractLauncherUiTest {
@Test
@PortraitLandscape
@Ignore
public void testWidgetConfig() throws Throwable {
runTest(true);
}
@Test
@PortraitLandscape
@Ignore
public void testConfigCancelled() throws Throwable {
runTest(false);
}

View File

@ -42,7 +42,6 @@ public class AddWidgetTest extends AbstractLauncherUiTest {
@Test
@PortraitLandscape
@Ignore
public void testDragIcon() throws Throwable {
clearHomescreen();
mDevice.pressHome();

View File

@ -368,7 +368,7 @@ public final class LauncherInstrumentation {
}
}
private void assertEquals(String message, String expected, String actual) {
void assertEquals(String message, String expected, String actual) {
if (!TextUtils.equals(expected, actual)) {
fail(message + " expected: '" + expected + "' but was: '" + actual + "'");
}

View File

@ -77,7 +77,7 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer {
return LauncherInstrumentation.ContainerType.WIDGETS;
}
public Widget getWidget(String label) {
public Widget getWidget(String labelText) {
final int margin = ResourceUtils.getNavbarSize(
ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1;
final UiObject2 widgetsContainer = verifyActiveContainer();
@ -86,17 +86,24 @@ public final class Widgets extends LauncherInstrumentation.VisibleContainer {
final Point displaySize = mLauncher.getRealDisplaySize();
int i = 0;
final BySelector selector = By.
clazz("com.android.launcher3.widget.WidgetCell").
hasDescendant(By.text(label));
final BySelector selector = By.clazz("android.widget.TextView").text(labelText);
for (; ; ) {
final UiObject2 widget = mLauncher.tryWaitForLauncherObject(selector, 300);
if (widget != null && widget.getVisibleBounds().bottom <= displaySize.y - margin) {
return new Widget(mLauncher, widget);
final UiObject2 label = mLauncher.tryWaitForLauncherObject(selector, 300);
if (label != null) {
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) {
return new Widget(mLauncher, widget);
}
}
if (++i > 40) fail("Too many attempts");
mLauncher.scroll(widgetsContainer, Direction.DOWN, 1f, MARGINS, 50);
mLauncher.scroll(widgetsContainer, Direction.DOWN, 0.8f, MARGINS, 50);
}
}
}