summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorVadim Tryshev <vadimt@google.com>2019-07-24 01:30:06 +0000
committerAndroid (Google) Code Review <android-gerrit@google.com>2019-07-24 01:30:06 +0000
commit7b0520afe48b511ed910de1048405185712e5b03 (patch)
tree19a97bba15f9b129fd315b4949d94f50a8d67e13 /tests
parent064cba456090fe1b651f98e0e891b3b84e541b1f (diff)
parent0dd1c782f0cb1653f191a2ec9db72f8f26190dc8 (diff)
downloadandroid_packages_apps_Trebuchet-7b0520afe48b511ed910de1048405185712e5b03.tar.gz
android_packages_apps_Trebuchet-7b0520afe48b511ed910de1048405185712e5b03.tar.bz2
android_packages_apps_Trebuchet-7b0520afe48b511ed910de1048405185712e5b03.zip
Merge "Checking Launcher internal integrity from tests" into ub-launcher3-qt-r1-dev
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java71
-rw-r--r--tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java17
2 files changed, 87 insertions, 1 deletions
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index 361f2fb53..8dc8cea40 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -17,6 +17,7 @@ package com.android.launcher3.ui;
import static androidx.test.InstrumentationRegistry.getInstrumentation;
+import static com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName;
import static org.junit.Assert.assertTrue;
@@ -45,6 +46,7 @@ import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherState;
+import com.android.launcher3.LauncherStateManager;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.Utilities;
import com.android.launcher3.compat.LauncherAppsCompat;
@@ -52,6 +54,7 @@ import com.android.launcher3.model.AppLaunchTracker;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.testcomponent.TestCommandReceiver;
+import com.android.launcher3.testing.TestProtocol;
import com.android.launcher3.util.PackageManagerHelper;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.FailureWatcher;
@@ -103,6 +106,10 @@ public abstract class AbstractLauncherUiTest {
Utilities.enableRunningInTestHarnessForTests();
mLauncher.setSystemHealthSupplier(() -> TestCommandReceiver.callCommand(
TestCommandReceiver.GET_SYSTEM_HEALTH_MESSAGE).getString("result"));
+ mLauncher.setOnSettledStateAction(
+ containerType -> executeOnLauncher(
+ launcher ->
+ checkLauncherIntegrity(launcher, containerType)));
}
}
@@ -379,4 +386,68 @@ public abstract class AbstractLauncherUiTest {
protected int getAllAppsScroll(Launcher launcher) {
return launcher.getAppsView().getActiveRecyclerView().getCurrentScrollY();
}
+
+ private static void checkLauncherIntegrity(
+ Launcher launcher, ContainerType expectedContainerType) {
+ if (launcher != null) {
+ final LauncherStateManager stateManager = launcher.getStateManager();
+ final LauncherState stableState = stateManager.getCurrentStableState();
+
+ assertTrue("Stable state != state: " + stableState.getClass().getSimpleName() + ", "
+ + stateManager.getState().getClass().getSimpleName(),
+ stableState == stateManager.getState());
+
+ final boolean isResumed = launcher.hasBeenResumed();
+ assertTrue("hasBeenResumed() != isStarted(), hasBeenResumed(): " + isResumed,
+ isResumed == launcher.isStarted());
+ assertTrue("hasBeenResumed() != isUserActive(), hasBeenResumed(): " + isResumed,
+ isResumed == launcher.isUserActive());
+
+ final int ordinal = stableState.ordinal;
+
+ switch (expectedContainerType) {
+ case WORKSPACE:
+ case WIDGETS: {
+ assertTrue(
+ "Launcher is not resumed in state: " + expectedContainerType,
+ isResumed);
+ assertTrue(TestProtocol.stateOrdinalToString(ordinal),
+ ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
+ break;
+ }
+ case ALL_APPS: {
+ assertTrue(
+ "Launcher is not resumed in state: " + expectedContainerType,
+ isResumed);
+ assertTrue(TestProtocol.stateOrdinalToString(ordinal),
+ ordinal == TestProtocol.ALL_APPS_STATE_ORDINAL);
+ break;
+ }
+ case OVERVIEW: {
+ assertTrue(
+ "Launcher is not resumed in state: " + expectedContainerType,
+ isResumed);
+ assertTrue(TestProtocol.stateOrdinalToString(ordinal),
+ ordinal == TestProtocol.OVERVIEW_STATE_ORDINAL);
+ break;
+ }
+ case BACKGROUND: {
+ assertTrue("Launcher is resumed in state: " + expectedContainerType,
+ !isResumed);
+ assertTrue(TestProtocol.stateOrdinalToString(ordinal),
+ ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
+ break;
+ }
+ default:
+ throw new IllegalArgumentException(
+ "Illegal container: " + expectedContainerType);
+ }
+ } else {
+ assertTrue(
+ "Container type is not BACKGROUND or FALLBACK_OVERVIEW: "
+ + expectedContainerType,
+ expectedContainerType == ContainerType.BACKGROUND ||
+ expectedContainerType == ContainerType.FALLBACK_OVERVIEW);
+ }
+ }
}
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 1a22e53de..f91e2ada7 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -72,6 +72,7 @@ import java.util.Deque;
import java.util.LinkedList;
import java.util.List;
import java.util.concurrent.TimeoutException;
+import java.util.function.Consumer;
import java.util.function.Supplier;
/**
@@ -86,7 +87,7 @@ public final class LauncherInstrumentation {
// 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 {
+ public enum ContainerType {
WORKSPACE, ALL_APPS, OVERVIEW, WIDGETS, BACKGROUND, FALLBACK_OVERVIEW
}
@@ -135,6 +136,8 @@ public final class LauncherInstrumentation {
private final Deque<String> mDiagnosticContext = new LinkedList<>();
private Supplier<String> mSystemHealthSupplier;
+ private Consumer<ContainerType> mOnSettledStateAction;
+
/**
* Constructs the root of TAPL hierarchy. You get all other objects from it.
*/
@@ -296,6 +299,10 @@ public final class LauncherInstrumentation {
this.mSystemHealthSupplier = supplier;
}
+ public void setOnSettledStateAction(Consumer<ContainerType> onSettledStateAction) {
+ mOnSettledStateAction = onSettledStateAction;
+ }
+
private String getSystemHealthMessage() {
final String testPackage = getContext().getPackageName();
try {
@@ -415,6 +422,14 @@ public final class LauncherInstrumentation {
assertTrue(error, error == null);
log("verifyContainerType: " + containerType);
+ final UiObject2 container = verifyVisibleObjects(containerType);
+
+ if (mOnSettledStateAction != null) mOnSettledStateAction.accept(containerType);
+
+ return container;
+ }
+
+ private UiObject2 verifyVisibleObjects(ContainerType containerType) {
try (Closable c = addContextLayer(
"but the current state is not " + containerType.name())) {
switch (containerType) {