diff options
Diffstat (limited to 'tests')
9 files changed, 79 insertions, 20 deletions
diff --git a/tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java b/tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java index dd3e859fd..59b2da036 100644 --- a/tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java +++ b/tests/src/com/android/launcher3/model/BaseModelUpdateTaskTestCase.java @@ -24,7 +24,7 @@ import androidx.test.rule.provider.ProviderTestRule; import com.android.launcher3.AllAppsList; import com.android.launcher3.AppFilter; import com.android.launcher3.AppInfo; -import com.android.launcher3.IconCache; +import com.android.launcher3.icons.IconCache; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppState; diff --git a/tests/src/com/android/launcher3/model/LoaderCursorTest.java b/tests/src/com/android/launcher3/model/LoaderCursorTest.java index 29e54b137..42a276401 100644 --- a/tests/src/com/android/launcher3/model/LoaderCursorTest.java +++ b/tests/src/com/android/launcher3/model/LoaderCursorTest.java @@ -10,7 +10,7 @@ import androidx.test.InstrumentationRegistry; import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; -import com.android.launcher3.IconCache; +import com.android.launcher3.icons.IconCache; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.ItemInfo; import com.android.launcher3.LauncherAppState; diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index d45036607..ba7d9c523 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -52,10 +52,10 @@ 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.After; import org.junit.Before; import org.junit.Rule; @@ -78,22 +78,31 @@ public abstract class AbstractLauncherUiTest { public static final long DEFAULT_WORKER_TIMEOUT_SECS = 5; protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor(); - protected UiDevice mDevice; - protected LauncherInstrumentation mLauncher; + protected final UiDevice mDevice; + protected final LauncherInstrumentation mLauncher; protected Context mTargetContext; protected String mTargetPackage; private static final String TAG = "AbstractLauncherUiTest"; + protected AbstractLauncherUiTest() { + mDevice = UiDevice.getInstance(getInstrumentation()); + mLauncher = new LauncherInstrumentation(getInstrumentation()); + } + @Rule public LauncherActivityRule mActivityMonitor = new LauncherActivityRule(); @Before public void setUp() throws Exception { - mDevice = UiDevice.getInstance(getInstrumentation()); - mLauncher = new LauncherInstrumentation(getInstrumentation()); mTargetContext = InstrumentationRegistry.getTargetContext(); mTargetPackage = mTargetContext.getPackageName(); + mDevice.executeShellCommand("settings put global heads_up_notifications_enabled 0"); + } + + @After + public void tearDown() throws Exception { + mDevice.executeShellCommand("settings put global heads_up_notifications_enabled 1"); } protected void lockRotation(boolean naturalOrientation) throws RemoteException { @@ -278,12 +287,7 @@ public abstract class AbstractLauncherUiTest { // flakiness. protected boolean waitForLauncherCondition( Function<Launcher, Boolean> condition, long timeout) { - return Wait.atMost(new Condition() { - @Override - public boolean isTrue() { - return getFromLauncher(condition); - } - }, timeout); + return Wait.atMost(() -> getFromLauncher(condition), timeout); } /** diff --git a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java index 0dc9b2e67..17fdd2692 100644 --- a/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java +++ b/tests/src/com/android/launcher3/ui/widget/BindWidgetTest.java @@ -103,6 +103,8 @@ public class BindWidgetTest extends AbstractLauncherUiTest { if (mSessionId > -1) { mTargetContext.getPackageManager().getPackageInstaller().abandonSession(mSessionId); } + + super.tearDown(); } @Test diff --git a/tests/src/com/android/launcher3/widget/WidgetsListAdapterTest.java b/tests/src/com/android/launcher3/widget/WidgetsListAdapterTest.java index d5b14f298..307a53eef 100644 --- a/tests/src/com/android/launcher3/widget/WidgetsListAdapterTest.java +++ b/tests/src/com/android/launcher3/widget/WidgetsListAdapterTest.java @@ -29,7 +29,7 @@ import androidx.test.filters.SmallTest; import androidx.test.runner.AndroidJUnit4; import android.view.LayoutInflater; -import com.android.launcher3.IconCache; +import com.android.launcher3.icons.IconCache; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppWidgetProviderInfo; import com.android.launcher3.WidgetPreviewLoader; diff --git a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java index dd286bd1f..42817c1af 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/AllAppsFromOverview.java @@ -17,9 +17,9 @@ package com.android.launcher3.tapl; import android.graphics.Point; -import androidx.test.uiautomator.UiObject2; import androidx.annotation.NonNull; +import androidx.test.uiautomator.UiObject2; /** * Operations on AllApps opened from Overview. @@ -44,6 +44,7 @@ public final class AllAppsFromOverview extends AllApps { allAppsContainer, "search_container_all_apps"); final Point start = qsb.getVisibleCenter(); final int endY = (int) (mLauncher.getDevice().getDisplayHeight() * 0.6); + LauncherInstrumentation.log("AllAppsFromOverview.switchBackToOverview before swipe"); mLauncher.swipe(start.x, start.y, start.x, endY); return new Overview(mLauncher); diff --git a/tests/tapl/com/android/launcher3/tapl/AppIcon.java b/tests/tapl/com/android/launcher3/tapl/AppIcon.java index 17bf5fcec..a11f6df0a 100644 --- a/tests/tapl/com/android/launcher3/tapl/AppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/AppIcon.java @@ -42,13 +42,29 @@ public final class AppIcon { /** * Clicks the icon to launch its app. */ + @Deprecated public Background launch() { + LauncherInstrumentation.log("AppIcon.launch before click"); LauncherInstrumentation.assertTrue( "Launching an app didn't open a new window: " + mIcon.getText(), mIcon.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS)); return new Background(mLauncher); } + /** + * Clicks the icon to launch its app. + */ + public Background launch(String packageName) { + LauncherInstrumentation.log("AppIcon.launch before click"); + LauncherInstrumentation.assertTrue( + "Launching an app didn't open a new window: " + mIcon.getText(), + mIcon.clickAndWait(Until.newWindow(), LauncherInstrumentation.WAIT_TIME_MS)); + LauncherInstrumentation.assertTrue( + "App didn't start: " + packageName, mLauncher.getDevice().wait(Until.hasObject( + By.pkg(packageName).depth(0)), LauncherInstrumentation.WAIT_TIME_MS)); + return new Background(mLauncher); + } + UiObject2 getIcon() { return mIcon; } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 434e421b6..7885e3cce 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -24,6 +24,8 @@ import android.app.UiAutomation; import android.os.Bundle; import android.os.Parcelable; import android.provider.Settings; +import android.util.Log; +import android.view.Surface; import android.view.accessibility.AccessibilityEvent; import androidx.annotation.NonNull; @@ -47,6 +49,8 @@ import java.util.concurrent.TimeoutException; */ public final class LauncherInstrumentation { + private static final String TAG = "Tapl"; + // Types for launcher containers that the user is interacting with. "Background" is a // pseudo-container corresponding to inactive launcher covered by another app. enum ContainerType { @@ -89,6 +93,7 @@ public final class LauncherInstrumentation { private final boolean mSwipeUpEnabled; private Boolean mSwipeUpEnabledOverride = null; private final Instrumentation mInstrumentation; + private int mExpectedRotation = Surface.ROTATION_0; /** * Constructs the root of TAPL hierarchy. You get all other objects from it. @@ -106,7 +111,7 @@ public final class LauncherInstrumentation { assertTrue("Device must run in a test harness", ActivityManager.isRunningInTestHarness()); } - // Used only by tests. + // Used only by TaplTests. public void overrideSwipeUpEnabled(Boolean swipeUpEnabledOverride) { mSwipeUpEnabledOverride = swipeUpEnabledOverride; } @@ -119,6 +124,10 @@ public final class LauncherInstrumentation { return mSwipeUpEnabledOverride != null ? mSwipeUpEnabledOverride : mSwipeUpEnabled; } + static void log(String message) { + Log.d(TAG, message); + } + private static void fail(String message) { Assert.fail("http://go/tapl : " + message); } @@ -137,13 +146,30 @@ public final class LauncherInstrumentation { fail(message + ". " + "Actual: " + actual); } + static public void assertEquals(String message, int expected, int actual) { + if (expected != actual) { + fail(message + " expected: " + expected + " but was: " + actual); + } + } + static void assertNotEquals(String message, int unexpected, int actual) { if (unexpected == actual) { failEquals(message, actual); } } + public void setExpectedRotation(int expectedRotation) { + mExpectedRotation = expectedRotation; + } + private UiObject2 verifyContainerType(ContainerType containerType) { + assertEquals("Unexpected display rotation", + mExpectedRotation, mDevice.getDisplayRotation()); + assertTrue("Presence of recents button doesn't match isSwipeUpEnabled()", + isSwipeUpEnabled() == + (mDevice.findObject(By.res(SYSTEMUI_PACKAGE, "recent_apps")) == null)); + log("verifyContainerType: " + containerType); + switch (containerType) { case WORKSPACE: { waitUntilGone(APPS_RES_ID); @@ -164,7 +190,11 @@ public final class LauncherInstrumentation { return waitForLauncherObject(APPS_RES_ID); } case OVERVIEW: { - waitForLauncherObject(APPS_RES_ID); + if (mDevice.isNaturalOrientation()) { + waitForLauncherObject(APPS_RES_ID); + } else { + waitUntilGone(APPS_RES_ID); + } waitUntilGone(WORKSPACE_RES_ID); waitUntilGone(WIDGETS_RES_ID); return waitForLauncherObject(OVERVIEW_RES_ID); @@ -217,7 +247,10 @@ public final class LauncherInstrumentation { // otherwise waitForIdle may return immediately in case when there was a big enough pause in // accessibility events prior to pressing Home. executeAndWaitForEvent( - () -> getSystemUiObject("home").click(), + () -> { + log("LauncherInstrumentation.pressHome before clicking"); + getSystemUiObject("home").click(); + }, event -> true, "Pressing Home didn't produce any events"); mDevice.waitForIdle(); diff --git a/tests/tapl/com/android/launcher3/tapl/Overview.java b/tests/tapl/com/android/launcher3/tapl/Overview.java index db0e6c5db..9841274d6 100644 --- a/tests/tapl/com/android/launcher3/tapl/Overview.java +++ b/tests/tapl/com/android/launcher3/tapl/Overview.java @@ -17,14 +17,14 @@ package com.android.launcher3.tapl; import android.graphics.Point; + +import androidx.annotation.NonNull; import androidx.test.uiautomator.Direction; import androidx.test.uiautomator.UiObject2; import java.util.Collections; import java.util.List; -import androidx.annotation.NonNull; - /** * Overview pane. */ @@ -46,6 +46,7 @@ public final class Overview extends LauncherInstrumentation.VisibleContainer { */ public void flingForward() { final UiObject2 overview = verifyActiveContainer(); + LauncherInstrumentation.log("Overview.flingForward before fling"); overview.fling(Direction.LEFT, DEFAULT_FLING_SPEED); mLauncher.waitForIdle(); verifyActiveContainer(); @@ -56,6 +57,7 @@ public final class Overview extends LauncherInstrumentation.VisibleContainer { */ public void flingBackward() { final UiObject2 overview = verifyActiveContainer(); + LauncherInstrumentation.log("Overview.flingBackward before fling"); overview.fling(Direction.RIGHT, DEFAULT_FLING_SPEED); mLauncher.waitForIdle(); verifyActiveContainer(); @@ -95,6 +97,7 @@ public final class Overview extends LauncherInstrumentation.VisibleContainer { // Swipe from navbar to the top. final UiObject2 navBar = mLauncher.getSystemUiObject("navigation_bar_frame"); final Point start = navBar.getVisibleCenter(); + LauncherInstrumentation.log("Overview.switchToAllApps before swipe"); mLauncher.swipe(start.x, start.y, start.x, 0); return new AllAppsFromOverview(mLauncher); |