Merge "Add to tapl quickswitch test for testing intermediate carousel." into sc-v2-dev

This commit is contained in:
TreeHugger Robot 2021-11-08 13:15:44 +00:00 committed by Android (Google) Code Review
commit 3555ef3b31
3 changed files with 111 additions and 39 deletions

View File

@ -271,7 +271,9 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
background.quickSwitchToPreviousAppSwipeLeft(); background.quickSwitchToPreviousAppSwipeLeft();
assertTrue("The 2nd app we should have quick switched to is not running", assertTrue("The 2nd app we should have quick switched to is not running",
isTestActivityRunning(3)); isTestActivityRunning(3));
getAndAssertBackground();
background = getAndAssertBackground();
background.switchToOverview();
} }
private boolean isTestActivityRunning(int activityNumber) { private boolean isTestActivityRunning(int activityNumber) {

View File

@ -30,6 +30,7 @@ import androidx.test.uiautomator.UiObject2;
import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.testing.TestProtocol;
import java.util.List;
import java.util.regex.Pattern; import java.util.regex.Pattern;
/** /**
@ -62,11 +63,12 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
"want to switch from background to overview")) { "want to switch from background to overview")) {
verifyActiveContainer(); verifyActiveContainer();
goToOverviewUnchecked(); goToOverviewUnchecked();
return mLauncher.isFallbackOverview() ? return mLauncher.isFallbackOverview()
new BaseOverview(mLauncher) : new Overview(mLauncher); ? new BaseOverview(mLauncher) : new Overview(mLauncher);
} }
} }
protected boolean zeroButtonToOverviewGestureStartsInLauncher() { protected boolean zeroButtonToOverviewGestureStartsInLauncher() {
return mLauncher.isTablet(); return mLauncher.isTablet();
} }
@ -78,47 +80,56 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
protected void goToOverviewUnchecked() { protected void goToOverviewUnchecked() {
switch (mLauncher.getNavigationModel()) { switch (mLauncher.getNavigationModel()) {
case ZERO_BUTTON: { case ZERO_BUTTON: {
final int centerX = mLauncher.getDevice().getDisplayWidth() / 2; sendDownPointerToEnterOverviewToLauncher();
final int startY = getSwipeStartY(); String swipeAndHoldToEnterOverviewActionName =
final int swipeHeight = mLauncher.getTestInfo(getSwipeHeightRequestName()). "swiping and holding to enter overview";
getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD); // If swiping from an app (e.g. Overview is in Background), we pause and hold on
final Point start = new Point(centerX, startY); // swipe up to make overview appear, or else swiping without holding would take
final Point end = // us to the Home state. If swiping up from Home (e.g. Overview in Home or
new Point(centerX, startY - swipeHeight - mLauncher.getTouchSlop()); // Workspace state where the below condition is true), there is no need to pause,
// and we will not test for an intermediate carousel as one will not exist.
final long downTime = SystemClock.uptimeMillis();
final LauncherInstrumentation.GestureScope gestureScope =
zeroButtonToOverviewGestureStartsInLauncher()
? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE
: LauncherInstrumentation.GestureScope.OUTSIDE_WITH_PILFER;
mLauncher.sendPointer(
downTime, downTime, MotionEvent.ACTION_DOWN, start, gestureScope);
Runnable swipeAndHold = () -> mLauncher.movePointer(
downTime,
downTime,
ZERO_BUTTON_SWIPE_UP_GESTURE_DURATION,
start,
end,
gestureScope);
String swipeAndHoldAction = "swiping and holding";
Runnable up = () -> mLauncher.sendPointer(
downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, end,
gestureScope);
String upAction = "sending UP event";
if (zeroButtonToOverviewGestureStateTransitionWhileHolding()) { if (zeroButtonToOverviewGestureStateTransitionWhileHolding()) {
mLauncher.runToState(swipeAndHold, OVERVIEW_STATE_ORDINAL, swipeAndHoldAction); mLauncher.runToState(this::sendSwipeUpAndHoldToEnterOverviewGestureToLauncher,
try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(upAction)) { OVERVIEW_STATE_ORDINAL, swipeAndHoldToEnterOverviewActionName);
up.run(); sendUpPointerToEnterOverviewToLauncher();
}
} else { } else {
// If swiping up from an app to overview, pause on intermediate carousel
// until snapshots are visible. No intermediate carousel when swiping from
// Home. The task swiped up is not a snapshot but the TaskViewSimulator. If
// only a single task exists, no snapshots will be available during swipe up.
mLauncher.executeAndWaitForLauncherEvent( mLauncher.executeAndWaitForLauncherEvent(
swipeAndHold, this::sendSwipeUpAndHoldToEnterOverviewGestureToLauncher,
event -> TestProtocol.PAUSE_DETECTED_MESSAGE.equals( event -> TestProtocol.PAUSE_DETECTED_MESSAGE.equals(
event.getClassName()), event.getClassName().toString()),
() -> "Pause wasn't detected", () -> "Pause wasn't detected",
swipeAndHoldAction); swipeAndHoldToEnterOverviewActionName);
mLauncher.runToState(up, OVERVIEW_STATE_ORDINAL, upAction); try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
"paused on swipe up to overview")) {
if (mLauncher.getRecentTasks().size() > 1) {
// When swiping up to grid-overview for tablets, the swiped tab will be
// in the middle of the screen (TaskViewSimulator, not a snapshot), and
// all remaining snapshots will be to the left of that task. In
// non-tablet overview, snapshots can be on either side of the swiped
// task, but we still check that they become visible after swiping and
// pausing.
mLauncher.waitForOverviewObject("snapshot");
if (mLauncher.isTablet()) {
List<UiObject2> tasks = mLauncher.getDevice().findObjects(
mLauncher.getOverviewObjectSelector("snapshot"));
final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
mLauncher.assertTrue(
"All tasks not to the left of the swiped task",
tasks.stream()
.allMatch(
t -> t.getVisibleBounds().right < centerX));
}
}
String upPointerToEnterOverviewActionName =
"sending UP pointer to enter overview";
mLauncher.runToState(this::sendUpPointerToEnterOverviewToLauncher,
OVERVIEW_STATE_ORDINAL, upPointerToEnterOverviewActionName);
}
} }
break; break;
} }
@ -167,6 +178,60 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
private void expectSwitchToOverviewEvents() { private void expectSwitchToOverviewEvents() {
} }
private void sendDownPointerToEnterOverviewToLauncher() {
final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
final int startY = getSwipeStartY();
final Point start = new Point(centerX, startY);
final long downTime = SystemClock.uptimeMillis();
final LauncherInstrumentation.GestureScope gestureScope =
zeroButtonToOverviewGestureStartsInLauncher()
? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE
: LauncherInstrumentation.GestureScope.OUTSIDE_WITH_PILFER;
mLauncher.sendPointer(
downTime, downTime, MotionEvent.ACTION_DOWN, start, gestureScope);
}
private void sendSwipeUpAndHoldToEnterOverviewGestureToLauncher() {
final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
final int startY = getSwipeStartY();
final int swipeHeight = mLauncher.getTestInfo(getSwipeHeightRequestName()).getInt(
TestProtocol.TEST_INFO_RESPONSE_FIELD);
final Point start = new Point(centerX, startY);
final Point end =
new Point(centerX, startY - swipeHeight - mLauncher.getTouchSlop());
final long downTime = SystemClock.uptimeMillis();
final LauncherInstrumentation.GestureScope gestureScope =
zeroButtonToOverviewGestureStartsInLauncher()
? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE
: LauncherInstrumentation.GestureScope.OUTSIDE_WITH_PILFER;
mLauncher.movePointer(
downTime,
downTime,
ZERO_BUTTON_SWIPE_UP_GESTURE_DURATION,
start,
end,
gestureScope);
}
private void sendUpPointerToEnterOverviewToLauncher() {
final int centerX = mLauncher.getDevice().getDisplayWidth() / 2;
final int startY = getSwipeStartY();
final int swipeHeight = mLauncher.getTestInfo(getSwipeHeightRequestName()).getInt(
TestProtocol.TEST_INFO_RESPONSE_FIELD);
final Point end =
new Point(centerX, startY - swipeHeight - mLauncher.getTouchSlop());
final long downTime = SystemClock.uptimeMillis();
final LauncherInstrumentation.GestureScope gestureScope =
zeroButtonToOverviewGestureStartsInLauncher()
? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE
: LauncherInstrumentation.GestureScope.OUTSIDE_WITH_PILFER;
mLauncher.sendPointer(downTime, SystemClock.uptimeMillis(),
MotionEvent.ACTION_UP, end, gestureScope);
}
@NonNull @NonNull
public Background quickSwitchToPreviousApp() { public Background quickSwitchToPreviousApp() {
boolean toRight = true; boolean toRight = true;

View File

@ -1155,6 +1155,11 @@ public final class LauncherInstrumentation {
return By.copy(selector).pkg(getLauncherPackageName()); return By.copy(selector).pkg(getLauncherPackageName());
} }
@NonNull
UiObject2 waitForOverviewObject(String resName) {
return waitForObjectBySelector(getOverviewObjectSelector(resName));
}
@NonNull @NonNull
UiObject2 waitForLauncherObject(String resName) { UiObject2 waitForLauncherObject(String resName) {
return waitForObjectBySelector(getLauncherObjectSelector(resName)); return waitForObjectBySelector(getLauncherObjectSelector(resName));