Loading quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java +54 −4 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.quickstep; import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; Loading @@ -34,6 +35,7 @@ import com.android.launcher3.LauncherState; import com.android.launcher3.tapl.AllApps; import com.android.launcher3.tapl.AllAppsFromOverview; import com.android.launcher3.tapl.Background; import com.android.launcher3.tapl.LauncherInstrumentation.NavigationModel; import com.android.launcher3.tapl.Overview; import com.android.launcher3.tapl.OverviewTask; import com.android.launcher3.tapl.TestHelpers; Loading Loading @@ -210,16 +212,21 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { @PortraitLandscape public void testBackground() throws Exception { startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR)); final Background background = getAndAssertBackground(); assertNotNull("Background.switchToOverview() returned null", background.switchToOverview()); assertTrue("Launcher internal state didn't switch to Overview", isInState(LauncherState.OVERVIEW)); } private Background getAndAssertBackground() { final Background background = mLauncher.getBackground(); assertNotNull("Launcher.getBackground() returned null", background); executeOnLauncher(launcher -> assertTrue( "Launcher activity is the top activity; expecting another activity to be the top " + "one", isInBackground(launcher))); assertNotNull("Background.switchToOverview() returned null", background.switchToOverview()); assertTrue("Launcher internal state didn't switch to Overview", isInState(LauncherState.OVERVIEW)); return background; } @Test Loading @@ -237,4 +244,47 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { assertTrue("Launcher internal state is not Home", isInState(LauncherState.NORMAL)); assertNotNull("getHome returned null", mLauncher.getWorkspace()); } @Test @NavigationModeSwitch @PortraitLandscape public void testQuickSwitchFromApp() throws Exception { startAppFast(getAppPackageName()); startTestActivity(2); String calculatorPackage = resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR); startAppFast(calculatorPackage); Background background = getAndAssertBackground(); background.quickSwitchToPreviousApp(); assertTrue("The first app we should have quick switched to is not running", isTestActivityRunning("TestActivity2")); background = getAndAssertBackground(); background.quickSwitchToPreviousApp(); 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.", mDevice.wait(Until.hasObject(By.pkg(calculatorPackage)), DEFAULT_UI_TIMEOUT)); } else { assertTrue("The second app we should have quick switched to is not running", isTestActivityRunning("Test Pin Item")); } getAndAssertBackground(); } private boolean isTestActivityRunning(String activityLabel) { return mDevice.wait(Until.hasObject(By.pkg(getAppPackageName()).text(activityLabel)), DEFAULT_UI_TIMEOUT); } @Test @NavigationModeSwitch @PortraitLandscape public void testQuickSwitchFromHome() throws Exception { startTestActivity(2); mLauncher.pressHome().quickSwitchToPreviousApp(); assertTrue("The most recent task is not running after quick switching from home", isTestActivityRunning("TestActivity2")); getAndAssertBackground(); } } tests/tapl/com/android/launcher3/tapl/Background.java +41 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.SystemClock; import android.view.MotionEvent; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; import com.android.launcher3.testing.TestProtocol; Loading Loading @@ -114,6 +115,46 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } } /** * Swipes right or double presses the square button to switch to the previous app. */ public Background quickSwitchToPreviousApp() { try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( "want to quick switch to the previous app")) { verifyActiveContainer(); quickSwitchToPreviousApp(getExpectedStateForQuickSwitch()); return new Background(mLauncher); } } protected int getExpectedStateForQuickSwitch() { return BACKGROUND_APP_STATE_ORDINAL; } protected void quickSwitchToPreviousApp(int expectedState) { switch (mLauncher.getNavigationModel()) { case ZERO_BUTTON: // Fall through, zero button and two button modes behave the same. case TWO_BUTTON: { // Swipe from the bottom left to the bottom right of the screen. final int startX = 0; final int startY = getSwipeStartY(); final int endX = mLauncher.getDevice().getDisplayWidth(); final int endY = startY; mLauncher.swipeToState(startX, startY, endX, endY, 20, expectedState); break; } case THREE_BUTTON: // Double press the recents button. UiObject2 recentsButton = mLauncher.waitForSystemUiObject("recent_apps"); recentsButton.click(); mLauncher.getOverview(); recentsButton.click(); break; } } protected String getSwipeHeightRequestName() { return TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT; } Loading tests/tapl/com/android/launcher3/tapl/Home.java +6 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.tapl; import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; import static com.android.launcher3.testing.TestProtocol.QUICK_SWITCH_STATE_ORDINAL; import androidx.annotation.NonNull; Loading Loading @@ -58,4 +59,9 @@ public abstract class Home extends Background { } } } @Override protected int getExpectedStateForQuickSwitch() { return QUICK_SWITCH_STATE_ORDINAL; } } No newline at end of file Loading
quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java +54 −4 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.quickstep; import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertTrue; Loading @@ -34,6 +35,7 @@ import com.android.launcher3.LauncherState; import com.android.launcher3.tapl.AllApps; import com.android.launcher3.tapl.AllAppsFromOverview; import com.android.launcher3.tapl.Background; import com.android.launcher3.tapl.LauncherInstrumentation.NavigationModel; import com.android.launcher3.tapl.Overview; import com.android.launcher3.tapl.OverviewTask; import com.android.launcher3.tapl.TestHelpers; Loading Loading @@ -210,16 +212,21 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { @PortraitLandscape public void testBackground() throws Exception { startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR)); final Background background = getAndAssertBackground(); assertNotNull("Background.switchToOverview() returned null", background.switchToOverview()); assertTrue("Launcher internal state didn't switch to Overview", isInState(LauncherState.OVERVIEW)); } private Background getAndAssertBackground() { final Background background = mLauncher.getBackground(); assertNotNull("Launcher.getBackground() returned null", background); executeOnLauncher(launcher -> assertTrue( "Launcher activity is the top activity; expecting another activity to be the top " + "one", isInBackground(launcher))); assertNotNull("Background.switchToOverview() returned null", background.switchToOverview()); assertTrue("Launcher internal state didn't switch to Overview", isInState(LauncherState.OVERVIEW)); return background; } @Test Loading @@ -237,4 +244,47 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { assertTrue("Launcher internal state is not Home", isInState(LauncherState.NORMAL)); assertNotNull("getHome returned null", mLauncher.getWorkspace()); } @Test @NavigationModeSwitch @PortraitLandscape public void testQuickSwitchFromApp() throws Exception { startAppFast(getAppPackageName()); startTestActivity(2); String calculatorPackage = resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR); startAppFast(calculatorPackage); Background background = getAndAssertBackground(); background.quickSwitchToPreviousApp(); assertTrue("The first app we should have quick switched to is not running", isTestActivityRunning("TestActivity2")); background = getAndAssertBackground(); background.quickSwitchToPreviousApp(); 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.", mDevice.wait(Until.hasObject(By.pkg(calculatorPackage)), DEFAULT_UI_TIMEOUT)); } else { assertTrue("The second app we should have quick switched to is not running", isTestActivityRunning("Test Pin Item")); } getAndAssertBackground(); } private boolean isTestActivityRunning(String activityLabel) { return mDevice.wait(Until.hasObject(By.pkg(getAppPackageName()).text(activityLabel)), DEFAULT_UI_TIMEOUT); } @Test @NavigationModeSwitch @PortraitLandscape public void testQuickSwitchFromHome() throws Exception { startTestActivity(2); mLauncher.pressHome().quickSwitchToPreviousApp(); assertTrue("The most recent task is not running after quick switching from home", isTestActivityRunning("TestActivity2")); getAndAssertBackground(); } }
tests/tapl/com/android/launcher3/tapl/Background.java +41 −0 Original line number Diff line number Diff line Loading @@ -23,6 +23,7 @@ import android.os.SystemClock; import android.view.MotionEvent; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; import com.android.launcher3.testing.TestProtocol; Loading Loading @@ -114,6 +115,46 @@ public class Background extends LauncherInstrumentation.VisibleContainer { } } /** * Swipes right or double presses the square button to switch to the previous app. */ public Background quickSwitchToPreviousApp() { try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer( "want to quick switch to the previous app")) { verifyActiveContainer(); quickSwitchToPreviousApp(getExpectedStateForQuickSwitch()); return new Background(mLauncher); } } protected int getExpectedStateForQuickSwitch() { return BACKGROUND_APP_STATE_ORDINAL; } protected void quickSwitchToPreviousApp(int expectedState) { switch (mLauncher.getNavigationModel()) { case ZERO_BUTTON: // Fall through, zero button and two button modes behave the same. case TWO_BUTTON: { // Swipe from the bottom left to the bottom right of the screen. final int startX = 0; final int startY = getSwipeStartY(); final int endX = mLauncher.getDevice().getDisplayWidth(); final int endY = startY; mLauncher.swipeToState(startX, startY, endX, endY, 20, expectedState); break; } case THREE_BUTTON: // Double press the recents button. UiObject2 recentsButton = mLauncher.waitForSystemUiObject("recent_apps"); recentsButton.click(); mLauncher.getOverview(); recentsButton.click(); break; } } protected String getSwipeHeightRequestName() { return TestProtocol.REQUEST_BACKGROUND_TO_OVERVIEW_SWIPE_HEIGHT; } Loading
tests/tapl/com/android/launcher3/tapl/Home.java +6 −0 Original line number Diff line number Diff line Loading @@ -17,6 +17,7 @@ package com.android.launcher3.tapl; import static com.android.launcher3.testing.TestProtocol.OVERVIEW_STATE_ORDINAL; import static com.android.launcher3.testing.TestProtocol.QUICK_SWITCH_STATE_ORDINAL; import androidx.annotation.NonNull; Loading Loading @@ -58,4 +59,9 @@ public abstract class Home extends Background { } } } @Override protected int getExpectedStateForQuickSwitch() { return QUICK_SWITCH_STATE_ORDINAL; } } No newline at end of file