summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorvadimt <vadimt@google.com>2019-06-11 19:15:14 -0700
committervadimt <vadimt@google.com>2019-06-17 15:13:25 -0700
commit06d30e54d597f5ec0c914966055a1e2b2aedbed8 (patch)
tree31ddf3bb1679268a8f32863d33ed5d3139ad5be6 /tests
parentf46e3956ddba136c44df97aa1997aa67b0387018 (diff)
downloadandroid_packages_apps_Trebuchet-06d30e54d597f5ec0c914966055a1e2b2aedbed8.tar.gz
android_packages_apps_Trebuchet-06d30e54d597f5ec0c914966055a1e2b2aedbed8.tar.bz2
android_packages_apps_Trebuchet-06d30e54d597f5ec0c914966055a1e2b2aedbed8.zip
Enabling tests in landscape mode
Bug: 121280703 Change-Id: I3245ca8d0b0496035658ce2a602882a62942f3f1
Diffstat (limited to 'tests')
-rw-r--r--tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java44
-rw-r--r--tests/src/com/android/launcher3/ui/PortraitLandscapeRunner.java63
-rw-r--r--tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java6
-rw-r--r--tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java2
-rw-r--r--tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java5
-rw-r--r--tests/tapl/com/android/launcher3/tapl/Background.java32
-rw-r--r--tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java6
-rw-r--r--tests/tapl/com/android/launcher3/tapl/Workspace.java4
8 files changed, 98 insertions, 64 deletions
diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
index abc93cd4b..e663e7030 100644
--- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
+++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java
@@ -35,7 +35,6 @@ import android.content.pm.PackageManager;
import android.os.Process;
import android.os.RemoteException;
import android.util.Log;
-import android.view.Surface;
import androidx.test.InstrumentationRegistry;
import androidx.test.uiautomator.By;
@@ -67,7 +66,6 @@ import org.junit.Before;
import org.junit.Rule;
import org.junit.rules.RuleChain;
import org.junit.rules.TestRule;
-import org.junit.runners.model.Statement;
import java.io.IOException;
import java.lang.annotation.ElementType;
@@ -124,46 +122,10 @@ public abstract class AbstractLauncherUiTest {
protected @interface PortraitLandscape {
}
- @Rule
- public TestRule mPortraitLandscapeExecutor =
- (base, description) -> false && description.getAnnotation(PortraitLandscape.class)
- != null ? new Statement() {
- @Override
- public void evaluate() throws Throwable {
- try {
- // Create launcher activity if necessary and bring it to the front.
- mLauncher.pressHome();
- waitForLauncherCondition("Launcher activity wasn't created",
- launcher -> launcher != null);
-
- executeOnLauncher(launcher ->
- launcher.getRotationHelper().forceAllowRotationForTesting(true));
-
- evaluateInPortrait();
- evaluateInLandscape();
- } finally {
- mDevice.setOrientationNatural();
- executeOnLauncher(launcher ->
- launcher.getRotationHelper().forceAllowRotationForTesting(false));
- mLauncher.setExpectedRotation(Surface.ROTATION_0);
- }
- }
-
- private void evaluateInPortrait() throws Throwable {
- mDevice.setOrientationNatural();
- mLauncher.setExpectedRotation(Surface.ROTATION_0);
- base.evaluate();
- }
-
- private void evaluateInLandscape() throws Throwable {
- mDevice.setOrientationLeft();
- mLauncher.setExpectedRotation(Surface.ROTATION_90);
- base.evaluate();
- }
- } : base;
-
protected TestRule getRulesInsideActivityMonitor() {
- return new FailureWatcher(this);
+ return RuleChain.
+ outerRule(new PortraitLandscapeRunner(this)).
+ around(new FailureWatcher(this));
}
@Rule
diff --git a/tests/src/com/android/launcher3/ui/PortraitLandscapeRunner.java b/tests/src/com/android/launcher3/ui/PortraitLandscapeRunner.java
new file mode 100644
index 000000000..20cd1e7d2
--- /dev/null
+++ b/tests/src/com/android/launcher3/ui/PortraitLandscapeRunner.java
@@ -0,0 +1,63 @@
+package com.android.launcher3.ui;
+
+import android.view.Surface;
+
+import com.android.launcher3.tapl.TestHelpers;
+
+import org.junit.rules.TestRule;
+import org.junit.runner.Description;
+import org.junit.runners.model.Statement;
+
+class PortraitLandscapeRunner implements TestRule {
+ private AbstractLauncherUiTest mTest;
+
+ public PortraitLandscapeRunner(AbstractLauncherUiTest test) {
+ mTest = test;
+ }
+
+ @Override
+ public Statement apply(Statement base, Description description) {
+ if (!TestHelpers.isInLauncherProcess() ||
+ description.getAnnotation(AbstractLauncherUiTest.PortraitLandscape.class) == null) {
+ return base;
+ }
+
+ return new Statement() {
+ @Override
+ public void evaluate() throws Throwable {
+ try {
+ mTest.mDevice.pressHome();
+ mTest.waitForLauncherCondition("Launcher activity wasn't created",
+ launcher -> launcher != null);
+
+ mTest.executeOnLauncher(launcher ->
+ launcher.getRotationHelper().forceAllowRotationForTesting(
+ true));
+
+ evaluateInPortrait();
+ evaluateInLandscape();
+ } finally {
+ mTest.mDevice.setOrientationNatural();
+ mTest.executeOnLauncher(launcher ->
+ launcher.getRotationHelper().forceAllowRotationForTesting(
+ false));
+ mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
+ }
+ }
+
+ private void evaluateInPortrait() throws Throwable {
+ mTest.mDevice.setOrientationNatural();
+ mTest.mLauncher.setExpectedRotation(Surface.ROTATION_0);
+ base.evaluate();
+ mTest.mLauncher.pressHome();
+ }
+
+ private void evaluateInLandscape() throws Throwable {
+ mTest.mDevice.setOrientationLeft();
+ mTest.mLauncher.setExpectedRotation(Surface.ROTATION_90);
+ base.evaluate();
+ mTest.mLauncher.pressHome();
+ }
+ };
+ }
+}
diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
index d171004fc..06c56f2c4 100644
--- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
+++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
@@ -59,11 +59,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
public static void initialize(AbstractLauncherUiTest test) throws Exception {
test.clearLauncherData();
- if (TestHelpers.isInLauncherProcess()) {
- test.mActivityMonitor.returnToHome();
- } else {
- test.mDevice.pressHome();
- }
+ test.mDevice.pressHome();
test.waitForLauncherCondition("Launcher didn't start", launcher -> launcher != null);
test.waitForState("Launcher internal state didn't switch to Home", LauncherState.NORMAL);
test.waitForResumed("Launcher internal state is still Background");
diff --git a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
index a57d7bab8..be27a66a4 100644
--- a/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
+++ b/tests/src/com/android/launcher3/ui/widget/RequestPinItemTest.java
@@ -190,7 +190,7 @@ public class RequestPinItemTest extends AbstractLauncherUiTest {
}
// Go back to home
- mActivityMonitor.returnToHome();
+ mLauncher.pressHome();
Wait.atMost(null, new ItemSearchCondition(itemMatcher), DEFAULT_ACTIVITY_TIMEOUT);
}
diff --git a/tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java b/tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java
index 145c3c89e..2aba7a56d 100644
--- a/tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java
+++ b/tests/src/com/android/launcher3/util/rule/LauncherActivityRule.java
@@ -72,11 +72,6 @@ public class LauncherActivityRule implements TestRule {
getInstrumentation().startActivitySync(getHomeIntentInPackage(getTargetContext()));
}
- public void returnToHome() {
- getTargetContext().startActivity(getHomeIntentInPackage(getTargetContext()));
- getInstrumentation().waitForIdleSync();
- }
-
private class MyStatement extends Statement implements ActivityLifecycleCallbacks {
private final Statement mBase;
diff --git a/tests/tapl/com/android/launcher3/tapl/Background.java b/tests/tapl/com/android/launcher3/tapl/Background.java
index 6c4619235..c9eaf276d 100644
--- a/tests/tapl/com/android/launcher3/tapl/Background.java
+++ b/tests/tapl/com/android/launcher3/tapl/Background.java
@@ -87,16 +87,24 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
}
case TWO_BUTTON: {
- final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
- final int startY = getSwipeStartY();
- final int swipeHeight = mLauncher.getTestInfo(getSwipeHeightRequestName()).
- getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
-
- mLauncher.swipeToState(
- centerX, startY, centerX,
- startY - swipeHeight - mLauncher.getTouchSlop(),
- 10,
- expectedState);
+ final int startX;
+ final int startY;
+ final int endX;
+ final int endY;
+ final int swipeLength = mLauncher.getTestInfo(getSwipeHeightRequestName()).
+ getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD) + mLauncher.getTouchSlop();
+
+ if (mLauncher.getDevice().isNaturalOrientation()) {
+ startX = endX = mLauncher.getDevice().getDisplayWidth() / 2;
+ startY = getSwipeStartY();
+ endY = startY - swipeLength;
+ } else {
+ startX = getSwipeStartX();
+ endX = startX - swipeLength;
+ startY = endY = mLauncher.getDevice().getDisplayHeight() / 2;
+ }
+
+ mLauncher.swipeToState(startX, startY, endX, endY, 10, expectedState);
break;
}
@@ -111,6 +119,10 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
return TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT;
}
+ protected int getSwipeStartX() {
+ return mLauncher.getRealDisplaySize().x - 1;
+ }
+
protected int getSwipeStartY() {
return mLauncher.getRealDisplaySize().y - 1;
}
diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
index 2db9d0826..5be4d8195 100644
--- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
+++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java
@@ -333,7 +333,11 @@ public final class LauncherInstrumentation {
"but the current state is not " + containerType.name())) {
switch (containerType) {
case WORKSPACE: {
- waitForLauncherObject(APPS_RES_ID);
+ if (mDevice.isNaturalOrientation()) {
+ waitForLauncherObject(APPS_RES_ID);
+ } else {
+ waitUntilGone(APPS_RES_ID);
+ }
waitUntilGone(OVERVIEW_RES_ID);
waitUntilGone(WIDGETS_RES_ID);
return waitForLauncherObject(WORKSPACE_RES_ID);
diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java
index 33754c125..26c7b8f30 100644
--- a/tests/tapl/com/android/launcher3/tapl/Workspace.java
+++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java
@@ -213,6 +213,8 @@ public final class Workspace extends Home {
@Override
protected int getSwipeStartY() {
- return mLauncher.waitForLauncherObject("hotseat").getVisibleBounds().top;
+ return mLauncher.getDevice().isNaturalOrientation() ?
+ mLauncher.waitForLauncherObject("hotseat").getVisibleBounds().top
+ : mLauncher.getRealDisplaySize().y - 1;
}
} \ No newline at end of file