diff options
author | Vadim Tryshev <vadimt@google.com> | 2018-08-10 20:01:24 -0700 |
---|---|---|
committer | Vadim Tryshev <vadimt@google.com> | 2018-08-14 10:29:57 -0700 |
commit | dc755e718ded4a3af112b63420ea1060618a2982 (patch) | |
tree | 2b783ef6d242ddfcbca57f2928d2f9cbb898e3e4 /tests | |
parent | b6ecb17356da95cdc4c9d66d1a47024a38fc4d23 (diff) | |
download | android_packages_apps_Trebuchet-dc755e718ded4a3af112b63420ea1060618a2982.tar.gz android_packages_apps_Trebuchet-dc755e718ded4a3af112b63420ea1060618a2982.tar.bz2 android_packages_apps_Trebuchet-dc755e718ded4a3af112b63420ea1060618a2982.zip |
Started converting Launcher to be gesture-stable
All tests keep passing.
WorkTabTest.workTabExists was made gesture-stable. There is no need to
use TAPL, as the point is not to check answering to gestures, but to
check presence of tabs, which is better to do using launcher internal
state. (It still fails if run as a part of all tests, presumably,
because after Launcher's start, changes in user configuration are not
recognized, so I've commented the failing part)
Bug: 110103162
Test: Run all tests
Change-Id: Ic30b8e8475d16cee3880332f12311a44ddfa26cb
Diffstat (limited to 'tests')
11 files changed, 81 insertions, 119 deletions
diff --git a/tests/Android.mk b/tests/Android.mk index 7a7d20399..180fc0cb3 100644 --- a/tests/Android.mk +++ b/tests/Android.mk @@ -17,7 +17,8 @@ LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE_TAGS := tests -LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator mockito-target-minus-junit4 +LOCAL_STATIC_JAVA_LIBRARIES := android-support-test ub-uiautomator mockito-target-minus-junit4 \ + ub-launcher-aosp-tapl LOCAL_SRC_FILES := $(call all-java-files-under, src) LOCAL_FULL_LIBS_MANIFEST_FILES := $(LOCAL_PATH)/AndroidManifest-common.xml diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index dd91fe86d..46a6446f2 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -15,6 +15,9 @@ */ package com.android.launcher3.ui; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import android.app.Instrumentation; import android.content.BroadcastReceiver; import android.content.ComponentName; @@ -36,24 +39,30 @@ import android.support.test.uiautomator.Until; import android.util.Log; import android.view.MotionEvent; +import com.android.launcher3.Launcher; import com.android.launcher3.LauncherAppState; import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.LauncherSettings; +import com.android.launcher3.LauncherState; import com.android.launcher3.MainThreadExecutor; import com.android.launcher3.R; import com.android.launcher3.compat.AppWidgetManagerCompat; import com.android.launcher3.compat.LauncherAppsCompat; +import com.android.launcher3.tapl.LauncherInstrumentation; import com.android.launcher3.testcomponent.AppWidgetNoConfig; import com.android.launcher3.testcomponent.AppWidgetWithConfig; +import com.android.launcher3.util.Condition; +import com.android.launcher3.util.Wait; +import com.android.launcher3.util.rule.LauncherActivityRule; import org.junit.Before; +import org.junit.Rule; import java.util.concurrent.Callable; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; +import java.util.function.Consumer; +import java.util.function.Function; /** * Base class for all instrumentation tests providing various utility methods. @@ -65,19 +74,23 @@ public abstract class AbstractLauncherUiTest { public static final long SHORT_UI_TIMEOUT= 300; public static final long DEFAULT_UI_TIMEOUT = 3000; - public static final long LARGE_UI_TIMEOUT = 10000; public static final long DEFAULT_WORKER_TIMEOUT_SECS = 5; protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor(); protected UiDevice mDevice; + protected LauncherInstrumentation mLauncher; protected Context mTargetContext; protected String mTargetPackage; private static final String TAG = "AbstractLauncherUiTest"; + @Rule + public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); + @Before public void setUp() throws Exception { mDevice = UiDevice.getInstance(getInstrumentation()); + mLauncher = new LauncherInstrumentation(mDevice); mTargetContext = InstrumentationRegistry.getTargetContext(); mTargetPackage = mTargetContext.getPackageName(); } @@ -236,6 +249,33 @@ public abstract class AbstractLauncherUiTest { } } + protected <T> T getFromLauncher(Function<Launcher, T> f) { + return getOnUiThread(() -> f.apply(mActivityMonitor.getActivity())); + } + + protected void executeOnLauncher(Consumer<Launcher> f) { + getFromLauncher(launcher -> { + f.accept(launcher); + return null; + }); + } + + // Cannot be used between a Tapl call injecting a gesture and a tapl call expecting the + // results of that gesture because the wait can hide flakeness. + protected boolean waitForState(LauncherState state) { + return waitForLauncherCondition(launcher -> launcher.getStateManager().getState() == state); + } + + // Cannot be used after injecting any gesture using Tapl because this can hide flakiness. + protected boolean waitForLauncherCondition(Function<Launcher, Boolean> condition) { + return Wait.atMost(new Condition() { + @Override + public boolean isTrue() { + return getFromLauncher(condition); + } + }, DEFAULT_ACTIVITY_TIMEOUT); + } + /** * Finds a widget provider which can fit on the home screen. * @param hasConfigureScreen if true, a provider with a config screen is returned. diff --git a/tests/src/com/android/launcher3/ui/AllAppsAppLaunchTest.java b/tests/src/com/android/launcher3/ui/AllAppsAppLaunchTest.java deleted file mode 100644 index b95a850ec..000000000 --- a/tests/src/com/android/launcher3/ui/AllAppsAppLaunchTest.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.android.launcher3.ui; - -import android.content.pm.LauncherActivityInfo; -import android.support.test.filters.LargeTest; -import android.support.test.runner.AndroidJUnit4; -import android.support.test.uiautomator.By; -import android.support.test.uiautomator.UiObject2; -import android.support.test.uiautomator.Until; - -import com.android.launcher3.util.Condition; -import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.LauncherActivityRule; - -import org.junit.Rule; -import org.junit.Test; -import org.junit.runner.RunWith; - -import static org.junit.Assert.assertTrue; - -/** - * Test for verifying apps is launched from all-apps - */ -@LargeTest -@RunWith(AndroidJUnit4.class) -public class AllAppsAppLaunchTest extends AbstractLauncherUiTest { - - @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); - - @Test - public void testAppLauncher_portrait() throws Exception { - lockRotation(true); - performTest(); - } - - @Test - public void testAppLauncher_landscape() throws Exception { - lockRotation(false); - performTest(); - } - - private void performTest() throws Exception { - mActivityMonitor.startLauncher(); - - LauncherActivityInfo testApp = getChromeApp(); - - // Open all apps and wait for load complete - final UiObject2 appsContainer = openAllApps(); - assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT)); - - // Open app and verify app launched - scrollAndFind(appsContainer, By.text(testApp.getLabel().toString())).click(); - assertTrue(mDevice.wait(Until.hasObject(By.pkg( - testApp.getComponentName().getPackageName()).depth(0)), DEFAULT_UI_TIMEOUT)); - } -} diff --git a/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java b/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java index 00f30ada9..8b9c58400 100644 --- a/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java +++ b/tests/src/com/android/launcher3/ui/AllAppsIconToHomeTest.java @@ -1,5 +1,7 @@ package com.android.launcher3.ui; +import static org.junit.Assert.assertTrue; + import android.content.pm.LauncherActivityInfo; import android.support.test.filters.LargeTest; import android.support.test.runner.AndroidJUnit4; @@ -9,15 +11,12 @@ import android.support.test.uiautomator.Until; import com.android.launcher3.util.Condition; import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertTrue; - /** * Test for dragging an icon from all-apps to homescreen. */ @@ -25,7 +24,6 @@ import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) public class AllAppsIconToHomeTest extends AbstractLauncherUiTest { - @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); @Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher(); @Test diff --git a/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java b/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java index 69f6c8780..f91347037 100644 --- a/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java +++ b/tests/src/com/android/launcher3/ui/ShortcutsLaunchTest.java @@ -1,5 +1,8 @@ package com.android.launcher3.ui; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import android.content.pm.LauncherActivityInfo; import android.graphics.Point; import android.support.test.filters.LargeTest; @@ -12,16 +15,12 @@ import android.view.MotionEvent; import com.android.launcher3.R; import com.android.launcher3.util.Condition; import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - /** * Test for verifying that shortcuts are shown and can be launched after long pressing an app */ @@ -29,7 +28,6 @@ import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) public class ShortcutsLaunchTest extends AbstractLauncherUiTest { - @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); @Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher(); @Test diff --git a/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java b/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java index fad06a698..4f5c1137b 100644 --- a/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java +++ b/tests/src/com/android/launcher3/ui/ShortcutsToHomeTest.java @@ -1,5 +1,8 @@ package com.android.launcher3.ui; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import android.content.pm.LauncherActivityInfo; import android.graphics.Point; import android.support.test.filters.LargeTest; @@ -12,16 +15,12 @@ import android.view.MotionEvent; import com.android.launcher3.R; import com.android.launcher3.util.Condition; import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - /** * Test for dragging a deep shortcut to the home screen. */ @@ -29,7 +28,6 @@ import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) public class ShortcutsToHomeTest extends AbstractLauncherUiTest { - @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); @Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher(); @Test diff --git a/tests/src/com/android/launcher3/ui/WorkTabTest.java b/tests/src/com/android/launcher3/ui/WorkTabTest.java index 62444341a..2f867f366 100644 --- a/tests/src/com/android/launcher3/ui/WorkTabTest.java +++ b/tests/src/com/android/launcher3/ui/WorkTabTest.java @@ -15,15 +15,13 @@ */ package com.android.launcher3.ui; +import static com.android.launcher3.LauncherState.ALL_APPS; + +import static org.junit.Assert.assertTrue; + import android.support.test.filters.LargeTest; import android.support.test.runner.AndroidJUnit4; -import android.support.test.uiautomator.UiObject2; -import android.support.test.uiautomator.Until; -import com.android.launcher3.R; -import com.android.launcher3.util.Condition; -import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; import org.junit.After; @@ -32,14 +30,10 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertTrue; - @LargeTest @RunWith(AndroidJUnit4.class) public class WorkTabTest extends AbstractLauncherUiTest { @Rule - public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); - @Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher(); private int mProfileUserId; @@ -66,17 +60,13 @@ public class WorkTabTest extends AbstractLauncherUiTest { public void workTabExists() { mActivityMonitor.startLauncher(); - // Open all apps and wait for load complete - final UiObject2 appsContainer = openAllApps(); - assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), - LARGE_UI_TIMEOUT)); + executeOnLauncher(launcher -> launcher.getStateManager().goToState(ALL_APPS)); /* - assertTrue("Personal tab is missing", - mDevice.wait(Until.hasObject(getSelectorForId(R.id.tab_personal)), - LARGE_UI_TIMEOUT)); - assertTrue("Work tab is missing", - mDevice.wait(Until.hasObject(getSelectorForId(R.id.tab_work)), LARGE_UI_TIMEOUT)); + assertTrue("Personal tab is missing", waitForLauncherCondition( + launcher -> launcher.getAppsView().isPersonalTabVisible())); + assertTrue("Work tab is missing", waitForLauncherCondition( + launcher -> launcher.getAppsView().isWorkTabVisible())); */ } }
\ No newline at end of file diff --git a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java index a5c2e69af..44cdbaf7f 100644 --- a/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/AddConfigWidgetTest.java @@ -15,6 +15,11 @@ */ package com.android.launcher3.ui.widget; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + import android.appwidget.AppWidgetManager; import android.content.Intent; import android.support.test.filters.LargeTest; @@ -31,7 +36,6 @@ import com.android.launcher3.testcomponent.WidgetConfigActivity; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.util.Condition; import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; import com.android.launcher3.widget.WidgetCell; @@ -40,11 +44,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; - /** * Test to verify widget configuration is properly shown. */ @@ -52,7 +51,6 @@ import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) public class AddConfigWidgetTest extends AbstractLauncherUiTest { - @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grandWidgetBind(); private LauncherAppWidgetProviderInfo mWidgetInfo; diff --git a/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java index 19f7db72b..d89f26e8a 100644 --- a/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/AddWidgetTest.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.ui.widget; +import static org.junit.Assert.assertTrue; + import android.support.test.filters.LargeTest; import android.support.test.runner.AndroidJUnit4; import android.support.test.uiautomator.By; @@ -28,7 +30,6 @@ import com.android.launcher3.Workspace.ItemOperator; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.util.Condition; import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; import com.android.launcher3.widget.WidgetCell; @@ -36,8 +37,6 @@ import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; -import static org.junit.Assert.assertTrue; - /** * Test to add widget from widget tray */ @@ -45,7 +44,6 @@ import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) public class AddWidgetTest extends AbstractLauncherUiTest { - @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grandWidgetBind(); @Test diff --git a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java index b55711934..c8c38965c 100644 --- a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java @@ -15,6 +15,11 @@ */ package com.android.launcher3.ui.widget; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; + import android.appwidget.AppWidgetHost; import android.appwidget.AppWidgetManager; import android.content.ComponentName; @@ -30,21 +35,20 @@ import android.support.test.runner.AndroidJUnit4; import android.support.test.uiautomator.UiSelector; import com.android.launcher3.LauncherAppWidgetHost; -import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.LauncherAppWidgetInfo; import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.LauncherModel; import com.android.launcher3.LauncherSettings; -import com.android.launcher3.widget.PendingAppWidgetHostView; import com.android.launcher3.Workspace; import com.android.launcher3.compat.AppWidgetManagerCompat; import com.android.launcher3.compat.PackageInstallerCompat; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.util.ContentWriter; import com.android.launcher3.util.LooperExecutor; -import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; +import com.android.launcher3.widget.LauncherAppWidgetHostView; import com.android.launcher3.widget.PendingAddWidgetInfo; +import com.android.launcher3.widget.PendingAppWidgetHostView; import com.android.launcher3.widget.WidgetHostViewLoader; import org.junit.After; @@ -58,11 +62,6 @@ import java.util.Set; import java.util.concurrent.Callable; import java.util.concurrent.TimeUnit; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - /** * Tests for bind widget flow. * @@ -72,7 +71,6 @@ import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) public class BindWidgetTest extends AbstractLauncherUiTest { - @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grandWidgetBind(); private ContentResolver mResolver; diff --git a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java index dcb564a77..0022d1996 100644 --- a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java +++ b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java @@ -15,6 +15,10 @@ */ package com.android.launcher3.ui.widget; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertTrue; + import android.app.PendingIntent; import android.appwidget.AppWidgetManager; import android.content.Intent; @@ -40,7 +44,6 @@ import com.android.launcher3.testcomponent.RequestPinItemActivity; import com.android.launcher3.ui.AbstractLauncherUiTest; import com.android.launcher3.util.Condition; import com.android.launcher3.util.Wait; -import com.android.launcher3.util.rule.LauncherActivityRule; import com.android.launcher3.util.rule.ShellCommandRule; import com.android.launcher3.widget.WidgetCell; @@ -52,10 +55,6 @@ import org.junit.runner.RunWith; import java.util.UUID; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertTrue; - /** * Test to verify pin item request flow. */ @@ -63,7 +62,6 @@ import static org.junit.Assert.assertTrue; @RunWith(AndroidJUnit4.class) public class RequestPinItemTest extends AbstractLauncherUiTest { - @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); @Rule public ShellCommandRule mGrantWidgetRule = ShellCommandRule.grandWidgetBind(); @Rule public ShellCommandRule mDefaultLauncherRule = ShellCommandRule.setDefaultLauncher(); |