Enabling tests in landscape mode
Bug: 121280703 Change-Id: I3245ca8d0b0496035658ce2a602882a62942f3f1
This commit is contained in:
parent
f46e3956dd
commit
06d30e54d5
|
@ -208,7 +208,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
|||
|
||||
@Test
|
||||
@NavigationModeSwitch
|
||||
@PortraitLandscape
|
||||
// @PortraitLandscape
|
||||
public void testBackground() throws Exception {
|
||||
startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
|
||||
final Background background = mLauncher.getBackground();
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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();
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
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();
|
||||
|
||||
mLauncher.swipeToState(
|
||||
centerX, startY, centerX,
|
||||
startY - swipeHeight - mLauncher.getTouchSlop(),
|
||||
10,
|
||||
expectedState);
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue