Merge "Add quick switch to trackpad gesture tests" into udc-qpr-dev
This commit is contained in:
@@ -16,11 +16,17 @@
|
||||
|
||||
package com.android.quickstep;
|
||||
|
||||
import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName;
|
||||
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import android.os.SystemProperties;
|
||||
|
||||
import androidx.test.uiautomator.By;
|
||||
import androidx.test.uiautomator.Until;
|
||||
|
||||
import com.android.launcher3.Launcher;
|
||||
import com.android.launcher3.tapl.LaunchedAppState;
|
||||
import com.android.launcher3.tapl.LauncherInstrumentation;
|
||||
import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
|
||||
import com.android.launcher3.ui.AbstractLauncherUiTest;
|
||||
@@ -76,6 +82,21 @@ public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest {
|
||||
}
|
||||
}
|
||||
|
||||
protected void assertTestActivityIsRunning(int activityNumber, String message) {
|
||||
assertTrue(message, mDevice.wait(
|
||||
Until.hasObject(By.pkg(getAppPackageName()).text("TestActivity" + activityNumber)),
|
||||
DEFAULT_UI_TIMEOUT));
|
||||
}
|
||||
|
||||
protected LaunchedAppState getAndAssertLaunchedApp() {
|
||||
final LaunchedAppState launchedAppState = mLauncher.getLaunchedAppState();
|
||||
executeOnLauncher(launcher -> assertTrue(
|
||||
"Launcher activity is the top activity; expecting another activity to be the top "
|
||||
+ "one",
|
||||
isInLaunchedApp(launcher)));
|
||||
return launchedAppState;
|
||||
}
|
||||
|
||||
private boolean isInLiveTileMode(Launcher launcher,
|
||||
LauncherInstrumentation.ContainerType expectedContainerType) {
|
||||
if (expectedContainerType != LauncherInstrumentation.ContainerType.OVERVIEW) {
|
||||
|
||||
@@ -241,16 +241,6 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
isInState(() -> LauncherState.OVERVIEW));
|
||||
}
|
||||
|
||||
private LaunchedAppState getAndAssertLaunchedApp() {
|
||||
final LaunchedAppState launchedAppState = mLauncher.getLaunchedAppState();
|
||||
assertNotNull("Launcher.getLaunchedApp() returned null", launchedAppState);
|
||||
executeOnLauncher(launcher -> assertTrue(
|
||||
"Launcher activity is the top activity; expecting another activity to be the top "
|
||||
+ "one",
|
||||
isInLaunchedApp(launcher)));
|
||||
return launchedAppState;
|
||||
}
|
||||
|
||||
private void quickSwitchToPreviousAppAndAssert(boolean toRight) {
|
||||
final LaunchedAppState launchedAppState = getAndAssertLaunchedApp();
|
||||
if (toRight) {
|
||||
@@ -292,22 +282,22 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
startTestActivity(4);
|
||||
|
||||
quickSwitchToPreviousAppAndAssert(true /* toRight */);
|
||||
assertTrue("The first app we should have quick switched to is not running",
|
||||
isTestActivityRunning(3));
|
||||
assertTestActivityIsRunning(3,
|
||||
"The first app we should have quick switched to is not running");
|
||||
|
||||
quickSwitchToPreviousAppAndAssert(true /* toRight */);
|
||||
if (mLauncher.getNavigationModel() == NavigationModel.THREE_BUTTON) {
|
||||
// 3-button mode toggles between 2 apps, rather than going back further.
|
||||
assertTrue("Second quick switch should have returned to the first app.",
|
||||
isTestActivityRunning(4));
|
||||
assertTestActivityIsRunning(4,
|
||||
"Second quick switch should have returned to the first app.");
|
||||
} else {
|
||||
assertTrue("The second app we should have quick switched to is not running",
|
||||
isTestActivityRunning(2));
|
||||
assertTestActivityIsRunning(2,
|
||||
"The second app we should have quick switched to is not running");
|
||||
}
|
||||
|
||||
quickSwitchToPreviousAppAndAssert(false /* toRight */);
|
||||
assertTrue("The 2nd app we should have quick switched to is not running",
|
||||
isTestActivityRunning(3));
|
||||
assertTestActivityIsRunning(3,
|
||||
"The 2nd app we should have quick switched to is not running");
|
||||
|
||||
final LaunchedAppState launchedAppState = getAndAssertLaunchedApp();
|
||||
launchedAppState.switchToOverview();
|
||||
@@ -331,9 +321,9 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
// Quick-switch to the test app with swiping to right.
|
||||
quickSwitchToPreviousAppAndAssert(true /* toRight */);
|
||||
|
||||
assertTrue("The first app we should have quick switched to is not running",
|
||||
isTestActivityRunning(2));
|
||||
|
||||
assertTestActivityIsRunning(2,
|
||||
"The first app we should have quick switched to is not running");
|
||||
// Expect task bar visible when the launched app was the test activity.
|
||||
launchedAppState = getAndAssertLaunchedApp();
|
||||
|
||||
Log.e(FLAKY_QUICK_SWITCH_TO_PREVIOUS_APP,
|
||||
@@ -347,12 +337,6 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isTestActivityRunning(int activityNumber) {
|
||||
return mDevice.wait(Until.hasObject(By.pkg(getAppPackageName())
|
||||
.text("TestActivity" + activityNumber)),
|
||||
DEFAULT_UI_TIMEOUT);
|
||||
}
|
||||
|
||||
@Test
|
||||
@NavigationModeSwitch
|
||||
@PortraitLandscape
|
||||
@@ -360,8 +344,8 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
|
||||
public void testQuickSwitchFromHome() throws Exception {
|
||||
startTestActivity(2);
|
||||
mLauncher.goHome().quickSwitchToPreviousApp();
|
||||
assertTrue("The most recent task is not running after quick switching from home",
|
||||
isTestActivityRunning(2));
|
||||
assertTestActivityIsRunning(2,
|
||||
"The most recent task is not running after quick switching from home");
|
||||
getAndAssertLaunchedApp();
|
||||
}
|
||||
|
||||
|
||||
@@ -19,6 +19,7 @@ package com.android.quickstep;
|
||||
import static com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assume.assumeFalse;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
@@ -30,6 +31,7 @@ import androidx.test.runner.AndroidJUnit4;
|
||||
|
||||
import com.android.launcher3.config.FeatureFlags;
|
||||
import com.android.launcher3.tapl.LauncherInstrumentation.TrackpadGestureType;
|
||||
import com.android.launcher3.tapl.Workspace;
|
||||
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
|
||||
import com.android.launcher3.ui.TaplTestsLauncher3;
|
||||
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
|
||||
@@ -112,4 +114,19 @@ public class TaplTestsTrackpad extends AbstractQuickStepTest {
|
||||
assertNotNull("switchToAllApps() returned null",
|
||||
mLauncher.getWorkspace().switchToAllApps());
|
||||
}
|
||||
|
||||
@Test
|
||||
@NavigationModeSwitch
|
||||
@PortraitLandscape
|
||||
public void testQuickSwitchFromHome() throws Exception {
|
||||
assumeTrue(mLauncher.isTablet());
|
||||
|
||||
startTestActivity(2);
|
||||
Workspace workspace = mLauncher.goHome();
|
||||
mLauncher.setTrackpadGestureType(TrackpadGestureType.FOUR_FINGER);
|
||||
workspace.quickSwitchToPreviousApp();
|
||||
assertTestActivityIsRunning(2,
|
||||
"The most recent task is not running after quick switching from home");
|
||||
getAndAssertLaunchedApp();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -240,76 +240,71 @@ public abstract class Background extends LauncherInstrumentation.VisibleContaine
|
||||
"want to quick switch to the previous app")) {
|
||||
verifyActiveContainer();
|
||||
final boolean launcherWasVisible = mLauncher.isLauncherVisible();
|
||||
switch (mLauncher.getNavigationModel()) {
|
||||
case ZERO_BUTTON: {
|
||||
final int startX;
|
||||
final int startY;
|
||||
final int endX;
|
||||
final int endY;
|
||||
final int cornerRadius = (int) Math.ceil(mLauncher.getWindowCornerRadius());
|
||||
if (toRight) {
|
||||
// Swipe from the bottom left to the bottom right of the screen.
|
||||
startX = cornerRadius;
|
||||
startY = getSwipeStartY();
|
||||
endX = mLauncher.getDevice().getDisplayWidth() - cornerRadius;
|
||||
endY = startY;
|
||||
} else {
|
||||
// Swipe from the bottom right to the bottom left of the screen.
|
||||
startX = mLauncher.getDevice().getDisplayWidth() - cornerRadius;
|
||||
startY = getSwipeStartY();
|
||||
endX = cornerRadius;
|
||||
endY = startY;
|
||||
}
|
||||
|
||||
LauncherInstrumentation.GestureScope gestureScope =
|
||||
launcherWasVisible
|
||||
? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE
|
||||
: LauncherInstrumentation.GestureScope.OUTSIDE_WITH_PILFER;
|
||||
mLauncher.executeAndWaitForEvent(
|
||||
() -> mLauncher.linearGesture(
|
||||
startX, startY, endX, endY, 20, false, gestureScope),
|
||||
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
|
||||
() -> "Quick switch gesture didn't change window state", "swiping");
|
||||
break;
|
||||
if (mLauncher.getNavigationModel() == NavigationModel.ZERO_BUTTON
|
||||
|| mLauncher.getTrackpadGestureType() == TrackpadGestureType.FOUR_FINGER) {
|
||||
final int startX;
|
||||
final int startY;
|
||||
final int endX;
|
||||
final int endY;
|
||||
final int cornerRadius = (int) Math.ceil(mLauncher.getWindowCornerRadius());
|
||||
if (toRight) {
|
||||
// Swipe from the bottom left to the bottom right of the screen.
|
||||
startX = cornerRadius;
|
||||
startY = getSwipeStartY();
|
||||
endX = mLauncher.getDevice().getDisplayWidth() - cornerRadius;
|
||||
endY = startY;
|
||||
} else {
|
||||
// Swipe from the bottom right to the bottom left of the screen.
|
||||
startX = mLauncher.getDevice().getDisplayWidth() - cornerRadius;
|
||||
startY = getSwipeStartY();
|
||||
endX = cornerRadius;
|
||||
endY = startY;
|
||||
}
|
||||
|
||||
case THREE_BUTTON:
|
||||
// Double press the recents button.
|
||||
UiObject2 recentsButton = mLauncher.waitForNavigationUiObject("recent_apps");
|
||||
if (mLauncher.isTablet()) {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
|
||||
LauncherInstrumentation.EVENT_TOUCH_DOWN);
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
|
||||
LauncherInstrumentation.EVENT_TOUCH_UP);
|
||||
}
|
||||
if (mLauncher.isTrackpadGestureEnabled()) {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_DOWN_TIS);
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_UP_TIS);
|
||||
}
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT);
|
||||
mLauncher.runToState(() -> recentsButton.click(), OVERVIEW_STATE_ORDINAL,
|
||||
"clicking Recents button for the first time");
|
||||
mLauncher.getOverview();
|
||||
if (mLauncher.isTablet()) {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
|
||||
LauncherInstrumentation.EVENT_TOUCH_DOWN);
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
|
||||
LauncherInstrumentation.EVENT_TOUCH_UP);
|
||||
}
|
||||
if (mLauncher.isTrackpadGestureEnabled()) {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_DOWN_TIS);
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_UP_TIS);
|
||||
}
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT);
|
||||
mLauncher.executeAndWaitForEvent(
|
||||
() -> recentsButton.click(),
|
||||
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
|
||||
() -> "Pressing recents button didn't change window state",
|
||||
"clicking Recents button for the second time");
|
||||
break;
|
||||
LauncherInstrumentation.GestureScope gestureScope =
|
||||
launcherWasVisible
|
||||
? LauncherInstrumentation.GestureScope.INSIDE_TO_OUTSIDE
|
||||
: LauncherInstrumentation.GestureScope.OUTSIDE_WITH_PILFER;
|
||||
mLauncher.executeAndWaitForEvent(
|
||||
() -> mLauncher.linearGesture(
|
||||
startX, startY, endX, endY, 20, false, gestureScope),
|
||||
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
|
||||
() -> "Quick switch gesture didn't change window state", "swiping");
|
||||
} else {
|
||||
// Double press the recents button.
|
||||
UiObject2 recentsButton = mLauncher.waitForNavigationUiObject("recent_apps");
|
||||
if (mLauncher.isTablet()) {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
|
||||
LauncherInstrumentation.EVENT_TOUCH_DOWN);
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
|
||||
LauncherInstrumentation.EVENT_TOUCH_UP);
|
||||
}
|
||||
if (mLauncher.isTrackpadGestureEnabled()) {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_DOWN_TIS);
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_UP_TIS);
|
||||
}
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT);
|
||||
mLauncher.runToState(() -> recentsButton.click(), OVERVIEW_STATE_ORDINAL,
|
||||
"clicking Recents button for the first time");
|
||||
mLauncher.getOverview();
|
||||
if (mLauncher.isTablet()) {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
|
||||
LauncherInstrumentation.EVENT_TOUCH_DOWN);
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN,
|
||||
LauncherInstrumentation.EVENT_TOUCH_UP);
|
||||
}
|
||||
if (mLauncher.isTrackpadGestureEnabled()) {
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_DOWN_TIS);
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_TIS, EVENT_TOUCH_UP_TIS);
|
||||
}
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, SQUARE_BUTTON_EVENT);
|
||||
mLauncher.executeAndWaitForEvent(
|
||||
() -> recentsButton.click(),
|
||||
event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
|
||||
() -> "Pressing recents button didn't change window state",
|
||||
"clicking Recents button for the second time");
|
||||
}
|
||||
mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user